예제 #1
0
 public function __construct($sName, $sDBHost = null, $sDBUser = null, $sDBPwd = null)
 {
     // Compute the name of a lock for mysql
     // Note: names are server-wide!!! So let's make the name specific to this iTop instance
     $oConfig = utils::GetConfig();
     // Will return an empty config when called during the setup
     $sDBName = $oConfig->GetDBName();
     $sDBSubname = $oConfig->GetDBSubname();
     $this->sName = 'itop.' . $sName;
     if (substr($sName, -strlen($sDBName . $sDBSubname)) != $sDBName . $sDBSubname) {
         // If the name supplied already ends with the expected suffix
         // don't add it twice, since the setup may try to detect an already
         // running cron job by its mutex, without knowing if the config already exists or not
         $this->sName .= $sDBName . $sDBSubname;
     }
     $this->bLocked = false;
     // Not yet locked
     if (!array_key_exists($this->sName, self::$aAcquiredLocks)) {
         self::$aAcquiredLocks[$this->sName] = 0;
     }
     // It is a MUST to create a dedicated session each time a lock is required, because
     // using GET_LOCK anytime on the same session will RELEASE the current and unique session lock (known issue)
     $sDBHost = is_null($sDBHost) ? $oConfig->GetDBHost() : $sDBHost;
     $sDBUser = is_null($sDBUser) ? $oConfig->GetDBUser() : $sDBUser;
     $sDBPwd = is_null($sDBPwd) ? $oConfig->GetDBPwd() : $sDBPwd;
     $this->InitMySQLSession($sDBHost, $sDBUser, $sDBPwd);
 }
예제 #2
0
 public function __construct($sName, $sDBHost = null, $sDBUser = null, $sDBPwd = null)
 {
     // Compute the name of a lock for mysql
     // Note: the name is server-wide!!!
     $this->sName = 'itop.' . $sName;
     $this->bLocked = false;
     // Not yet locked
     if (!array_key_exists($this->sName, self::$aAcquiredLocks)) {
         self::$aAcquiredLocks[$this->sName] = 0;
     }
     // It is a MUST to create a dedicated session each time a lock is required, because
     // using GET_LOCK anytime on the same session will RELEASE the current and unique session lock (known issue)
     $oConfig = utils::GetConfig();
     $sDBHost = is_null($sDBHost) ? $oConfig->GetDBHost() : $sDBHost;
     $sDBUser = is_null($sDBUser) ? $oConfig->GetDBUser() : $sDBUser;
     $sDBPwd = is_null($sDBPwd) ? $oConfig->GetDBPwd() : $sDBPwd;
     $this->InitMySQLSession($sDBHost, $sDBUser, $sDBPwd);
 }
 public function GetValidationPattern()
 {
     return $this->GetOptional('validation_pattern', '^' . utils::GetConfig()->Get('url_validation_pattern') . '$');
 }
예제 #4
0
                    $oDBRS = new DBRestore($sDBHost, $sDBUser, $sDBPwd, $sDBName, $sDBSubName);
                    $oDBRS->SetMySQLBinDir($sMySQLBinDir);
                    $sBackupDir = APPROOT . 'data/backups/';
                    $sBackupFile = $sBackupDir . $sFile;
                    $sRes = $oDBRS->RestoreFromZip($sBackupFile, $sEnvironment);
                    IssueLog::Info('Backup Restore - Done, releasing the LOCK');
                    $oRestoreMutex->Unlock();
                } catch (Exception $e) {
                    $oRestoreMutex->Unlock();
                    $oPage->p('Error: ' . $e->getMessage());
                }
            }
            $oPage->output();
            break;
        case 'download':
            require_once APPROOT . '/application/startup.inc.php';
            require_once APPROOT . '/application/loginwebpage.class.inc.php';
            LoginWebPage::DoLogin(true);
            // Check user rights and prompt if needed (must be admin)
            if (utils::GetConfig()->Get('demo_mode')) {
                throw new Exception('iTop is in demonstration mode: the feature is disabled');
            }
            $sFile = utils::ReadParam('file', '', false, 'raw_data');
            $oBackup = new DBBackupScheduled();
            $sBackupDir = APPROOT . 'data/backups/';
            $oBackup->DownloadBackup($sBackupDir . $sFile);
            break;
    }
} catch (Exception $e) {
    IssueLog::Error($e->getMessage());
}
예제 #5
0
    $aDisplayProcesses = array();
    foreach ($aProcesses as $oExecInstance) {
        $aDisplayProcesses[] = get_class($oExecInstance);
    }
    $sDisplayProcesses = implode(', ', $aDisplayProcesses);
    $oP->p("Background processes: " . $sDisplayProcesses);
}
if (utils::ReadParam('status_only', false, true)) {
    // Display status and exit
    DisplayStatus($oP);
    exit(0);
}
require_once APPROOT . 'core/mutex.class.inc.php';
$oP->p("Starting: " . time() . ' (' . date('Y-m-d H:i:s') . ')');
try {
    $oConfig = utils::GetConfig();
    $oMutex = new iTopMutex('cron.' . $oConfig->GetDBName() . '_' . $oConfig->GetDBSubname());
    if ($oMutex->TryLock()) {
        // Note: testing this now in case some of the background processes forces the read-only mode for a while
        //       in that case it is better to exit with the check on reentrance (mutex)
        if (!MetaModel::DBHasAccess(ACCESS_ADMIN_WRITE)) {
            $oP->p("A database maintenance is ongoing (read-only mode even for admins).");
            $oP->Output();
            exit - 1;
        }
        CronExec($oP, $aProcesses, $bVerbose);
        $oMutex->Unlock();
    } else {
        // Exit silently
        $oP->p("Already running...");
    }