This repository has been archived by the owner on Aug 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
cnl.py
184 lines (143 loc) · 4.77 KB
/
cnl.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# -*- coding: utf-8 -*-
from __future__ import absolute_import, unicode_literals
import os
import re
from base64 import standard_b64decode
from binascii import unhexlify
from builtins import int, str
from traceback import print_exc
from urllib.parse import unquote
from cryptography.fernet import Fernet
from future import standard_library
from bottle import HTTPError, request, route
from pyload.utils import purge
from pyload.utils.fs import ulopen
from .iface import API, DL_ROOT
standard_library.install_aliases()
try:
import js2py
except ImportError:
js2py = None
def generate_and_add(urls, paused):
packs = API.generate_packages(urls)
for name, urls in packs.items():
API.add_package(name, urls, paused=paused)
def local_check(function):
def _view(*args, **kwargs):
if (request.environ.get('REMOTE_ADDR', "0") in ('127.0.0.1', 'localhost') or
request.environ.get('HTTP_HOST', '0') in ('127.0.0.1:9666', 'localhost:9666')):
return function(*args, **kwargs)
else:
return HTTPError(403, "Forbidden")
return _view
@route("/flash")
@route("/flash/:id")
@route("/flash", method="POST")
@local_check
def flash(id="0"):
return "JDownloader\n"
@route("/flash/add", method="POST")
@local_check
def add(request):
package = request.POST.get('referer', None)
urls = [x for x in request.POST['urls'].split("\n") if x != ""]
if package:
API.add_package(package, urls, paused=True)
else:
generate_and_add(urls, True)
return ""
@route("/flash/addcrypted", method="POST")
@local_check
def addcrypted():
package = request.forms.get('referer', 'ClickAndLoad Package')
dlc = request.forms['crypted'].replace(" ", "+")
dlc_path = os.path.join(DL_ROOT, purge.name(package) + ".dlc")
with ulopen(dlc_path, mode='wb') as fp:
fp.write(dlc)
try:
API.add_package(package, [dlc_path], paused=True)
except Exception:
return HTTPError()
else:
return "success\n"
@route("/flash/addcrypted2", method="POST")
@local_check
def addcrypted2():
package = request.forms.get("source", None)
crypted = request.forms['crypted']
jk = request.forms['jk']
token = standard_b64decode(unquote(crypted.replace(" ", "+")))
try:
jk = "{0} f()".format(jk)
jk = js2py.eval_js(jk)
except AttributeError:
try:
jk = re.findall(r"return ('|\")(.+)('|\")", jk)[0][1]
except Exception:
# Test for some known js functions to decode
if jk.find("dec") > -1 and jk.find("org") > -1:
org = re.findall(r"var org = ('|\")([^\"']+)", jk)[0][1]
jk = reversed(org)
jk = "".join(jk)
# else:
# print("Could not decrypt key, please install py-spidermonkey or ossp-js")
try:
key = unhexlify(jk)
except Exception:
print("Could not decrypt key, please install py-spidermonkey or ossp-js")
return "failed"
f = Fernet(key)
result = f.decrypt(token).replace(
"\x00", "").replace("\r", "").split("\n")
result = [x for x in result if x != ""]
try:
if package:
API.add_package(package, result, paused=True)
else:
generate_and_add(result, True)
except Exception:
print_exc()
return "failed"
else:
return "success\n"
@route("/flashgot_pyload")
@route("/flashgot_pyload", method="POST")
@route("/flashgot")
@route("/flashgot", method="POST")
@local_check
def flashgot():
if request.environ['HTTP_REFERER'] != "http://localhost:9666/flashgot" and request.environ[
'HTTP_REFERER'] != "http://127.0.0.1:9666/flashgot":
return HTTPError()
autostart = bool(int(request.forms.get('autostart', 0)))
package = request.forms.get('package', None)
urls = [x for x in request.forms['urls'].split("\n") if x != ""]
# TODO: Use folder
folder = request.forms.get('dir', None)
if package:
API.add_package(package, urls, paused=autostart)
else:
generate_and_add(urls, autostart)
return ""
@route("/crossdomain.xml")
@local_check
def crossdomain():
rep = "<?xml version=\"1.0\"?>\n"
rep += "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd\">\n"
rep += "<cross-domain-policy>\n"
rep += "<allow-access-from domain=\"*\" />\n"
rep += "</cross-domain-policy>"
return rep
@route("/flash/checkSupportForUrl")
@local_check
def checksupport():
url = request.GET.get("url")
res = API.check_urls([url])
supported = (not res[0][1] is None)
return str(supported).lower()
@route("/jdcheck.js")
@local_check
def jdcheck():
rep = "jdownloader=true;\n"
rep += "var version='9.581;'"
return rep