Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cfg/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '</div>' . BR. NL;

Expand Down
11 changes: 11 additions & 0 deletions css/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 13 additions & 3 deletions include/CfgModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -32,7 +34,9 @@
amiport => '',
amiuser => '',
amipass => '',
cmdbuttons => []
cmdbuttons => [],
skywarn_master_enable => 'no',
skywarn_api_url => 'http://localhost:8100'
];

$gCfgName = [
Expand All @@ -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',
Expand All @@ -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
Expand Down
44 changes: 44 additions & 0 deletions include/viewUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,50 @@ function showConnStatusTable() {
';
}

function showSkywarnAlerts() {
global $gCfg;
$apiUrl = trim($gCfg[skywarn_api_url] ?? '');
if(!$apiUrl) {
echo '<p id="skywarn-msg" class="skywarn-simple">SkyWarn+NG: API URL not configured</p>' . 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 '<p id="skywarn-msg" class="skywarn-simple">SkyWarn+NG: API Offline</p>' . NL;
return;
}
$data = json_decode($json, true);
if(!is_array($data)) {
echo '<p id="skywarn-msg" class="skywarn-simple">SkyWarn+NG: API Error</p>' . NL;
return;
}
if(!empty($data['error'])) {
echo '<p id="skywarn-msg" class="skywarn-simple">SkyWarn+NG: ' . htmlspecialchars($data['error']) . '</p>' . NL;
return;
}
if(empty($data['has_alerts']) || empty($data['alerts'])) {
echo '<p id="skywarn-msg" class="skywarn-simple">SkyWarn+NG: No Alerts</p>' . 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[] = '<span style="color: ' . $color . ';">' . $event . '</span>';
}
echo '<p id="skywarn-msg" class="skywarn-simple">SkyWarn+NG: ' . implode(', ', $alertParts) . '</p>' . NL;
}

function showNodeCtrlForm() {
global $node, $remNode, $favsFile, $asdir, $gCfg;
if(modifyOk())
Expand Down
5 changes: 5 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@

showConnStatusTable();
showNodeCtrlForm();
if(strtolower($gCfg[skywarn_master_enable] ?? '') === 'yes') {
echo '<div class="skywarn-wrapper">';
showSkywarnAlerts();
echo '</div>';
}

h2('Favorites');
// Read in favorites.ini
Expand Down