add snippet and script for wpa_supplicant.conf
This commit is contained in:
parent
d6fcdb2060
commit
d0b0ba634b
@ -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
|
||||||
|
|
@ -1,3 +1,6 @@
|
|||||||
|
import subprocess
|
||||||
|
import re
|
||||||
|
|
||||||
def getUsername(username, gecos = True, passwd = "/etc/passwd"):
|
def getUsername(username, gecos = True, passwd = "/etc/passwd"):
|
||||||
content = [x.split(":") for x in open(passwd, "r").readlines()]
|
content = [x.split(":") for x in open(passwd, "r").readlines()]
|
||||||
|
|
||||||
@ -8,3 +11,14 @@ def getUsername(username, gecos = True, passwd = "/etc/passwd"):
|
|||||||
else:
|
else:
|
||||||
return username
|
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 ""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user