CMXX - Deactivate API when maintenancemode is ON
This commit is contained in:
29
api.php
29
api.php
@@ -65,6 +65,11 @@ if($is_jwt_valid && str_contains($version, 'v')) {
|
|||||||
{
|
{
|
||||||
echo null;
|
echo null;
|
||||||
}
|
}
|
||||||
|
//
|
||||||
|
//------------------------------------------
|
||||||
|
// Check for maintenance mode, exclude debug user
|
||||||
|
//------------------------------------------
|
||||||
|
if(maintenance_mode == false|| debug_id == $user_data['id']){
|
||||||
|
|
||||||
//------------------------------------------
|
//------------------------------------------
|
||||||
// Build up version and check if file is available
|
// Build up version and check if file is available
|
||||||
@@ -72,11 +77,15 @@ if($is_jwt_valid && str_contains($version, 'v')) {
|
|||||||
$api_file = './api/'.$version.'/get/'.$collection.'.php';
|
$api_file = './api/'.$version.'/get/'.$collection.'.php';
|
||||||
$api_file_post = './api/'.$version.'/post/'.$collection.'.php';
|
$api_file_post = './api/'.$version.'/post/'.$collection.'.php';
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
//GET CLEAN LANGUAGE CODE
|
//GET CLEAN LANGUAGE CODE
|
||||||
|
//------------------------------------------
|
||||||
$language_code = ($user_data['language']) ? $user_data['language'] : 'US';
|
$language_code = ($user_data['language']) ? $user_data['language'] : 'US';
|
||||||
$api_file_language = './settings/translations/translations_'.strtoupper($language_code).'.php';
|
$api_file_language = './settings/translations/translations_'.strtoupper($language_code).'.php';
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
//INCLUDE LANGUAGE FILE
|
//INCLUDE LANGUAGE FILE
|
||||||
|
//------------------------------------------
|
||||||
if (file_exists($api_file_language)){
|
if (file_exists($api_file_language)){
|
||||||
include_once $api_file_language; //Include the code
|
include_once $api_file_language; //Include the code
|
||||||
}
|
}
|
||||||
@@ -84,7 +93,9 @@ if($is_jwt_valid && str_contains($version, 'v')) {
|
|||||||
include_once './settings/translations/translations_US.php';
|
include_once './settings/translations/translations_US.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
//CHECK IF USER IS ALLOWED TO CALL SPECIFIC API
|
//CHECK IF USER IS ALLOWED TO CALL SPECIFIC API
|
||||||
|
//------------------------------------------
|
||||||
if (isAllowed($collection,$profile,$permission,'R') === 1 && empty($input) && file_exists($api_file)){
|
if (isAllowed($collection,$profile,$permission,'R') === 1 && empty($input) && file_exists($api_file)){
|
||||||
|
|
||||||
include_once $api_file;
|
include_once $api_file;
|
||||||
@@ -95,15 +106,27 @@ if($is_jwt_valid && str_contains($version, 'v')) {
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//------------------------------------------
|
||||||
|
// User not allowed to perform operation
|
||||||
|
//------------------------------------------
|
||||||
http_response_code(403); //Forbidden
|
http_response_code(403); //Forbidden
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//------------------------------------------
|
||||||
|
// Maintenance mode is activce -> service unavailable
|
||||||
|
//------------------------------------------
|
||||||
|
http_response_code(503); //Service Unavailable
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//------------------------------------------
|
|
||||||
// JWT not VALID
|
|
||||||
//------------------------------------------
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//------------------------------------------
|
||||||
|
// JWT not VALID
|
||||||
|
//------------------------------------------
|
||||||
http_response_code(403); //Forbidden
|
http_response_code(403); //Forbidden
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user