]> www.vanbest.org Git - motioneye-debian/commitdiff
added support for downloading log files
authorCalin Crisan <ccrisan@gmail.com>
Sun, 29 Mar 2015 16:44:50 +0000 (19:44 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Sun, 29 Mar 2015 17:18:20 +0000 (20:18 +0300)
src/handlers.py
src/server.py
static/js/main.js
templates/main.html

index 696787b5849ee0bcd54698237fc5eea78716f3d5..d799c96d8f1072c3b5ef30bd662b753e9b4b69ff 100644 (file)
@@ -1325,6 +1325,27 @@ class MovieHandler(BaseHandler):
             remote.del_media_group(camera_config, group=group, media_type='movie', callback=on_response)
 
 
+class LogHandler(BaseHandler):
+    LOGS = {
+        'motion': (os.path.join(settings.LOG_PATH, 'motion.log'),  'motion.log')
+    }
+
+    @BaseHandler.auth(admin=True)
+    def get(self, name):
+        log = self.LOGS.get(name)
+        if log is None:
+            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())
+
+
 class UpdateHandler(BaseHandler):
     @BaseHandler.auth(admin=True)
     def get(self):
index 2e6bf1074309bf589624be11f86f56ef427ea713..49b3280cbd0ff5889d7308482e74b1a69d0af823 100644 (file)
@@ -50,6 +50,7 @@ application = Application(
         (r'^/movie/(?P<camera_id>\d+)/(?P<op>list)/?$', handlers.MovieHandler),
         (r'^/movie/(?P<camera_id>\d+)/(?P<op>download|preview|delete)/(?P<filename>.+?)/?$', handlers.MovieHandler),
         (r'^/movie/(?P<camera_id>\d+)/(?P<op>delete_all)/(?P<group>.+?)/?$', handlers.MovieHandler),
+        (r'^/log/(?P<name>\w+)/?$', handlers.LogHandler),
         (r'^/update/?$', handlers.UpdateHandler),
         (r'^/power/(?P<op>shutdown|reboot)/?$', handlers.PowerHandler),
         (r'^/version/?$', handlers.VersionHandler),
index b3b62c67dcf6f9fe751716f1ae03c7b153be300e..96731b5dc9722aa0bea9f6a8c6b71096e940a152 100644 (file)
@@ -7,6 +7,7 @@ var inProgress = false;
 var refreshInterval = 50; /* milliseconds */
 var username = '';
 var password = '';
+var baseUri = null;
 
 
     /* utils */
@@ -1106,7 +1107,7 @@ function dict2MainUi(dict) {
     /* additional configs */
     $('tr.additional-config').each(function () {
         var $this = $(this);
-        var control = $this.find('input, select');
+        var control = $this.find('input, select, div.html');
         
         if (!control.hasClass('main-config')) {
             return;
@@ -1130,6 +1131,10 @@ function dict2MainUi(dict) {
             name = id.substring(0, id.length - 6);
             control[0].checked = dict['_' + name];
         }
+        else if (id.endsWith('Html')) {
+            name = id.substring(0, id.length - 4);
+            control.html(dict['_' + name]);
+        }
     });
 
     updateConfigUi();
@@ -1562,7 +1567,7 @@ function dict2CameraUi(dict) {
     /* additional configs */
     $('tr.additional-config').each(function () {
         var $this = $(this);
-        var control = $this.find('input, select');
+        var control = $this.find('input, select, div.html');
         
         if (!control.hasClass('camera-config')) {
             return;
@@ -1586,6 +1591,10 @@ function dict2CameraUi(dict) {
             name = id.substring(0, id.length - 6);
             control[0].checked = dict['_' + name];
         }
+        else if (id.endsWith('Html')) {
+            name = id.substring(0, id.length - 4);
+            control.html(dict['_' + name]);
+        }
     });
 
     updateConfigUi();
@@ -1648,6 +1657,8 @@ function endProgress() {
 }
 
 function downloadFile(uri) {
+    uri = baseUri + uri;
+
     var url = window.location.href;
     var parts = url.split('/');
     url = parts.slice(0, 3).join('/') + uri;
@@ -1958,7 +1969,7 @@ function doUpdate() {
 }
 
 function doBackup() {
-    downloadFile(baseUri + 'config/backup/');
+    downloadFile('config/backup/');
 }
 
 function doRestore() {
@@ -2061,7 +2072,7 @@ function doDownloadZipped(cameraId, groupKey) {
         }
         else {
             hideModalDialog(); /* progress */
-            downloadFile(baseUri + 'picture/' + cameraId + '/zipped/' + groupKey + '/?key=' + data.key);
+            downloadFile('picture/' + cameraId + '/zipped/' + groupKey + '/?key=' + data.key);
         }
     });
 }
@@ -2505,7 +2516,7 @@ function runPictureDialog(entries, pos, mediaType) {
             {caption: 'Close'},
             {caption: 'Download', isDefault: true, click: function () {
                 var entry = entries[pos];
-                downloadFile(baseUri + mediaType + '/' + entry.cameraId + '/download' + entry.path);
+                downloadFile(mediaType + '/' + entry.cameraId + '/download' + entry.path);
                 
                 return false;
             }}
@@ -2887,7 +2898,7 @@ function runTimelapseDialog(cameraId, groupKey, group) {
                         setTimeout(function () {
                             hideModalDialog(); /* progress */
                             hideModalDialog(); /* timelapse dialog */
-                            downloadFile(baseUri + 'picture/' + cameraId + '/timelapse/' + groupKey + '/?key=' + data.key);
+                            downloadFile('picture/' + cameraId + '/timelapse/' + groupKey + '/?key=' + data.key);
                         }, 500);
                     }
                     else {
@@ -2980,7 +2991,7 @@ function runMediaDialog(cameraId, mediaType) {
                     entryDiv.append(detailsDiv);
                     
                     downloadButton.click(function () {
-                        downloadFile(baseUri + mediaType + '/' + cameraId + '/download' + entry.path);
+                        downloadFile(mediaType + '/' + cameraId + '/download' + entry.path);
                         return false;
                     });
                     
index f3eed0ab3ee0a8f75998ea6899b708f336e86ca7..94134aa044c9c9ad40b3f34d5293af6f7272b41b 100644 (file)
@@ -37,6 +37,8 @@
                     <option value="{{choice[0]}}">{{choice[1]}}</option>
                     {% endfor %}
                 </select>
+            {% elif config['type'] == 'html' %}
+                <div class="html styled {{config['section']}} {% if config.get('camera') %}camera{% else %}main{% endif %}-config" id="{{config['name']}}Html">
             {% endif %}
         </td>
         <td>{% if config.get('description') %}<span class="help-mark" title="{{config['description']}}">?</span>{% endif %}</td>