From: Calin Crisan <ccrisan@gmail.com>
Date: Sun, 27 Dec 2015 09:16:17 +0000 (+0200)
Subject: wifictl: added support for open networks
X-Git-Url: http://www.vanbest.org/gitweb/?a=commitdiff_plain;h=fce758f39114cf0f77a2304ef55d6fa29d83077a;p=motioneye-debian

wifictl: added support for open networks
---

diff --git a/motioneye/wifictl.py b/motioneye/wifictl.py
index 32ec562..1902b88 100644
--- a/motioneye/wifictl.py
+++ b/motioneye/wifictl.py
@@ -99,6 +99,7 @@ def _set_wifi_settings(s):
     enabled = s['wifiEnabled']
     ssid = s['wifiNetworkName']
     psk = s['wifiNetworkKey']
+    key_mgmt = 'WPA-PSK WPA-EAP' if psk else 'NONE'
     
     # will update the first configured network
     try:
@@ -116,6 +117,7 @@ def _set_wifi_settings(s):
     in_section = False
     found_ssid = False
     found_psk = False
+    found_key_mgmt = False
     i = 0
     while i < len(lines):
         line = lines[i].strip()
@@ -132,8 +134,10 @@ def _set_wifi_settings(s):
                 lines.insert(i, '    ssid="' + ssid + '"\n')
             if enabled and psk and not found_psk:
                 lines.insert(i, '    psk="' + psk + '"\n')
+            if enabled and not found_key_mgmt:
+                lines.insert(i, '    key_mgmt=' + key_mgmt + '\n')
             
-            found_psk = found_ssid = True
+            found_psk = found_ssid = found_key_mgmt = True
             
             break
             
@@ -152,6 +156,10 @@ def _set_wifi_settings(s):
                         lines.pop(i)
                         i -= 1
         
+                elif re.match('key_mgmt\s*=\s*.*?', line):
+                    lines[i] = '    key_mgmt=' + key_mgmt + '\n'
+                    found_key_mgmt = True
+        
             else: # wifi disabled
                 if re.match('ssid\s*=\s*".*?"', line) or re.match('psk\s*=\s*".*?"', line):
                     lines.pop(i)
@@ -164,6 +172,7 @@ def _set_wifi_settings(s):
         lines.append('    scan_ssid=1\n')
         lines.append('    ssid="' + ssid + '"\n')
         lines.append('    psk="' + psk + '"\n')
+        lines.append('    key_mgmt=' + key_mgmt + '\n')
         lines.append('}\n\n')
 
     try: