Ejemplo n.º 1
0
 def send_resp(resp):
     if resp:
         self.transport.write(str(resp), (host, port))
         print pktutils.hexdump(str(resp), len(resp))
         self.syslog.debug(":: Send response to %s:%s: %s" % (host, port, repr(resp)))
Ejemplo n.º 2
0
        elif 'huaweiv1' in self.config.ac.vendor:
            return huawei.Portal(secret=self.config.ac.key, packet=datagram, source=(host, port))
        elif 'huaweiv2' in self.config.ac.vendor:
            return huawei.PortalV2(secret=self.config.ac.key, packet=datagram, source=(host, port))
        else:
            raise ACError("vendor {0} not support".format(self.config.ac.vendor))

    def datagramReceived(self, datagram, (host, port)):
        def send_resp(resp):
            if resp:
                self.transport.write(str(resp), (host, port))
                print pktutils.hexdump(str(resp), len(resp))
                self.syslog.debug(":: Send response to %s:%s: %s" % (host, port, repr(resp)))

        try:
            print pktutils.hexdump(datagram, len(datagram))
            request = self.parse(datagram, (host, port))
            self.syslog.debug(":: Received portal packet from %s:%s: %s" % (host, port, repr(request)))
            resp_deferd = self.ac_handlers[request.type].process(request)
            resp_deferd.addCallback(send_resp)
        except Exception as err:
            self.syslog.error(':: Dropping invalid packet from %s: %s' % ((host, port), str(err)))
            import traceback
            traceback.print_exc()

    def on_exception(self, err):
        self.syslog.error(':: Packet process error:%s' % str(err))

    def run_normal(self):
        self.syslog.info('running ac server')
        reactor.listenUDP(int(self.config.ac.port), self)