- from twisted.web.resource import Resource
- from jinja2 import Template, Environment
- from jinja2.loaders import DictLoader
- import subprocess
- import datetime
- import re
- class main(Resource):
- isLeaf = True
- disable = False
- def getChild(self, name, request):
- if name == '':
- return self
- return Resource.getChild(self, name, request)
- def render_GET(self, request):
- source = Environment().from_string(u'''\
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta name="Description" content="Yiff!"/>
- <meta http-equiv="refresh" content="{{ autorefresh }}" >
- <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"/>
- <meta name="Robots" content="index,follow" />
- <link rel="stylesheet" href="http://bitch.iotairc.net/urls/style.css" type="text/css"/>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
- <title>[yiff.iotairc.net] (Web panel)</title>
- <style>
- body { background: black;color: #090;font-size: 100px; text-align:center;padding-top:250px;font-family: monospace;}
- </style>
- <script>
- window.setInterval(function(){
- $.ajax({
- url: "index.rpy",
- context: document.body
- }).done(function(html) {
- $('body').html(html);
- });
- }, 1000);
- </script>
- </head>
- <body>
- {{ duration }}
- </body>
- </html>
- ''')
- p = subprocess.Popen(["ps", "-C", "ircd", "-O", "etime"], stdout=subprocess.PIPE)
- out, err = p.communicate()
- out = out.split()
- uptime = out[7]
- duration = datetime.timedelta(**dict((k, int(v)) for k, v in re.match(r'(?:(?P<days>\d+)-)?(?:(?P<hours>\d\d):?)(?P<minutes>\d+):(?P<seconds>\d+)', uptime).groupdict().iteritems()))
- page = source.render(duration=duration, autorefresh="o")
- return str(page)
- resource = main()