]> www.vanbest.org Git - motioneye-debian/commitdiff
initial work on wifi settings
authorCalin Crisan <ccrisan@gmail.com>
Wed, 25 Jun 2014 14:40:43 +0000 (17:40 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Wed, 25 Jun 2014 14:40:43 +0000 (17:40 +0300)
settings_default.py
src/config.py
static/css/main.css
static/js/main.js
templates/main.html

index 831ea31d0e5c52f1c64d3cb763c7a23f4f965e17..d90f6bb6ec7eb3174262f75a741834d25f8f04a7 100644 (file)
@@ -29,6 +29,9 @@ LISTEN = '0.0.0.0'
 # change the port according to your requirements/restrictions
 PORT = 8765
 
+# path to a wpa_supplicant.conf file if wifi settings UI is desired (requires root) 
+WPA_SUPPLICANT_CONF = None
+
 # enable SMB shares (requires root) 
 SMB_SHARES = False
 
index bec11d35f187014c22b7d7b30543ed917c371086..f96d0a51a7d128f92cb7645352672f2cc89ede33 100644 (file)
@@ -84,6 +84,10 @@ def get_main(as_lines=False):
         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
@@ -95,7 +99,11 @@ def set_main(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
@@ -135,10 +143,6 @@ def set_main(main_config):
     finally:
         file.close()
 
-    _main_config_cache = main_config
-
-    return main_config
-
 
 def get_camera_ids():
     global _camera_ids_cache
@@ -377,8 +381,6 @@ def set_camera(camera_id, camera_config):
     finally:
         file.close()
         
-    return camera_config
-
 
 def add_camera(device_details):
     global _camera_ids_cache
@@ -461,29 +463,39 @@ def rem_camera(camera_id):
 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)
@@ -1041,12 +1053,17 @@ def _is_old_motion():
 
 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))
@@ -1135,3 +1152,37 @@ def _set_default_motion_camera(camera_id, data, old_motion):
     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()
index fd89cf9487360271a5fa14b84e32985d895a1719..702d5e22a6df817e88cd86ef465d2236457362b4 100644 (file)
@@ -397,7 +397,7 @@ span.disk-usage-percent {
 
 div.hidden,
 tr.hidden {
-    display: none;
+    display: none !important;
 }
 
 
index bb47f249973e89deb6cf0e6ff627e6e2af629860..be75a960b74f2f43894ccca3e2e67d4cc0b285e3 100644 (file)
@@ -193,6 +193,7 @@ function initUI() {
     /* text validators */
     makeTextValidator($('#adminUsernameEntry'), true);
     makeTextValidator($('#normalUsernameEntry'), true);
+    makeTextValidator($('#wifiNameEntry'), true);
     makeTextValidator($('#deviceNameEntry'), true);
     makeTextValidator($('#networkServerEntry'), true);
     makeTextValidator($('#networkShareNameEntry'), true);
@@ -250,6 +251,7 @@ function initUI() {
     $('#preserveMoviesSelect').change(updateConfigUi);
     $('#motionNotificationsSwitch').change(updateConfigUi);
     $('#workingScheduleSwitch').change(updateConfigUi);
+    $('#wifiSwitch').change(updateConfigUi);
     
     /* fetch & push handlers */
     $('#videoDeviceSelect').change(function () {
@@ -278,7 +280,8 @@ function initUI() {
       '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');});
@@ -356,6 +359,11 @@ function updateConfigUi() {
         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);
@@ -503,22 +511,32 @@ function configUiValid() {
 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();
 }
 
index 8ee98730db557bfdccb89de16fd1cd804124c22f..8f18eaf3ce41c21e6a5b30f70d78d1eb5910c94a 100644 (file)
                     </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>