Commit 1112fcdd authored by Matthew Smith's avatar Matthew Smith
Browse files

Fix html generation

parent 7ca2a62e
......@@ -11,7 +11,7 @@ For watching, its probably best to use 'watch ovs status'.
}
function open_table_section() {
function Open_Table_Section() {
echo "
<tbody>
<tr>
......@@ -20,7 +20,7 @@ function open_table_section() {
"
}
function create_table_row() {
function Create_Table_Row() {
echo "
<tr class=\"$row_class\">
<td>$vpn_name</td>
......@@ -31,7 +31,7 @@ function create_table_row() {
"
}
function close_table_section {
function Close_Table_Section {
echo "
</tbody>
"
......@@ -56,11 +56,11 @@ function close_table_section {
#ovs status --disconnect &
#return 0
function create_Html_Status() {
function Create_Html_Status() {
rm /tmp/vpnstatus_*.html
rm /tmp/vpnstatus_*.html 2>&1
local template_html="/template/path/status.html"
local template_html="/usr/share/openvpn-server/config-templates/status.html"
local tmp_html="/tmp/vpnstatus_$$.html"
local connected_user=""
......@@ -79,23 +79,23 @@ function create_Html_Status() {
fi
if [ "$connection_type" == "connect" ] || [ "$connection_type" == "disconnect" ]; then
generated_details="<p>The most recent user was $this_vpnname who "`echo '$connection_type' | sed s/-//g`"ed from $public_ip at "`date`".<\/p>"
generated_details="<p>The most recent user was $this_vpnname who "`echo '$connection_type' | sed -e "s/-//g"`"ed from $public_ip at "`date`".<\/p>"
else
generated_details="<p>Generated on `date`.<\/p>"
fi
table_body=$(open_table_section)
table_body=$(Open_Table_Section)
TODO: Can we get this from the server conf?
#TODO: Can we get this from the server conf?
openvpn_index="/var/lib/openvpn-server/openssl/index.txt"
for vpn_name in `grep ^V $openvpn_index | grep emailAddress | sed "s/\/emailAddress//g" | awk -F"=" {'print $5'}`; do
for vpn_name in `grep ^V $openvpn_index | grep emailAddress | sed -e "s/\/emailAddress//g" | awk -F"=" {'print $5'}`; do
## Details of current status
#tail /var/lib/openvpn-server/openvpn/status.log | grep ltu-kit01 | tail -n1 | awk -F"," {'print $2 " " $1 " " $3 " " $4'} | sed -e 's/:[0-9]\{3,5\}//g'
connected_user=""
connected_user=$(grep "^CLIENT_LIST" "$status_log" | grep $vpn_name | sed -e 's/:[0-9]\{3,5\}//g')
connected_user=$(grep "^CLIENT_LIST" "$status_log" | grep $vpn_name | sed -e "s/:[0-9]\{3,5\}//g")
public_ip=""
public_ip=$(echo $connected_user | cut -f3 -d",")
......@@ -118,7 +118,7 @@ function create_Html_Status() {
row_class="$connection_type"
fi
elif grep -q $vpn_name "$status_log" ; then # non triggering connected user
elif grep -q $vpn_name "$status_log" ; then # non triggering connected user
row_class="connected"
vpn_ip=$(echo $connected_user | cut -f2 -d",")
connenected_since=$(echo $connected_user | cut -f7 -d",")
......@@ -126,15 +126,18 @@ function create_Html_Status() {
else # not connected
echo -n ""
fi
table_body+=$(create_table_row)
table_body+=$(Create_Table_Row)
done
table_body+=$(close_table_section)
table_body+=$(Close_Table_Section)
generated_details=`echo $generated_details | sed 's/</\\\\\</g; s/>/\\\\\>/g; s/"/\\\\\"/g;'`
table_body=`echo $table_body | sed 's/</\\\\\</g; s/>/\\\\\>/g; s/"/\\\\\"/g;'`
#TODO: These should be going from the template to the tmp file
cp "$template_html" "$tmp_html"
sed -i -e "s/$script_name/%%SCRIPTNAME%%/g" -e "s/$generated_details/%%GENERATED_DETAILS%%/g" -e "s/$table_body/%%TABLE_BODY%%/g" "$tmp_html"
sed -i -e "s|%%SCRIPTNAME%%|$script_name|g" -e "s|%%GENERATED_DETAILS%%|$generated_details|g" -e "s|%%TABLE_BODY%%|$table_body|g" "$tmp_html"
if [ "" != "$live_html" ]; then
cp "$tmp_html" "$live_html"
......@@ -151,13 +154,13 @@ function Echo_Status() {
grep CLIENT_LIST "$status_log" | head -n1 | sed -e "s/HEADER,//g" | awk -F "," '{printf "%-20s %-18s %-18s %-25s %14s %12s Routes\n",$2,$3,$4,$7,$5,$6}'
for client in $(grep ^CLIENT_LIST "$status_log" | awk -F "," '{print $2}'); do
row=$(grep ^CLIENT_LIST "$status_log" | sed -e 's/:[0-9]\{3,5\}//g' | grep "$client")
row=$(grep ^CLIENT_LIST "$status_log" | sed -e "s/:[0-9]\{3,5\}//g" | grep "$client")
routes=$(grep ^ROUTING_TABLE "$status_log" | grep "$client" | awk -F "," '{printf "%s|",$2}')
echo "$row,${routes::-1}" | awk -F "," '{printf "%-20s %-18s %-18s %-25s %11.0f MB %9.0f MB %2s\n",$2,$3,$4,$7,$5/1024/1024,$6/1024/1024,$10}'
done
echo " "
Bandwidth
echo " "
Bandwidth
}
function Bandwidth() {
......@@ -176,27 +179,27 @@ script_name="$0"
status_log=`grep "status " /etc/openvpn/$OVPN_ORGNICK-server.conf |cut -f2 -d ' '`
connection_type=""
if grep -q "status-version 2" "/etc/openvpn/$OVPN_ORGNICK-server.conf" ; then
case $1 in
--help)
Usage
;;
--html|--connect|--disconnect)
connection_type=`echo "$1" | sed "s/-//g"`
Create_Html_Status
;;
*)
Echo_Status
;;
esac
if grep -q "status-version 2" "/etc/openvpn/$OVPN_ORGNICK-server.conf" ; then
case $1 in
--help)
Usage
;;
--html|--connect|--disconnect)
connection_type=`echo "$1" | sed -e "s/-//g"`
Create_Html_Status
;;
*)
Echo_Status
;;
esac
else
echo "INFO: Add the line 'status-version 2' to /etc/openvpn/$OVPN_ORGNICK-server.conf for fancy or html output"
echo " "
cat $status_log
echo " "
Bandwidth
echo "INFO: Add the line 'status-version 2' to /etc/openvpn/$OVPN_ORGNICK-server.conf for fancy or html output"
echo " "
cat $status_log
echo " "
Bandwidth
fi
fi
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment