mirror of
https://github.com/barronwaffles/dwc_network_server_emulator.git
synced 2026-07-14 15:12:09 -05:00
I've decided to impliment a new feature into the server (disabled by default in nas_server.py) where when enabled, the server will check if a console's MAC is in BOTH the registered and pending database tables. If this is not the case, one of two error codes will be returned: error 23888 - Console pending activation by server admin error 23921 - Unknown console A registration page was also included on port 9998 for users to enter their MAC and add it to the pending table. The server admin can then log in to the admin page and activate the console if they so please.
127 lines
4.1 KiB
Python
127 lines
4.1 KiB
Python
# DWC Network Server Emulator
|
|
# Copyright (C) 2014 SMTDDR
|
|
# Copyright (C) 2014 kyle95wm
|
|
# Copyright (C) 2014 AdmiralCurtiss
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from twisted.web import server, resource
|
|
from twisted.internet import reactor
|
|
from twisted.internet.error import ReactorAlreadyRunning
|
|
import base64
|
|
import codecs
|
|
import sqlite3
|
|
import collections
|
|
import json
|
|
import time
|
|
import datetime
|
|
import other.utils as utils
|
|
import gamespy
|
|
import gamespy.gs_utility as gs_utils
|
|
|
|
class RegPage(resource.Resource):
|
|
isLeaf = True
|
|
|
|
def __init__(self,regpage):
|
|
self.regpage = regpage
|
|
|
|
def get_header(self, title = None):
|
|
if not title:
|
|
title = 'Register a Console'
|
|
s = (
|
|
'<html>'
|
|
'<head>'
|
|
'<title>' + title + '</title>'
|
|
'</head>'
|
|
'<body>'
|
|
'<p>'
|
|
'<a href="/register">Register a Console</a>'
|
|
'</p>'
|
|
)
|
|
return s
|
|
|
|
def get_footer(self):
|
|
s = (
|
|
'</body>'
|
|
'</html>'
|
|
)
|
|
return s
|
|
|
|
def update_maclist(self, request):
|
|
address = request.getClientIP()
|
|
dbconn = sqlite3.connect('gpcm.db')
|
|
macadr = request.args['macadr'][0].strip()
|
|
actiontype = request.args['action'][0]
|
|
if not macadr.isalnum():
|
|
request.setResponseCode(500)
|
|
logger.log(logging.INFO,address+" Bad data "+macadr+" ")
|
|
return "Bad data"
|
|
if actiontype == 'add':
|
|
dbconn.cursor().execute('insert into pending values(?)',(macadr,))
|
|
responsedata = "Added %s to pending list. Your application may take anywhere from 24 to 48 hours." % (macadr)
|
|
dbconn.commit()
|
|
dbconn.close()
|
|
request.setHeader("Content-Type", "text/html; charset=utf-8")
|
|
request.setResponseCode(303)
|
|
return responsedata
|
|
if not referer:
|
|
referer = "/register"
|
|
request.setHeader("Location", referer)
|
|
|
|
request.setResponseCode(303)
|
|
return responsedata
|
|
|
|
def render_maclist(self, request):
|
|
address = request.getClientIP()
|
|
dbconn = sqlite3.connect('gpcm.db')
|
|
responsedata = (""
|
|
"<form action='updatemaclist' method='POST'>"
|
|
"macadr (must be in the format of aabbccddeeff):<input type='text' name='macadr'>\r\n"
|
|
"<input type='hidden' name='action' value='add'>\r\n"
|
|
"<input type='submit' value='Register console'></form>\r\n"
|
|
"<table border='1'>"
|
|
"")
|
|
dbconn.close()
|
|
request.setHeader("Content-Type", "text/html; charset=utf-8")
|
|
return responsedata
|
|
|
|
def render_GET(self, request):
|
|
title = None
|
|
response = ''
|
|
if request.path == "/register":
|
|
title = 'Register a Console to ALTWFC'
|
|
response = self.render_maclist(request)
|
|
|
|
return self.get_header(title) + response + self.get_footer()
|
|
|
|
def render_POST(self, request):
|
|
if request.path == "/updatemaclist":
|
|
return self.update_maclist(request)
|
|
else:
|
|
return self.get_header() + self.get_footer()
|
|
|
|
port = 9998
|
|
class RegPageServer(object):
|
|
def start(self):
|
|
site = server.Site(RegPage(self))
|
|
reactor.listenTCP(port, site)
|
|
try:
|
|
if reactor.running == False:
|
|
reactor.run(installSignalHandlers=0)
|
|
except ReactorAlreadyRunning:
|
|
pass
|
|
|
|
if __name__ == "__main__":
|
|
RegPageServer().start()
|