<?php require_once 'config.php'; require_once 'routes.php'; session_start(); $parsedRequest = parseRequest(); executeRequest($parsedRequest);
public static function addSiteResponseProcessor($historyID, $responseData) { responseDirectErrorHandler($historyID, $responseData); if (empty($responseData['success'])) { if (!empty($GLOBALS['storage']['newSite']['advancedCUCT']) && $GLOBALS['storage']['newSite']['advancedCUCT'] < 6) { $GLOBALS['storage']['newSite']['advancedCUCT'] += 1; $advCUCT = $GLOBALS['storage']['newSite']['advancedCUCT']; if ($advCUCT == 1) { $GLOBALS['storage']['newSite']['callOpt']['contentType'] = ''; $GLOBALS['storage']['newSite']['connectURL'] = 'default'; } else { if ($advCUCT == 2) { $GLOBALS['storage']['newSite']['callOpt']['contentType'] = ''; $GLOBALS['storage']['newSite']['connectURL'] = 'siteURL'; } else { if ($advCUCT == 3) { $GLOBALS['storage']['newSite']['callOpt']['contentType'] = 'multipart/form-data'; $GLOBALS['storage']['newSite']['connectURL'] = 'default'; } else { if ($advCUCT == 4) { $GLOBALS['storage']['newSite']['callOpt']['contentType'] = 'multipart/form-data'; $GLOBALS['storage']['newSite']['connectURL'] = 'siteURL'; } else { if ($advCUCT == 5) { $GLOBALS['storage']['newSite']['callOpt']['contentType'] = 'text/plain'; $GLOBALS['storage']['newSite']['connectURL'] = 'default'; } else { if ($advCUCT == 6) { $GLOBALS['storage']['newSite']['callOpt']['contentType'] = 'text/plain'; $GLOBALS['storage']['newSite']['connectURL'] = 'siteURL'; } } } } } } $callOpt = $GLOBALS['storage']['newSite']['callOpt']; $requestData = $GLOBALS['storage']['newSite']['requestData']; $siteURL = $requestData['params']['site_url']; return executeRequest($historyID, 'site', 'add', $siteURL, $requestData, $timeout, true, $callOpt); } else { return false; } } if (!empty($responseData['success']['error'])) { //There is no variable "$responseData['error_data']" exists in plugin. especially, in add_site task. Error wont come in success array ... DB::update("?:history_additional_data", array('status' => 'error', 'errorMsg' => $responseData['success']['error'], 'error' => $responseData['success']['error_code']), "historyID='" . $historyID . "'"); } elseif (!empty($responseData['success'])) { DB::update("?:history_additional_data", array('status' => 'success'), "historyID='" . $historyID . "'"); $privateKey = $GLOBALS['storage']['newSite']['addSitePrivateKey']; $isOpenSSLActive = '1'; if ($responseData['success']['no_openssl']) { $privateKey = NULL; $isOpenSSLActive = '0'; } $URLParts = explode('/', $responseData['success']['site_home']); $siteData = array("URL" => $responseData['success']['site_home'] . '/', "adminURL" => $responseData['success']['admin_url'], "name" => str_replace(array('http://www.', 'https://www.', 'http://', 'https://'), '', $responseData['success']['site_home']), "privateKey" => $privateKey, "adminUsername" => $GLOBALS['storage']['newSite']['addSiteAdminUsername'], "isOpenSSLActive" => $isOpenSSLActive, "randomSignature" => $responseData['success']['no_openssl'], "WPVersion" => $responseData['success']['wordpress_version'], "pluginVersion" => $responseData['success']['worker_version'], "IP" => gethostbyname($URLParts[2]), "network" => $responseData['success']['network_install'] == -1 ? 1 : 0, "multisiteID" => empty($responseData['success']['wp_multisite']) ? 0 : $responseData['success']['wp_multisite'], "parent" => $responseData['success']['site_home'] == $responseData['success']['network_parent'] ? 1 : 0, "connectURL" => $GLOBALS['storage']['newSite']['connectURL']); // save data if (!empty($GLOBALS['storage']['newSite']['httpAuth']['username'])) { $siteData['httpAuth']['username'] = $GLOBALS['storage']['newSite']['httpAuth']['username']; $siteData['httpAuth']['password'] = $GLOBALS['storage']['newSite']['httpAuth']['password']; $siteData['httpAuth'] = @serialize($siteData['httpAuth']); } if (!empty($GLOBALS['storage']['newSite']['callOpt']) || $responseData['success']['use_cookie'] == 1) { $callOpt = array(); if ($responseData['success']['use_cookie'] == 1) { $callOpt['useCookie'] = 1; } if (!empty($GLOBALS['storage']['newSite']['callOpt'])) { $callOpt = array_merge($callOpt, $GLOBALS['storage']['newSite']['callOpt']); } $siteData['callOpt'] = @serialize($callOpt); } $siteID = DB::insert('?:sites', $siteData); DB::replace("?:user_access", array('userID' => $GLOBALS['userID'], 'siteID' => $siteID)); $groupsPlainText = $GLOBALS['storage']['newSite']['groupsPlainText']; $groupIDs = $GLOBALS['storage']['newSite']['groupIDs']; $managerIDs = $GLOBALS['storage']['newSite']['managerID']; if (isset($managerIDs) && !empty($managerIDs)) { foreach ($managerIDs as $key => $managerID) { DB::replace("?:user_access", array('userID' => $managerID, 'siteID' => $siteID)); } } panelRequestManager::addSiteSetGroups($siteID, $groupsPlainText, $groupIDs); unset($GLOBALS['storage']['newSite']); //---------------------------post process------------------------> $allParams = array('action' => 'getStats', 'args' => array('siteIDs' => array($siteID), 'extras' => array('directExecute' => true, 'doNotShowUser' => true))); panelRequestManager::handler($allParams); setHook('postAddSite', $siteID); } }
if ($element->getName() == 'multirequest') { $client->startMultiRequest(); foreach ($element->request as $request) { executeRequest($client, $request); } echo "Executing multirequest\n"; $multiResponse = $client->doMultiRequest(); foreach ($multiResponse as $index => $response) { if ($client->isError($response)) { echo "Executing failed for request #" . ($index + 1) . " with error [" . $response['message'] . "]\n"; throw new KalturaException($response["message"], $response["code"]); } $results[] = $response; } } elseif ($element->getName() == 'request') { $results[] = executeRequest($client, $element); } } /* -------- Generate output XML -------- */ function appandObject(SimpleXMLElement $outXml, $object, $name) { $objectXml = null; $type = gettype($object); if ($type == 'array') { $objectXml = $outXml->addChild($name); $objectXml->addAttribute('objectType', 'array'); foreach ($object as $arrayItem) { appandObject($objectXml, $arrayItem, 'item'); } } elseif ($type == 'object') { $objectXml = $outXml->addChild($name);
function prepareRequestAndAddHistory($PRP) { $defaultPRP = array('doNotExecute' => false, 'exitOnComplete' => false, 'doNotShowUser' => false, 'directExecute' => false, 'signature' => false, 'timeout' => DEFAULT_MAX_CLIENT_REQUEST_TIMEOUT, 'runCondition' => false, 'status' => 'pending', 'isPluginResponse' => 1, 'sendAfterAllLoad' => false, 'callOpt' => array()); $PRP = array_merge($defaultPRP, $PRP); @extract($PRP); if (empty($historyAdditionalData)) { echo 'noHistoryAdditionalData'; return false; } if ($siteData['connectURL'] == 'default' && defined('CONNECT_USING_SITE_URL') && CONNECT_USING_SITE_URL == 1 || $siteData['connectURL'] == 'siteURL') { $URL = $siteData['URL']; } else { //if($siteData['connectURL'] == 'default' || $siteData['connectURL'] == 'adminURL') $URL = $siteData['adminURL']; } $historyData = array('siteID' => $siteData['siteID'], 'actionID' => Reg::get('currentRequest.actionID'), 'userID' => $GLOBALS['userID'], 'type' => $type, 'action' => $action, 'events' => $events, 'URL' => $URL, 'timeout' => $timeout, 'isPluginResponse' => $isPluginResponse); if ($doNotShowUser) { $historyData['showUser'] = '******'; } if ($parentHistoryID) { $historyData['parentHistoryID'] = $parentHistoryID; } if (!empty($siteData['callOpt'])) { $callOpt = @unserialize($siteData['callOpt']); } if (!empty($siteData['httpAuth'])) { $callOpt['httpAuth'] = @unserialize($siteData['httpAuth']); } if (!empty($runCondition)) { $historyData['runCondition'] = $runCondition; } if (!empty($timeScheduled)) { $historyData['timeScheduled'] = $timeScheduled; } $historyData['callOpt'] = serialize($callOpt); $historyID = addHistory($historyData, $historyAdditionalData); if ($signature === false) { $signature = signData($requestAction . $historyID, $siteData['isOpenSSLActive'], $siteData['privateKey'], $siteData['randomSignature']); } $requestParams['username'] = $siteData['adminUsername']; if (isset($requestParams['secure'])) { $requestParams['secure'] = secureData($requestParams['secure'], $siteData['isOpenSSLActive'], $siteData['privateKey'], $siteData['randomSignature']); } if (!empty($requestParams['args'])) { $requestParams['args']['parentHID'] = $historyID; } $requestData = array('iwp_action' => $requestAction, 'params' => $requestParams, 'id' => $historyID, 'signature' => $signature, 'iwp_admin_version' => APP_VERSION); $updateHistoryData = array('status' => $status); updateHistory($updateHistoryData, $historyID); DB::insert("?:history_raw_details", array('historyID' => $historyID, 'request' => base64_encode(serialize($requestData)), 'panelRequest' => serialize($_REQUEST))); if ($directExecute) { set_time_limit(0); echo 'direct_execute<br />'; executeRequest($historyID, $type, $action, $siteData['URL'], $requestData, $timeout, true, $callOpt); } else { echo 'async_call_it_should_be<br />'; if ($exitOnComplete) { set_time_limit(0); echo "async_call_it_should_be_working"; Reg::set('currentRequest.exitOnComplete', true); } elseif ($sendAfterAllLoad) { Reg::set('currentRequest.sendAfterAllLoad', true); } } return $historyID; }
function executeJobs() { if (isset($GLOBALS['IS_EXECUTE_JOBS_OPEN']) && $GLOBALS['IS_EXECUTE_JOBS_OPEN']) { echo 'recurrsive execute jobs call'; return false; //recurrsive call } $GLOBALS['IS_EXECUTE_JOBS_OPEN'] = true; $settings = Reg::get('settings'); $noRequestRunning = true; $requestInitiated = 0; $requestPending = 0; $isExecuteRequest = false; static $lastIPRequestInitiated = ''; $totalCurrentRunningRequest = DB::getField("?:history H LEFT JOIN ?:sites S ON H.siteID = S.siteID", "COUNT(H.historyID)", "H.status IN ('initiated', 'running')"); if ($totalCurrentRunningRequest >= MAX_SIMULTANEOUS_REQUEST) { echo 'MAX_SIMULTANEOUS_REQUEST'; $GLOBALS['IS_EXECUTE_JOBS_OPEN'] = false; return false; } //dont execute any request $runningRequestByIP = DB::getFields("?:history H LEFT JOIN ?:sites S ON H.siteID = S.siteID", "COUNT(H.historyID), S.IP", "H.status IN ('initiated', 'running') AND H.isPluginResponse = '1' GROUP BY S.IP", "IP"); //H.isPluginResponse = 1 only WP sites call if (!empty($runningRequestByIP)) { //some request(s) are running $noRequestRunning = false; $runningRequestByServer = DB::getFields("?:history H LEFT JOIN ?:sites S ON H.siteID = S.siteID", "COUNT(H.historyID), S.serverGroup", "H.status IN ('initiated', 'running') GROUP BY S.serverGroup", "serverGroup"); } //get pending request $pendingRequests = DB::getArray("?:history H LEFT JOIN ?:sites S ON H.siteID = S.siteID", "H.historyID, S.IP, S.serverGroup, H.actionID, H.runCondition, H.isPluginResponse", "(H.status = 'pending' OR (H.status = 'scheduled' AND H.timescheduled <= " . time() . " AND H.timescheduled > 0)) ORDER BY H.historyID"); if ($noRequestRunning) { $runningRequestByIP = array(); $runningRequestByServer = array(); } if (!empty($runningRequestByIP) && $settings['CONSIDER_3PART_IP_ON_SAME_SERVER'] == 1) { //running IP information $tempRunningRequestByIP = $runningRequestByIP; $runningRequestByIP = array(); foreach ($tempRunningRequestByIP as $tempIP => $tempCount) { //only for IPv4 $IP3Part = explode('.', $tempIP); array_pop($IP3Part); $newTempIP = implode('.', $IP3Part); $runningRequestByIP[$newTempIP] = $tempCount; } } if (!empty($pendingRequests) && is_array($pendingRequests)) { foreach ($pendingRequests as $request) { $checkIPRestriction = true; $IPConsidered = $request['IP']; if ($request['isPluginResponse'] === '0') { $request['IP'] = ''; $checkIPRestriction = false; } if ($checkIPRestriction && $settings['CONSIDER_3PART_IP_ON_SAME_SERVER'] == 1) { //only for IPv4 $IP3Part = explode('.', $IPConsidered); array_pop($IP3Part); $IP3Part = implode('.', $IP3Part); $IPConsidered = $IP3Part; } if (!empty($request['runCondition']) && !isTaskRunConditionSatisfied($request['runCondition'])) { continue; } if ($checkIPRestriction && !isset($runningRequestByIP[$IPConsidered])) { $runningRequestByIP[$IPConsidered] = 0; } // if(!isset($runningRequestByServer[ $request['serverGroup'] ])) $runningRequestByServer[ $request['serverGroup'] ] = 0; if ($totalCurrentRunningRequest >= MAX_SIMULTANEOUS_REQUEST) { echo 'MAX_SIMULTANEOUS_REQUEST'; $GLOBALS['IS_EXECUTE_JOBS_OPEN'] = false; return false; } //check already request are running in allowed level if ($checkIPRestriction && $runningRequestByIP[$IPConsidered] >= MAX_SIMULTANEOUS_REQUEST_PER_IP) { if ($runningRequestByIP[$IPConsidered] >= MAX_SIMULTANEOUS_REQUEST_PER_IP) { echo 'MAX_SIMULTANEOUS_REQUEST_PER_IP<br>'; } /* if($runningRequestByServer[ $request['serverGroup'] ] >= MAX_SIMULTANEOUS_REQUEST_PER_SERVERGROUP) echo 'MAX_SIMULTANEOUS_REQUEST_PER_SERVERGROUP<br>';*/ continue; //already request are running on the limits } $updateRequest = array('H.status' => 'initiated', 'H.microtimeInitiated' => microtime(true)); $isUpdated = DB::update("?:history H", $updateRequest, "(H.status = 'pending' OR (H.status = 'scheduled' AND H.timescheduled <= " . time() . " AND H.timescheduled > 0)) AND H.historyID = " . $request['historyID']); $isUpdated = DB::affectedRows(); if ($isUpdated) { //ready to run a child php to run the request if ($lastIPRequestInitiated == $IPConsidered) { usleep(TIME_DELAY_BETWEEN_REQUEST_PER_IP * 1000); } //(defined('CRON_MODE') && ( CRON_MODE == 'systemCronShortTime' || CRON_MODE == 'systemCronDefault') ) //need to avoid balance idle time when systemCron is triggered. so that new trigger call(multiCall) can be called soon // echo '<br>executing child process'; if (defined('IS_EXECUTE_FILE') || defined('CRON_MODE') && (CRON_MODE == 'systemCronShortTime' || CRON_MODE == 'systemCronDefault') || $settings['executeUsingBrowser'] == 1) { //this will also statisfy Reg::get('settings.executeUsingBrowser') == 1 //echo '<br>executing_directly'; executeRequest($request['historyID']); $isExecuteRequest = true; $requestPending++; } else { // echo '<br>executing_async'; $callAsyncInfo = callURLAsync(APP_URL . EXECUTE_FILE, array('historyID' => $request['historyID'], 'actionID' => $request['actionID'])); onAsyncFailUpdate($request['historyID'], $callAsyncInfo); // echo '<pre>callExecuted:'; var_dump($callAsyncInfo); echo'</pre>'; } $requestInitiated++; if ($checkIPRestriction) { $runningRequestByIP[$IPConsidered]++; } // $runningRequestByServer[ $request['serverGroup'] ] ++; $totalCurrentRunningRequest++; if ($checkIPRestriction) { $lastIPRequestInitiated = $IPConsidered; } if ($isExecuteRequest) { break; } //breaking here once executeRequest runs(direct call) next forloop job might be executed by other instance because that job loaded in array which already loaded from DB, still only the job inititated here will run $isUpdated = DB::affectedRows(); } else { echo 'update error, this request might be executed by someother instance.'; } } } //return process $GLOBALS['IS_EXECUTE_JOBS_OPEN'] = false; return array('requestInitiated' => $requestInitiated, 'requestPending' => $requestPending); }
runOffBrowserLoad(); exit; } elseif (!empty($_POST['historyID']) && !empty($_POST['actionID'])) { $historyID = $_POST['historyID']; $actionID = $_POST['actionID']; //if(empty($historyID) || empty($actionID)){ echo 'invalidRequest'; exit; } //fix: add some security $isValid = DB::getExists("?:history", "historyID", "historyID = '" . $historyID . "' AND actionID = '" . $actionID . "'"); if ($isValid) { if (empty($GLOBALS['userID'])) { //setting userID of the task to session, because when this file running by fsock, it will not have the same session IWP Admin Panel $userID = DB::getField("?:history", "userID", "historyID = '" . $historyID . "' AND actionID = '" . $actionID . "'"); $GLOBALS['userID'] = $userID; $GLOBALS['offline'] = true; } echo 'executingRequest'; executeRequest($historyID); $isExecuteJobs = true; } } if ($isExecuteJobs || $_REQUEST['executeJobs'] == 'true') { $noNewTaskAfterNSecs = 25; //do additional jobs if ($GLOBALS['executeFileTimeStart'] + $noNewTaskAfterNSecs > time()) { do { autoPrintToKeepAlive("keepAliveExecuteJobs"); $status = executeJobs(); } while ($status['requestInitiated'] > 0 && $status['requestPending'] > 0 && $GLOBALS['executeFileTimeStart'] + $noNewTaskAfterNSecs > time()); } exit; }