From 9f573e77fd05c7bd6d0853ef0dcbb39588a1534c Mon Sep 17 00:00:00 2001 From: ngfchl Date: Wed, 25 Jan 2023 02:10:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=B2=B9=E7=8C=B4?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=EF=BC=8C=E8=AE=BF=E9=97=AE=E7=AB=99=E7=82=B9?= =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E4=B8=BB=E9=A1=B5=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=AB=99=E7=82=B9=E8=87=B3Ptools?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- PtToPtools.js | 144 +++++++++++++++++++++++++++++++++++++++++ auto_pt/urls.py | 1 + auto_pt/views.py | 52 +++++++++++++++ pt_site/UtilityTool.py | 11 ++-- 4 files changed, 203 insertions(+), 5 deletions(-) create mode 100644 PtToPtools.js diff --git a/PtToPtools.js b/PtToPtools.js new file mode 100644 index 0000000..80e643d --- /dev/null +++ b/PtToPtools.js @@ -0,0 +1,144 @@ +// ==UserScript== +// @name PtToPtools +// @author ngfchl +// @description PT站点cookie等信息发送到Ptools +// @namespace http://tampermonkey.net/ + +// @match https://1ptba.com/userdetails.php?id=* +// @match https://52pt.site/userdetails.php?id=* +// @match https://audiences.me/userdetails.php?id=* +// @match https://byr.pt/userdetails.php?id=* +// @match https://ccfbits.org/userdetails.php?id=* +// @match https://club.hares.top/userdetails.php?id=* +// @match https://discfan.net/userdetails.php?id=* +// @match https://et8.org/userdetails.php?id=* +// @match https://filelist.io/userdetails.php?id=* +// @match https://hdatmos.club/userdetails.php?id=* +// @match https://hdchina.org/userdetails.php?id=* +// @match https://hdcity.leniter.org/userdetails.php?id=* +// @match https://hdhome.org/userdetails.php?id=* +// @match https://hdmayi.com/userdetails.php?id=* +// @match https://hdsky.me/userdetails.php?id=* +// @match https://hdtime.org/userdetails.php?id=* +// @match https://hudbt.hust.edu.cn/userdetails.php?id=* +// @match https://iptorrents.com/t +// @match https://kp.m-team.cc/userdetails.php?id=* +// @match https://lemonhd.org/userdetails.php?id=* +// @match https://nanyangpt.com/userdetails.php?id=* +// @match https://npupt.com/userdetails.php?id=* +// @match https://ourbits.club/userdetails.php?id=* +// @match https://pt.btschool.club/userdetails.php?id=* +// @match https://pt.eastgame.org/userdetails.php?id=* +// @match https://pt.hdbd.us/userdetails.php?id=* +// @match https://pt.keepfrds.com/userdetails.php?id=* +// @match https://pterclub.com/userdetails.php?id=* +// @match https://pthome.net/userdetails.php?id=* +// @match https://springsunday.net/userdetails.php?id=* +// @match https://totheglory.im/userdetails.php?id=* +// @match https://u2.dmhy.org/userdetails.php?id=* +// @match https://www.beitai.pt/userdetails.php?id=* +// @match https://www.haidan.video/userdetails.php?id=* +// @match https://www.hdarea.co/userdetails.php?id=* +// @match https://www.hddolby.com/userdetails.php?id=* +// @match https://www.htpt.cc/userdetails.php?id=* +// @match https://www.nicept.net/userdetails.php?id=* +// @match https://www.pthome.net/userdetails.php?id=* +// @match https://www.pttime.org +// @match https://www.tjupt.org/userdetails.php?id=* +// @match https://www.torrentleech.org +// @match https://www.carpet.net/userdetails.php?id=* +// @match https://wintersakura.net/userdetails.php?id=* +// @match https://hhanclub.top/userdetails.php?id=* +// @match https://www.hdpt.xyz/userdetails.php?id=* +// @match https://ptchina.org/userdetails.php?id=* +// @match https://www.oshen.win/userdetails.php?id=* +// @match https://www.hd.ai/userdetails.php?id=* +// @match http://ihdbits.me/userdetails.php?id=* +// @match https://zmpt.cc/userdetails.php?id=* +// @match https://leaves.red/userdetails.php?id=* +// @match https://piggo.me/userdetails.php?id=* +// @version 0.0.1 +// @grant GM_xmlhttpRequest +// @grant none +// @license GPL-3.0 License +// @require https://cdn.bootcdn.net/ajax/libs/jquery/3.6.3/jquery.min.js +// ==/UserScript== + +/* +日志: + 2023.01.25 完成第一版0.0.1 + 2023.01.24 开始编写第一版脚本 + +*/ +this.$ = this.jQuery = jQuery.noConflict(true); + +// 设置ptools的访问地址,如http://192.168.1.2:8000 +let ptools = "http://127.0.0.1:8000/"; +// 获取安全密钥token,可以在ptools.toml中自定义, +// 格式 [token] token="ptools" +var token = "ptools"; +var path = "tasks/monkey_to_ptools"; + + +(function () { + 'use strict'; + main(); +})(); + +async function getSite() { + return $.ajax({ + url: ptools + path, + type: "get", + dataType: "json", + data: {url: document.location.origin + '/', token: token} + }).then(res => { + // console.log(data); + if (res.code !== 0) { + console.error(res.msg) + return + } + console.log('站点信息获取成功!', res.data) + return res.data + }) +} + +async function getData() { + var site_info = await getSite() + console.log(site_info) + //获取cookie与useragent + let user_agent = window.navigator.userAgent + let cookie = document.cookie + let re = /\d+/; + let href = document.location.search + let user_id = re.exec(href)[0] + return { + user_id: user_id, + site_id: site_info.site_id, + cookie: cookie, + token: token, + user_agent: user_agent + } +} + +async function main() { + var data = await getData(); + if (data == false) return; + console.log(data) + let res = await ajax_post(data) + console.log(res) + //await sendSiteToNastools(data); + +} + + +async function ajax_post(data) { + return $.ajax({ + type: "POST", + url: ptools + path, + dataType: "json", + data: JSON.stringify(data), + }).then(res => { + console.log(res) + return res + }); +} \ No newline at end of file diff --git a/auto_pt/urls.py b/auto_pt/urls.py index 2872dbf..cd22470 100644 --- a/auto_pt/urls.py +++ b/auto_pt/urls.py @@ -39,6 +39,7 @@ urlpatterns = [ path(r'remove_log_api', views.remove_log_api, name='remove_log_api'), path(r'get_site_list', views.get_site_list, name='get_site_list'), path(r'edit_my_site', views.edit_my_site, name='edit_my_site'), + path(r'monkey_to_ptools', views.monkey_to_ptools, name='monkey_to_ptools'), path(r'get_site_torrents', views.get_site_torrents, name='get_site_torrents'), path(r'get_helper_license', views.get_helper_license, name='get_helper_license'), path(r'downloading_status', views.downloading_status, name='downloading_status'), diff --git a/auto_pt/views.py b/auto_pt/views.py index af2ee27..b699d1f 100644 --- a/auto_pt/views.py +++ b/auto_pt/views.py @@ -1215,3 +1215,55 @@ def exec_shell_command(request): return JsonResponse(data=CommonResponse.success( data=p ).to_dict(), safe=False) + + +def monkey_to_ptools(request): + my_token = pt_spider.parse_token('token') + if my_token.code != 0: + return JsonResponse(data=CommonResponse.error( + msg='Token认证失败!' + ).to_dict(), safe=False) + own_token = my_token.data + if request.method == 'GET': + url = request.GET.get('url') + token = request.GET.get('token') + if len(token) > 0 and token != own_token.get('token'): + return JsonResponse(data=CommonResponse.error( + msg='Token认证失败!' + ).to_dict(), safe=False) + logger.info(url) + site_list = Site.objects.filter(url=url) + if len(site_list) == 1: + data = {'site_id': site_list.first().id} + # if len(my_site_list) == 1: + # data.update({ + # 'my_site_id': my_site_list.first().id + # }) + return JsonResponse(data=CommonResponse.success( + data=data + ).to_dict(), safe=False) + return JsonResponse(data=CommonResponse.error( + msg='站点信息获取失败!' + ).to_dict(), safe=False) + else: + my_site_params = json.loads(request.body) + logger.info(my_site_params) + token = my_site_params.get('token') + if len(token) > 0 and token != own_token.get('token'): + return JsonResponse(data=CommonResponse.error( + msg='Token认证失败!' + ).to_dict(), safe=False) + site_id = my_site_params.get('site_id') + logger.info(site_id) + try: + res_my_site = MySite.objects.update_or_create(site_id=site_id, defaults=my_site_params) + logger.info(res_my_site[1]) + + return JsonResponse(data=CommonResponse.success( + msg=f'{res_my_site[0].site.name} 添加成功!' + ).to_dict(), safe=False) + except: + logger.info(traceback.format_exc(3)) + return JsonResponse(data=CommonResponse.error( + msg='站点信息添加失败!' + ).to_dict(), safe=False) diff --git a/pt_site/UtilityTool.py b/pt_site/UtilityTool.py index a9b1bf8..986033b 100644 --- a/pt_site/UtilityTool.py +++ b/pt_site/UtilityTool.py @@ -2489,13 +2489,14 @@ class PtSpider: msg='配置文件文件已存在!', ) except Exception as e: - return CommonResponse.success( + return CommonResponse.error( msg=f'初始化失败!{e}', ) - def parse_uuid(self): + @staticmethod + def parse_token(cmd): with open('db/ptools.toml', 'r') as f: data = toml.load(f) - vip = data.get('vip') - os.environ['VIP'] = vip.get('key') - uuid = os.getenv() + return CommonResponse.success( + data=data.get(cmd) + )