Script improvements
This commit is contained in:
parent
19ea1f8b52
commit
9773b3a5c7
62
pyvpn
Executable file
62
pyvpn
Executable file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pexpect
|
||||
import os.path
|
||||
import base64
|
||||
|
||||
# This script can probably use some improvement
|
||||
|
||||
process = "/root/openvpn-install.sh"
|
||||
|
||||
operatingDir = "/root"
|
||||
|
||||
|
||||
fScript = pexpect.spawn(process)
|
||||
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
|
||||
if sys.argv[1] == "--create-client":
|
||||
|
||||
clientName = sys.argv[2]
|
||||
|
||||
configFilePath = operatingDir + "/" + clientName + ".ovpn"
|
||||
|
||||
fScript.expect("[1-4]:")
|
||||
|
||||
fScript.sendline("1")
|
||||
|
||||
fScript.expect("Client name: ")
|
||||
|
||||
fScript.sendline(clientName)
|
||||
|
||||
fScript.kill(0)
|
||||
|
||||
if os.path.exists(configFilePath):
|
||||
|
||||
file = open(configFilePath, 'r')
|
||||
|
||||
finalResult = base64.b64encode(file.read())
|
||||
|
||||
sys.stdout.write(finalResult)
|
||||
sys.stdout.flush()
|
||||
sys.exit()
|
||||
|
||||
else:
|
||||
sys.stdout.write("Error! OpenVPN did not create the Configuration file.")
|
||||
sys.stdout.flush()
|
||||
sys.stdout.exit()
|
||||
|
||||
|
||||
|
||||
else:
|
||||
sys.stdout.write("Error! Missing options!")
|
||||
sys.stdout.flush()
|
||||
sys.stdout.exit()
|
||||
|
||||
else:
|
||||
sys.stdout.write("Error! Missing client name!")
|
||||
sys.stdout.flush()
|
||||
sys.stdout.exit()
|
Loading…
Reference in New Issue
Block a user