diff --git a/plugins/zimg/conf/zimg.conf b/plugins/zimg/conf/zimg.conf new file mode 100755 index 000000000..0deb949aa --- /dev/null +++ b/plugins/zimg/conf/zimg.conf @@ -0,0 +1,102 @@ +## 文件保存相关 ## + +# 文件的保存路径(可使用绝对路径或相对路径), 默认: 当前启动位置 +dir=/tmp/aria2 +# 设置日志等级 +log-level=error +# 日志保存路径 +log={$SERVER_PATH}/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={$SERVER_PATH}/aria2.session +# 在Aria2退出时保存`错误/未完成`的下载任务到会话文件 +save-session={$SERVER_PATH}/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/zimg/ico.png b/plugins/zimg/ico.png new file mode 100644 index 000000000..c9b49fbb8 Binary files /dev/null and b/plugins/zimg/ico.png differ diff --git a/plugins/zimg/index.html b/plugins/zimg/index.html new file mode 100755 index 000000000..e909dcec7 --- /dev/null +++ b/plugins/zimg/index.html @@ -0,0 +1,19 @@ +
+
+
+

服务

+

自启动

+

配置修改

+

运行日志

+

说明

+
+
+
+
+
+
+ \ No newline at end of file diff --git a/plugins/zimg/index.py b/plugins/zimg/index.py new file mode 100755 index 000000000..fe1c73aac --- /dev/null +++ b/plugins/zimg/index.py @@ -0,0 +1,207 @@ +# 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 'zimg' + + +def getPluginDir(): + return mw.getPluginDir() + '/' + getPluginName() + + +def getServerDir(): + return mw.getServerDir() + '/' + getPluginName() + + +def getInitDTpl(): + path = getPluginDir() + "/init.d/zimg.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) + + aria2_path = getServerDir() + '/zimg' + mw.execShell('mkdir -p /tmp/download') + if not os.path.exists(aria2_path): + path = getPluginDir() + "/conf/zimg.conf" + content = mw.readFile(path) + content = content.replace('{$SERVER_PATH}', aria2_path) + + mw.writeFile(aria2_path + '/zimg.conf', content) + + 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 zimg |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') + # print data + 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 getServerDir() + '/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(): + source_bin = initDreplace() + initd_bin = getInitDFile() + shutil.copyfile(source_bin, initd_bin) + mw.execShell('chmod +x ' + initd_bin) + + if not app_debug: + mw.execShell('chkconfig --add ' + getPluginName()) + return 'ok' + + +def initdUinstall(): + if not app_debug: + mw.execShell('chkconfig --del ' + getPluginName()) + + initd_bin = getInitDFile() + + if os.path.exists(initd_bin): + os.remove(initd_bin) + return 'ok' + + +def getLog(): + if mw.isAppleSystem(): + user = mw.execShell( + "who | sed -n '2, 1p' |awk '{print $1}'")[0].strip() + return '/Users/' + user + '/.zimg/zimg.log' + return getServerDir() + '/zimg/zimg.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/zimg/info.json b/plugins/zimg/info.json new file mode 100755 index 000000000..d276896a9 --- /dev/null +++ b/plugins/zimg/info.json @@ -0,0 +1,15 @@ +{ + "title":"zimg", + "tip":"soft", + "name":"zimg", + "type":"其他插件", + "ps":"轻量级图片服务器软件", + "versions":"1.0", + "shell":"install.sh", + "checks":"server/zimg", + "path": "server/zimg", + "author":"midoks", + "home":"https://github.com/buaazp/zimg", + "date":"2021-04-13", + "pid": "5" +} \ No newline at end of file diff --git a/plugins/zimg/init.d/zimg.tpl b/plugins/zimg/init.d/zimg.tpl new file mode 100755 index 000000000..cf51102b4 --- /dev/null +++ b/plugins/zimg/init.d/zimg.tpl @@ -0,0 +1,49 @@ +#!/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 + aria2c --daemon --enable-rpc --rpc-listen-all -c -D --conf-path={$SERVER_PATH}/aria2/aria2/aria2.conf + echo "zimg started" +} +app_stop(){ + echo "Stopping ..." + arr=`ps -ef | grep "zimg" | 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 "zimg 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/zimg/install.sh b/plugins/zimg/install.sh new file mode 100755 index 000000000..82bee73ec --- /dev/null +++ b/plugins/zimg/install.sh @@ -0,0 +1,63 @@ +#!/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_libjpeg_turbo(){ + mkdir -p $serverPath/zimg/libjpeg-turbo + cd $serverPath/zimg/libjpeg-turbo + wget https://downloads.sourceforge.net/project/libjpeg-turbo/1.3.1/libjpeg-turbo-1.3.1.tar.gz + tar zxvf libjpeg-turbo-1.3.1.tar.gz + cd libjpeg-turbo-1.3.1 + ./configure --prefix=/usr/local --with-jpeg8 + make && make install +} + +Install_zimg_source(){ + mkdir -p $serverPath/zimg + cd $serverPath/zimg + git clone https://github.com/buaazp/zimg -b master --depth=1 + make +} + + +Install_zimg() +{ + isStart="" + echo '正在安装脚本文件...' > $install_tmp + mkdir -p $serverPath/zimg + echo '1.0' > $serverPath/zimg/version.pl + + if [ "Darwin" == "$SYSOS" ];then + echo 'macosx unavailable' > $install_tmp + else + if [ ! -f $serverPath/zimg/zimg ] + Install_libjpeg_turbo + Install_zimg_source + fi + fi + + echo 'Install complete' > $install_tmp +} + +Uninstall_zimg() +{ + rm -rf $serverPath/zimg + echo "Uninstall completed" > $install_tmp +} + +action=$1 +if [ "${1}" == 'install' ];then + Install_zimg +else + Uninstall_zimg +fi diff --git a/plugins/zimg/js/zimg.js b/plugins/zimg/js/zimg.js new file mode 100755 index 000000000..1f56ea10e --- /dev/null +++ b/plugins/zimg/js/zimg.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 = ''; + $('.soft-man-con').html(readme); +}