/**
  * Gets the data where the compiler has left them...
  * @param $sDesignSourceId Identifier of the section module_design (generally a module name)
  * @throws Exception
  */
 protected function LoadFromCompiledDesigns($sDesignSourceId)
 {
     $sDesignDir = APPROOT . 'env-' . utils::GetCurrentEnvironment() . '/core/module_designs/';
     $sFile = $sDesignDir . $sDesignSourceId . '.xml';
     if (!file_exists($sFile)) {
         $aFiles = glob($sDesignDir . '/*.xml');
         if (count($aFiles) == 0) {
             $sAvailable = 'none!';
         } else {
             var_dump($aFiles);
             $aAvailable = array();
             foreach ($aFiles as $sFile) {
                 $aAvailable[] = "'" . basename($sFile, '.xml') . "'";
             }
             $sAvailable = implode(', ', $aAvailable);
         }
         throw new Exception("Could not load module design '{$sDesignSourceId}'. Available designs: {$sAvailable}");
     }
     // Silently keep track of errors
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     $this->load($sFile);
     //$bValidated = $oDocument->schemaValidate(APPROOT.'setup/itop_design.xsd');
     $aErrors = libxml_get_errors();
     if (count($aErrors) > 0) {
         $aDisplayErrors = array();
         foreach ($aErrors as $oXmlError) {
             $aDisplayErrors[] = 'Line ' . $oXmlError->line . ': ' . $oXmlError->message;
         }
         throw new Exception("Invalid XML in '{$sFile}'. Errors: " . implode(', ', $aDisplayErrors));
     }
 }
    public function __construct($s_title, $bPrintable = false)
    {
        parent::__construct($s_title, $bPrintable);
        $this->m_aReadyScripts = array();
        $this->add_linked_script("../js/jquery-1.10.0.min.js");
        $this->add_linked_script("../js/jquery-migrate-1.2.1.min.js");
        // Needed since many other plugins still rely on oldies like $.browser
        $this->add_linked_stylesheet('../css/ui-lightness/jquery-ui-1.10.3.custom.min.css');
        $this->add_linked_script('../js/jquery-ui-1.10.3.custom.min.js');
        $this->add_linked_script("../js/hovertip.js");
        // table sorting
        $this->add_linked_script("../js/jquery.tablesorter.js");
        $this->add_linked_script("../js/jquery.tablesorter.pager.js");
        $this->add_linked_script("../js/jquery.tablehover.js");
        $this->add_linked_script('../js/field_sorter.js');
        $this->add_linked_script('../js/datatable.js');
        $this->add_linked_script("../js/jquery.positionBy.js");
        $this->add_linked_script("../js/jquery.popupmenu.js");
        $this->add_ready_script(<<<EOF
\t//add new widget called TruncatedList to properly display truncated lists when they are sorted
\t\$.tablesorter.addWidget({ 
\t\t// give the widget a id 
\t\tid: "truncatedList", 
\t\t// format is called when the on init and when a sorting has finished 
\t\tformat: function(table)
\t\t{ 
\t\t\t// Check if there is a "truncated" line
\t\t\tthis.truncatedList = false;  
\t\t\tif (\$("tr td.truncated",table).length > 0)
\t\t\t{
\t\t\t\tthis.truncatedList = true;
\t\t\t}
\t\t\tif (this.truncatedList)
\t\t\t{
\t\t\t\t\$("tr td",table).removeClass('truncated');
\t\t\t\t\$("tr:last td",table).addClass('truncated');
\t\t\t}
\t\t} 
\t});
\t
\t\$.tablesorter.addWidget({ 
\t\t// give the widget a id 
\t\tid: "myZebra", 
\t\t// format is called when the on init and when a sorting has finished 
\t\tformat: function(table)
\t\t{
\t\t\t// Replace the 'red even' lines by 'red_even' since most browser do not support 2 classes selector in CSS, etc..
\t\t\t\$("tbody tr:even",table).addClass('even');
\t\t\t\$("tbody tr.red:even",table).removeClass('red').removeClass('even').addClass('red_even');
\t\t\t\$("tbody tr.orange:even",table).removeClass('orange').removeClass('even').addClass('orange_even');
\t\t\t\$("tbody tr.green:even",table).removeClass('green').removeClass('even').addClass('green_even');
\t\t\t// In case we sort again the table, we need to remove the added 'even' classes on odd rows
\t\t\t\$("tbody tr:odd",table).removeClass('even');
\t\t\t\$("tbody tr.red_even:odd",table).removeClass('even').removeClass('red_even').addClass('red');
\t\t\t\$("tbody tr.orange_even:odd",table).removeClass('even').removeClass('orange_even').addClass('orange');
\t\t\t\$("tbody tr.green_even:odd",table).removeClass('even').removeClass('green_even').addClass('green');
\t\t} 
\t});
\t\$("table.listResults").tableHover(); // hover tables
EOF
);
        $this->add_saas("css/light-grey.scss");
        $this->m_sRootUrl = $this->GetAbsoluteUrlAppRoot();
        $sAbsURLAppRoot = addslashes($this->m_sRootUrl);
        $sAbsURLModulesRoot = addslashes($this->GetAbsoluteUrlModulesRoot());
        $sEnvironment = addslashes(utils::GetCurrentEnvironment());
        $sAppContext = addslashes($this->GetApplicationContext());
        $this->add_script(<<<EOF
function GetAbsoluteUrlAppRoot()
{
\treturn '{$sAbsURLAppRoot}';
}

function GetAbsoluteUrlModulesRoot()
{
\treturn '{$sAbsURLModulesRoot}';
}

function GetAbsoluteUrlModulePage(sModule, sPage, aArguments)
{
\t// aArguments is optional, it default to an empty hash
\taArguments = typeof aArguments !== 'undefined' ? aArguments : {};

\tvar sUrl = '{$sAbsURLAppRoot}'+'pages/exec.php?exec_module='+sModule+'&exec_page='+sPage+'&exec_env='+'{$sEnvironment}';
\tfor (var sArgName in aArguments)
\t{
\t\tif (aArguments.hasOwnProperty(sArgName))
\t\t{
\t\t\tsUrl = sUrl + '&'+sArgName+'='+aArguments[sArgname];
\t\t}
\t}
\treturn sUrl;
}

function AddAppContext(sURL)
{
\tvar sContext = '{$sAppContext}';
\tif (sContext.length > 0)
\t{
\t\tif (sURL.indexOf('?') == -1)
\t\t{
\t\t\treturn sURL+'?'+sContext;
\t\t}\t\t\t\t
\t\treturn sURL+'&'+sContext;
\t}
\treturn sURL;
}
EOF
);
    }
Пример #3
0
        $oP->add_style(<<<EOF
textarea {
\t-webkit-box-sizing: border-box;
\t-moz-box-sizing: border-box;
\tbox-sizing: border-box;

\twidth: 100%;
\theight: 550px;
}
.current_line {
\tdisplay: none;
\tmargin-left: 20px;
}
EOF
);
        $sConfigFile = APPROOT . 'conf/' . utils::GetCurrentEnvironment() . '/config-itop.php';
        if ($sOperation == 'save') {
            $sConfig = utils::ReadParam('new_config', '', false, 'raw_data');
            $sOrginalConfig = utils::ReadParam('prev_config', '', false, 'raw_data');
            if ($sConfig == $sOrginalConfig) {
                $oP->add('<div id="save_result" class="header_message">' . Dict::S('config-no-change') . '</div>');
            } else {
                try {
                    TestConfig($sConfig, $oP);
                    // throws exceptions
                    @chmod($sConfigFile, 0770);
                    // Allow overwriting the file
                    file_put_contents($sConfigFile, $sConfig);
                    @chmod($sConfigFile, 0444);
                    // Read-only
                    $oP->p('<div id="save_result" class="header_message message_ok">' . Dict::S('Successfully recorded.') . '</div>');
Пример #4
0
// Needed to read the parameters (with sanitization)
require_once APPROOT . 'application/utils.inc.php';
$sModule = utils::ReadParam('exec_module', '');
if ($sModule == '') {
    echo "Missing argument 'exec_module'";
    exit;
}
$sModule = basename($sModule);
// protect against ../.. ...
$sPage = utils::ReadParam('exec_page', '', false, 'raw_data');
if ($sPage == '') {
    echo "Missing argument 'exec_page'";
    exit;
}
$sPage = basename($sPage);
// protect against ../.. ...
session_name('itop-' . md5(APPROOT));
session_start();
$sEnvironment = utils::ReadParam('exec_env', utils::GetCurrentEnvironment());
session_write_close();
$sTargetPage = APPROOT . 'env-' . $sEnvironment . '/' . $sModule . '/' . $sPage;
if (!file_exists($sTargetPage)) {
    // Do not recall the parameters (security takes precedence)
    echo "Wrong module, page name or environment...";
    exit;
}
/////////////////////////////////////////
//
// GO!
//
require_once $sTargetPage;
Пример #5
0
 public function CreateZip($sZipFile, $sSourceConfigFile = null)
 {
     // Note: the file is created by tempnam and might not be writeable by another process (Windows/IIS)
     // (delete it before spawning a process)
     $sDataFile = tempnam(SetupUtils::GetTmpDir(), 'itop-');
     $this->LogInfo("Data file: '{$sDataFile}'");
     $aContents = array();
     $aContents[] = array('source' => $sDataFile, 'dest' => 'itop-dump.sql');
     if (is_null($sSourceConfigFile)) {
         $sSourceConfigFile = MetaModel::GetConfig()->GetLoadedFile();
     }
     if (!empty($sSourceConfigFile)) {
         $aContents[] = array('source' => $sSourceConfigFile, 'dest' => 'config-itop.php');
     }
     $this->DoBackup($sDataFile);
     $sDeltaFile = APPROOT . 'data/' . utils::GetCurrentEnvironment() . '.delta.xml';
     if (file_exists($sDeltaFile)) {
         $aContents[] = array('source' => $sDeltaFile, 'dest' => 'delta.xml');
     }
     $sExtraDir = APPROOT . 'data/' . utils::GetCurrentEnvironment() . '-modules/';
     if (is_dir($sExtraDir)) {
         $aContents[] = array('source' => $sExtraDir, 'dest' => utils::GetCurrentEnvironment() . '-modules/');
     }
     $this->DoZip($aContents, $sZipFile);
     // Windows/IIS: the data file has been created by the spawned process...
     //   trying to delete it will issue a warning, itself stopping the setup abruptely
     @unlink($sDataFile);
 }
Пример #6
0
 public static function GetFileIcon($sFileName)
 {
     $aPathParts = pathinfo($sFileName);
     switch ($aPathParts['extension']) {
         case 'doc':
         case 'docx':
             $sIcon = 'doc.png';
             break;
         case 'xls':
         case 'xlsx':
             $sIcon = 'xls.png';
             break;
         case 'ppt':
         case 'pptx':
             $sIcon = 'ppt.png';
             break;
         case 'pdf':
             $sIcon = 'pdf.png';
             break;
         case 'txt':
         case 'text':
             $sIcon = 'txt.png';
             break;
         case 'rtf':
             $sIcon = 'rtf.png';
             break;
         case 'odt':
             $sIcon = 'odt.png';
             break;
         case 'ods':
             $sIcon = 'ods.png';
             break;
         case 'odp':
             $sIcon = 'odp.png';
             break;
         case 'html':
         case 'htm':
             $sIcon = 'html.png';
             break;
         case 'png':
         case 'gif':
         case 'jpg':
         case 'jpeg':
         case 'tiff':
         case 'tif':
         case 'bmp':
             $sIcon = 'image.png';
             break;
         case 'zip':
         case 'gz':
         case 'tgz':
         case 'rar':
             $sIcon = 'zip.png';
             break;
         default:
             $sIcon = 'document.png';
             break;
     }
     return 'env-' . utils::GetCurrentEnvironment() . "/itop-attachments/icons/{$sIcon}";
 }
Пример #7
0
 $sMySQLVersion = CMDBSource::GetDBVersion();
 $sPHPVersion = phpversion();
 $sOSVersion = PHP_OS;
 $sWebServerVersion = $_SERVER["SERVER_SOFTWARE"];
 $sModules = implode(', ', get_loaded_extensions());
 // Get the datamodel directory
 $oFilter = DBObjectSearch::FromOQL('SELECT ModuleInstallation WHERE name="datamodel"');
 $oSet = new DBObjectSet($oFilter, array('installed' => false));
 // Most recent first
 $oLastInstall = $oSet->Fetch();
 $sLastInstallDate = $oLastInstall->Get('installed');
 $sDataModelVersion = $oLastInstall->Get('version');
 $aDataModelInfo = json_decode($oLastInstall->Get('comment'), true);
 $sDataModelSourceDir = $aDataModelInfo['source_dir'];
 require_once APPROOT . 'setup/runtimeenv.class.inc.php';
 $sCurrEnv = utils::GetCurrentEnvironment();
 $oRuntimeEnv = new RunTimeEnvironment($sCurrEnv);
 $aAvailableModules = $oRuntimeEnv->AnalyzeInstallation(MetaModel::GetConfig(), array(APPROOT . $sDataModelSourceDir, APPROOT . 'extensions'));
 require_once APPROOT . 'setup/setuputils.class.inc.php';
 $aLicenses = SetupUtils::GetLicenses();
 $aItopSettings = array('cron_max_execution_time', 'timezone');
 $aPHPSettings = array('memory_limit', 'max_execution_time', 'upload_max_filesize', 'post_max_size');
 $aMySQLSettings = array('max_allowed_packet', 'key_buffer_size', 'query_cache_size');
 $aMySQLStatuses = array('Key_read_requests', 'Key_reads');
 if (extension_loaded('suhosin')) {
     $aPHPSettings[] = 'suhosin.post.max_vars';
     $aPHPSettings[] = 'suhosin.get.max_value_length';
 }
 $aMySQLVars = array();
 foreach (CMDBSource::QueryToArray('SHOW VARIABLES') as $aRow) {
     $aMySQLVars[$aRow['Variable_name']] = $aRow['Value'];
 protected static function MakeIconFromName($sIconName, $bImgTag = true)
 {
     $sIcon = '';
     if ($sIconName != '') {
         $sPath = '../env-' . utils::GetCurrentEnvironment() . '/itop-change-mgmt-itil/images/' . $sIconName;
         if ($bImgTag) {
             $sIcon = "<img src=\"{$sPath}\" style=\"vertical-align:middle;\"/>";
         } else {
             $sIcon = $sPath;
         }
     }
     return $sIcon;
 }
Пример #9
0
 public function Process($iUnixTimeLimit)
 {
     $oMutex = new iTopMutex('backup.' . utils::GetCurrentEnvironment());
     $oMutex->Lock();
     try {
         // Make sure the target directory exists
         SetupUtils::builddir($this->sBackupDir);
         $oBackup = new DBBackupScheduled();
         // Eliminate files exceeding the retention setting
         //
         if ($this->iRetentionCount > 0) {
             $aFiles = $oBackup->ListFiles($this->sBackupDir);
             while (count($aFiles) >= $this->iRetentionCount) {
                 $sFileToDelete = array_shift($aFiles);
                 unlink($sFileToDelete);
                 if (file_exists($sFileToDelete)) {
                     // Ok, do not loop indefinitely on this
                     break;
                 }
             }
         }
         // Do execute the backup
         //
         $oBackup->SetMySQLBinDir(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
         $sBackupFile = MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'file_name_format', '__DB__-%Y-%m-%d_%H_%M');
         $sName = $oBackup->MakeName($sBackupFile);
         if ($sName == '') {
             $sName = $oBackup->MakeName(BACKUP_DEFAULT_FORMAT);
         }
         $sZipFile = $this->sBackupDir . $sName . '.zip';
         $sSourceConfigFile = APPCONF . utils::GetCurrentEnvironment() . '/' . ITOP_CONFIG_FILE;
         $oBackup->CreateZip($sZipFile, $sSourceConfigFile);
     } catch (Exception $e) {
         $oMutex->Unlock();
         throw $e;
     }
     $oMutex->Unlock();
     return "Created the backup: {$sZipFile}";
 }
Пример #10
0
 /**
  * Overriden because the application is not fully loaded when the setup is being run
  */
 public function GetAbsoluteUrlModulesRoot()
 {
     return $this->GetAbsoluteUrlAppRoot() . utils::GetCurrentEnvironment();
 }
Пример #11
0
 public static function GetEnvironmentId()
 {
     return md5(APPROOT) . '-' . utils::GetCurrentEnvironment();
 }
Пример #12
0
 public function __construct($sCode, $sLabel = '', $defaultValue = '')
 {
     parent::__construct($sCode, $sLabel, $defaultValue);
     if (count(self::$aAllIcons) == 0) {
         self::$aAllIcons = self::FindIconsOnDisk(APPROOT . 'env-' . utils::GetCurrentEnvironment());
         ksort(self::$aAllIcons);
     }
     $aValues = array();
     foreach (self::$aAllIcons as $sFilePath) {
         $aValues[] = array('value' => $sFilePath, 'label' => basename($sFilePath), 'icon' => utils::GetAbsoluteUrlModulesRoot() . $sFilePath);
     }
     $this->SetAllowedValues($aValues);
 }
Пример #13
0
    $oP->p(Dict::Format('bkp-next-backup', $aWeekDayToString[$oNext->Format('N')], $oNext->Format('Y-m-d'), $oNext->Format('H:i')));
    $oP->p('<button onclick="LaunchBackupNow();">' . Dict::S('bkp-button-backup-now') . '</button>');
    $oP->add('<div id="backup_success" class="header_message message_ok" style="display: none;"></div>');
    $oP->add('<div id="backup_errors" class="header_message message_error" style="display: none;"></div>');
    $oP->add('<input type="hidden" name="restore_token" id="restore_token"/>');
    $sConfirmBackup = addslashes(Dict::S('bkp-confirm-backup'));
    $sPleaseWaitBackup = addslashes(Dict::S('bkp-wait-backup'));
    $sPleaseWaitRestore = addslashes(Dict::S('bkp-wait-restore'));
    $sRestoreDone = addslashes(Dict::S('bkp-success-restore'));
    $sMySQLBinDir = addslashes(MetaModel::GetConfig()->GetModuleSetting('itop-backup', 'mysql_bindir', ''));
    $sDBHost = addslashes(MetaModel::GetConfig()->GetDBHost());
    $sDBUser = addslashes(MetaModel::GetConfig()->GetDBUser());
    $sDBPwd = addslashes(MetaModel::GetConfig()->GetDBPwd());
    $sDBName = addslashes(MetaModel::GetConfig()->GetDBName());
    $sDBSubName = addslashes(MetaModel::GetConfig()->GetDBSubName());
    $sEnvironment = addslashes(utils::GetCurrentEnvironment());
    $oP->add_script(<<<EOF
function LaunchBackupNow()
{
\t\$('#backup_success').hide();
\t\$('#backup_errors').hide();

\tif (confirm('{$sConfirmBackup}'))
\t{
\t\t\$.blockUI({ message: '<h1><img src="../images/indicator.gif" /> {$sPleaseWaitBackup}</h1>' });

\t\tvar oParams = {};
\t\toParams.operation = 'backup';
\t\t\$.post(GetAbsoluteUrlModulePage('itop-backup', 'ajax.backup.php'), oParams, function(data){
\t\t\tif (data.search(/error|exceptio|notice|warning/i) != -1)
\t\t\t{
 /**
  * Renders (in PDF) the key (legend) of the graphics vertically to the left of the specified zone (xmin,ymin, xmax,ymax),
  * and the comment (if any) at the bottom of the page. Returns the position of remaining area.
  * @param TCPDF $oPdf
  * @param string $sComments
  * @param float $xMin
  * @param float $yMin
  * @param float $xMax
  * @param float $yMax
  * @param hash $aContextDefs
  * @return hash An array ('xmin' => , 'xmax' => ,'ymin' => , 'ymax' => ) of the remaining available area to paint the graph
  */
 protected function RenderKey(TCPDF $oPdf, $sComments, $xMin, $yMin, $xMax, $yMax, $aContextDefs)
 {
     $fFontSize = 7;
     // in mm
     $fIconSize = 6;
     // in mm
     $fPadding = 1;
     // in mm
     $oIterator = new RelationTypeIterator($this, 'Node');
     $fMaxWidth = max($oPdf->GetStringWidth(Dict::S('UI:Relation:Key')) - $fIconSize, $oPdf->GetStringWidth(Dict::S('UI:Relation:Comments')) - $fIconSize);
     $aClasses = array();
     $aIcons = array();
     $aContexts = array();
     $aContextIcons = array();
     $oPdf->SetFont('dejavusans', '', $fFontSize, '', true);
     foreach ($oIterator as $sId => $oNode) {
         if ($sClass = $oNode->GetObjectClass()) {
             if (!array_key_exists($sClass, $aClasses)) {
                 $sClassLabel = MetaModel::GetName($sClass);
                 $width = $oPdf->GetStringWidth($sClassLabel);
                 $fMaxWidth = max($width, $fMaxWidth);
                 $aClasses[$sClass] = $sClassLabel;
                 $sIconUrl = $oNode->GetProperty('icon_url');
                 $sIconPath = str_replace(utils::GetAbsoluteUrlModulesRoot(), APPROOT . 'env-' . utils::GetCurrentEnvironment() . '/', $sIconUrl);
                 $aIcons[$sClass] = $sIconPath;
             }
         }
         $aContextRootCauses = $oNode->GetProperty('context_root_causes');
         if (!is_null($aContextRootCauses)) {
             foreach ($aContextRootCauses as $key => $aObjects) {
                 $aContexts[$key] = Dict::S($aContextDefs[$key]['dict']);
                 $aContextIcons[$key] = APPROOT . 'env-' . utils::GetCurrentEnvironment() . '/' . $aContextDefs[$key]['icon'];
             }
         }
     }
     $oPdf->SetXY($xMin + $fPadding, $yMin + $fPadding);
     $yPos = $yMin + $fPadding;
     $oPdf->SetFillColor(225, 225, 225);
     $oPdf->Cell($fIconSize + $fPadding + $fMaxWidth, $fIconSize + $fPadding, Dict::S('UI:Relation:Key'), 0, 1, 'C', true);
     $yPos += $fIconSize + 2 * $fPadding;
     foreach ($aClasses as $sClass => $sLabel) {
         $oPdf->SetX($xMin + $fIconSize + $fPadding);
         $oPdf->Cell(0, $fIconSize + 2 * $fPadding, $sLabel, 0, 1);
         $oPdf->Image($aIcons[$sClass], $xMin + 1, $yPos, $fIconSize, $fIconSize);
         $yPos += $fIconSize + 2 * $fPadding;
     }
     foreach ($aContexts as $key => $sLabel) {
         $oPdf->SetX($xMin + $fIconSize + $fPadding);
         $oPdf->Cell(0, $fIconSize + 2 * $fPadding, $sLabel, 0, 1);
         $oPdf->Image($aContextIcons[$key], $xMin + 1 + $fIconSize * 0.125, $yPos + $fIconSize * 0.125, $fIconSize * 0.75, $fIconSize * 0.75);
         $yPos += $fIconSize + 2 * $fPadding;
     }
     $oPdf->Rect($xMin, $yMin, $fMaxWidth + $fIconSize + 3 * $fPadding, $yMax - $yMin, 'D');
     if ($sComments != '') {
         // Draw the comment text (surrounded by a rectangle)
         $xPos = $xMin + $fMaxWidth + $fIconSize + 4 * $fPadding;
         $w = $xMax - $xPos - 2 * $fPadding;
         $iNbLines = 1;
         $sText = '<p>' . str_replace("\n", '<br/>', htmlentities($sComments, ENT_QUOTES, 'UTF-8'), $iNbLines) . '</p>';
         $fLineHeight = $oPdf->getStringHeight($w, $sText);
         $h = (1 + $iNbLines) * $fLineHeight;
         $yPos = $yMax - 2 * $fPadding - $h;
         $oPdf->writeHTMLCell($w, $h, $xPos + $fPadding, $yPos + $fPadding, $sText, 0, 1);
         $oPdf->Rect($xPos, $yPos, $w + 2 * $fPadding, $h + 2 * $fPadding, 'D');
         $yMax = $yPos - $fPadding;
     }
     return array('xmin' => $xMin + $fMaxWidth + $fIconSize + 4 * $fPadding, 'xmax' => $xMax, 'ymin' => $yMin, 'ymax' => $yMax);
 }