/** * Monitor the backup * * @copyright Copyright (C) 2013 Combodo SARL * @license http://opensource.org/licenses/AGPL-3.0 */ require_once('../../approot.inc.php'); require_once(APPROOT.'application/application.inc.php'); require_once(APPROOT.'application/itopwebpage.class.inc.php'); require_once(APPROOT.'application/startup.inc.php'); require_once(APPROOT.'application/loginwebpage.class.inc.php'); function TestConfig($sContents, $oP) { try { ini_set('display_errors', 1); ob_start(); eval('?'.'>'.trim($sContents)); $sNoise = trim(ob_get_contents()); ob_end_clean(); } catch (Exception $e) { // well, never reach in case of parsing error :-( throw new Exception('Error in configuration: '.$e->getMessage()); } if (strlen($sNoise) > 0) { if (preg_match("/(Error|Parse error|Notice|Warning): (.+) in \S+ : eval\(\)'d code on line (\d+)/i", strip_tags($sNoise), $aMatches)) { $sMessage = $aMatches[2]; $sLine = $aMatches[3]; $iLine = (int) $sLine; // Highlight the line $aLines = explode("\n", $sContents); $iStart = 0; for ($i = 0 ; $i < $iLine - 1; $i++) $iStart += strlen($aLines[$i]); $iEnd = $iStart + strlen($aLines[$iLine - 1]); $iTotalLines = count($aLines); $oP->add_ready_script( <<'.$sNoise.''); } } } ///////////////////////////////////////////////////////////////////// // Main program // LoginWebPage::DoLogin(true); // Check user rights and prompt if needed (must be admin) //$sOperation = utils::ReadParam('operation', 'menu'); //$oAppContext = new ApplicationContext(); $oP = new iTopWebPage(Dict::S('config-edit-title')); $oP->set_base(utils::GetAbsoluteUrlAppRoot().'pages/'); try { $sOperation = utils::ReadParam('operation', ''); $oP->add("

".Dict::S('config-edit-title')."

"); if (MetaModel::GetConfig()->Get('demo_mode')) { $oP->add("
Sorry, iTop is in demonstration mode: the configuration file cannot be edited.
"); } else { $oP->add_style( <<add('
'.Dict::S('config-no-change').'
'); } 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('
'.Dict::S('Successfully recorded.').'
'); $sOrginalConfig = str_replace("\r\n", "\n", file_get_contents($sConfigFile)); } catch (Exception $e) { $oP->p('
'.$e->getMessage().'
'); } } } else { $sConfig = str_replace("\r\n", "\n", file_get_contents($sConfigFile)); $sOrginalConfig = $sConfig; } $sConfigEscaped = htmlentities($sConfig, ENT_QUOTES, 'UTF-8'); $sOriginalConfigEscaped = htmlentities($sOrginalConfig, ENT_QUOTES, 'UTF-8'); $oP->p(Dict::S('config-edit-intro')); $oP->add("
"); $oP->add(""); $oP->add(""); $oP->add("".Dict::Format('config-current-line', "").""); $oP->add(""); $oP->add(""); $oP->add(""); $oP->add("".Dict::Format('config-current-line', "").""); $oP->add("
"); $sConfirmCancel = addslashes(Dict::S('config-confirm-cancel')); $oP->add_script( <<p(''.$e->getMessage().''); } $oP->output();