Files
api/services/nginx/app/routes/moduleConfigRoute.php
T
Jepp9350 849f1cc53e Add GatewayAPI module with configuration, routing, and core logic
Introduced a new GatewayAPI module to handle SMS messaging integration. This includes interfaces, core classes for API interaction, configuration management, and routing for config retrieval and update. Added necessary initializations in `index.php` to integrate the module seamlessly.
2025-04-10 10:51:32 +02:00

375 lines
15 KiB
PHP

<?php
namespace routes;
use classes\authentication;
use classes\backup_store;
use classes\economic;
use classes\email;
use classes\fxratesapi;
use classes\motorapi;
use classes\recaptcha;
use classes\response;
use classes\router;
use classes\stripe;
use objects\logs_o;
use traits\route_t;
class moduleConfigRoute
{
use route_t;
public function run(): void
{
global /** @var response $response */
/** @var router $router */
$router, $response;
/** Economic config > GET */
$this->get('/economic/config', function () {
global $response;
$this->requirePermission('economic_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('economic_config', 'global', 1, $user->id, 'ECONOMIC_CONFIG', 'Successfully fetched economic config');
$response->success(
(new economic())->config->getConfigRequest()
);
} else {
(new logs_o())->add('economic_config', 'global', 1, 0, 'ECONOMIC_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'economic_config' => 'Get economic config'
]
);
/** Economic config > POST */
$this->post('/economic/config', function () {
global $response;
$this->requirePermission('economic_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('economic_config', 'global', 1, $user->id, 'ECONOMIC_CONFIG', 'Successfully updated economic config');
$response->success(
(new economic())->config->postConfigRequest()
);
} else {
(new logs_o())->add('economic_config', 'global', 1, 0, 'ECONOMIC_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'economic_config' => 'Update economic config'
]
);
/** reCAPTCHA config > GET */
$this->get('/reCAPTCHA/config', function () {
global $response;
$this->requirePermission('recaptcha_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('recaptcha_config', 'global', 1, $user->id, 'RECAPTCHA_CONFIG', 'Successfully fetched recaptcha config');
$response->success(
(new recaptcha())->config->getConfigRequest()
);
} else {
(new logs_o())->add('recaptcha_config', 'global', 1, 0, 'RECAPTCHA_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'recaptcha_config' => 'Get recaptcha config'
]
);
/** reCAPTCHA config > POST */
$this->post('/reCAPTCHA/config', function () {
global $response;
$this->requirePermission('recaptcha_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('recaptcha_config', 'global', 1, $user->id, 'RECAPTCHA_CONFIG', 'Successfully updated recaptcha config');
$response->success(
(new recaptcha())->config->postConfigRequest()
);
} else {
(new logs_o())->add('recaptcha_config', 'global', 1, 0, 'RECAPTCHA_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'recaptcha_config' => 'Update recaptcha config'
]
);
/** Email config > GET */
$this->get('/email/config', function () {
global $response;
$this->requirePermission('email_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('email_config', 'global', 1, $user->id, 'EMAIL_CONFIG', 'Successfully fetched email config');
$response->success(
(new email())->config->getConfigRequest()
);
} else {
(new logs_o())->add('email_config', 'global', 1, 0, 'EMAIL_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'email_config' => 'Get email config'
]
);
/** Email config > POST */
$this->post('/email/config', function () {
global $response;
$this->requirePermission('email_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('email_config', 'global', 1, $user->id, 'EMAIL_CONFIG', 'Successfully updated email config');
$response->success(
(new email())->config->postConfigRequest()
);
} else {
(new logs_o())->add('email_config', 'global', 1, 0, 'EMAIL_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'email_config' => 'Update email config'
]
);
/** Email config > TEST */
$this->post('/email/config/test', function () {
global $response;
$this->requirePermission('email_config');
$user = (new authentication())->get_user();
if ($user) {
$test_recipient = $this->fromRequest('email');
if (!$test_recipient) {
(new logs_o())->add('email_config', 'global', 1, $user->id, 'EMAIL_CONFIG', 'Test email recipient not set');
$response->error('Test email recipient not set', 400);
}
// Check if the test recipient is a valid email
if (!filter_var($test_recipient, FILTER_VALIDATE_EMAIL)) {
(new logs_o())->add('email_config', 'global', 1, $user->id, 'EMAIL_CONFIG', 'Invalid test email recipient');
$response->error('Invalid test email recipient', 400);
}
// Log the incident
(new logs_o())->add('email_config', 'global', 1, $user->id, 'EMAIL_CONFIG', 'Successfully tested email config');
$response->success(
(new email())->testConfigRequest($test_recipient)
);
} else {
(new logs_o())->add('email_config', 'global', 1, 0, 'EMAIL_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'email_config' => 'Test email config'
]
);
$this->get('/backups/config', function () {
global $response;
$this->requirePermission('backups_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('backups_config', 'global', 1, $user->id, 'BACKUPS_CONFIG', 'Successfully fetched backups config');
$response->success(
(new backup_store())->config->getConfigRequest()
);
} else {
(new logs_o())->add('backups_config', 'global', 1, 0, 'BACKUPS_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'backups_config' => 'Get backups config'
]
);
$this->post('/backups/config', function () {
global $response;
$this->requirePermission('backups_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('backups_config', 'global', 1, $user->id, 'BACKUPS_CONFIG', 'Successfully updated backups config');
$response->success(
(new backup_store())->config->postConfigRequest()
);
} else {
(new logs_o())->add('backups_config', 'global', 1, 0, 'BACKUPS_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'backups_config' => 'Update backups config'
]
);
/** MotorAPI config > GET */
$this->get('/motorapi/config', function () {
global $response;
$this->requirePermission('motorapi_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('motorapi_config', 'global', 1, $user->id, 'MOTORAPI_CONFIG', 'Successfully fetched motorapi config');
$response->success(
(new motorapi())->config->getConfigRequest()
);
} else {
(new logs_o())->add('motorapi_config', 'global', 1, 0, 'MOTORAPI_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'motorapi_config' => 'Get motorapi config'
]
);
/** MotorAPI config > POST */
$this->post('/motorapi/config', function () {
global $response;
$this->requirePermission('motorapi_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('motorapi_config', 'global', 1, $user->id, 'MOTORAPI_CONFIG', 'Successfully updated motorapi config');
$response->success(
(new motorapi())->config->postConfigRequest()
);
} else {
(new logs_o())->add('motorapi_config', 'global', 1, 0, 'MOTORAPI_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'motorapi_config' => 'Update motorapi config'
]
);
/** Stripe config > GET */
$this->get('/stripe/config', function () {
global $response;
$this->requirePermission('stripe_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('stripe_config', 'global', 1, $user->id, 'STRIPE_CONFIG', 'Successfully fetched stripe config');
$response->success(
(new stripe())->config->getConfigRequest()
);
} else {
(new logs_o())->add('stripe_config', 'global', 1, 0, 'STRIPE_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'stripe_config' => 'Get stripe config'
]
);
/** Stripe config > POST */
$this->post('/stripe/config', function () {
global $response;
$this->requirePermission('stripe_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('stripe_config', 'global', 1, $user->id, 'STRIPE_CONFIG', 'Successfully updated stripe config');
$response->success(
(new stripe())->config->postConfigRequest()
);
} else {
(new logs_o())->add('stripe_config', 'global', 1, 0, 'STRIPE_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'stripe_config' => 'Update stripe config'
]
);
/** FXRatesAPI config > GET */
$this->get('/fxratesapi/config', function () {
global $response;
$this->requirePermission('fxratesapi_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('fxratesapi_config', 'global', 1, $user->id, 'FXRATESAPI_CONFIG', 'Successfully fetched fxratesapi config');
$response->success(
(new fxratesapi())->config->getConfigRequest()
);
} else {
(new logs_o())->add('fxratesapi_config', 'global', 1, 0, 'FXRATESAPI_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'fxratesapi_config' => 'Get fxratesapi config'
]
);
/** FXRatesAPI config > POST */
$this->post('/fxratesapi/config', function () {
global $response;
$this->requirePermission('fxratesapi_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('fxratesapi_config', 'global', 1, $user->id, 'FXRATESAPI_CONFIG', 'Successfully updated fxratesapi config');
$response->success(
(new fxratesapi())->config->postConfigRequest()
);
} else {
(new logs_o())->add('fxratesapi_config', 'global', 1, 0, 'FXRATESAPI_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'fxratesapi_config' => 'Update fxratesapi config'
]
);
/** GatewayAPI config > GET */
$this->get('/gatewayapi/config', function () {
global $response;
$this->requirePermission('gatewayapi_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('gatewayapi_config', 'global', 1, $user->id, 'GATEWAYAPI_CONFIG', 'Successfully fetched gatewayapi config');
$response->success(
(new \classes\gatewayapi())->config->getConfigRequest()
);
} else {
(new logs_o())->add('gatewayapi_config', 'global', 1, 0, 'GATEWAYAPI_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'gatewayapi_config' => 'Get gatewayapi config'
]
);
/** GatewayAPI config > POST */
$this->post('/gatewayapi/config', function () {
global $response;
$this->requirePermission('gatewayapi_config');
$user = (new authentication())->get_user();
if ($user) {
(new logs_o())->add('gatewayapi_config', 'global', 1, $user->id, 'GATEWAYAPI_CONFIG', 'Successfully updated gatewayapi config');
$response->success(
(new \classes\gatewayapi())->config->postConfigRequest()
);
} else {
(new logs_o())->add('gatewayapi_config', 'global', 1, 0, 'GATEWAYAPI_CONFIG', 'No user found, or invalid session');
$response->error('Invalid session', 400);
}
},
[
'gatewayapi_config' => 'Update gatewayapi config'
]
);
}
}