From: Calin Crisan Date: Sun, 29 Mar 2015 16:44:50 +0000 (+0300) Subject: added support for downloading log files X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=d2f1f4f2d194fa26cca914db2b518a508c894f81;p=motioneye-debian added support for downloading log files --- diff --git a/src/handlers.py b/src/handlers.py index 696787b..d799c96 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -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): diff --git a/src/server.py b/src/server.py index 2e6bf10..49b3280 100644 --- a/src/server.py +++ b/src/server.py @@ -50,6 +50,7 @@ application = Application( (r'^/movie/(?P\d+)/(?Plist)/?$', handlers.MovieHandler), (r'^/movie/(?P\d+)/(?Pdownload|preview|delete)/(?P.+?)/?$', handlers.MovieHandler), (r'^/movie/(?P\d+)/(?Pdelete_all)/(?P.+?)/?$', handlers.MovieHandler), + (r'^/log/(?P\w+)/?$', handlers.LogHandler), (r'^/update/?$', handlers.UpdateHandler), (r'^/power/(?Pshutdown|reboot)/?$', handlers.PowerHandler), (r'^/version/?$', handlers.VersionHandler), diff --git a/static/js/main.js b/static/js/main.js index b3b62c6..96731b5 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -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; }); diff --git a/templates/main.html b/templates/main.html index f3eed0a..94134aa 100644 --- a/templates/main.html +++ b/templates/main.html @@ -37,6 +37,8 @@ {% endfor %} + {% elif config['type'] == 'html' %} +
{% endif %} {% if config.get('description') %}?{% endif %}