From 5e572ff66a8a921a6416567f6bd9bc0e25f1b1d0 Mon Sep 17 00:00:00 2001 From: dman776 Date: Tue, 18 Aug 2020 16:17:03 -0500 Subject: [PATCH] aredn: add aredn local alerts capability (#552) --- files/etc/init.d/local | 9 ++++++++- files/usr/local/bin/aredn_message.sh | 27 ++++++++++++++++++++++++++- files/www/cgi-bin/advancedconfig | 8 +++++++- files/www/cgi-bin/perlfunc.pm | 2 ++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/files/etc/init.d/local b/files/etc/init.d/local index 8f2354a4..12255f66 100755 --- a/files/etc/init.d/local +++ b/files/etc/init.d/local @@ -75,7 +75,7 @@ boot() { fi /usr/local/bin/usb_passthrough "${usbvalue}" - # package repositorys + # package repositories local repos="core base arednpackages packages luci routing telephony" set -- $repos while [ -n "$1" ]; do @@ -95,4 +95,11 @@ boot() { fi shift done + + # set local alerts if available + local alertslocalpath=$(uci -q get aredn.@alerts[0].localpath) + if [ -z "$alertslocalpath" ]; then + uci -q add aredn alerts + uci -q commit aredn + fi } diff --git a/files/usr/local/bin/aredn_message.sh b/files/usr/local/bin/aredn_message.sh index 91e297f5..c0d66edc 100755 --- a/files/usr/local/bin/aredn_message.sh +++ b/files/usr/local/bin/aredn_message.sh @@ -39,12 +39,12 @@ ping -q -W10 -c1 downloads.arednmesh.org > /dev/null && [ -f /tmp/aredn_message ] && rm /tmp/aredn_message +nodename=$(echo "$HOSTNAME" | tr '[:upper:]' '[:lower:]') if [ $online = "true" ] then # fetch node specific message file # nodename=$(echo "$HOSTNAME" | tr 'A-Z' 'a-z') - nodename=$(echo "$HOSTNAME" | tr 'A-Z' 'a-z') wget -q -O aredn_message -P /tmp http://downloads.arednmesh.org/messages/"${nodename}".txt echo "(${nodename}):"|cat - /tmp/aredn_message > /tmp/out && mv /tmp/out /tmp/aredn_message if [ $? -ne 0 ] # no node specific file @@ -62,3 +62,28 @@ then fi fi +# are local alerts enabled? uci: aredn.alerts.localpath != NULL +# +alertslocalpath=$(uci -q get aredn.@alerts[0].localpath) +if [ ! -z "$alertslocalpath" ]; then + # fetch node specific message file + wget -q -O local_message -P /tmp "${alertslocalpath}/${nodename}".txt + echo "(LOCAL ${nodename}):"|cat - /tmp/local_message > /tmp/out && mv /tmp/out /tmp/local_message + if [ $? -ne 0 ] # no node specific file + then + # fetch broadcast message file + wget -q -O local_message -P /tmp "${alertslocalpath}/all.txt" + echo "(LOCAL QST):"|cat - /tmp/local_message > /tmp/out && mv /tmp/out /tmp/local_message + else + # need to append to node file + wget -q -O local_message_all -P /tmp "${alertslocalpath}/all.txt" && + echo "(LOCAL QST):"|cat - /tmp/local_message_all > /tmp/out && mv /tmp/out /tmp/local_message_all + echo "
" >> /tmp/local_message; + [ -f /tmp/local_message_all ] && + cat /tmp/local_message_all >> /tmp/local_message && + rm /tmp/local_message_all; + fi +fi + + + diff --git a/files/www/cgi-bin/advancedconfig b/files/www/cgi-bin/advancedconfig index 76a5911d..16f8b8d3 100755 --- a/files/www/cgi-bin/advancedconfig +++ b/files/www/cgi-bin/advancedconfig @@ -2,7 +2,7 @@ =for comment Part of AREDN -- Used for creating Amateur Radio Emergency Data Networks - Copyright (C) 2018 - Darryl Quinn + Copyright (C) 2020 - Darryl Quinn See Contributors file for additional contributors Copyright (c) 2013 David Rivenburg et al. BroadBand-HamNet @@ -146,6 +146,12 @@ push @setting, { desc => "Value doesn't matter. Will attempt to pull any AREDN Alert messages.", postcallback => "aam_refresh()" }; +push @setting, { + key => "aredn.\@alerts[0].localpath", + type => "string", + desc => "Specifies the URL of the location from which local AREDN Alerts can be downloaded.", + default => "" +}; # ---------------------------------------- diff --git a/files/www/cgi-bin/perlfunc.pm b/files/www/cgi-bin/perlfunc.pm index c17470f0..220eaa28 100644 --- a/files/www/cgi-bin/perlfunc.pm +++ b/files/www/cgi-bin/perlfunc.pm @@ -1908,6 +1908,7 @@ sub alert_banner { # if /tmp/aredn_message file exists, then read and set $aredn_message to contents $aredn_message = `cat /tmp/aredn_message` if( -f "/tmp/aredn_message"); + $local_message = `cat /tmp/local_message` if( -f "/tmp/local_message"); print "
"; @@ -1927,6 +1928,7 @@ sub alert_banner } } print "
AREDN Alert(s):
$aredn_message
\n" if $aredn_message; + print "
Local Alert(s):
$local_message
\n" if $local_message; #TopBanner print "
";