Exemplo n.º 1
0
 public static function managePluginsThemesResponseProcessor($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 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);
 }
Exemplo n.º 2
0
 public static function readdSiteResponseProcessor($historyID, $responseData)
 {
     responseDirectErrorHandler($historyID, $responseData);
     if (empty($responseData['success'])) {
         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']['oldSite']['readdSitePrivateKey'];
         $isOpenSSLActive = '1';
         if ($responseData['success']['no_openssl']) {
             $privateKey = NULL;
             $isOpenSSLActive = '0';
         }
         $URLParts = explode('/', $responseData['success']['site_home']);
         $siteData = array("privateKey" => $privateKey, "randomSignature" => $responseData['success']['no_openssl']);
         $siteID = DB::getField("?:history", "siteID", "historyID = '" . $historyID . "'");
         DB::update("?:sites", $siteData, "siteID = '" . $siteID . "'");
         DB::replace("?:user_access", array('userID' => $GLOBALS['userID'], 'siteID' => $siteID));
         unset($GLOBALS['storage']['oldSite']);
         //---------------------------post process------------------------>
         $allParams = array('action' => 'getStats', 'args' => array('siteIDs' => array($siteID), 'extras' => array('directExecute' => true, 'doNotShowUser' => true)));
         panelRequestManager::handler($allParams);
         setHook('postReaddSite', $siteID);
         //check this once
     }
 }
Exemplo n.º 3
0
function deactivateAddons($addons)
{
    foreach ($addons as $key => $addon) {
        $isExist = DB::getField("?:addons", "slug", "slug='" . $addon['slug'] . "'");
        if (!$isExist) {
            $addons[$key]['deactivate'] = false;
            addNotification($type = 'E', $title = 'Addon deactivation failed', $message = 'The ' . $addon['slug'] . ' addon does not exist in the database.', $state = 'U', $callbackOnClose = '', $callbackReference = '');
            continue;
        }
        if (file_exists(APP_ROOT . '/addons/' . $addon['slug'] . '/addon.' . $addon['slug'] . '.php')) {
            //activating the addon
            $isDone = DB::update("?:addons", array('status' => 'inactive'), "slug = '" . $addon['slug'] . "'");
            if ($isDone) {
                $addons[$key]['deactivate'] = true;
                $success[$addon['slug']] = DB::getField("?:addons", "addon", "slug = '" . $addon['slug'] . "'");
                include_once APP_ROOT . '/addons/' . $addon['slug'] . '/addon.' . $addon['slug'] . '.php';
                if (method_exists('addon' . ucfirst($addon['slug']), 'deactivate')) {
                    call_user_func(array('addon' . ucfirst($addon['slug']), 'deactivate'));
                }
            }
        } else {
            $addons[$key]['deactivate'] = false;
            addNotification($type = 'E', $title = 'Addon deactivation failed', $message = 'A file was found missing while deactivating the ' . $addon['slug'] . ' addon.', $state = 'U', $callbackOnClose = '', $callbackReference = '');
        }
    }
    if (!empty($success)) {
        addNotification($type = 'N', $title = 'Addon has been deactivated', $message = implode('<br>', $success), $state = 'U', $callbackOnClose = '', $callbackReference = '');
    }
    return $addons;
}
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 function getReaddedSite()
 {
     $actionID = Reg::get('currentRequest.actionID');
     $data = DB::getRow("?:history", "siteID,historyID", "actionID = '" . $actionID . "'");
     $siteID = $data['siteID'];
     $historyID = $data['historyID'];
     $status = DB::getField("?:history_additional_data", "status", "historyID = '" . $historyID . "'");
     if ($status == 'success') {
         return array('siteID' => $siteID);
     } else {
         return false;
     }
 }
Exemplo n.º 6
0
 /**
  *
  * Возвращает кол-во рядов попадающих под запрос
  * @param string $table    имя таблицы
  * @param array $condition условие запроса
  */
 public static function getRowsCount($table, $condition = array())
 {
     $condition = self::getCondition($condition);
     $sql = 'select count(*) as `count` from %s where %s';
     $sql = sprintf($sql, DB::$connection->real_escape_string($table), $condition);
     return intval(DB::getField($sql, 'count'));
 }
Exemplo n.º 7
0
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);
}
Exemplo n.º 8
0
include_once APP_ROOT . "/includes/manageCookies.php";
include_once APP_ROOT . "/controllers/appFunctions.php";
include_once APP_ROOT . "/controllers/manageClients.php";
include_once APP_ROOT . "/controllers/panelRequestManager.php";
include_once APP_ROOT . "/controllers/TPLFunctions.php";
include_once APP_ROOT . "/controllers/manageEasyCron.php";
//Static Data
include_once APP_ROOT . "/includes/httpErrorCodes.php";
define('APP_PHP_CRON_CMD', 'php -q -d safe_mode=Off ');
Reg::set('config', $config);
unset($config);
Reg::set('hooks', array());
//DB connection starts here
DBConnectAndSetOptions();
if (defined('USER_SESSION_NOT_REQUIRED')) {
    $userID = DB::getField("?:users", "userID", "accessLevel = 'admin' ORDER BY userID ASC LIMIT 1");
    if (empty($userID)) {
        return false;
    }
    $GLOBALS['userID'] = $userID;
    $GLOBALS['offline'] = true;
}
$settings = DB::getRow("?:settings", "*", 1);
Reg::set('settings', unserialize($settings['general']));
$settings = Reg::get('settings');
$enableHTTPS = intval($settings['enableHTTPS']);
define('APP_HTTPS', $enableHTTPS);
//1 => HTTPS on, 0 => HTTPS off
$APP_URL = 'http' . (APP_HTTPS == 1 ? 's' : '') . '://' . rtrim(APP_DOMAIN_PATH, "/") . "/";
define('APP_URL', $APP_URL);
define('IWP_SITE_URL', getOption('IWPSiteURL'));
Exemplo n.º 9
0
}
set_time_limit(3600);
//3600 = 1hr, this is only for safety, we are controlling timeout in CURL
if ($_REQUEST['runOffBrowserLoad'] == 'true') {
    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();
Exemplo n.º 10
0
 public static function getStatsResponseProcessor($historyID, $responseData)
 {
     responseDirectErrorHandler($historyID, $responseData);
     $siteID = DB::getField("?:history", "siteID", "historyID='" . $historyID . "'");
     if (empty($siteID)) {
         return false;
     }
     if (empty($responseData['success'])) {
         //For left site color code
         DB::update("?:sites", array('connectionStatus' => '0'), "siteID = '" . $siteID . "'");
     } else {
         DB::update("?:sites", array('connectionStatus' => '1'), "siteID = '" . $siteID . "'");
     }
     if (empty($responseData['success'])) {
         return false;
     }
     self::backupStatusCheck($responseData);
     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;
     }
     DB::update("?:history_additional_data", array('status' => 'success'), "historyID='" . $historyID . "' AND uniqueName = 'getStats'");
     $siteStatsData = array();
     $siteStatsData['siteID'] = $siteID;
     $siteStatsData['stats'] = base64_encode(serialize($responseData['success']));
     $siteStatsData['lastUpdatedTime'] = time();
     DB::replace("?:site_stats", $siteStatsData);
     $callOpt = false;
     if ($responseData['success']['use_cookie'] == 1) {
         $callOpt = DB::getField("?:sites", "callOpt", "siteID = '" . $siteID . "'");
         if (!empty($callOpt)) {
             $callOpt = unserialize($callOpt);
         } else {
             $callOpt = array();
         }
         $callOpt['useCookie'] = 1;
         $callOpt = serialize($callOpt);
     }
     if (!empty($responseData['success']['wordpress_version']) && !empty($responseData['success']['client_version'])) {
         $updateSiteData = array("WPVersion" => $responseData['success']['wordpress_version'], "pluginVersion" => $responseData['success']['client_version']);
         if (!empty($callOpt)) {
             $updateSiteData['callOpt'] = $callOpt;
         }
         DB::update("?:sites", $updateSiteData, "siteID = '" . $siteID . "'");
     }
 }
Exemplo n.º 11
0
 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);
         }
     }
 }