Exemplo n.º 1
0
    def create_dynamic_dns_group(self, form, ctx):
        txt = self.nc_uitexts
        g = formalutils.CollapsibleGroup('ddns_group', label=txt.ddns_group_caption)
        g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseDynamicDns))
        # XXX: provider is required, but 'none' option is 'disabled'
        g.add(formalutils.Field('ddns_provider', formal.String(required=True),
                                formal.widgetFactory(formal.SelectChoice, options=txt.ddns_providers),
                                label=txt.ddns_providers_label))
        g.add(formalutils.Field('ddns_username', formal.String(required=False), label=txt.ddns_username_label))
        g.add(formalutils.Field('ddns_password', formal.String(required=False),
                                formal.widgetFactory(formalutils.SemiHiddenPassword),
                                label=txt.ddns_password_label))
        g.add(formalutils.Field('ddns_hostname', formal.String(required=False), label=txt.ddns_hostname_label))

        ddns_address_options = [
            ('interface', 'Use Internet connection IP address'),
            ('natted', 'Use NATted Internet connection IP address'),
            ('static', 'Use the following IP address'),
            ]
        g.add(formalutils.Field('ddns_address_type', formal.String(required=False),
                                formal.widgetFactory(formal.RadioChoice, options=ddns_address_options),
                                label='IP address to update'))

        g.add(formalutils.Field('ddns_address', formal.String(required=False), label='Static IP address'))
        return g
Exemplo n.º 2
0
    def form_addNAT(self, data):
        form = formal.Form()

        ifs = []
        for i in Utils.getInterfaces():
            if i[:3] in ['eth', 'ppp', 'tap', 'tun']: # Only allow tap and eth binds...
                ifs.append((i, i))

        form.addField('dstif', formal.String(required=True), formal.widgetFactory(formal.SelectChoice, options = ifs), label = "External Interface",
            description = "The interface to which this traffic will be NATed.")

        form.addField('srcif', formal.String(), formal.widgetFactory(formal.SelectChoice, options = ifs), label = "Source Interface",
            description = "The interface which will have NAT applied to it")

        form.addField('destip', formal.String(), label = "Destination IP", description = ["Destination IP or network (Leave blank for ANY). ", 
        "This is the destination network you would like to NAT to"])

        form.addField('srcip', formal.String(), label = "Source IP", description = ["Source IP or network (Leave blank for ANY). ", 
        "This is the source network you would like to NAT from."])

        form.addField('natip', formal.String(), label = "NAT IP", description = ["The IP address that you would like to NAT the connections as.",
            "Leave this blank to let the firewall decide based on the interface configuration."])

        form.addField('proto', formal.String(), formal.widgetFactory(formal.SelectChoice, options = self.protocols), 
            label = "Protocol", description = "Protocol to NAT")
        form.addField('srcport', formal.String(strip=True, validators=[PageHelpers.PortRangeValidator()]), label = "Source port", description = "TCP/UDP port to NAT.")

        form.addAction(self.submitNAT)

        return form
Exemplo n.º 3
0
Arquivo: UPS.py Projeto: calston/tums
    def form_addUps(self, data):

        ports = self.getSers()

        drivers = [('apcsmart', 'APC'), ('belkin', 'Belkin'),
                   ('belkinunv', 'Belkin Universal UPS'),
                   ('mge-shut', 'MGE Ellipse/Esprit'),
                   ('newmge-shut', 'MGE Ellipse/Esprit V2'),
                   ('mge-utalk', 'MGE Pulsar E/Comet'),
                   ('powercom', 'Powercom')]

        form = formal.Form()
        form.addField('name', formal.String(required=True), label="Name")
        form.addField('desc',
                      formal.String(required=True),
                      label="Description")
        form.addField('driver',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=drivers),
                      label="Driver")
        form.addField('port',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice, options=ports),
                      label="Port")
        form.addAction(self.submitForm)
        return form
Exemplo n.º 4
0
 def gotResolved(res):
     form = formal.Form()
     addr = []
     for address in entries:
         if address[0] in res:
             nam = (address[1], res[address[0]])
         else:
             nam = (address[1], address[0])
         addr.append((address[1], "%s(%s)" % nam))
     userWidgetFactory = formal.widgetFactory(formal.SelectChoice,
                                              options=self.getUsers())
     addressWidgetFactory = formal.widgetFactory(formal.SelectChoice,
                                                 options=addr)
     form.addField('userSelect',
                   formal.String(),
                   userWidgetFactory,
                   label="User")
     form.addField('user', formal.String(), label="")
     form.addField('addrSelect',
                   formal.String(),
                   addressWidgetFactory,
                   label="Network Address")
     form.addField('addr', formal.String(), label="")
     form.addAction(handleSubmit)
     return form
Exemplo n.º 5
0
    def form_itemSelection(self, ctx):

        # Get the element id of the field to update from the request params.
        # We'll store it in a hidden field for the POST to use.
        elementId = ctx.arg("element_id")

        # Set up the form
        f = forms.Form(self._submit)

        f.addField('type', forms.String(), forms.widgetFactory(forms.SelectChoice, noneOption=None, options=self.data_types))
        f.addField('name', forms.String())
        f.addField('categories', forms.Sequence(forms.Integer()), forms.widgetFactory(categorieswidget.CheckboxTreeMultichoice))
        f.addField('maxPublishedAge', forms.Integer())
        f.addField('maxItems', forms.Integer())
        f.addField('paging', forms.Integer(), label="Items per page")
        f.addField('template', forms.String(), forms.widgetFactory(forms.SelectChoice, noneOption=None, options=[]))
        f.addField('elementId', forms.String(), widgetFactory=forms.Hidden)

        f.addAction(self._submit)
        # If we have a value request parameter then decode it and set the
        # form's initial values.
        value = inevow.IRequest(ctx).args.get('value', [None])[0]
        f.data = {"elementId": elementId}
        if value is not None:
            itemsel = ItemSelection.fromString(value)
            f.data['type'] = itemsel.type
            f.data['name'] = itemsel.name
            f.data['categories'] = itemsel.categories
            f.data['maxPublishedAge'] = itemsel.maxPublishedAge
            f.data['maxItems'] = itemsel.maxItems
            f.data['template'] = itemsel.template
            f.data['paging'] = itemsel.paging
        return f
Exemplo n.º 6
0
    def form_source(self, data):
        form = formal.Form()
        zones = []

        # Read zones available for balancing
        i = 1
        for bal in self.sysconf.ShorewallBalance:
            zones.append((i, bal[0]))
            i+= 1

        protocols = [
            ('-', 'Any'),
            ('tcp', 'TCP'),
            ('udp', 'UDP'),
            ('47', 'PPTP'),
            ('icmp', 'ICMP')
        ]

        form.addField('zone', formal.Integer(required=True), formal.widgetFactory(formal.SelectChoice, options = zones), 
            label = "Destination Zone",
            description = "Route packets matching this rule to this zone")

        form.addField('source', formal.String(), label = "Source", description = "Source CIDR network or IP. For anywhere leave blank.")

        form.addField('dest',   formal.String(), label = "Destination", description = "Destination CIDR network or IP. For anywhere leave blank.")

        form.addField('protocol', formal.String(required=True),formal.widgetFactory(formal.SelectChoice, options = protocols), label = "Protocol")
        form.addField('port', formal.String(), label = "Port", description = "TCP/UDP port, or sub-protocol type. Leave blank for a source-only policy")

        form.addAction(self.submitSource)
        return form
Exemplo n.º 7
0
 def form_changepassword(self, ctx):
     form = formal.Form()
     g = formalutils.CollapsibleGroup('changepassword',
                                      label='Change Password')
     g.setCollapsed(False)
     g.add(
         formal.Field('pw1',
                      formal.String(required=True),
                      formal.widgetFactory(formalutils.HiddenPassword),
                      label='Old password'))
     g.add(
         formal.Field('pw2',
                      formal.String(required=True),
                      formal.widgetFactory(formalutils.HiddenPassword),
                      label='New password'))
     g.add(
         formal.Field('pw3',
                      formal.String(required=True),
                      formal.widgetFactory(formalutils.HiddenPassword),
                      label='New password (again)'))
     sg = formalutils.SubmitFieldGroup('buttons')
     sg.add(
         formalutils.SubmitField('changepassword',
                                 formal.String(),
                                 label='Change password'))
     g.add(sg)
     form.add(g)
     form.addAction(self.submitted, name='changepassword', validate=False)
     return form
Exemplo n.º 8
0
    def form_parp(self, data):
        form = formal.Form()

        ifs = []
        for i in Utils.getInterfaces():
            if 'eth' in i or 'tap' in i:  # Only allow tap and eth binds...
                ifs.append((i, i))

        form.addField('ip',
                      formal.String(required=True,
                                    strip=True,
                                    validators=[PageHelpers.IPValidator()]),
                      label="IP Address")

        form.addField(
            'extif',
            formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice, options=ifs),
            label="External Interface",
            description=
            "The interface where this server will advertise availability of this IP address"
        )

        form.addField(
            'intif',
            formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice, options=ifs),
            label="Internal Interface",
            description=
            "The interface to which this IP address will be routed (Where the server binding this IP address is)"
        )

        form.addAction(self.submitProxyARP)
        return form
Exemplo n.º 9
0
    def addForm(self, form):
        acls = []

        for ip, i in self.sysconf.ProxyConfig.get('srcacls', []):
            if (not i in acls):
                acls.append((i, i))

        for n, i in self.sysconf.ProxyConfig.get('aclusers', []):
            if (not i in acls):
                acls.append((i, i))

        for n, i in self.sysconf.ProxyConfig.get('domacls', []):
            if (not i in acls):
                acls.append((i, i))

        for i in self.sysconf.ProxyConfig.get('adacls', []):
            if (not i[2] in acls):
                acls.append((i[2], i[2]))

        form.addField('acl',
                      formal.Sequence(formal.String()),
                      formal.widgetFactory(formal.CheckboxMultiChoice,
                                           options=acls),
                      label="ACLs",
                      description="Select the ACL(s) to apply this rule to"),

        #form.addField('acl', formal.String(required=True), label = "ACL Name")
        form.addField('perms',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=[('deny', 'deny'),
                                                    ('allow', 'allow')]),
                      label="Permission")

        form.data['perms'] = 'deny'
Exemplo n.º 10
0
    def form_allowPort(self, data):
        form = formal.Form()
        form.addField('destport',
                      formal.String(required=True),
                      label="Destination Port",
                      description="TCP/UDP port to permit")
        form.addField(
            'destip',
            formal.String(),
            label="Destination IP",
            description=
            "Destination IP address or network (Leave blank for ANY)")
        form.addField('proto',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=self.protocols),
                      label="Protocol")
        form.data['proto'] = 'tcp'
        form.addField('zone',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=self.getZones()),
                      label="Zone")
        form.data['zone'] = "net"
        form.addAction(self.submitAllowPort)

        return form
Exemplo n.º 11
0
    def form_addDrive(self, data):
        form = formal.Form()

        # Make a list of drive letters F - Z
        AvailLetters = [chr(i) for i in range(70,91)]
        # Remove letters that are used already
        for letter in [i[1] for i in self.getMaps()]:
            del AvailLetters[AvailLetters.index(letter)]

        # Get groups on system
        l = LDAP.createLDAPConnection(Settings.LDAPServer, 'o='+Settings.LDAPBase, Settings.LDAPManager, Settings.LDAPPass)
        dc = "%s,o=%s" % (LDAP.domainToDC(Settings.defaultDomain), Settings.LDAPBase)

        groups = LDAP.getGroups(l, dc)
        groups.sort()

        form.addField('sharepath', formal.String(required=True), label = "Share Path", 
            description = "Network path to the share, for example \\\\tcs\\Public\\")
            
        form.addField('loginGroup', formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice, options = [(i[1],i[1]) for i in groups]), label = "Login Group", 
            description = "Requred login group for this network drive")

        form.addField('driveletter', formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice, options = [(i,i) for i in AvailLetters]), label = "Drive Letter")

        form.data['driveletter'] = AvailLetters[0]
        form.data['loginGroup']  = "Domain Users"

        form.addAction(self.submitDriveForm)
        return form
Exemplo n.º 12
0
 def create_source_routing_group(self, form, ctx):
     txt = self.route_uitexts
     g = formalutils.CollapsibleGroup('sr_group',
                                      label=txt.source_routing_caption)
     g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseSourceRouting))
     g.add(
         formalutils.Field('source_routing_selection',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.RadioChoice,
                               options=txt.source_routing_select_options),
                           label=txt.source_routing_select_label))
     g.add(
         formalutils.Field('network_connection',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.SelectChoice,
                               options=txt.routing_nw_options),
                           label=txt.routing_nw_label))
     g.add(
         formalutils.Field('gateway_selection',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.RadioChoice,
                               options=txt.routing_gw_select_options),
                           label=txt.routing_gw_select_label))
     g.add(
         formalutils.Field('gateway',
                           dt.FormIPv4Address(required=False),
                           label=txt.routing_gw_label))
     return g
Exemplo n.º 13
0
 def _create_fwrule_list_entry(index):
     g = formalutils.CollapsibleGroup(str(index), label='')
     g.setCollapsed(collapsed=False)
     g.add(
         formalutils.Field('ip_subnet',
                           dt.FormIPv4Subnet(required=True),
                           label='IP address or subnet'))
     g.add(
         formalutils.Field('protocol',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.SelectChoice,
                               options=txt.fw_protocol_select_options),
                           label='Protocol'))
     g.add(
         formalutils.Field(
             'port',
             formal.Integer(
                 required=False,
                 validators=[formal.RangeValidator(min=0, max=65535)]),
             label='Port'))
     g.add(
         formalutils.Field('action',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.SelectChoice,
                               options=txt.fw_protocol_action_options),
                           label='Action'))
     return g
Exemplo n.º 14
0
 def _create_route_list_entry(index):
     g = formalutils.CollapsibleGroup(str(index), label='')
     g.setCollapsed(False)
     g.add(
         formalutils.Field('subnet',
                           dt.FormIPv4Subnet(required=True),
                           label=txt.routing_subnet))
     g.add(
         formalutils.Field('network_connection',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.SelectChoice,
                               options=txt.routing_nw_options),
                           label=txt.routing_nw_label))
     g.add(
         formalutils.Field('gateway_selection',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.RadioChoice,
                               options=txt.routing_gw_select_options),
                           label=txt.routing_gw_select_label))
     g.add(
         formalutils.Field('gateway',
                           dt.FormIPv4Address(required=False),
                           label=txt.routing_gw_label))
     return g
Exemplo n.º 15
0
    def form_dateRange(self, ctx):
        form = formal.Form()

        months = [(m + 1, Utils.months[m + 1]) for m in range(12)]
        days = [(0, 'Whole Month')] + [(m + 1, m + 1) for m in range(31)]
        yearLim = datetime.datetime.now().year
        years = [(y, y) for y in reversed(range(yearLim - 3, yearLim + 1))]

        form.addField('day',
                      formal.Integer(),
                      formal.widgetFactory(formal.SelectChoice, options=days),
                      label="Day")

        form.addField('month',
                      formal.Integer(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=months),
                      label="Month")

        form.addField('year',
                      formal.Integer(required=True),
                      formal.widgetFactory(formal.SelectChoice, options=years),
                      label="Year")

        form.data['month'] = self.month
        form.data['day'] = self.day
        form.data['year'] = self.year

        form.addAction(self.selectDate)
        return form
Exemplo n.º 16
0
    def form_forwardPort(self, data):
        form = formal.Form()
        form.addField(
            'szone',
            formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice, options=self.getZones()),
            label="Source Zone",
            description="Source zone from which this rule will catch packets. "
        )

        form.addField(
            'dzone',
            formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice, options=self.getZones()),
            label="Destination Zone",
            description=
            "Destination Zone to which this rule will forward packets.")

        form.addField(
            'port',
            formal.String(strip=True,
                          validators=[PageHelpers.PortRangeValidator()]),
            label="Port",
            description=
            "TCP/UDP port to forward. Blank for protocol forward (like PPTP). Use separate ranges with a colon."
        )
        form.addField('destip',
                      formal.String(required=True,
                                    strip=True,
                                    validators=[PageHelpers.IPValidator()]),
                      label="Forward To",
                      description="Destination IP address to forward to")
        form.addField(
            'dstport',
            formal.String(strip=True,
                          validators=[PageHelpers.PortValidator()]),
            label="Forward To:Port",
            description="TCP/UDP port to forward to. Blank for the same port.")
        form.addField('sourceip',
                      formal.String(strip=True,
                                    validators=[PageHelpers.IPValidator()]),
                      label="Destination IP",
                      description="External IP to forward from")
        form.addField('source',
                      formal.String(strip=True,
                                    validators=[PageHelpers.IPValidator()]),
                      label="Source IP",
                      description="External IP to accept connections from")
        form.addField('proto',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=self.protocols),
                      label="Protocol")
        form.data['proto'] = 'tcp'
        form.data['szone'] = 'net'
        form.data['dzone'] = 'loc'
        form.addAction(self.submitForwardPort)
        return form
Exemplo n.º 17
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('isoFormatDate', formal.Date(), formal.TextInput)
     form.addField('monthFirstDate', formal.Date(), formal.DatePartsInput)
     form.addField('dayFirstDate', formal.Date(), formal.widgetFactory(formal.DatePartsInput, dayFirst=True))
     form.addField('monthYearDate', formal.Date(), formal.MMYYDatePartsInput)
     form.addField('twoCharYearDate', formal.Date(), formal.widgetFactory(formal.DatePartsInput, twoCharCutoffYear=70))
     form.addField('time', formal.Time())
     form.addAction(self.submitted)
     return form
Exemplo n.º 18
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('RichTextString', formal.RichTextType(required=True),
             widgetFactory = formal.widgetFactory(formal.RichTextArea, parsers=[('plain','Plain Text'),('reverseplain','Reversed Plain Text')]))
     form.addField('RichTextStringNotRequired', formal.RichTextType(),
             widgetFactory = formal.widgetFactory(formal.RichTextArea, parsers=[('plain','Plain Text'),('reverseplain','Reversed Plain Text'),('html','XHTML')]))
     form.addField('RichTextStringOnlyOneParser', formal.RichTextType(required=True),
             widgetFactory = formal.widgetFactory(formal.RichTextArea, parsers=[('markdown','MarkDown')]))
     form.addAction(self.submitted)
     return form
Exemplo n.º 19
0
 def create_client_connection_group():
     cc_group = formalutils.CollapsibleGroup('client_connection',
                                             label=txt.cc_group_caption)
     cc_group.setCollapsed(
         uihelpers.collapse_setting(ns_ui.collapseClientConnection))
     #cc_group.add(formalutils.Field('server_name', formal.String(required=False), label=txt.server_address_label))
     cc_group.add(
         formalutils.Field('psk_1',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formalutils.SemiHiddenPassword),
                           label='Primary pre-shared key'))
     cc_group.add(
         formalutils.Field('psk_2',
                           formal.String(required=False),
                           formal.widgetFactory(
                               formalutils.SemiHiddenPassword),
                           label='Secondary pre-shared key'))
     cc_group.add(
         formalutils.Field('dns',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.RadioChoice,
                               options=txt.client_dns_options),
                           label=txt.client_dns_options_label))
     cc_group.add(
         formalutils.Field('dns_1',
                           dt.FormIPv4Address(required=False),
                           label=txt.primary_dns_label))
     cc_group.add(
         formalutils.Field('dns_2',
                           dt.FormIPv4Address(required=False),
                           label=txt.secondary_dns_label))
     cc_group.add(
         formalutils.Field('wins_1',
                           dt.FormIPv4Address(required=False),
                           label=txt.primary_wins_label))
     cc_group.add(
         formalutils.Field('wins_2',
                           dt.FormIPv4Address(required=False),
                           label=txt.secondary_wins_label))
     cc_group.add(
         formalutils.Field('client_subnet',
                           dt.FormIPv4Subnet(required=True),
                           label=txt.client_subnet_label))
     cc_group.add(
         formalutils.Field('client_address_range',
                           dt.FormIPv4AddressRange(required=True),
                           label=txt.client_address_range_label))
     cc_group.add(
         formalutils.Field('client_compression',
                           formal.Boolean(required=True),
                           label='VPN client traffic compression'))
     return cc_group
Exemplo n.º 20
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('isoFormatDate', formal.Date(), formal.TextInput)
     form.addField('datePartsSelect', formal.Date(), formal.widgetFactory(formal.DatePartsSelect, dayFirst=True))
     form.addField('monthFirstDate', formal.Date(), formal.DatePartsInput)
     form.addField('dayFirstDate', formal.Date(), formal.widgetFactory(formal.DatePartsInput, dayFirst=True))
     form.addField('monthYearDate', formal.Date(), formal.MMYYDatePartsInput)
     form.addField('twoCharYearDate', formal.Date(), formal.widgetFactory(formal.DatePartsInput, twoCharCutoffYear=70))
     form.addField('time', formal.Time())
     form.addAction(self.submitted)
     return form
Exemplo n.º 21
0
 def _create_fwrule_list_entry(index):
     g = formalutils.CollapsibleGroup(str(index), label='')
     g.setCollapsed(collapsed=False)
     g.add(formalutils.Field('ip_subnet', dt.FormIPv4Subnet(required=True), label='IP address or subnet'))
     g.add(formalutils.Field('protocol', formal.String(required=True),
                             formal.widgetFactory(formal.SelectChoice, options=txt.fw_protocol_select_options),
                             label='Protocol'))
     g.add(formalutils.Field('port', formal.Integer(required=False, validators=[formal.RangeValidator(min=0, max=65535)]), label='Port'))
     g.add(formalutils.Field('action', formal.String(required=True),
                             formal.widgetFactory(formal.SelectChoice, options=txt.fw_protocol_action_options),
                             label='Action'))
     return g
Exemplo n.º 22
0
 def _create_route_list_entry(index):
     g = formalutils.CollapsibleGroup(str(index), label='')
     g.setCollapsed(False)
     g.add(formalutils.Field('subnet', dt.FormIPv4Subnet(required=True), label=txt.routing_subnet))
     g.add(formalutils.Field('network_connection', formal.String(required=True),
                             formal.widgetFactory(formal.SelectChoice, options=txt.routing_nw_options),
                             label=txt.routing_nw_label))
     g.add(formalutils.Field('gateway_selection', formal.String(required=True),
                             formal.widgetFactory(formal.RadioChoice, options=txt.routing_gw_select_options),
                             label=txt.routing_gw_select_label))
     g.add(formalutils.Field('gateway', dt.FormIPv4Address(required=False), label=txt.routing_gw_label))
     return g
Exemplo n.º 23
0
 def create_internet_connection_group(self, form, ctx):
     txt = self.nc_uitexts
     g = formalutils.CollapsibleGroup('ic_group',
                                      label=txt.ic_group_caption)
     g.setCollapsed(
         uihelpers.collapse_setting(ns_ui.collapseInternetConnection))
     g.add(
         formalutils.Field('if',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.SelectChoice,
                               options=uihelpers.interface_options()),
                           label=txt.if_label))
     g.add(
         formalutils.Field('ip_address_selection',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.RadioChoice,
                               options=txt.ip_selection_options),
                           label=txt.ip_selection_label))
     g.add(
         formalutils.Field('ip_address',
                           dt.FormIPv4AddressSubnet(required=False),
                           label=txt.ip_label))
     g.add(
         formalutils.Field('subnet_mask',
                           dt.FormSubnetMask(required=False),
                           label=txt.subnet_label))
     g.add(
         formalutils.Field('default_gateway',
                           dt.FormIPv4Address(required=False),
                           label=txt.default_gw_label))
     g.add(
         formalutils.Field(
             'mtu',
             formal.Integer(
                 required=True,
                 validators=[formal.RangeValidator(min=576, max=1500)]),
             label=txt.mtu_label))
     g.add(
         formalutils.Field(
             'uplink',
             dt.FormFloat(required=False,
                          validators=[formal.RangeValidator(min=0.128)]),
             label=txt.uplink_label))
     g.add(
         formalutils.Field('client_traffic',
                           formal.String(required=True),
                           formal.widgetFactory(
                               formal.RadioChoice,
                               options=txt.client_traffic_options),
                           label=txt.client_traffic_label))
     return g
Exemplo n.º 24
0
 def create_default_route_group(self, form, ctx):
     txt = self.route_uitexts
     g = formalutils.CollapsibleGroup('dr_group', label=txt.default_route_caption)
     g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseDefaultRoute))
     g.add(formalutils.Field('network_connection', formal.String(required=True),
                             formal.widgetFactory(formal.SelectChoice, options=txt.routing_nw_options),
                             label=txt.routing_nw_label))
     g.add(formalutils.Field('gateway_selection', formal.String(required=True),
                             formal.widgetFactory(formal.RadioChoice, options=txt.routing_gw_select_options),
                             label=txt.routing_gw_select_label))
     g.add(formalutils.Field('gateway', dt.FormIPv4Address(required=False), label=txt.routing_gw_label))
     return g
Exemplo n.º 25
0
Arquivo: Ppp.py Projeto: calston/tums
    def addForm(self, form):
        form.addField('link',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=[
                                               (i, i)
                                               for i in self.getEthernets()
                                           ]),
                      label="Ethernet Link")

        form.addField('username',
                      formal.String(required=True),
                      label="Username")
        form.addField('password',
                      formal.String(required=True),
                      label="Password")

        form.addField(
            'localOnly',
            formal.Boolean(),
            label="Local Only",
            description=
            "Checking this box will cause only South African traffic to be routed over this link"
        )
        form.addField('defaultRoute',
                      formal.Boolean(),
                      label="Default Routes",
                      description="Make this the default internet connection")
        form.addField(
            'defaultDNS',
            formal.Boolean(),
            label="Default DNS",
            description="Use the DNS servers that this connection provides")
        form.addField(
            'createNAT',
            formal.Boolean(),
            label="Default NAT",
            description="Ensure there is a default NAT rule for this connection"
        )

        form.addField('zone',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=self.getZones()),
                      label="Firewall Zone")

        form.data['createNAT'] = True
        form.data['link'] = 'eth0'
        form.data['defaultRoute'] = True
Exemplo n.º 26
0
    def form_transProxy(self, data):
        form = formal.Form()

        form.addField(
            'zone',
            formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice, options=self.getZones()),
            label="Source Zone",
            description="Source zone from which this rule will catch traffic")

        form.addField(
            'sourceip',
            formal.String(),
            label="Source IP",
            description=[
                "Source IP address of connecting host or network (Leave blank for ANY)."
                " This is usually a source host or network you want to exclude."
            ])

        form.addField(
            'destip',
            formal.String(),
            label="Destination IP",
            description=[
                "Destination IP address or network (Leave blank for ANY). ",
                "This is usually the opposite (!) of your local network.",
                "This is NOT the server you'd like to proxy to."
            ])
        form.addField('srcport',
                      formal.String(strip=True,
                                    validators=[PageHelpers.PortValidator()]),
                      label="Source port",
                      description="TCP/UDP port to catch.")
        form.addField('dstport',
                      formal.String(strip=True,
                                    validators=[PageHelpers.PortValidator()]),
                      label="Destination port",
                      description="TCP/UDP port to forward to.")
        form.addField('proto',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=self.protocols),
                      label="Protocol")
        form.data['proto'] = 'tcp'
        form.data['szone'] = 'loc'
        form.addAction(self.submitTransProxy)

        return form
Exemplo n.º 27
0
    def form_addVLAN(self, data):
        form = formal.Form()

        form.addField('interface',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=[
                                               (i, i.replace('eth', 'Port '))
                                               for i in Utils.getInterfaces()
                                               if not i == "lo"
                                           ]),
                      label="Attached Interface")

        form.addField('vlan', formal.Integer(), label="VLAN Number")
        form.addField('ip', formal.String(), label="IP Address")
        form.addField('netmask',
                      formal.String(),
                      label="Netmask",
                      description="Netmask or CIDR bitmask for this range")
        form.addField('dhcpserver',
                      formal.Boolean(),
                      label="DHCP Server",
                      description="Serve DHCP on this interface")
        form.addAction(self.submitVlan)
        return form
Exemplo n.º 28
0
    def form_example(self, ctx):
        form = formal.Form()
        form.addField('myTextArea', formal.String(),
               formal.widgetFactory(TextAreaWithSelect,values=(('aval','alabel'),('bval','blabel'))  ))

        form.addAction(self.submitted)
        return form
Exemplo n.º 29
0
    def addForm(self, form):
        acls = []

        for ip, i in self.sysconf.ProxyConfig.get('srcacls', []):
            if (not i in acls):
                acls.append((i, i))

        for n, i in self.sysconf.ProxyConfig.get('aclusers', []):
            if (not i in acls):
                acls.append((i, i))

        for n, i in self.sysconf.ProxyConfig.get('domacls', []):
            if (not i in acls):
                acls.append((i, i))

        for i in self.sysconf.ProxyConfig.get('adacls', []):
            if (not i[2] in acls):
                acls.append((i[2], i[2]))

        form.addField('acl',
                      formal.String(),
                      formal.widgetFactory(formal.SelectChoice, options=acls),
                      label="ACL Name",
                      description="Select the ACL to apply this rule to"),

        #form.addField('acl', formal.String(required=True), label = "ACL Name")
        form.addField(
            'gateway',
            formal.String(required=True),
            label="Bind IP",
            description="Local internet IP address to bind for this ACL")
Exemplo n.º 30
0
    def form_addShare(self, data):
        form = formal.Form()

        form.addField('share',
                      formal.String(required=True),
                      label="Shared Folder")
        form.addField('path',
                      formal.String(required=True),
                      label="Shared Path",
                      description="Path to be shared")
        form.addField('comment', formal.String(required=True), label="Comment")

        form.addField('public', formal.Boolean(), label="Public")
        form.addField('writable', formal.Boolean(), label="Writable")

        l = LDAP.createLDAPConnection(Settings.LDAPServer,
                                      'o=' + Settings.LDAPBase,
                                      Settings.LDAPManager, Settings.LDAPPass)
        dc = "%s,o=%s" % (LDAP.domainToDC(
            Settings.defaultDomain), Settings.LDAPBase)

        groups = LDAP.getGroups(l, dc)
        groups.sort()

        form.addField('group',
                      formal.String(),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=[(i[1], i[1])
                                                    for i in groups]),
                      label="Required Group")

        form.addAction(self.submitForm)

        return form
Exemplo n.º 31
0
    def form_addTime(self, data):
        acls = []

        for ip, i in self.sysconf.ProxyConfig.get('srcacls', []):
            acls.append((i,i))

        for n, i in self.sysconf.ProxyConfig.get('aclusers', []):
            acls.append((i,i))

        for n, i in self.sysconf.ProxyConfig.get('domacls', []):
            acls.append((i,i))

        form = formal.Form(self.submitTime)[        
            formal.Field('allow', formal.Boolean(), label = "Allow",
                description = "Allow traffic at these times"),
            formal.Field('from', formal.Time(required=True), label = "From time", 
                description = "Starting time (24 hour format)"),
            formal.Field('to', formal.Time(required=True), label = "To time", 
                description = "Ending time (24 hour format), must be later than the starting time and must not overlap midnight"),

            formal.Field('domain', formal.String(), label = "Domain", 
                description = "Apply this rule to a specific domain"), 

            formal.Field('exacl', formal.String(), formal.widgetFactory(formal.SelectChoice, options = acls), label = "Extra ACL", 
                description = "Apply this rule to a specific other ACL"),
            
            formal.Group('Days')[
                [ formal.Field(i, formal.Boolean(), label = i) for i in PageHelpers.days ]
            ]
        ]
        form.data['from'] = datetime.time(0,0)
        form.data['to'] = datetime.time(23,59)
        form.addAction(self.submitTime)
        return form
Exemplo n.º 32
0
Arquivo: DNS.py Projeto: calston/tums
    def form_addRecord(self, data):
        recordTypes = ["CNAME", "A", "AAAA", "NS", "MX"]

        form = formal.Form()

        form.addField('type',
                      formal.String(required=True),
                      formal.widgetFactory(formal.SelectChoice,
                                           options=[(i, i)
                                                    for i in recordTypes]),
                      label="Type")
        form.addField(
            'host',
            formal.String(),
            label="Host",
            description="Hostname or blank for a record in the base FQDN")
        form.addField('data',
                      formal.String(),
                      label="Data",
                      description="Content of the record")
        form.addField('prio',
                      formal.Integer(),
                      label="Priority",
                      description="Priority of MX record")

        form.addAction(self.submitRecForm)
        return form
Exemplo n.º 33
0
def addFields(form, forCreate = False):

    if forCreate:
        codeField = formal.String(required=True, strip=True)
        countField = formal.Integer()
        multiuseField = formal.Boolean()
    else:
        codeField = formal.String(immutable=True)
        countField = formal.Integer(immutable=True)
        multiuseField = formal.Boolean(immutable=True)

    form.add( formal.Field('code', codeField) )

    form.add( formal.Field('categories', formal.Sequence(formal.String()), 
        widgetFactory=categorieswidget.FormalCheckboxTreeMultichoice ) )

    form.add( formal.Field('count', countField) )
    form.add( formal.Field('multiuse', multiuseField) )
    form.add( formal.Field('start_date', formal.Date()) )
    form.add( formal.Field('end_date', formal.Date()) )
    form.add( formal.Field('amount', formal.String(strip=True), description="Either an amount or a '%'") )

    form.add( formal.Field('mForN', formal.Sequence(formal.Integer), 
        widgetFactory=formal.widgetFactory(nfields.NFieldWidget, 2, ['for'])))

    return form
Exemplo n.º 34
0
    def form_confZone(self, data):
        form = formal.Form()

        form.addField(
            'policy',
            formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice,
                                 options=[('ACCEPT', 'ACCEPT'),
                                          ('DROP', 'DROP')]),
            label="Policy",
            description=
            "The default action to take on traffic not matching any rule")

        form.addField(
            'log',
            formal.String(),
            label="Log",
            description=
            "Advanced: Logging target for dropped packets. Usualy $log if policy is ACCEPT"
        )

        form.addAction(self.confZone)

        k = self.sysconf.Shorewall
        zdef = k.get('zones', {}).get(self.zone)
        form.data['log'] = zdef.get('log', '')
        form.data['policy'] = zdef.get('policy', '')

        return form
Exemplo n.º 35
0
    def form_statroutes(self, data):
        form = formal.Form()

        form.addField(
            'dest',
            formal.String(required=True,
                          strip=True,
                          validators=[PageHelpers.IPMaskValidator()]),
            label="Destination network",
            description=
            "Destination network in CIDR or '0.0.0.0/0' for the default route."
        )
        form.addField('gate',
                      formal.String(validators=[PageHelpers.IPValidator()]),
                      label="Gateway",
                      description="Gateway to forward this network to")

        ifs = []
        for i in Utils.getInterfaces():
            if 'eth' or 'ppp':  # Only allow ppp and eth binds...
                ifs.append((i, i))

        form.addField(
            'device',
            formal.String(),
            formal.widgetFactory(formal.SelectChoice, options=ifs),
            label="Device",
            description=
            "Device to forward this traffic to, or the interface to assign this route to"
        )

        form.addAction(self.submitRoute)

        return form
Exemplo n.º 36
0
 def _create_user_list_entry(self, index):
     g = formalutils.CollapsibleGroup(str(index), label='')
     g.setCollapsed(False)
     g.add(
         formalutils.Field('username',
                           formal.String(required=True),
                           label='Username'))
     g.add(
         formalutils.Field('password',
                           formal.String(required=False),
                           formal.widgetFactory(
                               formalutils.SemiHiddenPassword),
                           label='Set password'))
     g.add(
         formalutils.Field('fixed_ip',
                           dt.FormIPv4Address(required=False),
                           label='Fixed IP address'))
     g.add(
         formalutils.Field('admin_rights',
                           formal.Boolean(required=True),
                           label='Allow VPNease administration'))
     g.add(
         formalutils.Field('vpn_rights',
                           formal.Boolean(required=True),
                           label='Allow VPN access'))
     return g
Exemplo n.º 37
0
    def form_addZone(self, data):
        form = formal.Form()

        form.addField('zone',
                      formal.String(required=True),
                      label="Zone name",
                      description="The name of this zone")

        form.addField(
            'policy',
            formal.String(required=True),
            formal.widgetFactory(formal.SelectChoice,
                                 options=[('ACCEPT', 'ACCEPT'),
                                          ('DROP', 'DROP')]),
            label="Policy",
            description=
            "The default action to take on traffic not matching any rule")

        form.addField(
            'log',
            formal.String(),
            label="Log",
            description=
            "Advanced: Logging target for dropped packets. Usualy $log if policy is ACCEPT"
        )

        #form.addField('interfaces', formal.String(), label = "Interface members", description = "Advanced: Comma separated list of interface defenitions.")

        form.data['policy'] = "ACCEPT"

        form.addAction(self.submitZone)

        return form
Exemplo n.º 38
0
    def form_addSNAT(self, data):
        form = formal.Form()

        ifs = []
        for i in Utils.getInterfaces():
            if 'eth' in i or 'tap' in i: # Only allow tap and eth binds...
                ifs.append((i, i))

        form.addField('dstif', formal.String(required=True), formal.widgetFactory(formal.SelectChoice, options = ifs), label = "External Interface",
            description = "The interface to which this traffic will be NATed. (Generaly the outside/internet interface)")

        form.addField('dstip', formal.String(required=True, validators=[PageHelpers.IPValidator()]), label = "External IP",
            description = "The IP to which this traffic will be NATed")

        form.addField('srcip', formal.String(required=True, strip=True, validators=[PageHelpers.IPValidator()]), label = "Source IP", description = ["The source IP you would like to NAT to and from."])

        form.addField('all', formal.Boolean(), label = "Any Interface", 
            description = "Tick this if the rule should apply to all interfaces and not just the External Interface.")

        form.addField('local', formal.Boolean(), label = "Use Internal", description = "Apply this NAT rule to this servers traffic as well.")

        form.data['local'] = False
        form.data['all'] = False

        form.addAction(self.submitSNAT)

        return form
Exemplo n.º 39
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('required', formal.String(required=True))
     form.addField('file', formal.File(), formal.FileUploadWidget)
     form.addField('removeableFile', formal.File(), formal.widgetFactory(formal.FileUploadWidget, removeable=True ) )
                   
     form.addAction(self.submitted)
     return form
Exemplo n.º 40
0
 def create_iface_count_group(self, form, ctx):
     txt = self.nc_uitexts
     g = formalutils.CollapsibleGroup('ifcount_group', label='Network Setup')
     g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseInterfaceCount))
     g.add(formalutils.Field('interface_count', formal.String(required=True),
                             formal.widgetFactory(formal.RadioChoice, options=txt.ifcount_options), 
                             label=txt.ifcount_label))
     return g
Exemplo n.º 41
0
 def create_private_network_group(self, form, ctx):
     txt = self.nc_uitexts
     g = formalutils.CollapsibleGroup('pn_group', label=txt.pn_group_caption)
     g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapsePrivateNetwork))
     g.add(formalutils.Field('if', formal.String(required=False),
                             formal.widgetFactory(formal.SelectChoice, options=uihelpers.interface_options()),
                             label=txt.if_label))
     g.add(formalutils.Field('ip_address_selection', formal.String(required=False),
                             formal.widgetFactory(formal.RadioChoice, options=txt.ip_selection_options),
                             label=txt.ip_selection_label))
     g.add(formalutils.Field('ip_address', dt.FormIPv4AddressSubnet(required=False), label=txt.ip_label))
     g.add(formalutils.Field('subnet_mask', dt.FormSubnetMask(required=False), label=txt.subnet_label))
     g.add(formalutils.Field('default_gateway', dt.FormIPv4Address(required=False), label=txt.default_gw_label))
     g.add(formalutils.Field('client_traffic', formal.String(required=False),
                             formal.widgetFactory(formal.RadioChoice, options=txt.client_traffic_options),
                             label=txt.client_traffic_label))
     return g
Exemplo n.º 42
0
    def form_select_target(self, ctx):
        form = formal.Form()

        g = formalutils.CollapsibleGroup('selecttarget', label='Installation Targets')
        g.setCollapsed(False)
        
        targets = []
        for m in self._get_disks():
            errors = []
            if m.get_size() < constants.DISK_SIZE_MINIMUM:
                errors.append('device too small')
            if m.is_write_protected():
                errors.append('write-protected')
            if errors:
                errorstr = ' [' + (', '.join(errors)) + ']'
            else:
                errorstr = ''
                
            devname = m.get_device()
            devstring = '%s %s (%s) %s' % (m.get_size_pretty(), m.get_human_readable_description(), m.get_device(), errorstr)
            targets.append((devname, devstring))

        def _target_cmp(x, y):
            x_dev, x_info = x
            y_dev, y_info = y
            return unicode.__cmp__(unicode(x_dev), unicode(y_dev))
        targets.sort(cmp=_target_cmp)
            
        # XXX: we can't currently disable individual radiobuttons in Formal.
        # We thus leave them enabled, and check for device size below.  This
        # is unfortunate, but better than not showing small devices at all
        
        lbl = 'Target device'
        g.add(formal.Field('target', formal.String(required=True),
                           formal.widgetFactory(formal.RadioChoice, options=targets),
                           label=lbl))
        g.add(formal.Field('recovery', formal.Boolean(required=False), label='Attempt recovery'))
        
        sg = formalutils.SubmitFieldGroup('buttons')
        sg.add(formalutils.SubmitField('selecttarget', formal.String(), label='Next'))
        sg.add(formalutils.SubmitField('rescan', formal.String(), label='Rescan'))
        sg.add(formalutils.SubmitField('cancel', formal.String(), label='Cancel'))
        g.add(sg)
        
        form.add(g)
        form.addAction(self.submitted_select_target, name='selecttarget', label='Next', validate=False)
        form.addAction(self.submitted_rescan, name='rescan', label='Rescan', validate=False)
        form.addAction(self.submitted_cancel_installation, name='cancel', label='Cancel', validate=False)

        # set previous selection if exists as default value
        cfg = livecddb.get_livecd_database_root()
        if cfg.hasS(ns_ui.targetDevice):
            form.data['selecttarget.target'] = cfg.getS(ns_ui.targetDevice, rdf.String)
        if cfg.hasS(ns_ui.attemptRecovery):
            form.data['selecttarget.recovery'] = cfg.getS(ns_ui.attemptRecovery, rdf.Boolean)
            
        return form
Exemplo n.º 43
0
    def _create_s2s_connection_list_entry(self, index):
        mode_options = [ ('server', 'Respond to a connection from a remote server'),
                         ('client', 'Initiate connection to a remote server') ]

        g = formalutils.CollapsibleGroup(str(index), label='')
        g.setCollapsed(False)
        g.add(formalutils.Field('s2s_username', formal.String(required=True), label='Username'))
        g.add(formalutils.Field('s2s_password', formal.String(required=True),
                                formal.widgetFactory(formalutils.SemiHiddenPassword),
                                label='Password'))
        g.add(formalutils.Field('s2s_subnets', dt.FormIPv4SubnetList(required=True), label='Remote subnets'))
        g.add(formalutils.Field('s2s_mode', formal.String(required=True),
                                formal.widgetFactory(formal.RadioChoice, options=mode_options),
                                label='Connection mode'))
        g.add(formalutils.Field('s2s_server', formal.String(required=False), label='Remote server address'))
        g.add(formalutils.Field('s2s_psk', formal.String(required=False),
                                formal.widgetFactory(formalutils.SemiHiddenPassword),
                                label='Remote server pre-shared key'))
        return g
Exemplo n.º 44
0
 def _create_port_forward_list_entry(index):
     g = formalutils.CollapsibleGroup(str(index), label='')
     g.setCollapsed(collapsed=False)
     g.add(formalutils.Field('new_fw_protocol', formal.String(required=True),
                             formal.widgetFactory(formal.SelectChoice, options=txt.new_fw_protocol_options),
                             label=txt.new_fw_protocol_label))
     g.add(formalutils.Field('new_fw_port_in', formal.Integer(required=True, validators=[formal.RangeValidator(min=0, max=65535)]), label=txt.new_fw_port_in_label))
     g.add(formalutils.Field('new_fw_ip_out', dt.FormIPv4Address(required=True), label=txt.new_fw_ip_out_label))
     g.add(formalutils.Field('new_fw_port_out', formal.Integer(required=True, validators=[formal.RangeValidator(min=0, max=65535)]), label=txt.new_fw_port_out_label))
     return g
Exemplo n.º 45
0
 def form_changepassword(self, ctx):
     form = formal.Form()
     g = formalutils.CollapsibleGroup('changepassword', label='Change Password')
     g.setCollapsed(False)
     g.add(formal.Field('pw1', formal.String(required=True),
                        formal.widgetFactory(formalutils.HiddenPassword),
                        label='Old password'))
     g.add(formal.Field('pw2', formal.String(required=True),
                        formal.widgetFactory(formalutils.HiddenPassword),
                        label='New password'))
     g.add(formal.Field('pw3', formal.String(required=True),
                        formal.widgetFactory(formalutils.HiddenPassword),
                        label='New password (again)'))
     sg = formalutils.SubmitFieldGroup('buttons')
     sg.add(formalutils.SubmitField('changepassword', formal.String(), label='Change password'))
     g.add(sg)
     form.add(g)
     form.addAction(self.submitted, name='changepassword', validate=False)
     return form
Exemplo n.º 46
0
 def create_dns_group(self, form, ctx):
     txt = self.nc_uitexts
     g = formalutils.CollapsibleGroup('dns_group', label=txt.dns_group_caption)
     g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseDns))
     g.add(formalutils.Field('dns_selection', formal.String(required=True),
                             formal.widgetFactory(formal.RadioChoice, options=txt.dns_select_options),
                             label=txt.dns_select_label))
     g.add(formalutils.Field('dns_1', dt.FormIPv4Address(required=False), label=txt.primary_dns_label))
     g.add(formalutils.Field('dns_2', dt.FormIPv4Address(required=False), label=txt.secondary_dns_label))
     return g
Exemplo n.º 47
0
 def create_internet_connection_group(self, form, ctx):
     txt = self.nc_uitexts
     g = formalutils.CollapsibleGroup('ic_group', label=txt.ic_group_caption)
     g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseInternetConnection))
     g.add(formalutils.Field('if', formal.String(required=True),
                             formal.widgetFactory(formal.SelectChoice, options=uihelpers.interface_options()),
                             label=txt.if_label))
     g.add(formalutils.Field('ip_address_selection', formal.String(required=True),
                             formal.widgetFactory(formal.RadioChoice, options=txt.ip_selection_options),
                             label=txt.ip_selection_label))
     g.add(formalutils.Field('ip_address', dt.FormIPv4AddressSubnet(required=False), label=txt.ip_label))
     g.add(formalutils.Field('subnet_mask', dt.FormSubnetMask(required=False), label=txt.subnet_label))
     g.add(formalutils.Field('default_gateway', dt.FormIPv4Address(required=False), label=txt.default_gw_label))
     g.add(formalutils.Field('mtu', formal.Integer(required=True, validators=[formal.RangeValidator(min=576, max=1500)]), label=txt.mtu_label))
     g.add(formalutils.Field('uplink', dt.FormFloat(required=False, validators=[formal.RangeValidator(min=0.128)]), label=txt.uplink_label))
     g.add(formalutils.Field('client_traffic', formal.String(required=True),
                             formal.widgetFactory(formal.RadioChoice, options=txt.client_traffic_options),
                             label=txt.client_traffic_label))
     return g
Exemplo n.º 48
0
def addCoreFields(form, forCreation=False, billingCountryOptions=None, optInDescription=None, termsDescription=None):
    """
    Add customer fields to a form.
    """

    genderOptions = [(o,o) for o in ('male', 'female')]

    if forCreation:
        email = formal.String(required=True, strip=True)
        terms = formal.Boolean(required=True)
        password = formal.String(required=True, strip=True)
    else:
        email = formal.String(immutable=True)
        terms = formal.Boolean(immutable=True)
        password = formal.String(strip=True)

    form.add( formal.Field('email', email) )
    form.add( formal.Field('password', password, widgetFactory=formal.CheckedPassword) )
    form.add( formal.Field('gender', formal.String(required=True),
        widgetFactory=formal.widgetFactory(formal.SelectChoice, options=genderOptions)) )
    form.add( formal.Field('first_name', formal.String(required=True, strip=True)) )
    form.add( formal.Field('last_name', formal.String(required=True, strip=True)) )
    form.add( formal.Field('dateOfBirth', formal.Date(required=True),
        widgetFactory=formal.widgetFactory(formal.DatePartsInput, dayFirst=True)) )
    form.add( formal.Field('phoneNumber', formal.String(strip=True, required=True)) )
    form.add( formal.Field('billingAddress1', formal.String(required=True, strip=True), label='Billing Address Line 1') )
    form.add( formal.Field('billingAddress2', formal.String(strip=True), label='Billing Address Line 2') )
    form.add( formal.Field('billingAddress3', formal.String(strip=True), label='Billing Address Line 3') )
    form.add( formal.Field('billingCity', formal.String(required=True, strip=True), label='Billing City') )
    form.add( formal.Field('billingPostcode', formal.String(required=True, strip=True), label='Billing Postcode') )
    if billingCountryOptions:
        form.add( formal.Field('billingCountry', formal.String(required=True, strip=True), 
            formal.widgetFactory(formal.SelectChoice, options=billingCountryOptions), label='Billing Country') )
    else:
        form.add( formal.Field('billingCountry', formal.String(required=True, strip=True), label='Billing Country') )


    form.add( formal.Field('secretQuestion', formal.String(required=True, strip=True)) )
    form.add( formal.Field('secretAnswer', formal.String(required=True, strip=True)) )

    form.add( formal.Field('optIn', formal.Boolean(), description=optInDescription) )
    form.add( formal.Field('terms', terms, label="T's & C's", description=termsDescription) )
Exemplo n.º 49
0
 def create_radius_group(self, ctx, form):
     g = formalutils.CollapsibleGroup('radius', label='RADIUS Servers')
     g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseRadius))
     g.add(formalutils.Field('server1', formal.String(required=False), label='Primary RADIUS server address'))
     g.add(formalutils.Field('serverport1',
                             formal.Integer(required=False, validators=[formal.RangeValidator(min=1, max=65535)]),
                             label='Primary RADIUS server port'))
     g.add(formalutils.Field('secret1', formal.String(required=False),
                             formal.widgetFactory(formalutils.SemiHiddenPassword),
                             label='Primary RADIUS shared secret'))
     g.add(formalutils.Field('server2', formal.String(required=False), label='Secondary RADIUS server address'))
     g.add(formalutils.Field('serverport2',
                             formal.Integer(required=False, validators=[formal.RangeValidator(min=1, max=65535)]),
                             label='Secondary RADIUS server port'))
     g.add(formalutils.Field('secret2', formal.String(required=False),
                             formal.widgetFactory(formalutils.SemiHiddenPassword),
                             label='Secondary RADIUS shared secret'))
     g.add(formalutils.Field('nasidentifier', formal.String(required=False),
                             label='NAS Identifier'))
     return g
Exemplo n.º 50
0
 def _create_user_list_entry(self, index):
     g = formalutils.CollapsibleGroup(str(index), label='')
     g.setCollapsed(False)
     g.add(formalutils.Field('username', formal.String(required=True), label='Username'))
     g.add(formalutils.Field('password', formal.String(required=False),
                             formal.widgetFactory(formalutils.SemiHiddenPassword),
                             label='Set password'))
     g.add(formalutils.Field('fixed_ip', dt.FormIPv4Address(required=False), label='Fixed IP address'))
     g.add(formalutils.Field('admin_rights', formal.Boolean(required=True), label='Allow VPNease administration'))
     g.add(formalutils.Field('vpn_rights', formal.Boolean(required=True), label='Allow VPN access'))
     return g
Exemplo n.º 51
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('restString', formal.String(required=True),
             widgetFactory=formal.ReSTTextArea)
     if docutilsAvailable:
         w = Writer()
         w.translator_class = CustomisedHTMLTranslator
         form.addField('customRestString', formal.String(required=True),
                 formal.widgetFactory(formal.ReSTTextArea, restWriter=w))
     form.addAction(self.submitted)
     return form
Exemplo n.º 52
0
 def create_client_connection_group():
     cc_group = formalutils.CollapsibleGroup('client_connection', label=txt.cc_group_caption)
     cc_group.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseClientConnection))
     #cc_group.add(formalutils.Field('server_name', formal.String(required=False), label=txt.server_address_label))
     cc_group.add(formalutils.Field('psk_1', formal.String(required=True),
                                    formal.widgetFactory(formalutils.SemiHiddenPassword),
                                    label='Primary pre-shared key'))
     cc_group.add(formalutils.Field('psk_2', formal.String(required=False),
                                    formal.widgetFactory(formalutils.SemiHiddenPassword),
                                    label='Secondary pre-shared key'))
     cc_group.add(formalutils.Field('dns', formal.String(required=True),
                                    formal.widgetFactory(formal.RadioChoice, options=txt.client_dns_options),
                                    label=txt.client_dns_options_label))
     cc_group.add(formalutils.Field('dns_1', dt.FormIPv4Address(required=False), label=txt.primary_dns_label))
     cc_group.add(formalutils.Field('dns_2', dt.FormIPv4Address(required=False), label=txt.secondary_dns_label))
     cc_group.add(formalutils.Field('wins_1', dt.FormIPv4Address(required=False), label=txt.primary_wins_label))
     cc_group.add(formalutils.Field('wins_2', dt.FormIPv4Address(required=False), label=txt.secondary_wins_label))
     cc_group.add(formalutils.Field('client_subnet', dt.FormIPv4Subnet(required=True), label=txt.client_subnet_label))
     cc_group.add(formalutils.Field('client_address_range', dt.FormIPv4AddressRange(required=True), label=txt.client_address_range_label))
     cc_group.add(formalutils.Field('client_compression', formal.Boolean(required=True), label='VPN client traffic compression'))
     return cc_group
Exemplo n.º 53
0
    def form_select_target(self, ctx):
        form = formal.Form()

        g = formalutils.CollapsibleGroup('selecttarget', label='Select Target Device')
        g.setCollapsed(False)
        
        targets = []
        for m in self._get_disks():
            errors = []
            if m.is_write_protected():
                errors.append('write-protected')
            if errors:
                errorstr = ' [' + (', '.join(errors)) + ']'
            else:
                errorstr = ''
                
            devname = m.get_device()
            devstring = '%s %s (%s) %s' % (m.get_size_pretty(), m.get_human_readable_description(), m.get_device(), errorstr)
            targets.append((devname, devstring))

        def _target_cmp(x, y):
            x_dev, x_info = x
            y_dev, y_info = y
            return unicode.__cmp__(unicode(x_dev), unicode(y_dev))
        targets.sort(cmp=_target_cmp)
            
        lbl = 'Target device'
        g.add(formal.Field('target', formal.String(required=True),
                           formal.widgetFactory(formal.RadioChoice, options=targets),
                           label=lbl))
        sg = formalutils.SubmitFieldGroup('buttons')
        sg.add(formalutils.SubmitField('selecttarget', formal.String(), label='Next'))
        sg.add(formalutils.SubmitField('rescan', formal.String(), label='Rescan'))
        sg.add(formalutils.SubmitField('cancel', formal.String(), label='Cancel'))
        g.add(sg)
        
        form.add(g)
        form.addAction(self.submitted_select_target, name='selecttarget', label='Continue', validate=False)
        form.addAction(self.submitted_rescan, name='rescan', label='Rescan targets', validate=False)
        form.addAction(self.submitted_cancel_formatting, name='cancel', label='Cancel formatting', validate=False)

        # set previous selection if exists as default value
        cfg = livecddb.get_livecd_database_root()
        if cfg.hasS(ns_ui.targetDevice):
            form.data['selecttarget.target'] = cfg.getS(ns_ui.targetDevice, rdf.String)

        return form
Exemplo n.º 54
0
def addArtworkFields(form, forCreation=False):
    """
    Add artwork fields to a form.

    If forCreation is True then the main image will be a required field. This is
    to work around a limitation in Formal's file upload handling.
    """


    form.addField('title', formal.String(required=True, strip=True))
    form.addField('longTitle', formal.String(strip=True))

    availability = formal.Group('availability')
    form.add( availability )

    availability.add( formal.Field('show', formal.Boolean()))
    availability.add( formal.Field('available', formal.Boolean()) )

    description = formal.Group('description')
    form.add( description )

    description.add( formal.Field('shortDescription', formal.String(strip=True),
            widgetFactory=formal.TextArea) )
    description.add( formal.Field('categories', formal.Sequence(), 
        widgetFactory=categorieswidget.FormalCheckboxTreeMultichoice ) )

    pricing = formal.Group('pricing')
    form.add( pricing )
    pricing.add( formal.Field('price', formal.Decimal(required=True)) )

    images = formal.Group('images')
    form.add( images )
    images.add( formal.Field('mainImage', formal.File(required=forCreation), 
        widgetFactory=formal.widgetFactory( formal.FileUploadWidget,
            convertibleFactory=contenttypeutil.KeyToFileConverter,
            originalKeyIsURL=True)) )

    seo = formal.Group('seo')
    form.add( seo )
    seo.add( formal.Field('titleTag', formal.String()) )
    seo.add( formal.Field('metaDescription', formal.String()) )
    seo.add( formal.Field('metaKeywords', formal.String()) )
Exemplo n.º 55
0
def addProductFields(form, forCreation=False, restWriter=None, hasOptions=False):
    """
    Add product fields to a form.

    If forCreation is True then the main image will be a required field. This is
    to work around a limitation in Formal's file upload handling.
    """
    form.addField('code', formal.String(required=True, strip=True))
    form.addField('title', formal.String(required=True, strip=True))

    images = formal.Group('images')
    form.add( images )
    images.add( formal.Field('mainImage', formal.File(required=forCreation), 
        widgetFactory=formal.widgetFactory( formal.FileUploadWidget,
            convertibleFactory=contenttypeutil.KeyToFileConverter,
            originalKeyIsURL=True),description='click to change') )
    images.add( formal.Field('ndgrad', formal.File(), 
        widgetFactory=formal.widgetFactory( formal.FileUploadWidget,
            convertibleFactory=contenttypeutil.KeyToFileConverter,
            originalKeyIsURL=True),description='click to change') )


    availability = formal.Group('availability')
    form.add( availability )

    availability.add( formal.Field('show', formal.Boolean()))
    availability.add( formal.Field('available', formal.Boolean()) )
    availability.add( formal.Field('availabilityDescription', formal.String()) )

    metadata = formal.Group('metadata')
    form.add( metadata )

    metadata.add( formal.Field('date', formal.Date(), formal.widgetFactory(formal.DatePartsInput, dayFirst=True)))
    metadata.add( formal.Field('location', formal.String()) )
    
    lensOptions = [
        "72mm Schneider Super Angulon f5.6",
        "90mm Schneider Super Angulon f5.6",
        "150mm Schneider Apo-Symmar f5.6",
        "210mm Schneider Apo-Symmar f5.6",
        "270mm Nikon T*ED f6.3",
        "400mm Fujinon T f8"
    ]
    metadata.add( formal.Field('lens', formal.String(),formal.widgetFactory(formal.SelectOtherChoice, options=lensOptions)  ) )
    
    # this is a redundant field... need to remove if possible
    metadata.add( formal.Field('speedaperture', formal.String()) )
    
    speedOptions = ['1/500', '1/250','1/125','1/60','1/30','1/15','1/8','1/4','1/2','1s','2s','4s','8s','15s','30s','1m','2m']
    metadata.add( formal.Field('speed', formal.String(),formal.widgetFactory(formal.SelectOtherChoice, options=speedOptions),description='If you enter a text value please use the same format as the existing values e.g. 6s, 1/3, 2m' ) )
    
    
    apertureOptions = ['f/5.6','f/6.3','f/8','f/8⅓','f/8½','f/8⅔','f/16','f/16⅓','f/16½','f/16⅔','f/22','f/22⅓','f/22½','f/22⅔','f/32','f/32⅓','f/32½','f/32⅔','f/45','f/45⅓','f/45½','f/45⅔']
    metadata.add( formal.Field('aperture', formal.String(),formal.widgetFactory(formal.SelectOtherChoice, options=apertureOptions) ) )  
    metadata.add( formal.Field('tiltswing', formal.String()) )
    metadata.add( formal.Field('risefall', formal.String()) )
    ndfilters = ['0.3S','0.45S','0.6S','0.75S','0.9S','0.3H','0.45H','0.6H','0.75H','0.9H']
    metadata.add( formal.Field('ndfilters', formal.String(),formal.widgetFactory(formal.SelectOtherChoice, options=ndfilters)) )
    otherfilters=['81A','81B','81C','Polariser']
    metadata.add( formal.Field('otherfilters', formal.String(), formal.widgetFactory(formal.SelectOtherChoice, options=otherfilters)) )

    
    
    
    data_strings = [
        (0, '-'),
        (1, '*'),
        (2, '**'),
        (3, '***'),
        (4, '****'),
        (5, '*****'),
        ] 
    
    metadata.add( formal.Field('rating', formal.Integer() ) )
    #metadata.add( formal.Field('rating', formal.Integer(), formal.widgetFactory(formal.SelectChoice, options=data_strings)) )


    description = formal.Group('description')
    form.add( description )
    parsers = [('markdown','MarkDown'),('xhtml','XHTML'),('plain','Plain Text')]
    description.add( formal.Field('summary',  formal.RichTextType(required=True),
            widgetFactory=formal.widgetFactory(richtextarea.RichTextArea, parsers=parsers),
            cssClass=' '.join(['imagepicker','preview','itemselector']) ) )
    description.add( formal.Field('description', formal.RichTextType(required=True),
            widgetFactory=formal.widgetFactory(richtextarea.RichTextArea, parsers=parsers),
            cssClass=' '.join(['imagepicker','preview','itemselector']) ) )
    description.add( formal.Field('categories', formal.Sequence(formal.String()), 
        widgetFactory=categorieswidget.FormalCheckboxTreeMultichoice ) )



    if not hasOptions:
        pricing = formal.Group('pricing')
        form.add( pricing )
        pricing.add( formal.Field('price', formal.Decimal(required=True)) )


    seo = formal.Group('seo')
    form.add( seo )
    seo.add( formal.Field('titleTag', formal.String()) )
    seo.add( formal.Field('metaDescription', formal.String()) )
    seo.add( formal.Field('metaKeywords', formal.String()) )
Exemplo n.º 56
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('required', formal.String(required=True))
     form.addField('oneString', formal.String(),
             formal.widgetFactory(formal.SelectChoice, options=strings))
     form.addField('anotherString', formal.String(),
             formal.widgetFactory(formal.SelectChoice, options=data_strings))
     form.addField('oneMoreString', formal.String(required=True),
             formal.widgetFactory(formal.RadioChoice, options=data_strings))
     form.addField('oneDate', formal.Date(),
             formal.widgetFactory(formal.SelectChoice, options=dates))
     form.addField('multipleStrings', formal.Sequence(formal.String()),
             formal.widgetFactory(formal.CheckboxMultiChoice,
                 options=data_strings))
     form.addField('multipleDates', formal.Sequence(formal.Date()),
             formal.widgetFactory(formal.CheckboxMultiChoice, options=dates))
     form.addField('differentNoneSelect', formal.String(),
             formal.widgetFactory(formal.SelectChoice, options=strings,
                 noneOption=differentNone))
     form.addField('differentNoneRadios', formal.String(),
             formal.widgetFactory(formal.RadioChoice, options=data_strings,
                 noneOption=differentNone))
     form.addField('selectOther', formal.String(),
             formal.widgetFactory(formal.SelectOtherChoice, options=['Mr',
                 'Mrs']))
     form.addField('selectOtherCustomOther', formal.String(),
             formal.widgetFactory(formal.SelectOtherChoice, options=['Mr',
                 'Mrs'], otherOption=('...','Other (Please Enter)')))
     form.addField('selectOtherRequired', formal.String(required=True),
             formal.widgetFactory(formal.SelectOtherChoice, options=['Mr',
                 'Mrs']))
     form.addField('multiselect', formal.String(),
             formal.widgetFactory(formal.MultiselectChoice, options=strings))
     form.addAction(self.submitted)
     return form
Exemplo n.º 57
0
    def form_form(self,ctx):
        form = formal.Form()
        for field in self.original.getParsedFormDefinition():

            # Parse the required
            if field['required'] == 'True':
                required = True
            else:
                required = False
                
            # Map the field's type to a formal type.
            try:
                fieldType = field['type']
                if fieldType.startswith('Sequence/'):
                    fieldType = fieldType.split('/',1)[1]
                    fieldType = formal.Sequence(getattr(formal, fieldType)(), required=required)
                else:
                    fieldType = getattr(formal, fieldType)(required=required)
            except AttributeError:
                fieldType = None

            # Skip if we don't know the type or widget.
            if not fieldType or not hasattr(formal,field['widget']):
                continue

            # Build the widget
            if field['widget'] == 'Checkbox':
                form.addField(field['name'], fieldType, label=field['options'],widgetFactory=getattr(formal,field['widget']))
            elif not field['widget'].startswith('Select') and not field['widget'].startswith('Radio') and field['widget'] != 'CheckboxMultiChoice':
                form.addField(field['name'], fieldType, label=field['label'], widgetFactory=getattr(formal,field['widget']))
            else:
                form.addField(field['name'], fieldType, label=field['label'], widgetFactory=formal.widgetFactory(getattr(formal,field['widget']),options=field['options']))
            if field['widget'] == 'Hidden':
                form.data[field['name']] = field['options']
        form.addField('humanCheck', formal.String(required=True,validators=[HumanCheckValidator()]), description="Enter Tim's Surname")
        form.addAction(self._submit)
        return form          
Exemplo n.º 58
0
    def form_management(self, ctx):    
        form = formal.Form()
        fda = formalutils.FormDataAccessor(form, [], ctx)
        tzhelp = uihelpers.TimezoneHelper()
        txt = self.mng_uitexts
        
        ### License

        g = formalutils.CollapsibleGroup('license_group', label=txt.license_group_caption)
        g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseLicense))
        g.add(formalutils.Field('license_key', formal.String(required=False), label=txt.license_key_label))
        form.add(g)

        ### Locale

        tzoptions = []
        for tzname in tzhelp.get_timezones():
            tzoptions.append((tzname, tzname))
        def _tz_cmp(x,y):
            x_name, x_label = x
            y_name, y_label = y
            return unicode.__cmp__(unicode(x_label), unicode(y_label))
        tzoptions.sort(cmp=_tz_cmp)

        # XXX: keymap values are truncated because they are so long
        keymapoptions = []
        for gname, gname_escaped, human in gnomeconfig.get_keymap_list():
            keymapoptions.append((gname_escaped, uihelpers.ui_truncate(human, 56)))
        def _km_cmp(x,y):
            x_name, x_label = x
            y_name, y_label = y
            return unicode.__cmp__(unicode(x_label), unicode(y_label))
        keymapoptions.sort(cmp=_km_cmp)
        
        g = formalutils.CollapsibleGroup('locale_group', label='Locale Settings')
        g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseLocale))
        g.add(formalutils.Field('timezone', formal.String(required=True),
                                formal.widgetFactory(formal.SelectChoice, options=tzoptions),
                                label='Timezone'))
        g.add(formalutils.Field('keymap', formal.String(required=True),
                                formal.widgetFactory(formal.SelectChoice, options=keymapoptions),
                                label='Keyboard layout'))

        # XXX: it would be good if we could show a time example using the timezone
        # admin has selected.
        
        form.add(g)

        ### Reboots

        g = formalutils.CollapsibleGroup('reboot_group', label=txt.reboot_group_caption)
        g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseProductMaintenance))
        g.add(formalutils.Field('reboot_day', formal.Integer(required=True),
                                formal.widgetFactory(formal.SelectChoice, options=txt.reboot_day_options),
                                label=txt.reboot_day_label))
        g.add(formalutils.Field('reboot_time', formal.Integer(required=True),
                                formal.widgetFactory(formal.SelectChoice, options=txt.reboot_time_options),
                                label=txt.reboot_time_label))
        # Information about the periodic reboot consequences (about 5 minutes downtime).
        g.add(formalutils.Field('automatic_updates', formal.Boolean(required=True), label=txt.automatic_update_label))
        form.add(g)

        ### SNMP

        g = formalutils.CollapsibleGroup('snmp_group', label='SNMP Monitoring')
        g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseSnmp))
        g.add(uihelpers.create_access_control_dropdown('snmp_access', 'SNMP read-only access'))
        g.add(formalutils.Field('snmp_community', formal.String(required=False),
                                formal.widgetFactory(formalutils.SemiHiddenPassword),
                                label='SNMP community string (password)'))
        form.add(g)

        ### Remote management

        g = formalutils.CollapsibleGroup('remote_group', label=txt.remote_group_caption)
        g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseRemoteManagement))
        g.add(uihelpers.create_access_control_dropdown('www_administration', 'Web administration'))
        g.add(uihelpers.create_access_control_dropdown('ssh_connection', 'SSH connection'))
        g.add(formalutils.Field('root_password1', formal.String(required=False),
                                formal.widgetFactory(formalutils.HiddenPassword),
                                label='Set root password'))
        g.add(formalutils.Field('root_password2', formal.String(required=False),
                                formal.widgetFactory(formalutils.HiddenPassword),
                                label='Re-enter root password'))
        form.add(g)

        ### Admin e-mails

        # XXX: not yet implemented
        #g = formalutils.CollapsibleGroup('email_group', label='Administrator E-mail')
        #g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseAdminEmail))
        #g.add(formalutils.Field('smtp_server', formal.String(required=False), label='SMTP server'))
        #g.add(formalutils.Field('smtp_from', formal.String(required=False), label='FROM address'))
        #g.add(formalutils.Field('smtp_to', formal.String(required=False), label='TO address(es) (comma separated)'))
        #form.add(g)
        
        ### SSL certificate

        g = formalutils.CollapsibleGroup('ssl_group', label='SSL Certificate')
        g.setCollapsed(uihelpers.collapse_setting(ns_ui.collapseSslCertificate))
        g.add(formalutils.Field('ssl_certificate_chain', formal.String(required=False),
                                formal.widgetFactory(formal.TextArea, cols=80, rows=10),
                                label='SSL Certificate Chain (PEM format, server certificate first)'))
        g.add(formalutils.Field('ssl_private_key', formal.String(required=False),
                                formal.widgetFactory(formal.TextArea, cols=80, rows=10),
                                label='SSL Private Key (PEM format)'))
        form.add(g)

        ### Submit buttons
        
        sg = formalutils.SubmitFieldGroup('buttons')
        sg.add(formalutils.SubmitField('submit', formal.String(), label='Save changes'))
        form.add(sg)
        form.addAction(self.submitted, name='submit', validate=False)        

        ### Fill data to form
        
        try:
            self.fill_management(ctx, fda)
        except:
            # ignore failure so user has chance to edit the form
            _log.exception('fill_form_data failed, ignoring')

        return form
Exemplo n.º 59
0
    def _build_details_form(self, billingCountryOptions, deliveryCountryOptions):

        form = formal.Form()
        form.addField('firstName', formal.String(required=True, strip=True))
        form.addField('lastName', formal.String(required=True, strip=True))
        form.addField('phoneNumber', formal.String(required=True, strip=True))
        form.addField('billingAddress1', formal.String(required=True, strip=True))
        form.addField('billingAddress2', formal.String(strip=True))
        form.addField('billingAddress3', formal.String(strip=True))
        form.addField('billingCity', formal.String(required=True, strip=True))
        form.addField('billingPostcode', formal.String(required=True, strip=True))
        form.addField('billingCountry', formal.String(required=True, strip=True),
            widgetFactory=formal.widgetFactory(formal.SelectChoice, options=billingCountryOptions) )
        form.addField('cardType', formal.String(required=True), 
            formal.widgetFactory(formal.SelectChoice, CommonData.Cards))
        form.addField('cardNumber', formal.String(required=True, strip=True))
        form.addField('cvv2', formal.String(required=True, strip=True), 
            label='Card Security Code',description='last three numbers on signature strip')
        form.addField('expiryDate', formal.Date(required=True), 
            formal.widgetFactory(formal.MMYYDatePartsInput), description='e.g. 12/05' ) 
        form.addField('issueNumber', formal.String(strip=True), 
            description='for maestro and switch only')
        form.addField('startDate', formal.Date(), 
            formal.widgetFactory(formal.MMYYDatePartsInput), description='for switch only' )

        delivery = formal.Group('delivery', label='Delivery Address', description="Only enter details here if the delivery address is different from the billing address above.")
        form.add( delivery )
        delivery.add( formal.Field('name', formal.String(strip=True)) )
        delivery.add( formal.Field('address1', formal.String(strip=True)))
        delivery.add( formal.Field('address2', formal.String(strip=True)))
        delivery.add( formal.Field('address3', formal.String(strip=True)))
        delivery.add( formal.Field('city', formal.String(strip=True)))
        delivery.add( formal.Field('postcode', formal.String(strip=True)) )
        delivery.add( formal.Field('country', formal.String(strip=True),
            widgetFactory=formal.widgetFactory(formal.SelectChoice, options=deliveryCountryOptions)) )

        message = formal.Group('message', label='Gift Message', description="If you have chosen to use our gift wrapping service you can specify a message here")
        form.add( message )
        message.add( formal.Field('message', formal.String(strip=True), widgetFactory=formal.TextArea) )

        form.addAction(self._confirm, label="Confirm Order")

        if self.avatar.checkoutDetails:
            form.data = self.avatar.checkoutDetails
        elif self.avatar.customer:
            form.data = {
                'firstName': self.avatar.customer.first_name,
                'lastName': self.avatar.customer.last_name,
                'phoneNumber': self.avatar.customer.phoneNumber,
                'billingAddress1': self.avatar.customer.billingAddress1,
                'billingAddress2': self.avatar.customer.billingAddress2,
                'billingAddress3': self.avatar.customer.billingAddress3,
                'billingCity': self.avatar.customer.billingCity,
                'billingPostcode': self.avatar.customer.billingPostcode,
                'billingCountry': self.avatar.customer.billingCountry,
            }

            if self.avatar.realm.config['ecommerce']['paymentGateway'].get('use_test_data', False):

                from datetime import date
                from dateutil.relativedelta import relativedelta

                form.data['cardType'] = 'VISA'
                form.data['cardNumber'] = '4111111111111111'
                form.data['cvv2'] = '432'
                form.data['expiryDate'] = date.today()+relativedelta(months=6)

        return form