-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdash.py
117 lines (92 loc) · 4.12 KB
/
dash.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
import sys
try:
import time,subprocess,os,colors
except:
process_display(1,1,"Module not found\n Make sure you have installed 'requirements.txt' and configured DASH")
sys.exit(0)
def header():
print('\n\t\t{}-{} DASH {}-{}\n'.format(colors.red,colors.white,colors.red,colors.white))
def process_display(verbose,type,message):
if args.v is False:
verbose = 0
if type == 0 and verbose == 0:
colors.success(message)
elif type == 1 and verbose == 0:
colors.error(message)
elif type == 2 and verbose == 0:
colors.process(message)
elif type == 3 and verbose == 0:
colors.info(message)
def local(port,path):
local_process = subprocess.Popen(['python3 ./local.py -port {} -path {}'.format(port,path)],stdout=subprocess.PIPE,stderr=subprocess.STDOUT,shell = True)
for output in local_process.stdout:
output=output.decode('utf-8')
if "Traceback" in output:
process_display(0,1,"Error due to usable port")
process_display(0,3,"Restarting with new port")
local(int(port)+1,path)
elif "Running" in output:
process_display(1,0,"[2/2] Local Server is started.")
print("\n")
elif "ClientIP" in output:
ClientIP = output[10:]
elif "127.0.0.1" in output:
out = str(output).split(' ')
with open('ip.bin', 'r') as file: # extracting the ip from the file
ip = file.read()
if out[6] == '/':
process_display(0,0,"Someone at {} has opened your page.".format(ip))
elif out[-2] == '204':
process_display(0,0,"File received from {}".format(ip))
def forward(port):
try:
import requests
import json
except:
process_display(1,1,"Module not found\n Make sure you have installed 'requirements.txt' and configured DASH")
sys.exit(0)
ngrok = subprocess.Popen(['ngrok','http','-region','ap' ,str(port)],stdout=subprocess.PIPE)
process_display(1,0,"[1/2] Public Server is started.")
time.sleep(3)
tunnel_url = requests.get("http://localhost:4040/api/tunnels").text
j = json.loads(tunnel_url)
try:
tunnel_url = j['tunnels'][0]['public_url']
process_display(0,0,"The link for the page is : "+tunnel_url)
except IndexError:
process_display(1,2,"Rechecking the URLs in 4s :/ ")
time.sleep(4)
tunnel_url = requests.get("http://localhost:4040/api/tunnels").text
j = json.loads(tunnel_url)
tunnel_url = j['tunnels'][0]['public_url']
process_display(0,0,"The link for the page is : "+tunnel_url)
print("\n{}-------------------------------{} _^_ {}-------------------------------{}\n".format(colors.white,colors.red,colors.white,colors.red))
if __name__ == "__main__":
try:
header() # Prints logo on console. P.S : I'm not a designer :/
try:
import argparse
parser = argparse.ArgumentParser()
except:
process_display(1,1,"Module not found\n Make sure you have installed 'requirements.txt' and configured DASH")
sys.exit(0)
parser.add_argument('-port',help="Port address",required = False,default = 5050)
parser.add_argument('-path',help="Path to save file",required = False,default=os.path.expanduser('~')+'/Desktop')
parser.add_argument('-v',help="Verbose",default=False, action='store_true',required = False)
args = parser.parse_args()
try:
import threading
except:
process_display(1,1,"Module not found\n Make sure you have installed 'requirements.txt' and configured DASH")
sys.exit(0)
thread1 = threading.Thread(target=forward,args=(args.port,))
thread2 = threading.Thread(target=local,args=(args.port,args.path))
thread1.start()
time.sleep(1)
thread2.start()
thread1.join()
thread2.join()
except:
os.remove('ip.bin') # deleting the file which contains the ip
print("\nYou're Great..!\nThanks for using :)")
sys.exit(0)