示例#1
0
function executeRequest($historyID, $type = '', $action = '', $URL = '', $requestData = '', $timeout = '', $isPluginResponse = true, $callOpt = array())
{
    $responseProcessor = array();
    $responseProcessor['plugins']['install'] = $responseProcessor['themes']['install'] = 'installPluginsThemes';
    $responseProcessor['plugins']['manage'] = $responseProcessor['themes']['manage'] = 'managePluginsThemes';
    $responseProcessor['plugins']['get'] = $responseProcessor['themes']['get'] = 'getPluginsThemes';
    $responseProcessor['stats']['getStats'] = 'getStats';
    $responseProcessor['PTC']['update'] = 'updateAll';
    $responseProcessor['backup']['now'] = 'backup';
    $responseProcessor['backup']['multiCallNow'] = 'backup';
    $responseProcessor['backup']['restore'] = 'restoreBackup';
    $responseProcessor['backup']['remove'] = 'removeBackup';
    $responseProcessor['site']['add'] = 'addSite';
    $responseProcessor['site']['readd'] = 'readdSite';
    $responseProcessor['site']['maintain'] = 'iwpMaintenance';
    $responseProcessor['site']['auto_updater_settings'] = 'editSite';
    $responseProcessor['site']['remove'] = 'removeSite';
    $responseProcessor['site']['backupTest'] = 'backupTest';
    $responseProcessor['clientPlugin']['update'] = 'updateClient';
    $responseProcessor['backup']['trigger'] = 'triggerRecheck';
    $responseProcessor['cookie']['get'] = 'getCookie';
    setHook('responseProcessors', $responseProcessor);
    $historyData = getHistory($historyID);
    $actionResponse = $responseProcessor[$historyData['type']][$historyData['action']];
    if (manageClients::methodPreExists($actionResponse)) {
        manageClients::executePre($actionResponse, $historyID);
        $historyDataTemp = getHistory($historyID);
        if ($historyDataTemp['status'] != 'pending') {
            return false;
        }
        unset($historyDataTemp);
    }
    if (empty($type) || empty($action) || empty($URL) || empty($requestData)) {
        $historyRawDetails = DB::getRow("?:history_raw_details", "*", "historyID='" . $historyID . "'");
        $requestData = unserialize(base64_decode($historyRawDetails['request']));
        $historyData = getHistory($historyID);
        $type = $historyData['type'];
        $action = $historyData['action'];
        $URL = $historyData['URL'];
        $timeout = $historyData['timeout'];
        $isPluginResponse = $historyData['isPluginResponse'];
        $callOpt = @unserialize($historyData['callOpt']);
    }
    $siteID = $historyData['siteID'];
    $callOpt = buildCookie($callOpt, $siteID, $historyData);
    addNoCacheToURL($URL, $historyData);
    updateHistory(array('microtimeInitiated' => microtime(true), 'status' => 'running'), $historyID);
    $updateHistoryData = array();
    list($rawResponseData, $updateHistoryData['microtimeStarted'], $updateHistoryData['microtimeEnded'], $curlInfo, $rawResponseHeader) = doCall($URL, $requestData, $timeout, $callOpt);
    DB::update("?:history_raw_details", array('response' => addslashes($rawResponseData), 'callInfo' => serialize($curlInfo)), "historyID = '" . $historyID . "'");
    $cookie = extractCookie($rawResponseHeader);
    saveCookie($cookie, $siteID);
    $cURLErrors = new cURLErrors($curlInfo);
    if (!$cURLErrors->isOk()) {
        $updateHistoryAdditionalData = array();
        $updateHistoryAdditionalData = $cURLErrors->getErrorDetails();
        $updateHistoryData['status'] = $updateHistoryAdditionalData['status'];
        $updateHistoryData['error'] = $updateHistoryAdditionalData['error'];
        if (!isPluginResponse($rawResponseData)) {
            //sometimes 500 error with proper IWP Client Response, so if it not proper response continue set error and exit
            updateHistory($updateHistoryData, $historyID, $updateHistoryAdditionalData);
            return checkTriggerStatus();
        }
    }
    if ($isPluginResponse) {
        //$isPluginResponse is set to true then expecting result should be pluginResponse
        //$siteID = DB::getField("?:history", "siteID", "historyID='".$historyID."'"); //commented:siteID fetched from $historyData['siteID'];
        //checking response is the plugin data
        if (!isPluginResponse($rawResponseData)) {
            //Checking the timeout
            //For left menu color codes.
            if ($type == 'stats' && $action == 'getStats') {
                DB::update("?:sites", array('connectionStatus' => '0'), "siteID = '" . $siteID . "'");
            }
            $updateHistoryAdditionalData = array();
            $updateHistoryAdditionalData['status'] = $updateHistoryData['status'] = 'error';
            $updateHistoryAdditionalData['error'] = $updateHistoryData['error'] = 'main_plugin_connection_error';
            $updateHistoryAdditionalData['errorMsg'] = 'IWP Client plugin connection error.';
            updateHistory($updateHistoryData, $historyID, $updateHistoryAdditionalData);
            return checkTriggerStatus();
        } else {
            if ($type == 'stats' && $action == 'getStats') {
                DB::update("?:sites", array('connectionStatus' => '1'), "siteID = '" . $siteID . "'");
            }
        }
        removeResponseJunk($rawResponseData);
        $responseData = processCallReturn(unserialize(base64_decode($rawResponseData)));
    } else {
        $responseData = $rawResponseData;
    }
    $updateHistoryData['status'] = 'processingResponse';
    updateHistory($updateHistoryData, $historyID);
    //handling reponseData below
    if (manageClients::methodResponseExists($actionResponse)) {
        manageClients::executeResponse($actionResponse, $historyID, $responseData);
        //call_user_func('manageClients::'.$funcName, $historyID, $responseData);
        $status = "completed";
        $historyReponseStatus = Reg::get("historyResponseStatus");
        if (isset($historyReponseStatus[$historyID])) {
            $status = $historyReponseStatus[$historyID];
        }
        updateHistory(array('status' => $status), $historyID);
        return true;
    } else {
        updateHistory(array('status' => 'completed'), $historyID);
        echo '<br>no_response_processor';
        return 'no_response_processor';
    }
}
示例#2
0
global $lang, $rootpath, $usr, $absolute_server_URI, $cookie;
//prepare the templates and include all neccessary
require_once 'lib/common.inc.php';
$ocConfig = \lib\Objects\OcConfig\OcConfig::instance();
$appContainer = lib\Objects\ApplicationContainer::Instance();
require_once 'lib/cache.php';
require_once __DIR__ . '/lib/cachemap3lib.inc.php';
$_SESSION['powerTrail']['userFounds'] = $usr['userFounds'];
if ($ocConfig->getPowerTrailModuleSwitchOn() === false) {
    header("location: {$absolute_server_URI}");
}
$firePtMenu = true;
//Preprocessing
if ($error == false) {
    if (isset($_REQUEST['sortBy']) || isset($_REQUEST['filter']) || isset($_REQUEST['sortDir'])) {
        saveCookie($cookie);
    } else {
        if ($cookie->is_set("ptSrBy")) {
            $_REQUEST['sortBy'] = $cookie->get("ptSrBy");
        } else {
            $_REQUEST['sortBy'] = 'cacheCount';
        }
        if ($cookie->is_set("ptFltr")) {
            $_REQUEST['filter'] = $cookie->get("ptFltr");
        } else {
            $_REQUEST['filter'] = 0;
        }
        if ($cookie->is_set("ptSrDr")) {
            $_REQUEST['sortDir'] = $cookie->get("ptSrDr");
        } else {
            $_REQUEST['sortDir'] = 'desc';