import mediafiles
import motionctl
import powerctl
+import prefs
import remote
import settings
import smbctl
logging.error('authentication failed for user %(user)s' % {'user': username})
return None
+
+ def get_pref(self, key, default=None):
+ return prefs.get(self.current_user or 'anonymous', key, default)
+
+ def set_pref(self, key, value):
+ return prefs.set(self.current_user or 'anonymous', key, value)
def _handle_request_exception(self, exception):
try:
raise HTTPError(400, 'unknown operation')
+class PrefsHandler(BaseHandler):
+ def get(self, key):
+ self.finish_json(self.get_pref(key))
+
+ def post(self, key):
+ try:
+ value = json.loads(self.request.body)
+
+ except Exception as e:
+ logging.error('could not decode json: %s' % e)
+
+ raise
+
+ self.set_pref(key, value)
+
+
class RelayEventHandler(BaseHandler):
@BaseHandler.auth(admin=True)
def post(self):
--- /dev/null
+
+# Copyright (c) 2013 Calin Crisan
+# This file is part of motionEye.
+#
+# motionEye is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import json
+import logging
+import os.path
+
+import settings
+
+
+_PREFS_FILE_NAME = 'prefs.json'
+_prefs = None
+
+
+def _load():
+ global _prefs
+
+ _prefs = {}
+
+ file_path = os.path.join(settings.CONF_PATH, _PREFS_FILE_NAME)
+
+ if os.path.exists(file_path):
+ logging.debug('loading preferences from "%s"...' % file_path)
+
+ try:
+ file = open(file_path, 'r')
+
+ except Exception as e:
+ logging.error('could not open preferences file "%s": %s' % (file_path, e))
+
+ return
+
+ try:
+ _prefs = json.load(file)
+
+ except Exception as e:
+ logging.error('could not read preferences from file "%s": %s'(file_path, e))
+
+ finally:
+ file.close()
+
+ else:
+ logging.debug('preferences file "%s" does not exist, using default preferences')
+
+
+def _save():
+ file_path = os.path.join(settings.CONF_PATH, _PREFS_FILE_NAME)
+
+ logging.debug('saving preferences to "%s"...' % file_path)
+
+ try:
+ file = open(file_path, 'w')
+
+ except Exception as e:
+ logging.error('could not open preferences file "%s": %s' % (file_path, e))
+
+ return
+
+ try:
+ json.dump(_prefs, file, sort_keys=True, indent=4)
+
+ except Exception as e:
+ logging.error('could not save preferences to file "%s": %s'(file_path, e))
+
+ finally:
+ file.close()
+
+
+def get(username, key, default=None):
+ if _prefs is None:
+ _load()
+
+ return _prefs.get(username, {}).get(key, default)
+
+
+def set(username, key, value):
+ if _prefs is None:
+ _load()
+
+ _prefs.setdefault(username, {})[key] = value
+ _save()
+
(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'^/prefs/(?P<key>\w+)/?$', handlers.PrefsHandler),
(r'^/_relay_event/?$', handlers.RelayEventHandler),
(r'^/log/(?P<name>\w+)/?$', handlers.LogHandler),
(r'^/update/?$', handlers.UpdateHandler),
</div>
<table class="settings">
<tr class="settings-item">
- <td class="settings-item-label"><span class="settings-item-label">Show Advanced Settings</span></td>
+ <td class="settings-item-label"><span class="settings-item-label">Advanced Settings</span></td>
<td class="settings-item-value"><input type="checkbox" class="styled general main-config" id="showAdvancedSwitch"></td>
<td><span class="help-mark" title="enable this to be able to access all the advanced settings">?</span></td>
</tr>
<tr class="settings-item" required="true" strip="true">
- <td class="settings-item-label"><span class="settings-item-label">Administrator Username</span></td>
+ <td class="settings-item-label"><span class="settings-item-label">Admin Username</span></td>
<td class="settings-item-value"><input type="text" class="styled general main-config" id="adminUsernameEntry" readonly="readonly"></td>
<td><span class="help-mark" title="the username to be used for configuring the system">?</span></td>
</tr>
<tr class="settings-item" strip="true" {% if enable_reboot %}reboot="true"{% endif %}>
- <td class="settings-item-label"><span class="settings-item-label">Administrator Password</span></td>
+ <td class="settings-item-label"><span class="settings-item-label">Admin Password</span></td>
<td class="settings-item-value"><input type="password" class="styled general main-config" id="adminPasswordEntry"></td>
<td><span class="help-mark" title="administrator's password">?</span></td>
</tr>