import update
import utils
import v4l2ctl
+import wifictl
_CAMERA_CONFIG_FILE_NAME = 'thread-%(id)s.conf'
_set_default_motion(main_config)
_main_config_cache = dict(main_config)
- if settings.WPA_SUPPLICANT_CONF:
- _set_wifi_settings(main_config)
-
- if settings.LOCAL_TIME_FILE:
- _set_localtime_settings(main_config)
+ _set_wifi_settings(main_config)
+ _set_localtime_settings(main_config)
config_file_path = os.path.join(settings.CONF_PATH, _MAIN_CONFIG_FILE_NAME)
'@admin_password': ui['admin_password'],
'@normal_username': ui['normal_username'],
'@normal_password': ui['normal_password'],
+ '@time_zone': ui['time_zone'],
'@wifi_enabled': ui['wifi_enabled'],
'@wifi_name': ui['wifi_name'],
'admin_password': data['@admin_password'],
'normal_username': data['@normal_username'],
'normal_password': data['@normal_password'],
+ 'time_zone': data['@time_zone'],
'wifi_enabled': data['@wifi_enabled'],
'wifi_name': data['@wifi_name'],
data.setdefault('@admin_password', '')
data.setdefault('@normal_username', 'user')
data.setdefault('@normal_password', '')
- data.setdefault('@timezone', 'UTC')
+ data.setdefault('@time_zone', 'UTC')
data.setdefault('@wifi_enabled', False)
data.setdefault('@wifi_name', '')
def _get_wifi_settings(data):
- # will return the first configured network
-
- logging.debug('reading wifi settings from %s' % settings.WPA_SUPPLICANT_CONF)
-
- try:
- conf_file = open(settings.WPA_SUPPLICANT_CONF, 'r')
-
- except Exception as e:
- logging.error('could open wifi settings file %(path)s: %(msg)s' % {
- 'path': settings.WPA_SUPPLICANT_CONF, 'msg': unicode(e)})
-
- return
-
- lines = conf_file.readlines()
- conf_file.close()
-
- ssid = psk = ''
- in_section = False
- for line in lines:
- line = line.strip()
- if line.startswith('#'):
- continue
-
- if '{' in line:
- in_section = True
-
- elif '}' in line:
- in_section = False
- break
-
- elif in_section:
- m = re.search('ssid\s*=\s*"(.*?)"', line)
- if m:
- ssid = m.group(1)
-
- m = re.search('psk\s*=\s*"(.*?)"', line)
- if m:
- psk = m.group(1)
+ wifi_settings = wifictl.get_wifi_settings()
- data['@wifi_enabled'] = bool(ssid)
- data['@wifi_name'] = ssid
- data['@wifi_key'] = psk
-
- if ssid:
- logging.debug('wifi is enabled (name = "%s")' % ssid)
-
- else:
- logging.debug('wifi is disabled')
+ data['@wifi_enabled'] = bool(wifi_settings['ssid'])
+ data['@wifi_name'] = wifi_settings['ssid']
+ data['@wifi_key'] = wifi_settings['psk']
def _set_wifi_settings(data):
- # will update the first configured network
-
- logging.debug('writing wifi settings to %s' % settings.WPA_SUPPLICANT_CONF)
-
wifi_enabled = data.pop('@wifi_enabled', False)
wifi_name = data.pop('@wifi_name', '')
wifi_key = data.pop('@wifi_key', '')
- try:
- conf_file = open(settings.WPA_SUPPLICANT_CONF, 'r')
-
- except Exception as e:
- logging.error('could open wifi settings file %(path)s: %(msg)s' % {
- 'path': settings.WPA_SUPPLICANT_CONF, 'msg': unicode(e)})
-
- return
-
- lines = conf_file.readlines()
- conf_file.close()
-
- in_section = False
- found_ssid = False
- found_psk = False
- i = 0
- while i < len(lines):
- line = lines[i].strip()
- if line.startswith('#'):
- i += 1
- continue
-
- if '{' in line:
- in_section = True
-
- elif '}' in line:
- in_section = False
- if wifi_enabled and wifi_name and not found_ssid:
- lines.insert(i, ' ssid="' + wifi_name + '"\n')
- if wifi_enabled and wifi_key and not found_psk:
- lines.insert(i, ' psk="' + wifi_key + '"\n')
-
- found_psk = found_ssid = True
-
- break
-
- elif in_section:
- if wifi_enabled:
- if re.match('ssid\s*=\s*".*?"', line):
- lines[i] = ' ssid="' + wifi_name + '"\n'
- found_ssid = True
-
- elif re.match('psk\s*=\s*".*?"', line):
- if wifi_key:
- lines[i] = ' psk="' + wifi_key + '"\n'
- found_psk = True
-
- else:
- lines.pop(i)
- i -= 1
-
- else: # wifi disabled
- if re.match('ssid\s*=\s*".*?"', line) or re.match('psk\s*=\s*".*?"', line):
- lines.pop(i)
- i -= 1
+ if settings.WPA_SUPPLICANT_CONF:
+ s = {
+ 'ssid': wifi_enabled and wifi_name,
+ 'psk': wifi_key
+ }
- i += 1
-
- if wifi_enabled and not found_ssid:
- lines.append('network={\n')
- lines.append(' ssid="' + wifi_name + '"\n')
- lines.append(' psk="' + wifi_key + '"\n')
- lines.append('}\n\n')
-
- try:
- conf_file = open(settings.WPA_SUPPLICANT_CONF, 'w')
-
- except Exception as e:
- logging.error('could open wifi settings file %(path)s: %(msg)s' % {
- 'path': settings.WPA_SUPPLICANT_CONF, 'msg': unicode(e)})
-
- return
-
- for line in lines:
- conf_file.write(line)
-
- conf_file.close()
+ wifictl.set_wifi_settings(s)
def _get_localtime_settings(data):
def _set_localtime_settings(data):
time_zone = data.pop('@time_zone')
- if time_zone:
+ if time_zone and settings.LOCAL_TIME_FILE:
tzctl.set_time_zone(time_zone)
--- /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 logging
+import re
+import settings
+
+
+def get_wifi_settings():
+ # will return the first configured network
+
+ logging.debug('reading wifi settings from %s' % settings.WPA_SUPPLICANT_CONF)
+
+ try:
+ conf_file = open(settings.WPA_SUPPLICANT_CONF, 'r')
+
+ except Exception as e:
+ logging.error('could open wifi settings file %(path)s: %(msg)s' % {
+ 'path': settings.WPA_SUPPLICANT_CONF, 'msg': unicode(e)})
+
+ return {
+ 'ssid': None,
+ 'psk': None
+ }
+
+ lines = conf_file.readlines()
+ conf_file.close()
+
+ ssid = psk = ''
+ in_section = False
+ for line in lines:
+ line = line.strip()
+ if line.startswith('#'):
+ continue
+
+ if '{' in line:
+ in_section = True
+
+ elif '}' in line:
+ in_section = False
+ break
+
+ elif in_section:
+ m = re.search('ssid\s*=\s*"(.*?)"', line)
+ if m:
+ ssid = m.group(1)
+
+ m = re.search('psk\s*=\s*"(.*?)"', line)
+ if m:
+ psk = m.group(1)
+
+ if ssid:
+ logging.debug('wifi is enabled (ssid = "%s")' % ssid)
+
+ else:
+ logging.debug('wifi is disabled')
+
+ return {
+ 'ssid': ssid,
+ 'psk': psk
+ }
+
+
+def set_wifi_settings(s):
+ # will update the first configured network
+
+ logging.debug('writing wifi settings to %s' % settings.WPA_SUPPLICANT_CONF)
+
+ enabled = bool(s['ssid'])
+ ssid = s['ssid']
+ psk = s['psk']
+
+ try:
+ conf_file = open(settings.WPA_SUPPLICANT_CONF, 'r')
+
+ except Exception as e:
+ logging.error('could open wifi settings file %(path)s: %(msg)s' % {
+ 'path': settings.WPA_SUPPLICANT_CONF, 'msg': unicode(e)})
+
+ return
+
+ lines = conf_file.readlines()
+ conf_file.close()
+
+ in_section = False
+ found_ssid = False
+ found_psk = False
+ i = 0
+ while i < len(lines):
+ line = lines[i].strip()
+ if line.startswith('#'):
+ i += 1
+ continue
+
+ if '{' in line:
+ in_section = True
+
+ elif '}' in line:
+ in_section = False
+ if enabled and ssid and not found_ssid:
+ lines.insert(i, ' ssid="' + ssid + '"\n')
+ if enabled and psk and not found_psk:
+ lines.insert(i, ' psk="' + psk + '"\n')
+
+ found_psk = found_ssid = True
+
+ break
+
+ elif in_section:
+ if enabled:
+ if re.match('ssid\s*=\s*".*?"', line):
+ lines[i] = ' ssid="' + ssid + '"\n'
+ found_ssid = True
+
+ elif re.match('psk\s*=\s*".*?"', line):
+ if psk:
+ lines[i] = ' psk="' + psk + '"\n'
+ found_psk = True
+
+ else:
+ lines.pop(i)
+ i -= 1
+
+ else: # wifi disabled
+ if re.match('ssid\s*=\s*".*?"', line) or re.match('psk\s*=\s*".*?"', line):
+ lines.pop(i)
+ i -= 1
+
+ i += 1
+
+ if enabled and not found_ssid:
+ lines.append('network={\n')
+ lines.append(' ssid="' + ssid + '"\n')
+ lines.append(' psk="' + psk + '"\n')
+ lines.append('}\n\n')
+
+ try:
+ conf_file = open(settings.WPA_SUPPLICANT_CONF, 'w')
+
+ except Exception as e:
+ logging.error('could open wifi settings file %(path)s: %(msg)s' % {
+ 'path': settings.WPA_SUPPLICANT_CONF, 'msg': unicode(e)})
+
+ return
+
+ for line in lines:
+ conf_file.write(line)
+
+ conf_file.close()
fetchCurrentCameraConfig(endProgress);
}
});
- $('input.general').change(pushMainConfig);
+ $('input.general, select.general').change(pushMainConfig);
$('input.wifi').change(pushMainConfig);
$('input.device, select.device, ' +
'input.storage, select.storage, ' +
'admin_password': $('#adminPasswordEntry').val(),
'normal_username': $('#normalUsernameEntry').val(),
'normal_password': $('#normalPasswordEntry').val(),
+ 'time_zone': $('#timeZoneSelect').val(),
'wifi_enabled': $('#wifiSwitch')[0].checked,
'wifi_name': $('#wifiNameEntry').val(),
$('#adminPasswordEntry').val(dict['admin_password']);
$('#normalUsernameEntry').val(dict['normal_username']);
$('#normalPasswordEntry').val(dict['normal_password']);
+ $('#timeZoneSelect').val(dict['time_zone']);
$('#wifiSwitch')[0].checked = dict['wifi_enabled'];
$('#wifiNameEntry').val(dict['wifi_name']);