Exemple #1
0
    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(),
            'network': network.encode(),
            'interface': data['interface'].encode(),
            'dhcpserver': data['dhcpserver']
        }

        ifaces['vlan%s' % data['vlan']] = defn

        self.sysconf.EthernetDevices = ifaces

        if os.path.exists('/etc/debian_version'):
            WebUtils.system('/usr/local/tcs/tums/configurator --debnet')
        else:
            WebUtils.system('/usr/local/tcs/tums/configurator --net')
        return url.root.child('Network')
Exemple #2
0
    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')
Exemple #3
0
    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')
Exemple #4
0
    def submitForm(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,
            'network': network,
            'type': 'static',
            'dhcpserver': data['dhcpserver']
        }

        if data.get('ipv6', False):
            defn['ipv6'] = data['ipv6'].encode()
            defn['ipv6adv'] = data['ipv6adv']

        if data['dhcp']:
            defn['type'] = 'dhcp'
        else:
            defn['type'] = 'static'

        ifaces[data['interface']] = defn

        self.sysconf.EthernetDevices = ifaces
        if os.path.exists('/etc/debian_version'):
            WebUtils.system('/usr/local/tcs/tums/configurator --debnet')
        else:
            WebUtils.system('/usr/local/tcs/tums/configurator --net')
        return url.root.child('Network')
Exemple #5
0
    def writeConfig(self, *a):
        lans = Utils.getLanNetworks(config)
        extramain = config.DHCP.get('main','')
        
        ips = Utils.getLanIPs(config)
        myIp = ips[0]
        rev = '.'.join([i for i in reversed(myIp.split('.')[:3])])

        ifaces = []
        
        dhcpconf = """# DHCPD config generated by TUMS Configurator
ddns-update-style interim;
default-lease-time 21600;
max-lease-time 21600;
allow booting;
allow bootp;
authoritative;
log-facility local7;

zone %(domain)s. {
    primary 127.0.0.1;
}

zone %(rev)s.in-addr.arpa. {
    primary 127.0.0.1;
}

option local-pac-server code 252 = text;

%(extramain)s
"""     % {
            'extramain': extramain, 
            'domain': config.Domain,
            'rev': rev
        }
        
        n = 0 
        for k,v in lans.items():
            myNet = v
            myIp = config.EthernetDevices[k].get('ip', '/').split('/')[0]
            
            dhcpConf = config.DHCP.get(k, {})
            
            if not myIp:
                # No IP set for this interface (is DHCP itself)
                continue 
            if not config.EthernetDevices[k].get('dhcpserver'):
                # Not set to do DHCP
                continue
            
            ifaces.append(k)

            statics = ""
            
            for ip, hostmac in config.DHCP.get('leases',{}).items():
                if Utils.matchIP(myNet, ip):
                    # make sure the IP is in this network
                    host, mac = hostmac
                    statics += """    host %s {
            fixed-address %s;
            hardware ethernet %s;
        }\n""" % (host, ip, mac)
            
            myNetmask = Utils.cidr2netmask(myNet.split('/')[1])
            
            rangeStart  = dhcpConf.get('rangeStart', "100")
            rangeEnd    = dhcpConf.get('rangeEnd', "240")

            netmask     = dhcpConf.get('netmask', myNetmask)
            netbios     = dhcpConf.get('netbios', myIp)
            nameserver  = dhcpConf.get('nameserver', myIp)
            router      = dhcpConf.get('gateway', myIp)
            myNet       = dhcpConf.get('network', Utils.getNetwork(config.EthernetDevices[k]['ip']))
            domain      = dhcpConf.get('domain', config.Domain)
            if not '/' in myNet:
                # AAAAAAAAAAAARGH GOD DAMN DIE IN HELL PAUL VIXIE
                cdr = Utils.netmask2cidr(netmask)
                myNet = "%s/%s" % (myNet, cdr)
                bcast       = Utils.getBroadcast(myNet)
            else:
                bcast = Utils.getBroadcast(myNet)
            
            # allow custom configuration options
            custom = dhcpConf.get('custom', '')
            
            netL = '.'.join(myNet.split('.')[:3])

            if not ("." in rangeStart):
                rangeStart = "%s.%s" % (netL, rangeStart)
                rangeEnd = "%s.%s" % (netL, rangeEnd)

            defn = {
                'netname': 'DHCP%s' % k.upper(),
                'myIp': myIp,
                'pacIp': myIp.replace('.', '-'),
                'domain': domain,
                'network': netL,
                'networkF': myNet.split('/')[0],
                'static': statics,
                'custom': custom,
                'netmask': netmask,
                'rangeStart': rangeStart,
                'rangeEnd': rangeEnd,
                'myNetbios': netbios,
                'myDns': nameserver,
                'myRouter': router,
                'extramain': extramain,
                'bcast': bcast
            }
            
            dhcpnet = """
shared-network %(netname)s {
    use-host-decl-names           on;
    option domain-name            "%(domain)s";
    option domain-name-servers    %(myDns)s;
    
    option netbios-name-servers   %(myNetbios)s;
    option netbios-node-type      8;

    option local-pac-server "http://%(myIp)s/wpad-%(pacIp)s.pac"; 

    option ntp-servers            %(myIp)s;
    option time-servers           %(myIp)s;
    option log-servers            %(myIp)s;
    option font-servers           %(myIp)s;
    option pop-server             %(myIp)s;
    option smtp-server            %(myIp)s;
    option x-display-manager      %(myIp)s;
    
    subnet %(networkF)s netmask %(netmask)s {
        range dynamic-bootp           %(rangeStart)s %(rangeEnd)s;
        option subnet-mask            %(netmask)s;
        option broadcast-address      %(bcast)s;
        option routers                %(myRouter)s;
    }
%(static)s
%(custom)s
}\n"""      % defn
            
            dhcpconf += dhcpnet
        
        # Check for debianism (goes in /etc/dhcp3)
        f = open('/etc/dhcp3/dhcpd.conf', 'wt')
        f.write(dhcpconf)
        f.close()

        f = open('/etc/default/dhcp3-server', 'wt')
        f.write('# On what interfaces should the DHCP server (dhcpd) serve DHCP requests?\n')
        f.write('#       Separate multiple interfaces with spaces, e.g. "eth0 eth1".\n')
        f.write('INTERFACES="%s"\n' % ' '.join(ifaces))
        f.close()