Newer
Older
from django.utils.translation import gettext as _
from netbox.forms import (
NetBoxModelForm,
NetBoxModelFilterSetForm,
NetBoxModelImportForm,
)
from utilities.forms.fields import DynamicModelMultipleChoiceField, TagFilterField
from utilities.forms import BOOLEAN_WITH_BLANK_CHOICES, add_blank_choice
from .models import (
Mapping,
AuthenticationChoices,
HttpHeader,
ApplyToChoices,
SamlConfig,
class MappingForm(NetBoxModelForm):
class Meta:
model = Mapping
fields = (
"source",
"target",
"authentication",
"webdav",
"testingpage",
"gzip_proxied",
"keepalive_requests",
"keepalive_timeout",
"proxy_cache",
"proxy_read_timeout",
"client_max_body_size",
help_texts = {
"target": "URL-friendly unique shorthand",
"keepalive_requests": "Min value 100 requests, max 5000 requests, default 1000 requests.",
"keepalive_timeout": "In seconds. Min value 1, max 300, default 75.",
"proxy_read_timeout": "In seconds. Min value 1, max 300, default 60.",
"client_max_body_size": "In Mega Bytes. Min 1, max 255, default 1.",
"source": "Source URL",
"target": "Target URL",
"testingpage": "Testing Page URL",
"keepalive_timeout": "Keepalive timeout (s)",
"proxy_read_timeout": " Proxy read timeout (s)",
"client_max_body_size": "Client max body size (MB)",
"sorry_page": "Sorry Page URL",
}
class MappingFilterForm(NetBoxModelFilterSetForm):
max_length=URL_MAX_SIZE, min_length=1, required=False, label="Source URL"
max_length=URL_MAX_SIZE, min_length=1, required=False, label="Target URL"
authentication = forms.MultipleChoiceField(
choices=AuthenticationChoices,
required=False,
)
required=False, widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES)
)
testingpage = forms.CharField(
max_length=120, min_length=1, required=False, label="Testing URL"
)
Comment = forms.CharField(
max_length=500, min_length=1, required=False, label="Comment"
gzip_proxied = webdav = forms.BooleanField(
required=False, widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES)
)
keepalive_requests = forms.IntegerField(
min_value=100, max_value=5000, required=False
)
keepalive_timeout = forms.IntegerField(min_value=1, max_value=300, required=False)
proxy_cache = forms.BooleanField(
required=False, widget=forms.Select(choices=BOOLEAN_WITH_BLANK_CHOICES)
)
proxy_read_timeout = forms.IntegerField(min_value=1, max_value=300, required=False)
client_max_body_size = forms.IntegerField(
min_value=1, max_value=255, required=False
)
sorry_page = forms.CharField(
max_length=URL_MAX_SIZE, min_length=1, required=False, label="Sorry Page URL"
)
class MappingImportForm(NetBoxModelImportForm):
"""Mapping importation form definition class"""
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
authentication = forms.MultipleChoiceField(
choices=AuthenticationChoices,
required=False,
help_text='Authentication method. Can be "none", "ldap" and "ecas". Default to "none".',
)
keepalive_requests = forms.IntegerField(
min_value=100,
max_value=5000,
required=False,
help_text="Min value 100 requests, max 5000 requests, default 1000 requests.",
)
keepalive_timeout = forms.IntegerField(
min_value=1,
max_value=300,
required=False,
help_text="In seconds. Min value 1, max 300, default 75.",
)
proxy_read_timeout = forms.IntegerField(
min_value=1,
max_value=300,
required=False,
help_text="In seconds. Min value 1, max 300, default 60.",
)
client_max_body_size = forms.IntegerField(
min_value=1,
max_value=255,
required=False,
help_text="In Mega Bytes. Min 1, max 255, default 1.",
)
sorry_page = forms.CharField(
max_length=URL_MAX_SIZE,
min_length=1,
required=False,
help_text="Sorry Page URL",
)
fields = (
"source",
"target",
"authentication",
"testingpage",
"webdav",
"testingpage",
"Comment",
"gzip_proxied",
"keepalive_requests",
"keepalive_timeout",
"proxy_cache",
"proxy_read_timeout",
"client_max_body_size",
"sorry_page",
)
help_texts = {
"source": "Source URL",
"target": "Target URL",
"testingpage": "Testing page URL",
"webdav": 'Define if the mapping handle Webdav protocol. Default to "false"',
"gzip_proxied": 'Is gzip proxied. Default to "false"',
"proxy_cache": 'Is proxy cache activated. Default to "false"',
}
fields = ("mapping", "name", "value", "apply_to")
"mapping": "Mapping",
"name": "Name",
"value": "Value",
"apply_to": "Apply to",
class HttpHeaderFilterForm(NetBoxModelFilterSetForm):
"""HTTP header filter form definition class"""
name = forms.CharField(
max_length=120, min_length=1, required=False, label="Header name"
)
value = forms.CharField(
max_length=256, min_length=1, required=False, label="Header value"
)
apply_to = forms.ChoiceField(
choices=add_blank_choice(ApplyToChoices), required=False, label="Apply to"
)
mapping = DynamicModelMultipleChoiceField(
queryset=Mapping.objects.all(), required=False, label=_("Mapping")
)
tag = TagFilterField(model)
class SamlConfigForm(NetBoxModelForm):
class Meta:
model = SamlConfig
fields = ("mapping", "acs_url", "logout_url", "force_nauth")
labels = {
"mapping": "Mapping",
"acs_url": "ACS URL",
"logout_url": "Logout URL",
"force_nauth": "Force AuthnRequest",
}