This repository has been archived by the owner on Dec 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHandler.py
71 lines (65 loc) · 2.41 KB
/
Handler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#
# EmulatorFrontier Ptototype Server
# Copyright (C) 2018 Arves100
#
# 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 http.server import HTTPHandler
from http.data import HTTPData
import Logger
import Features
import Config
class BraveHandler(HTTPHandler):
def Send404(self):
http = HTTPData()
http.AppendData('<h1>404: Not found</h1>')
http.SetError(404)
self.client.SendHTTPData(http)
self.client.Close()
def OnHTTPRead(self, data):
if data.GetRequest() == 'GET':
self.DoGET(data)
elif data.GetRequest() == 'POST':
self.DoPOST(data)
else:
Logger.PrintError('Unknown request %s from %s' % (data.GetRequest(), self.client.GetAddress()))
self.client.Close()
def DoGET(self, data):
if data.GetLocation() == '/bf/web/terms.htm':
Features.SendTerms(self.client)
elif data.GetLocation() == '/bf/gme/action/Dynamic_background.php':
http = HTTPData()
http.AppendData(Features.Base64Crypt(Config.GetWallpaper()))
http.SetContentType('application/json')
self.client.SendHTTPData(http)
elif data.GetLocation() == '/shutdown_server':
if self.client.GetAddress() == '127.0.0.1':
http = HTTPData()
http.AppendData('Shutting down...')
self.client.SendHTTPData(http)
self.client.Close()
self.StopServer()
else:
self.Send404()
else:
Logger.PrintError('Unknown location %s from %s' % (data.GetLocation(), self.client.GetAddress()))
self.Send404()
def DoPOST(self, data):
if data.GetLocation() == '/bf/gme/action/Dynamic_background.php':
http = HTTPData()
http.AppendData(Features.Base64Crypt(Config.GetWallpaper()))
http.SetContentType('application/json')
self.client.SendHTTPData(http)
else:
Logger.PrintError('Unknown location %s from %s' % (data.GetLocation(), self.client.GetAddress()))
self.Send404()