Esempio n. 1
0
def checkPHPVersion(version):
    try:
        uri = "/phpfpm_" + version + "_status?json"
        result = public.request_php(version, uri, '')
        loads(result)
        return True
    except:
        logging.info("PHP-{} unreachable detected".format(version))
        return False
Esempio n. 2
0
 def GetPHPInfo(self, get):
     sPath = '/www/server/phpinfo'
     if os.path.exists(sPath):
         public.ExecShell("rm -rf " + sPath)
     p_file = '/dev/shm/phpinfo.php'
     public.writeFile(p_file, '<?php phpinfo(); ?>')
     phpinfo = public.request_php(get.version, '/phpinfo.php', p_file, '')
     if os.path.exists(p_file): os.remove(p_file)
     return phpinfo
Esempio n. 3
0
def checkPHPVersion(version):
    try:
        cgi_file = '/tmp/php-cgi-{}.sock'.format(version)
        if os.path.exists(cgi_file):
            uri = "/phpfpm_" + version + "_status?json"
            result = public.request_php(version, uri, '')
            loads(result)
        return True
    except:
        logging.info("PHP-{} unreachable detected".format(version))
        return False
Esempio n. 4
0
    def _post_php(self, url, data, timeout, headers, verify):
        php_version = self._get_php_version()
        if not php_version:
            raise Exception('没有可用的PHP版本!')
        tmp_file = '/dev/shm/http.php'
        http_php = '''<?php
if(isset($_POST['data'])){
    $data = json_decode($_POST['data'],1);
}else{
    $data = json_decode(getopt('',array('post:'))['post'],1);
}
$url  = $data['url'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER,$data['headers']);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data['data']));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $data['verify']);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $data['verify']);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $data['timeout']);
curl_setopt($ch, CURLOPT_TIMEOUT, $data['timeout']);
curl_setopt($ch, CURLOPT_POST, true);
$result = curl_exec($ch);
$h_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($result, 0, $h_size);
$body = substr($result,$h_size,strlen($result));
curl_close($ch);
exit($header."\r\n\r\n".json_encode($body));
?>'''
        public.writeFile(tmp_file, http_php)
        #if 'Content-Type' in headers:
        #    if headers['Content-Type'].find('application/json') != -1:
        #        data = json.dumps(pdata)

        data = json.dumps({
            "url": url,
            "timeout": timeout,
            "verify": verify,
            "headers": self._php_headers(headers),
            "data": data
        })
        if php_version.find('/www/server/php') != -1:
            result = public.ExecShell(php_version + ' ' + tmp_file +
                                      " --post='" + data + "'")[0]
        else:
            result = public.request_php(php_version, '/http.php', tmp_file, '',
                                        'POST', {"data": data})

        if os.path.exists(tmp_file): os.remove(tmp_file)
        r_body, r_headers, r_status_code = self._curl_format(result)
        return response(json.loads(r_body), r_status_code, r_headers)
Esempio n. 5
0
 def GetPHPInfo(self,get):
     if public.get_webserver() == "openlitespeed":
         shell_str = "/usr/local/lsws/lsphp{}/bin/php -i".format(get.version)
         return public.ExecShell(shell_str)[0]
     sPath = '/www/server/phpinfo'
     if os.path.exists(sPath):
         public.ExecShell("rm -rf " + sPath)
     p_file = '/dev/shm/phpinfo.php'
     public.writeFile(p_file,'<?php phpinfo(); ?>')
     phpinfo = public.request_php(get.version,'/phpinfo.php',p_file,'')
     if os.path.exists(p_file): os.remove(p_file)
     return phpinfo.decode();
Esempio n. 6
0
 def GetPHPStatus(self, get):
     #取指定PHP版本的负载状态
     try:
         version = get.version
         uri = "/phpfpm_" + version + "_status"
         result = public.request_php(version, uri, uri, 'json')
         tmp = json.loads(result)
         fTime = time.localtime(int(tmp['start time']))
         tmp['start time'] = time.strftime('%Y-%m-%d %H:%M:%S', fTime)
         return tmp
     except Exception as ex:
         public.WriteLog('信息获取', "PHP负载状态获取失败: %s" % ex)
         return public.returnMsg(False, '负载状态获取失败!')
Esempio n. 7
0
 def GetPHPStatus(self,get):
     #取指定PHP版本的负载状态
     try:
         version = get.version
         uri = "/phpfpm_"+version+"_status?json"
         result = public.request_php(version,uri,'')
         tmp = json.loads(result)
         fTime = time.localtime(int(tmp['start time']))
         tmp['start time'] = time.strftime('%Y-%m-%d %H:%M:%S',fTime)
         return tmp
     except Exception as ex:
         public.WriteLog('GET_INFO',"PHP_LOAD_ERR",(public.get_error_info(),))
         return public.returnMsg(False,'PHP_LOAD_ERR1')