I use OpenVPN at my company and am trying to automate user creation process. There's a problem at the certificate generation step I faced now. When trying to build a key for the user (all parameters are predefined) program has to press Enter multiple times and in the end "y" and "Enter" 2 times. I tried using Popen and PIPE, but no luck so far. Would appreciate any insight.
import sys, os
from subprocess import Popen, PIPE
# Generate an .ovpn file
try:
username = sys.argv[1]
except:
print "Error. Supply a username!"
sys.exit()
print("Adding user")
os.system("useradd" + " -m" + " -s" + " /bin/bash" + username)
print("Sourcing vars")
os.system('source + /home/myuser/openvpn-ca/vars')
enter = Popen(['/home/myuser/openvpn-ca/build-key {}'.format(username)]),
stdin=PIPE, shell=True)
enter.communicate(input='\n')
Edit:
This is different than what it was marked [duplicate] for. Here's why:
I don't need to generate a custom certificate, change any values etc. It just needs to press "Enter" multiple times and input "yes" and "Enter" 2 times.