#!/bin/sh #------------------------------------------------------------------------------ # __FLI4LVER__ # /srv/www/include/OpenVPN_output.inc # Creation: 15.05.2005 hh # Last Update: $Id$ #------------------------------------------------------------------------------ [ "$gui_started" != "true" ] && exit 1 # must not be called standalone #------- Output Functions ------------------------------------------------------- show_header () { # show footer of html-file with header of main table # show back link if not on main page show_html_header "$1" "cssfile=status_OpenVPN" [ "$FORM_sec" = "status" ] || echo "$_MN_bck

" shift show_tab_header "$@" } show_footer () { # show footer of html-file show_tab_footer case "$FORM_sec" in status) echo '
' #echo "$_refresh ..." echo "' echo '
' ;; esac show_html_footer } show_lang () { # show language-switch-link cd /usr/local/htdocs/openvpn/lang/ ls *.cgi | cut -d. -f1 > /tmp/languages.$$ echo "
" while read x; do [ "$FORM_lang" = "$x" ] || echo "$x " done < /tmp/languages.$$ echo "
" rm -f /tmp/languages.$$ } show_connections () { # Show all connections with status # Get all ovpn names cd /etc/openvpn/ ls *.conf | cut -d. -f 1 > /tmp/ovpnnames.$$ # Test for every name if session is running echo "" switch="odd" while read name; do echo "" hold="hold" action="stop" state=`state_ovpn` case $state in STOPPED) symbol="stopped" action="start" ;; CONNECTED) symbol="running" ;; HOLD) symbol="noconn" hold="release" ;; *) symbol="noconn" ;; esac # show status-icons, name and action-icons echo "" echo "' # change row-color if [ "$switch" = "odd" ] then switch="even" else switch="odd" fi done < /tmp/ovpnnames.$$ echo '
$_MT_stat$_VPN_name$_VPN_action
`icon $symbol $state state-$name`
" case $FORM_showtext in yes) echo "
" ;; esac echo "
$name" echo "`icon $action`" if [ "$state" != "STOPPED" ] then echo "`icon reload`" echo "`icon $hold`" fi echo '
' rm -f /tmp/ovpnnames.$$ } show_packetfilter () { # Shows packetfilter-table case $2 in in) chain="Input" ;; fw) chain="Forward" ;; pre-in) chain="NAT Pre-Routing" ;; post-out) chain="NAT Post-Routing" ;; esac echo "

$chain Chain:

" echo "" if /sbin/iptables -t $1 -nvL $2-ovpn-$3 > /dev/null then iptables -t $1 --line-numbers -nvL $2-ovpn-$3 | \ while read line do case "$line" in '') ;; Chain*) echo ' ' ;; num*) echo "$line" | sed -e 's/^/" #" ;; *) set -f set $line def=`echo "$1 $2 $3 $4 $5 $6 $7 $8 $9 ${10}" | sed -e 's/^/##g'` target=$4 shift 10 restr=`echo "" | sed -e 's,/[*].*[*]/,,;s###g'` src=`echo "$*" | sed -e 's#.*/[*]\(.*\)[*]/#\1#'` echo "$def $restr" set +f ;; esac done else echo "" fi echo "
'$line'
/;s/[[:space:]]\+/<\/th>/g' echo "additional restrictionsconfig source
/;s/[[:space:]]\+/<\/td>/g;s/$/<\/td>/;s#\(all\|[*]\|--\|0\.\0\.\0\.0/0\)$*
`eval echo '$_no_VPN_'$1'chain'`
" } show_bridge () { # Show bridge conig of current connection echo "

$_VPN_head_bridge:

" echo "" brctl show | sed -r 's/ /_/g;s/[[:space:]]+/~/g;s/$/<\/td><\/tr>/;s/^~/<\/td>
<\/td><\/td>/;\ s/~/<\/td>/g;s/^/
/;s/_/ /g' echo "
" } show_stats () { # Show table with statistics of current connection echo "

$_VPN_head_stats:

" case `state_ovpn` in HOLD|STOPPED) # no statistics available if connection is hold eval echo '$_VPN_'`state_ovpn`'.\' echo $_VPN_nostats ;; *) echo "" echo '' mkdir -p /tmp/ovpn-webgui.$$ cd /tmp/ovpn-webgui.$$ ocontrol "status" | grep -v -e "STATISTICS" -e "Updated" > a cat a | cut -d, -f1 | sed 's/ bytes//' > b cat a | cut -d, -f2 > c exec 4" done rm -rf /tmp/ovpn-webgui.$$ #ocontrol "status" | sed "s°^°°;s°,°
'$_VPN_what''$_VPN_amount'
$x`cnum $y | sed '/[^B]$/s/$/<\/td>bytes/;s/ /<\/td>/'`
°;s°$°
°" | grep -v "STATISTICS" echo "
" ;; esac } show_config () { # Show configuration of current connection echo "

$_VPN_head_config:

" echo "
" echo "" echo "" echo "" echo "" echo "" echo "
" echo "
" } show_logfile () { # Show log of current connection case $1 in debug) mkdir -p /tmp/ovpn-webgui.$$ cd /tmp/ovpn-webgui.$$ echo $$ > /var/lock/ovpn-debug.lck start_ovpn debug | sed -r -e 's°[[:space:]]+° °g' > a & sleep 2 stop_ovpn debug rm -f /var/lock/ovpn-debug.lck cat a | cut -d" " -f4 > b cat a | cut -d" " -f7-99 > c exec 4$x$y" done rm -rf /tmp/ovpn-webgui.$$ echo "" ;; *) mkdir -p /tmp/ovpn-webgui.$$ cd /tmp/ovpn-webgui.$$ ocontrol "log $1" | grep -v "HOLD" > a cat a | cut -d, -f1 > b cat a | cut -d, -f2 > c cat a | cut -d, -f3-99 | sed "s°$°°" > d exec 4`ctime $x "$_VPN_dateformat<\/td>$_VPN_timeformat"`$z" done rm -rf /tmp/ovpn-webgui.$$ echo "" ;; esac } show_support () { # Show all support infos for current connection echo "

$_VPN_head_supp:

" echo "

$_VPN_head_state:

" eval echo '$_VPN_'`state_ovpn` echo "

$_VPN_head_config:

" sed "s°$°
°" /etc/openvpn/$name.conf echo "
" if cat /etc/openvpn/$name.conf | grep -q "^dev tun" then show_packet else show_bridge fi case $1 in debug) echo "

$_VPN_head_log

" echo "" show_logfile $1 ;; *) echo "

$_VPN_head_log ($_MN_all $_MN_rows):

" echo "
$_MN_time$_VPN_notice
" show_logfile $1 ;; esac echo "" } show_dsupp () { # Show all support infos for current connection show_support debug } show_dlog () { # Show all support infos for current connection echo "

$_VPN_head_log

" echo "
$_MN_date$_MN_time$_VPN_notice
" show_logfile debug } show_packet () { # Show packetfilter of current connection case `state_ovpn` in HOLD|STOPPED) # no statistics available if connection is hold eval echo '$_VPN_'`state_ovpn`'.\
' echo $_VPN_nopacket ;; *) show_packetfilter filter in $name show_packetfilter filter fw $name show_packetfilter nat pre-in $name show_packetfilter nat post-out $name ;; esac } show_supp () { # Show all Supportinfos show_support all } show_log () { # Show log of current connection case "$FORM_nrlog" in all|$_MN_all|*[^0-9]*) n=$_MN_all ;; *[0-9]*) n=$FORM_nrlog ;; esac echo "

$_VPN_head_log ($n $_MN_rows):

" # Display form to change number of shown rows of logfile echo "" echo "" echo "" echo "" echo "" echo " $_MN_rows  " echo "" echo "" echo "
$_MN_time$_VPN_notice
" show_logfile $FORM_nrlog } show_secret () { # create secret [ -f /etc/openvpn/$keyfile -o -f /tmp/$keyfile ] || create_secret if [ -f /tmp/$keyfile ] && [ -f /etc/openvpn/$keyfile ] || [ -f /etc/openvpn/$keyfile.orig ] then rlink="\"undo\"" else rlink="\"undo\"" fi if [ -f /tmp/$keyfile ] then slink="\"save\"" keyfile=/tmp/$keyfile else slink="\"save\"" keyfile=/etc/openvpn/$keyfile fi echo "

Secret: $keyfile

" echo "
" echo "\"new\"" echo $slink echo $rlink echo "\"download\"" echo "" echo "" echo "" }
$_MN_date$_MN_time$_VPN_notice