]>
jfr.im git - irc/quakenet/qwebirc.git/blob - qwebirc/engines/adminengine.py
1 from twisted
.web
import resource
, server
, static
3 from urllib
import urlencode
4 import config
, copy
, time
7 <html><head><link rel="stylesheet" href="/css/qui.css"></link><link rel="stylesheet" href="/css/dialogs.css"></link></head><body class="qwebirc-qui">
8 <div class="qwebirc-aboutpane lines" style="bottom: 0px; top: 0px; position: absolute; right: 0px; left: 0px;">
12 <td><img src="/images/qwebircsmall.png" alt="qwebirc" title="qwebirc"/></td>
13 <td> </td>
14 <td align="center"><div class="title">qwebirc</div><div class="version">AdminEngine</div></td>
18 <div class="mainbody" style="bottom: 100px">
21 FOOTER
= """</div></body></html>"""
23 class AdminEngineException(Exception):
26 class AdminEngineAction
:
27 def __init__(self
, link_text
, function
, uniqid
=None):
28 self
._link
_text
= link_text
29 self
.function
= function
32 def get_link(self
, **kwargs
):
33 kwargs
= copy
.deepcopy(kwargs
)
34 if self
.uniqid
is not None:
35 kwargs
["uniqid"] = self
.uniqid
36 return "<a href=\"?%s\">%s</a>" % (urlencode(kwargs
), escape(self
._link
_text
))
38 class AdminEngine(resource
.Resource
):
39 def __init__(self
, path
, services
):
40 self
.__services
= services
42 self
.__creation
_time
= time
.time()
45 def adminEngine(self
):
47 "Permitted hosts": (config
.ADMIN_ENGINE_HOSTS
,),
48 "Started": ((time
.asctime(time
.localtime(self
.__creation
_time
)),),),
49 "Running for": (("%d seconds" % int(time
.time() - self
.__creation
_time
),),),
50 "CPU time used (UNIX only)": (("%.2f seconds" % time
.clock(),),)
53 def process_action(self
, args
):
55 engine
= args
["engine"][0]
56 heading
= args
["heading"][0]
57 pos
= int(args
["pos"][0])
58 pos2
= int(args
["pos2"][0])
60 uniqid
= args
.get("uniqid", [None])[0]
62 obj
= self
.__services
[engine
].adminEngine
[heading
][pos
]
64 raise AdminEngineException("Bad action description.")
70 if not isinstance(x
, AdminEngineAction
):
72 if x
.uniqid
== uniqid
:
76 raise AdminEngineException("Action does not exist.")
78 def render_GET(self
, request
):
79 if request
.getClientIP() not in config
.ADMIN_ENGINE_HOSTS
:
80 raise AdminEngineException("Access denied")
82 args
= request
.args
.get("engine")
84 self
.process_action(request
.args
)
87 return server
.NOT_DONE_YET
93 data
.extend(["<li>" + escape(x
) + "</li>" for x
in lines
])
96 def add_text(text
, block
="p"):
97 data
.append("<%s>%s</%s>" % (block
, escape(text
), block
))
100 return escape(text
).replace("\n", "<br/>")
102 for engine
, obj
in self
.__services
.items():
103 if not hasattr(obj
, "adminEngine"):
105 add_text(engine
, "h2")
107 for heading
, obj2
in obj
.adminEngine
.items():
108 add_text(heading
, "h3")
110 for pos
, obj3
in enumerate(obj2
):
112 for pos2
, obj4
in enumerate(obj3
):
113 if isinstance(obj4
, AdminEngineAction
):
114 elements
.append(obj4
.get_link(engine
=engine
, heading
=heading
, pos
=pos
, pos2
=pos2
))
116 elements
.append(brescape(str(obj4
)))
118 data
+=["<p>", " ".join(elements
), "</p>"]