-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
68 lines (53 loc) · 2.31 KB
/
admin.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
#!/usr/bin/env python
# $Id: $
import wsgiref.handlers
import cgi
import radupdater
from radupdater import Settings
from radupdater import UpdateInfo
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.api import users
class MainHandler(webapp.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
if not users.is_current_user_admin():
self.redirect(users.create_logout_url("/noaccess"))
return
if self.request.get("set_version") != "":
new_version = self.request.get('new_version')
if new_version != '':
settings = Settings(key_name = "current_version", value = new_version)
settings.put();
new_site = self.request.get("new_site")
if new_site != '':
settings = Settings(key_name = "current_site", value = new_site)
settings.put();
new_motd = self.request.get("new_motd")
if new_motd != '':
settings = Settings(key_name = "current_motd", value = new_motd)
settings.put();
new_display_motd = self.request.get("new_display_motd")
settings = Settings(key_name = "current_display_motd", value = ("false", "true")[new_display_motd != ""])
settings.put();
info = UpdateInfo()
self.response.out.write(
template.render('templates/adm_main.html', {
"version": cgi.escape(info.CurrentVersion),
"site": cgi.escape(info.DownloadSite),
"motd": cgi.escape(info.MOTD),
"display_motd": ("", " checked")[info.DisplayMOTD],
"logouturl": users.create_logout_url("/")
}))
return
else:
self.redirect(users.create_login_url(self.request.uri))
return
def main():
app = webapp.WSGIApplication([
(r'/admin/', MainHandler),
], debug=False)
wsgiref.handlers.CGIHandler().run(app)
if __name__ == '__main__':
main()