forked from michrob/bitboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitboard.py
More file actions
194 lines (137 loc) · 6.29 KB
/
bitboard.py
File metadata and controls
194 lines (137 loc) · 6.29 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import web
from bitmessage_gateway import gateway_instance as nexus
import config
import math
import themes
import os
import signal
t_globals = dict(
math=math,
bitmessage=nexus,
datestr=web.datestr,
themes=themes.themes,
config=config)
urls = (
'/delete/*(.+)', 'Delete',
'/images/*(.+)', 'Images',
'/join/*(.+)', 'Join',
'/board/*(.+)', 'Board',
'/catalog/*(.+)', 'Catalog',
'/thread/*(.+)', 'Thread',
'/*(.+)', 'Index'
)
render = web.template.render('templates/', cache=config.cache, globals=t_globals)
render._keywords['globals']['render'] = render
render._keywords['globals']['bitmessage'] = nexus
app = web.application(urls, globals())
app.daemon = True
app.internalerror = web.debugerror
class Delete:
def __init__(self):
pass
def GET(self, url):
web_input = web.input(chan=None, threadid=None, messageid=None)
render._keywords['globals']['model'] = {"current_thread": web_input.threadid,
"current_chan": web_input.chan}
render._keywords['globals']['model']['status_message'] = None
if web_input.messageid:
result = nexus.deleteMessage(web_input.chan, web_input.messageid)
render._keywords['globals']['model']['status_message'] = result
render._keywords['globals']['model']['status_title'] = "Deleted Message"
if web_input.threadid:
result = nexus.deleteThread(web_input.chan, web_input.threadid)
render._keywords['globals']['model']['status_message'] = result
render._keywords['globals']['model']['status_title'] = "Deleted Thread"
return render.base(render.pages.alert())
class Images:
def __init__(self):
pass
def GET(self, url):
web_input = web.input(image=None)
return nexus.getImage(web_input.image)
class Join:
def __init__(self):
pass
def POST(self, url):
web_input = web.input(chan=None, passphrase=None)
render._keywords['globals']['model'] = {"current_chan": web_input.chan}
result = nexus.joinChan(web_input.passphrase)
render._keywords['globals']['model']['status_title'] = "Success"
render._keywords['globals']['model']['status_message'] = result
return render.base(render.pages.alert())
class Board:
def __init__(self):
pass
def GET(self, url):
web_input = web.input(chan=None, page=1, threadid=None, theme=None)
if not web_input.chan:
raise web.seeother("/")
render._keywords['globals']['model'] = {"current_thread": web_input.threadid,
"current_page": web_input.page,
"current_chan": web_input.chan}
return render.base(render.pages.board())
def POST(self, url):
web_input = web.input(chan=None, subject="", body="", image=None, theme=None)
if web_input.theme:
config.theme = web_input.theme
raise web.seeother(web.ctx.query)
render._keywords['globals']['model'] = {"current_chan": web_input.chan}
if not web_input.chan:
render._keywords['globals']['model']['status_message'] = "You must post to a valid chan!"
elif len(web_input.subject.strip()) == 0 or len(web_input.body.strip()) == 0:
render._keywords['globals']['model']['status_message'] = "You must include a subject and message."
if "status_message" in render._keywords['globals']['model']:
render._keywords['globals']['model']['status_title'] = "Uh oh, something went wrong!"
return render.base(render.pages.alert())
result = nexus.submitPost(web_input.chan, web_input.subject, web_input.body, web_input.image)
render._keywords['globals']['model']['status_title'] = "Success"
render._keywords['globals']['model']['status_message'] = result
return render.base(render.pages.alert())
class Thread:
def __init__(self):
pass
def GET(self, url):
web_input = web.input(chan=None, threadid=None, theme=None)
render._keywords['globals']['model'] = {"current_thread": web_input.threadid,
"current_chan": web_input.chan}
if not web_input.chan:
raise web.seeother("/")
return render.base(render.pages.thread())
def POST(self, url):
web_input = web.input(chan=None, subject="", body="", image=None, theme=None)
if web_input.theme:
config.theme = web_input.theme
raise web.seeother(web.ctx.query)
render._keywords['globals']['model'] = {"current_thread": web_input.threadid,
"current_chan": web_input.chan}
if not web_input.chan:
render._keywords['globals']['model']['status_message'] = "You must post to a valid chan!"
elif len(web_input.subject.strip()) == 0 or len(web_input.body.strip()) == 0:
render._keywords['globals']['model']['status_message'] = "You must include a subject and message."
if "status_message" in render._keywords['globals']['model']:
render._keywords['globals']['model']['status_title'] = "Uh oh, something went wrong!"
return render.base(render.pages.alert())
result = nexus.submitPost(web_input.chan, web_input.subject, web_input.body, web_input.image)
render._keywords['globals']['model']['status_title'] = "Success"
render._keywords['globals']['model']['status_message'] = result
return render.base(render.pages.alert())
class Index:
def __init__(self):
pass
def POST(self, url):
web_input = web.input(theme=None)
if web_input.theme:
config.theme = web_input.theme
raise web.seeother(web.ctx.query)
def GET(self, url):
render._keywords['globals']['model'] = {}
status = nexus.getAPIStatus()
if not status == True:
render._keywords['globals']['model']['status_title'] = "Success"
render._keywords['globals']['model']['status_message'] = status
return render.base(render.pages.index())
def signal_handler(signal, frame):
os._exit(0)
if __name__ == "__main__":
signal.signal(signal.SIGINT, signal_handler)
app.run()