jokyone commited on
Commit
dc0849b
·
verified ·
1 Parent(s): f65d879

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +120 -0
app.py ADDED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, request, jsonify
2
+ import os
3
+ import requests
4
+
5
+ app = Flask(__name__)
6
+
7
+ # 定义全局字符串变量
8
+ str_values = ''
9
+ str_uvalues = ''
10
+ # 从环境变量中获取密码
11
+ password = os.environ.get('PASSWORD', '123456')
12
+
13
+ # 定义一个函数,接受 Cookie-Values 和要保留的键的列表作为参数
14
+ def filter_cookie_values(cookie_values, keep_keys):
15
+ new_cookie_values = ""
16
+ pairs = [pair.strip() for pair in cookie_values.split(';')]
17
+ for pair in pairs:
18
+ if '=' in pair:
19
+ key, value = pair.split('=', 1)
20
+ key = key.strip()
21
+ value = value.strip()
22
+ if key in keep_keys:
23
+ new_cookie_values += f'{key}={value}; '
24
+ new_cookie_values = new_cookie_values[:-2]
25
+ return new_cookie_values
26
+
27
+ @app.route('/SET', methods=['POST'])
28
+ def set_value():
29
+ method = request.method
30
+ pwd = request.args.get('pwd')
31
+ if not pwd or pwd!= password:
32
+ return 'Invalid password', 401
33
+ keep_keys = ["_U",
34
+ "MUID",
35
+ 'KievRPSSecAuth',
36
+ 'cct',
37
+ 'buid',
38
+ 'ak_bmsc',
39
+ 'bm_sv',
40
+ 'cl_dtrs',
41
+ '_RwBf',
42
+ 'SRCHHPGUSR',
43
+ 'WLS']
44
+ keep_keys_u = ["_U",
45
+ "WLS"]
46
+ cookie_values = request.headers.get('Cookie-Values')
47
+ set_value = filter_cookie_values(cookie_values, keep_keys)
48
+ get_u_value = filter_cookie_values(cookie_values, keep_keys_u)
49
+ if set_value:
50
+ str_values = set_value
51
+ if get_u_value and get_u_value not in str_uvalues:
52
+ str_uvalues += ';' + get_u_value
53
+ return 'Set value successfully'
54
+ else:
55
+ return 'No Cookie-Values in header', 400
56
+
57
+ @app.route('/GET', methods=['GET'])
58
+ def get_value():
59
+ method = request.method
60
+ pwd = request.args.get('pwd')
61
+ if not pwd or pwd!= password:
62
+ return 'Invalid password', 401
63
+ result = {'result': {'cookies': str_values}}
64
+ return jsonify(result)
65
+
66
+ @app.route('/CLS', methods=['GET', 'POST'])
67
+ def clear_value():
68
+ method = request.method
69
+ pwd = request.args.get('pwd')
70
+ if not pwd or pwd!= password:
71
+ return 'Invalid password', 401
72
+ replaced_str = str_uvalues.replace(';', '<br>')
73
+ str_values = ''
74
+ str_uvalues = ''
75
+ return 'Clear value successfully' + '\n' + replaced_str
76
+
77
+ @app.route('/HisU', methods=['GET', 'POST'])
78
+ def history_u():
79
+ method = request.method
80
+ pwd = request.args.get('pwd')
81
+ if not pwd or pwd!= password:
82
+ return 'Invalid password', 401
83
+ replaced_str = str_uvalues.replace(';', '<br>')
84
+ return 'Ukey History:' + '\n' + replaced_str
85
+
86
+ @app.route('/', methods=['GET', 'POST'])
87
+ def root():
88
+ return 'Please visit /SET /GET or /CLS with?pwd=xxxxxx'
89
+
90
+ @app.route('/q', methods=['GET'])
91
+ def q_route():
92
+ url = request.args.get('url')
93
+ if not url:
94
+ return jsonify({'error': 'URL is required'}), 400
95
+ keep_keys = ["_U",
96
+ "MUID",
97
+ 'KievRPSSecAuth',
98
+ 'cct',
99
+ 'buid',
100
+ 'ak_bmsc',
101
+ 'bm_sv',
102
+ '_RwBf',
103
+ 'SRCHHPGUSR',
104
+ 'WLS']
105
+ response = requests.get(url, headers={
106
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0',
107
+ 'Accept-Language': 'zh-CN,zh;q=0.9'
108
+ })
109
+ set_cookie_array = response.headers.get('set-cookie', [])
110
+ if set_cookie_array:
111
+ cookies = [cookie.split(';')[0] for cookie in set_cookie_array]
112
+ cookies_str = '; '.join(cookies)
113
+ else:
114
+ cookies_str = ''
115
+ set_value = filter_cookie_values(cookies_str, keep_keys)
116
+ result = {'result': {'cookies': set_value}}
117
+ return jsonify(result)
118
+
119
+ if __name__ == '__main__':
120
+ app.run(port=7860)