Ejemplo n.º 1
0
def panel_status():
    time.sleep(1)
    panel_path = '/www/server/panel'
    pool = 'http://'
    if os.path.exists(panel_path + '/data/ssl.pl'): pool = 'https://'
    port = '8888'
    if os.path.exists(panel_path + '/data/port.pl'):
        port = public.readFile(panel_path + '/data/port.pl').strip()
    panel_url = pool + '127.0.0.1:' + port + '/service_status'
    panel_pid = get_panel_pid()
    n = 0
    s = 0
    v = 0
    while True:
        time.sleep(1)
        if not panel_pid: panel_pid = get_panel_pid()
        if not panel_pid: run_panel()
        try:
            if psutil.Process(panel_pid).cmdline()[-1] != 'runserver:app':
                run_panel()
                time.sleep(3)
                panel_pid = get_panel_pid()
                continue
        except:
            run_panel()
            time.sleep(3)
            panel_pid = get_panel_pid()
            continue

        n += 1
        v += 1

        if v > 10:
            v = 0
            log_path = panel_path + '/logs/error.log'
            if os.path.exists(log_path):
                e_body = public.GetNumLines(log_path, 10)
                if e_body:
                    if e_body.find(
                            'PyWSGIServer.do_close') != -1 or e_body.find(
                                'Expected GET method:') != -1 or e_body.find(
                                    'Invalid HTTP method:'
                                ) != -1 or e_body.find('table session') != -1:
                        result = public.httpGet(panel_url)
                        if result != 'True':
                            if e_body.find('table session') != -1:
                                sess_file = '/dev/shm/session.db'
                                if os.path.exists(sess_file):
                                    os.remove(sess_file)
                            os.system("/etc/init.d/bt reload &")
                            time.sleep(10)
                            result = public.httpGet(panel_url)
                            if result == 'True':
                                public.WriteLog(
                                    'TYPE_SOFE',
                                    'Checked to panel service exception, has been automatically restored!'
                                )

        if n > 18000:
            n = 0
            result = public.httpGet(panel_url)
            if result == 'True':
                time.sleep(10)
                continue
            os.system("/etc/init.d/bt reload &")
            result = public.httpGet(panel_url)
            if result == 'True':
                public.WriteLog(
                    'TYPE_SOFE',
                    'Checked to panel service exception, has been automatically restored!'
                )
                time.sleep(10)
                continue
Ejemplo n.º 2
0
 def get_panel_error_logs(self, get):
     filename = 'logs/error.log'
     if not os.path.exists(filename):
         return public.returnMsg(False, '没有找到运行日志')
     result = public.GetNumLines(filename, 2000)
     return public.returnMsg(True, result)
Ejemplo n.º 3
0
 def get_error_logs(self, get):
     return public.GetNumLines('logs/error.log', 2000)
Ejemplo n.º 4
0
 def GetOpeLogs(self, get):
     if not os.path.exists(get.path):
         return public.returnMsg(False, '日志文件不存在!')
     return public.returnMsg(True, public.GetNumLines(get.path, 1000))
Ejemplo n.º 5
0
 def GetSlowLogs(self, get):
     path = self.GetMySQLInfo(get)['datadir'] + '/mysql-slow.log'
     if not os.path.exists(path): return public.returnMsg(False, '日志文件不存在!')
     return public.returnMsg(True, public.GetNumLines(path, 100))
Ejemplo n.º 6
0
 def GetSlowLogs(self, get):
     path = '/www/server/data/mysql-slow.log'
     if not os.path.exists(path): return public.returnMsg(
             False, '日志文件不存在!')
     return public.returnMsg(True, public.GetNumLines(path, 1000))
Ejemplo n.º 7
0
 def GetFpmSlowLogs(self, get):
     path = '/www/server/php/' + get.version + '/var/log/slow.log'
     if not os.path.exists(path): return public.returnMsg(
             False, '日志文件不存在!')
     return public.returnMsg(True, public.GetNumLines(path, 1000))
Ejemplo n.º 8
0
 def GetExecShellMsg(self, get):
     fileName = '/tmp/panelShell.pl'
     if not os.path.exists(fileName): return 'FILE_SHELL_EMPTY'
     status = not public.process_exists('bash', None, '/tmp/panelShell.sh')
     return public.returnMsg(status, public.GetNumLines(fileName, 200))
Ejemplo n.º 9
0
 def GetLastLine(self, inputfile, lineNum):
     result = public.GetNumLines(inputfile, lineNum)
     if len(result) < 1:
         return public.getMsg('TASK_SLEEP')
     return result
Ejemplo n.º 10
0
 def ssh_login_task(OO0O00000OOO0000O, get=None):  #line:372
     O0OOO00O0O000O00O = public.GetNumLines('/var/log/secure',
                                            500).split('\n')  #line:373
     OOO0O0OO00O0O0000 = '/dev/shm/ssh_total_time.pl'  #line:374
     if not os.path.exists(OOO0O0OO00O0O0000):
         public.writeFile(OOO0O0OO00O0O0000,
                          str(int(time.time())))  #line:375
     O000O00OO00O00OOO = int(public.readFile(OOO0O0OO00O0O0000))  #line:376
     O00O00O00OO000OO0 = int(time.time())  #line:377
     O0OO0O0O000O0OO0O = O00O00O00OO000OO0 - O000O00OO00O00OOO  #line:378
     OO0O00000OOO0000O.__OO00OO0OOO00OOOO0 = OO0O00000OOO0000O.__OO00OO00O0O00OO0O(
     )  #line:379
     OOO0OO0O0OOOOO0OO = OO0O00000OOO0000O.__OO00OO0OOO00OOOO0[
         'ssh']  #line:380
     OO0O00000OOO0000O.get_deny_list()  #line:381
     OOO0O0000OOOO00O0 = False  #line:382
     for O0O00OO00OO00O00O in OO0O00000OOO0000O.__OO0OOO00000OO0000.keys(
     ):  #line:383
         if OO0O00000OOO0000O.__OO0OOO00000OO0000[
                 O0O00OO00OO00O00O] > O00O00O00OO000OO0 or OO0O00000OOO0000O.__OO0OOO00000OO0000[
                     O0O00OO00OO00O00O] == 0:
             continue  #line:384
         OO0O00000OOO0000O.ip = O0O00OO00OO00O00O  #line:385
         OO0O00000OOO0000O.remove_ssh_limit(None)  #line:386
     OOOOOOOO00O0OOO0O = {}  #line:387
     for O0000O00O00O00O00 in O0OOO00O0O000O00O:  #line:388
         if O0000O00O00O00O00.find('Failed password for') != -1:  #line:389
             OOOOOO0O0000O0000 = OO0O00000OOO0000O.__O0O0OOOO0000OO0O0(
                 re.search('^\w+\s+\d+\s+\d+:\d+:\d+',
                           O0000O00O00O00O00).group())  #line:390
             if O00O00O00OO000OO0 - OOOOOO0O0000O0000 > OOO0OO0O0OOOOO0OO[
                     'cycle']:
                 continue  #line:391
             O00OOOO0OO00O0O00 = re.search(
                 '(\d+\.)+\d+', O0000O00O00O00O00).group()  #line:392
             if O00OOOO0OO00O0O00 in OO0O00000OOO0000O.__OO0OOO00000OO0000:
                 continue  #line:393
             if not O00OOOO0OO00O0O00 in OOOOOOOO00O0OOO0O:
                 OOOOOOOO00O0OOO0O[O00OOOO0OO00O0O00] = 0  #line:394
             OOOOOOOO00O0OOO0O[O00OOOO0OO00O0O00] += 1  #line:395
             if OOOOOOOO00O0OOO0O[O00OOOO0OO00O0O00] < OOO0OO0O0OOOOO0OO[
                     'limit_count']:
                 continue  #line:396
             OO0O00000OOO0000O.__OO0OOO00000OO0000[
                 O00OOOO0OO00O0O00] = O00O00O00OO000OO0 + OOO0OO0O0OOOOO0OO[
                     'limit']  #line:397
             OO0O00000OOO0000O.save_deay_list()  #line:398
             OO0O00000OOO0000O.ip = O00OOOO0OO00O0O00  #line:399
             OO0O00000OOO0000O.add_ssh_limit(None)  #line:400
             public.WriteLog(u'SSH登录',
                             u"[%s]在[%s]秒内连续[%s]次登录SSH失败,封锁[%s]秒" %
                             (O00OOOO0OO00O0O00, OOO0OO0O0OOOOO0OO['cycle'],
                              OOO0OO0O0OOOOO0OO['limit_count'],
                              OOO0OO0O0OOOOO0OO['limit']))  #line:401
         elif O0000O00O00O00O00.find('Accepted p') != -1:  #line:402
             OOOOOO0O0000O0000 = OO0O00000OOO0000O.__O0O0OOOO0000OO0O0(
                 re.search('^\w+\s+\d+\s+\d+:\d+:\d+',
                           O0000O00O00O00O00).group())  #line:403
             if OOOOOO0O0000O0000 < O000O00OO00O00OOO:
                 continue
                 #line:404
             O00OOOO0OO00O0O00 = re.search(
                 '(\d+\.)+\d+', O0000O00O00O00O00).group()  #line:405
             O0000OOOOOO0O0O00 = re.findall("(\w+)\s+from",
                                            O0000O00O00O00O00)[0]  #line:406
             public.WriteLog(
                 u'SSH登录', u"用户[%s]成功登录服务器,用户IP:[%s],登录时间:[%s]" %
                 (O0000OOOOOO0O0O00, O00OOOO0OO00O0O00,
                  time.strftime(
                      '%Y-%m-%d %X',
                      time.localtime(OOOOOO0O0000O0000))))  #line:407
     public.writeFile(OOO0O0OO00O0O0000, str(int(time.time())))  #line:408
     return 'success'  #line:409
Ejemplo n.º 11
0
 def GetOpeLogs(self,get):
     if not os.path.exists(get.path): return public.returnMsg(False,'AJAX_LOG_FILR_NOT_EXISTS')
     return public.returnMsg(True,public.GetNumLines(get.path,1000))
Ejemplo n.º 12
0
 def GetFpmLogs(self,get):
     path = '/www/server/php/' + get.version + '/var/log/php-fpm.log'
     if not os.path.exists(path): return public.returnMsg(False,'AJAX_LOG_FILR_NOT_EXISTS')
     return public.returnMsg(True,public.GetNumLines(path,1000))