92 lines
2.3 KiB
Bash
Executable File
92 lines
2.3 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# IngRRD (https://forge.riquer.fr/p/ingrrd/)
|
|
# Copyright (C) 2014 Vincent Riquer
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
. settings
|
|
|
|
if [[ $REQUEST_METHOD != POST ]] || [ ! -w "$rrdfile" ]
|
|
then
|
|
cat <<-EOHead
|
|
Content-type: text/plain
|
|
Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
|
|
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
|
|
refresh: 0,url=/cgi/$webuser/add.html
|
|
|
|
EOHead
|
|
exit
|
|
fi
|
|
|
|
declare -A POST
|
|
exprdsname='^[[:upper:][:lower:]_]+$'
|
|
exprvalue='^-?[[:digit:]]+$'
|
|
while read dsname value
|
|
do
|
|
if [[ $dsname =~ $exprdsname ]] \
|
|
&& [[ $value =~ $exprvalue ]]
|
|
then
|
|
POST["$dsname"]="$value"
|
|
fi
|
|
done < <(
|
|
sed 's/&/\n/g;s/=/ /g'
|
|
)
|
|
cat <<-EOHead
|
|
Content-type: text/plain
|
|
Last-Modified: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
|
|
Expires: $(LC_ALL=C TZ=GMT date +'%a, %d %b %Y %X %Z')
|
|
refresh: 0,url=/cgi/$webuser/?start=${POST["start"]}&end=${POST["end"]}
|
|
|
|
EOHead
|
|
|
|
if [[ $webuser == $AUTH_USER || $webuser == dev ]]
|
|
then
|
|
echo "Welcome agent $webuser"$'!\n\n'
|
|
else
|
|
echo 'Nice try!'
|
|
exit
|
|
fi
|
|
|
|
while read ds junk
|
|
do
|
|
ds="${ds//ds[/}"
|
|
ds="${ds//]*/}"
|
|
datasets+=("$ds")
|
|
done < <(rrdtool info ingress.rrd |grep index)
|
|
for ds in ${dsnames[@]}
|
|
do
|
|
if [[ ! ${datasets[@]} =~ $ds ]]
|
|
then
|
|
cp -f ingress.rrd ingress.rrd.bak_add_$ds
|
|
./dsaddtor.pl ingress.rrd $ds GAUGE $((48*60*60)) 0 NaN
|
|
fi
|
|
done
|
|
data=N
|
|
for dsname in "${dsnames[@]}"
|
|
do
|
|
data+=:${POST["$dsname"]:=U}
|
|
template+="${template:+:}$dsname"
|
|
echo "$dsname....${POST["$dsname"]}"
|
|
done
|
|
|
|
echo ${POST["innovator"]} > .innovator
|
|
rrdtool update ingress.rrd -t $template "$data"
|
|
|
|
if [ -n "$CACHE_DIR" ]
|
|
then
|
|
find "$CACHE_DIR" -type f -delete
|
|
echo $'\nCache cleared!'
|
|
fi
|