Ejemplo n.º 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';
    }
}
Ejemplo n.º 2
0
    }
} else {
    @date_default_timezone_set($getTimeZone);
}
//session
$cookiePath = parse_url(APP_URL, PHP_URL_PATH);
//@session_set_cookie_params(0, $cookiePath);
//@session_start();
//To prevent SQL Injection
$_REQUEST_ORIGINAL = $_REQUEST;
$_GET_ORIGINAL = $_GET;
$_POST_ORIGINAL = $_POST;
$_REQUEST = filterParameters($_REQUEST);
$_GET = filterParameters($_GET);
$_POST = filterParameters($_POST);
include_once APP_ROOT . "/controllers/processManager.php";
Reg::set('dateFormatLong', 'M d, Y @ h:ia');
Reg::set('dateFormatYearLess', 'M d @ h:ia');
clearUncompletedTask();
checkTriggerStatus();
checkBackupTasks();
checkUserLoggedInAndRedirect();
defineAppFullURL();
if (!defined('FORCED_AJAX_CALL_MIN_INTERVAL')) {
    define('FORCED_AJAX_CALL_MIN_INTERVAL', 1);
}
//need user id for checkUserLoggedInAndRedirect() so this code move top to here
if (!defined('UPDATE_PAGE')) {
    //addons //reason why it is not used in update page(update process page) is if those addons are loaded, in update process it include the latest file to run particular addon's update process by including its class, which results in fatal error of class already exists.
    loadActiveAddons();
}