From 29e8718e009809daf9bd5dcea04a19fbd56c06b3 Mon Sep 17 00:00:00 2001 From: midoks Date: Sun, 11 Apr 2021 10:46:53 +0800 Subject: [PATCH] aria2 --- data/api_login.txt | 1 + plugins/aria2/conf/aria2.conf | 102 +++++++++++++++++ plugins/aria2/ico.png | Bin 0 -> 1761 bytes plugins/aria2/index.html | 19 ++++ plugins/aria2/index.py | 193 +++++++++++++++++++++++++++++++++ plugins/aria2/info.json | 15 +++ plugins/aria2/init.d/aria2.tpl | 48 ++++++++ plugins/aria2/install.sh | 49 +++++++++ plugins/aria2/js/aria2.js | 92 ++++++++++++++++ 9 files changed, 519 insertions(+) create mode 100644 data/api_login.txt create mode 100755 plugins/aria2/conf/aria2.conf create mode 100644 plugins/aria2/ico.png create mode 100755 plugins/aria2/index.html create mode 100755 plugins/aria2/index.py create mode 100755 plugins/aria2/info.json create mode 100755 plugins/aria2/init.d/aria2.tpl create mode 100755 plugins/aria2/install.sh create mode 100755 plugins/aria2/js/aria2.js diff --git a/data/api_login.txt b/data/api_login.txt new file mode 100644 index 000000000..8579ef3e5 --- /dev/null +++ b/data/api_login.txt @@ -0,0 +1 @@ +jnuxgfkj \ No newline at end of file diff --git a/plugins/aria2/conf/aria2.conf b/plugins/aria2/conf/aria2.conf new file mode 100755 index 000000000..486da5202 --- /dev/null +++ b/plugins/aria2/conf/aria2.conf @@ -0,0 +1,102 @@ +## 文件保存相关 ## + +# 文件的保存路径(可使用绝对路径或相对路径), 默认: 当前启动位置 +dir=/Users/midoks/Downloads +# 设置日志等级 +log-level=error +# 日志保存路径 +log=/Users/midoks/.aria2/aria2.log +# 启用磁盘缓存, 0为禁用缓存, 需1.16以上版本, 默认:16M +disk-cache=32M +# 文件预分配方式, 能有效降低磁盘碎片, 默认:prealloc +# 预分配所需时间: none < falloc ? trunc < prealloc +# falloc和trunc则需要文件系统和内核支持 +# NTFS建议使用falloc, EXT3/4建议trunc, MAC 下需要注释此项 +#file-allocation=none +# 断点续传 +continue=true + +## 下载连接相关 ## + +# 最大同时下载任务数, 运行时可修改, 默认:5 +max-concurrent-downloads=5 +# 同一服务器连接数, 添加时可指定, 默认:1 +max-connection-per-server=10 +# 最小文件分片大小, 添加时可指定, 取值范围1M -1024M, 默认:20M +# 假定size=10M, 文件为20MiB 则使用两个来源下载; 文件为15MiB 则使用一个来源下载 +min-split-size=10M +# 单个任务最大线程数, 添加时可指定, 默认:5 +split=128 +# 整体下载速度限制, 运行时可修改, 默认:0 +#max-overall-download-limit=0 +# 单个任务下载速度限制, 默认:0 +#max-download-limit=0 +# 整体上传速度限制, 运行时可修改, 默认:0 +#max-overall-upload-limit=0 +# 单个任务上传速度限制, 默认:0 +#max-upload-limit=0 +# 禁用IPv6, 默认:false +disable-ipv6=true + +## 进度保存相关 ## + +# 从会话文件中读取下载任务 +input-file=/Users/midoks/.aria2/aria2.session +# 在Aria2退出时保存`错误/未完成`的下载任务到会话文件 +save-session=/Users/midoks/.aria2/aria2.session +# 定时保存会话, 0为退出时才保存, 需1.16.1以上版本, 默认:0 +#save-session-interval=60 + +## RPC相关设置 ## + +# 启用RPC, 默认:false +enable-rpc=true +# 允许所有来源, 默认:false +rpc-allow-origin-all=true +# 允许非外部访问, 默认:false +rpc-listen-all=true +# 事件轮询方式, 取值:[epoll, kqueue, port, poll, select], 不同系统默认值不同 +#event-poll=select +# RPC监听端口, 端口被占用时可以修改, 默认:6800 +rpc-listen-port=6800 +# 设置的RPC授权令牌, v1.18.4新增功能, 取代 --rpc-user 和 --rpc-passwd 选项 +#rpc-secret=sark +# 设置的RPC访问用户名, 此选项新版已废弃, 建议改用 --rpc-secret 选项 +#rpc-user= +# 设置的RPC访问密码, 此选项新版已废弃, 建议改用 --rpc-secret 选项 +#rpc-passwd= + +## BT/PT下载相关 ## + +# 当下载的是一个种子(以.torrent结尾)时, 自动开始BT任务, 默认:true +#follow-torrent=true +# BT监听端口, 当端口被屏蔽时使用, 默认:6881-6999 +listen-port=51413 +# 单个种子最大连接数, 默认:55 +#bt-max-peers=55 +# 打开DHT功能, PT需要禁用, 默认:true +enable-dht=false +# 打开IPv6 DHT功能, PT需要禁用 +#enable-dht6=false +# DHT网络监听端口, 默认:6881-6999 +#dht-listen-port=6881-6999 +# 本地节点查找, PT需要禁用, 默认:false +#bt-enable-lpd=false +# 种子交换, PT需要禁用, 默认:true +enable-peer-exchange=false +# 每个种子限速, 对少种的PT很有用, 默认:50K +#bt-request-peer-speed-limit=50K +# 客户端伪装, PT需要 +peer-id-prefix=-TR2770- +user-agent=Transmission/2.77 +# 当种子的分享率达到这个数时, 自动停止做种, 0为一直做种, 默认:1.0 +seed-ratio=0 +# 强制保存会话, 即使任务已经完成, 默认:false +# 较新的版本开启后会在任务完成后依然保留.aria2文件 +#force-save=false +# BT校验相关, 默认:true +#bt-hash-check-seed=true +# 继续之前的BT任务时, 无需再次校验, 默认:false +bt-seed-unverified=true +# 保存磁力链接元数据为种子文件(.torrent文件), 默认:false +bt-save-metadata=true diff --git a/plugins/aria2/ico.png b/plugins/aria2/ico.png new file mode 100644 index 0000000000000000000000000000000000000000..51d26b021aeea00e29506ab1f82ded5b17847db5 GIT binary patch literal 1761 zcmV<71|Io|P)(Pt>~0ZMEM)8sP%*Ic53$7#Y*FkS1ADBoMX(cVL=feZ zwIAnQ@5y`4ym7(dKHk}T?e#l*?-jqjM=>%oAFwa50I*=@`3iU^o{xYJfk)dmaa7w1 zOZ06EY!B>SW85c!8-VM9KWp^MZ91huZv>nOtedgq0pKCvGVUEJ@L~ncmjVX>hL_C&v#Tz|xb8AH zQs_I}TBTA3dPU$_VCL|^&SF)$8Q2AIrnjrwsX@ELf%5{ez)PhJ^q#;q;f=?YY8&2Q zn*jVRFjvjKb(*gYJQE!p$MFiK47A?*1mIjCWmRQ5)BD+gPXK@QvTs%GShL-9v5giA zNBVSG|1!`w0lNZw0oRr(>+{~F?TqUeEE>9!6u0#wI=6vl`iTfZ>qpX2rmy$?VG&1< zjD1(Pf7SNtKPMu~A!VJ4X8Imrt5DDs^o+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h|kQ&~N4N-kQ#-W6z#OQGhAIA79}mWk(H9tle(xct38`b}A +
+
+

服务

+

自启动

+

配置修改

+

运行日志

+

说明

+
+
+
+
+
+ + \ No newline at end of file diff --git a/plugins/aria2/index.py b/plugins/aria2/index.py new file mode 100755 index 000000000..ff7e00e6e --- /dev/null +++ b/plugins/aria2/index.py @@ -0,0 +1,193 @@ +# coding:utf-8 + +import sys +import io +import os +import time +import shutil + +sys.path.append(os.getcwd() + "/class/core") +import mw + +app_debug = False +if mw.isAppleSystem(): + app_debug = True + + +def getPluginName(): + return 'aria2' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getInitDTpl(): + path = getPluginDir() + "/init.d/aria2.tpl" + return path + + +def getArgs(): + args = sys.argv[2:] + tmp = {} + args_len = len(args) + + if args_len == 1: + t = args[0].strip('{').strip('}') + t = t.split(':') + tmp[t[0]] = t[1] + elif args_len > 1: + for i in range(len(args)): + t = args[i].split(':') + tmp[t[0]] = t[1] + + return tmp + + +def initDreplace(): + + file_tpl = getInitDTpl() + service_path = os.path.dirname(os.getcwd()) + + initD_path = getServerDir() + '/init.d' + + file_bin = initD_path + '/' + getPluginName() + if not os.path.exists(initD_path): + os.mkdir(initD_path) + + # initd replace + content = mw.readFile(file_tpl) + content = content.replace('{$SERVER_PATH}', service_path) + mw.writeFile(file_bin, content) + mw.execShell('chmod +x ' + file_bin) + + return file_bin + + +def checkArgs(data, ck=[]): + for i in range(len(ck)): + if not ck[i] in data: + return (False, mw.returnJson(False, '参数:(' + ck[i] + ')没有!')) + return (True, mw.returnJson(True, 'ok')) + + +def status(): + cmd = "ps -ef|grep aria2 |grep -v grep | grep -v 'mdserver-web'| awk '{print $2}'" + data = mw.execShell(cmd) + if data[0] == '': + return 'stop' + return 'start' + + +def start(): + + file = initDreplace() + data = mw.execShell(file + ' start') + if data[1] == '': + return 'ok' + return data[1] + + +def stop(): + file = initDreplace() + data = mw.execShell(file + ' stop') + if data[1] == '': + return 'ok' + return data[1] + + +def restart(): + file = initDreplace() + data = mw.execShell(file + ' reload') + if data[1] == '': + return 'ok' + return data[1] + + +def reload(): + file = initDreplace() + data = mw.execShell(file + ' reload') + if data[1] == '': + return 'ok' + return data[1] + + +def getPathFile(): + if mw.isAppleSystem(): + user = mw.execShell( + "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() + return '/Users/' + user + '/.aria2/aria2.conf' + return '/root/.aria2/aria2.conf' + + +def getInitDFile(): + if app_debug: + return '/tmp/' + getPluginName() + return '/etc/init.d/' + getPluginName() + + +def initdStatus(): + if not app_debug: + if mw.isAppleSystem(): + return "Apple Computer does not support" + initd_bin = getInitDFile() + if os.path.exists(initd_bin): + return 'ok' + return 'fail' + + +def initdInstall(): + import shutil + if not app_debug: + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl enable ' + getPluginName()) + return 'ok' + + +def initdUinstall(): + if not app_debug: + if mw.isAppleSystem(): + return "Apple Computer does not support" + + mw.execShell('systemctl disable ' + getPluginName()) + return 'ok' + + +def getLog(): + if mw.isAppleSystem(): + user = mw.execShell( + "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() + return '/Users/' + user + '/.aria2/aria2.log' + return '/root/.aria2/aria2.log' + + +if __name__ == "__main__": + func = sys.argv[1] + if func == 'status': + print status() + elif func == 'start': + print start() + elif func == 'stop': + print stop() + elif func == 'restart': + print restart() + elif func == 'reload': + print reload() + elif func == 'conf': + print getPathFile() + elif func == 'initd_status': + print initdStatus() + elif func == 'initd_install': + print initdInstall() + elif func == 'initd_uninstall': + print initdUinstall() + elif func == 'run_log': + print getLog() + else: + print 'error' diff --git a/plugins/aria2/info.json b/plugins/aria2/info.json new file mode 100755 index 000000000..c7bf31ce2 --- /dev/null +++ b/plugins/aria2/info.json @@ -0,0 +1,15 @@ +{ + "title":"aria2", + "tip":"soft", + "name":"aria2", + "type":"其他插件", + "ps":"一款下载神器", + "versions":"1.0", + "shell":"install.sh", + "checks":"server/aria2", + "path": "server/aria2", + "author":"midoks", + "home":"https://github.com/aria2/aria2", + "date":"2020-06-08", + "pid": "5" +} \ No newline at end of file diff --git a/plugins/aria2/init.d/aria2.tpl b/plugins/aria2/init.d/aria2.tpl new file mode 100755 index 000000000..94559d6ed --- /dev/null +++ b/plugins/aria2/init.d/aria2.tpl @@ -0,0 +1,48 @@ +#!/bin/sh +# chkconfig: 2345 55 25 +# description: aria2 Service + +### BEGIN INIT INFO +# Provides: aria2 +# Required-Start: $all +# Required-Stop: $all +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts aria2 +# Description: starts the MDW-Web +### END INIT INFO + + +app_start(){ + aria2c -D + echo "aria2 started" +} +app_stop(){ + echo "Stopping ..." + arr=`ps -ef | grep "aria2" | grep -v 'grep' | grep -v '/bin/sh'|grep -v 'index.py' | awk '{print $2}'` + echo $arr + for p in ${arr[@]} + do + kill -9 $p &>/dev/null + done + echo "aria2 stopped" +} + + +case "$1" in + start) + app_start + ;; + stop) + app_stop + ;; + restart|reload) + app_stop + sleep 0.3 + app_start + ;; + *) + echo "Please use start or stop as first argument" + ;; +esac + diff --git a/plugins/aria2/install.sh b/plugins/aria2/install.sh new file mode 100755 index 000000000..145c900d4 --- /dev/null +++ b/plugins/aria2/install.sh @@ -0,0 +1,49 @@ +#!/bin/bash +PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin +export PATH + +curPath=`pwd` +rootPath=$(dirname "$curPath") +rootPath=$(dirname "$rootPath") +serverPath=$(dirname "$rootPath") + + +install_tmp=${rootPath}/tmp/mw_install.pl + +SYSOS=`uname` + +Install_aria2() +{ + isStart="" + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/aria2 + echo '1.0' > $serverPath/aria2/version.pl + + if [ "Darwin" == "$SYSOS" ];then + echo 'macosx unavailable' > $install_tmp + find_sh=`which aria2c` + if [ ! -f $find_sh ];then + brew install aria2 + fi + else + find_sh=`which aria2c` + if [ ! -f $find_sh ];then + yum install aria2 -y + fi + fi + + echo 'Install complete' > $install_tmp +} + +Uninstall_aria2() +{ + rm -rf $serverPath/aria2 + echo "Uninstall completed" > $install_tmp +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_aria2 +else + Uninstall_aria2 +fi diff --git a/plugins/aria2/js/aria2.js b/plugins/aria2/js/aria2.js new file mode 100755 index 000000000..1f56ea10e --- /dev/null +++ b/plugins/aria2/js/aria2.js @@ -0,0 +1,92 @@ +function str2Obj(str){ + var data = {}; + kv = str.split('&'); + for(i in kv){ + v = kv[i].split('='); + data[v[0]] = v[1]; + } + return data; +} + +function lpPost(method,args,callback, title){ + + var _args = null; + if (typeof(args) == 'string'){ + _args = JSON.stringify(str2Obj(args)); + } else { + _args = JSON.stringify(args); + } + + var _title = '正在获取...'; + if (typeof(title) != 'undefined'){ + _title = title; + } + + var loadT = layer.msg(_title, { icon: 16, time: 0, shade: 0.3 }); + $.post('/plugins/run', {name:'aria2', func:method, args:_args}, function(data) { + layer.close(loadT); + if (!data.status){ + layer.msg(data.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + + if(typeof(callback) == 'function'){ + callback(data); + } + },'json'); +} + +function lpAsyncPost(method,args){ + var _args = null; + if (typeof(args) == 'string'){ + _args = JSON.stringify(str2Obj(args)); + } else { + _args = JSON.stringify(args); + } + + var loadT = layer.msg('正在获取...', { icon: 16, time: 0, shade: 0.3 }); + return syncPost('/plugins/run', {name:'l2tp', func:method, args:_args}); +} + +function userList(){ + lpPost('user_list', '' ,function(data){ + var rdata = $.parseJSON(data['data']); + + if (!rdata['status']){ + layer.msg(rdata.msg,{icon:0,time:2000,shade: [0.3, '#000']}); + return; + } + var list = rdata['data']; + + var con = ''; + con += '
'; + con += ''; + con += ''; + con += ''; + con += ''; + con += ''; + + con += ''; + + for (var i = 0; i < list.length; i++) { + con += ''+ + '' + + '' + + ''; + } + + con += ''; + con += '
用户密码操作(添加)
' + list[i]['user']+'' + list[i]['pwd']+'改密|删除
'; + + $(".soft-man-con").html(con); + }); +} + + + +function readme(){ + var readme = '
    '; + readme += '
  • 使用时,查看对应的端口
  • '; + readme += '
'; + $('.soft-man-con').html(readme); +}