python wifidog_auth_server.py
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python wifidog_auth_server.py相关的知识,希望对你有一定的参考价值。
#!/usr/bin/env python3
import collections
import signal
import time
import tornado.ioloop
import tornado.iostream
import tornado.log
import tornado.options
import tornado.tcpserver
import tornado.util
import tornado.web
TOKENS = collections.defaultdict(set)
class MainHandler(tornado.web.RequestHandler):
def get(self):
print(self.get_args())
def get_args(self):
return tornado.util.ObjectDict(
(k, self.get_argument(k))
for k in self.request.arguments
)
class PingHandler(MainHandler):
def get(self):
print(self.get_args())
self.write("Pong")
class LoginHandler(MainHandler):
def get(self):
"""
?gw_address=192.168.1.1&gw_port=2060&gw_id=dd0&url=http%3A//23.61.194.194/ncsi.txt
"""
args = self.get_args()
token = time.strftime("%H%M%S")
TOKENS[args.gw_id].add(token)
self.write("""<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<a href="http://{}:{}/wifidog/auth?token={}">LOGIN</a>""".format(
args.gw_address, args.gw_port, token))
class AuthHandler(MainHandler):
def get(self):
"""
?stage=counters&ip=192.168.1.124&mac=0C:30:21:CC:42:CD&token=XXX&incoming=14860&outgoing=10573&gw_id=dd0
"""
args = self.get_args()
authenticated = args.token in TOKENS[args.gw_id]
self.write("Auth: {}".format(int(authenticated)))
class PortalHandler(MainHandler):
def get(self):
self.write("ok")
class MessageHandler(MainHandler):
def get(self):
self.write(self.get_args())
class LogoutHandler(MainHandler):
def get(self):
args = self.get_args()
TOKENS[args.gw_id].discard(args.token)
self.write(str(TOKENS))
HANDLERS = [
(r"/ping/", PingHandler),
(r"/login/", LoginHandler),
(r"/auth/", AuthHandler),
(r"/portal/", PortalHandler),
(r"/gw_message.php", MessageHandler),
(r"/", MainHandler),
(r"/logout", LogoutHandler),
]
def run():
tornado.log.enable_pretty_logging()
io_loop = tornado.ioloop.IOLoop.instance()
tornado.web.Application(HANDLERS).listen(1026)
def _term(signal_number=None, stack_frame=None):
io_loop.stop()
signal.signal(signal.SIGTERM, _term)
try:
io_loop.start()
except KeyboardInterrupt:
_term()
if __name__ == "__main__":
run()
以上是关于python wifidog_auth_server.py的主要内容,如果未能解决你的问题,请参考以下文章
001--python全栈--基础知识--python安装
Python代写,Python作业代写,代写Python,代做Python
Python开发
Python,python,python
Python 介绍
Python学习之认识python