/** * Displays the specified 'step' of the wizard * @param WizardStep $oStep The 'step' to display */ protected function DisplayStep(WizardStep $oStep) { $oPage = new SetupPage($oStep->GetTitle()); if ($oStep->RequiresWritableConfig()) { $sConfigFile = utils::GetConfigFilePath(); if (file_exists($sConfigFile)) { // The configuration file already exists if (!is_writable($sConfigFile)) { $oP = new SetupPage('Installation Cannot Continue'); $oP->add("<h2>Fatal error</h2>\n"); $oP->error("<b>Error:</b> the configuration file '" . $sConfigFile . "' already exists and cannot be overwritten."); $oP->p("The wizard cannot modify the configuration file for you. If you want to upgrade " . ITOP_APPLICATION . ", make sure that the file '<b>" . realpath($sConfigFile) . "</b>' can be modified by the web server."); $oP->output(); return; } } } $oPage->add_linked_script('../setup/setup.js'); $oPage->add_script("function CanMoveForward()\n{\n" . $oStep->JSCanMoveForward() . "\n}\n"); $oPage->add_script("function CanMoveBackward()\n{\n" . $oStep->JSCanMoveBackward() . "\n}\n"); $oPage->add('<form id="wiz_form" method="post">'); $oStep->Display($oPage); // Add the back / next buttons and the hidden form // to store the parameters $oPage->add('<input type="hidden" id="_class" name="_class" value="' . get_class($oStep) . '"/>'); $oPage->add('<input type="hidden" id="_state" name="_state" value="' . $oStep->GetState() . '"/>'); foreach ($this->aParameters as $sCode => $value) { $oPage->add('<input type="hidden" name="_params[' . $sCode . ']" value="' . htmlentities($value, ENT_QUOTES, 'UTF-8') . '"/>'); } $oPage->add('<input type="hidden" name="_steps" value="' . htmlentities(json_encode($this->aSteps), ENT_QUOTES, 'UTF-8') . '"/>'); $oPage->add('<table style="width:100%;"><tr>'); if (count($this->aSteps) > 0 && $oStep->CanMoveBackward()) { $oPage->add('<td style="text-align: left"><button id="btn_back" type="submit" name="operation" value="back"> << Back </button></td>'); } if ($oStep->CanMoveForward()) { $oPage->add('<td style="text-align:right;"><button id="btn_next" class="default" type="submit" name="operation" value="next">' . htmlentities($oStep->GetNextButtonLabel(), ENT_QUOTES, 'UTF-8') . '</button></td>'); } $oPage->add('</tr></table>'); $oPage->add("</form>"); $oPage->add('<div id="async_action" style="display:none;overflow:auto;max-height:100px;color:#F00;font-size:small;"></div>'); // The div may become visible in case of error // Hack to have the "Next >>" button, be the default button, since the first submit button in the form is the default one $oPage->add_ready_script(<<<EOF \$('form').each(function () { \tvar thisform = \$(this); \t\tthisform.prepend(thisform.find('button.default').clone().removeAttr('id').removeAttr('disabled').css({ \t\tposition: 'absolute', \t\tleft: '-999px', \t\ttop: '-999px', \t\theight: 0, \t\twidth: 0 \t})); }); \$('#btn_back').click(function() { \$('#wiz_form').data('back', true); }); \$('#wiz_form').submit(function() { \tif (\$(this).data('back')) \t{ \t\treturn CanMoveBackward(); \t} \telse \t{ \t\treturn CanMoveForward(); \t} }); \$('#wiz_form').data('back', false); WizardUpdateButtons(); EOF ); $oPage->output(); }
/** * Check if the user is already authentified, if yes, then performs some additional validations to redirect towards the desired "portal" * @param string|null $sRequestedPortalId The requested "portal" interface, null for any * @param bool $bMustBeAdmin Whether or not the user must be an admin to access the current page * @param int iOnExit What action to take if the user is not logged on (one of the class constants EXIT_...) */ static function DoLoginEx($sRequestedPortalId = null, $bMustBeAdmin = false, $iOnExit = self::EXIT_PROMPT) { $operation = utils::ReadParam('loginop', ''); $sMessage = self::HandleOperations($operation); // May exit directly $iRet = self::Login($iOnExit); if ($iRet == self::EXIT_CODE_OK) { if ($bMustBeAdmin && !UserRights::IsAdministrator()) { if ($iOnExit == self::EXIT_RETURN) { return self::EXIT_CODE_MUSTBEADMIN; } else { require_once APPROOT . '/setup/setuppage.class.inc.php'; $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError')); $oP->add("<h1>" . Dict::S('UI:Login:Error:AccessAdmin') . "</h1>\n"); $oP->p("<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/logoff.php\">" . Dict::S('UI:LogOffMenu') . "</a>"); $oP->output(); exit; } } $iRet = call_user_func(array(self::$sHandlerClass, 'ChangeLocation'), $sRequestedPortalId, $iOnExit); } if ($iOnExit == self::EXIT_RETURN) { return $iRet; } else { return $sMessage; } }
$oLog->Set('impact', 'Page could not be displayed'); $oLog->Set('callstack', $e->getTrace()); $oLog->Set('data', $e->getContextData()); $oLog->DBInsertNoReload(); } catch (Exception $e) { IssueLog::Error("Failed to log issue into the DB"); } } IssueLog::Error($e->getMessage()); } // For debugging only //throw $e; } catch (Exception $e) { require_once APPROOT . '/setup/setuppage.class.inc.php'; $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError')); $oP->add("<h1>" . Dict::S('UI:FatalErrorMessage') . "</h1>\n"); $oP->error(Dict::Format('UI:Error_Details', $e->getMessage())); //$oP->p($e->getTraceAsString()); $oP->output(); if (MetaModel::IsLogEnabledIssue()) { if (MetaModel::IsValidClass('EventIssue')) { try { $oLog = new EventIssue(); $oLog->Set('message', $e->getMessage()); $oLog->Set('userinfo', ''); $oLog->Set('issue', 'PHP Exception'); $oLog->Set('impact', 'Page could not be displayed'); $oLog->Set('callstack', $e->getTrace()); $oLog->Set('data', array()); $oLog->DBInsertNoReload(); } catch (Exception $e) {
/** * Display the form for the second step of the configuration wizard * which consists in sending an email, which maybe a problem under Windows */ function DisplayStep2(SetupPage $oP, $sFrom, $sTo) { //$sNextOperation = 'step3'; $oP->add("<h1>iTop configuration wizard</h1>\n"); $oP->add("<h2>Step 2: send an email</h2>\n"); $oP->add("<p>Sending an email to '{$sTo}'... (From: '{$sFrom}')</p>\n"); $oP->add("<form method=\"post\">\n"); $oEmail = new Email(); $oEmail->SetRecipientTO($sTo); $oEmail->SetRecipientFrom($sFrom); $oEmail->SetSubject("Test iTop"); $oEmail->SetBody("<p>Hello,</p><p>The email function is now working fine.</p><p>You may now be able to use the notification function.</p><p>iTop</p>"); $iRes = $oEmail->Send($aIssues, true); switch ($iRes) { case EMAIL_SEND_OK: $sTransport = MetaModel::GetConfig()->Get('email_transport'); if ($sTransport == 'LogFile') { $oP->ok("The email has been logged into the file " . APPROOT . "/log/mail.log."); } else { $oP->ok("The email has been sent, check your inbox for the incoming mail..."); } $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n"); break; case EMAIL_SEND_PENDING: $oP->ok("Email queued"); $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n"); break; case EMAIL_SEND_ERROR: foreach ($aIssues as $sError) { $oP->error($sError); } $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n"); break; } }
/** * Ask the user what are the settings for the data load */ function DisplayStep1(SetupPage $oP) { $sNextOperation = 'step2'; $oP->add("<h1>iTop benchmarking</h1>\n"); $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Evaluating real plans...', 10)\">\n"); $oP->add("<fieldset><legend>Data load configuration</legend>\n"); $aForm = array(); $aForm[] = array('label' => "Contacts:", 'input' => "<input id=\"from\" type=\"text\" name=\"plannedcontacts\" value=\"100\">", 'help' => ''); $aForm[] = array('label' => "Contracts:", 'input' => "<input id=\"from\" type=\"text\" name=\"plannedcontracts\" value=\"10\">", 'help' => ''); $oP->form($aForm); $oP->add("</fieldset>\n"); $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_structure\">\n"); $oP->add("<button type=\"submit\">Next >></button>\n"); $oP->add("</form>\n"); $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Evaluating real plans...', 10)\">\n"); $oP->add("<fieldset><legend>Data load configuration</legend>\n"); $aForm = array(); $aForm[] = array('label' => "Main CIs:", 'input' => "<input id=\"to\" type=\"text\" name=\"plannedcis\" value=\"70\">", 'help' => ' exclude interfaces, subnets or any other type of secondary CI'); $oP->form($aForm); $oP->add("</fieldset>\n"); $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_cis\">\n"); $oP->add("<button type=\"submit\">Next >></button>\n"); $oP->add("</form>\n"); $oP->add("<form method=\"post\" onSubmit=\"return DoSubmit('Evaluating real plans...', 10)\">\n"); $oP->add("<fieldset><legend>Data load configuration</legend>\n"); $aForm = array(); $aForm[] = array('label' => "Tickets:", 'input' => "<input id=\"to\" type=\"text\" name=\"plannedtickets\" value=\"200\">", 'help' => ' 50% incidents, 50% changes'); $aForm[] = array('label' => "CIs for the big ticket:", 'input' => "<input id=\"to\" type=\"text\" name=\"plannedbigticketcis\" value=\"200\">", 'help' => 'Number of CI for the single big ticket'); $oP->form($aForm); $oP->add("</fieldset>\n"); $oP->add("<input type=\"hidden\" name=\"operation\" value=\"create_tickets\">\n"); $oP->add("<button type=\"submit\">Next >></button>\n"); $oP->add("</form>\n"); }
/** * Check if the user is already authentified, if yes, then performs some additional validations: * - if $bMustBeAdmin is true, then the user must be an administrator, otherwise an error is displayed * - if $bIsAllowedToPortalUsers is false and the user has only access to the portal, then the user is redirected to the portal * @param bool $bMustBeAdmin Whether or not the user must be an admin to access the current page * @param bool $bIsAllowedToPortalUsers Whether or not the current page is considered as part of the portal * @param int iOnExit What action to take if the user is not logged on (one of the class constants EXIT_...) */ static function DoLogin($bMustBeAdmin = false, $bIsAllowedToPortalUsers = false, $iOnExit = self::EXIT_PROMPT) { $sMessage = ''; // In case we need to return a message to the calling web page $operation = utils::ReadParam('loginop', ''); if ($operation == 'logoff') { if (isset($_SESSION['login_mode'])) { $sLoginMode = $_SESSION['login_mode']; } else { $aAllowedLoginTypes = MetaModel::GetConfig()->GetAllowedLoginTypes(); if (count($aAllowedLoginTypes) > 0) { $sLoginMode = $aAllowedLoginTypes[0]; } else { $sLoginMode = 'form'; } } self::ResetSession(); $oPage = self::NewLoginWebPage(); $oPage->DisplayLoginForm($sLoginMode, false); $oPage->output(); exit; } else { if ($operation == 'forgot_pwd') { $oPage = self::NewLoginWebPage(); $oPage->DisplayForgotPwdForm(); $oPage->output(); exit; } else { if ($operation == 'forgot_pwd_go') { $oPage = self::NewLoginWebPage(); $oPage->ForgotPwdGo(); $oPage->output(); exit; } else { if ($operation == 'reset_pwd') { $oPage = self::NewLoginWebPage(); $oPage->DisplayResetPwdForm(); $oPage->output(); exit; } else { if ($operation == 'do_reset_pwd') { $oPage = self::NewLoginWebPage(); $oPage->DoResetPassword(); $oPage->output(); exit; } else { if ($operation == 'change_pwd') { $sAuthUser = $_SESSION['auth_user']; UserRights::Login($sAuthUser); // Set the user's language $oPage = self::NewLoginWebPage(); $oPage->DisplayChangePwdForm(); $oPage->output(); exit; } } } } } } if ($operation == 'do_change_pwd') { $sAuthUser = $_SESSION['auth_user']; UserRights::Login($sAuthUser); // Set the user's language $sOldPwd = utils::ReadPostedParam('old_pwd', '', false, 'raw_data'); $sNewPwd = utils::ReadPostedParam('new_pwd', '', false, 'raw_data'); if (UserRights::CanChangePassword() && (!UserRights::CheckCredentials($sAuthUser, $sOldPwd) || !UserRights::ChangePassword($sOldPwd, $sNewPwd))) { $oPage = self::NewLoginWebPage(); $oPage->DisplayChangePwdForm(true); // old pwd was wrong $oPage->output(); exit; } $sMessage = Dict::S('UI:Login:PasswordChanged'); } $iRet = self::Login($iOnExit); if ($iRet == self::EXIT_CODE_OK) { if ($bMustBeAdmin && !UserRights::IsAdministrator()) { if ($iOnExit == self::EXIT_RETURN) { return self::EXIT_CODE_MUSTBEADMIN; } else { require_once APPROOT . '/setup/setuppage.class.inc.php'; $oP = new SetupPage(Dict::S('UI:PageTitle:FatalError')); $oP->add("<h1>" . Dict::S('UI:Login:Error:AccessAdmin') . "</h1>\n"); $oP->p("<a href=\"" . utils::GetAbsoluteUrlAppRoot() . "pages/logoff.php\">" . Dict::S('UI:LogOffMenu') . "</a>"); $oP->output(); exit; } } $iRet = call_user_func(array(self::$sHandlerClass, 'ChangeLocation'), $bIsAllowedToPortalUsers, $iOnExit); } if ($iOnExit == self::EXIT_RETURN) { return $iRet; } else { return $sMessage; } }
/** * Display the form for the second step of the configuration wizard * which consists in sending an email, which maybe a problem under Windows */ function DisplayStep2(SetupPage $oP, $sFrom, $sTo) { //$sNextOperation = 'step3'; $oP->add("<h1>iTop configuration wizard</h1>\n"); $oP->add("<h2>Step 2: send an email</h2>\n"); $oP->add("<p>Sending an email to '{$sTo}'... (From: '{$sFrom}')</p>\n"); $oP->add("<form method=\"post\">\n"); $oEmail = new Email(); $oEmail->SetRecipientTO($sTo); $oEmail->SetRecipientFrom($sFrom); $oEmail->SetSubject("Test iTop"); $oEmail->SetBody("<p>Hello,</p><p>The email function is now working fine.</p><p>You may now be able to use the notification function.</p><p>iTop</p>"); $iRes = $oEmail->Send($aIssues, true); switch ($iRes) { case EMAIL_SEND_OK: $oP->ok("The email has been sent, you may now check that the email will arrive..."); break; case EMAIL_SEND_PENDING: $oP->ok("Email queued"); $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n"); break; case EMAIL_SEND_ERROR: foreach ($aIssues as $sError) { $oP->error($sError); } $oP->add("<button onClick=\"window.history.back();\"><< Back</button>\n"); break; } }