forked from merwin-asm/DarkmaskAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
111 lines (96 loc) · 2.3 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
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
"""
Darkmask API
By ~ Darkmash
"""
from flask import Flask, request
from flask_cors import CORS
import logging
import random
import string
import json
app = Flask(__name__)
CORS(app)
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
def read():
db = open("db.json", "r")
URLS =json.loads(db.read())
db.close()
return URLS
def write(new):
db = open("db.json", "w")
db.write(json.dumps(new))
db.close()
def set(a,b):
db = read()
db[a] = b
write(db)
def encode_url(url):
print(f"ENCODE : URL : {url}")
while True:
result = ''.join((random.choice(string.ascii_lowercase) for x in range(8)))
try:
read()[result]
except:
break
set(result, url)
return result
def decode_url(url):
url_ = read()
if url_[url] == None:
return False
print(f"DECODE : URL : {url_[url]}")
return url_[url]
@app.route('/')
def main_func_():
print("PING__UPTIME")
return """
<meta
property="og:image"
content="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
<meta
name="description"
content="An API for generating masked urls."
/>
<meta name="keywords" content="mask , url , darkmask ,darkmash , tools , startup , coders" />
<link
rel="icon"
type="image/png"
href="https://cdn.discordapp.com/attachments/1023460179087470663/1062001193733337158/image.png"
/>
<title>Darkmask API ~ Darkmash</title>
######## DARKMASH ~ DARKMASK API ~ V.1.0.0 ###################<br>
To use the service [GET - method] ,<br>
  /from <br>
    give the url as url in headers <br>
    returns a masked url <br>
##############################################################
"""
@app.route('/from', methods=['GET'])
def get():
url = request.headers.get("url")
return "https://Darkmask.darkmash.repl.co/" + encode_url(url)
@app.route('/<url>')
def random_(url):
try:
url = decode_url(url)
if url == False:
return f"""
ERROR : Site Not Found
"""
if "https://" in url :
return f"""
<script>
location.href = '{url}';
</script>
"""
else:
return f"""
<script>
location.href = 'https://{url}';
</script>
"""
except:
return "Invalid Url.."
app.run(host="0.0.0.0", port=8080)