diff --git a/app/admin/base_view.py b/app/admin/base_view.py index 8a77b07..b86ffd2 100644 --- a/app/admin/base_view.py +++ b/app/admin/base_view.py @@ -23,36 +23,6 @@ from shelljob import proc ##全局_pid global _pid _pid=None -############功能函数 -def set(key,value,user=GetConfig('default_pan')): - InfoLogger().print_r('set {}:{}'.format(key,value)) - config_path=os.path.join(config_dir,'self_config.py') - if key in ['client_secret','client_id','share_path','other_name','od_type','app_url']: - # old_kv=re.findall('"{}":.*{{[\w\W]*}}'.format(user),old_text)[0] - # new_kv=re.sub('"{}":.*.*?,'.format(key),'"{}":"{}",'.format(key,value),old_kv,1) - # new_text=old_text.replace(old_kv,new_kv,1) - od_users[user][key]=value - config_path=os.path.join(config_dir,'self_config.py') - with open(config_path,'r') as f: - old_text=f.read() - with open(config_path,'w') as f: - old_od=re.findall('od_users={[\w\W]*}',old_text)[0] - new_od='od_users='+json.dumps(od_users,indent=4,ensure_ascii=False) - new_text=old_text.replace(old_od,new_od,1) - f.write(new_text) - return - with open(config_path,'r') as f: - old_text=f.read() - with open(config_path,'w') as f: - if key=='allow_site': - value=value.split(',') - new_text=re.sub('{}=.*'.format(key),'{}={}'.format(key,value),old_text) - elif key in ['tj_code','cssCode','headCode','footCode','robots']: - new_text=re.sub('{}="""[\w\W]*?"""'.format(key),'{}="""{}"""'.format(key,value),old_text) - else: - new_text=re.sub('{}=.*'.format(key),'{}="{}"'.format(key,value),old_text) - f.write(new_text) - ############视图函数 @admin.before_request diff --git a/app/admin/install.py b/app/admin/install.py index f02d0ce..730c1de 100644 --- a/app/admin/install.py +++ b/app/admin/install.py @@ -3,34 +3,69 @@ from base_view import * ###########################################安装 +def check_mongo(host,port,user,password,db): + try: + mongo = MongoClient(host=host,port=int(port),connect=False,serverSelectionTimeoutMS=3) + mon_db=eval('mongo.{}'.format(db)) + if GetConfig_pre('MONGO_PASSWORD')!='': + try: + mon_db.authenticate(user,password) + except: + return False + try: + mon_db.items.remove() + except: + return False + except: + return False + return True + +def check_redis(host,port,password,db): + try: + if password!='': + pool=redis.ConnectionPool(host=host,port=int(port),db=db,password=password,socket_connect_timeout=3) + redis_client=redis.Redis(connection_pool=pool) + else: + pool=redis.ConnectionPool(host=host,port=int(port),db=db,socket_connect_timeout=3) + redis_client=redis.Redis(connection_pool=pool) + try: + redis_client.exists('test') + return True + except: + return False + except: + return False + + + + @admin.route('/install',methods=['POST','GET']) def install(): + step=request.args.get('step',0,type=int) + user=request.args.get('user','A') if request.method=='POST': - step=request.form.get('step',type=int) - user=request.form.get('user') - od_type=request.form.get('od_type','nocn') - if step==0: - resp=MakeResponse(render_template('admin/install/install_0.html',step=step,cur_user=user,od_type=od_type,redirectUrl=redirect_uri)) - return resp - elif step==1: + if step==3: + od_type=request.form.get('od_type','nocn') + set('od_type',od_type,user) + elif step==4: + od_type=request.form.get('od_type','nocn') od_prefix=request.form.get('od_prefix') client_id=request.form.get('client_id') client_secret=request.form.get('client_secret') set('client_id',client_id,user) set('client_secret',client_secret,user) - set('od_type',od_type,user) if od_type=='cn': set('app_url','https://{}-my.sharepoint.cn/'.format(od_prefix),user) - login_url=GetLoginUrl(client_id=client_id,redirect_uri=redirect_uri,od_type=od_type) - return render_template('admin/install/install_1.html',client_secret=client_secret,client_id=client_id,login_url=login_url,cur_user=user,od_type=od_type) + login_url=GetLoginUrl(client_id=client_id,redirect_uri=GetConfig('redirect_uri'),od_type=od_type) else: client_secret=request.form.get('client_secret') client_id=request.form.get('client_id') code=request.form.get('code') + od_type=request.form.get('od_type','nocn') #授权 headers={'Content-Type':'application/x-www-form-urlencoded'} headers.update(default_headers) - data=AuthData.format(client_id=client_id,redirect_uri=urllib.quote(redirect_uri),client_secret=urllib.quote(client_secret),code=code) + data=AuthData.format(client_id=client_id,redirect_uri=urllib.quote(GetConfig('redirect_uri')),client_secret=urllib.quote(client_secret),code=code) if od_type=='cn': data+='&resource=00000003-0000-0ff1-ce00-000000000000' url=GetOAuthUrl(od_type) @@ -55,9 +90,51 @@ def install(): return make_response('

授权成功!
请先在后台-更新列表,全量更新数据
然后点击进入首页


'.format(GetConfig('admin_prefix'),time.time())) else: return jsonify(Atoken) - step=request.args.get('step',type=int) - user=request.args.get('user','A') - resp=MakeResponse(render_template('admin/install/install_00.html',step=step,cur_user=user)) + if step==0: + resp=MakeResponse(render_template('admin/install/install_mongo.html',step=step,cur_user=user)) + elif step==1: + resp=MakeResponse(render_template('admin/install/install_redis.html',step=step,cur_user=user)) + elif step==2: + resp=MakeResponse(render_template('admin/install/install_choose_type.html',step=step,cur_user=user)) + elif step==3: + resp=MakeResponse(render_template('admin/install/install_fetch_key.html',step=step,cur_user=user,od_type=od_type)) + elif step==4: + resp=render_template('admin/install/install_login.html',client_secret=client_secret,client_id=client_id,login_url=login_url,cur_user=user,od_type=od_type) + return resp + +@admin.route('/install/test_config',methods=['POST']) +def test_config(): + soft=request.form.get('soft') + host=request.form.get('host') + port=request.form.get('port') + user=request.form.get('user') + password=request.form.get('password') + db=request.form.get('db') + resp={} + if soft=='mongo': + if check_mongo(host,port,user,password,db): + resp['msg']='MongoDB信息检查正确!' + resp['code']=1 + set('MONGO_HOST',host) + set('MONGO_PORT',port) + set('MONGO_USER',user) + set('MONGO_PASSWORD',password) + set('MONGO_DB',db) + + else: + resp['msg']='MongoDB信息错误!' + resp['code']=0 + else: + if check_redis(host,port,password,db): + resp['msg']='Redis信息检查正确!' + resp['code']=1 + set('REDIS_HOST',host) + set('REDIS_PORT',port) + set('REDIS_PASSWORD',password) + set('REDIS_DB',db) + else: + resp['msg']='Redis信息错误!' + resp['code']=0 return resp ###########################################卸载 diff --git a/app/templates/admin/install/install_00.html b/app/templates/admin/install/install_choose_type.html similarity index 85% rename from app/templates/admin/install/install_00.html rename to app/templates/admin/install/install_choose_type.html index 6ff5047..3a65e84 100644 --- a/app/templates/admin/install/install_00.html +++ b/app/templates/admin/install/install_choose_type.html @@ -12,12 +12,12 @@ -
+ - +
diff --git a/app/templates/admin/install/install_0.html b/app/templates/admin/install/install_fetch_key.html similarity index 96% rename from app/templates/admin/install/install_0.html rename to app/templates/admin/install/install_fetch_key.html index 30b1a05..15239ab 100644 --- a/app/templates/admin/install/install_0.html +++ b/app/templates/admin/install/install_fetch_key.html @@ -13,7 +13,7 @@ -
+
https @@ -34,7 +34,7 @@ {%else%} -
+
@@ -110,7 +110,7 @@

2. 点击新注册

- 名称:随便填
 - 受支持的帐户类型:默认
-- 重定向 URI (可选):Web - https://auth.pyone.me/ (怕不安全?看https://www.abbeyok.com/archives/281。或者干脆不用)
+- 重定向 URI (可选):Web - {{GetConfig('redirect_uri')}} (怕不安全?看https://www.abbeyok.com/archives/281。或者干脆不用)

    点击创建,进入下一步

    *创建之后,看到应用程序(客户端) ID,复制到上方应用 ID(client_id)

3. 开启权限:第2步创建应用程序之后,进入该应用的概述页面。

diff --git a/app/templates/admin/install/install_1.html b/app/templates/admin/install/install_login.html similarity index 96% rename from app/templates/admin/install/install_1.html rename to app/templates/admin/install/install_login.html index 57c1f6c..d08dfaa 100644 --- a/app/templates/admin/install/install_1.html +++ b/app/templates/admin/install/install_login.html @@ -18,7 +18,7 @@
1. 绑定账号 - +
https diff --git a/app/templates/admin/install/install_mongo.html b/app/templates/admin/install/install_mongo.html new file mode 100644 index 0000000..0e66483 --- /dev/null +++ b/app/templates/admin/install/install_mongo.html @@ -0,0 +1,74 @@ +{%extends 'admin/layout.html'%} + +{%block content%} +
+
+

系统安装 MongoDB信息配置

+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+
+ +
+ +{%endblock content%} diff --git a/app/templates/admin/install/install_redis.html b/app/templates/admin/install/install_redis.html new file mode 100644 index 0000000..db11d5c --- /dev/null +++ b/app/templates/admin/install/install_redis.html @@ -0,0 +1,68 @@ +{%extends 'admin/layout.html'%} + +{%block content%} +
+
+

系统安装 Redis信息配置

+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ +
+ +
+
+
+ +
+ +{%endblock content%} diff --git a/app/templates/admin/manage/manage.html b/app/templates/admin/manage/manage.html index cdc089b..f7f53ab 100644 --- a/app/templates/admin/manage/manage.html +++ b/app/templates/admin/manage/manage.html @@ -29,7 +29,7 @@ a:hover {
{%for user in get_od_user(True)%} {%if user[1]=='添加网盘'%} - + diff --git a/app/templates/admin/pan_manage/pan_manage.html b/app/templates/admin/pan_manage/pan_manage.html index 776d2f4..77181f1 100644 --- a/app/templates/admin/pan_manage/pan_manage.html +++ b/app/templates/admin/pan_manage/pan_manage.html @@ -42,7 +42,7 @@
显示名称
绑定onedrive
-
点击绑定
+
点击绑定
diff --git a/app/templates/admin/upload.html b/app/templates/admin/upload.html index e6da59a..595b0f1 100644 --- a/app/templates/admin/upload.html +++ b/app/templates/admin/upload.html @@ -70,7 +70,7 @@ function ClearHist(){ layer.close(index); $.ajax({ type: "POST", - url: "/admin/upload/jsonrpc", + url: "{{url_for('admin.UploadRPCserver')}}", data:{action:'ClearHist'}, dataType: "json", beforeSend: function(xhr) { @@ -98,7 +98,7 @@ function Restart(){ layer.close(index); $.ajax({ type: "POST", - url: "/admin/upload/jsonrpc", + url: "{{url_for('admin.UploadRPCserver')}}", data:{action:'Restart'}, dataType: "json", beforeSend: function(xhr) { @@ -123,7 +123,7 @@ function GetPagination() { var getTimestamp = new Date().getTime(); $.ajax({ type: "POST", - url: "/admin/upload/jsonrpc?t=" + getTimestamp, + url: "{{url_for('admin.UploadRPCserver')}}?t=" + getTimestamp, data: { page: '{{page}}', action: 'pagination' }, cache: false, //使用同步的方式,true为异步方式 // async: false, //使用同步的方式,true为异步方式 @@ -171,7 +171,7 @@ function GetTasks() { var getTimestamp = new Date().getTime(); $.ajax({ type: "POST", - url: "/admin/upload/jsonrpc?t=" + getTimestamp, + url: "{{url_for('admin.UploadRPCserver')}}?t=" + getTimestamp, data: { page: '{{page}}' }, cache: false, //使用同步的方式,true为异步方式 // async: false, //使用同步的方式,true为异步方式 diff --git a/app/templates/error.html b/app/templates/error.html index 2a54655..f2b4192 100644 --- a/app/templates/error.html +++ b/app/templates/error.html @@ -60,8 +60,8 @@

检查:

    -
  • 1.Redis、MongoDB是否安装?是否运行?。
  • -
  • 自建状态
  • +
  • 1.Redis、MongoDB是否安装?是否运行?
  • +
  • 检测状态
  • {{msg|safe}}
  • 2.如果上诉没问题,可清空Redis缓存:
  • redis-cli
    diff --git a/app/utils/header.py b/app/utils/header.py
    index 57a264c..5549d2e 100644
    --- a/app/utils/header.py
    +++ b/app/utils/header.py
    @@ -64,19 +64,30 @@ browser=requests.Session()
     
     #获取参数
     def GetConfig(key):
    -    if key=='allow_site':
    -        value=redis_client.get('allow_site') if redis_client.exists('allow_site') else ','.join(allow_site)
    -    else:
    -        value=redis_client.get(key) if redis_client.exists(key) else eval(key)
    -    #这里是为了储存
    -    if key=='od_users'and isinstance(value,dict):
    -        config_path=os.path.join(config_dir,'self_config.py')
    -        with open(config_path,'r') as f:
    -            text=f.read()
    -        value=re.findall('od_users=([\w\W]*})',text)[0]
    -        # value=json.dumps(value)
    -    if not redis_client.exists(key):
    -        redis_client.set(key,value)
    +    try:
    +        if key=='allow_site':
    +            value=redis_client.get('allow_site') if redis_client.exists('allow_site') else ','.join(allow_site)
    +        else:
    +            value=redis_client.get(key) if redis_client.exists(key) else eval(key)
    +        #这里是为了储存
    +        if key=='od_users'and isinstance(value,dict):
    +            config_path=os.path.join(config_dir,'self_config.py')
    +            with open(config_path,'r') as f:
    +                text=f.read()
    +            value=re.findall('od_users=([\w\W]*})',text)[0]
    +            # value=json.dumps(value)
    +        if not redis_client.exists(key):
    +            redis_client.set(key,value)
    +    except:
    +        if key=='allow_site':
    +            value=','.join(allow_site)
    +        else:
    +            value=eval(key)
    +        if key=='od_users'and isinstance(value,dict):
    +            config_path=os.path.join(config_dir,'self_config.py')
    +            with open(config_path,'r') as f:
    +                text=f.read()
    +            value=re.findall('od_users=([\w\W]*})',text)[0]
         #这里是为了转为字典
         if key=='od_users':
             config_path=os.path.join(config_dir,'self_config.py')
    @@ -86,6 +97,39 @@ def GetConfig(key):
             value=json.loads(value)
         return value
     
    +
    +############功能函数
    +def set(key,value,user=GetConfig('default_pan')):
    +    InfoLogger().print_r('set {}:{}'.format(key,value))
    +    config_path=os.path.join(config_dir,'self_config.py')
    +    if key in ['client_secret','client_id','share_path','other_name','od_type','app_url']:
    +        # old_kv=re.findall('"{}":.*{{[\w\W]*}}'.format(user),old_text)[0]
    +        # new_kv=re.sub('"{}":.*.*?,'.format(key),'"{}":"{}",'.format(key,value),old_kv,1)
    +        # new_text=old_text.replace(old_kv,new_kv,1)
    +        od_users[user][key]=value
    +        config_path=os.path.join(config_dir,'self_config.py')
    +        with open(config_path,'r') as f:
    +            old_text=f.read()
    +        with open(config_path,'w') as f:
    +            old_od=re.findall('od_users={[\w\W]*}',old_text)[0]
    +            new_od='od_users='+json.dumps(od_users,indent=4,ensure_ascii=False)
    +            new_text=old_text.replace(old_od,new_od,1)
    +            f.write(new_text)
    +        return
    +    with open(config_path,'r') as f:
    +        old_text=f.read()
    +    with open(config_path,'w') as f:
    +        if key=='allow_site':
    +            value=value.split(',')
    +            new_text=re.sub('{}=.*'.format(key),'{}={}'.format(key,value),old_text)
    +        elif key in ['tj_code','cssCode','headCode','footCode','robots']:
    +            new_text=re.sub('{}="""[\w\W]*?"""'.format(key),'{}="""{}"""'.format(key,value),old_text)
    +        else:
    +            new_text=re.sub('{}=.*'.format(key),'{}="{}"'.format(key,value),old_text)
    +        f.write(new_text)
    +
    +
    +
     #转字符串
     def convert2unicode(string):
         return string.encode('utf-8')
    diff --git a/install.sh b/install.sh
    index 4bf8248..f55445b 100755
    --- a/install.sh
    +++ b/install.sh
    @@ -1,130 +1,295 @@
    -#!/etc/bash
    -function wget_exists(){
    -    echo "1. 安装wget";
    -    which wget > /dev/null 2>&1
    -    if [ $? == 0 ]; then
    -        echo "wget exist"
    -    else
    -        echo "wget dose not exist"
    -        yum install wget -y
    +#!/bin/bash
    +export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
    +
    +# ====================================================
    +# Description:PyOne 一键脚本 for Debian 8+ 、CentOS 7、Ubuntu 16+
    +# ====================================================
    +
    +#fonts color
    +Red="\033[31m"
    +Font="\033[0m"
    +Blue="\033[36m"
    +
    +
    +check_port() {
    +        netstat -tlpn | grep "\b$1\b"
    +}
    +#root permission
    +check_root(){
    +        if [[ $EUID -ne 0 ]]; then
    +        echo "${Red}Error:请使用root运行该脚本!"${Font} 1>&2
    +        exit 1
    +        fi
    +}
    +
    +#check system
    +check_system(){
    +        if [[ -f /etc/redhat-release ]]; then
    +        release="centos"
    +    elif cat /etc/issue | grep -Eqi "debian"; then
    +        release="debian"
    +    elif cat /etc/issue | grep -Eqi "ubuntu"; then
    +        release="ubuntu"
    +    elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
    +        release="centos"
    +    elif cat /proc/version | grep -Eqi "debian"; then
    +        release="debian"
    +    elif cat /proc/version | grep -Eqi "ubuntu"; then
    +        release="ubuntu"
    +    elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
    +        release="centos"
         fi
     }
     
    -function git_exists(){
    -    echo "2. 安装git";
    -    which git > /dev/null 2>&1
    -    if [ $? == 0 ]; then
    -        echo "git exist"
    +#check version
    +check_version(){
    +    if [[ -s /etc/redhat-release ]]; then
    +     version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
    +    else
    +     version=`grep -oE  "[0-9.]+" /etc/issue | cut -d . -f 1`
    +    fi
    +    bit=`uname -m`
    +    if [[ ${bit} = "x86_64" ]]; then
    +        bit="64"
         else
    -        echo "git dose not exist"
    -        yum install git -y
    +        bit="32"
         fi
    +    if [[ "${release}" = "centos" && ${version} -ge 7 ]];then
    +        echo -e "${Blue}当前系统为CentOS ${version}${Font} "
    +    elif [[ "${release}" = "debian" && ${version} -ge 8 ]];then
    +        echo -e "${Blue}当前系统为Debian ${version}${Font} "
    +    elif [[ "${release}" = "ubuntu" && ${version} -ge 16 ]];then
    +        echo -e "${Blue}当前系统为Ubuntu ${version}${Font} "
    +    else
    +        echo -e "${Red}脚本不支持当前系统,安装中断!${Font} "
    +        exit 1
    +    fi
    +    for EXE in grep cut xargs systemctl ip awk
    +    do
    +        if ! type -p ${EXE}; then
    +            echo -e "${Red}系统精简厉害,脚本自动退出${Font}"
    +            exit 1
    +        fi
    +    done
     }
    -#安装pip
    -function pip_exists(){
    -    echo "3. 安装pip";
    -    which pip > /dev/null 2>&1
    -    if [ $? == 0 ]; then
    -        echo "pip exist"
    +
    +
    +check_service(){
    +    read -p "请输入redis端口号[6379]:" redis_port
    +    if [ -z "${redis_port}" ];then
    +        redis_port=6379
    +    fi
    +
    +    read -p "请输入redis端口号[27017]:" mongo_port
    +
    +    if [ -z "${mongo_port}" ];then
    +        mongo_port=27017
    +    fi
    +
    +
    +    if check_port ${redis_port}; then
    +        echo ""
         else
    -        echo "pip dose not exist"
    -        wget https://bootstrap.pypa.io/get-pip.py
    -        python get-pip.py
    -        rm -rf get-pip.py
    +        echo -e "${Red}Error:请先在宝塔安装redis"${Font} 1>&2
    +        exit 1
    +    fi
    +
    +    if check_port ${mongo_port}; then
    +        echo ""
    +    else
    +        echo -e "${Red}Error:请先在宝塔安装MongoDB"${Font} 1>&2
    +        exit 1
         fi
     }
     
    -#安装python依赖包
    -function install_(){
    -    echo "4. 安装python依赖包";
    -    pip install -r requirements.txt -U
    +#enter info
    +enter(){
    +    stty erase '^H' && read -p "请设置Aria2密钥:" aria2_pass
    +    sed -i "s/ARIA2_SECRET=\"abbey\"/ARIA2_SECRET=\"${aria2_pass}\"/g" self_config.py
    +
    +    read -p "请设置PyOne的后台密码:" pyone_pass
    +    sed -i "s/password=\"PyOne\"/password=\"${pyone_pass}\"/g" self_config.py
     }
     
    -#配置文件
    -function config_file(){
    -    echo "5. 配置文件";
    +
    +config_file(){
         cur_dir=`pwd`
         cp self_config.py.sample self_config.py
    -    cp supervisord.conf.sample supervisord.conf
    -    mkdir /var/run/supervisor
    -    chmod +x /var/run/supervisor
         sed -i "s|/root/PyOne|$cur_dir|" self_config.py
    -    sed -i "s|/root/PyOne|$cur_dir|" supervisord.conf
     }
     
    -#添加开机任务
    -function auto_boot(){
    -    echo "6. 配置开机启动";
    -    cur_dir=`pwd`
    -    echo "supervisord -c $cur_dir/supervisord.conf" >> /etc/rc.d/rc.local
    -    echo "sh /data/aria2/aria2.sh start" >> /etc/rc.d/rc.local
    -    chmod +x /etc/rc.d/rc.local
    -    # sh /data/arai2/aria2.sh start
    -}
     
     
    -#安装aria2
    -function install_aria2(){
    -    echo "7. 安装aria2";
    -    which aria2c > /dev/null 2>&1
    -    if [ $? == 0 ]; then
    -        echo "检测到已安装aria2"
    -        echo "请到后台配置aria2信息"
    -        echo "如果您配置了aria2授权信息,请确保是rpc-secret模式!如果不是,则不能正常工作。"
    -        echo "开启rpc-secret模式方法:"
    -        echo "  >1. 编辑aria2的配置文件,将rpc-secret这一行反注释,然后'rpc-secret='后面填写密码"
    -        echo "  >2. 将rpc-user和rpc-passwd注释掉"
    -        echo "  >3. 重启aria2"
    +#install depend
    +install_depend(){
    +echo -e "${Blue}开始安装依赖${Font}"
    +    if [[ "${release}" = "centos" ]]; then
    +        yum -y install make git gcc crontabs lsof unzip python-devel libffi-devel openssl-devel -y
         else
    -        git clone https://github.com/abbeyokgo/aria2_installer.git
    -        cd aria2_installer
    -        sh install_aria2.sh
    -        echo "安装aria2完成"
    -        echo "如果已经成功安装,请到后台配置aria2信息"
    -        cd ..
    -        rm -rf aria2_installer
    +        apt update -y
    +        apt install -y make git cron build-essential python-dev lsof unzip python-setuptools python-wheel libffi-devel libssl-dev
         fi
     }
     
    -#开放端口
    -function open_port(){
    -    if [ -e "/etc/sysconfig/iptables" ]
    -        then
    -            iptables -I INPUT -p tcp --dport 34567 -j ACCEPT
    -            service iptables save
    -            service iptables restart
    +
    +#install aria2
    +install_aria2(){
    +    echo -e "${Blue}开始安装Aria2...${Font}"
    +    wget -N --no-check-certificate https://www.moerats.com/usr/shell/PyOne/aria2-1.34.0-linux-${bit}.tar.gz
    +    tar zxvf aria2-1.34.0-linux-${bit}.tar.gz
    +    rm -rf aria2-1.34.0-linux-${bit}.tar.gz
    +    cd aria2-1.34.0-linux-${bit}
    +    make install
    +     EXEC="$(command -v aria2c)"
    +        if [[ -n ${EXEC} ]]; then
    +            echo -e "${Blue}Aria2安装成功!${Font}"
             else
    -            firewall-cmd --zone=public --add-port=34567/tcp --permanent
    -            firewall-cmd --reload
    +            echo -e "${Red}Aria2安装失败!${Font}"
    +            exit 1
             fi
    +    cd ..
    +    rm -rf aria2-1.34.0-linux-${bit}
    +    mkdir "/root/.aria2" && mkdir /root/Download
    +    wget -N --no-check-certificate https://www.moerats.com/usr/shell/Aria2/dht.dat -P '/root/.aria2/'
    +    wget -N --no-check-certificate https://www.moerats.com/usr/shell/PyOne/aria2.conf -P '/root/.aria2/'
    +    wget -N --no-check-certificate https://www.moerats.com/usr/shell/PyOne/trackers-list-aria2.sh -P '/root/.aria2/'
    +    touch /root/.aria2/aria2.session
    +    chmod +x /root/.aria2/trackers-list-aria2.sh
    +    chmod 777 /root/.aria2/aria2.session
    +    sed -i "s/rpc-secret=/rpc-secret=${pass}/g" /root/.aria2/aria2.conf
    +    echo -e "${Blue}开始设置trackers-list自动更新!${Font}"
    +    if [[ "${release}" = "centos" ]]; then
    +        echo "0 0 */7 * * /root/.aria2/trackers-list-aria2.sh" >> /var/spool/cron/root
    +    else
    +        echo "0 0 */7 * * /root/.aria2/trackers-list-aria2.sh" >> /var/spool/cron/crontabs/root
    +    fi
    +}
    +
    +#install pyone
    +install_pip(){
    +    echo -e "${Blue}正在安装pip!${Font}"
    +    if [[ "${release}" = "centos" ]]; then
    +        yum install -y python-pip
    +        EXEC="$(command -v pip)"
    +        if [[ -z ${EXEC} ]]; then
    +        wget https://bootstrap.pypa.io/get-pip.py
    +        python get-pip.py
    +        fi
    +    else
    +        apt -y install python-pip
    +    fi
    +    EXEC="$(command -v pip)"
    +    if [[ -n ${EXEC} ]]; then
    +    echo -e "${Blue}pip安装成功!${Font}"
    +    else
    +    echo -e "${Red}pip安装失败!${Font}"
    +    exit 1
    +    fi
    +
    +}
    +
    +install_package(){
    +    pip2 install -r requirements.txt
    +}
    +
    +
    +
    +#open firewall
    +firewall(){
    +    if [[ "${release}" = "centos" ]]; then
    +        firewall-cmd --zone=public --add-port=6800/tcp --permanent
    +        firewall-cmd --zone=public --add-port=34567/tcp --permanent
    +        firewall-cmd --zone=public --add-port=80/tcp --permanent
    +        firewall-cmd --zone=public --add-port=443/tcp --permanent
    +        firewall-cmd --reload
    +    fi
     }
     
     
     
    +#set start up
    +start(){
    +        echo -e "${Blue}正在为相关应用设置开机自启!${Font}"
    +echo "[Unit]
    +Description=Aria2 server
    +After=network.target
    +Wants=network.target
    +
    +[Service]
    +Type=simple
    +PIDFile=/var/run/aria2c.pid
    +ExecStart=/usr/bin/aria2c --conf-path=/root/.aria2/aria2.conf
    +RestartPreventExitStatus=23
    +Restart=always
    +User=root
    +
    +[Install]
    +WantedBy=multi-user.target
    +" > '/etc/systemd/system/aria2.service'
     
    +echo "[Unit]
    +Description=pyone
    +After=network.target
    +Wants=network.target
     
    -#执行
    -install_
    -config_file
    -#auto_boot
    -#install_aria2
    -open_port
    -yum install gcc libffi-devel python-devel openssl-devel -y
    -yum install lsof -y
    -mkdir logs
    -echo "---------------------------------------------------------------"
    -echo "一键脚本运行完成!请检查以下文件:"
    -echo "  > 1. self_config.py、supervisord.conf是否存在!"
    -echo "  > 2. 检查self_config.py、supervisord.conf脚本里面的目录是否正确!"
    -echo "  > 3. 请确保已经安装Nginx、Redis、MongoDB,并已经运行!"
    -echo "  > 4. 检查/data/aria2是否存在。"
    -echo "  > 5. 检查aria2是否运行:pgrep 'aria2c'"
    -echo "    如果aria2没有运行,运行:sh /data/aria2/aria2.sh start"
    -echo
    -echo "如果检查没有问题!在网站目录可运行以下脚本运行网站"
    -echo "supervisord -c supervisord.conf"
    -echo "---------------------------------------------------------------"
    -echo
    -echo "PyOne交流群:864996565"
    -echo "PyOne交流群TG:https://t.me/joinchat/JQOOug6MY11gy_MiXTmqIA"
    +[Service]
    +Type=simple
    +PIDFile=/var/run/pyone.pid
    +WorkingDirectory=/root/PyOne
    +ExecStart=gunicorn -keventlet -b 0.0.0.0:34567 run:app
    +RestartPreventExitStatus=23
    +Restart=always
    +User=root
    +
    +[Install]
    +WantedBy=multi-user.target
    +" > '/etc/systemd/system/pyone.service'
    +
    +        EXEC="$(command -v gunicorn)"
    +        sed -i "s#gunicorn#${EXEC}#g" /etc/systemd/system/pyone.service
    +        systemctl start aria2 pyone
    +        systemctl enable aria2 pyone
    +}
    +
    +#Complete info
    +info(){
    +    local_ip=`curl http://whatismyip.akamai.com`
    +    echo -e "———————————————————————————————————————"
    +    echo -e "${Blue}PyOne安装完成!${Font}"
    +    echo -e "${Blue}请通过访问:http://${local_ip}:34567 继续后面的安装${Font}"
    +    echo -e "${Blue}PyOne后台密码:${pyone_pass}${Font}"
    +    echo -e "${Blue}Aria2密匙:${aria2_pass}${Font}"
    +    echo -e "${Blue}常用命令:${Font}"
    +    echo -e "${Blue}1. 暂停PyOne: systemctl stop pyone${Font}"
    +    echo -e "${Blue}2. 启动PyOne: systemctl start pyone${Font}"
    +    echo -e "${Blue}3. 重启PyOne: systemctl restart pyone${Font}"
    +    echo -e "${Blue}4. 手动运行PyOne: systemctl stop pyone && gunicorn -keventlet -b 0:34567 run:app${Font}"
    +    echo -e "———————————————————————————————————————"
    +    echo -e "${Blue}PyOne交流群:864996565${Font}"
    +    echo -e "${Blue}PyOne交流群TG:https://t.me/joinchat/JQOOug6MY11gy_MiXTmqIA${Font}"
    +}
    +
    +#start menu
    +main(){
    +    check_root
    +    check_system
    +    check_version
    +    check_service
    +    clear
    +    echo -e "———————————————————————————————————————"
    +    echo -e "${Blue}PyOne一键脚本 for Debian 8+ 、CentOS 7、Ubuntu 16+${Font}"
    +    echo -e "本脚本参考【萌鼠博客】:https://www.moerats.com/archives/806/"
    +    echo -e "${Blue}安装之前请确保已经在安装宝塔,并且在宝塔-软件管理已经安装MongoDB和redis${Font}"
    +    echo -e "———————————————————————————————————————"
    +    config_file
    +    enter
    +    install_depend
    +    install_aria2
    +    install_pip
    +    install_package
    +    firewall
    +    start
    +    info
    +}
     
    +main
    diff --git a/run.py b/run.py
    index 88482bc..45179aa 100755
    --- a/run.py
    +++ b/run.py
    @@ -2,6 +2,7 @@
     import eventlet
     eventlet.monkey_patch()
     import os
    +import traceback
     from flask_script import Manager, Shell
     from app import create_app
     from self_config import *
    @@ -30,25 +31,58 @@ if REDIS_PASSWORD!="":
     else:
         pool = ConnectionPool(host=REDIS_HOST, port=REDIS_PORT, db=REDIS_DB)
     tmp_rd=Redis(connection_pool=pool)
    -tmp_rd.set('title',title)
    -tmp_rd.set('tj_code',tj_code)
    -tmp_rd.set('downloadUrl_timeout',downloadUrl_timeout)
    -tmp_rd.set('allow_site',','.join(allow_site))
    -tmp_rd.set('ARIA2_HOST',ARIA2_HOST)
    -tmp_rd.set('ARIA2_PORT',ARIA2_PORT)
    -tmp_rd.set('ARIA2_SECRET',ARIA2_SECRET)
    -tmp_rd.set('ARIA2_SCHEME',ARIA2_SCHEME)
    -tmp_rd.set('password',password)
    -tmp_rd.set('verify_url',verify_url)
    -tmp_rd.set('balance',balance)
    -tmp_rd.set('admin_prefix',admin_prefix)
    -tmp_rd.set('thread_num',thread_num)
    -config_path=os.path.join(config_dir,'self_config.py')
    -with open(config_path,'r') as f:
    -    text=f.read()
    -tmp_rd.set('users',re.findall('od_users=([\w\W]*})',text)[0])
    -key='themelist'
    -tmp_rd.delete(key)
    +try:
    +    tmp_rd.set("allow_site",','.join(allow_site))
    +    tmp_rd.set("downloadUrl_timeout",downloadUrl_timeout)
    +    tmp_rd.set("password",password)
    +    tmp_rd.set("title",title)
    +    tmp_rd.set("tj_code",tj_code)
    +    tmp_rd.set("headCode",headCode)
    +    tmp_rd.set("footCode",footCode)
    +    tmp_rd.set("cssCode",cssCode)
    +    tmp_rd.set("robots",robots)
    +    tmp_rd.set("theme",theme)
    +    tmp_rd.set("title_pre",title_pre)
    +    tmp_rd.set("redirect_uri",redirect_uri)
    +    tmp_rd.set("BaseAuthUrl",BaseAuthUrl)
    +    tmp_rd.set("app_url",app_url)
    +    tmp_rd.set("ARIA2_HOST",ARIA2_HOST)
    +    tmp_rd.set("ARIA2_PORT",ARIA2_PORT)
    +    tmp_rd.set("ARIA2_SECRET",ARIA2_SECRET)
    +    tmp_rd.set("ARIA2_SCHEME",ARIA2_SCHEME)
    +    tmp_rd.set("MONGO_HOST",MONGO_HOST)
    +    tmp_rd.set("MONGO_PORT",MONGO_PORT)
    +    tmp_rd.set("MONGO_USER",MONGO_USER)
    +    tmp_rd.set("MONGO_PASSWORD",MONGO_PASSWORD)
    +    tmp_rd.set("MONGO_DB",MONGO_DB)
    +    tmp_rd.set("REDIS_HOST",REDIS_HOST)
    +    tmp_rd.set("REDIS_PORT",REDIS_PORT)
    +    tmp_rd.set("REDIS_PASSWORD",REDIS_PASSWORD)
    +    tmp_rd.set("REDIS_DB",REDIS_DB)
    +    tmp_rd.set("show_secret",show_secret)
    +    tmp_rd.set("default_sort",default_sort)
    +    tmp_rd.set("order_m",order_m)
    +    tmp_rd.set("encrypt_file",encrypt_file)
    +    tmp_rd.set("default_pan",default_pan)
    +    tmp_rd.set("admin_prefix",admin_prefix)
    +    tmp_rd.set("balance",balance)
    +    tmp_rd.set("thread_num",thread_num)
    +    tmp_rd.set("verify_url",verify_url)
    +    tmp_rd.set("show_doc",show_doc)
    +    tmp_rd.set("show_image",show_image)
    +    tmp_rd.set("show_video",show_video)
    +    tmp_rd.set("show_dash",show_dash)
    +    tmp_rd.set("show_audio",show_audio)
    +    tmp_rd.set("show_code",show_code)
    +    tmp_rd.set("show_redirect",show_redirect)
    +    config_path=os.path.join(config_dir,'self_config.py')
    +    with open(config_path,'r') as f:
    +        text=f.read()
    +    tmp_rd.set('users',re.findall('od_users=([\w\W]*})',text)[0])
    +    key='themelist'
    +    tmp_rd.delete(key)
    +except:
    +    print('\033[31m redis鉴权失败!请注意修改!\033[0m')
     ######################函数
     app.jinja_env.globals['version']=config.version
     app.jinja_env.globals['FetchData']=FetchData
    diff --git a/update.sh b/update.sh
    index b85c706..4c9d1d4 100755
    --- a/update.sh
    +++ b/update.sh
    @@ -1,5 +1,61 @@
     #!/etc/bash
     
    +
    +#check system
    +check_system(){
    +        if [[ -f /etc/redhat-release ]]; then
    +        release="centos"
    +    elif cat /etc/issue | grep -Eqi "debian"; then
    +        release="debian"
    +    elif cat /etc/issue | grep -Eqi "ubuntu"; then
    +        release="ubuntu"
    +    elif cat /etc/issue | grep -Eqi "centos|red hat|redhat"; then
    +        release="centos"
    +    elif cat /proc/version | grep -Eqi "debian"; then
    +        release="debian"
    +    elif cat /proc/version | grep -Eqi "ubuntu"; then
    +        release="ubuntu"
    +    elif cat /proc/version | grep -Eqi "centos|red hat|redhat"; then
    +        release="centos"
    +    fi
    +}
    +
    +#check version
    +check_version(){
    +    if [[ -s /etc/redhat-release ]]; then
    +     version=`cat /etc/redhat-release|sed -r 's/.* ([0-9]+)\..*/\1/'`
    +    else
    +     version=`grep -oE  "[0-9.]+" /etc/issue | cut -d . -f 1`
    +    fi
    +    bit=`uname -m`
    +    if [[ ${bit} = "x86_64" ]]; then
    +        bit="64"
    +    else
    +        bit="32"
    +    fi
    +    if [[ "${release}" = "centos" && ${version} -ge 7 ]];then
    +        echo -e "${Blue}当前系统为CentOS ${version}${Font} "
    +    elif [[ "${release}" = "debian" && ${version} -ge 8 ]];then
    +        echo -e "${Blue}当前系统为Debian ${version}${Font} "
    +    elif [[ "${release}" = "ubuntu" && ${version} -ge 16 ]];then
    +        echo -e "${Blue}当前系统为Ubuntu ${version}${Font} "
    +    else
    +        echo -e "${Red}脚本不支持当前系统,安装中断!${Font} "
    +        exit 1
    +    fi
    +    for EXE in grep cut xargs systemctl ip awk
    +    do
    +        if ! type -p ${EXE}; then
    +            echo -e "${Red}系统精简厉害,脚本自动退出${Font}"
    +            exit 1
    +        fi
    +    done
    +}
    +
    +check_system
    +check_version
    +
    +
     #11.20
     del_rubbish(){
         python -c "from function import *;mon_db.down_db.delete_many({});"
    @@ -97,9 +153,6 @@ Disallow:  /
     }
     
     
    -
    -
    -
     #2019.02.15
     upgrade_to4(){
         echo '-------------------------------'
    @@ -115,15 +168,13 @@ upgrade(){
             touch .install
         fi
         update_config
    -    yum install gcc libffi-devel python-devel openssl-devel -y
    -    pip install -r requirements.txt
    -    which lsof > /dev/null 2>&1
    -    if [ $? == 0 ]; then
    -        echo "lsof exist"
    +    if [[ "${release}" = "centos" ]]; then
    +        yum install gcc libffi-devel python-devel openssl-devel lsof -y
         else
    -        echo "lsof dose not exist"
    -        yum install lsof -y
    +        apt update -y
    +        apt install -y make git cron build-essential python-dev lsof unzip python-setuptools python-wheel libffi-devel libssl-dev
         fi
    +    pip install -r requirements.txt
     }
     
     change_redirect(){
    @@ -132,7 +183,12 @@ change_redirect(){
     
     
     restart(){
    -    supervisorctl -c supervisord.conf restart pyone
    +    num=`ls /etc/systemd/system | grep pyone.service | wc -l`
    +    if [ $num == 0 ]; then
    +        supervisorctl -c supervisord.conf restart pyone
    +    else
    +        systemctl restart pyone
    +    fi
     }
     
     #执行
    @@ -187,6 +243,7 @@ echo "2019.05.29更新版本:支持自定义线程数"
     echo "2019.05.31更新版本:新增功能:1)下载链接验证开关;优化:1)aria2信息不对时,无法添加任务"
     echo "2019.06.13更新版本:新增功能:文件展示设置"
     echo "2019.06.14更新版本:稍微完善一下日志记录;分享页面取消token验证;修复开启下载验证之后,后台文件打开失败的bug;新增内嵌窗口"
    +echo "2019.07.24更新版本:1. 优化安装脚本,适应Centos7、Debian9+、Ubuntu16+等系统;2、优化安装流程"
     echo "---------------------------------------------------------------"
     echo "更新完成!"
     echo "如果网站无法访问,请检查config.py!"