def submitVlan(self, ctx, form, data): ifaces = self.sysconf.EthernetDevices if '/' in data['ip']: ip = data['ip'] network = Utils.getNetwork(ip) else: if "." in data['netmask']: cidr = Utils.netmask2cidr(data['netmask']) ip = "%s/%s" % (data['ip'], cidr) network = Utils.getNetwork(ip) else: ip = "%s/%s" % (data['ip'], data['netmask']) network = Utils.getNetwork(ip) defn = { 'ip': ip.encode("ascii", "replace"), 'network': network.encode("ascii", "replace"), 'interface': data['interface'].encode("ascii", "replace"), 'dhcpserver': data['dhcpserver'] } ifaces['vlan%s' % data['vlan']] = defn self.sysconf.EthernetDevices = ifaces WebUtils.restartNetworking(data['dhcpserver']) return url.root.child('Network')
def submitForm(self, ctx, form, data): ifaces = self.sysconf.EthernetDevices iface = data['interface'].encode("ascii", "replace") if '/' in data['ip']: ip = data['ip'] network = Utils.getNetwork(ip) else: if "." in data['netmask']: cidr = Utils.netmask2cidr(data['netmask']) ip = "%s/%s" % (data['ip'], cidr) network = Utils.getNetwork(ip) else: ip = "%s/%s" % (data['ip'], data['netmask']) network = Utils.getNetwork(ip) defn = { 'ip': ip, 'network': network, 'type': 'static', 'dhcpserver': data['dhcpserver'] } if (data['mtu'] > 1200) and (data['mtu'] < 1501): defn['mtu'] = data['mtu'] if data['dhcpserver']: d = self.sysconf.DHCP if not d.get(iface): d[iface] = {} self.sysconf.DHCP = d if data.get('ipv6', False): defn['ipv6'] = data['ipv6'].encode("ascii", "replace") defn['ipv6adv'] = data['ipv6adv'] if data['dhcp']: defn['type'] = 'dhcp' else: defn['type'] = 'static' ifaces[iface] = defn self.sysconf.EthernetDevices = ifaces WebUtils.restartNetworking(data['dhcpserver']) return url.root.child('Network')
def submitForm(self, ctx, form, data): if data['ipAlias']: aliases = data['ipAlias'].encode("ascii", "replace").replace(' ', '').split(',') else: aliases = [] if data['ip']: ip = data['ip'].strip().encode("ascii", "replace") else: ip = "" if data['dhcp']: type = "dhcp" else: type = "static" if data['netmask']: network = data['netmask'].strip().encode("ascii", "replace") elif data['ip']: # make a foney /24 network if we don't know wtf is going on network = '.'.join(ip.split('.')[:3]) + '.0/24' else: # ok we're just boned, save and carry on network = "" iFaces = copy.deepcopy(self.sysconf.EthernetDevices) thisIf = iFaces.get(self.iface, {}) thisIf['dhcpserver'] = data['dhcpserver'] thisIf['type'] = type thisIf['ip'] = ip # set the defualt route routes = thisIf.get('routes', []) rDict = dict(routes) if data['gateway']: fGateway = data['gateway'].encode("ascii", "replace") # Remove any other default routes because one is set here for dev, conf in self.sysconf.EthernetDevices.items(): if dev == self.iface: # Skip configured interface here continue oldRoutes = conf.get('routes', []) newRoutes = [] skip = True for dst, gw in oldRoutes: if dst == "default": skip = False continue newRoutes.append((dst, gw)) if not skip: iFaces[dev]['routes'] = newRoutes else: fGateway = "" if fGateway: rDict['default'] = fGateway elif rDict.get('default'): del rDict['default'] newRoutes = [i for i in rDict.items()] if newRoutes: thisIf['routes'] = newRoutes elif thisIf.get('routes'): del thisIf['routes'] # Continue config thisIf['network'] = network thisIf['aliases'] = aliases if (data['mtu'] > 1200) and (data['mtu'] < 1501): thisIf['mtu'] = data['mtu'] if data.get('ipv6', False): thisIf['ipv6'] = data['ipv6'].encode("ascii", "replace") thisIf['ipv6adv'] = data['ipv6adv'] iFaces[self.iface] = thisIf self.sysconf.EthernetDevices = iFaces lp = self.sysconf.LANPrimary newLP = lp if data['interior']: if self.iface not in lp: newLP.append(self.iface) self.sysconf.LANPrimary = newLP else: if self.iface in lp: newLP = [] for k in lp: if k != self.iface: newLP.append(k) self.sysconf.LANPrimary = newLP # Perform shorewall configuration shoreWall = copy.deepcopy(self.sysconf.Shorewall) shoreWall['zones'][ data['firewallZone']]['policy'] = data['firewallPolicy'] # check the interface isn't there ifaceZone = shoreWall['zones'][data['firewallZone']]['interfaces'] for cnt, iface in enumerate(ifaceZone): if self.iface in iface: del shoreWall['zones'][data['firewallZone']]['interfaces'][cnt] shoreWall['zones'][data['firewallZone']]['interfaces'].append( '%s detect dhcp,routeback' % (self.iface)) # Delete interface from other zones for zone in shoreWall['zones']: if zone != data['firewallZone']: ifaceDefs = [] for i in shoreWall['zones'][zone]['interfaces']: if self.iface not in i: ifaceDefs.append(i) shoreWall['zones'][zone]['interfaces'] = ifaceDefs self.sysconf.Shorewall = shoreWall # Clear old aliases out of system oldAliases = self.sysconf.EthernetDevices.get(self.iface, {}).get('aliases', []) for addr in oldAliases: if addr not in aliases: WebUtils.system('ip addr del %s dev %s' % (i, self.iface)) WebUtils.restartNetworking(data['dhcpserver']) return url.root.child('Network')