def createForm(form): form.addField('domain', formal.String(strip=True), label="Domain", description="Domain name") form.addField( 'netbios', formal.String(strip=True, validators=[PageHelpers.IPValidator()]), label="Windows Server", description="A windows server (if any) to delegate for WINS and Netbios" ) form.addField('nameserver', formal.String(strip=True, validators=[PageHelpers.IPValidator()]), label="DNS Server", description="DNS server") form.addField('network', formal.String(strip=True, validators=[PageHelpers.IPValidator()]), label="Network address") form.addField('netmask', formal.String(strip=True, validators=[PageHelpers.IPValidator()]), label="Subnet mask") form.addField('rangeStart', formal.String(), label="Start IP") form.addField('rangeEnd', formal.String(), label="End IP") form.addField('gateway', formal.String(strip=True, validators=[PageHelpers.IPValidator()]), label="Default gateway")
def render_content(self, ctx, seg): try: stat = eval(open('/usr/local/tcs/tums/rrd/dindex.nid').read()) except: return ctx.tag[tags.h3[tags.img(src="/images/system.png"), " Disk Utilisation"], tags.br, "No statistics have been generated."] #unpack it home = stat['home'] shares = stat['shares'] mail = stat['mail'] homeTotal = sum([int(i) for i in home.values()]) sharesTotal = sum([int(i) for i in shares.values()]) mailTotal = sum([int(i) for i in mail.values()]) return ctx.tag[ tags.h3[tags.img(src="/images/system.png"), " Disk Utilisation"], tags.br, tags.h3["Home folders"], tags.hr, self.pieChartImg(home), PageHelpers.dataTable(['User', 'Utilisation'], self.refilterTable(home, homeTotal)), tags.h3["Shared folders"], tags.hr, self.pieChartImg(shares), PageHelpers.dataTable(['Folder', 'Utilisation'], self.refilterTable(shares, sharesTotal)), tags.h3["Mailboxes"], tags.hr, self.pieChartImg(mail), PageHelpers.dataTable(['Mailbox', 'Utilisation'], self.refilterTable(mail, mailTotal)), ]
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
def render_content(self, ctx, data): Utils.log.msg('%s opened Tools/Webserver' % (self.avatarId.username)) H = self.sysconf.General.get('http', {}) hosts = [] #hosts.append(('[default]', H.get('defaults',{}).get('DocumentRoot', "/var/www/localhost/htdocs/"))) for host, v in H.get('vhosts', {}).items(): hosts.append((host, v.get('DocumentRoot', '<Misconfigured>'), tags.a(href="Edit/%s/" % host)["Edit"])) return ctx.tag[ tags.h3[tags.img(src="/images/networking_section.png"), " Webserver"], PageHelpers.TabSwitcher(( ('Webserver Vhosts', 'panelVhost'), ('Webserver Default', 'panelDefault'), )), tags.div(id="panelVhost", _class="tabPane")[ tags.h3["Webserver Vhosts"], PageHelpers.dataTable( ["Domain", "Content Directory", ''], hosts, sortable=True), tags.h3["Add Vhost"], tags.directive('form addVhost')], tags.div(id="panelDefault", _class="tabPane")[ tags.h3["Default vhost"], ], PageHelpers.LoadTabSwitcher()]
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
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
def render_content(self, ctx, data): return ctx.tag[tags.h3[tags.img(src="/images/netdrive.png"), " System Policy"], PageHelpers.TabSwitcher( (('Internet Policy', 'panelInetpol'), )), tags.div(id="panelInetpol", _class="tabPane")[ tags.h3["Internet Policy"], tags.directive('form inetPol')], PageHelpers.LoadTabSwitcher()]
def generateReport(): return [ tags.a(href=url.root.child('TelReport').child( 'Overview').child(self.day).child(self.month).child( self.year))["Back to Overview"], tags.h3['Outbound'], PageHelpers.dataTable(outHeader, outData, sortable=False), tags.br, tags.h3['Inbound'], PageHelpers.dataTable(inHeader, inData, sortable=False) ]
def render_content(self, ctx, data): records = [] if not self.sysconf.General['zones'][self.domain]['records']: records = self.parseZone() for rec in self.sysconf.General['zones'][self.domain]['records']: # Ditch duplicates automatically if rec not in records: records.append(rec) # Save parsed records G = self.sysconf.General G['zones'][self.domain]['records'] = records self.sysconf.General = G # Make the table rnum = 0 nrecords = [] for r in records: l = r.split() if len(l)>3 and "MX" in r: # Has MX thisRec = [l[0], l[1], l[3], l[2]] else: thisRec = l thisRec.append("") thisRec.append(tags.a(href="Delete/%s/"%rnum)["Delete"]) rnum += 1 nrecords.append(thisRec) return ctx.tag[ tags.h3[tags.img(src="/images/networking_section.png"), " Editing zone %s" % self.domain], PageHelpers.TabSwitcher(( ('Records', 'panelDNSRecs'), ('Add Record', 'panelDNSAdd'), ('Edit Options', 'panelDNSOpt'), )), tags.div(id="panelDNSRecs", _class="tabPane")[ PageHelpers.dataTable(["Host", "Type", "Data", "Priority", ""], nrecords, sortable = True ), ], tags.div(id="panelDNSAdd", _class="tabPane")[ tags.h3["Add new record"], tags.directive('form addRecord'), ], tags.div(id="panelDNSOpt", _class="tabPane")[ tags.h3["Edit zone options"], tags.directive('form editZone') ], PageHelpers.LoadTabSwitcher() ]
def render_editContent(self, ctx, data): return ctx.tag[tags.h2[self.text.userHeadingAddUser, self.domain], PageHelpers.TabSwitcher([(self.text.userTabSettings, 'addForm-userSettings'), (self.text.userTabPermissions, 'addForm-userPermissions'), (self.text.userTabMail, 'addForm-mailSettings'), (self.text.userTabAccess, 'addForm-userAccess')]), tags.directive('form addForm'), PageHelpers.LoadTabSwitcher()]
def render_content(self, ctx, data): blacklist = [] j = 0 for i in self.sysconf.Mail.get('blacklist', []): blacklist.append([ i, tags. a(href=url.root.child("Mailserver").child("BDelete").child(j), onclick="return confirm('%s');" % self.text.eximConfirmDelete)[tags.img(src="/images/ex.png")] ]) j += 1 whitelist = [] j = 0 for i in self.sysconf.Mail.get('whitelist', []): whitelist.append([ i, tags. a(href=url.root.child("Mailserver").child("WDelete").child(j), onclick="return confirm('%s');" % self.text.eximConfirmDelete)[tags.img(src="/images/ex.png")] ]) j += 1 return ctx.tag[ tags.h2[tags.img(src="/images/mailsrv.png"), " Email Server Config"], PageHelpers.TabSwitcher( ((self.text.eximTabMail, 'panelMail'), (self.text.eximTabRelay, 'panelRelay'), (self.text.eximTabHubbed, 'panelHubbed'), (self.text.eximTabLocal, 'panelLocal'), (self.text.eximTabBlocked, 'panelBlack'), (self.text.eximTabWhitelist, 'panelWhite'))), tags.div(id="panelMail", _class="tabPane" )[tags.directive('form mailConfig')], tags.div(id="panelRelay", _class="tabPane" )[tags.directive('form mailRelay')], tags.div(id="panelHubbed", _class="tabPane" )[tags.directive('form mailHubbed')], tags.div(id="panelLocal", _class="tabPane" )[tags.directive('form mailLocal')], tags.div(id="panelBlack", _class="tabPane")[ PageHelpers.dataTable([self.text.eximAddr, ''], blacklist), tags.h3[self.text.eximAddBlacklist], tags.directive('form mailBlacklist')], tags.div(id="panelWhite", _class="tabPane")[ PageHelpers.dataTable([self.text.eximAddrOrHost, ''], whitelist ), tags.h3[self.text.eximAddWhitelist], tags.directive('form mailWhitelist')], PageHelpers.LoadTabSwitcher()]
def render_content(self, ctx, data): heading = " Configure cluster relationship with %s" % self.ip return ctx.tag[tags.h3[tags.img(src="/images/networking_section.png"), heading], PageHelpers.TabSwitcher([('Topology', 'config-topology'), ('Failover', 'config-failover'), ('Load Sharing', 'config-loadbalance')]), tags.directive('form config'), PageHelpers.LoadTabSwitcher()]
def render_content(self, ctx, data): return ctx.tag[tags.h3[tags.img(src="/images/dhcp.png"), " Edit Zone %s" % self.zone], PageHelpers.TabSwitcher(( ('Settings', 'panelConfig'), ('Members', 'panelMembers'), ), id="zones"), tags.div(id="panelConfig", _class="tabPane" )[tags.directive("form confZone")], tags.div(id="panelMembers", _class="tabPane" )[self.interfaceList.applyTable(self)], PageHelpers.LoadTabSwitcher(id="zones")]
def render_content(self, ctx, data): keys = [i for i in os.listdir('/etc/openvpn/keys/') if 'key' in i] keys.sort() for key in ['vpn.key', 'ca.key']: try: keys.remove(key) except: pass return ctx.tag[ tags.h2[tags.img(src="/images/vpn.png"), self.text.vpnConfig], PageHelpers.TabSwitcher(( (self.text.vpnTabWindows, 'panelWindows'), (self.text.vpnTabTCS, 'panelOpenVPN'), (self.text.vpnTabUsers, 'panelVPNUsers') )), tags.div(id="panelWindows", _class="tabPane")[ tags.h3[self.text.vpnHeadingWindows], tags.directive('form winForm'), ], tags.div(id="panelOpenVPN", _class="tabPane")[ tags.h3[self.text.vpnHeadingTCS], tags.directive('form vpnForm'), tags.br, ], tags.div(id="panelVPNUsers", _class="tabPane")[ tags.h3[self.text.vpnHeadingTCSUsers], tags.table(cellspacing=0, _class='listing')[ tags.thead(background="/images/gradMB.png")[ tags.tr[ tags.th[self.text.vpnCertificateName], tags.th[""], ] ], tags.tbody[ [ tags.tr[ tags.td['.'.join(i.split('.')[:-1])], tags.td[tags.a(href="Revoke/%s/" % '.'.join(i.split('.')[:-1]), onclick="return confirm('%s');" % self.text.vpnConfirmRevoke)[ tags.img(src="/images/ex.png")] ] ] for i in keys], ] ], tags.br, tags.h3[self.text.vpnHeadingAddUser], tags.directive('form addUser') ], PageHelpers.LoadTabSwitcher() ]
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") form.addField('gate', formal.String(validators=[PageHelpers.IPValidator()]), label = "Gateway", description = "Gateway to forward this network to") ifs = [(i,i) for i in self.sysconf.WANDevices.keys()] form.addField('device', formal.String(), formal.widgetFactory(formal.SelectChoice, options = ifs), label = "Device", description = "Device to forward this traffic to - do not specify a gateway as well as this field") form.addAction(self.submitRoute) return form
def render_content(self, ctx, data): return ctx.tag[ PageHelpers.TabSwitcher( (('Configuration', 'panelConf'), ('Mapping', 'panelMap'), ('Computers', 'panelComp'))), tags.div(id="panelConf", _class="tabPane")[ tags.h3[tags.img(src="/images/sharefold.png"), " Domain configuration"], tags.directive('form configSamba')], tags.div(id="panelMap", _class="tabPane")[tags.invisible( render=tags.directive('drives'))], tags.div(id="panelComp", _class="tabPane")[tags.invisible( render=tags.directive('computers'))], PageHelpers.LoadTabSwitcher()]
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
def render_content(self, ctx, data): return ctx.tag[ tags.h3[tags.img(src="/images/networking_section.png"), " Cluster"], PageHelpers.TabSwitcher([('Configuration', 'config-me'), ('Cluster', 'config-cluster')]), tags.div(id='config-me', _class='tabPane')[ tags.h3["Cluster port"], tags.directive('form clusterPort'), tags.h3["Generate access key"], tags.directive('form genKey'), tags.h3["Master key"], tags.directive('form masterKey')], tags.div(id='config-cluster', _class='tabPane')[tags.div[ tags.invisible(render=tags.directive('thisFragment')), tags.a(href="Sync/")['Synchronise Cluster']]], PageHelpers.LoadTabSwitcher()]
def form_editDomain(self, data): form = formal.Form() form.addField('name', formal.String(required=True), label="Server name", description="Server Name") form.addField( 'memory', formal.Integer(), label="Memory", description= "Amount of reserved memory in MB (swap is always equal to this)") form.addField('ip', formal.String(strip=True, validators=[PageHelpers.IPValidator()]), label="IP", description="IP address (leave blank to use DHCP).") form.data = self.sysconf.General.get('xen', {}).get('images', {}).get(self.name, {}) form.data['name'] = self.name form.addAction(self.submitDomain) return form
def render_content(self, ctx, data): dir = os.listdir('/usr/local/tcs/tums/profiles/') dir.sort() tab = [] for l in dir: if l[-3:] == ".py": name = l[:-3].replace('_', ' ').capitalize() tab.append((name, [ tags.a(href="copy/%s" % l)["Copy"], " ", tags. a(href="#", onclick= "showElement('ren'); getElement('rename-source').value = '%s'; return false;" % name)["Rename"], " ", tags. a(href="delete/%s" % (l), onclick= "return confirm('Are you sure you want to delete this profile?');", title="Delete this profile")[tags.img( src="/images/ex.png")] ])) return ctx.tag[tags.h3[tags.img(src="/images/netdrive.png"), " Configuration Profiles"], PageHelpers.dataTable(['Profile Name', ""], tab), tags.br, tags.div(id="ren", style="display:none;" )[tags.directive('form rename')]]
def returnMonthView(dayData): """ Returns the details for a particular month""" flatBlocks = [] date = datetime.date(self.year, self.month, 1).strftime("%h %Y") tsite = "" for rows in dayData: tsite = rows[6] flatBlocks.append(( tags.a(href=url.root.child("ProxyUse").child("ShowHost").child(rows[2]).child(self.year).child(self.month).child('0'))[rows[1]], rows[4], "%0.2fMB" % (rows[0]/(1024*1024)), )) return ctx.tag[ tags.h3[ tags.img(src="/images/stock-download.png"), "Web Usage - Hosts who visited %s during %s" % (tsite, date) ], tags.a(href=url.root.child("ProxyUse"))["Back to overview"], " ", tags.a(href=url.root.child("ProxyUse").child("ShowDays").child(self.year).child(self.month))["Back to month overview"], " ", tags.a(href=url.root.child("ProxyUse").child("ShowDays").child(self.year).child(self.month).child(self.day))["Back to day overview"], " ", tags.a(href=url.root.child("ProxyUse").child("ShowSites").child(self.year).child(self.month).child('0'))["Back to sites overview"], tags.br, tags.br, PageHelpers.dataTable([('str', 'Host'), ('str', 'Username'), ('int', 'Total Traffic')], flatBlocks, sortable=True) ]
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
def form_neigh(self, data): form = formal.Form() form.addField('ip', formal.String(required=True, validators=[PageHelpers.IPValidator()]), label="Remote IP") form.addField( 'asn', formal.String(), label="Remote AS", description= "Remote AS number of peer. Leave blank for the same AS as this router" ) #form.addField('hold', formal.Integer(required=True), label = "Hold time", description="Override the Hold timer for this peer (default 120)") #form.data['hold'] = 120 form.addField( 'multihop', formal.Boolean(), label="EBGP Multihop", description="Set this if the peer is more than 1 hop away") form.addField( 'nexthop', formal.String(), label="Next-Hop", description= "Set this to an IP if you want to rewrite the next-hop of routes coming in from this peer. This is useful for route servers." ) form.addAction(self.submitNeigh) return form
def formatTable(routes): rtab = [] for l in routes.split('\n'): if not l.strip(): continue ln = l.split() src = ln[0] data = {'via': '', 'device': '', 'type': ''} t = "" for n in ln: if t: data[t] = n if n == 'via': t = 'via' data['type'] = "Static" elif n == 'dev': t = 'device' if not data['type']: data['type'] = "Connected" else: t = "" print data if "kernel" in l: data['type'] = "System" rtab.append([ src, data['via'], data['device'], data['type'], ]) return ctx.tag[PageHelpers.dataTable( ['Destination', 'Next hop', 'Interface', 'Type'], rtab), ]
def returnMonthView(monthData): # Construct some sensible data. dateBlocks = {} order = [] for rows in monthData: yearMonth = "%s - %s" % (rows[0].year, rows[0].month) if yearMonth in dateBlocks: dateBlocks[yearMonth][0] += rows[1] dateBlocks[yearMonth][1] += rows[2] else: order.append(yearMonth) dateBlocks[yearMonth] = [rows[1], rows[2]] # flatten the dictionary flatBlocks = [] for date in order: values = dateBlocks[date] year = int(date.split()[0]) day = int(date.split()[1]) month = int(date.split()[2]) flatBlocks.append( (tags.a(href=url.root.child("ProxyUse").child("ShowDays"). child(year).child(day).child(month))[datetime.date( year, month, 1).strftime("%h %Y")], "%0.2fMB" % (values[0] / (1024 * 1024)), values[1])) return ctx.tag[ tags.h3[tags.img(src="/images/stock-download.png"), "Proxy Usage - Month Overview"], PageHelpers.dataTable( ['Date', 'Total Traffic', 'Sites Visited'], flatBlocks)]
def form_addVLAN(self, data): form = formal.Form() form.addField('interface', formal.String(required=True), formal.widgetFactory(formal.SelectChoice, options=[ (i, i) 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(strip=True, validators=[PageHelpers.IPValidator()]), 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
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
def form_vpnForm(self, data): """ OpenVPN (Vulani VPN) form""" form = formal.Form() form.addField('openvpn', formal.Boolean(), label = self.text.vpnLabelOpenvpn, description=self.text.vpnDescripOpenvpn) form.addField('iprange1', formal.String(required=True), label = self.text.vpnRangeStart) form.addField('iprange2', formal.String(required=True), label = self.text.vpnRangeTo) form.addField('mtu', formal.String(), label = self.text.vpnMTU) form.addField('WINS', formal.String(strip=True, validators=[PageHelpers.IPValidator()]), label = self.text.vpnWINSServer) form.addField('DNS', formal.String(), label = self.text.vpnDNSServer) form.addField('DOMAIN', formal.String(), label = self.text.vpnDomain) form.addField('tcp', formal.Boolean(), label = "Use TCP", description = "Use TCP instead of UDP for connections. Not recommended, but helps with connection issues from high packet-loss sites like GPRS or 3G, at the expense of performance. TCP port 1194 needs to be opened in the firewall for this to be successful") def returnForm(result): print result conf, routes = result form.addField( 'routes', formal.Sequence(formal.String()), formal.widgetFactory(formal.CheckboxMultiChoice, [(i,i) for i in routes]), label = self.text.vpnRoutesPush ) form.data = conf form.addAction(self.submitForm) return form return VPN.get_openvpn_settings(self.sysconf).addBoth(returnForm)
def render_content(self, ctx, data): return ctx.tag[ tags.h2[tags.img(src='/images/srvman.png'), self.text.compHeading], tags.h3[self.text.compHeadingList], PageHelpers.dataTable([self.text.compName, ''], self.getComputers( )), tags.h3[self.text.compHeadingAdd], tags.directive('form addComputer'), ]
def form_createMapping(self, ctx): def handleSubmit(ctx, form, data): if not data["userSelect"] and not data["user"]: raise formal.FormError( "Please provide a valid user entry to map to") if not data["addrSelect"] and not data["addr"]: raise formal.FormError("Please provide a valid address to map") user = data["userSelect"] and data["userSelect"] or data["user"] addr = data["addrSelect"] and data["addrSelect"] or data["addr"] r = self.sysconf.Reporting mappings = r.get('userMappings', {}) userEnt = mappings.get(user, []) userEnt.append(addr) mappings[user] = userEnt r["userMappings"] = mappings self.sysconf.Reporting = r 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 entries = [i for i in PageHelpers.getArp()] d = PageHelpers.resolveIP([i[0] for i in entries], True) d.addCallback(gotResolved) return d