255 lines
7.3 KiB
Bash
Executable File
255 lines
7.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
|
|
|
|
for lib in lib/*
|
|
do
|
|
source $lib
|
|
done
|
|
read_query_string
|
|
|
|
template=AP:Explorer:Seer:XM:Walked:Builder:Connector:Mind_Controller:MU:Longest_Link:Largest_Field:Recharger:Liberator:Pioneer:Engineer:Purifier:Neutralized:Links_Destroyed:Fields_Destroyed:Guardian:Link_Maintained:Link_Length_x_Days:Field_Held:Field_x_Days:Mercenary:Hacker
|
|
|
|
if [[ $REQUEST_METHOD == POST ]]
|
|
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')
|
|
|
|
EOHead
|
|
cat <<-EOHead >/dev/null
|
|
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
|
|
|
|
declare -A POST
|
|
exprdsname='^[[:upper:][:lower:]_]+$'
|
|
while read dsname value
|
|
do
|
|
if [[ $dsname =~ $exprdsname ]]
|
|
then
|
|
POST["$dsname"]="$value"
|
|
fi
|
|
done < <(
|
|
sed 's/&/\n/g;s/=/ /g'
|
|
)
|
|
POST["data"]="${POST["data"]//%0D%0A/
|
|
}"
|
|
POST["data"]="${POST["data"]//%3A/:}"
|
|
POST["data"]="${POST["data"]//+/ }"
|
|
echo "${POST["data"]}"
|
|
while read date hour data
|
|
do
|
|
data=$(date -d "$date $hour" +%s):${data// /:}
|
|
rrdtool update ingress.rrd -t $template "$data" 2>&1
|
|
done <<<"${POST["data"]}"
|
|
|
|
if [ -n "$CACHE_DIR" ]
|
|
then
|
|
find "$CACHE_DIR" -type f -delete
|
|
echo $'\nCache cleared!'
|
|
fi
|
|
else
|
|
cat <<-EOHTML
|
|
content-type: text/xml
|
|
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')
|
|
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
|
|
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>IngRRD - $webuser - Import Data</title>
|
|
<link rel="stylesheet" type="text/css" href="/ingrrd.css" />
|
|
</head>
|
|
<body>
|
|
<div class="container" style="width:$(( graph_width + 97 ))px">
|
|
EOHTML
|
|
if ! [ -w "$rrdfile" ]
|
|
then
|
|
rrdtool create ingress.rrd -s $((60*60)) \
|
|
DS:AP:GAUGE:$((2*24*60*60)):0:NaN \
|
|
DS:Explorer:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Seer:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:XM:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Hacker:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Builder:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Connector:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Mind_Controller:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:MU:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Longest_Link:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Largest_Field:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Recharger:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Liberator:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Pioneer:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Purifier:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Neutralized:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Links_Destroyed:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Fields_Destroyed:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Walked:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Guardian:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Link_Maintained:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Link_Length_x_Days:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Field_Held:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Field_x_Days:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Mercenary:GAUGE:$((48*60*60)):0:NaN \
|
|
DS:Engineer:GAUGE:$((48*60*60)):0:NaN \
|
|
RRA:HWPREDICT:8760:8e-1:8e-1:$((24)) \
|
|
RRA:AVERAGE:99e-2:1:$((24*15)) \
|
|
RRA:MAX:99e-2:1:$((24*15)) \
|
|
RRA:AVERAGE:99e-2:4:$((24*180)) \
|
|
RRA:MAX:99e-2:4:$((24*180)) \
|
|
RRA:AVERAGE:99e-2:24:$(((4*365)+1)) \
|
|
RRA:MAX:99e-2:24:$(((4*365)+1)) \
|
|
RRA:AVERAGE:99e-2:$((24*30)):$(((32*365)+8)) \
|
|
RRA:MAX:99e-2:$((24*30)):$(((32*365)+8)) \
|
|
|| {
|
|
cat <<-EOHTML
|
|
<h1 style="color:red">Cannot create $rrdfile</h1>
|
|
</body>
|
|
</html>
|
|
EOHTML
|
|
exit
|
|
}
|
|
fi
|
|
readlast
|
|
medals
|
|
get_current_level
|
|
cat <<-EOHTML
|
|
<div class="main">
|
|
<p>Import data from e.g. https://www.agent-stats.com/ <br/>
|
|
<small>Expected format: <tt>YYYY-MM-DD hh:mm:ss
|
|
${template[@]//:/ }</tt></small></p>
|
|
<form method="post" action="import">
|
|
<input type="hidden" name="start" value="$start" />
|
|
<input type="hidden" name="end" value="$end" />
|
|
<textarea name="data" rows="30" cols="110" /><br/>
|
|
<button type="submit" name="submit" value="send">Send</button>
|
|
</form>
|
|
<table style="width:$(( graph_width + 97 ))px">
|
|
<tr>
|
|
<td style="width:180px">
|
|
<a
|
|
href="http://validator.w3.org/check?uri=https%3A%2F%2F$SERVER_NAME$encodeduri">
|
|
<img
|
|
src="/valid-xhtml11"
|
|
alt="Valid XHTML 1.1"
|
|
height="31"
|
|
width="88" />
|
|
</a>
|
|
<a
|
|
href="http://jigsaw.w3.org/css-validator/validator?uri=https%3A%2F%2F$SERVER_NAME$encodeduri">
|
|
<img
|
|
style="border:0;width:88px;height:31px"
|
|
src="/vcss"
|
|
alt="Valid CSS!" />
|
|
</a>
|
|
</td>
|
|
<td style="text-align:center">
|
|
Generated by <a href="https://forge.riquer.fr/p/ingrrd/">IngRRD</a> © 2014 Vincent Riquer
|
|
</td>
|
|
<td style="text-align:right; width:180px">
|
|
<a href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">
|
|
<img src="/AGPL.png" height="31" width="88" />
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</div>
|
|
<div class="menu">
|
|
<table style="width:$(( graph_width + 97 ))px" class="menu">
|
|
<tr>
|
|
<td class="menu"><a href="/cgi/$webuser/?start=$start&end=$end">Overview</a></td>
|
|
<td class="menu">
|
|
<table class="menu-nobrd">
|
|
<tr>
|
|
<td colspan="2" class="menu-nobrd">
|
|
<a href="/cgi/$webuser/?hist&start=$start&end=$end">
|
|
History & Trend
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td class="menu">
|
|
<a href="/cgi/$webuser/?hist&start=$start&end=$end">
|
|
Medals
|
|
</a>
|
|
</td>
|
|
<td class="menu">
|
|
<a href="/cgi/$webuser/?hist&show=all&start=$start&end=$end">
|
|
All
|
|
</a>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
<td class="menu-inv">
|
|
<table class="menu">
|
|
<tr>
|
|
<td colspan="2" class="menu-inv">
|
|
<b>Add data</b>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<td
|
|
class="menu">
|
|
<a href="add.html?start=$start&end=$end"><b>Add</b></a>
|
|
</td>
|
|
<td class="submenu-inv">
|
|
Import
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
EOHTML
|
|
show_current_level
|
|
cat <<-EOHTML
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
EOHTML
|
|
fi
|