コード例 #1
0
 def GetCpuInfo(self, interval=1):
     time.sleep(0.5)
     #取CPU信息
     cpuCount = psutil.cpu_count()
     used = self.get_cpu_percent()
     used_all = psutil.cpu_percent(percpu=True)
     cpu_name = public.getCpuType()
     return used, cpuCount, used_all, cpu_name
コード例 #2
0
 def GetCpuInfo(self, interval=1):
     #取CPU信息
     cpuCount = psutil.cpu_count()
     cpuNum = psutil.cpu_count(logical=False)
     c_tmp = public.readFile('/proc/cpuinfo')
     d_tmp = re.findall("physical id.+", c_tmp)
     cpuW = len(set(d_tmp))
     used = psutil.cpu_percent(interval)
     used_all = psutil.cpu_percent(percpu=True)
     cpu_name = public.getCpuType() + " * {}".format(cpuW)
     return used, cpuCount, used_all, cpu_name, cpuNum, cpuW
コード例 #3
0
ファイル: system.py プロジェクト: wonderking/aaPanel
    def GetCpuInfo(self, interval=1):
        #取CPU信息
        cpuCount = psutil.cpu_count()
        cpuNum = psutil.cpu_count(logical=False)
        c_tmp = public.readFile('/proc/cpuinfo')
        d_tmp = re.findall("physical id.+", c_tmp)
        cpuW = len(set(d_tmp))
        import threading
        p = threading.Thread(target=self.get_cpu_percent_thead,
                             args=(interval, ))
        p.setDaemon(True)
        p.start()

        used = cache.get('cpu_used_all')
        if not used: used = self.get_cpu_percent_thead(interval)

        used_all = psutil.cpu_percent(percpu=True)
        cpu_name = public.getCpuType() + " * {}".format(cpuW)
        return used, cpuCount, used_all, cpu_name, cpuNum, cpuW
コード例 #4
0
ファイル: ajax.py プロジェクト: novecle/baota
 def UpdatePanel(self,get):
     #return public.returnMsg(False,'演示服务器,禁止此操作!');
     try:
         if not public.IsRestart(): return public.returnMsg(False,'EXEC_ERR_TASK');
         import web,json
         if int(web.ctx.session.config['status']) == 0:
             public.httpGet(web.ctx.session.home+'/Api/SetupCount?type=Linux');
             public.M('config').where("id=?",('1',)).setField('status',1);
         
         #取回远程版本信息
         if hasattr(web.ctx.session,'updateInfo') == True and hasattr(get,'check') == False:
             updateInfo = web.ctx.session.updateInfo;
         else:
             login_temp = 'data/login.temp';
             if os.path.exists(login_temp):
                 logs = public.readFile(login_temp)
                 os.remove(login_temp);
             else:
                 logs = '';
             import psutil,panelPlugin,system;
             mem = psutil.virtual_memory();
             mplugin = panelPlugin.panelPlugin();
             mplugin.ROWS = 10000;
             panelsys = system.system();
             data = {}
             data['sites'] = str(public.M('sites').count());
             data['ftps'] = str(public.M('ftps').count());
             data['databases'] = str(public.M('databases').count());
             data['system'] = panelsys.GetSystemVersion() + '|' + str(mem.total / 1024 / 1024) + 'MB|' + public.getCpuType() + '*' + str(psutil.cpu_count()) + '|' + public.get_webserver() + '|' + web.ctx.session.version;
             data['system'] += '||'+self.GetInstalleds(mplugin.getPluginList(None));
             data['logs'] = logs
             data['oem'] = ''
             data['intrusion'] = self.get_ssh_intrusion();
             msg = public.getMsg('PANEL_UPDATE_MSG');
             sUrl = web.ctx.session.home + '/Api/updateLinux';
             betaIs = 'data/beta.pl';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False':
                     sUrl = web.ctx.session.home + '/Api/updateLinuxBeta';
                     msg = public.getMsg('PANEL_UPDATE_MSG_TEST');
             
             betaIs = 'plugin/beta/config.conf';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False':
                     sUrl = web.ctx.session.home + '/Api/updateLinuxBeta';
                     msg = public.getMsg('PANEL_UPDATE_MSG_TEST');
             
             updateInfo = json.loads(public.httpPost(sUrl,data));
             if not updateInfo: return public.returnMsg(False,"CONNECT_ERR");
             updateInfo['msg'] = msg;
             web.ctx.session.updateInfo = updateInfo;
             
         #检查是否需要升级
         if updateInfo['version'] == web.ctx.session.version:
             try:
                 return public.returnMsg(False,updateInfo['msg']);
             except:
                 return public.returnMsg(False,'PANEL_UPDATE_ERR_NEW');
         
         
         #是否执行升级程序 
         if(updateInfo['force'] == True or hasattr(get,'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True):
             setupPath = web.ctx.session.setupPath;
             uptype = 'update';
             betaIs = 'plugin/beta/config.conf';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False': uptype = 'updateTest';
             betaIs = 'data/beta.pl';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False': uptype = 'updateTest';
             httpUrl = public.get_url();
             if httpUrl: updateInfo['downUrl'] =  httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo['version'] + '.zip';
             
             public.downloadFile(updateInfo['downUrl'],'panel.zip');
             if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN");
             public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/');
             import compileall
             if os.path.exists(setupPath + '/panel/main.py'): public.ExecShell('rm -f ' + setupPath + '/panel/*.pyc');
             if os.path.exists(setupPath + '/panel/class/common.py'): public.ExecShell('rm -f ' + setupPath + '/panel/class/*.pyc');
             
             compileall.compile_dir(setupPath + '/panel');
             compileall.compile_dir(setupPath + '/panel/class');
             public.ExecShell('rm -f panel.zip');
             web.ctx.session.version = updateInfo['version']
             return public.returnMsg(True,'PANEL_UPDATE',(updateInfo['version'],));
         
         #输出新版本信息
         data = {
             'status' : True,
             'version': updateInfo['version'],
             'updateMsg' : updateInfo['updateMsg']
         };
         
         public.ExecShell('rm -rf /www/server/phpinfo/*');
         return data;
     except Exception,ex:
         return public.returnMsg(False,"CONNECT_ERR");
コード例 #5
0
ファイル: ajax.py プロジェクト: zwt12370/BaoTa
 def UpdatePanel(self,get):
     try:
         if not public.IsRestart(): return public.returnMsg(False,'EXEC_ERR_TASK');
         import json
         if int(session['config']['status']) == 0:
             public.HttpGet(public.GetConfigValue('home')+'/Api/SetupCount?type=Linux');
             public.M('config').where("id=?",('1',)).setField('status',1);
         
         #取回远程版本信息
         if 'updateInfo' in session and hasattr(get,'check') == False:
             updateInfo = session['updateInfo'];
         else:
             login_temp = 'data/login.temp';
             if os.path.exists(login_temp):
                 logs = public.readFile(login_temp)
                 os.remove(login_temp);
             else:
                 logs = '';
             import psutil,panelPlugin,system;
             mem = psutil.virtual_memory();
             mplugin = panelPlugin.panelPlugin();
             mplugin.ROWS = 10000;
             panelsys = system.system();
             data = {}
             data['sites'] = str(public.M('sites').count());
             data['ftps'] = str(public.M('ftps').count());
             data['databases'] = str(public.M('databases').count());
             data['system'] = panelsys.GetSystemVersion() + '|' + str(mem.total / 1024 / 1024) + 'MB|' + public.getCpuType() + '*' + str(psutil.cpu_count()) + '|' + public.get_webserver() + '|' +session['version'];
             data['system'] += '||'+self.GetInstalleds(mplugin.getPluginList(None));
             data['logs'] = logs
             data['oem'] = ''
             data['intrusion'] = 0;
             msg = public.getMsg('PANEL_UPDATE_MSG');
             sUrl = public.GetConfigValue('home') + '/api/panel/updateLinux';                
             updateInfo = json.loads(public.httpPost(sUrl,data));
             if not updateInfo: return public.returnMsg(False,"CONNECT_ERR");
             updateInfo['msg'] = msg;
             session['updateInfo'] = updateInfo;
             
         #检查是否需要升级
         if updateInfo['version'] ==session['version']:
             try:
                 return public.returnMsg(False,updateInfo['msg']);
             except:
                 return public.returnMsg(False,'PANEL_UPDATE_ERR_NEW');
         
         
         #是否执行升级程序 
         if(updateInfo['force'] == True or hasattr(get,'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True):
             setupPath = public.GetConfigValue('setup_path');
             uptype = 'update';
             httpUrl = public.get_url();
             if httpUrl: updateInfo['downUrl'] =  httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo['version'] + '.zip';
             public.downloadFile(updateInfo['downUrl'],'panel.zip');
             if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN");
             public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/');
             import compileall
             if os.path.exists('/www/server/panel/runserver.py'): public.ExecShell('rm -f /www/server/panel/*.pyc');
             if os.path.exists('/www/server/panel/class/common.py'): public.ExecShell('rm -f /www/server/panel/class/*.pyc');
             
             if os.path.exists('panel.zip'):os.remove("panel.zip")
             session['version'] = updateInfo['version']
             if 'getCloudPlugin' in session: del(session['getCloudPlugin']);
             return public.returnMsg(True,'PANEL_UPDATE',(updateInfo['version'],));
         
         #输出新版本信息
         data = {
             'status' : True,
             'version': updateInfo['version'],
             'updateMsg' : updateInfo['updateMsg']
         };
         
         public.ExecShell('rm -rf /www/server/phpinfo/*');
         return data;
     except Exception as ex:
         return public.returnMsg(False,"CONNECT_ERR");
コード例 #6
0
ファイル: ajax.py プロジェクト: qiaoshuixia521/linux-yunwei
    def UpdatePanel(self, get):
        try:
            if not public.IsRestart():
                return public.returnMsg(False, 'EXEC_ERR_TASK')
            import json
            if int(session['config']['status']) == 0:
                public.HttpGet(
                    public.GetConfigValue('home') +
                    '/Api/SetupCount?type=Linux')
                public.M('config').where("id=?", ('1', )).setField('status', 1)

            #取回远程版本信息
            if 'updateInfo' in session and hasattr(get, 'check') == False:
                updateInfo = session['updateInfo']
            else:
                logs = ''
                import psutil, system, sys
                mem = psutil.virtual_memory()
                import panelPlugin
                mplugin = panelPlugin.panelPlugin()

                mplugin.ROWS = 10000
                panelsys = system.system()
                data = {}
                data['sites'] = str(public.M('sites').count())
                data['ftps'] = str(public.M('ftps').count())
                data['databases'] = str(public.M('databases').count())
                data['system'] = panelsys.GetSystemVersion() + '|' + str(
                    mem.total / 1024 /
                    1024) + 'MB|' + str(public.getCpuType()) + '*' + str(
                        psutil.cpu_count()) + '|' + str(
                            public.get_webserver()) + '|' + session['version']
                data['system'] += '||' + self.GetInstalleds(
                    mplugin.getPluginList(None))
                data['logs'] = logs
                data['client'] = request.headers.get('User-Agent')
                data['oem'] = ''
                data['intrusion'] = 0
                data['uid'] = self.get_uid()
                #msg = public.getMsg('PANEL_UPDATE_MSG');
                data['o'] = ''
                filename = '/www/server/panel/data/o.pl'
                if os.path.exists(filename):
                    data['o'] = str(public.readFile(filename))
                sUrl = public.GetConfigValue('home') + '/api/panel/updateLinux'
                updateInfo = json.loads(public.httpPost(sUrl, data))
                if not updateInfo:
                    return public.returnMsg(False, "CONNECT_ERR")
                #updateInfo['msg'] = msg;
                session['updateInfo'] = updateInfo

            #检查是否需要升级
            if updateInfo['is_beta'] == 1:
                if updateInfo['beta']['version'] == session['version']:
                    return public.returnMsg(False, updateInfo)
            else:
                if updateInfo['version'] == session['version']:
                    return public.returnMsg(False, updateInfo)

            #是否执行升级程序
            if (updateInfo['force'] == True or hasattr(get, 'toUpdate') == True
                    or os.path.exists('data/autoUpdate.pl') == True):
                if updateInfo['is_beta'] == 1:
                    updateInfo['version'] = updateInfo['beta']['version']
                setupPath = public.GetConfigValue('setup_path')
                uptype = 'update'
                httpUrl = public.get_url()
                if httpUrl:
                    updateInfo[
                        'downUrl'] = httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo[
                            'version'] + '.zip'
                public.downloadFile(updateInfo['downUrl'], 'panel.zip')
                if os.path.getsize('panel.zip') < 1048576:
                    return public.returnMsg(False, "PANEL_UPDATE_ERR_DOWN")
                public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/')
                import compileall
                if os.path.exists('/www/server/panel/runserver.py'):
                    public.ExecShell('rm -f /www/server/panel/*.pyc')
                if os.path.exists('/www/server/panel/class/common.py'):
                    public.ExecShell('rm -f /www/server/panel/class/*.pyc')

                if os.path.exists('panel.zip'): os.remove("panel.zip")
                session['version'] = updateInfo['version']
                if 'getCloudPlugin' in session: del (session['getCloudPlugin'])
                if updateInfo['is_beta'] == 1: self.to_beta()
                public.ExecShell("/etc/init.d/bt start")
                public.writeFile('data/restart.pl', 'True')
                return public.returnMsg(True, 'PANEL_UPDATE',
                                        (updateInfo['version'], ))

            #输出新版本信息
            data = {
                'status': True,
                'version': updateInfo['version'],
                'updateMsg': updateInfo['updateMsg']
            }

            public.ExecShell('rm -rf /www/server/phpinfo/*')
            return public.returnMsg(True, updateInfo)
        except Exception as ex:
            return public.returnMsg(False, "CONNECT_ERR")
コード例 #7
0
ファイル: ajax.py プロジェクト: soitun/BaoTa-Panel
 def UpdatePanel(self,get):
     #return public.returnMsg(False,'演示服务器,禁止此操作!');
     try:
         if not public.IsRestart(): return public.returnMsg(False,'EXEC_ERR_TASK');
         import web,json
         if int(web.ctx.session.config['status']) == 0:
             public.httpGet(web.ctx.session.home+'/Api/SetupCount?type=Linux');
             public.M('config').where("id=?",('1',)).setField('status',1);
         
         #取回远程版本信息
         if hasattr(web.ctx.session,'updateInfo') == True and hasattr(get,'check') == False:
             updateInfo = web.ctx.session.updateInfo;
         else:
             login_temp = 'data/login.temp';
             if os.path.exists(login_temp):
                 logs = public.readFile(login_temp)
                 os.remove(login_temp);
             else:
                 logs = '';
             import psutil,panelPlugin,system;
             mem = psutil.virtual_memory();
             mplugin = panelPlugin.panelPlugin();
             mplugin.ROWS = 10000;
             panelsys = system.system();
             data = {}
             data['sites'] = str(public.M('sites').count());
             data['ftps'] = str(public.M('ftps').count());
             data['databases'] = str(public.M('databases').count());
             data['system'] = panelsys.GetSystemVersion() + '|' + str(mem.total / 1024 / 1024) + 'MB|' + public.getCpuType() + '*' + str(psutil.cpu_count()) + '|' + public.get_webserver() + '|' + web.ctx.session.version;
             data['system'] += '||'+self.GetInstalleds(mplugin.getPluginList(None));
             data['logs'] = logs
             data['oem'] = ''
             data['intrusion'] = self.get_ssh_intrusion();
             msg = public.getMsg('PANEL_UPDATE_MSG');
             sUrl = web.ctx.session.home + '/Api/updateLinux';
             betaIs = 'data/beta.pl';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False':
                     sUrl = web.ctx.session.home + '/Api/updateLinuxBeta';
                     msg = public.getMsg('PANEL_UPDATE_MSG_TEST');
             
             betaIs = 'plugin/beta/config.conf';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False':
                     sUrl = web.ctx.session.home + '/Api/updateLinuxBeta';
                     msg = public.getMsg('PANEL_UPDATE_MSG_TEST');
             
             updateInfo = json.loads(public.httpPost(sUrl,data));
             if not updateInfo: return public.returnMsg(False,"CONNECT_ERR");
             updateInfo['msg'] = msg;
             web.ctx.session.updateInfo = updateInfo;
             
         #检查是否需要升级
         if updateInfo['version'] == web.ctx.session.version:
             try:
                 return public.returnMsg(False,updateInfo['msg']);
             except:
                 return public.returnMsg(False,'PANEL_UPDATE_ERR_NEW');
         
         
         #是否执行升级程序 
         if(updateInfo['force'] == True or hasattr(get,'toUpdate') == True or os.path.exists('data/autoUpdate.pl') == True):
             setupPath = web.ctx.session.setupPath;
             uptype = 'update';
             betaIs = 'plugin/beta/config.conf';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False': uptype = 'updateTest';
             betaIs = 'data/beta.pl';
             betaStr = public.readFile(betaIs);
             if betaStr:
                 if betaStr.strip() != 'False': uptype = 'updateTest';
             httpUrl = public.get_url();
             if httpUrl: updateInfo['downUrl'] =  httpUrl + '/install/' + uptype + '/LinuxPanel-' + updateInfo['version'] + '.zip';
             
             public.downloadFile(updateInfo['downUrl'],'panel.zip');
             if os.path.getsize('panel.zip') < 1048576: return public.returnMsg(False,"PANEL_UPDATE_ERR_DOWN");
             public.ExecShell('unzip -o panel.zip -d ' + setupPath + '/');
             import compileall
             if os.path.exists(setupPath + '/panel/main.py'): public.ExecShell('rm -f ' + setupPath + '/panel/*.pyc');
             if os.path.exists(setupPath + '/panel/class/common.py'): public.ExecShell('rm -f ' + setupPath + '/panel/class/*.pyc');
             
             compileall.compile_dir(setupPath + '/panel');
             compileall.compile_dir(setupPath + '/panel/class');
             public.ExecShell('rm -f panel.zip');
             web.ctx.session.version = updateInfo['version']
             return public.returnMsg(True,'PANEL_UPDATE',(updateInfo['version'],));
         
         #输出新版本信息
         data = {
             'status' : True,
             'version': updateInfo['version'],
             'updateMsg' : updateInfo['updateMsg']
         };
         
         public.ExecShell('rm -rf /www/server/phpinfo/*');
         return data;
     except Exception,ex:
         return public.returnMsg(False,"CONNECT_ERR");