From d0b0ba634b83b0e9007ba7f871a5065ad64fdb82 Mon Sep 17 00:00:00 2001 From: valeth Date: Thu, 21 Apr 2016 22:11:26 +0200 Subject: [PATCH] add snippet and script for wpa_supplicant.conf --- UltiSnips/all.snippets | 18 ++++++++++++++++++ pythonx/ultisnips/all.py | 14 ++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/UltiSnips/all.snippets b/UltiSnips/all.snippets index e69de29..61cd00f 100644 --- a/UltiSnips/all.snippets +++ b/UltiSnips/all.snippets @@ -0,0 +1,18 @@ +global !p +from ultisnips.all import * +endglobal + +snippet wpanet "wpa_supplicant network entry" b +network=\{ + ssid="${1:SSID}" + key_mgmt=${2:WPA-PSK} + proto=${3:RSN WPA} + pairwise=${4:CCMP TKIP} + group=${5:CCMP TKIP} + #psk="${6:PSK}" + psk=`!p snip.rv = getWPAPassphraseHash(t[1], t[6])` + priority=${7:10} +\} + +endsnippet + diff --git a/pythonx/ultisnips/all.py b/pythonx/ultisnips/all.py index 7bf056f..c6f718b 100644 --- a/pythonx/ultisnips/all.py +++ b/pythonx/ultisnips/all.py @@ -1,3 +1,6 @@ +import subprocess +import re + def getUsername(username, gecos = True, passwd = "/etc/passwd"): content = [x.split(":") for x in open(passwd, "r").readlines()] @@ -8,3 +11,14 @@ def getUsername(username, gecos = True, passwd = "/etc/passwd"): else: return username +def getWPAPassphraseHash(ssid, passphrase): + if len(passphrase) >= 8: + cmds = ["wpa_passphrase", ssid, passphrase, "|", "grep", "-E", "'^\s*psk.*'", "|", "cut", "-d=", "-f2"] + proc = subprocess.Popen(cmds, stdout=subprocess.PIPE) + proc.wait() + for line in proc.stdout.readlines(): + match = re.match("^\s*psk.*$", line.decode("utf-8")) + if match: + return match.string.split("=")[1].strip() + return "" +