Esempio n. 1
0
 /**
  * activates the script function.
  *
  * @return void
  * @access public
  */
 function activate()
 {
     parent::activate();
     if ($_SERVER['argv']['1'] == '-s' && SensitiveIO::isPositiveInteger($_SERVER['argv']['2'])) {
         // SUB-SCRIPT : Processes one script task
         @ini_set('max_execution_time', SUB_SCRIPT_TIME_OUT);
         //set max execution time for sub script
         @set_time_limit(SUB_SCRIPT_TIME_OUT);
         //set the PHP timeout for sub script
         $sql = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\twhere\n\t\t\t\t\tid_reg = '" . $_SERVER['argv']['2'] . "'\n\t\t\t";
         $q = new CMS_query($sql);
         if ($q->getNumRows()) {
             $data = $q->getArray();
             //send script informations to process manager
             $this->_processManager->setParameters($data['module_reg'], $data['parameters_reg']);
             //instanciate script module
             $module = CMS_modulesCatalog::getByCodename($data['module_reg']);
             //then send script task to module (return task title by reference)
             $task = $module->scriptTask(unserialize($data['parameters_reg']));
             //delete the current script task
             $sql_delete = "\n\t\t\t\t\tdelete\n\t\t\t\t\tfrom\n\t\t\t\t\t\tregenerator\n\t\t\t\t\twhere\n\t\t\t\t\t\tid_reg='" . $data['id_reg'] . "'";
             $q = new CMS_query($sql_delete);
             if ($this->_debug) {
                 $this->raiseError($this->_processManager->getPIDFilePath() . " : task " . $_SERVER['argv']['2'] . " seems " . (!$task ? 'NOT ' : '') . "done !");
                 $this->raiseError($this->_processManager->getPIDFilePath() . " : PID file exists ? " . @file_exists($this->_processManager->getPIDFilePath()));
             }
             $fpath = $this->_processManager->getPIDFilePath() . '.ok';
             if (@touch($fpath) && @chmod($fpath, octdec(FILES_CHMOD))) {
                 $f = @fopen($fpath, 'a');
                 if (!@fwrite($f, 'Script OK')) {
                     $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't write into file: " . $fpath);
                 }
                 @fclose($f);
             } else {
                 $this->raiseError($this->_processManager->getPIDFilePath() . " : Can't create file: " . $fpath);
             }
         }
     } else {
         // MASTER SCRIPT : Processes all sub-scripts
         @ini_set('max_execution_time', MASTER_SCRIPT_TIME_OUT);
         //set max execution time for master script
         @set_time_limit(MASTER_SCRIPT_TIME_OUT);
         //set the PHP timeout  for master script
         //max simultaneous scripts
         $maxScripts = $_SERVER['argv']['2'];
         $scriptsArray = array();
         //send script informations to process manager
         $this->_processManager->setParameters(processManager::MASTER_SCRIPT_NAME, '');
         //the sql script which selects one script task at a time
         $sql_select = "\n\t\t\t\tselect\n\t\t\t\t\t*\n\t\t\t\tfrom\n\t\t\t\t\tregenerator\n\t\t\t\tlimit\n\t\t\t\t\t" . $maxScripts . "\n\t\t\t";
         //and now, launch all sub-scripts until table is empty.
         while (true) {
             //get scripts
             $q = new CMS_query($sql_select);
             if ($q->getNumRows()) {
                 while (count($scriptsArray) < $maxScripts && ($data = $q->getArray())) {
                     // Launch sub-process
                     if (!APPLICATION_IS_WINDOWS) {
                         // On unix system
                         $sub_system = PATH_PACKAGES_FS . "/scripts/script.php -s " . $data["id_reg"] . " > /dev/null 2>&1 &";
                         if (!defined('PATH_PHP_CLI_UNIX') || !PATH_PHP_CLI_UNIX) {
                             CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; php " . $sub_system, $error);
                             if ($error) {
                                 CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; php ' . $sub_system . '), please check your configuration : ' . $error);
                                 return false;
                             }
                         } else {
                             CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; " . PATH_PHP_CLI_UNIX . " " . $sub_system, $error);
                             if ($error) {
                                 CMS_grandFather::raiseError('Error during execution of sub script command (cd ' . PATH_REALROOT_FS . '; ' . PATH_PHP_CLI_UNIX . ' ' . $sub_system . '), please check your configuration : ' . $error);
                                 return false;
                             }
                         }
                         $PIDfile = $this->_processManager->getTempPath() . "/" . SCRIPT_CODENAME . "_" . $data["id_reg"];
                         if ($this->_debug) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Executes system(" . $sub_system . ")");
                         }
                         //sleep a little
                         @sleep(SLEEP_TIME);
                     } else {
                         // On windows system
                         //Create the BAT file
                         $command = '@echo off' . "\r\n" . '@start /B /BELOWNORMAL ' . realpath(PATH_PHP_CLI_WINDOWS) . ' ' . realpath(PATH_PACKAGES_FS . '\\scripts\\script.php') . ' -s ' . $data["id_reg"];
                         if (!@touch(realpath(PATH_WINDOWS_BIN_FS) . DIRECTORY_SEPARATOR . "sub_script.bat")) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Create file error : sub_script.bat");
                         }
                         $replace = array('program files (x86)' => 'progra~2', 'program files' => 'progra~1', 'documents and settings' => 'docume~1');
                         $command = str_ireplace(array_keys($replace), $replace, $command);
                         $fh = fopen(realpath(PATH_WINDOWS_BIN_FS . DIRECTORY_SEPARATOR . "sub_script.bat"), "wb");
                         if (is_resource($fh)) {
                             if (!fwrite($fh, $command, io::strlen($command))) {
                                 CMS_grandFather::raiseError(processManager::MASTER_SCRIPT_NAME . " : Save file error : sub_script.bat");
                             }
                             fclose($fh);
                         }
                         $WshShell = new COM("WScript.Shell");
                         $oExec = $WshShell->Run(str_ireplace(array_keys($replace), $replace, realpath(PATH_WINDOWS_BIN_FS . '\\sub_script.bat')), 0, false);
                         $PIDfile = $this->_processManager->getTempPath() . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . "_" . $data["id_reg"];
                         //sleep a little
                         @sleep(SLEEP_TIME);
                     }
                     if ($this->_debug) {
                         $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : script : " . $data["id_reg"] . " - sub_system : " . $sub_system);
                     }
                     $scriptsArray[] = array("PID" => $PIDfile, "startTime" => CMS_stats::getmicrotime(), "scriptID" => $data["id_reg"], "scriptDatas" => $data);
                 }
             } else {
                 // no more scripts to process
                 // > delete all temporary files
                 // > end script
                 if (APPLICATION_IS_WINDOWS) {
                     $files = glob(realpath($this->_processManager->getTempPath()) . DIRECTORY_SEPARATOR . SCRIPT_CODENAME . '*.ok', GLOB_NOSORT);
                     if (is_array($files)) {
                         foreach ($files as $file) {
                             if (!CMS_file::deleteFile($file)) {
                                 $this->raiseError("Can't delete file " . $file);
                                 return false;
                             }
                         }
                     }
                 } else {
                     $tmpDir = dir($this->_processManager->getTempPath());
                     while (false !== ($file = $tmpDir->read())) {
                         if (io::strpos($file, SCRIPT_CODENAME) !== false) {
                             @unlink($this->_processManager->getTempPath() . '/' . $file);
                         }
                     }
                 }
                 break;
             }
             while (true) {
                 @sleep(SLEEP_TIME);
                 //wait a little to check sub_scripts
                 $break = false;
                 $timeStop = CMS_stats::getmicrotime();
                 if ($this->_debug) {
                     $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Scripts in progress : " . sizeof($scriptsArray));
                 }
                 foreach ($scriptsArray as $nb => $aScript) {
                     if ($this->_debug) {
                         $this->raiseError(processManager::MASTER_SCRIPT_NAME . " PID : " . $aScript["PID"] . " - time : " . ($timeStop - $aScript["startTime"]));
                     }
                     $ok = '';
                     $ok = is_file($aScript["PID"] . '.ok');
                     if ($ok) {
                         //$break = true;
                         if ($this->_debug) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " Script : " . $aScript["PID"] . " OK !");
                         }
                         unset($scriptsArray[$nb]);
                     } elseif ($timeStop - $aScript["startTime"] >= SUB_SCRIPT_TIME_OUT) {
                         if ($this->_debug) {
                             $this->raiseError(processManager::MASTER_SCRIPT_NAME . " : Script : " . $aScript["PID"] . " NOT OK !");
                         }
                         $this->raiseError(processManager::MASTER_SCRIPT_NAME . ' : Error on task : ' . $aScript["scriptID"] . ' ... skip it. Task parameters : ' . print_r($aScript['scriptDatas'], true));
                         //$break = true;
                         unset($scriptsArray[$nb]);
                         //delete the script in error from task list
                         $q_del = "\n\t\t\t\t\t\t\t\tdelete\n\t\t\t\t\t\t\t\tfrom\n\t\t\t\t\t\t\t\t\tregenerator\n\t\t\t\t\t\t\t\twhere\n\t\t\t\t\t\t\t\t\tid_reg='" . $aScript["scriptID"] . "'";
                         $q_del = new CMS_query($q_del);
                     }
                 }
                 if (!$scriptsArray) {
                     break;
                 }
             }
         }
     }
 }
Esempio n. 2
0
if (!$installed) {
    if (CMS_patch::executeSqlScript(PATH_MAIN_FS . '/sql/updates/mod_object_oembed_definition.sql', true)) {
        CMS_patch::executeSqlScript(PATH_MAIN_FS . '/sql/updates/mod_object_oembed_definition.sql', false);
        $content .= 'Database successfuly updated (add Oembed definitions table)<br/>';
    } else {
        $content .= 'Error during database update ! Script ' . PATH_MAIN_FS . '/sql/updates/mod_object_oembed_definition.sql must be executed manualy<br/>';
    }
}
// END UPDATE FROM 4.2.1 TO 4.2.2
//Update Automne messages
$files = glob(PATH_MAIN_FS . "/sql/messages/*/*.sql", GLOB_NOSORT);
if (is_array($files)) {
    $content .= "Start update of Automne messages ...<br />";
    foreach ($files as $file) {
        if (file_exists($file) && CMS_patch::executeSqlScript($file, true)) {
            CMS_patch::executeSqlScript($file);
        } else {
            $content .= 'Error during database update ! Script ' . $file . ' must be executed manualy<br/>';
        }
    }
    $content .= "Automne messages updated.<br /><br />";
}
//clear caches
$content .= "Clean Automne cache.<br /><br />";
CMS_cache::clearTypeCache('polymod');
CMS_cache::clearTypeCache('atm-polymod-structure');
CMS_cache::clearTypeCache('text/javascript');
CMS_cache::clearTypeCache('text/css');
CMS_cache::clearTypeCache('atm-backtrace');
//compile polymod definitions
CMS_polymod::compileDefinitions();
Esempio n. 3
0
 /**
  * Start the scripts process queue.
  * Remove the lock file then relaunch the script if force is true
  *
  * @param boolean $force Set to true if you wish to remove the lock file before launch
  * @return void
  * @access public
  * @static
  */
 static function startScript($force = false)
 {
     if (USE_BACKGROUND_REGENERATOR) {
         $forceRestart = '';
         if ($force) {
             $forceRestart = ' -F';
         } elseif (processManager::hasRunningScript()) {
             return false;
         }
         //test if we're on windows or linux, for the output redirection
         if (APPLICATION_IS_WINDOWS) {
             if (realpath(PATH_PHP_CLI_WINDOWS) === false) {
                 CMS_grandFather::raiseError("Unknown CLI location : " . PATH_PHP_CLI_WINDOWS . ", please check your configuration.");
                 return false;
             }
             // Create the BAT file
             $command = '@echo off' . "\r\n" . 'start /B /LOW ' . realpath(PATH_PHP_CLI_WINDOWS) . ' ' . realpath(PATH_PACKAGES_FS . '\\scripts\\script.php') . ' -m ' . REGENERATION_THREADS . $forceRestart;
             $replace = array('program files (x86)' => 'progra~2', 'program files' => 'progra~1', 'documents and settings' => 'docume~1');
             $command = str_ireplace(array_keys($replace), $replace, $command);
             if (!@touch(PATH_WINDOWS_BIN_FS . "/script.bat")) {
                 CMS_grandFather::_raiseError("CMS_scriptsManager : startScript : Create file error : " . PATH_WINDOWS_BIN_FS . "/script.bat");
                 return false;
             }
             $fh = @fopen(PATH_WINDOWS_BIN_FS . "/script.bat", "wb");
             if (is_resource($fh)) {
                 if (!@fwrite($fh, $command, io::strlen($command))) {
                     CMS_grandFather::raiseError("Save file error : script.bat");
                 }
                 @fclose($fh);
             }
             $WshShell = new COM("WScript.Shell");
             $oExec = $WshShell->Run(str_ireplace(array_keys($replace), $replace, realpath(PATH_WINDOWS_BIN_FS . '\\script.bat')), 0, false);
         } else {
             $error = '';
             if (!defined('PATH_PHP_CLI_UNIX') || !PATH_PHP_CLI_UNIX) {
                 $return = CMS_patch::executeCommand('which php 2>&1', $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error when finding php CLI with command "which php", please check your configuration : ' . $error);
                     return false;
                 }
                 if (io::substr($return, 0, 1) != '/') {
                     CMS_grandFather::raiseError('Can\'t find php CLI with command "which php", please check your configuration.');
                     return false;
                 }
                 $return = CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; php " . PATH_PACKAGES_FS . "/scripts/script.php -m " . REGENERATION_THREADS . $forceRestart . " > /dev/null 2>&1 &", $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error during execution of script command (cd ' . PATH_REALROOT_FS . '; php ' . PATH_PACKAGES_FS . '/scripts/script.php -m ' . REGENERATION_THREADS . $forceRestart . '), please check your configuration : ' . $error);
                     return false;
                 }
             } else {
                 $return = CMS_patch::executeCommand(PATH_PHP_CLI_UNIX . ' -v 2>&1', $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error when testing php CLI with command "' . PATH_PHP_CLI_UNIX . ' -v", please check your configuration : ' . $error);
                     return false;
                 }
                 if (io::strpos(io::strtolower($return), '(cli)') === false) {
                     CMS_grandFather::raiseError(PATH_PHP_CLI_UNIX . ' is not the CLI version');
                     return false;
                 }
                 $return = CMS_patch::executeCommand("cd " . PATH_REALROOT_FS . "; " . PATH_PHP_CLI_UNIX . " " . PATH_PACKAGES_FS . "/scripts/script.php -m " . REGENERATION_THREADS . $forceRestart . " > /dev/null 2>&1 &", $error);
                 if ($error) {
                     CMS_grandFather::raiseError('Error during execution of script command (cd ' . PATH_REALROOT_FS . '; ' . PATH_PHP_CLI_UNIX . ' ' . PATH_PACKAGES_FS . '/scripts/script.php -m ' . REGENERATION_THREADS . $forceRestart . '), please check your configuration : ' . $error);
                     return false;
                 }
             }
             //CMS_grandFather::log($return);
             //CMS_grandFather::log("cd ".PATH_REALROOT_FS."; php ".PATH_PACKAGES_FS."/scripts/script.php -m ".REGENERATION_THREADS.$forceRestart." > /dev/null 2>&1 &");
             //@system("cd ".PATH_REALROOT_FS."; php ".PATH_PACKAGES_FS."/scripts/script.php -m ".REGENERATION_THREADS.$forceRestart." > /dev/null 2>&1 &");
         }
     } else {
         CMS_session::setSessionVar('start_script', true);
     }
 }
Esempio n. 4
0
         } else {
             report('Error : Extraction directory does not exist', true);
         }
     } else {
         report('Error : Unable to extract archive wanted ' . $filename . '. It is not a valid format...', true);
     }
     if (!$archive->hasError()) {
         verbose('-> Extraction successfull');
     } else {
         report('Extraction error...', true);
     }
     unset($archive);
 }
 //Check files content
 report('Start patching process...');
 $automnePatch = new CMS_patch($cms_user);
 //read patch or export param file and check versions
 verbose('Read patch file...');
 $patchFile = new CMS_file(PATH_TMP_FS . "/patch");
 $exportFile = new CMS_file(PATH_TMP_FS . "/export.xml");
 if ($patchFile->exists()) {
     $patch = $patchFile->readContent("array");
     if (!$automnePatch->checkPatch($patch)) {
         report('Error : Patch does not match current version ...', true);
     } else {
         verbose('-> Patch version match.');
     }
     //read install param file and do maximum check on it before starting the installation process
     verbose('Read install file...');
     $installFile = new CMS_file(PATH_TMP_FS . "/install");
     if ($installFile->exists()) {
Esempio n. 5
0
    } else {
        $content .= '<li class="atm-pic-ok">GD extension OK</li>';
    }
    //XAPIAN
    if (class_exists('CMS_module_ase')) {
        $return = CMS_patch::executeCommand('"' . $cliPath . '" -r "echo (function_exists(\'xapian_version_string\') ? xapian_version_string() : (function_exists(\'flint_open\') ? version_string() : \'none\'));"', $error);
        if ($error || $return == 'none') {
            $content .= '<li class="atm-pic-cancel">Error, Xapian extension not installed ' . $error . ' ' . $return . '</li>';
        } else {
            $content .= '<li class="atm-pic-ok">Xapian extension OK (' . $return . ')</li>';
        }
    }
    $content .= '
		</ul>';
    //Ini file infos
    $return = CMS_patch::executeCommand('"' . $cliPath . '" --ini', $error);
    if (!$error && $return) {
        $content .= '<code>' . str_replace("\n", '<br />', $return) . '</code>';
    }
    $content .= '
	</fieldset>';
}
//Daily Routine
if ($mysqlOk) {
    $modules = CMS_modulesCatalog::getAll();
    $drContent = '';
    foreach ($modules as $aModule) {
        //see if the action was done today
        $sql = "\n\t\t\tselect\n\t\t\t\t*\n\t\t\tfrom\n\t\t\t\tactionsTimestamps\n\t\t\twhere\n\t\t\t\ttype_at='DAILY_ROUTINE'\n\t\t\t\tand module_at='" . io::sanitizeSQLString($aModule->getCodename()) . "'\n\t\t";
        $q = new CMS_query($sql);
        if ($q->getNumRows()) {
Esempio n. 6
0
            }
            $countSize += $object->getSize();
        }
        if ($content) {
            $cms_message = $cms_language->getMessage(MESSAGE_CHECK_ERROR);
            $content = '<span class="atm-red">' . $cms_language->getMessage(MESSAGE_FILES_ACCESS_ERROR) . '</span><ul class="atm-server">' . $content . '</ul>';
        } else {
            $cms_message = $cms_language->getMessage(MESSAGE_CHECK_DONE);
        }
        $filesize = $countSize < 1073741824 ? round($countSize / 1048576, 2) . ' M' : round($countSize / 1073741824, 2) . ' G';
        $content = $cms_language->getMessage(MESSAGE_PAGE_FOLDER_NO) . ' <strong>' . $countDir . '</strong><br />
		' . $cms_language->getMessage(MESSAGE_PAGE_FILES_NO) . ' <strong>' . $countFile . '</strong><br />
		' . $cms_language->getMessage(MESSAGE_PAGE_DISK_SPACE) . ' <strong>' . $filesize . '</strong><br /><br />' . $content;
        break;
    case 'check-htaccess':
        $automnePatch = new CMS_patch($cms_user);
        if ($automnePatch->automneGeneralScript()) {
            $cms_message = $cms_language->getMessage(MESSAGE_CHECK_DONE);
        } else {
            $cms_message = $cms_language->getMessage(MESSAGE_CHECK_ERROR);
        }
        $return = $automnePatch->getReturn();
        $content = '<ul class="atm-server">';
        foreach ($return as $line) {
            switch ($line['type']) {
                case 'verbose':
                    $content .= '<li>' . $line['text'] . '</li>';
                    break;
                case 'report':
                    switch ($line['error']) {
                        case 0:
Esempio n. 7
0
function patch($patchFile, &$error)
{
    $archive = new CMS_gzip_file($patchFile);
    if (!$archive->hasError()) {
        $archive->set_options(array('basedir' => PATH_TMP_FS . "/", 'overwrite' => 1, 'level' => 1, 'dontUseFilePerms' => 1, 'forceWriting' => 1));
        if (is_dir(PATH_TMP_FS)) {
            if (!method_exists($archive, 'extract_files') || !$archive->extract_files()) {
                $error = 'Error : Extraction error...';
                return false;
            }
        } else {
            $error = 'Error : Extraction directory does not exist';
            return false;
        }
    } else {
        $error = 'Error : Unable to extract archive wanted ' . $filename . '. It is not a valid format...';
        return false;
    }
    if (!$archive->hasError()) {
        unset($archive);
    } else {
        $error = 'Extraction error...';
        return false;
    }
    //Check files content
    $automnePatch = new CMS_patch();
    //read patch param file and check versions
    $patchFile = new CMS_file(PATH_TMP_FS . "/patch");
    if ($patchFile->exists()) {
        $patch = $patchFile->readContent("array");
    } else {
        $error = 'Error : File ' . PATH_TMP_FS . '/patch does not exists ...';
        return false;
    }
    if (!$automnePatch->checkPatch($patch)) {
        $error = 'Error : Patch does not match current version ...';
        return false;
    }
    //read install param file and do maximum check on it before starting the installation process
    $installFile = new CMS_file(PATH_TMP_FS . "/install");
    if ($installFile->exists()) {
        $install = $installFile->readContent("array");
    } else {
        $error = 'Error : File ' . PATH_TMP_FS . '/install does not exists ...';
        return false;
    }
    $installError = $automnePatch->checkInstall($install, $errorsInfos);
    if ($installError) {
        $error = 'Error : Invalid install file :';
        $error .= $installError;
        return false;
    }
    //start Installation process
    $automnePatch->doInstall($install);
    $installError = false;
    $return = $automnePatch->getReturn();
    foreach ($return as $line) {
        if ($line['type'] == 'report') {
            $error .= $line['text'];
        }
    }
    if ($installError) {
        $error = 'Error during installation process : ' . $error;
        return false;
    }
    //remove temporary files
    !CMS_file::deltree(PATH_TMP_FS);
    return true;
}