return lines
main_config = _conf_to_dict(lines, list_names=['thread'])
+
+ if settings.WPA_SUPPLICANT_CONF:
+ _get_wifi_settings(main_config)
+
_set_default_motion(main_config)
_main_config_cache = main_config
global _main_config_cache
_set_default_motion(main_config)
-
+ _main_config_cache = dict(main_config)
+
+ if settings.WPA_SUPPLICANT_CONF:
+ _set_wifi_settings(main_config)
+
config_file_path = os.path.join(settings.CONF_PATH, _MAIN_CONFIG_FILE_NAME)
# read the actual configuration from file
finally:
file.close()
- _main_config_cache = main_config
-
- return main_config
-
def get_camera_ids():
global _camera_ids_cache
finally:
file.close()
- return camera_config
-
def add_camera(device_details):
global _camera_ids_cache
def main_ui_to_dict(ui):
return {
'@enabled': ui['enabled'],
+
'@show_advanced': ui['show_advanced'],
'@admin_username': ui['admin_username'],
'@admin_password': ui['admin_password'],
'@normal_username': ui['normal_username'],
- '@normal_password': ui['normal_password']
+ '@normal_password': ui['normal_password'],
+
+ '@wifi_enabled': ui['wifi_enabled'],
+ '@wifi_name': ui['wifi_name'],
+ '@wifi_key': ui['wifi_key'],
}
def main_dict_to_ui(data):
return {
'enabled': data['@enabled'],
+
'show_advanced': data['@show_advanced'],
'admin_username': data['@admin_username'],
'admin_password': data['@admin_password'],
'normal_username': data['@normal_username'],
- 'normal_password': data['@normal_password']
+ 'normal_password': data['@normal_password'],
+
+ 'wifi_enabled': data['@wifi_enabled'],
+ 'wifi_name': data['@wifi_name'],
+ 'wifi_key': data['@wifi_key'],
}
def camera_ui_to_dict(ui):
if not ui['resolution']: # avoid errors for empty resolution setting
ui['resolution'] = '352x288'
-
+
width = int(ui['resolution'].split('x')[0])
height = int(ui['resolution'].split('x')[1])
threshold = int(float(ui['frame_change_threshold']) * width * height / 100)
def _set_default_motion(data):
data.setdefault('@enabled', True)
+
data.setdefault('@show_advanced', False)
data.setdefault('@admin_username', 'admin')
data.setdefault('@admin_password', '')
data.setdefault('@normal_username', 'user')
data.setdefault('@normal_password', '')
+ data.setdefault('@wifi_enabled', False)
+ data.setdefault('@wifi_name', '')
+ data.setdefault('@wifi_key', '')
+
def _set_default_motion_camera(camera_id, data, old_motion):
data.setdefault('@name', 'Camera' + str(camera_id))
data.setdefault('@motion_notifications_emails', '')
data.setdefault('@working_schedule', '')
+
+
+def _get_wifi_settings(data):
+ 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
+
+ # TODO read settings from file
+
+ conf_file.close()
+
+
+def _set_wifi_settings(data):
+ wifi_enabled = data.pop('@wifi_enabled', False)
+ wifi_name = data.pop('@wifi_name', None)
+ wifi_key = data.pop('@wifi_key', None)
+
+ 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
+
+ # TODO write settings to file
+
+ conf_file.close()
/* text validators */
makeTextValidator($('#adminUsernameEntry'), true);
makeTextValidator($('#normalUsernameEntry'), true);
+ makeTextValidator($('#wifiNameEntry'), true);
makeTextValidator($('#deviceNameEntry'), true);
makeTextValidator($('#networkServerEntry'), true);
makeTextValidator($('#networkShareNameEntry'), true);
$('#preserveMoviesSelect').change(updateConfigUi);
$('#motionNotificationsSwitch').change(updateConfigUi);
$('#workingScheduleSwitch').change(updateConfigUi);
+ $('#wifiSwitch').change(updateConfigUi);
/* fetch & push handlers */
$('#videoDeviceSelect').change(function () {
'input.motion-movies, select.motion-movies, ' +
'input.motion-detection, select.motion-detection, ' +
'input.notifications, select.notifications, ' +
- 'input.working-schedule, select.working-schedule').change(pushCameraConfig);
+ 'input.working-schedule, select.working-schedule, ' +
+ 'input.wifi, select.wifi').change(pushCameraConfig);
/* preview controls */
$('#brightnessSlider').change(function () {pushPreview('brightness');});
objs.not($('#motionEyeSwitch').parents('div').get(0)).each(markHide);
}
+ /* wifi switch */
+ if (!$('#wifiSwitch').get(0).checked) {
+ $('#wifiSwitch').parent().next('table.settings').find('tr.settings-item').each(markHide);
+ }
+
if ($('#videoDeviceSelect').find('option').length < 2) { /* no camera configured */
$('#videoDeviceSwitch').parent().each(markHide);
$('#videoDeviceSwitch').parent().nextAll('div.settings-section-title, table.settings').each(markHide);
function mainUi2Dict() {
return {
'enabled': $('#motionEyeSwitch')[0].checked,
+
'show_advanced': $('#showAdvancedSwitch')[0].checked,
'admin_username': $('#adminUsernameEntry').val(),
'admin_password': $('#adminPasswordEntry').val(),
'normal_username': $('#normalUsernameEntry').val(),
- 'normal_password': $('#normalPasswordEntry').val()
+ 'normal_password': $('#normalPasswordEntry').val(),
+
+ 'wifi_enabled': $('#wifiSwitch')[0].checked,
+ 'wifi_name': $('#wifiNameEntry').val(),
+ 'wifi_key': $('#wifiKeyEntry').val()
};
}
function dict2MainUi(dict) {
$('#motionEyeSwitch')[0].checked = dict['enabled'];
+
$('#showAdvancedSwitch')[0].checked = dict['show_advanced'];
$('#adminUsernameEntry').val(dict['admin_username']);
$('#adminPasswordEntry').val(dict['admin_password']);
$('#normalUsernameEntry').val(dict['normal_username']);
$('#normalPasswordEntry').val(dict['normal_password']);
+ $('#wifiSwitch')[0].checked = dict['wifi_enabled'];
+ $('#wifiNameEntry').val(dict['wifi_name']);
+ $('#wifiKeyEntry').val(dict['wifi_key']);
+
updateConfigUi();
}
</tr>
</table>
+ <div class="settings-section-title advanced-setting"><input type="checkbox" class="styled section wifi" id="wifiSwitch">Wireless Network</div>
+ <table class="settings advanced-setting">
+ <tr class="settings-item advanced-setting">
+ <td class="settings-item-label"><span class="settings-item-label">Network Name</span></td>
+ <td class="settings-item-value"><input type="text" class="styled wifi" id="wifiNameEntry" placeholder="name..."></td>
+ <td><span class="help-mark" title="the name (SSID) of your wireless network">?</span></td>
+ </tr>
+ <tr class="settings-item advanced-setting">
+ <td class="settings-item-label"><span class="settings-item-label">Network Key</span></td>
+ <td class="settings-item-value"><input type="password" class="styled wifi" id="wifiKeyEntry" placeholder="key..."></td>
+ <td><span class="help-mark" title="the key (PSK) required to connect to your wireless network">?</span></td>
+ </tr>
+ </table>
+
<div class="settings-section-title"><input type="checkbox" class="styled section device" id="videoDeviceSwitch">Video Device</div>
<table class="settings">
<tr class="settings-item">
<td><span class="help-mark" title="sets the working schedule time interval for Sunday">?</span></td>
</tr>
</table>
+
<div class="settings-progress"></div>
</div>
</div>