Dies ist eine alte Version des Dokuments!
Installation der Statusseite
Eine kleine Statusseite die den Verkehr und den Status des Gateways anzeigt. Dafür wird lighttpd und ein CGI-Script verwendet.
apt-get install lighttpd apt-get install gawk
gawk wird für das CGI-Script benötigt. Der Inhalt von /etc/lighttpd/lighttpd.conf:
server.document-root = "/etc/lighttpd/www/" server.port = 80 server.bind = "10.29.x.y" server.username = "www" server.groupname = "www" mimetype.assign = ( ".html" => "text/html", ".txt" => "text/plain", ".jpg" => "image/jpeg", ".png" => "image/png", ".css" => "text/css" ) index-file.names = ( "index.html" )
In der Konfigurationsdatei muss anstatt 10.29.x.y die korrekte IP eingetragen werden unter der die Statusseite im Freifunknetz erreichbar sein soll.
Der Inhalt von /etc/lighttpd/generate.sh:
#!/bin/bash dst="$1" src="/tmp/index.html.tmp" #write stdout to file exec >"$src" 2>&1 convert() { echo $1 | awk '{ split("B,KiB,MiB,GiB,TiB,EiB,PiB,YiB,ZiB", s, ",") c=1; x=$1 while (x>=1024 && c<8) {x/=1024; c++} xf=(c==1)?"%d":"%.2f" printf(xf" %s\n", x, s[c]) }' } handle() { local ifname="$1" tx_id=$2 rx_id=$3 ifconfig "$ifname" &> /dev/null || return get() { cat "/sys/class/net/$ifname/statistics/$1"; } tx_bytes=`get tx_bytes` rx_bytes=`get rx_bytes` avg_time=5 sleep $avg_time tx_speed=$(((`get tx_bytes`-$tx_bytes)/$avg_time)) rx_speed=$(((`get rx_bytes`-$rx_bytes)/$avg_time)) #connections=`netstat -nt | awk '{ print $5}' | cut -d: -f1 | sed -e '/^$/d' | sort -n | uniq | wc -l` echo '<script type="text/javascript">' echo "document.getElementById('$tx_id').innerHTML='`convert $tx_bytes` (`convert $tx_speed`/s)';" echo "document.getElementById('$rx_id').innerHTML='`convert $rx_bytes` (`convert $rx_speed`/s)';" echo '</script>' } echo '<html>' echo '<head>' echo '<title>Gateway-Status</title>' echo '<link rel="stylesheet" type="text/css" href="style.css">' echo '</head>' echo '<body>' echo '<h2>Statusseite des Gateways von Freifunk Bielefeld</h2>' echo "<center>(`date`)</center>" echo '<table>' echo '<tr style="vertical-align:bottom;">' echo '<td id="left_top"></td>' echo '<td id="middle_top"></td>' echo '<td id="right_top"></td>' echo '</tr>' echo '<tr>' echo '<td colspan=3><img src="schema.png" class="schema"></td></tr>' echo '<tr style="vertical-align:top;">' echo '<td id="left_bottom"></td>' echo '<td id="middle_bottom"></td>' echo '<td id="right_bottom"></td>' echo '</tr>' echo '</table>' handle "tun0" 'left_top' 'left_bottom' handle "n2n_bat" 'right_bottom' 'right_top' u=`uptime` load="${u##*:}" u="${u%%,*}" uptime="${u##*up}" hdd=`df -h | grep '/$' | cut -d' ' -f 20` echo '<script type="text/javascript">' echo "document.getElementById('middle_top').innerHTML='<b>Load:</b>$load<br><b>Uptime:</b>$uptime';" echo "document.getElementById('middle_bottom').innerHTML='<b>HDD:</b> $hdd<br><a href="/vnstat-test/index.php">Traffic Statistics</a>';" echo '</script>' echo '</body>' echo '</html>' #move to final destiantion mv "$src" "$dst" exit 0
Das obige Script generiert die Statusseite und soll alle zwei Minuten ausgeführt werden. Dafür wird ein Eintrag in die /etc/crontab vorgenommen:
*/2 * * * * www /etc/lighttpd/generate.sh '/etc/lighttpd/www/index.html'
Das gewählte Inhaltsverzeichnis muss noch erstellt werden:
mkdir /etc/lighttpd/www
Bevor lighttpd gestartet wird wird dafür noch eine Nutzer und eine Gruppe angelegt:
groupadd www useradd -g www -d /etc/lighttpd/www -s /sbin/nologin www chown -R www:www /etc/lighttpd/www/ chmod -R 775 /etc/lighttpd/www/
Nun kann der Webserver gestartet werden.
/etc/init.d/lighttpd start
*vnstat*
apt-get install php5-cgi apt-get install vnstat vnstat -u -i n2n_bat vnstat -u -i tun0
In der /etc/vnstat.conf muss unter #default Interface:
Interface "tun0" Interface 'n2n_bat"
In /etc/lighttpd/lighttpd.conf muss dann hinzugefügt werden:
server.modules = ("mod_fastcgi") fastcgi.server = ( ".php" => (( "bin-path" => "/usr/bin/php-cgi", "socket" => "/tmp/php.socket" )))
und
index-file.names = ( "index.html" )
wird durch
index-file.names = ( "index.html", "index.php" )
ersetzt
Nun muss nur noch das php-frontend (http://www.sqweek.com/sqweek/files/vnstat_php_frontend-1.5.1.tar.gz) in den richtigen Pfad heruntergeladen und entpackt werden und die config.php angepasst werden: Alle Interfaces müssen als array aufgeführt sein:
$iface_list = array('tun0', 'n2n_bat', 'eth0');
und für Jedes Interface wird noch ein Titel vergeben
$iface_title['tun0'] = 'VPN'; $iface_title['n2n_bat'] = 'Freifunk'; $iface_title['eth0'] = 'Internet';