mirror of
https://github.com/newnius/YAO-portal.git
synced 2025-12-13 09:06:43 +00:00
init & add agent & add job
This commit is contained in:
36
Securer.class.php
Executable file
36
Securer.class.php
Executable file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
require_once('util4p/util.php');
|
||||
require_once('util4p/CRObject.class.php');
|
||||
require_once('util4p/Random.class.php');
|
||||
|
||||
class Securer
|
||||
{
|
||||
|
||||
/* configuration && initialization */
|
||||
public static function configure(CRObject $config)
|
||||
{
|
||||
}
|
||||
|
||||
/**/
|
||||
public static function set_csrf_token()
|
||||
{
|
||||
if (!isset($_COOKIE['csrf_token'])) {
|
||||
setcookie('csrf_token', Random::randomString(32));
|
||||
}
|
||||
}
|
||||
|
||||
/**/
|
||||
public static function validate_csrf_token()
|
||||
{
|
||||
$csrf_token = null;
|
||||
if (isset($_SERVER['HTTP_X_CSRF_TOKEN'])) {
|
||||
$csrf_token = $_SERVER['HTTP_X_CSRF_TOKEN'];
|
||||
}
|
||||
$success = $csrf_token !== null && isset($_COOKIE['csrf_token']) && $csrf_token === $_COOKIE['csrf_token'];
|
||||
/* whatever, refresh csrf_token to expire current token */
|
||||
setcookie('csrf_token', Random::randomString(32));
|
||||
return $success;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user