Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lm317379829 authored May 26, 2023
1 parent 8fe9bc0 commit 96b5f6a
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 59 deletions.
12 changes: 2 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@

### 自行部署到replit等平台,或利用docker部署。token经过AES加密,iv与key自行保存,防止token泄露。

访问服务器ip或域名:8888为默认网页
访问服务器ip或域名:8888为默认404网页

### 首次使用

post 访问 服务器ip或域名:8888/token?token=你的token&iv=你的初始化向量&key=你的秘钥

将AES加密后的token上传至服务器content.txt文件中。

### 后续使用

get 访问 服务器ip或域名:8888/token?iv=你的初始化向量&key=你的秘钥
访问 服务器ip或域名:8888/token?iv=你的初始化向量&key=你的秘钥

可添加参数:display、delFile、refresh

Expand Down
134 changes: 85 additions & 49 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import re
import os
import json
import time
import base64
import requests

from flask import Flask, request, render_template
from flask import Flask, redirect, request, render_template, send_from_directory
from aes import AES
from ali import Ali

Expand All @@ -29,8 +29,13 @@ def encrypt(self, iv, key, content):
def web():
return render_template('index.html')

@app.route('/token', methods=['POST', 'GET'])
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'templates'), 'favicon.ico', mimetype='image/vnd.microsoft.icon')

@app.route('/token')
def token():
tokenDict = {}
iv = request.args.get('iv')
key = request.args.get('key')
if not iv:
Expand All @@ -46,56 +51,87 @@ def token():
else:
key = key[:16]
try:
if request.method == 'GET':
refresh = request.args.get('refresh')
delFile = request.args.get('delFile')
if delFile:
delFile = True
else:
delFile = False
if refresh:
refresh = True
else:
refresh = False
alicache = requests.get('http://127.0.0.1:8888/cache',params={'key': 'alicache'}).text
if alicache != '' and not refresh:
enc_tokenDict = json.loads(alicache)
if enc_tokenDict['expires_at'] > int(time.time()):
tokenDict = {}
for tkey in enc_tokenDict:
if tkey == 'expires_at':
tokenDict[tkey] = enc_tokenDict[tkey]
continue
tokenDict[tkey] = cryption().decrypt(iv, key, enc_tokenDict[tkey])
else:
with open('content.txt', 'r') as file:
content = file.read()
tokenDict = Ali().refresh_token(cryption().decrypt(iv, key, content), delFile)
enc_tokenDict = {}
for tkey in tokenDict:
refresh = request.args.get('refresh')
delFile = request.args.get('delFile')
if delFile:
delFile = True
else:
delFile = False
if refresh:
refresh = True
else:
refresh = False
alicache = requests.get('http://127.0.0.1:8888/cache', params={'key': 'alicache'}).text
if alicache != '' and not refresh:
enc_tokenDict = json.loads(alicache)
if enc_tokenDict['expires_at'] > int(time.time()):
tokenDict = {}
for tkey in enc_tokenDict:
if tkey == 'expires_at':
enc_tokenDict[tkey] = tokenDict[tkey]
tokenDict[tkey] = enc_tokenDict[tkey]
continue
enc_tokenDict[tkey] = cryption().encrypt(iv, key, tokenDict[tkey])
value = json.dumps(enc_tokenDict).encode()
requests.post('http://127.0.0.1:8888/cache', params={'key': 'alicache'}, data=value, headers={'Content-Length': str(len(value))})
display = request.args.get('display')
if not display:
display = 'token'
if display == 'all':
return json.dumps(tokenDict)
elif display not in ['all', 'token', 'authorization', 'opentoken', 'opauthorization', 'user_id', 'drive_id']:
return tokenDict['token']
else:
return tokenDict[display]
tokenDict[tkey] = cryption().decrypt(iv, key, enc_tokenDict[tkey])
else:
token = request.args.get('token')
content_str = cryption().encrypt(iv, key, token)
with open('content.txt', "w") as file:
file.write(content_str)
return content_str
with open('content.txt', 'r') as file:
content = file.read()
if content == '':
return redirect('/submit')
tokenDict = Ali().refresh_token(cryption().decrypt(iv, key, content), delFile)
if tokenDict == {}:
return redirect('/submit')
enc_tokenDict = {}
for tkey in tokenDict:
if tkey == 'expires_at':
enc_tokenDict[tkey] = tokenDict[tkey]
continue
enc_tokenDict[tkey] = cryption().encrypt(iv, key, tokenDict[tkey])
value = json.dumps(enc_tokenDict).encode()
requests.post('http://127.0.0.1:8888/cache', params={'key': 'alicache'}, data=value, headers={'Content-Length': str(len(value))})
display = request.args.get('display')
if not display:
display = 'token'
if display == 'all':
return json.dumps(tokenDict)
elif display not in ['all', 'token', 'authorization', 'opentoken', 'opauthorization', 'user_id', 'drive_id']:
return tokenDict['token']
else:
return tokenDict[display]
except:
return ''
return redirect('/submit')

@app.route('/process', methods=['POST'])
def process():
iv = request.form.get('iv')
key = request.form.get('key')
if not iv:
iv = ''
if not key:
key = ''
if len(iv) < 16:
iv = iv.rjust(16, '0')
else:
iv = iv[:16]
if len(key) < 16:
key = key.rjust(16, '0')
else:
key = key[:16]
token = request.form.get('token')
content_str = cryption().encrypt(iv, key, token)
with open('content.txt', "w") as file:
file.write(content_str)
domain = request.host_url[:-1]
message = '请牢记你的iv与key。'
show_token = '加密后token为:{}'.format(content_str)
get_token = '{}/token?iv={}&key={}'.format(domain, request.form.get('iv'), request.form.get('key'))
get_all = '{}/token?iv={}&key={}&display=all'.format(domain, request.form.get('iv'), request.form.get('key'))
force_refresh = '{}/token?iv={}&key={}&refresh=True'.format(domain, request.form.get('iv'), request.form.get('key'))
del_file = '{}/token?iv={}&key={}&delFile=True'.format(domain, request.form.get('iv'), request.form.get('key'))
return render_template('result.html', message=message, show_token=show_token, get_token=get_token, get_all=get_all, force_refresh=force_refresh, del_file=del_file)


@app.route('/submit')
def submit():
return render_template('cryption.html')

data = {}
@app.route('/cache', methods=['POST', 'PUT', 'GET', 'DELETE'])
Expand Down
15 changes: 15 additions & 0 deletions templates/cryption.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>加密Token</title>
</head>
<body>
<form method="POST" action="/process">
<input type="text" name="iv">请输入iv<br>
<input type="text" name="key">请输入key<br>
<input type="text" name="token">请输入token<br>
<input type="submit" value="提交">
</form>
</body>
</html>
14 changes: 14 additions & 0 deletions templates/result.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>结果</title>
</head>
<body>
<h1>{{ message }}</h1>
<p>加密后token为:{{ show_token }}</p>
<p>获得token:<a href={{ get_token }}>{{ get_token }}</a><br></p>
<p>获得所有参数:<a href={{ get_all }}>{{ get_all }}</a><br></p>
<p>强制刷新token:<a href={{ force_refresh }}>{{ force_refresh }}</a><br></p>
<p>删除根目录文件:<a href={{ del_file }}>{{ del_file }}</a></p>
</body>
</html>

1 comment on commit 96b5f6a

@vercel
Copy link

@vercel vercel bot commented on 96b5f6a May 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

alitoken – ./

alitoken-lm317379829.vercel.app
alitoken-git-main-lm317379829.vercel.app
alitoken-pi.vercel.app

Please sign in to comment.