Ejemplo n.º 1
0
class ASCreationForm(_CreateUpdateModelForm):
    """
    Specialised ModelForm for AS creation which will initialise keys and initialise default AS
    services. Also allows to define the internal/public and bind IPs for the first host of the AS.
    """
    class Meta:
        fields = (
            'isd',
            'as_id',
            'label',
            'mtu',
            'is_core',
            'owner',
        )

    internal_ip = forms.GenericIPAddressField(required=False,
                                              initial=DEFAULT_HOST_INTERNAL_IP)
    public_ip = forms.GenericIPAddressField()
    bind_ip = forms.GenericIPAddressField(required=False)

    def create(self):
        """
        Create the AS, initialise keys and create a first host with default services.
        """
        return AS.objects.create_with_default_services(
            isd=self.cleaned_data['isd'],
            as_id=self.cleaned_data['as_id'],
            label=self.cleaned_data['label'],
            mtu=self.cleaned_data['mtu'],
            is_core=self.cleaned_data['is_core'],
            owner=self.cleaned_data['owner'],
            internal_ip=self.cleaned_data['internal_ip'],
            public_ip=self.cleaned_data['public_ip'],
            bind_ip=self.cleaned_data['bind_ip'],
        )
Ejemplo n.º 2
0
class NetTestForm(forms.Form):
    test_site = forms.URLField(label="Test Site", required=True, help_text="Site to use to test HTTP/S connections",
                               widget=forms.URLInput(attrs={'class': 'form-control'}))
    proxy_address = forms.GenericIPAddressField(unpack_ipv4=True, label="Proxy IP",
                                                widget=forms.TextInput(attrs={'class': 'form-control'}))
    gateway_address = forms.GenericIPAddressField(unpack_ipv4=True, label="Gateway Address",
                                                  help_text="By default, this is at .254 of your range",
                                                  widget=forms.TextInput(attrs={'class': 'form-control'}))
Ejemplo n.º 3
0
class SearchForm(forms.Form):
    def __init__(self, *args, **kwargs):
        super(SearchForm, self).__init__(*args, **kwargs)
        self.fields['uid'] = forms.CharField(widget=forms.widgets.Select(choices=uid_list()))

    src = forms.GenericIPAddressField(required=False)
    dst = forms.GenericIPAddressField(required=False)
    date_from = forms.DateTimeField(required=False, input_formats=('%Y-%m-%d %H:%M',), widget=forms.DateTimeInput(format=('%Y-%m-%d %H:%M',), attrs={'type': 'datetime-local'}))
    date_until = forms.DateTimeField(required=False, input_formats=('%Y-%m-%d %H:%M',), widget=forms.DateTimeInput(format=('%Y-%m-%d %H:%M',), attrs={'type': 'datetime-local'}))
Ejemplo n.º 4
0
class AppForm(forms.Form):
    name = forms.CharField(max_length=256)
    description = forms.CharField(max_length=1024)
    server_pool = forms.CharField(max_length=1024)
    protocol = forms.IntegerField()
    socket_port = forms.IntegerField()
    packet_per_second = forms.IntegerField()
    vip = forms.GenericIPAddressField()
    src_ip = forms.GenericIPAddressField()
Ejemplo n.º 5
0
class GitSettingForm(forms.ModelForm):
    hostname = forms.CharField(label=u'GitLab域名', widget=forms.TextInput(attrs={'class': 'form-control',"placeholder": "gitlab.niubilety.com"}))
    rootoken = forms.CharField(label=u'管理员Token', widget=forms.TextInput(attrs={'class': 'form-control'}))
    sourcepath = forms.CharField(label=u'上线源目录', widget=forms.TextInput(attrs={'class': 'form-control',"placeholder": "/var/htdocs"}))
    ngxpath = forms.CharField(label=u'nginx目录', widget=forms.TextInput(attrs={'class': 'form-control',"placeholder": "/usr/local/nginx1.8.0"}))
    testserver = forms.GenericIPAddressField(label=u'测试服务器IP', widget=forms.TextInput(attrs={'class': 'form-control',"placeholder": "127.0.0.1"}))
    devserver = forms.GenericIPAddressField(label=u'开发服务器IP', widget=forms.TextInput(attrs={'class': 'form-control',"placeholder": "127.0.0.1"}))
    class Meta:
        model = GitSetting
        fields ='__all__'

        widgets = {
            'ngxconf': forms.Textarea(attrs={'style': 'height:200px;width:800px'}),
        }
Ejemplo n.º 6
0
class HostBaseForm(forms.ModelForm):
    groups = forms.ModelMultipleChoiceField(
        required=False,
        queryset=models.Group.objects.all(),
        to_field_name="id",
        widget=forms.SelectMultiple(attrs={'class': 'select2'}),
        label=u'应用组')
    storages = forms.ModelMultipleChoiceField(
        required=False,
        queryset=models.Storage.objects.all(),
        to_field_name="id",
        widget=forms.SelectMultiple(attrs={'class': 'select2'}),
        label=u'存储')
    systemtype = forms.ModelChoiceField(
        required=True,
        queryset=models.System_Type.objects.all(),
        to_field_name="id",
        widget=forms.Select(attrs={'class': 'select2'}),
        label=u'操作系统')
    connect_ip = forms.GenericIPAddressField(required=True, label=u"连接IP")
    service_ip = forms.GenericIPAddressField(required=False, label=u"服务IP")

    coreness = forms.CharField(required=False, max_length=5, label=u"CPU核数")
    memory = forms.CharField(required=False, max_length=7, label=u"内存大小")
    root_disk = forms.CharField(required=False, max_length=7, label=u"本地磁盘")

    server_position = forms.CharField(required=False, empty_value=u'未指定位置')
    hostname = forms.CharField(required=False,
                               empty_value=u'localhost.localdomain')
    sshport = forms.IntegerField(required=True, label=u'连接端口')
    info = forms.CharField(widget=forms.Textarea(attrs=None), label=u'信息')

    class Meta:
        model = models.Host
        fields = [
            'groups', 'storages', 'systemtype', 'connect_ip', 'service_ip',
            'coreness', 'memory', 'root_disk', 'server_position', 'hostname',
            'sshport', 'info'
        ]

    #
    #
    # def clean_sshpasswd(self):
    #     sshpasswd = self.cleaned_data['sshpasswd']
    #     if checkpass.checkPassword(sshpasswd):
    #         return aes.encrypt(sshpasswd)
    #     else:
    #         raise forms.ValidationError(u'密码复杂度不足')
    def save(self, commit=True):
        host = super(HostBaseForm, self).save(commit=commit)
Ejemplo n.º 7
0
class EnhancedNumberForm(NumberForm):
    STATUS = (
        ('1', 'Активный'),
        ('0', 'Отключен'),
    )

    name = forms.CharField(max_length=255)
    status = forms.ChoiceField(choices=STATUS)
    address = forms.CharField(max_length=255)
    description = forms.CharField(max_length=255)
    device_name = forms.CharField(max_length=255)
    device_login = forms.CharField(max_length=255)
    device_password = forms.CharField(max_length=255)
    device_wan = forms.GenericIPAddressField(protocol='IPv4')
    device_lan = forms.GenericIPAddressField(protocol='IPv4', required=False)
    ArticleFormSet = forms.formset_factory(CustomerForm)

    def clean(self):
        cleaned_data = super(EnhancedNumberForm, self).clean()

        Current_device = Device()
        Current_customer = Customer()
        name = cleaned_data.get("name")
        status = cleaned_data.get("status")
        address = cleaned_data.get("address")
        description = cleaned_data.get("description")

        Current_customer.name = name
        Current_customer.status = status
        Current_customer.address = address
        Current_customer.description = description

        device_name = cleaned_data.get("device_name")
        device_login = cleaned_data.get("device_login")
        device_password = cleaned_data.get("device_password")
        device_wan = cleaned_data.get("device_wan")
        device_lan = cleaned_data.get("device_lan")

        Current_device.name = device_name
        Current_device.login = device_login
        Current_device.password = device_password
        Current_device.wan = device_wan
        Current_device.lan = device_lan

        self.instance.device = Current_device
        self.instance.customer = Current_customer
        if self.is_valid():
            self.instance.device.save()
            self.instance.customer.save()
Ejemplo n.º 8
0
class AddHostForm(forms.Form):
    hostname = forms.CharField(label="主机名", max_length=128)
    type = forms.IntegerField(label="类型")
    ip = forms.GenericIPAddressField(label="主机IP")
    wip = forms.GenericIPAddressField(label="公网IP", required=False)
    protocol = forms.IntegerField(label='协议')
    env = forms.IntegerField(label='环境')
    port = forms.IntegerField(label='端口')
    release = forms.CharField(label="系统/型号", max_length=255)
    memo = forms.CharField(label="备注",
                           max_length=255,
                           widget=forms.Textarea,
                           required=False)
    enabled = forms.BooleanField(label="是否启用", required=False)
    binduserid = forms.IntegerField(label="绑定账号")
Ejemplo n.º 9
0
class remoteDatabaseParamsModelForm(ModelForm):
    TYPE_CHOICE = [('-1', u'不使用汇总库'), ('1', '使用汇总库')]
    dbip = forms.GenericIPAddressField(label=u"远端数据库IP地址*",
                                       required=True,
                                       widget=forms.TextInput(attrs={
                                           'class': 'form-control',
                                           'for': 'id_ip'
                                       }))
    username = forms.CharField(label=u"远端数据库用户名*",
                               required=True,
                               initial='postgres',
                               widget=forms.TextInput(attrs={
                                   'class': 'form-control',
                                   'for': 'id_username'
                               }))
    password = forms.CharField(label=u"远端数据库密码*",
                               required=True,
                               initial='root',
                               widget=forms.PasswordInput(attrs={
                                   'class': 'form-control',
                                   'for': 'id_password'
                               }))
    districtcode = forms.ChoiceField(
        label=u"是否使用汇总库*",
        required=False,
        choices=TYPE_CHOICE,
        widget=Select(attrs={
            'class': 'form-control',
            'for': 'id_clienttype'
        }))

    class Meta:
        model = IcbcDb
        fields = ['dbip', 'username', 'password', 'districtcode']
Ejemplo n.º 10
0
class remoteDatabaseParamsForm(forms.Form):
    IP = forms.GenericIPAddressField(label=u"远端数据库IP地址*",
                                     required=True,
                                     widget=forms.TextInput(attrs={
                                         'class': 'form-control',
                                         'for': 'id_ip'
                                     }))
    Port = forms.IntegerField(label=u"远端数据库的端口*",
                              required=True,
                              initial=5432,
                              min_value=2000,
                              max_value=99999,
                              widget=forms.TextInput(attrs={
                                  'class': 'form-control',
                                  'for': 'id_port'
                              }))
    username = forms.CharField(label=u"远端数据库用户名*",
                               required=True,
                               initial='postgres',
                               widget=forms.TextInput(attrs={
                                   'class': 'form-control',
                                   'for': 'id_username'
                               }))
    password = forms.CharField(label=u"远端数据库密码*",
                               required=True,
                               initial='root',
                               widget=forms.PasswordInput(attrs={
                                   'class': 'form-control',
                                   'for': 'id_password'
                               }))
Ejemplo n.º 11
0
class VulnScanForm(FormFieldMixin, MaterialModelForm):
    site_ip = forms.GenericIPAddressField()
    name = forms.CharField(required=True)

    class Meta:
        model = VulnScanModel
        fields = ('name', 'site_ip')
Ejemplo n.º 12
0
class AddDirectoryForm(forms.Form):
    # your_name = forms.CharField(label='Your name', max_length=100)
    # date_added = forms.DateTimeField('date added')
    edit_id = forms.IntegerField(initial=0, widget=forms.HiddenInput())
    name = forms.CharField(max_length=100)
    location = forms.CharField(max_length=50, widget=forms.HiddenInput(), required=False)
    backup_type = forms.CharField(max_length=50, widget=forms.HiddenInput(), required=False)
    path = forms.CharField(max_length=200)
    remote_url = forms.GenericIPAddressField(max_length=200, required=False)
    remote_port = forms.IntegerField(initial=22)
    remote_user = forms.CharField(max_length=100, required=False)
    remote_pass = forms.CharField(max_length=100, required=False, widget=forms.PasswordInput(render_value=True))
    exclude_dirs = forms.CharField(max_length=5000, widget=forms.Textarea, required=False)

    def __init__(self, item_id=None, *args, **kwargs):
        super().__init__(*args, **kwargs)
        if item_id is not None:
            db_dir = Directories.objects.filter(id=item_id)
            if len(db_dir) >= 1:
                db_dir = db_dir[0]
                self.fields['edit_id'].initial = item_id
                self.fields['name'].initial = db_dir.name
                self.fields['location'].initial = db_dir.location
                self.fields['path'].initial = db_dir.path
                self.fields['remote_url'].initial = db_dir.remote_url
                self.fields['remote_port'].initial = db_dir.remote_port
                self.fields['remote_user'].initial = db_dir.remote_user
                self.fields['remote_pass'].initial = db_dir.remote_pass
                excluded = '\r\n'.join(db_dir.exclude_dirs.split(','))
                self.fields['exclude_dirs'].initial = excluded