Removed application folder (Ci3) added maintenance mode
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
|
||||
class Down extends BaseCommand
|
||||
{
|
||||
protected $group = 'Housekeeping';
|
||||
protected $name = 'down';
|
||||
protected $description = 'Put the application into maintenance mode.';
|
||||
protected $usage = 'down [options]';
|
||||
protected $options = [
|
||||
'--allow' => 'IP address(es) to whitelist (comma-separated or use multiple --allow)',
|
||||
'--message' => 'Custom message for the maintenance page',
|
||||
];
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
$allowedIps = [];
|
||||
|
||||
// Get allowed IPs from command line
|
||||
if (CLI::getOption('allow')) {
|
||||
$allow = CLI::getOption('allow');
|
||||
if (is_array($allow)) {
|
||||
foreach ($allow as $ip) {
|
||||
$allowedIps = array_merge($allowedIps, array_map('trim', explode(',', $ip)));
|
||||
}
|
||||
} else {
|
||||
$allowedIps = array_map('trim', explode(',', $allow));
|
||||
}
|
||||
}
|
||||
|
||||
// Get custom message
|
||||
$message = CLI::getOption('message') ?: '';
|
||||
|
||||
// Create maintenance data
|
||||
$data = [
|
||||
'time' => date('Y-m-d H:i:s'),
|
||||
'allowed' => array_values(array_filter($allowedIps)),
|
||||
'message' => $message,
|
||||
];
|
||||
|
||||
$filePath = WRITEPATH . 'down';
|
||||
|
||||
if (file_put_contents($filePath, json_encode($data, JSON_PRETTY_PRINT))) {
|
||||
CLI::write('Application is now in maintenance mode.', 'yellow');
|
||||
|
||||
if (! empty($allowedIps)) {
|
||||
CLI::write('Whitelisted IPs: ' . implode(', ', $allowedIps), 'green');
|
||||
}
|
||||
} else {
|
||||
CLI::error('Failed to enable maintenance mode. Check writable directory permissions.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user