if (!empty($responseData['success']['error'])) {
            DB::update("?:history_additional_data", array('status' => 'error', 'errorMsg' => $responseData['success']['error'], 'error' => $responseData['success']['error_code']), "historyID='" . $historyID . "'");
            return false;
        }
        $type = DB::getField("?:history", "type", "historyID='" . $historyID . "'");
        $siteID = DB::getField("?:history", "siteID", "historyID='" . $historyID . "'");
        $successUniqueName = array();
        $pluginsThemes = $responseData['success'][$type];
        if (!empty($pluginsThemes)) {
            foreach ($pluginsThemes as $name => $status) {
                if ($status == 'OK') {
                    $successUniqueName[] = $name;
                } else {
                    if (!empty($status['error'])) {
                        if ($status['error'] == 'The plugin generated unexpected output.') {
                            //This was replicated from wordpress 3.8.3
                            $successUniqueName[] = $name;
                        } else {
                            DB::update("?:history_additional_data", array('status' => 'error', 'errorMsg' => $status['error'], 'error' => $status['error_code']), "historyID='" . $historyID . "' AND uniqueName = '" . $name . "'");
                        }
                    }
                }
            }
            DB::update("?:history_additional_data", array('status' => 'success'), "historyID='" . $historyID . "' AND uniqueName IN ('" . implode("', '", $successUniqueName) . "')");
        }
        $allParams = array('action' => 'getStats', 'args' => array('siteIDs' => array($siteID), 'extras' => array('sendAfterAllLoad' => false, 'doNotShowUser' => true)));
        panelRequestManager::handler($allParams);
    }
}
manageClients::addClass('manageClientsPluginsThemes');
        $historyAdditionalData[] = array('uniqueName' => 'backupTest', 'detailedAction' => 'Backup Test');
        foreach ($siteIDs as $siteID) {
            $siteData = getSiteData($siteID);
            $PRP = array();
            $PRP['requestAction'] = $requestAction;
            $PRP['siteData'] = $siteData;
            $PRP['type'] = $type;
            $PRP['action'] = $action;
            $PRP['events'] = $events;
            $PRP['historyAdditionalData'] = $historyAdditionalData;
            $PRP['doNotExecute'] = false;
            $PRP['directExecute'] = true;
            $PRP['doNotShowUser'] = true;
            prepareRequestAndAddHistory($PRP);
        }
    }
    public static function backupTestResponseProcessor($historyID, $responseData)
    {
        responseDirectErrorHandler($historyID, $responseData);
        if (!empty($responseData['success']['error'])) {
            DB::update("?:history_additional_data", array('status' => 'error', 'errorMsg' => $responseData['error_data']), "historyID='" . $historyID . "'");
        } elseif (!empty($responseData['success'])) {
            $historyData = DB::getRow("?:history", "type, actionID, siteID", "historyID='" . $historyID . "'");
            $siteID = $historyData['siteID'];
            DB::update("?:sites", array('siteTechinicalInfo' => serialize($responseData['success']), 'infoLastUpdate' => date("Y-m-d H:i:s")), "siteID='" . $siteID . "'");
            DB::update("?:history_additional_data", array('status' => 'success'), "historyID='" . $historyID . "'");
        }
    }
}
manageClients::addClass('manageClientsSites');
            //													  'select' => 'historyID',
            //													   'where' => "parentHistoryID = ".$params['resultID']." AND status IN('completed', 'error', 'netError') ORDER BY ID DESC LIMIT 1");
            //													  /*'where' => "type IN('backup', 'scheduleBackup') AND action IN('multiCallNow, 'now', 'multiCallRunTask', 'runTask') AND status IN('success', 'error', 'netError')");*/
            //													  //'where' => "status NOT IN('multiCallWaiting')");
            //				$PRP['runCondition'] = serialize($runCondition);
            //				$PRP['status'] = 'scheduled';
            //			}
            prepareRequestAndAddHistory($PRP);
        }
    }
    public static function removeBackupResponseProcessor($historyID, $responseData)
    {
        responseDirectErrorHandler($historyID, $responseData);
        if (empty($responseData['success'])) {
            return false;
        }
        if (!empty($responseData['success']['error'])) {
            DB::update("?:history_additional_data", array('status' => 'error', 'errorMsg' => $responseData['success']['error'], 'error' => $responseData['success']['error_code']), "historyID='" . $historyID . "'");
            return;
        }
        if (!empty($responseData['success'])) {
            DB::update("?:history_additional_data", array('status' => 'success'), "historyID='" . $historyID . "'");
        }
        //---------------------------post process------------------------>
        $siteID = DB::getField("?:history", "siteID", "historyID='" . $historyID . "'");
        $allParams = array('action' => 'getStats', 'args' => array('siteIDs' => array($siteID), 'extras' => array('sendAfterAllLoad' => false, 'doNotShowUser' => true)));
        panelRequestManager::handler($allParams);
    }
}
manageClients::addClass('manageClientsBackup');
Exemple #4
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';
    }
}
 public static function getBackups($siteID, $refresh = false)
 {
     //viewBackups
     if ($refresh) {
         manageClients::getStatsProcessor(array($siteID));
     }
     $sitesStatRaw = DB::getRow("?:site_stats", "*", "stats IS NOT NULL AND siteID = '" . $siteID . "'");
     $backups = unserialize(base64_decode($sitesStat['stats']['iwp_backups']));
     return $backups;
 }
        $requestAction = 'get_cookie';
        $requestParams = array();
        $historyAdditionalData[] = array('uniqueName' => 'getCookie', 'detailedAction' => 'get');
        $PRP = array();
        $PRP['requestAction'] = $requestAction;
        $PRP['requestParams'] = $requestParams;
        $PRP['siteData'] = $siteData;
        $PRP['type'] = $type;
        $PRP['action'] = $action;
        $PRP['events'] = 1;
        $PRP['historyAdditionalData'] = $historyAdditionalData;
        $PRP['doNotExecute'] = false;
        $PRP['directExecute'] = true;
        $PRP['sendAfterAllLoad'] = false;
        $PRP['exitOnComplete'] = false;
        $PRP['doNotShowUser'] = true;
        $historyID = prepareRequestAndAddHistory($PRP);
        return $historyID;
    }
    public static function getCookieResponseProcessor($historyID, $responseData)
    {
        responseDirectErrorHandler($historyID, $responseData);
        if (!empty($responseData) && is_array($responseData) && $responseData['success'] === true) {
            DB::update("?:history_additional_data", array('status' => 'success'), "historyID='" . $historyID . "' AND uniqueName = 'getCookie'");
        } else {
            DB::update("?:history_additional_data", array('status' => 'error', 'errorMsg' => 'An Unknown error occurred.', 'error' => 'unknown_error_while_getcookie'), "historyID='" . $historyID . "' AND uniqueName = 'getCookie'");
        }
    }
}
manageClients::addClass('manageClientsFetch');
                $PRP['requestParams'] = $requestParams;
                $PRP['siteData'] = $siteData;
                $PRP['type'] = $type;
                $PRP['action'] = $action;
                $PRP['events'] = $events;
                $PRP['historyAdditionalData'] = $historyAdditionalData;
                $PRP['sendAfterAllLoad'] = true;
                prepareRequestAndAddHistory($PRP);
            }
        }
    }
    public static function updateClientResponseProcessor($historyID, $responseData)
    {
        responseDirectErrorHandler($historyID, $responseData);
        if (empty($responseData['success'])) {
            return false;
        }
        foreach ($responseData['success'] as $key => $value) {
            DB::update("?:history_additional_data", array('status' => $key, 'errorMsg' => $value), "historyID='" . $historyID . "' AND uniqueName = 'clientPlugin'");
            if ($key == 'success') {
                //---------------------------callback process------------------------>
                $siteID = DB::getField("?:history", "siteID", "historyID='" . $historyID . "'");
                // 'directExecute'=>true for client plugin update notification
                $allParams = array('action' => 'getStats', 'args' => array('siteIDs' => array($siteID), 'extras' => array('sendAfterAllLoad' => false, 'directExecute' => true, 'doNotShowUser' => true)));
                panelRequestManager::handler($allParams);
            }
        }
    }
}
manageClients::addClass('manageClientsUpdate');