Exemplo n.º 1
0
    def locateChild(self, ctx, segments):
        sysconf = confparse.Config()
        req = inevow.IRequest(ctx)
        host = req.received_headers.get('x-forwarded-for', req.client.host)

        # Trace back our topology and find our closest interface to this host
        iface, zone, network, routed = Utils.traceTopology(sysconf, host)
        ipserv = sysconf.EthernetDevices[iface]['ip'].split('/')[0]

        return url.URL.fromString('http://%s:9682/myvulani/%s' %
                                  (ipserv, '/'.join(segments))), ()
Exemplo n.º 2
0
            def returnAuth(res):
                # Trace back our topology and find our closest interface to this host
                iface, zone, network, routed = Utils.traceTopology(
                    self.sysconf, host)
                ipserv = self.sysconf.EthernetDevices[iface]['ip'].split(
                    '/')[0]
                print res, user, passw, ipserv, iface, zone, network, routed, host
                if res:
                    print "Ok bitch"

                    # Add our record to the zone
                    def done(mac):
                        print "User has this MAC", mac
                        l = open('/tmp/caportal/%s' % host, 'wt')
                        l.write("%s|%s|%s" %
                                (time.time(), mac.strip('\n'), user))
                        l.close()
                        os.chmod('/tmp/caportal/%s' % host, 0777)
                        print "Resturning person to ", segments
                        #return url.URL.fromString('http://%s' % ('/'.join(segments[1:])))
                        return RefreshTo(url='http://%s' %
                                         ('/'.join(segments[1:])))

                    def next(_):
                        print "Added shorewall, going to ARP check"
                        return WebUtils.system(
                            "arp -n | grep %s | awk '{print $3}'" %
                            host).addBoth(done)

                    return WebUtils.system(
                        'shorewall add %s:%s c%s' %
                        (iface, host, zone)).addBoth(next), ()

                print "Invalid authentication from", user, ":", repr(res)

                return Portal(self.host, self.url,
                              "Invalid username or password."), ()