Add forgotten source code
This commit is contained in:
parent
7ecbc34d17
commit
25cbcd97e5
53
pyVPN.py
Normal file
53
pyVPN.py
Normal file
@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import sys
|
||||
import pexpect
|
||||
import os.path
|
||||
import base64
|
||||
|
||||
# This script can probably use some improvement
|
||||
|
||||
process = "/root/openvpn-install/openvpn-installer.sh"
|
||||
operatingDir = "/root"
|
||||
|
||||
fScript = pexpect.spawn("/bin/bash" + process)
|
||||
|
||||
if len(sys.argv) > 2:
|
||||
|
||||
if sys.argv[2] == "--create-client":
|
||||
|
||||
clientName = sys.argv[3]
|
||||
configFilePath = operatingDir + "/" + clientName + ".ovpn"
|
||||
|
||||
fScript.expect(r'/(?:Select\ an\ option\ \[1\-4\]\:)/')
|
||||
fScript.sendline('1')
|
||||
fScript.expect(r'(?: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(0)
|
||||
|
||||
else:
|
||||
sys.stdout.write("Error! OpenVPN did not create the Configuration file.")
|
||||
sys.stdout.flush()
|
||||
sys.stdout.exit(1)
|
||||
|
||||
|
||||
|
||||
else:
|
||||
sys.stdout.write("Error! Missing options!")
|
||||
sys.stdout.flush()
|
||||
sys.stdout.exit(2)
|
||||
|
||||
else:
|
||||
sys.stdout.write("Error! Missing client name!")
|
||||
sys.stdout.flush()
|
||||
sys.stdout.exit(3)
|
Loading…
Reference in New Issue
Block a user