|
2 | 2 |
|
3 | 3 | namespace Tailscale;
|
4 | 4 |
|
| 5 | +enum NotificationType: string |
| 6 | +{ |
| 7 | + case NORMAL = 'normal'; |
| 8 | + case WARNING = 'warning'; |
| 9 | + case ALERT = 'alert'; |
| 10 | +} |
| 11 | + |
5 | 12 | class System
|
6 | 13 | {
|
7 | 14 | public const RESTART_COMMAND = "/usr/local/emhttp/webGui/scripts/reload_services";
|
@@ -87,6 +94,12 @@ public static function checkServeConfig(): void
|
87 | 94 |
|
88 | 95 | if ($configPort == $httpPort || $configPort == $httpsPort) {
|
89 | 96 | Utils::logmsg("Serve TCP Port {$configPort} conflicts with WebGUI, removing");
|
| 97 | + self::sendNotification( |
| 98 | + "Tailscale Serve Port Conflict", |
| 99 | + "Tailscale Serve Port Conflict", |
| 100 | + "Port {$configPort} conflicts with WebGUI port. The Tailscale serve config has been reset to remove the conflict.", |
| 101 | + NotificationType::ALERT |
| 102 | + ); |
90 | 103 | $localAPI->resetServeConfig();
|
91 | 104 | Utils::run_command(self::RESTART_COMMAND);
|
92 | 105 |
|
@@ -184,25 +197,29 @@ public static function notifyOnKeyExpiration(): void
|
184 | 197 |
|
185 | 198 | switch (true) {
|
186 | 199 | case $interval->days <= 7:
|
187 |
| - $priority = 'alert'; |
| 200 | + $priority = NotificationType::ALERT; |
188 | 201 | break;
|
189 | 202 | case $interval->days <= 30:
|
190 |
| - $priority = 'warning'; |
| 203 | + $priority = NotificationType::WARNING; |
191 | 204 | break;
|
192 | 205 | default:
|
193 | 206 | return;
|
194 | 207 | }
|
195 | 208 |
|
196 |
| - $event = "Tailscale Key Expiration - {$priority} - {$expiryTime->format('Ymd')}"; |
| 209 | + $event = "Tailscale Key Expiration - {$priority->value} - {$expiryTime->format('Ymd')}"; |
197 | 210 | Utils::logmsg("Sending notification for key expiration: {$event}");
|
198 |
| - |
199 |
| - $command = self::NOTIFY_COMMAND . " -l '/Settings/Tailscale' -e " . escapeshellarg($event) . " -s " . escapeshellarg("Tailscale key is expiring") . " -d " . escapeshellarg("{$message}") . " -i \"{$priority}\" -x 2>/dev/null"; |
200 |
| - exec($command); |
| 211 | + self::sendNotification($event, "Tailscale key is expiring", $message, $priority); |
201 | 212 | } else {
|
202 | 213 | Utils::logmsg("Tailscale key expiration is not set.");
|
203 | 214 | }
|
204 | 215 | }
|
205 | 216 |
|
| 217 | + public static function sendNotification(string $event, string $subject, string $message, NotificationType $priority): void |
| 218 | + { |
| 219 | + $command = self::NOTIFY_COMMAND . " -l '/Settings/Tailscale' -e " . escapeshellarg($event) . " -s " . escapeshellarg($subject) . " -d " . escapeshellarg("{$message}") . " -i \"{$priority->value}\" -x 2>/dev/null"; |
| 220 | + exec($command); |
| 221 | + } |
| 222 | + |
206 | 223 | public static function refreshWebGuiCert(bool $restartIfChanged = true): void
|
207 | 224 | {
|
208 | 225 | $localAPI = new LocalAPI();
|
|
0 commit comments