Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove some http_response_code()/exit()/die() usages #18068

Merged
8 changes: 3 additions & 5 deletions ajax/map.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,16 @@
* ---------------------------------------------------------------------
*/

use Glpi\Exception\Http\BadRequestHttpException;

header("Content-Type: application/json; charset=UTF-8");
Html::header_nocache();

Session::checkLoginUser();

$result = [];
if (!isset($_POST['itemtype']) || !isset($_POST['params'])) {
http_response_code(500);
$result = [
'success' => false,
'message' => __('Required argument missing!')
];
throw new BadRequestHttpException();
} else {
$itemtype = $_POST['itemtype'];
$params = $_POST['params'];
Expand Down
2 changes: 1 addition & 1 deletion front/central.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
Html::zeroSecurityIframedHeader($grid->getDashboard()->getTitle(), 'central', 'central');
$grid->embed($_REQUEST);
Html::popFooter();
exit;
return;
}

// Change profile system
Expand Down
4 changes: 3 additions & 1 deletion front/crontask.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* ---------------------------------------------------------------------
*/

use Glpi\Exception\Http\BadRequestHttpException;

/**
* Form to edit Cron Task
*/
Expand Down Expand Up @@ -79,7 +81,7 @@
Html::back();
} else {
if (!isset($_GET["id"]) || empty($_GET["id"])) {
exit();
throw new BadRequestHttpException();
}
$menus = ['config', 'crontask'];
CronTask::displayFullPageForItem($_GET['id'], $menus);
Expand Down
4 changes: 1 addition & 3 deletions front/initpassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
'title' => __('Forgotten initialization'),
'messages_only' => true,
]);
exit();
return;
}

$user = new User();
Expand All @@ -74,5 +74,3 @@
User::showPasswordInitRequestForm();
}
}

exit();
9 changes: 6 additions & 3 deletions front/locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@
if (!($messages instanceof \Laminas\I18n\Translator\TextDomain)) {
// No TextDomain found means that there is no translations for given domain.
// It is mostly related to plugins that does not provide any translations.
exit($default_response);
echo $default_response;
return;
}

// Extract headers from main po file
Expand All @@ -98,7 +99,8 @@
);
if (false === $po_file_handle) {
trigger_error(sprintf('Unable to extract locales data from "%s".', $po_file), E_USER_WARNING);
exit($default_response);
echo $default_response;
return;
}
$in_headers = false;
$headers = [];
Expand All @@ -122,7 +124,8 @@
}
if (count(array_diff($header_keys, array_keys($headers))) > 0) {
trigger_error(sprintf('Missing mandatory locale headers in "%s".', $po_file), E_USER_WARNING);
exit($default_response);
echo $default_response;
return;
}

// Output messages and headers
Expand Down
19 changes: 3 additions & 16 deletions front/login.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
* ---------------------------------------------------------------------
*/

use Glpi\Exception\AuthenticationFailedException;

/**
* @since 0.85
*/

use Glpi\Application\View\TemplateRenderer;

/**
* @var array $CFG_GLPI
*/
Expand Down Expand Up @@ -77,14 +77,6 @@

$remember = isset($_SESSION['rmbfield']) && isset($_POST[$_SESSION['rmbfield']]) && $CFG_GLPI["login_remember_time"];

// Redirect management
$REDIRECT = "";
if (isset($_POST['redirect']) && (strlen($_POST['redirect']) > 0)) {
$REDIRECT = "?redirect=" . rawurlencode($_POST['redirect']);
} else if (isset($_GET['redirect']) && strlen($_GET['redirect']) > 0) {
$REDIRECT = "?redirect=" . rawurlencode($_GET['redirect']);
}

$auth = new Auth();


Expand All @@ -102,10 +94,5 @@
if ($auth->login($login, $password, (isset($_REQUEST["noAUTO"]) ? $_REQUEST["noAUTO"] : false), $remember, $login_auth, $mfa_params)) {
Auth::redirectIfAuthenticated();
} else {
http_response_code(401);
TemplateRenderer::getInstance()->display('pages/login_error.html.twig', [
'errors' => $auth->getErrors(),
'login_url' => $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1' . str_replace("?", "&", $REDIRECT),
]);
exit();
throw new AuthenticationFailedException(authentication_errors: $auth->getErrors());
}
4 changes: 2 additions & 2 deletions front/logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@

// Redirect management
if (isset($_POST['redirect']) && (strlen($_POST['redirect']) > 0)) {
$toADD = "?redirect=" . $_POST['redirect'];
$toADD = "?redirect=" . rawurlencode($_POST['redirect']);
} else if (isset($_GET['redirect']) && (strlen($_GET['redirect']) > 0)) {
$toADD = "?redirect=" . $_GET['redirect'];
$toADD = "?redirect=" . rawurlencode($_GET['redirect']);
}

if (isset($_SESSION["noAUTO"]) || isset($_GET['noAUTO'])) {
Expand Down
4 changes: 1 addition & 3 deletions front/lostpassword.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
TemplateRenderer::getInstance()->display('forgotpassword.html.twig', [
'messages_only' => true,
]);
exit();
return;
}

$user = new User();
Expand All @@ -75,5 +75,3 @@
User::showPasswordForgetRequestForm();
}
}

exit();
2 changes: 1 addition & 1 deletion front/massiveaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
echo "</div>";

Html::popFooter();
exit();
return;
}
Html::popHeader(__('Bulk modification'), $_SERVER['PHP_SELF']);

Expand Down
2 changes: 1 addition & 1 deletion front/palette_preview.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
$blank = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=');
header(sprintf('Content-Length: %s', strlen($blank)));
echo $blank;
exit();
return;
}

header('Cache-Control: public, max-age=2592000, must-revalidate'); // 1 month cache
Expand Down
5 changes: 3 additions & 2 deletions front/pluginimage.send.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
*/

use Glpi\Event;
use Glpi\Exception\Http\AccessDeniedHttpException;

/** @var array $CFG_GLPI */
global $CFG_GLPI;
Expand All @@ -56,7 +57,7 @@
//TRANS: %s is user name
sprintf(__('%s makes a bad usage.'), $_SESSION["glpiname"])
);
die("security");
throw new AccessDeniedHttpException();
}

$dir = GLPI_PLUGIN_DOC_DIR . "/" . $_GET["plugin"] . "/";
Expand All @@ -78,7 +79,7 @@
"security",
sprintf(__('%s tries to use a non standard path.'), $_SESSION["glpiname"])
);
die("security");
throw new AccessDeniedHttpException();
}

// Now send the file with header() magic
Expand Down
2 changes: 1 addition & 1 deletion front/report.dynamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
// Plugin case
if ($plug = isPluginItemType($itemtype)) {
if (Plugin::doOneHook($plug['plugin'], 'dynamicReport', $_GET)) {
exit();
return;
}
}
$params = Search::manageParams($itemtype, $_GET);
Expand Down
4 changes: 2 additions & 2 deletions front/rule.common.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
&& $rulecollection->warningBeforeReplayRulesOnExistingDB($_SERVER['PHP_SELF'])
) {
Html::footer();
exit();
return;
}

echo "<table class='tab_cadrehov'>";
Expand Down Expand Up @@ -143,7 +143,7 @@
}

Html::footer();
exit();
return;
}

Html::header(
Expand Down
4 changes: 3 additions & 1 deletion front/rule.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
* ---------------------------------------------------------------------
*/

use Glpi\Exception\Http\BadRequestHttpException;

Session::checkCentralAccess();

if (isset($_POST["sub_type"])) {
Expand All @@ -53,7 +55,7 @@

/** @var Rule $rule */
if (!$rule = getItemForItemtype($sub_type)) {
exit;
throw new BadRequestHttpException();
}
$rule->checkGlobal(READ);

Expand Down
2 changes: 1 addition & 1 deletion front/smtp_oauth2_callback.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<body></body>
</html>
HTML;
exit;
return;
}

Session::checkRight("config", UPDATE);
Expand Down
3 changes: 2 additions & 1 deletion front/stat.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* ---------------------------------------------------------------------
*/

use Glpi\Exception\Http\BadRequestHttpException;
use Glpi\Stat\Data\Sglobal\StatDataAverageSatisfaction;
use Glpi\Stat\Data\Sglobal\StatDataSatisfaction;
use Glpi\Stat\Data\Sglobal\StatDataTicketAverageTime;
Expand Down Expand Up @@ -67,7 +68,7 @@
Stat::title();

if (!$item = getItemForItemtype($_GET['itemtype'])) {
exit;
throw new BadRequestHttpException();
}

$stat = new Stat();
Expand Down
3 changes: 2 additions & 1 deletion front/stat.graph.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

use Glpi\Application\View\TemplateRenderer;
use Glpi\Exception\Http\BadRequestHttpException;
use Glpi\Stat\Data\Graph\StatDataSatisfaction;
use Glpi\Stat\Data\Graph\StatDataSatisfactionSurvey;
use Glpi\Stat\Data\Graph\StatDataTicketAverageTime;
Expand All @@ -50,7 +51,7 @@

/** @var CommonITILObject $item */
if (!$item = getItemForItemtype($_GET['itemtype'])) {
exit;
throw new BadRequestHttpException();
}

//sanitize dates
Expand Down
2 changes: 1 addition & 1 deletion front/stat.location.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
) {
// Do nothing
Html::footer();
exit();
return;
}


Expand Down
3 changes: 2 additions & 1 deletion front/stat.tracking.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

use Glpi\Application\View\TemplateRenderer;
use Glpi\Exception\Http\BadRequestHttpException;
use Glpi\Stat\Data\Location\StatDataClosed;
use Glpi\Stat\Data\Location\StatDataLate;
use Glpi\Stat\Data\Location\StatDataOpened;
Expand All @@ -48,7 +49,7 @@
Session::checkRight("statistic", READ);

if (!$item = getItemForItemtype($_GET['itemtype'])) {
exit;
throw new BadRequestHttpException();
}

//sanitize dates
Expand Down
4 changes: 2 additions & 2 deletions front/transfer.action.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@
echo "<div class='fw-bold text-center'>" . __s('Operation successful') . "<br>";
echo "<a href='central.php' role='button' class='btn btn-primary'>" . __s('Back') . "</a></div>";
Html::footer();
exit();
return;
}
} else if (isset($_POST['clear'])) {
unset($_SESSION['glpitransfer_list']);
echo "<div class='fw-bold text-center'>" . __s('Operation successful') . "<br>";
echo "<a href='central.php' role='button' class='btn btn-primary'>" . __s('Back') . "</a></div>";
echo "</div>";
Html::footer();
exit();
return;
}

unset($_SESSION['glpimassiveactionselected']);
Expand Down
2 changes: 1 addition & 1 deletion install/update.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function showSecurityKeyCheckForm()
$result = Config::displayCheckDbEngine(true);
echo "</p>";
if ($result > 0) {
die(1);
return;
}
if (
$update->isExpectedSecurityKeyFileMissing()
Expand Down
2 changes: 1 addition & 1 deletion src/Glpi/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function call(): void
// Include the legacy API entrypoint and then die
$api = new \Glpi\Api\APIRest();
$api->call();
die();
return;
}

$supported_versions = Router::getAPIVersions();
Expand Down
17 changes: 8 additions & 9 deletions src/Glpi/Controller/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ private function call(): void
echo '</div>';
echo '</div>';
Html::nullFooter();
return;
}
die();
}

//Try to detect GLPI agent calls
$rawdata = file_get_contents("php://input");
if (!isset($_POST['totp_code']) && !empty($rawdata) && $_SERVER['REQUEST_METHOD'] === 'POST') {
include_once(GLPI_ROOT . '/front/inventory.php');
die();
return;
}

Session::checkCookieSecureConfig();
Expand Down Expand Up @@ -149,17 +149,16 @@ private function call(): void
}
}

// redirect to ticket
if ($redirect !== '') {
Toolbox::manageRedirect($redirect);
}

if (count($errors)) {
if (count($errors) > 0) {
TemplateRenderer::getInstance()->display('pages/login_error.html.twig', [
'errors' => $errors,
'login_url' => $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1&redirect=' . str_replace("?", "&", $redirect),
'login_url' => $CFG_GLPI["root_doc"] . '/front/logout.php?noAUTO=1&redirect=' . \rawurlencode($redirect),
]);
} else {
if ($redirect !== '') {
Toolbox::manageRedirect($redirect);
}

if (isset($_SESSION['mfa_pre_auth'], $_POST['skip_mfa'])) {
Html::redirect($CFG_GLPI['root_doc'] . '/front/login.php?skip_mfa=1');
}
Expand Down
Loading