Skip to content

Commit

Permalink
20200614更新
Browse files Browse the repository at this point in the history
  • Loading branch information
AragonSnow committed Jun 14, 2020
1 parent fb25316 commit 4f41e5b
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Build Image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ jobs:
publish: true
imageName: asdaragon/qiandao # dockerid/imageName
platform: linux/arm64,linux/amd64 # 你准备构建的镜像平台
tag: 20200612,latest
tag: 20200614,latest
dockerHubUser: ${{ secrets.DOCKER_USERNAME }} # docker hub userid 在setting创建secrets name=DOCKER_USERNAME value=dockerid
dockerHubPassword: ${{ secrets.DOCKER_PASSWORD }} # docker hub password,在setting创建secrets name=DOCKER_PASSWORD value=dockerpassword
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ docker地址:[https://hub.docker.com/r/asdaragon/qiandao](https://hub.docker.c

docker部署命令:``` docker run -d --name qiandao -p 12345:80 -v $(pwd)/qiandao/config:/usr/src/app/config asdaragon/qiandao ```

## 2020.6.14 更新
1. 添加RSA加密/解密
2. 用户管理页面添加用户最后登陆时间
3. 字符串替换功能可以返回纯文本,避免有转义'\\'的出现,需要替换参数r=text

## 2020.6.12 更新
1. 定时日志BUG太多,修不过来,取消此功能
2. 修复用户不存在时登录500错误
Expand Down
2 changes: 1 addition & 1 deletion web/handlers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def get(self, userid):
if user and user['role'] == "admin":
adminflg = True
users = []
for user in self.db.user.list(fields=('id','status', 'role', 'ctime', 'email')):
for user in self.db.user.list(fields=('id','status', 'role', 'ctime', 'email', 'atime')):
if user['role'] != 'admin':
users.append(user)

Expand Down
109 changes: 108 additions & 1 deletion web/handlers/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,19 @@
import pytz
from base import *
from tornado import gen
import base64
from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5
from Crypto import Random


def request_parse(req_data):
'''解析请求数据并以json形式返回'''
if req_data.method == 'POST':
data = req_data.body_arguments
elif req_data.method == 'GET':
data = req_data.arguments
return data


class UtilDelayHandler(BaseHandler):
Expand Down Expand Up @@ -112,13 +125,106 @@ def get(self):
t = self.get_argument("t", "")
Rtv[u"原始字符串"] = s
Rtv[u"处理后字符串"] = re.sub(p, t, s)
Rtv[u"状态"] = "OK"
Rtv[u"状态"] = "OK"
if self.get_argument("r", "") == "text":
self.write(Rtv[u"处理后字符串"])
return
else:
self.set_header('Content-Type', 'application/json; charset=UTF-8')
self.write(json.dumps(Rtv, ensure_ascii=False, indent=4))
return
except Exception as e:
Rtv["状态"] = str(e)

self.set_header('Content-Type', 'application/json; charset=UTF-8')
self.write(json.dumps(Rtv, ensure_ascii=False, indent=4))

class UtilRSAHandler(BaseHandler):
@gen.coroutine
def get(self):
try:
res_data = request_parse(self.request)
key = res_data["key"][0] if "key" in res_data else None
data = res_data["data"][0] if "data" in res_data else None
func = res_data["f"][0] if "f" in res_data else None
if (key) and (data) and (func):
lines = ""
temp = key
temp = re.findall("-----.*?-----", temp)
if (len(temp) == 2):
keytemp = key
for t in temp:
keytemp = keytemp.replace(t, "")

while(keytemp):
line = keytemp[0:63]
lines = lines+line+"\n"
keytemp = keytemp.replace(line, "")

lines = temp[0]+"\n" + lines + temp[1]

else:
self.write(u"证书格式错误")
return

cipher_rsa = PKCS1_v1_5.new(RSA.import_key(lines))
if (func.find("encode") > -1):
crypt_text = cipher_rsa.encrypt(bytes(data))
crypt_text = base64.b64encode(crypt_text).decode('utf8')
self.write(crypt_text)
return
elif (func.find("decode") > -1):
t1 = base64.b64decode(data)
decrypt_text = cipher_rsa.decrypt(t1, Random.new().read)
decrypt_text = decrypt_text.decode('utf8')
self.write(decrypt_text)
return
else:
self.write(u"功能选择错误")
return
else:
self.write(u"参数不完整,请确认")
except Exception as e:
self.write(str(e))
return

@gen.coroutine
def post(self):
try:
res_data = request_parse(self.request)
key = res_data["key"][0] if "key" in res_data else None
data = res_data["data"][0] if "data" in res_data else None
func = res_data["f"][0] if "f" in res_data else None
if (key) and (data) and (func):
lines = ""
for line in key.split("\n"):
if (line.find("--") < 0):
line = line.replace(" ", "+")
lines = lines+line+"\n"
data = data.replace(" ", "+")

cipher_rsa = PKCS1_v1_5.new(RSA.import_key(lines))
if (func.find("encode") > -1):
crypt_text = cipher_rsa.encrypt(bytes(data))
crypt_text = base64.b64encode(crypt_text).decode('utf8')
self.write(crypt_text)
return
elif (func.find("decode") > -1):
decrypt_text = cipher_rsa.decrypt(base64.b64decode(data), Random.new().read)
decrypt_text = decrypt_text.decode('utf8')
self.write(decrypt_text)
return
else:
self.write(u"功能选择错误")
return
else:
self.write(u"参数不完整,请确认")
except Exception as e:
self.write(str(e))
return




handlers = [
('/util/delay/(\d+)', UtilDelayHandler),
Expand All @@ -127,4 +233,5 @@ def get(self):
('/util/urldecode', UrlDecodeHandler),
('/util/regex', UtilRegexHandler),
('/util/string/replace', UtilStrReplaceHandler),
('/util/rsa', UtilRSAHandler),
]
24 changes: 23 additions & 1 deletion web/static/har/entry_editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions web/tpl/har/entry_editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,7 @@
<button type=button class="btn btn-default btn-xs" ng-click="add_urldecode_request()">插入url解码</button>
<button type=button class="btn btn-default btn-xs" ng-click="add_regex_request()">插入正则表达式</button>
<button type=button class="btn btn-default btn-xs" ng-click="add_string_replace_request()">插入字符串替换</button>
<button type=button class="btn btn-default btn-xs" ng-click="add_string_replace_request()">插入RSA加密</button>
</div>
<button type="button" class="btn btn-success do-test" data-loading-test="Loading..."
ng-show="panel=='test' || panel=='preview' || panel=='preview-headers'"
Expand Down
2 changes: 2 additions & 0 deletions web/tpl/user_manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ <h2 class="text-center">用户列表</h2>
<th>用户邮箱</th>
<th>状态</th>
<th>创建时间</th>
<th>最后登陆时间</th>
</tr>
</thead>
<tbody>
Expand All @@ -26,6 +27,7 @@ <h2 class="text-center">用户列表</h2>
<td>{{ user.email }}</td>
<td>{{ user.status }}</td>
<td>{{ format_date(user.ctime,-8*60,True,False,True)}}</td>
<td>{{ format_date(user.atime,-8*60,True,False,True)}}</td>
</tr>
{% endfor %}
</tbody>
Expand Down

0 comments on commit 4f41e5b

Please sign in to comment.