-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
76 lines (50 loc) · 2.02 KB
/
main.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from configurations.import_json_configuration import loaddata
import requests
from clint.textui import progress
import os
from ngrok_core import NgRokCore
NGROK_FILE_LOCATION=""
FETCHING_METHOD=""
NGROK_FILE_NAME=""
BACKEND_OS_NGROK=""
ngcore
class Configration:
def __init__(self):
self.NGROK_FILE_LOCATION, self.FETCHING_METHOD, self.NGROK_FILE_NAME, self.BACKEND_OS_NGROK = loaddata()
def download_ngrok_file(ngrokresource,filename):
config = Configration()
print(f"------------ Downloading File {config.NGROK_FILE_NAME} : Progress ------------")
r = requests.get(config.NGROK_FILE_LOCATION, stream=True)
path = config.NGROK_FILE_NAME+".zip"
with open(path, 'wb') as f:
total_length = int(r.headers.get('content-length'))
for chunk in progress.bar(r.iter_content(chunk_size=1024), expected_size=(total_length / 1024) + 1):
if chunk:
f.write(chunk)
f.flush()
print(f"------------ Downloading File {config.NGROK_FILE_NAME} : Completed ------------")
def setpasswd(passkey):
"""
This function is set passwd for sshprocess for user:root,
When making a ssh session for remote instance. required a password for
establishing secure connection
example:
>> ssh_ngrok.setpasswd("your-passkey")
"""
os.system(f"echo \"root:{passkey}\" | chpasswd > /dev/null")
__setupconf__
def setauth(self,auth):
ngrokcore = NgRokCore(authkey=auth)
def __setupconf__():
"""
This function added the additional sshd configuration for remote connection
"""
os.system("echo \"PasswordAuthentication yes\" > /etc/ssh/sshd_config")
os.system("echo \"PermitUserEnvironment yes\" > /etc/ssh/sshd_config")
os.system("echo \"PermitRootLogin yes\" > /etc/ssh/sshd_config")
os.system("service ssh restart > /dev/null")
def main():
config = Configration()
download_ngrok_file(config.NGROK_FILE_LOCATION,config.NGROK_FILE_NAME)
if __name__ == '__main__':
main()