Commits

Josh VanderLinden committed 88120e8

Adding an expires header to the graphs

  • Participants
  • Parent commits 93a80e0

Comments (0)

Files changed (5)

 makedepends=('git' 'python-docutils')
 optdepends=(
   'nginx: fast server to proxy requests to vnstatui'
-  'python-docutils: to generate a page for the license'
 )
 backup=(
   'etc/conf.d/vnstatui.conf'
   python3 setup.py install --optimize=1 --root="${pkgdir}/"
   install -D vnstatui/index.tpl "${pkgdir}/usr/lib/python3.3/site-packages/vnstatui/index.tpl"
 
+  msg "Copying configuration files"
   install -D vnstatui.conf "${pkgdir}/etc/conf.d/vnstatui.conf"
   install -D vnstatui.nginx "${pkgdir}/etc/nginx/sites/vnstatui.conf"
   install -D vnstatui.service "${pkgdir}/usr/lib/systemd/system/vnstatui.service"
   install -D LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"
 
+  msg "Creating manpage"
   rst2man README.rst | gzip > vnstatui.1.gz
   install -D vnstatui.1.gz "${pkgdir}/usr/share/man/man1/vnstatui.1.gz"
 
+  msg "Generating HTML version of license"
   rst2html LICENSE > "${pkgdir}/usr/lib/python3.3/site-packages/vnstatui/license.html"
 }
 
 ----------------------------------------------------------
 
 :Author: Josh VanderLinden <arch@cloudlery.com>
-:Date:   2013-01-18
+:Date:   2013-01-23
 :Copyright: Public Domain
-:Version: 0.3
+:Version: 20130121
 :Manual section: 1
 :Manual group: System Tools
 

File update_readme.sh

+#!/bin/bash
+#
+# Pre-commit hook to update the README based on what is in the PKGBUILD
+#
+
+source PKGBUILD
+
+sed -i "s,^:Version: .*,:Version: ${pkgver},;s,^:Date: .*,:Date:   $(date +%Y-%m-%d)," README.rst
+
+git add README.rst

File vnstatui.conf

 #
 graphs = summary,hourly,daily,monthly,top
 
-# just in case you don't want to install python-docutils
-show_license = true
-
 # show all interfaces
 interfaces =
 

File vnstatui/app.py

 
 from collections import namedtuple
 from configparser import SafeConfigParser
+from datetime import datetime
 from subprocess import Popen, PIPE
 import os
 import re
 from bottle import response, route, run, view
 
 
-__version__ = '0.3'
+__version__ = '0.4'
 __author__ = 'Josh VanderLinden <arch@cloudlery.com>'
 
 CFG_RE = re.compile(r'^(?P<var>\w+) +(?:"(?P<sval>.*?)"|(?P<nval>\d+))$', re.M)
 def make_graph(interface, graph):
     """Generate a graph for the specified interface"""
 
+    cfg = load_vnstat_config()
+
     flag = GRAPH_MAP[graph]
     cmd = ['/usr/bin/vnstati',
            '-%s' % flag,
     pipe = Popen(cmd, stdout=PIPE)
     (img, _) = pipe.communicate()
 
+    # expiration
+    now = datetime.utcnow()
+    expires = now.replace(minute=now.minute + cfg.SaveInterval, second=10)
+    response.set_header('Expires',
+                        expires.strftime('%a, %d %b %Y %H:%M:%S +0000'))
+
     response.content_type = 'image/png'
+
     return img
 
 
 
 
 if __name__ == '__main__':
-    serve()
+    import argparse
+    parser = argparse.ArgumentParser(description='VNStat UI')
+    parser.add_argument('-b', '--bind', default='0.0.0.0',
+                        help='IP address to listen for request on')
+    parser.add_argument('-p', '--port', default=7000, type=int,
+                        help='Port to listen for requests on')
+    args = parser.parse_args()
+
+    serve(**args.__dict__)