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 * @throws \DI\NotFoundException
*/ */
public function createLogin(Request $request, Response $response){ public function createLogin(Request $request, Response $response){
$isWebAuthnEnabled = envi('WEB_AUTHN_ENABLED') === 'true'; $isWebAuthnEnabled = (envi('WEB_AUTHN_ENABLED') === 'true') ? true : false;
return view($response, 'auth/login.twig', ['isWebaEnabled' => $isWebaEnabled]); return view($response, 'auth/login.twig', ['isWebaEnabled' => $isWebAuthnEnabled]);
} }
/** /**

View file

@ -2046,11 +2046,13 @@ class DomainsController extends Controller
[ $domain_id ] [ $domain_id ]
); );
foreach ($results as $row) { if (is_array($results) && !empty($results)) {
$status = $row['status']; foreach ($results as $row) {
if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) { $status = $row['status'];
$this->container->get('flash')->addMessage('error', 'It has a status that does not allow deletion, first change the status'); if (preg_match('/.*(UpdateProhibited|DeleteProhibited)$/', $status) || preg_match('/^pending/', $status)) {
return $response->withHeader('Location', '/domains')->withStatus(302); $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);
}
} }
} }
@ -2112,28 +2114,30 @@ class DomainsController extends Controller
[$domain_id] [$domain_id]
); );
foreach ($hostIds as $host) { if (is_array($hostIds) && !empty($hostIds)) {
$host_id = $host['id']; foreach ($hostIds as $host) {
$host_id = $host['id'];
// Delete operations // Delete operations
$db->delete( $db->delete(
'host_addr', 'host_addr',
[ [
'host_id' => $host_id 'host_id' => $host_id
] ]
); );
$db->delete( $db->delete(
'host_status', 'host_status',
[ [
'host_id' => $host_id 'host_id' => $host_id
] ]
); );
$db->delete( $db->delete(
'domain_host_map', 'domain_host_map',
[ [
'host_id' => $host_id 'host_id' => $host_id
] ]
); );
}
} }
// Delete domain related records // Delete domain related records

View file

@ -188,7 +188,7 @@ class HomeController extends Controller
public function mode(Request $request, Response $response) 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'; $_SESSION['_screen_mode'] = 'light';
} else { } else {
$_SESSION['_screen_mode'] = 'dark'; $_SESSION['_screen_mode'] = 'dark';

View file

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

View file

@ -3,14 +3,12 @@
namespace App\Lib; namespace App\Lib;
use Monolog\ErrorHandler; use Monolog\ErrorHandler;
use Monolog\Handler\StreamHandler; use Monolog\Handler\RotatingFileHandler;
use Whoops\Handler\PrettyPageHandler; use Whoops\Handler\PrettyPageHandler;
use Whoops\Run; use Whoops\Run;
/** /**
* Logger * Logger
*
* @author Hezekiah O. <support@hezecom.com>
*/ */
class Logger extends \Monolog\Logger class Logger extends \Monolog\Logger
{ {
@ -26,14 +24,20 @@ class Logger extends \Monolog\Logger
{ {
parent::__construct($key); 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)) { if (empty($config)) {
$LOG_PATH = '/var/log/namingo';
$config = [ $config = [
'logFile' => "{$LOG_PATH}/{$key}.log", 'logFile' => "{$LOG_PATH}/cp.log", // Base log name
'logLevel' => \Monolog\Logger::DEBUG '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) public static function systemLogs($enable = true)
{ {
if ($enable) {
$LOG_PATH = '/var/log/namingo'; // Output pretty HTML error
$appEnv = envi('APP_ENV') ?? 'local';
if($enable) {
// output pretty html error
self::htmlError(); self::htmlError();
}else { } else {
// Error Log to file // Register system errors to rotating log file
self::$loggers['error'] = new Logger('errors'); $logger = new Logger('errors'); // Key 'errors' remains for compatibility
self::$loggers['error']->pushHandler(new StreamHandler("{$LOG_PATH}/cp.log")); ErrorHandler::register($logger);
ErrorHandler::register(self::$loggers['error']);
} }
} }
/** /**
* Display pretty html formatted errors during development * Display pretty HTML formatted errors during development
*/ */
public static function htmlError(){ public static function htmlError()
$run = new Run; {
$run->pushHandler(new PrettyPageHandler); $run = new Run();
$run->pushHandler(new PrettyPageHandler());
$run->register(); $run->register();
} }
} }