def locateChild(self, ctx, segs): if segs[0] == "Edit": return EditPage(self.avatarId, self.db, segs[1]), () if segs[0] == "Delnet": Utils.log.msg('%s deleted shared DHCP net %s' % (self.avatarId.username, segs[1])) nets = self.sysconf.DHCP try: del nets[segs[1]] except: pass self.sysconf.DHCP = nets # Disable it on the interface too Eths = self.sysconf.EthernetDevices Eths[segs[1]]['dhcpserver'] = False self.sysconf.EthernetDevices = Eths return WebUtils.restartService('dhcp').addBoth( lambda _: url.root.child('Dhcp')), () if segs[0] == "CreateLease": data = {'mac': segs[1], 'ip': segs[2], 'hostname': segs[3]} DHCP.create_lease(self.sysconf, data) return WebUtils.restartService('dhcp').addBoth( lambda _: url.root.child('Dhcp')), () return rend.Page.locateChild(self, ctx, segs)
def submitZone(self, ctx, form, data): G = self.sysconf.General # save form to zone options options = [] if data['master']: options.append('type master') else: options.append('type slave') if data['notify']: options.append('notify yes') else: options.append('notify no') G['zones'][self.domain]['options'] = options G['zones'][self.domain]['update'] = data['update'].encode().replace( ' ', '').split(',') G['zones'][self.domain]['ns'] = data['ns'].encode().replace( ' ', '').split(',') self.sysconf.General = G def returnRoot(_): print _ return url.root.child('DNS').child('Edit').child(self.domain) return WebUtils.restartService('bind').addCallback(returnRoot)
def submitZone(self, ctx, form, data): G = self.sysconf.General # save form to zone options type = data['master'] and "master" or "slave" options = ['type %s' % type] if data['forward']: type = 'forward' options = ['type %s' % type] G['zones'][self.domain]['forward'] = data['forward'] else: G['zones'][self.domain]['forward'] = [] if data['notify']: options.append('notify yes') else: options.append('notify no') G['zones'][self.domain]['options'] = options G['zones'][self.domain]['update'] = data['update'].encode("ascii", "replace").replace(' ','').split(',') G['zones'][self.domain]['ns'] = data['ns'].encode("ascii", "replace").replace(' ','').split(',') self.sysconf.General = G def returnRoot(_): print _ return url.root.child('DNS')#.child('Edit').child(self.domain) return WebUtils.restartService('bind').addCallback(returnRoot)
def submitZone(self, ctx, form, data): D = self.sysconf.General type = data['master'] and "master" or "slave" options = ['type %s' % type, 'notify no'] if data['forward']: type = 'forward' options = ['type %s' % type] if data['update']: update = ['127.0.0.1', data['update'].encode()] else: update = ['127.0.0.1'] defaultZone = { 'update': update, 'options': options, 'ns': [self.sysconf.ExternalName], 'records': [], 'forward': data['forward'] } if D.get('zones'): D['zones'][data['zone'].encode()] = defaultZone else: D['zones'] = {data['zone'].encode(): defaultZone} self.sysconf.General = D def next(_): return url.root.child('DNS') return WebUtils.restartService('bind').addBoth(next)
def submitRecForm(self, ctx, form, data): G = self.sysconf.General if data['type'] == "MX": if not data['prio']: data['prio'] = 1 # Check users blood alcohol level if not data['host']: host = "%s." % self.domain else: host = data['host'].encode().strip('.') if self.domain in host: host = "%s." % self.domain record = "%(host)s %(type)s%(prio)s %(data)s" % { "type": data['type'].encode(), "prio": data['prio'] and " %s" % data['prio'] or "", "host": host, "data": data['data'].encode() } G['zones'][self.domain]['records'].append(record) self.sysconf.General = G def returnRoot(_): print _ return url.root.child('DNS').child('Edit').child(self.domain) return WebUtils.restartService('bind').addCallback(returnRoot)
def submitVhost(self, ctx, form, data): D = self.sysconf.General self.sysconf.General = D def res(_): return url.root.child('Webserver') return WebUtils.restartService('bind').addCallbacks(res, res)
def set_dhcp_config(sysconf, data, iface): config = sysconf.DHCP nc = {} for i,v in data.items(): nc[i] = v config[iface] = nc sysconf.DHCP = config return WebUtils.restartService('dhcp')
def locateChild(self, ctx, segs): if segs[0] == "Delete": G = self.sysconf.General print self.avatarId.username, " deleting zone ", segs[1] del G['zones'][segs[1]] self.sysconf.General = G def null(_): return url.root.child('DNS'), () return WebUtils.restartService('bind').addCallbacks(null, null) return PageHelpers.DefaultPage.locateChild(self, ctx, segs)
def submitNSForm(self, ctx, form, data): Utils.log.msg('%s changed forwarding nameservers %s' % (self.avatarId.username, repr(data))) forward = data['forward'].replace(' ', '').replace('\n', '').replace('\r', '').split(',') self.sysconf.ForwardingNameservers = forward gen = self.sysconf.General sysresolv = data['sysresolv'].replace(' ', '').replace('\n', '').replace('\r', '').split(',') gen['sysresolv'] = sysresolv self.sysconf.General = gen def res(_): return url.root.child('DNS') return WebUtils.restartService('bind').addCallbacks(res, res)
def submitTunnel(self, ctx, form, data): tun = self.sysconf.Tunnel tun['ipv6'] = { 'remoteip': data['remoteip'], 'localip': data['localip'], 'localv6': data['localv6'] } self.sysconf.Tunnel = tun WebUtils.restartService('debnet', either='net') remote = data['remoteip'] local = data['localip'] localv6 = data['localv6'] cont = [] cont.append('ip tun del ipv6tun;') cont.append( 'ip tunnel add ipv6tun mode sit remote %s local %s ttl 255; ' % (remote, local)) cont.append('ip link set ipv6tun up; ') cont.append('ip addr add %s dev ipv6tun; ' % (localv6)) cont.append('ip -6 ro add 2003::/3 dev ipv6tun') WebUtils.system(''.join(cont)) return url.root.child('Network')
def locateChild(self, ctx, segs): if '.' in segs[0] and len(segs) < 3: return EditDNS(self.avatarId, self.db, segs[0]), () if len(segs)>1 and segs[1] == "Delete": G = self.sysconf.General print self.avatarId.username, " deleting zone record", G['zones'][segs[0]]['records'][int(segs[2])] del G['zones'][segs[0]]['records'][int(segs[2])] self.sysconf.General = G def null(_): print "Restart done" return url.root.child('DNS').child('Edit').child(segs[0]), () return WebUtils.restartService('bind').addBoth(null) return url.root.child('DNS'), ()
def set_windows_vpn(sysconf, data, callback): """ Configures Windows PPTP VPN Passthrough Returns a C{deferred} which will fire [callback] when complete @param sysconf: An instance of L{Core.confparse.Config} @param data: A dictionary of data options. This module requres the following 'windows': C{bool} whether or not this configuration will handle PPTP passthrough 'winip': C{str} of the IP address for the windows server 'winextip': C{str} for external IP address from which to forward these connections @param callback: C{function} which will be returned once this (potential) deferred chain is complete """ confdata = sysconf.Shorewall rset = confdata.get('rules', []) rule = "DNAT net loc:%s 47 - - %s" % ( data['winip'] or "", data['winextip'] or "") rule2 = "DNAT net loc:%s tcp 1723 - %s" % ( data['winip'] or "", data['winextip'] or "") # Find such a rule and strip it: rsetnew = [] for en, ru in rset: rusp = ru.split() try: if "DNAT" == rusp[0] and "47" == rusp[3]: exists = True elif "DNAT" == rusp[0] and "1723" == rusp[4]: exists = True else: exists = False except: exists = False if not exists: rsetnew.append([en, ru]) if data['windows']: rsetnew.append([1, rule.encode()]) rsetnew.append([1, rule2.encode()]) confdata['rules'] = rsetnew sysconf.Shorewall = confdata return WebUtils.restartService('shorewall').addBoth(callback)
def returnAction(self, data): return WebUtils.restartService('dhcp').addBoth( lambda _: url.root.child('Dhcp'))