From: Calin Crisan Date: Sat, 27 Dec 2014 14:57:30 +0000 (+0200) Subject: the reboot function is back X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=f55961e723850ecd1fefa94632112b424e440f62;p=motioneye-debian the reboot function is back --- diff --git a/motioneye.py b/motioneye.py index 46784db..6b28b8e 100755 --- a/motioneye.py +++ b/motioneye.py @@ -150,9 +150,9 @@ def _test_requirements(): print('SMB_SHARES require root privileges') return False - if settings.ENABLE_REBOOT: - print('reboot requires root privileges') - return False +# if settings.ENABLE_REBOOT: +# print('reboot requires root privileges') +# return False try: import tornado # @UnusedImport diff --git a/src/handlers.py b/src/handlers.py index 3396bfe..9bf912a 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -1224,10 +1224,16 @@ class PowerHandler(BaseHandler): def post(self, op): if op == 'shutdown': self.shut_down() + + elif op == 'reboot': + self.reboot() def shut_down(self): IOLoop.instance().add_timeout(datetime.timedelta(seconds=2), powerctl.shut_down) + def reboot(self): + IOLoop.instance().add_timeout(datetime.timedelta(seconds=2), powerctl.reboot) + class VersionHandler(BaseHandler): def get(self): diff --git a/src/server.py b/src/server.py index 5041419..19b3d4a 100644 --- a/src/server.py +++ b/src/server.py @@ -51,7 +51,7 @@ application = Application( (r'^/movie/(?P\d+)/(?Pdownload|preview|delete)/(?P.+?)/?$', handlers.MovieHandler), (r'^/movie/(?P\d+)/(?Pdelete_all)/(?P.+?)/?$', handlers.MovieHandler), (r'^/update/?$', handlers.UpdateHandler), - (r'^/power/(?Pshutdown)/?$', handlers.PowerHandler), + (r'^/power/(?Pshutdown|reboot)/?$', handlers.PowerHandler), (r'^/version/?$', handlers.VersionHandler), (r'^/login/?$', handlers.LoginHandler), (r'^.*$', handlers.NotFoundHandler), diff --git a/static/css/main.css b/static/css/main.css index 69025bc..a50f1ec 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -359,7 +359,8 @@ img.apply-progress { } div.update-button, -div.shut-down-button { +div.shut-down-button, +div.reboot-button { position: relative; height: 1.5em; line-height: 1.5em; @@ -376,7 +377,8 @@ div.update-button { background: #317CAD; } -div.shut-down-button { +div.shut-down-button, +div.reboot-button { background: #c0392b; } @@ -384,7 +386,8 @@ div.update-button:HOVER { background: #3498db; } -div.shut-down-button:HOVER { +div.shut-down-button:HOVER, +div.reboot-button:HOVER { background: #D43F2F; } @@ -392,7 +395,8 @@ div.update-button:ACTIVE { background: #317CAD; } -div.shut-down-button:ACTIVE { +div.shut-down-button:ACTIVE, +div.reboot-button:ACTIVE { background: #B03427; } diff --git a/static/js/main.js b/static/js/main.js index c06fdd8..3088aca 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -587,6 +587,11 @@ function initUI() { doShutDown(); }); + /* reboot button */ + $('#rebootButton').click(function () { + doReboot(); + }); + /* whenever the window is resized, * if a modal dialog is visible, it should be repositioned */ $(window).resize(updateModalDialogPosition); @@ -1458,6 +1463,37 @@ function doShutDown() { }); } +function doReboot() { + runConfirmDialog('Really reboot?', function () { + ajax('POST', '/power/reboot/'); + setTimeout(function () { + refreshInterval = 1000000; + showModalDialog(''); + var shutDown = false; + + function checkServer() { + ajax('GET', '/', null, + function () { + if (!shutDown) { + setTimeout(checkServer, 1000); + } + else { + runAlertDialog('The system has been rebooted!', function () { + window.location.reload(true); + }); + } + }, + function () { + shutDown = true; /* the first error indicates the system was shut down */ + } + ); + } + + checkServer(); + }, 10); + }); +} + function doRemCamera() { if (Object.keys(pushConfigs).length) { return runAlertDialog('Please apply the modified settings first!'); diff --git a/templates/main.html b/templates/main.html index 8534a75..1be6446 100644 --- a/templates/main.html +++ b/templates/main.html @@ -96,6 +96,11 @@
Shut Down
? + + +
Reboot
+ ? +
Wireless Network