-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_vpn.py
More file actions
49 lines (38 loc) · 1.51 KB
/
setup_vpn.py
File metadata and controls
49 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import pysftp
from linode_api4 import LinodeClient
from constants import LINODE_REGIONS
import os
def create_vpn(provider, region, token):
if provider == "Linode":
return create_linode_vpn(token, region=LINODE_REGIONS[region])
def create_linode_vpn(token, region="eu-west", ltype="g6-nanode-1", image="linode/ubuntu18.10"):
client = LinodeClient(token)
linode, password = client.linode.instance_create(ltype, region, image=image)
print(password)
print(linode.status)
return setup(linode.ipv4[0], "root", password, linode, token)
def setup(ip, username, password, node, token="token"):
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
connected = False
while not connected:
try:
# print(node.status)
sftp = pysftp.Connection(ip, username=username, password=password, cnopts=cnopts)
connected = True
except Exception as e:
print(e)
sftp.put('install.sh')
sftp.execute("bash install.sh")
sftp.execute("mkdir profiles")
sftp.execute("mv /root/yourkeyfile.ovpn /root/profiles/{}.ovpn".format(token))
if not os.path.exists(os.getcwd() + '/configs'):
os.makedirs(os.getcwd() + '/configs')
sftp.get_d('/root/profiles', 'configs')
sftp.execute('rm install.sh')
sftp.close()
return ip, password
if __name__ == "__main__":
setup("45.33.15.88", "root", "n04cce55", None)
# sftp = pysftp.Connection("88.80.188.89", username="root", password="n04cce55")
# sftp.put("openvpn-install.sh")