Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
* refs #3835
Browse files Browse the repository at this point in the history
  • Loading branch information
Lionel Assepo committed Oct 21, 2015
1 parent de23c00 commit c1df94c
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions www/lib/HTML/QuickForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -2019,6 +2019,49 @@ function errorMessage($value)
return isset($errorMessages[$value]) ? $errorMessages[$value] : $errorMessages[QUICKFORM_ERROR];
} // end func errorMessage

/**
*
*/
function createSecurityToken()
{
$token = md5(uniqid());
$_SESSION['x-centreon-token'] = $token;
$_SESSION['x-centreon-token-generated-at'] = time();

$myTokenElement = $this->addElement('hidden', 'centreon_token');
$myTokenElement->setValue($token);
}

/**
*
* @param type $submittedValues
* @return boolean
*/
function checkSecurityToken($submittedValues)
{
$success = false;

if (isset($submittedValues['centreon_token']) && isset($_SESSION['x-centreon-token']) && isset($_SESSION['x-centreon-token-generated-at'])) {
$elapsedTime = time() - $_SESSION['x-centreon-token-generated-at'];
if ($elapsedTime < (15 * 60)) {
if ($submittedValues['centreon_token'] == $_SESSION['x-centreon-token']) {
unset($_SESSION['x-centreon-token']);
unset($_SESSION['x-centreon-token-generated-at']);
$success = true;
}
}
}

if ($success) {
$error = true;
} else {
$error = array('centreon_token' => 'The Token is invalid');
echo "<div class='msg' align='center'>"._("The CRSF token is invalid")."</div>";
}

return $error;
}

// }}}
} // end class HTML_QuickForm

Expand Down

0 comments on commit c1df94c

Please sign in to comment.