[Web] Cache validation result in Redis
parent
6aa7664d79
commit
294e0bc07f
|
@ -5,6 +5,9 @@ if (isset($_SESSION['mailcow_cc_role']) && $_SESSION['mailcow_cc_role'] == "admi
|
||||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
|
require_once $_SERVER['DOCUMENT_ROOT'] . '/inc/header.inc.php';
|
||||||
$_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
|
$_SESSION['return_to'] = $_SERVER['REQUEST_URI'];
|
||||||
$tfa_data = get_tfa();
|
$tfa_data = get_tfa();
|
||||||
|
if (!isset($_SESSION['gal']) && $license_cache = $redis->Get('LICENSE_STATUS_CACHE')) {
|
||||||
|
$_SESSION['gal'] = json_decode($license_cache, true);
|
||||||
|
}
|
||||||
?>
|
?>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
|
|
||||||
|
@ -87,7 +90,7 @@ $tfa_data = get_tfa();
|
||||||
<div class="col-sm-9">
|
<div class="col-sm-9">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<span class="input-group-addon">
|
<span class="input-group-addon">
|
||||||
<span class="glyphicon <?=(isset($_SESSION['gal']['valid']) && $_SESSION['gal']['valid'] === true) ? 'glyphicon-heart text-danger' : 'glyphicon-remove';?>" aria-hidden="true"></span>
|
<span class="glyphicon <?=(isset($_SESSION['gal']['valid']) && $_SESSION['gal']['valid'] === "true") ? 'glyphicon-heart text-danger' : 'glyphicon-remove';?>" aria-hidden="true"></span>
|
||||||
</span>
|
</span>
|
||||||
<input type="text" id="guid" class="form-control" value="<?=license('guid');?>" readonly>
|
<input type="text" id="guid" class="form-control" value="<?=license('guid');?>" readonly>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1250,24 +1250,34 @@ function license($action, $data = null) {
|
||||||
$json_return = json_decode($response, true);
|
$json_return = json_decode($response, true);
|
||||||
if ($response && $json_return) {
|
if ($response && $json_return) {
|
||||||
if ($json_return['response'] === "ok") {
|
if ($json_return['response'] === "ok") {
|
||||||
$_SESSION['gal']['valid'] = true;
|
$_SESSION['gal']['valid'] = "true";
|
||||||
$_SESSION['gal']['c'] = $json_return['c'];
|
$_SESSION['gal']['c'] = $json_return['c'];
|
||||||
$_SESSION['gal']['s'] = $json_return['s'];
|
$_SESSION['gal']['s'] = $json_return['s'];
|
||||||
return true;
|
}
|
||||||
}
|
elseif ($json_return['response'] === "invalid") {
|
||||||
if ($json_return['response'] === "invalid") {
|
$_SESSION['gal']['valid'] = "false";
|
||||||
$_SESSION['gal']['valid'] = false;
|
|
||||||
$_SESSION['gal']['c'] = $lang['mailbox']['no'];
|
$_SESSION['gal']['c'] = $lang['mailbox']['no'];
|
||||||
$_SESSION['gal']['s'] = $lang['mailbox']['no'];
|
$_SESSION['gal']['s'] = $lang['mailbox']['no'];
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$_SESSION['gal']['valid'] = false;
|
$_SESSION['gal']['valid'] = "false";
|
||||||
$_SESSION['gal']['c'] = $lang['danger']['temp_error'];
|
$_SESSION['gal']['c'] = $lang['danger']['temp_error'];
|
||||||
$_SESSION['gal']['s'] = $lang['danger']['temp_error'];
|
$_SESSION['gal']['s'] = $lang['danger']['temp_error'];
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// json_encode needs "true"/"false" instead of true/false, to not encode it to 0 or 1
|
||||||
|
$redis->Set('LICENSE_STATUS_CACHE', json_encode($_SESSION['gal']));
|
||||||
|
}
|
||||||
|
catch (RedisException $e) {
|
||||||
|
$_SESSION['return'][] = array(
|
||||||
|
'type' => 'danger',
|
||||||
|
'log' => array(__FUNCTION__, $_action, $_data_log),
|
||||||
|
'msg' => array('redis_error', $e)
|
||||||
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return $_SESSION['gal']['valid'];
|
||||||
break;
|
break;
|
||||||
case "guid":
|
case "guid":
|
||||||
$stmt = $pdo->query("SELECT `version` FROM `versions` WHERE `application` = 'GUID'");
|
$stmt = $pdo->query("SELECT `version` FROM `versions` WHERE `application` = 'GUID'");
|
||||||
|
|
Loading…
Reference in New Issue