コード例 #1
0
 def GetQiniuFileList(self,get):
     try:
         import json             
         result = public.ExecShell(public.get_python_bin() + " " + public.GetConfigValue('setup_path') + "/panel/script/backup_"+get.name+".py list")
         return json.loads(result[0])
     except:
         return public.returnMsg(False, 'GET_QINIU_FILE_LIST')
コード例 #2
0
def set_crond():
    try:
        echo = public.md5(public.md5('renew_lets_ssl_bt'))
        cron_id = public.M('crontab').where('echo=?', (echo, )).getField('id')

        import crontab
        args_obj = public.dict_obj()
        if not cron_id:
            cronPath = public.GetConfigValue('setup_path') + '/cron/' + echo
            shell = public.get_python_bin(
            ) + ' /www/server/panel/class/panelLets.py renew_lets_ssl'
            public.writeFile(cronPath, shell)
            args_obj.id = public.M('crontab').add(
                'name,type,where1,where_hour,where_minute,echo,addtime,status,save,backupTo,sType,sName,sBody,urladdress',
                ("续签Let's Encrypt证书", 'day', '', '0', '10', echo,
                 time.strftime('%Y-%m-%d %X', time.localtime()), 0, '',
                 'localhost', 'toShell', '', shell, ''))
            crontab.crontab().set_cron_status(args_obj)
        else:
            cron_path = public.get_cron_path()
            if os.path.exists(cron_path):
                cron_s = public.readFile(cron_path)
                if cron_s.find(echo) == -1:
                    public.M('crontab').where('echo=?',
                                              (echo, )).setField('status', 0)
                    args_obj.id = cron_id
                    crontab.crontab().set_cron_status(args_obj)
    except:
        print(public.get_error_info())
コード例 #3
0
ファイル: sewer_Usage.py プロジェクト: tgd1973/aaPanel
 def delete_dns_record(self, domain_name, domain_dns_value):
     root, _, acme_txt = extract_zone(domain_name)
     print("delete_dns_record start: ", acme_txt, domain_dns_value)
     public.ExecShell(
         '''{} /www/server/panel/plugin/model/dns_main.py remove_txt {} {}'''
         .format(public.get_python_bin(), acme_txt + '.' + root,
                 domain_dns_value))
     print("delete_dns_record_success")
コード例 #4
0
ファイル: crontab.py プロジェクト: xdev-asia/aaPanel
    def GetShell(self,param):
        #try:
        type=param['sType']
        if type=='toFile':
            shell=param.sFile
        else :
            head="#!/bin/bash\nPATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin\nexport PATH\n"
            log='-access_log'
            python_bin = public.get_python_bin()
            if public.get_webserver()=='nginx':
                log='.log'
            if type in ['site','path'] and param['sBody'] != 'undefined' and len(param['sBody']) > 1:
                exports = param['sBody'].replace("\r\n","\n").replace("\n",",")
                head += "BT_EXCLUDE=\"" + exports.strip() + "\"\nexport BT_EXCLUDE\n"
            wheres={
                    'path': head + python_bin +" " + public.GetConfigValue('setup_path')+"/panel/script/backup.py path "+param['sName']+" "+str(param['save']),
                    'site'  :   head +python_bin+ " " + public.GetConfigValue('setup_path')+"/panel/script/backup.py site "+param['sName']+" "+str(param['save']),
                    'database': head +python_bin+ " " + public.GetConfigValue('setup_path')+"/panel/script/backup.py database "+param['sName']+" "+str(param['save']),
                    'logs'  :   head +python_bin+ " " + public.GetConfigValue('setup_path')+"/panel/script/logsBackup "+param['sName']+log+" "+str(param['save']),
                    'rememory' : head + "/bin/bash " + public.GetConfigValue('setup_path') + '/panel/script/rememory.sh',
                    'webshell': head +python_bin+ " " + public.GetConfigValue('setup_path') + '/panel/class/webshell_check.py site ' + param['sName'] +' ' +param['urladdress']
                    }
            if param['backupTo'] != 'localhost':
                cfile = public.GetConfigValue('setup_path') + "/panel/plugin/" + param['backupTo'] + "/" + param['backupTo'] + "_main.py"
                if not os.path.exists(cfile): cfile = public.GetConfigValue('setup_path') + "/panel/script/backup_" + param['backupTo'] + ".py"
                wheres={
                    'path': head + python_bin+" " + cfile + " path " + param['sName'] + " " + str(param['save']),
                    'site'  :   head + python_bin+" " + cfile + " site " + param['sName'] + " " + str(param['save']),
                    'database': head + python_bin+" " + cfile + " database " + param['sName'] + " " + str(param['save']),
                    'logs'  :   head + python_bin+" " + public.GetConfigValue('setup_path')+"/panel/script/logsBackup "+param['sName']+log+" "+str(param['save']),
                    'rememory' : head + "/bin/bash " + public.GetConfigValue('setup_path') + '/panel/script/rememory.sh',
                     'webshell': head + python_bin+" " + public.GetConfigValue('setup_path') + '/panel/class/webshell_check.py site ' + param['sName'] +' ' +param['urladdress']
                    }
                
            try:
                shell=wheres[type]
            except:
                if type == 'toUrl':
                    shell = head + "curl -sS --connect-timeout 10 -m 3600 '" + param['urladdress']+"'"
                else:
                    shell=head+param['sBody'].replace("\r\n","\n")
                    
                shell += '''
echo "----------------------------------------------------------------------------"
endDate=`date +"%Y-%m-%d %H:%M:%S"`
echo "★[$endDate] Successful"
echo "----------------------------------------------------------------------------"
'''
        cronPath=public.GetConfigValue('setup_path')+'/cron'
        if not os.path.exists(cronPath): public.ExecShell('mkdir -p ' + cronPath)
        if not 'echo' in param:
            cronName=public.md5(public.md5(str(time.time()) + '_bt'))
        else:
            cronName = param['echo']
        file = cronPath+'/' + cronName
        public.writeFile(file,self.CheckScript(shell))
        public.ExecShell('chmod 750 ' + file)
        return cronName
コード例 #5
0
ファイル: database.py プロジェクト: xdev-asia/aaPanel
    def SetupPassword(self, get):
        password = get['password'].strip()
        try:
            if not password:
                return public.returnMsg(False, 'Root password cannot be empty')
            rep = "^[\w@\.\?\-\_\>\<\~\!\#\$\%\^\&\*\(\)]+$"
            if not re.match(rep, password):
                return public.returnMsg(False, 'DATABASE_NAME_ERR_T')
            mysql_root = public.M('config').where("id=?",
                                                  (1, )).getField('mysql_root')
            #修改MYSQL
            mysql_obj = panelMysql.panelMysql()
            result = mysql_obj.query("show databases")
            isError = self.IsSqlError(result)
            is_modify = True
            if isError != None:
                #尝试使用新密码
                public.M('config').where("id=?", (1, )).setField(
                    'mysql_root', password)
                result = mysql_obj.query("show databases")
                isError = self.IsSqlError(result)
                if isError != None:
                    public.ExecShell("cd /www/server/panel && " +
                                     public.get_python_bin() +
                                     " tools.py root \"" + password + "\"")
                    is_modify = False
            if is_modify:
                m_version = public.readFile(
                    public.GetConfigValue('setup_path') + '/mysql/version.pl')

                if m_version.find('5.7') == 0 or m_version.find(
                        '8.0') == 0 or m_version.find('10.4.') != -1:
                    panelMysql.panelMysql().execute(
                        "UPDATE mysql.user SET authentication_string='' WHERE user='******'"
                    )
                    panelMysql.panelMysql().execute(
                        "ALTER USER 'root'@'localhost' IDENTIFIED BY '%s'" %
                        password)
                    panelMysql.panelMysql().execute(
                        "ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '%s'" %
                        password)
                else:
                    result = mysql_obj.execute(
                        "update mysql.user set Password=password('" +
                        password + "') where User='******'")
                mysql_obj.execute("flush privileges")

            msg = public.getMsg('DATABASE_ROOT_SUCCESS')
            #修改SQLITE
            public.M('config').where("id=?",
                                     (1, )).setField('mysql_root', password)
            public.WriteLog("TYPE_DATABASE", "DATABASE_ROOT_SUCCESS")
            session['config']['mysql_root'] = password
            return public.returnMsg(True, msg)
        except Exception as ex:
            return public.returnMsg(False, 'EDIT_ERROR' + str(ex))
コード例 #6
0
ファイル: sewer_Usage.py プロジェクト: tgd1973/aaPanel
 def create_dns_record(self, domain_name, domain_dns_value):
     root, _, acme_txt = extract_zone(domain_name)
     print("create_dns_record,", acme_txt, domain_dns_value)
     result = public.ExecShell(
         '''{} /www/server/panel/plugin/model/dns_main.py add_txt {} {}'''.
         format(public.get_python_bin(), acme_txt + '.' + root,
                domain_dns_value))
     if result[0].strip() == "False":
         sys.exit(json.dumps({"data": public.GetMsg("BT_DNSRES_ERR")}))
     print("create_dns_record_end")
コード例 #7
0
ファイル: sewer_Usage.py プロジェクト: WytheLi/panel
 def create_dns_record(self, domain_name, domain_dns_value):
     root, _, acme_txt = extract_zone(domain_name)
     print("create_dns_record,", acme_txt, domain_dns_value)
     result = public.ExecShell(
         '''{} /www/server/panel/plugin/dns/dns_main.py add_txt {} {}'''.
         format(public.get_python_bin(), acme_txt + '.' + root,
                domain_dns_value))
     if result[0].strip() == "False":
         sys.exit(json.dumps({"data": "当前绑定的宝塔DNS云解析账户里面不存在这个域名,添加解析失败!"}))
     print("create_dns_record_end")
コード例 #8
0
 def SetQiniuAS(self,get):
     info = self.GetLibInfo(get.name)
     filename = public.GetConfigValue('setup_path') + '/panel/data/'+get.name+'As.conf'
     conf = get.access_key.strip() + '|' + get.secret_key.strip() + '|' + get.bucket_name.strip() + '|' + get.bucket_domain.strip()
     public.writeFile(filename,conf)
     public.ExecShell("chmod 600 " + filename)
     result = public.ExecShell(public.get_python_bin() + " " + public.GetConfigValue('setup_path') + "/panel/script/backup_"+get.name+".py list")
     
     if result[0].find("ERROR:") == -1: 
         public.WriteLog("PLUG_MAM","SET_PLUG[" +info['name']+ "]AS!")
         return public.returnMsg(True, 'SET_SUCCESS')
     return public.returnMsg(False,'AK_SK_CONNECT_ERROR'+info['name']+',Please check if the [AK/SK/Storage] setting is correct.')
コード例 #9
0
ファイル: jobs.py プロジェクト: tgd1973/aaPanel
def run_script():
    os.system("{} {}/script/run_script.py".format(public.get_python_bin(),public.get_panel_path()))
    run_tip = '/dev/shm/bt.pl'
    if os.path.exists(run_tip): return
    public.writeFile(run_tip,str(time.time()))
    uptime = int(public.readFile('/proc/uptime').split()[0])
    if uptime > 1800: return
    run_config ='/www/server/panel/data/run_config'
    script_logs = '/www/server/panel/logs/script_logs'
    if not os.path.exists(run_config):
        os.makedirs(run_config,384)
    if not os.path.exists(script_logs):
        os.makedirs(script_logs,384)

    for sname in os.listdir(run_config):
        script_conf_file = '{}/{}'.format(run_config,sname)
        if not os.path.exists(script_conf_file): continue
        script_info = json.loads(public.readFile(script_conf_file))
        exec_log_file = '{}/{}'.format(script_logs,sname)

        if not os.path.exists(script_info['script_file']) \
            or script_info['script_file'].find('/www/server/panel/plugin/') != 0 \
                or not re.match('^\w+$',script_info['script_file']):
            os.remove(script_conf_file)
            if os.path.exists(exec_log_file): os.remove(exec_log_file)
            continue


        if script_info['script_type'] == 'python':
            _bin = public.get_python_bin()
        elif script_info['script_type'] == 'bash':
            _bin = '/usr/bin/bash'
            if not os.path.exists(_bin): _bin = 'bash'

        exec_script = 'nohup {} {} &> {} &'.format(_bin,script_info['script_file'],exec_log_file)
        public.ExecShell(exec_script)
        script_info['last_time'] = time.time()
        public.writeFile(script_conf_file,json.dumps(script_info))
コード例 #10
0
ファイル: database.py プロジェクト: wonderking/aaPanel
 def DelBackup(self,get):
     try:
         id = get.id
         where = "id=?"
         filename = public.M('backup').where(where,(id,)).getField('filename')
         if os.path.exists(filename): os.remove(filename)
         name=''
         if filename == 'qiniu':
             name = public.M('backup').where(where,(id,)).getField('name')
             public.ExecShell(public.get_python_bin() + " "+public.GetConfigValue('setup_path') + '/panel/script/backup_qiniu.py delete_file ' + name)
         
         public.M('backup').where(where,(id,)).delete()
         public.WriteLog("TYPE_DATABASE", 'DATABASE_BACKUP_DEL_SUCCESS',(name,filename))
         return public.returnMsg(True, 'DEL_SUCCESS')
     except Exception as ex:
         public.WriteLog("TYPE_DATABASE", 'DATABASE_BACKUP_DEL_ERR',(name,filename,str(ex)))
         return public.returnMsg(False,'DEL_ERROR')
コード例 #11
0
ファイル: backup_bak.py プロジェクト: wonderking/aaPanel
# | 宝塔Linux面板
# +-------------------------------------------------------------------
# | Copyright (c) 2015-2099 宝塔软件(http://bt.cn) All rights reserved.
# +-------------------------------------------------------------------
# | Author: [email protected]
# |   主控   备份
# +---------------------------------------
import sys, os
if sys.version_info[0] == 2:
    reload(sys)
    sys.setdefaultencoding('utf-8')
os.chdir('/www/server/panel')
if not 'class/' in sys.path:
    sys.path.insert(0,'class/')
import time,hashlib,sys,os,json,requests,re,public,random,string,panelMysql,downloadFile
python_bin=public.get_python_bin()
class backup_bak:
    _chek_site_file='/tmp/chekc_site.json'
    _check_database = '/www/server/panel/data/check_database.json'
    _check_site = '/www/server/panel/data/check_site_data.json'
    _chekc_path='/www/server/panel/data/check_path_data.json'
    _down_path='/www/server/panel/data/download_path_data.json'
    _check_database_data=[]
    _check_site_data=[]
    _check_path_data=[]
    _down_path_data=[]
    #备份所有站点的进度
    _check_all_site = '/www/server/panel/data/check_site_data_all.json'
    _check_site_all_data=[]
    #备份所有数据库的进度
    _check_all_date = '/www/server/panel/data/check_date_data_all.json'
コード例 #12
0
                ret = self.renew_lest_cert(data)
                if ret['status']:
                    sucess_list.append(siteName)
                else:
                    err_list.append({"siteName": siteName, "msg": ret['msg']})
            print("|-任务执行完毕,共需续订[%s],续订成功[%s],续订失败[%s]. " %
                  (len(cron_list), len(sucess_list), len(err_list)))
            if len(sucess_list) > 0:
                print("|-续订成功:%s" % (','.join(sucess_list)))
            if len(err_list) > 0:
                print("|-续订失败:")
                for x in err_list:
                    print("    %s ->> %s" % (x['siteName'], x['msg']))

            print(
                '======================================================================='
            )
            print(" ")


if __name__ == "__main__":
    if len(sys.argv) > 1:
        type = sys.argv[1]
        if type == 'renew_lets_ssl':
            try:
                panelLets().renew_lets_ssl()
            except:
                pass
            os.system(public.get_python_bin() +
                      " /www/server/panel/class/acme_v2.py --renew=1")