]> www.vanbest.org Git - motioneye-debian/commitdiff
log download: added support for downloading output of a command
authorCalin Crisan <ccrisan@gmail.com>
Sat, 16 May 2015 16:00:01 +0000 (19:00 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sat, 16 May 2015 16:00:01 +0000 (19:00 +0300)
src/handlers.py

index 1e160dab4b20bfb72770c03f5877f52c4d6b3b90..382fd86ca26af8f9f327dce8dd8e7593d7c99844 100644 (file)
@@ -21,6 +21,7 @@ import logging
 import os
 import re
 import socket
+import subprocess
 
 from tornado.web import RequestHandler, HTTPError, asynchronous
 from tornado.ioloop import IOLoop
@@ -1391,14 +1392,27 @@ class LogHandler(BaseHandler):
             raise HTTPError(404, 'no such log')
 
         (path, filename) = log
-        logging.debug('serving log file %s from %s' % (filename, path))
 
         self.set_header('Content-Type', 'text/plain')
         self.set_header('Content-Disposition', 'attachment; filename=' + filename + ';')
 
-        with open(path) as f:
-            self.finish(f.read())
+        if path.startswith('/'): # an actual path        
+            logging.debug('serving log file "%s" from "%s"' % (filename, path))
 
+            with open(path) as f:
+                self.finish(f.read())
+                
+        else: # a command to execute 
+            logging.debug('serving log file "%s" from command "%s"' % (filename, path))
+
+            try:
+                output = subprocess.check_output(path, shell=True)
+            
+            except Exception as e:
+                output = 'failed to execute command: %s' % e
+                
+            self.finish(output)
+                
 
 class UpdateHandler(BaseHandler):
     @BaseHandler.auth(admin=True)