コード例 #1
0
 def error_num(self, s=True):
     nKey = 'panelNum'
     num = cache.get(nKey)
     if not num:
         cache.set(nKey, 1)
         num = 1
     if s: cache.inc(nKey, 1)
     if num > 6: session['code'] = True
コード例 #2
0
    def check_login(self):
        try:
            api_check = True
            g.api_request = False
            if not 'login' in session:
                api_check = self.get_sk()
                if api_check:
                    session.clear()
                    return api_check
                g.api_request = True
            else:
                if session['login'] == False:
                    session.clear()
                    return redirect('/login')

                if 'tmp_login_expire' in session:
                    s_file = 'data/session/{}'.format(session['tmp_login_id'])
                    if session['tmp_login_expire'] < time.time():
                        session.clear()
                        if os.path.exists(s_file): os.remove(s_file)
                        return redirect('/login')
                    if not os.path.exists(s_file):
                        session.clear()
                        return redirect('/login')

            if api_check:
                try:
                    sess_out_path = 'data/session_timeout.pl'
                    sess_input_path = 'data/session_last.pl'
                    if not os.path.exists(sess_out_path): public.writeFile(sess_out_path,'86400')
                    if not os.path.exists(sess_input_path): public.writeFile(sess_input_path,str(int(time.time())))
                    session_timeout = int(public.readFile(sess_out_path))
                    session_last = int(public.readFile(sess_input_path))
                    if time.time() - session_last > session_timeout:
                        os.remove(sess_input_path)
                        session['login'] = False
                        cache.set('dologin', True)
                        session.clear()
                        return redirect('/login')
                    public.writeFile(sess_input_path, str(int(time.time())))
                except:
                    pass

            filename = '/www/server/panel/data/login_token.pl'
            if os.path.exists(filename):
                token = public.readFile(filename).strip()
                if 'login_token' in session:
                    if session['login_token'] != token:
                        session.clear()
                        return redirect('/login?dologin=True&go=1')
            if api_check:
                filename = 'data/sess_files/' + public.get_sess_key()
                if not os.path.exists(filename):
                    session.clear()
                    return redirect('/login?dologin=True&go=2')
        except:
            session.clear()
            return redirect('/login')
コード例 #3
0
ファイル: wxapp.py プロジェクト: alsyundawy/aaPanel
 def login_qrcode(self, get):
     tid = public.GetRandomString(12)
     qrcode_str = 'https://app.bt.cn/app.html?&panel_url=' + public.getPanelAddr(
     ) + '&v=' + public.GetRandomString(3) + '?login&tid=' + tid
     data = public.get_session_id() + ':' + str(time.time())
     public.writeFile(self.app_path + "app_login_check.pl", data)
     cache.set(tid, public.get_session_id(), 360)
     cache.set(public.get_session_id(), tid, 360)
     return public.returnMsg(True, qrcode_str)
コード例 #4
0
 def login_for_app(self, get):
     from BTPanel import cache
     tid = get.tid
     if (len(tid) != 12): return public.returnMsg(False, '无效的登录密钥')
     session_id = cache.get(tid)
     if not session_id: return public.returnMsg(False, '指定密钥不存在,或已过期')
     if (len(session_id) != 64): return public.returnMsg(False, '无效的登录密钥')
     cache.set(session_id, 'True', 120)
     return public.returnMsg(True, '扫码成功,正在登录!')
コード例 #5
0
ファイル: system.py プロジェクト: weweyes/aaPanel
    def get_disk_iostat(self):
        iokey = 'iostat'
        diskio = cache.get(iokey)
        mtime = int(time.time())
        if not diskio:
            diskio = {}
            diskio['info'] = None
            diskio['time'] = mtime
        diskio_1 = diskio['info']
        stime = mtime - diskio['time']
        if not stime: stime = 1
        diskInfo = {}
        diskInfo['ALL'] = {}
        diskInfo['ALL']['read_count'] = 0
        diskInfo['ALL']['write_count'] = 0
        diskInfo['ALL']['read_bytes'] = 0
        diskInfo['ALL']['write_bytes'] = 0
        diskInfo['ALL']['read_time'] = 0
        diskInfo['ALL']['write_time'] = 0
        diskInfo['ALL']['read_merged_count'] = 0
        diskInfo['ALL']['write_merged_count'] = 0
        try:
            if os.path.exists('/proc/diskstats'):
                diskio_2 = psutil.disk_io_counters(perdisk=True)
                if not diskio_1:
                    diskio_1 = diskio_2
                for disk_name in diskio_2.keys():
                    diskInfo[disk_name] = {}
                    diskInfo[disk_name]['read_count']   = int((diskio_2[disk_name].read_count - diskio_1[disk_name].read_count) / stime)
                    diskInfo[disk_name]['write_count']  = int((diskio_2[disk_name].write_count - diskio_1[disk_name].write_count) / stime)
                    diskInfo[disk_name]['read_bytes']   = int((diskio_2[disk_name].read_bytes - diskio_1[disk_name].read_bytes) / stime)
                    diskInfo[disk_name]['write_bytes']  = int((diskio_2[disk_name].write_bytes - diskio_1[disk_name].write_bytes) / stime)
                    diskInfo[disk_name]['read_time']    = int((diskio_2[disk_name].read_time - diskio_1[disk_name].read_time) / stime)
                    diskInfo[disk_name]['write_time']   = int((diskio_2[disk_name].write_time - diskio_1[disk_name].write_time) / stime)
                    diskInfo[disk_name]['read_merged_count'] = int((diskio_2[disk_name].read_merged_count - diskio_1[disk_name].read_merged_count) / stime)
                    diskInfo[disk_name]['write_merged_count'] = int((diskio_2[disk_name].write_merged_count - diskio_1[disk_name].write_merged_count) / stime)

                    diskInfo['ALL']['read_count'] += diskInfo[disk_name]['read_count']
                    diskInfo['ALL']['write_count'] += diskInfo[disk_name]['write_count']
                    diskInfo['ALL']['read_bytes'] += diskInfo[disk_name]['read_bytes']
                    diskInfo['ALL']['write_bytes'] += diskInfo[disk_name]['write_bytes']
                    if diskInfo['ALL']['read_time'] < diskInfo[disk_name]['read_time']:
                        diskInfo['ALL']['read_time'] = diskInfo[disk_name]['read_time']
                    if diskInfo['ALL']['write_time'] < diskInfo[disk_name]['write_time']:
                        diskInfo['ALL']['write_time'] = diskInfo[disk_name]['write_time']
                    diskInfo['ALL']['read_merged_count'] += diskInfo[disk_name]['read_merged_count']
                    diskInfo['ALL']['write_merged_count'] += diskInfo[disk_name]['write_merged_count']

                cache.set(iokey,{'info':diskio_2,'time':mtime})
        except:
            public.writeFile('/tmp/2',str(public.get_error_info()))
            return diskInfo
        return diskInfo
コード例 #6
0
ファイル: panelApi.py プロジェクト: CQT-IT-Service/SA-CP
 def login_for_app(self, get):
     from BTPanel import cache
     tid = get.tid
     if (len(tid) != 12):
         return public.returnMsg(False, 'Invalid login key')
     session_id = cache.get(tid)
     if not session_id:
         return public.returnMsg(
             False, 'The specified key does not exist or has expired')
     if (len(session_id) != 64):
         return public.returnMsg(False, 'Invalid login key')
     cache.set(session_id, 'True', 120)
     return public.returnMsg(True, 'Scan code successfully, log in!')
コード例 #7
0
ファイル: system.py プロジェクト: tgd1973/aaPanel
 def GetDiskInfo2(self):
     #取磁盘分区信息
     key = 'sys_disk'
     diskInfo = cache.get(key)
     if diskInfo: return diskInfo
     temp = public.ExecShell(
         "df -hT -P|grep '/'|grep -v tmpfs|grep -v 'snap/core'|grep -v udev"
     )[0]
     tempInodes = public.ExecShell(
         "df -i -P|grep '/'|grep -v tmpfs|grep -v 'snap/core'|grep -v udev"
     )[0]
     temp1 = temp.split('\n')
     tempInodes1 = tempInodes.split('\n')
     diskInfo = []
     n = 0
     cuts = [
         '/mnt/cdrom', '/boot', '/boot/efi', '/dev', '/dev/shm',
         '/run/lock', '/run', '/run/shm', '/run/user'
     ]
     for tmp in temp1:
         n += 1
         try:
             if ',' in tmp:
                 tmp = re.sub(',\d+', '', tmp)
             inodes = tempInodes1[n - 1].split()
             disk = re.findall(
                 r"^(.+)\s+([\w\.]+)\s+([\w\.]+)\s+([\w\.]+)\s+([\w\.]+)\s+([\d%]{2,4})\s+(/.{0,100})$",
                 tmp.strip())
             if disk: disk = disk[0]
             if len(disk) < 6: continue
             if disk[2].find('M') != -1: continue
             if disk[2].find('K') != -1: continue
             if len(disk[6].split('/')) > 10: continue
             if disk[6] in cuts: continue
             if disk[6].find('docker') != -1: continue
             if disk[1].strip() in ['tmpfs']: continue
             arr = {}
             arr['filesystem'] = disk[0].strip()
             arr['type'] = disk[1].strip()
             arr['path'] = disk[6].replace(
                 '/usr/local/lighthouse/softwares/btpanel', '/www')
             tmp1 = [disk[2], disk[3], disk[4], disk[5]]
             arr['size'] = tmp1
             arr['inodes'] = [inodes[1], inodes[2], inodes[3], inodes[4]]
             diskInfo.append(arr)
         except Exception as ex:
             public.WriteLog('GET_INFO', str(ex))
             continue
     cache.set(key, diskInfo, 10)
     return diskInfo
コード例 #8
0
ファイル: common.py プロジェクト: xgocn/aaPanel
    def check_login(self):
        try:
            api_check = True
            if not 'login' in session:
                api_check = self.get_sk()
                if api_check:
                    session.clear()
                    return api_check
            else:
                if session['login'] == False:
                    session.clear()
                    return redirect('/login')
            if api_check:
                try:
                    sess_out_path = 'data/session_timeout.pl'
                    sess_input_path = 'data/session_last.pl'
                    if not os.path.exists(sess_out_path):
                        public.writeFile(sess_out_path, '86400')
                    if not os.path.exists(sess_input_path):
                        public.writeFile(sess_input_path,
                                         str(int(time.time())))
                    session_timeout = int(public.readFile(sess_out_path))
                    session_last = int(public.readFile(sess_input_path))
                    if time.time() - session_last > session_timeout:
                        os.remove(sess_input_path)
                        session['login'] = False
                        cache.set('dologin', True)
                        session.clear()
                        return redirect('/login')
                    public.writeFile(sess_input_path, str(int(time.time())))
                except:
                    pass

            filename = '/www/server/panel/data/login_token.pl'
            if os.path.exists(filename):
                token = public.readFile(filename).strip()
                if 'login_token' in session:
                    if session['login_token'] != token:
                        session.clear()
                        return redirect('/login?dologin=True')
            if api_check:
                filename = 'data/sess_files/' + public.get_sess_key()
                if not os.path.exists(filename):
                    session.clear()
                    return redirect('/login?dologin=True')
        except:
            return public.returnMsg(False, public.get_error_info())
            session.clear()
            return redirect('/login')
コード例 #9
0
ファイル: system.py プロジェクト: weweyes/aaPanel
 def GetSystemVersion(self):
     #取操作系统版本
     key = 'sys_version'
     version = cache.get(key)
     if version: return version
     import public
     version = public.readFile('/etc/redhat-release')
     if not version:
         version = public.readFile('/etc/issue').strip().split("\n")[0].replace('\\n','').replace('\l','').strip()
     else:
         version = version.replace('release ','').replace('Linux','').replace('(Core)','').strip()
     v_info = sys.version_info
     version = version + '(Py' + str(v_info.major) + '.' + str(v_info.minor) + '.' + str(v_info.micro) + ')'
     cache.set(key,version,600)
     return version
コード例 #10
0
ファイル: system.py プロジェクト: tgd1973/aaPanel
 def GetMemInfo(self, get=None):
     #取内存信息
     skey = 'memInfo'
     memInfo = cache.get(skey)
     if memInfo: return memInfo
     mem = psutil.virtual_memory()
     memInfo = {
         'memTotal': int(mem.total / 1024 / 1024),
         'memFree': int(mem.free / 1024 / 1024),
         'memBuffers': int(mem.buffers / 1024 / 1024),
         'memCached': int(mem.cached / 1024 / 1024)
     }
     memInfo['memRealUsed'] = memInfo['memTotal'] - memInfo[
         'memFree'] - memInfo['memBuffers'] - memInfo['memCached']
     cache.set(skey, memInfo, 60)
     return memInfo
コード例 #11
0
ファイル: system.py プロジェクト: wonderking/aaPanel
 def GetBootTime(self):
     #取系统启动时间
     key = 'sys_time'
     sys_time = cache.get(key)
     if sys_time: return sys_time
     import public, math
     conf = public.readFile('/proc/uptime').split()
     tStr = float(conf[0])
     min = tStr / 60
     hours = min / 60
     days = math.floor(hours / 24)
     hours = math.floor(hours - (days * 24))
     min = math.floor(min - (days * 60 * 24) - (hours * 60))
     sys_time = "{} Days".format(int(days))
     cache.set(key, sys_time, 1800)
     return sys_time
コード例 #12
0
 def get_io_read(self, io_read):
     disk_io_read = 0
     old_io_read = cache.get('io_read')
     if not old_io_read:
         cache.set('io_read', io_read)
         return disk_io_read
     old_io_time = cache.get('io_time')
     new_io_time = time.time()
     if not old_io_time: old_io_time = new_io_time
     io_end = (io_read - old_io_read)
     time_end = (time.time() - old_io_time)
     if io_end > 0:
         if time_end < 1: time_end = 1
         disk_io_read = io_end / time_end
     cache.set('io_read', io_read)
     if disk_io_read > 0: return int(disk_io_read)
     return 0
コード例 #13
0
ファイル: system.py プロジェクト: zwt12370/BaoTa
    def get_cpu_percent(self):
        percent = 0.00;
        old_cpu_time = cache.get('old_cpu_time')
        old_process_time = cache.get('old_process_time')
        if not old_cpu_time: 
            old_cpu_time = self.get_cpu_time()
            old_process_time = self.get_process_cpu_time()
            time.sleep(1)
        new_cpu_time = self.get_cpu_time()
        new_process_time = self.get_process_cpu_time()
        percent = round(100.00 * ((new_process_time - old_process_time) / (new_cpu_time - old_cpu_time)),2)

        cache.set('old_cpu_time',new_cpu_time)
        cache.set('old_process_time',new_process_time)
        if percent > 100: percent = 100
        if percent > 0: return percent;
        return 0.00;
コード例 #14
0
    def get_request_count_qps(self, args):
        from BTPanel import cache

        cache_timeout = 86400

        old_total_request = cache.get('old_total_request')
        otime = cache.get("old_get_time")
        if not old_total_request or not otime:
            otime = time.time()
            old_total_request = self._get_request_count(args)
            time.sleep(2)
        ntime = time.time()
        new_total_request = self._get_request_count(args)

        qps = float(new_total_request - old_total_request) / (ntime - otime)

        cache.set('old_total_request', new_total_request, cache_timeout)
        cache.set('old_get_time', ntime, cache_timeout)
        return {'qps': qps, 'request_count': new_total_request}
コード例 #15
0
    def limit_address(self,type,v=""):
        import time
        clientIp = public.GetClientIp()
        numKey = 'limitIpNum_' + v + clientIp
        limit = 6
        outTime = 600
        try:
            #初始化
            num1 = cache.get(numKey)
            if not num1:
                cache.set(numKey,1,outTime)
                num1 = 1
                        
            #计数
            if type == '+':
                cache.inc(numKey,1)
                self.error_num()
                session['code'] = True
                return limit - (num1+1)

            #计数验证器
            if type == '++':
                cache.inc(numKey,1)
                self.error_num()
                session['code'] = False
                return limit - (num1+1)

            #清空
            if type == '-':
                cache.delete(numKey)
                session['code'] = False
                return 1

            #清空验证器
            if type == '--':
                cache.delete(numKey)
                session['code'] = False
                return 1
            return limit - num1
        except:
            return limit
コード例 #16
0
ファイル: common.py プロジェクト: kodmek/BaoTa
    def checkDomain(self):
        try:
            api_check = True
            if not 'login' in session:
                api_check = self.get_sk()
                if api_check: return api_check
            else:
                if session['login'] == False: return redirect('/login')
            tmp = public.GetHost()
            domain = public.ReadFile('data/domain.conf')
            if domain:
                if (tmp.strip().lower() != domain.strip().lower()):
                    return redirect('/login')
            if api_check:
                try:
                    sess_out_path = 'data/session_timeout.pl'
                    sess_input_path = 'data/session_last.pl'
                    if not os.path.exists(sess_out_path):
                        public.writeFile(sess_out_path, '86400')
                    if not os.path.exists(sess_input_path):
                        public.writeFile(sess_input_path,
                                         str(int(time.time())))
                    session_timeout = int(public.readFile(sess_out_path))
                    session_last = int(public.readFile(sess_input_path))
                    if time.time() - session_last > session_timeout:
                        os.remove(sess_input_path)
                        session['login'] = False
                        cache.set('dologin', True)
                        return redirect('/login')
                    public.writeFile(sess_input_path, str(int(time.time())))
                except:
                    pass

            filename = 'data/login_token.pl'
            if os.path.exists(filename):
                token = public.readFile(filename).strip()
                if 'login_token' in session:
                    if session['login_token'] != token:
                        return redirect('/login?dologin=True')
        except:
            return redirect('/login')
コード例 #17
0
 def checkBackup(self):
     if cache.get('check_backup'): return None
     #检查备份脚本是否存在
     filePath=public.GetConfigValue('setup_path')+'/panel/script/backup'
     if not os.path.exists(filePath):
         public.downloadFile(public.GetConfigValue('home') + '/linux/backup.sh',filePath)
     #检查日志切割脚本是否存在
     filePath=public.GetConfigValue('setup_path')+'/panel/script/logsBackup'
     if not os.path.exists(filePath):
         public.downloadFile(public.GetConfigValue('home') + '/linux/logsBackup.py',filePath)
     #检查计划任务服务状态
     
     import system
     sm = system.system()
     if os.path.exists('/etc/init.d/crond'): 
         if not public.process_exists('crond'): public.ExecShell('/etc/init.d/crond start')
     elif os.path.exists('/etc/init.d/cron'):
         if not public.process_exists('cron'): public.ExecShell('/etc/init.d/cron start')
     elif os.path.exists('/usr/lib/systemd/system/crond.service'):
         if not public.process_exists('crond'): public.ExecShell('systemctl start crond')
     cache.set('check_backup',True,3600)
コード例 #18
0
ファイル: jobs.py プロジェクト: zuoapp-ly/BaoTa
def install_task():
    if cache.get('install_task'): return True
    if cache.get('install_exists'): return True
    sql = db.Sql()
    sql.table('tasks').where("status=?",('-1',)).setField('status','0')
    taskArr = sql.table('tasks').where("status=?",('0',)).field('id,type,execstr').order("id asc").select();
    cache.set('install_exists',True)
    cache.delete('install_task')
    logPath = '/tmp/panelExec.log'
    for value in taskArr:
        start = int(time.time());
        if not sql.table('tasks').where("id=?",(value['id'],)).count(): continue;
        sql.table('tasks').where("id=?",(value['id'],)).save('status,start',('-1',start))
        if value['type'] == 'download':
            import downloadFile
            argv = value['execstr'].split('|bt|')
            downloadFile.downloadFile().DownloadFile(argv[0],argv[1])
        elif value['type'] == 'execshell':
           os.system(value['execstr'] + " > " + logPath + " 2>&1")
        end = int(time.time())
        sql.table('tasks').where("id=?",(value['id'],)).save('status,end',('1',end))
    cache.delete('install_exists')
コード例 #19
0
ファイル: panelPHP.py プロジェクト: syncsm/aaPanel
    def get_phpmyadmin_phpversion(self):
        '''
            @name 获取当前phpmyadmin设置的PHP版本
            @author hwliang<2020-07-13>
            @return string
        '''
        ikey = 'pma_phpv'
        phpv = cache.get(ikey)
        if phpv: return phpv
        webserver = public.get_webserver()
        if webserver == 'nginx':
            filename = public.GetConfigValue(
                'setup_path') + '/nginx/conf/enable-php.conf'
            conf = public.readFile(filename)
            if not conf: return None
            rep = r"php-cgi-(\d+)\.sock"
            phpv = re.findall(rep, conf)
        elif webserver == 'openlitespeed':
            filename = public.GetConfigValue(
                'setup_path'
            ) + "/panel/vhost/openlitespeed/detail/phpmyadmin.conf"
            conf = public.readFile(filename)
            if not conf: return None
            rep = r"/usr/local/lsws/lsphp(\d+)/bin/lsphp"
            phpv = re.findall(rep, conf)
        else:
            filename = public.GetConfigValue(
                'setup_path') + '/apache/conf/extra/httpd-vhosts.conf'
            conf = public.readFile(filename)
            if not conf: return None
            rep = r"php-cgi-(\d+)\.sock"
            phpv = re.findall(rep, conf)

        if not phpv: return None
        cache.set(ikey, phpv[0], 3)
        return phpv[0]
コード例 #20
0
    def get_io_write(self, io_write):
        disk_io_write = 0
        old_io_write = cache.get('io_write')
        if not old_io_write:
            cache.set('io_write', io_write)
            return disk_io_write

        old_io_time = cache.get('io_time')
        new_io_time = time.time()
        if not old_io_time: old_io_time = new_io_time
        io_end = (io_write - old_io_write)
        time_end = (time.time() - old_io_time)
        if io_end > 0:
            if time_end < 1: time_end = 1
            disk_io_write = io_end / time_end
        cache.set('io_write', io_write)
        cache.set('io_time', new_io_time)
        if disk_io_write > 0: return int(disk_io_write)
        return 0
コード例 #21
0
    def GetNetWorkOld(self):
        #取网络流量信息
        import time
        pnet = public.readFile('/proc/net/dev')
        rep = '([^\s]+):[\s]{0,}(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)'
        pnetall = re.findall(rep, pnet)
        networkInfo = {}
        networkInfo['upTotal'] = networkInfo['downTotal'] = networkInfo[
            'up'] = networkInfo['down'] = networkInfo[
                'downPackets'] = networkInfo['upPackets'] = 0

        for pnetInfo in pnetall:
            if pnetInfo[0] == 'io': continue
            networkInfo['downTotal'] += int(pnetInfo[1])
            networkInfo['downPackets'] += int(pnetInfo[2])
            networkInfo['upTotal'] += int(pnetInfo[9])
            networkInfo['upPackets'] += int(pnetInfo[10])

        cache_timeout = 86400
        otime = cache.get("otime")
        if not otime:
            otime = time.time()
            cache.set('up', networkInfo['upTotal'], cache_timeout)
            cache.set('down', networkInfo['downTotal'], cache_timeout)
            cache.set('otime', otime, cache_timeout)

        ntime = time.time()
        tmpDown = networkInfo['downTotal'] - cache.get("down")
        tmpUp = networkInfo['upTotal'] - cache.get("up")
        networkInfo['down'] = str(
            round(float(tmpDown) / 1024 / (ntime - otime), 2))
        networkInfo['up'] = str(round(
            float(tmpUp) / 1024 / (ntime - otime), 2))
        if networkInfo['down'] < 0: networkInfo['down'] = 0
        if networkInfo['up'] < 0: networkInfo['up'] = 0

        otime = time.time()
        cache.set('up', networkInfo['upTotal'], cache_timeout)
        cache.set('down', networkInfo['downTotal'], cache_timeout)
        cache.set('otime', ntime, cache_timeout)

        networkInfo['cpu'] = self.GetCpuInfo()
        return networkInfo
コード例 #22
0
    def GetNetWork(self, get=None):
        cache_timeout = 86400
        networkIo = psutil.net_io_counters()[:4]
        otime = cache.get("otime")
        if not otime:
            otime = time.time()
            cache.set('up', networkIo[0], cache_timeout)
            cache.set('down', networkIo[1], cache_timeout)
            cache.set('otime', otime, cache_timeout)

        ntime = time.time()
        networkInfo = {}
        networkInfo['upTotal'] = networkIo[0]
        networkInfo['downTotal'] = networkIo[1]
        networkInfo['up'] = round(
            float(networkIo[0] - cache.get("up")) / 1024 / (ntime - otime), 2)
        networkInfo['down'] = round(
            float(networkIo[1] - cache.get("down")) / 1024 / (ntime - otime),
            2)
        networkInfo['downPackets'] = networkIo[3]
        networkInfo['upPackets'] = networkIo[2]

        cache.set('up', networkIo[0], cache_timeout)
        cache.set('down', networkIo[1], cache_timeout)
        cache.set('otime', time.time(), cache_timeout)
        if get != False:
            networkInfo['cpu'] = self.GetCpuInfo(0.2)
            networkInfo['load'] = self.GetLoadAverage(get)
            networkInfo['mem'] = self.GetMemInfo(get)
            networkInfo['version'] = session['version']
            networkInfo['disk'] = self.GetDiskInfo2()

        networkInfo['title'] = self.GetTitle()
        networkInfo['time'] = self.GetBootTime()
        networkInfo['site_total'] = public.M('sites').count()
        networkInfo['ftp_total'] = public.M('ftps').count()
        networkInfo['database_total'] = public.M('databases').count()
        return networkInfo
コード例 #23
0
ファイル: panelPHP.py プロジェクト: syncsm/aaPanel
    def start(self, puri, document_root, last_path=''):
        '''
            @name 开始处理PHP请求
            @author hwliang<2020-07-11>
            @param puri string(URI地址)
            @return socket or Response
        '''
        if puri in ['/', '', None]: puri = 'index.php'
        if puri[0] == '/': puri = puri[1:]
        self.document_root = document_root
        self.last_path = last_path
        filename = document_root + puri

        #如果是PHP文件
        if puri[-4:] == '.php':
            if request.path.find('/phpmyadmin/') != -1:
                ikey = 'pma_php_version'
                self.php_version = cache.get(ikey)
                if not self.php_version:
                    php_version = self.get_phpmyadmin_phpversion()
                    php_versions = self.check_phpmyadmin_phpversion()
                    if not php_versions:
                        if php_versions == False:
                            return Resp(
                                'Phpmyadmin is not installed, or support for phpMyAdmin4.6 has been discontinued due to security issues, uninstall and install other secure versions in the software store!'
                            )
                        else:
                            return Resp('phpmyadmin is not installed')
                    if not php_version or not php_version in php_versions:
                        php_version = php_versions
                    self.php_version = self.get_php_version(php_version)
                    if not self.php_version:
                        php_version = self.check_phpmyadmin_phpversion()
                        self.php_version = self.get_php_version(php_version)
                        if not php_version:
                            return Resp(
                                'No supported PHP version found: {}'.format(
                                    php_versions))

                    if not self.php_version in php_versions:
                        self.php_version = self.get_php_version(php_versions)

                        if not self.php_version:
                            return Resp(
                                'No supported PHP version found: {}'.format(
                                    php_versions))
                    cache.set(ikey, self.php_version, 1)
                if request.method == 'POST':
                    #登录phpmyadmin
                    if puri in ['index.php', '/index.php']:
                        content = public.url_encode(request.form.to_dict())
                        if not isinstance(content, bytes):
                            content = content.encode()
                        self.re_io = StringIO(content)
                        username = request.form.get('pma_username')
                        if username:
                            password = request.form.get('pma_password')
                            if not self.write_pma_passwd(username, password):
                                return Resp('Phpmyadmin is not installed')

                if puri in ['logout.php', '/logout.php']:
                    self.write_pma_passwd(None, None)
            else:
                src_path = '/www/server/panel/adminer'
                dst_path = '/www/server/adminer'
                if os.path.exists(src_path):
                    if not os.path.exists(dst_path): os.makedirs(dst_path)
                    public.ExecShell("\cp -arf {}/* {}/".format(
                        src_path, dst_path))
                    public.ExecShell("chown -R www:www {}".format(dst_path))
                    public.ExecShell("chmod -R 700 {}".format(dst_path))
                    public.ExecShell("rm -rf {}".format(src_path))

                if not os.path.exists(dst_path + '/index.php'):
                    return Resp(
                        "The AdMiner file is missing. Please try again after the [Fix] panel on the first page!"
                    )

                ikey = 'aer_php_version'
                self.php_version = cache.get(ikey)
                if not self.php_version:
                    self.php_version = self.get_php_version(None)
                    cache.set(ikey, self.php_version, 10)
                    if not self.php_version:
                        return Resp('没有找到可用的PHP版本')

            #文件是否存在?
            if not os.path.exists(filename):
                return abort(404)

            #发送到FPM
            try:
                return self.request_php(puri)
            except Exception as ex:
                if str(ex).find('No such file or directory') != -1:
                    return Resp(
                        'Specify PHP version: {}, not started, or unable to connect!'
                        .format(self.php_version))
                return Resp(str(ex))

        if not os.path.exists(filename):
            return abort(404)

        #如果是静态文件
        return send_file(filename)
コード例 #24
0
ファイル: wxapp.py プロジェクト: WytheLi/panel
 def login_qrcode(self, get):
     tid = public.GetRandomString(12)
     qrcode_str = 'https://app.bt.cn/app.html?&panel_url='+public.getPanelAddr()+'&v=' + public.GetRandomString(3)+'?login&tid=' + tid
     cache.set(tid,public.get_session_id(),360)
     cache.set(public.get_session_id(),tid,360)
     return public.returnMsg(True, qrcode_str)
コード例 #25
0
ファイル: system.py プロジェクト: zwt12370/BaoTa
    def GetNetWork(self,get=None):
        cache_timeout = 86400
        networkIo = psutil.net_io_counters()[:4]
        otime = cache.get("otime")
        if not otime:
            otime = time.time()
            cache.set('up',networkIo[0],cache_timeout)
            cache.set('down',networkIo[1],cache_timeout)
            cache.set('otime',otime ,cache_timeout)
            
        ntime = time.time();
        networkInfo = {}
        networkInfo['upTotal']   = networkIo[0]
        networkInfo['downTotal'] = networkIo[1]
        networkInfo['up']        = round(float(networkIo[0] -  cache.get("up")) / 1024 / (ntime - otime),2)
        networkInfo['down']      = round(float(networkIo[1] -  cache.get("down")) / 1024 / (ntime -  otime),2)
        networkInfo['downPackets'] =networkIo[3]
        networkInfo['upPackets']   =networkIo[2]
            
        cache.set('up',networkIo[0],cache_timeout)
        cache.set('down',networkIo[1],cache_timeout)
        cache.set('otime', time.time(),cache_timeout)
        if get != False:
            networkInfo['cpu'] = self.GetCpuInfo()
            networkInfo['load'] = self.GetLoadAverage(get);
            networkInfo['mem'] = self.GetMemInfo(get)

        return networkInfo
コード例 #26
0
ファイル: system.py プロジェクト: wonderking/aaPanel
    def GetNetWork(self, get=None):
        cache_timeout = 86400
        otime = cache.get("otime")
        ntime = time.time()
        networkInfo = {}
        networkInfo['network'] = {}
        networkInfo['upTotal'] = 0
        networkInfo['downTotal'] = 0
        networkInfo['up'] = 0
        networkInfo['down'] = 0
        networkInfo['downPackets'] = 0
        networkInfo['upPackets'] = 0
        networkIo_list = psutil.net_io_counters(pernic=True)
        for net_key in networkIo_list.keys():
            networkIo = networkIo_list[net_key][:4]
            up_key = "{}_up".format(net_key)
            down_key = "{}_down".format(net_key)
            otime_key = "otime"

            if not otime:
                otime = time.time()

                cache.set(up_key, networkIo[0], cache_timeout)
                cache.set(down_key, networkIo[1], cache_timeout)
                cache.set(otime_key, otime, cache_timeout)

            networkInfo['network'][net_key] = {}
            up = cache.get(up_key)
            down = cache.get(down_key)
            if not up:
                up = networkIo[0]
            if not down:
                down = networkIo[1]
            networkInfo['network'][net_key]['upTotal'] = networkIo[0]
            networkInfo['network'][net_key]['downTotal'] = networkIo[1]
            networkInfo['network'][net_key]['up'] = round(
                float(networkIo[0] - up) / 1024 / (ntime - otime), 2)
            networkInfo['network'][net_key]['down'] = round(
                float(networkIo[1] - down) / 1024 / (ntime - otime), 2)
            networkInfo['network'][net_key]['downPackets'] = networkIo[3]
            networkInfo['network'][net_key]['upPackets'] = networkIo[2]

            networkInfo['upTotal'] += networkInfo['network'][net_key][
                'upTotal']
            networkInfo['downTotal'] += networkInfo['network'][net_key][
                'downTotal']
            networkInfo['up'] += networkInfo['network'][net_key]['up']
            networkInfo['down'] += networkInfo['network'][net_key]['down']
            networkInfo['downPackets'] += networkInfo['network'][net_key][
                'downPackets']
            networkInfo['upPackets'] += networkInfo['network'][net_key][
                'upPackets']

            cache.set(up_key, networkIo[0], cache_timeout)
            cache.set(down_key, networkIo[1], cache_timeout)
            cache.set(otime_key, time.time(), cache_timeout)

        if get != False:
            networkInfo['cpu'] = self.GetCpuInfo(1)
            networkInfo['load'] = self.GetLoadAverage(get)
            networkInfo['mem'] = self.GetMemInfo(get)
            networkInfo['version'] = session['version']
            networkInfo['disk'] = self.GetDiskInfo2()

        networkInfo['title'] = self.GetTitle()
        networkInfo['time'] = self.GetBootTime()
        networkInfo['site_total'] = public.M('sites').count()
        networkInfo['ftp_total'] = public.M('ftps').count()
        networkInfo['database_total'] = public.M('databases').count()
        networkInfo['system'] = self.GetSystemVersion()
        networkInfo['installed'] = self.CheckInstalled()
        import panelSSL
        networkInfo['user_info'] = panelSSL.panelSSL().GetUserInfo(None)
        networkInfo['up'] = round(float(networkInfo['up']), 2)
        networkInfo['down'] = round(float(networkInfo['down']), 2)

        return networkInfo
コード例 #27
0
ファイル: system.py プロジェクト: wonderking/aaPanel
 def get_cpu_percent_thead(self, interval):
     used = psutil.cpu_percent(interval)
     cache.set('cpu_used_all', used, 10)
     return used
コード例 #28
0
ファイル: public.py プロジェクト: piaoyunsoft/bt_lnmp
def cache_set(key,value,timeout = None):
    from BTPanel import cache
    return cache.set(key,value,timeout)
コード例 #29
0
    def start(self, puri, document_root, last_path=''):
        '''
            @name 开始处理PHP请求
            @author hwliang<2020-07-11>
            @param puri string(URI地址)
            @return socket or Response
        '''
        if puri in ['/', '', None]: puri = 'index.php'
        if puri[0] == '/': puri = puri[1:]
        self.document_root = document_root
        self.last_path = last_path
        filename = document_root + puri

        #如果是PHP文件
        if puri[-4:] == '.php':
            if request.path.find('/phpmyadmin/') != -1:
                ikey = 'pma_php_version'
                self.php_version = cache.get(ikey)
                if not self.php_version:
                    php_version = self.get_phpmyadmin_phpversion()
                    php_versions = self.check_phpmyadmin_phpversion()
                    if not php_versions:
                        if php_versions == False:
                            return Resp(
                                '因安全问题,已停止对phpMyAdmin4.6的支持,到软件商店卸载并安装其它安全版本!')
                        else:
                            return Resp('未安装phpmyadmin')
                    if not php_version or not php_version in php_versions:
                        php_version = php_versions
                    self.php_version = self.get_php_version(php_version)
                    if not self.php_version:
                        php_version = self.check_phpmyadmin_phpversion()
                        self.php_version = self.get_php_version(php_version)
                        if not php_version:
                            return Resp(
                                '没有找到支持的PHP版本: {}'.format(php_versions))

                    if not self.php_version in php_versions:
                        self.php_version = self.get_php_version(php_versions)

                        if not self.php_version:
                            return Resp(
                                '没有找到支持的PHP版本: {}'.format(php_versions))
                    cache.set(ikey, self.php_version, 1)

                if request.method == 'POST':
                    #登录phpmyadmin
                    if puri in ['index.php', '/index.php']:
                        content = public.url_encode(request.form.to_dict())
                        if not isinstance(content, bytes):
                            content = content.encode()
                        self.re_io = StringIO(content)
                        username = request.form.get('pma_username')
                        if username:
                            password = request.form.get('pma_password')
                            if not self.write_pma_passwd(username, password):
                                return Resp('未安装phpmyadmin')

                if puri in ['logout.php', '/logout.php']:
                    self.write_pma_passwd(None, None)
            else:
                src_path = '/www/server/panel/adminer'
                dst_path = '/www/server/adminer'
                if os.path.exists(src_path):
                    if not os.path.exists(dst_path): os.makedirs(dst_path)
                    public.ExecShell("\cp -arf {}/* {}/".format(
                        src_path, dst_path))
                    public.ExecShell("chown -R www:www {}".format(dst_path))
                    public.ExecShell("chmod -R 700 {}".format(dst_path))
                    public.ExecShell("rm -rf {}".format(src_path))

                if not os.path.exists(dst_path + '/index.php'):
                    return Resp("adminer文件缺失,请在首页[修复]面板后重试!")

                ikey = 'aer_php_version'
                self.php_version = cache.get(ikey)
                if not self.php_version:
                    self.php_version = self.get_php_version(None)
                    cache.set(ikey, self.php_version, 10)
                    if not self.php_version:
                        return Resp('没有找到可用的PHP版本')

            #文件是否存在?
            if not os.path.exists(filename):
                return abort(404)

            #发送到FPM
            try:

                return self.request_php(puri)
            except Exception as ex:
                if str(ex).find('No such file or directory') != -1:
                    return Resp('指定PHP版本: {},未启动,或无法连接!'.format(
                        self.php_version))
                return Resp(str(ex))

        if not os.path.exists(filename):
            return abort(404)

        #如果是静态文件
        return send_file(filename)