From 97b88e61c03178ffb7cffb74d6a6cca007745e6f Mon Sep 17 00:00:00 2001 From: PESCHE Romain Date: Wed, 3 Jun 2015 21:15:15 +0200 Subject: [PATCH] add new module for wpa_supplicant in Linux --- Linux/src/config/manageModules.py | 2 + Linux/src/softwares/wifi/wpa_supplicant.py | 59 ++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Linux/src/softwares/wifi/wpa_supplicant.py diff --git a/Linux/src/config/manageModules.py b/Linux/src/config/manageModules.py index dcccd237..a822fb00 100644 --- a/Linux/src/config/manageModules.py +++ b/Linux/src/config/manageModules.py @@ -12,6 +12,7 @@ from softwares.chats.jitsi import Jitsi # wifi from softwares.wifi.wifi import Wifi +from softwares.wifi.wpa_supplicant import wpa_supplicant # databases from softwares.databases.squirrel import Squirrel from softwares.databases.dbvis import DbVisualizer @@ -42,6 +43,7 @@ def get_modules(): SQLDeveloper(), Squirrel(), Wifi(), + wpa_supplicant(), kde() ] return moduleNames diff --git a/Linux/src/softwares/wifi/wpa_supplicant.py b/Linux/src/softwares/wifi/wpa_supplicant.py new file mode 100644 index 00000000..7315ad8b --- /dev/null +++ b/Linux/src/softwares/wifi/wpa_supplicant.py @@ -0,0 +1,59 @@ +from config.header import Header +from config.write_output import print_debug, print_output +from config.moduleInfo import ModuleInfo +import re +import os + +class wpa_supplicant(ModuleInfo): + + filestr = '/etc/wpa_supplicant/wpa_supplicant.conf' + + + def __init__(self): + options = {'command': '-wp', 'action': 'store_true', 'dest': 'wpa_supplicant', 'help': 'WPA Supplicant - Need root Privileges'} + ModuleInfo.__init__(self, 'wpa_supplicant', 'wifi', options) + + def parse_file_network(self, fd): + password=None + ssid=None + + for line in fd: + if re.match('^[ \t]*ssid=', line): + ssid=(line.split("\"")[1]) + if re.match('^[ \t]*psk=', line): + password=line.split("\"")[1] + if re.match('^[ \t]*password=', line): + password=line.split("\"")[1] + if re.match('^[ \t]*}', line): + return (ssid, password) + + + + def parse_file(self): + pwdFound = [] + fd = open(self.filestr) + + for line in fd: + if "network=" in line: + values = {} + (ssid,password) = self.parse_file_network(fd) + if ssid and password: + values['PASSWORD'] = password + values['SSID'] = ssid + pwdFound.append(values) + return pwdFound; + + + def check_file_access(self): + if not os.path.exists(self.filestr): + print_debug('WARNING', 'the path "%s" does not exist' %(self.filestr)) + return -1 + return 0 + + def run(self): + Header().title_info('Wifi (from WPA Supplicant)') + if self.check_file_access(): + return + pwdFound = self.parse_file() + + print_output("wpa_supplicant", pwdFound)