From Sharp Pig, 12 Years ago, written in Plain Text.
Embed
  1. from twisted.web.resource import Resource
  2. from jinja2 import Template, Environment
  3. from jinja2.loaders import DictLoader
  4. import subprocess
  5. import datetime
  6. import re
  7.  
  8. class main(Resource):
  9.  
  10.         isLeaf = True
  11.         disable = False
  12.  
  13.         def getChild(self, name, request):
  14.                 if name == '':
  15.                         return self
  16.                 return Resource.getChild(self, name, request)
  17.  
  18.         def render_GET(self, request):
  19.                 source = Environment().from_string(u'''\
  20. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  21.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  22. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  23. <head>
  24.   <meta name="Description" content="Yiff!"/>
  25.   <meta http-equiv="refresh" content="{{ autorefresh }}" >
  26.   <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"/>
  27.   <meta name="Robots" content="index,follow" />
  28.   <link rel="stylesheet" href="http://bitch.iotairc.net/urls/style.css" type="text/css"/>
  29.   <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.js"></script>
  30.   <title>[yiff.iotairc.net] (Web panel)</title>
  31.   <style>
  32.         body { background: black;color: #090;font-size: 100px; text-align:center;padding-top:250px;font-family: monospace;}
  33.   </style>
  34.   <script>
  35. window.setInterval(function(){
  36.  
  37.         $.ajax({
  38.                 url: "index.rpy",
  39.                 context: document.body
  40.         }).done(function(html) {
  41.                 $('body').html(html);
  42.         });
  43. }, 1000);
  44.   </script>
  45. </head>
  46. <body>
  47.   {{ duration }}
  48. </body>
  49. </html>
  50. ''')
  51.                 p = subprocess.Popen(["ps", "-C", "ircd", "-O", "etime"], stdout=subprocess.PIPE)
  52.                 out, err = p.communicate()
  53.                 out = out.split()
  54.                 uptime = out[7]
  55.                 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()))
  56.                 page = source.render(duration=duration, autorefresh="o")
  57.                 return str(page)
  58. resource = main()
  59.