Feat: actually update timezone on the server
This commit is contained in:
@@ -5,8 +5,7 @@ namespace App\Livewire\Server;
|
|||||||
use App\Actions\Server\StartSentinel;
|
use App\Actions\Server\StartSentinel;
|
||||||
use App\Actions\Server\StopSentinel;
|
use App\Actions\Server\StopSentinel;
|
||||||
use App\Jobs\PullSentinelImageJob;
|
use App\Jobs\PullSentinelImageJob;
|
||||||
use App\Models\Server;
|
use App\Models\Server;;
|
||||||
use DateTimeZone;
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class Form extends Component
|
class Form extends Component
|
||||||
@@ -179,6 +178,7 @@ class Form extends Component
|
|||||||
|
|
||||||
public function submit()
|
public function submit()
|
||||||
{
|
{
|
||||||
|
ray('Submit method called');
|
||||||
if (isCloud() && !isDev()) {
|
if (isCloud() && !isDev()) {
|
||||||
$this->validate();
|
$this->validate();
|
||||||
$this->validate([
|
$this->validate([
|
||||||
@@ -192,27 +192,48 @@ class Form extends Component
|
|||||||
})->pluck('ip')->toArray();
|
})->pluck('ip')->toArray();
|
||||||
if (in_array($this->server->ip, $uniqueIPs)) {
|
if (in_array($this->server->ip, $uniqueIPs)) {
|
||||||
$this->dispatch('error', 'IP address is already in use by another team.');
|
$this->dispatch('error', 'IP address is already in use by another team.');
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
refresh_server_connection($this->server->privateKey);
|
refresh_server_connection($this->server->privateKey);
|
||||||
$this->server->settings->wildcard_domain = $this->wildcard_domain;
|
$this->server->settings->wildcard_domain = $this->wildcard_domain;
|
||||||
$this->server->settings->cleanup_after_percentage = $this->cleanup_after_percentage;
|
$this->server->settings->cleanup_after_percentage = $this->cleanup_after_percentage;
|
||||||
|
|
||||||
// Update the timezone if it has changed
|
ray('Current timezone:', $this->server->settings->getOriginal('server_timezone'));
|
||||||
if ($this->server->settings->isDirty('server_timezone')) {
|
ray('New timezone:', $this->server->settings->server_timezone);
|
||||||
|
|
||||||
|
$currentTimezone = $this->server->settings->getOriginal('server_timezone');
|
||||||
|
$newTimezone = $this->server->settings->server_timezone;
|
||||||
|
|
||||||
|
ray('Comparing timezones:', $currentTimezone, $newTimezone);
|
||||||
|
|
||||||
|
if ($currentTimezone !== $newTimezone || $currentTimezone === '') {
|
||||||
|
ray('Timezone change detected');
|
||||||
try {
|
try {
|
||||||
$message = $this->updateServerTimezone($this->server->settings->server_timezone);
|
ray('Calling updateServerTimezone');
|
||||||
$this->dispatch('success', $message);
|
$timezoneUpdated = $this->updateServerTimezone($newTimezone);
|
||||||
|
ray('updateServerTimezone result:', $timezoneUpdated);
|
||||||
|
if ($timezoneUpdated) {
|
||||||
|
$this->server->settings->server_timezone = $newTimezone;
|
||||||
|
$this->server->settings->save();
|
||||||
|
ray('New timezone saved to database:', $newTimezone);
|
||||||
|
} else {
|
||||||
|
ray('Timezone update failed');
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
ray('Exception in updateServerTimezone:', $e->getMessage());
|
||||||
$this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());
|
$this->dispatch('error', 'Failed to update server timezone: ' . $e->getMessage());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ray('No timezone change detected');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ray('Saving server settings');
|
||||||
$this->server->settings->save();
|
$this->server->settings->save();
|
||||||
$this->server->save();
|
$this->server->save();
|
||||||
$this->dispatch('success', 'Server updated.');
|
$this->dispatch('success', 'Server updated.');
|
||||||
|
ray('Submit method completed');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updatedServerTimezone($value)
|
public function updatedServerTimezone($value)
|
||||||
@@ -226,12 +247,18 @@ class Form extends Component
|
|||||||
|
|
||||||
private function updateServerTimezone($value)
|
private function updateServerTimezone($value)
|
||||||
{
|
{
|
||||||
|
ray('updateServerTimezone called with value:', $value);
|
||||||
|
try {
|
||||||
$commands = [
|
$commands = [
|
||||||
"date +%Z",
|
"date +%Z",
|
||||||
"if command -v timedatectl >/dev/null 2>&1; then timedatectl set-timezone " . escapeshellarg($value) . " 2>&1 || echo 'timedatectl failed'; fi",
|
"if command -v timedatectl >/dev/null 2>&1; then timedatectl set-timezone " . escapeshellarg($value) . " 2>&1 || echo 'timedatectl failed'; fi",
|
||||||
"if [ -f /etc/timezone ]; then echo " . escapeshellarg($value) . " > /etc/timezone && dpkg-reconfigure -f noninteractive tzdata 2>&1 || echo '/etc/timezone update failed'; fi",
|
"if [ -f /etc/timezone ]; then echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo '/etc/timezone update failed'; fi",
|
||||||
"if [ -L /etc/localtime ]; then ln -sf /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 || echo '/etc/localtime update failed'; fi",
|
"if [ -L /etc/localtime ] || [ -f /etc/localtime ]; then ln -sf /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 || echo '/etc/localtime update failed'; fi",
|
||||||
|
"if command -v dpkg-reconfigure >/dev/null 2>&1; then dpkg-reconfigure -f noninteractive tzdata 2>&1 || echo 'dpkg-reconfigure failed'; fi",
|
||||||
|
"if command -v apk >/dev/null 2>&1; then apk add --no-cache tzdata 2>&1 && cp /usr/share/zoneinfo/" . escapeshellarg($value) . " /etc/localtime 2>&1 && echo " . escapeshellarg($value) . " > /etc/timezone 2>&1 || echo 'Alpine timezone update failed'; fi",
|
||||||
|
"if [ -f /etc/sysconfig/clock ]; then sed -i 's/^ZONE=.*/ZONE=\"" . escapeshellarg($value) . "\"/' /etc/sysconfig/clock 2>&1 || echo '/etc/sysconfig/clock update failed'; fi",
|
||||||
"date +%Z",
|
"date +%Z",
|
||||||
|
"cat /etc/timezone 2>/dev/null || echo 'Unable to read /etc/timezone'",
|
||||||
];
|
];
|
||||||
|
|
||||||
$result = instant_remote_process($commands, $this->server);
|
$result = instant_remote_process($commands, $this->server);
|
||||||
@@ -262,16 +289,17 @@ class Form extends Component
|
|||||||
throw new \Exception("Timezone change failed. The timezone is still set to {$oldTimezone}.");
|
throw new \Exception("Timezone change failed. The timezone is still set to {$oldTimezone}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
$dateTime = new \DateTime('now', new \DateTimeZone($value));
|
$dateTime = new \DateTime('now', new \DateTimeZone($value));
|
||||||
$phpTimezone = $dateTime->getTimezone()->getName();
|
$phpTimezone = $dateTime->getTimezone()->getName();
|
||||||
} catch (\Exception $e) {
|
|
||||||
throw new \Exception("Invalid PHP timezone: {$value}. Error: " . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->server->settings->server_timezone = $phpTimezone;
|
$this->server->settings->server_timezone = $phpTimezone;
|
||||||
$this->server->settings->save();
|
$this->server->settings->save();
|
||||||
|
|
||||||
return "Timezone successfully changed from {$oldTimezone} to {$newTimezone} (PHP: {$phpTimezone}).";
|
$this->dispatch('success', "Timezone successfully changed from {$oldTimezone} to {$newTimezone} (PHP: {$phpTimezone}).");
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->dispatch('error', $e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user