From 204a4fcc8866cb630b227e9b2d64e9cdefdbaf58 Mon Sep 17 00:00:00 2001 From: "Jory A. Pratt" Date: Thu, 29 Jan 2026 21:36:05 -0600 Subject: [PATCH] Add SkywarnPlus-NG weather alerts integration - Add SkywarnPlus config: master enable, API URL (CfgModel) - Add showSkywarnAlerts() with severity-based color coding (viewUtils) - Display alerts between node controls and favorites on main page - When disabled: show nothing on main page - When enabled, no alerts: simple one-line 'SkyWarn+NG: No Alerts' (no box/bold) - Active alerts: severity colors (Extreme/Severe/Moderate/Minor) - GitHub link on Cfgs page only - Add SkywarnPlus config help in Cfgs tab --- cfg/index.php | 1 + css/main.css | 11 +++++++++++ include/CfgModel.php | 16 +++++++++++++--- include/viewUtils.php | 44 +++++++++++++++++++++++++++++++++++++++++++ index.php | 5 +++++ 5 files changed, 74 insertions(+), 3 deletions(-) diff --git a/cfg/index.php b/cfg/index.php index 8a9c54d..bd85448 100644 --- a/cfg/index.php +++ b/cfg/index.php @@ -44,6 +44,7 @@ h2("Configuration Parameters"); $view->showCfgs($gCfg); p("Node Number and AMI Cfgs default to values in /etc/asterisk/ rpt.conf and manager.conf if not set here."); +p("SkywarnPlus cfgs integrate weather alerts from " . $html->a('https://github.com/hardenedpenguin/SkywarnPlus-NG', null, 'SkywarnPlus-NG', null, '_blank') . ". Enable and set API URL (e.g. http://localhost:8100).", 'w800', false); $view->showForms($cfg ?? null); echo '' . BR. NL; diff --git a/css/main.css b/css/main.css index 4c4bf3c..0bdfc40 100644 --- a/css/main.css +++ b/css/main.css @@ -310,6 +310,17 @@ font-size:12px; background-color:#448; color:#fff; } +.skywarn-wrapper { +display:block; +width:100%; +clear:both; +margin:0.5em 0; +} +p.skywarn-simple { +margin:0.3em 0; +font-size:13px; +} + .greenborder { border:solid 3px rgb(39,144,39); border-radius:15px; diff --git a/include/CfgModel.php b/include/CfgModel.php index b7dd46f..b919bb5 100644 --- a/include/CfgModel.php +++ b/include/CfgModel.php @@ -18,6 +18,8 @@ define('amiuser', 10); define('amipass', 11); define('cmdbuttons', 12); +define('skywarn_master_enable', 13); +define('skywarn_api_url', 14); // Global Cfgs Default Values $gCfgDef = [ @@ -32,7 +34,9 @@ amiport => '', amiuser => '', amipass => '', - cmdbuttons => [] + cmdbuttons => [], + skywarn_master_enable => 'no', + skywarn_api_url => 'http://localhost:8100' ]; $gCfgName = [ @@ -47,9 +51,13 @@ amiport => 'AMI Port', amiuser => 'AMI User', amipass => 'AMI Pass', - cmdbuttons => 'Custom Cmd Buttons' + cmdbuttons => 'Custom Cmd Buttons', + skywarn_master_enable => 'SkywarnPlus Enable', + skywarn_api_url => 'SkywarnPlus API URL' ]; +$skywarnEnableVals = ['no' => 'Off', 'yes' => 'On']; + $publicPermissionVals = [ PERMISSION_NONE => 'None (No Access)', PERMISSION_READ_ONLY => 'Read Only', @@ -71,7 +79,9 @@ amiport => null, amiuser => null, amipass => null, - cmdbuttons => null + cmdbuttons => null, + skywarn_master_enable => $skywarnEnableVals, + skywarn_api_url => null ]; // Global Cfgs structure diff --git a/include/viewUtils.php b/include/viewUtils.php index 6b837f2..dbede67 100644 --- a/include/viewUtils.php +++ b/include/viewUtils.php @@ -22,6 +22,50 @@ function showConnStatusTable() { '; } +function showSkywarnAlerts() { + global $gCfg; + $apiUrl = trim($gCfg[skywarn_api_url] ?? ''); + if(!$apiUrl) { + echo '

SkyWarn+NG: API URL not configured

' . NL; + return; + } + $statusUrl = rtrim($apiUrl, '/') . '/api/status'; + $ctx = stream_context_create(['http' => ['timeout' => 5]]); + $json = @file_get_contents($statusUrl, false, $ctx); + if($json === false) { + echo '

SkyWarn+NG: API Offline

' . NL; + return; + } + $data = json_decode($json, true); + if(!is_array($data)) { + echo '

SkyWarn+NG: API Error

' . NL; + return; + } + if(!empty($data['error'])) { + echo '

SkyWarn+NG: ' . htmlspecialchars($data['error']) . '

' . NL; + return; + } + if(empty($data['has_alerts']) || empty($data['alerts'])) { + echo '

SkyWarn+NG: No Alerts

' . NL; + return; + } + $alerts = array_slice($data['alerts'], 0, 3); + $severityColors = [ + 'Extreme' => '#FF0000', + 'Severe' => '#FF6600', + 'Moderate'=> '#FFCC00', + 'Minor' => '#FFFF00' + ]; + $alertParts = []; + foreach($alerts as $alert) { + $event = htmlspecialchars($alert['event'] ?? 'Unknown', ENT_QUOTES, 'UTF-8'); + $severity = $alert['severity'] ?? 'Unknown'; + $color = $severityColors[$severity] ?? '#FF0000'; + $alertParts[] = '' . $event . ''; + } + echo '

SkyWarn+NG: ' . implode(', ', $alertParts) . '

' . NL; +} + function showNodeCtrlForm() { global $node, $remNode, $favsFile, $asdir, $gCfg; if(modifyOk()) diff --git a/index.php b/index.php index 8ff2325..b13fcef 100644 --- a/index.php +++ b/index.php @@ -76,6 +76,11 @@ showConnStatusTable(); showNodeCtrlForm(); +if(strtolower($gCfg[skywarn_master_enable] ?? '') === 'yes') { + echo '
'; + showSkywarnAlerts(); + echo '
'; +} h2('Favorites'); // Read in favorites.ini