Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 90eaa62

Browse files
db notice
1 parent 9a22635 commit 90eaa62

File tree

6 files changed

+103
-13
lines changed

6 files changed

+103
-13
lines changed

‎Dockerfile‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
FROM python:3.8-alpine
1+
FROM python:3.8-alpine as builder
22

3-
RUN apk update && apk add --no-cache tzdata ca-certificates
3+
RUN apk update && apk add --no-cache tzdata ca-certificates alpine-sdk libressl-dev libffi-dev
44
COPY requirements.txt /requirements.txt
5-
RUN pip3 install --no-cache-dir -r /requirements.txt && rm /requirements.txt
5+
RUN pip3 install --user -r /requirements.txt && rm /requirements.txt
6+
7+
8+
9+
FROM python:3.8-alpine
10+
11+
COPY --from=builder /root/.local /usr/local
12+
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
13+
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
614
COPY . /YYeTsBot
15+
RUN apk update && apk add --no-cache libressl
716

817
ENV TZ=Asia/Shanghai
918
WORKDIR /YYeTsBot/yyetsbot
10-
CMD ["python", "bot.py"]
19+
CMD ["python", "bot.py"]

‎requirements.txt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ tgbot-ping
55
redis
66
apscheduler
77
pymongo
8-
tornado
8+
tornado
9+
cryptography

‎web/crypto.py‎

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/local/bin/python3
2+
# coding: utf-8
3+
4+
# YYeTsBot - test.py
5+
# 2/7/21 12:07
6+
#
7+
8+
__author__ = "Benny <benny.think@gmail.com>"
9+
10+
import base64
11+
from hashlib import md5
12+
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
13+
14+
15+
def pad(data):
16+
length = 16 - (len(data) % 16)
17+
return data + (chr(length) * length).encode()
18+
19+
20+
def unpad(data):
21+
return data[:-(data[-1] if type(data[-1]) == int else ord(data[-1]))]
22+
23+
24+
def bytes_to_key(data, salt, output=48):
25+
# extended from https://gist.github.com/gsakkis/4546068
26+
assert len(salt) == 8, len(salt)
27+
data = bytes(data, "ascii")
28+
data += salt
29+
key = md5(data).digest()
30+
final_key = key
31+
while len(final_key) < output:
32+
key = md5(key + data).digest()
33+
final_key += key
34+
return final_key[:output]
35+
36+
37+
def decrypt(encrypted, passphrase):
38+
encrypted = base64.b64decode(encrypted)
39+
assert encrypted[0:8] == b"Salted__"
40+
salt = encrypted[8:16]
41+
key_iv = bytes_to_key(passphrase, salt, 32 + 16)
42+
key = key_iv[:32]
43+
iv = key_iv[32:]
44+
cipher = Cipher(algorithms.AES(key), modes.CBC(iv))
45+
decryptor = cipher.decryptor()
46+
a = decryptor.update(encrypted[16:]) + decryptor.finalize()
47+
return unpad(a)
48+
49+
50+
if __name__ == '__main__':
51+
passphrase = "39300"
52+
test = "U2FsdGVkX19Sch0x9oifjNaBt9eTkZSPUUVVhpjAp0s="
53+
result = decrypt(test, passphrase)
54+
print(result)

‎web/index.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@
6161
<h1>人人影视下载分享</h1>
6262
<h1>By Benny</h1>
6363
<br>
64-
<h2>这是我偷过来的,嘿嘿😝</h2>
64+
<h2>本站数据库<b><a style="text-decoration: none;color: skyblue" href="https://t.me/mikuri520/668">永久开源免费</a></b>,请不要做无意义的爬虫
65+
</h2>
6566
<h2><a style="text-decoration: none;color: deepskyblue" href="https://t.me/yyets_bot">这个 Telegram Bot</a>
6667
里去使用,或者使用下方搜索框</h2>
6768
<form action="search.html">

‎web/js/jquery.min.js‎

Lines changed: 1 addition & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎web/server.py‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import os
1111
import contextlib
12+
import logging
1213

1314
import pymongo
1415
from http import HTTPStatus
@@ -19,6 +20,8 @@
1920
from tornado.concurrent import run_on_executor
2021
from apscheduler.schedulers.background import BackgroundScheduler
2122

23+
from crypto import decrypt
24+
2225
enable_pretty_logging()
2326

2427
mongo_host = os.getenv("mongo") or "localhost"
@@ -48,11 +51,37 @@ def get(self):
4851
self.write(html)
4952

5053

54+
def anti_crawler(self) -> bool:
55+
cypertext = self.request.headers.get("ne1", "")
56+
referer = self.request.headers.get("Referer")
57+
param = self.get_query_argument("id")
58+
59+
if (referer is None) or (param not in referer):
60+
return True
61+
62+
try:
63+
logging.info("Verifying for %s", self.request.uri)
64+
passphrase = param
65+
result = decrypt(cypertext, passphrase).decode('u8')
66+
except Exception:
67+
logging.error("Decrypt failed")
68+
result = ""
69+
70+
if result != self.request.uri:
71+
return True
72+
73+
5174
class ResourceHandler(BaseHandler):
5275
executor = ThreadPoolExecutor(50)
5376

5477
@run_on_executor()
5578
def get_resource_data(self):
79+
if anti_crawler(self):
80+
# X-Real-IP
81+
logging.info("%s@%s make you happy:-(", self.request.headers.get("user-agent"),
82+
self.request.headers.get("X-Real-IP")
83+
)
84+
return {}
5685
param = self.get_query_argument("id")
5786
with contextlib.suppress(ValueError):
5887
param = int(param)
@@ -115,12 +144,12 @@ class MetricsHandler(BaseHandler):
115144

116145
@run_on_executor()
117146
def set_metrics(self):
118-
self.mongo.db['metrics'].update(
147+
self.mongo.db['metrics'].update_one(
119148
{'type': "access"}, {'$inc': {'count': 1}},
120149
upsert=True
121150
)
122151
# today
123-
self.mongo.db['metrics'].update(
152+
self.mongo.db['metrics'].update_one(
124153
{'type': "today"}, {'$inc': {'count': 1}},
125154
upsert=True
126155
)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /