Quite a few fixes in the CP, logs now match the rest

This commit is contained in:
Pinga 2024-11-27 18:03:39 +02:00
parent d312db4f14
commit 09a3ae3cc4
5 changed files with 71 additions and 65 deletions

View file

@ -32,8 +32,8 @@ class AuthController extends Controller
* @throws \DI\NotFoundException
*/
public function createLogin(Request $request, Response $response){
$isWebAuthnEnabled = envi('WEB_AUTHN_ENABLED') === 'true';
return view($response, 'auth/login.twig', ['isWebaEnabled' => $isWebaEnabled]);
$isWebAuthnEnabled = (envi('WEB_AUTHN_ENABLED') === 'true') ? true : false;
return view($response, 'auth/login.twig', ['isWebaEnabled' => $isWebAuthnEnabled]);
}
/**

View file

@ -2046,14 +2046,16 @@ class DomainsController extends Controller
[ $domain_id ]
);
foreach ($results as $row) {
$status = $row['status'];
if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) {
$this->container->get('flash')->addMessage('error', 'It has a status that does not allow deletion, first change the status');
return $response->withHeader('Location', '/domains')->withStatus(302);
if (is_array($results) && !empty($results)) {
foreach ($results as $row) {
$status = $row['status'];
if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) {
$this->container->get('flash')->addMessage('error', 'It has a status that does not allow deletion, first change the status');
return $response->withHeader('Location', '/domains')->withStatus(302);
}
}
}
$grace_period = 30;
$db->delete(
@ -2111,31 +2113,33 @@ class DomainsController extends Controller
'SELECT id FROM host WHERE domain_id = ?',
[$domain_id]
);
foreach ($hostIds as $host) {
$host_id = $host['id'];
// Delete operations
$db->delete(
'host_addr',
[
'host_id' => $host_id
]
);
$db->delete(
'host_status',
[
'host_id' => $host_id
]
);
$db->delete(
'domain_host_map',
[
'host_id' => $host_id
]
);
if (is_array($hostIds) && !empty($hostIds)) {
foreach ($hostIds as $host) {
$host_id = $host['id'];
// Delete operations
$db->delete(
'host_addr',
[
'host_id' => $host_id
]
);
$db->delete(
'host_status',
[
'host_id' => $host_id
]
);
$db->delete(
'domain_host_map',
[
'host_id' => $host_id
]
);
}
}
// Delete domain related records
$db->delete(
'domain_contact_map',

View file

@ -185,10 +185,10 @@ class HomeController extends Controller
]);
}
}
public function mode(Request $request, Response $response)
{
if ($_SESSION['_screen_mode'] == 'dark') {
if (isset($_SESSION['_screen_mode']) && $_SESSION['_screen_mode'] == 'dark') {
$_SESSION['_screen_mode'] = 'light';
} else {
$_SESSION['_screen_mode'] = 'dark';

View file

@ -692,14 +692,16 @@ class SystemController extends Controller
return $response->withHeader('Location', '/registry/tld/'.$tld_extension)->withStatus(302);
}
if ($data['dnssec_enable'] === 'on' && $data['bind9_enable'] === 'on') {
$dnssec_both = 1;
} elseif ($data['dnssec_enable'] === 'on' && $data['bind9_enable'] !== 'on') {
$this->container->get('flash')->addMessage('error', 'DNSSEC can be only enabled for BIND9');
return $response->withHeader('Location', '/registry/tld/'.$tld_extension)->withStatus(302);
} elseif ($data['dnssec_enable'] !== 'on' && $data['bind9_enable'] === 'on') {
$this->container->get('flash')->addMessage('error', 'DNSSEC can be only enabled for BIND9');
return $response->withHeader('Location', '/registry/tld/'.$tld_extension)->withStatus(302);
if (isset($data['dnssec_enable'], $data['bind9_enable'])) {
if ($data['dnssec_enable'] === 'on' && $data['bind9_enable'] === 'on') {
$dnssec_both = 1;
} elseif ($data['dnssec_enable'] === 'on' && $data['bind9_enable'] !== 'on') {
$this->container->get('flash')->addMessage('error', 'DNSSEC can be only enabled for BIND9');
return $response->withHeader('Location', '/registry/tld/'.$tld_extension)->withStatus(302);
} elseif ($data['dnssec_enable'] !== 'on' && $data['bind9_enable'] === 'on') {
$this->container->get('flash')->addMessage('error', 'DNSSEC can be only enabled for BIND9');
return $response->withHeader('Location', '/registry/tld/'.$tld_extension)->withStatus(302);
}
}
try {

View file

@ -3,14 +3,12 @@
namespace App\Lib;
use Monolog\ErrorHandler;
use Monolog\Handler\StreamHandler;
use Monolog\Handler\RotatingFileHandler;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run;
/**
* Logger
*
* @author Hezekiah O. <support@hezecom.com>
*/
class Logger extends \Monolog\Logger
{
@ -26,14 +24,20 @@ class Logger extends \Monolog\Logger
{
parent::__construct($key);
// Set log path and maximum number of files to retain
$LOG_PATH = '/var/log/namingo';
$maxFiles = 30; // Number of days to keep logs
if (empty($config)) {
$LOG_PATH = '/var/log/namingo';
$config = [
'logFile' => "{$LOG_PATH}/{$key}.log",
'logLevel' => \Monolog\Logger::DEBUG
'logFile' => "{$LOG_PATH}/cp.log", // Base log name
'logLevel' => \Monolog\Logger::DEBUG,
'maxFiles' => $maxFiles,
];
}
$this->pushHandler(new StreamHandler($config['logFile'], $config['logLevel']));
// Use RotatingFileHandler for automatic rotation
$this->pushHandler(new RotatingFileHandler($config['logFile'], $config['maxFiles'], $config['logLevel']));
}
/**
@ -51,31 +55,27 @@ class Logger extends \Monolog\Logger
}
/**
* Output error bate on environment
* Output error based on environment
*/
public static function systemLogs($enable = true)
{
$LOG_PATH = '/var/log/namingo';
$appEnv = envi('APP_ENV') ?? 'local';
if($enable) {
// output pretty html error
if ($enable) {
// Output pretty HTML error
self::htmlError();
}else {
// Error Log to file
self::$loggers['error'] = new Logger('errors');
self::$loggers['error']->pushHandler(new StreamHandler("{$LOG_PATH}/cp.log"));
ErrorHandler::register(self::$loggers['error']);
} else {
// Register system errors to rotating log file
$logger = new Logger('errors'); // Key 'errors' remains for compatibility
ErrorHandler::register($logger);
}
}
/**
* Display pretty html formatted errors during development
* Display pretty HTML formatted errors during development
*/
public static function htmlError(){
$run = new Run;
$run->pushHandler(new PrettyPageHandler);
public static function htmlError()
{
$run = new Run();
$run->pushHandler(new PrettyPageHandler());
$run->register();
}
}