Procházet zdrojové kódy

Extended reporting to html table, added search function, etc.

pmacko před 2 měsíci
rodič
revize
89a5f8a448
1 změnil soubory, kde provedl 72 přidání a 2 odebrání
  1. 72 2
      checkvpn.sh

+ 72 - 2
checkvpn.sh

@@ -2,7 +2,7 @@
 #########################################################################
 #                  Check VPN connection including users                 #
 #                           Created by DoIT-PM                          #
-#                               ver 0.2                                 #
+#                               ver 0.3                                 #
 #########################################################################
 
 #---------------------------- VARIABLES --------------------------------#
@@ -47,13 +47,83 @@ else
 fi
 }
 
+#---------------------------- WEB-REPORT -------------------------------#
+webrep(){
+echo -e "- \e[1;32mBuilding\e[0m webreport [\e[1;35m$WEB/menu.html\e[0m]"
+cat > $WEB/menu.html << EOF
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+table, td, th {
+    border: 1px solid #ddd;
+    text-align: center;
+    vertical-align: middle;
+}
+table {
+    border-collapse: collapse;
+    width: 100%;
+}
+th, td {
+    padding: 5px;
+}
+</style>
+</head>
+<title></title>
+<body>
+<table>
+<TD align="center">
+<form action="search.php" method="post">
+  <input type="text" name="search" placeholder="Type username or ..." size="60">
+  <input type="submit" name="submit" value="Search" />
+</form>
+</TD>
+</table>
+<table>
+EOF
+cat $WEB/vpn.clr | egrep -v "\---|ADDRESS" | awk '{print $1","$2,$3,$4,$5}' > $WEB/vpn.tab
+cat /tmp/vpn.rep | egrep -v "\---|ADDRESS" > /tmp/vpn.tab
+sed -i "s/^/$DAB,/" /tmp/vpn.tab
+cat /tmp/vpn.tab | egrep -v "\---|ADDRESS" >> $WEB/vpn.tab
+cat $WEB/vpn.tab | sed 's/,/ /g' | column -t > $WEB/vpn.src
+LST=$(cat $WEB/vpn.tab | awk '{print $1}')
+#NUMG=$(cat $WEB/vpn.tab | awk '{print $2}' | sort | uniq | wc -l)
+#NUMU=$(cat $WEB/vpn.tab | awk '{print $3}' | sort | uniq | wc -l)
+for i in $LST;
+do
+DATE=$(cat $WEB/vpn.tab | grep -w "$i" | sed 's/,/ /g' | awk '{print $1}')
+TIME=$(cat $WEB/vpn.tab | grep -w "$i" | sed 's/,/ /g' | awk '{print $2}')
+GROUP=$(cat $WEB/vpn.tab | grep -w "$i" | awk '{print $2}')
+USER=$(cat $WEB/vpn.tab | grep -w "$i" | awk '{print $3}')
+ADDRESS=$(cat $WEB/vpn.tab | grep -w "$i" | awk '{print $4}')
+cat >> $WEB/menu.html <<EOF
+<tr>
+<td width="20%">$DATE</td>
+<td width="20%">$TIME</td>
+<td width="20%">$GROUP</td>
+<td width="20%">$USER</td>
+<td width="20%">$ADDRESS</td>
+</tr>
+EOF
+done
+
+cat >> $WEB/menu.html <<\EOF
+</table>
+</body>
+</html>
+EOF
+#sed -i "s/NUMG/$NUMG/g" $WEB/menu.html
+#sed -i "s/NUMU/$NUMU/g" $WEB/menu.html
+}
+
 #------------------------------- CORE ----------------------------------#
 clear
 collect
 bigdata
+webrep
 cat $REP | column -t
 USR=$(cat $REP | awk '{print $3}' | egrep -v "USER|\---" | sort | uniq | wc -l)
 VPN=$(cat $REP | egrep -v "USER|\---" | sort | wc -l)
 echo -e "- Summary today VPN access: [\e[1;33m$VPN\e[0m]"
 echo -e "- Unique today VPN users: [\e[1;33m$USR\e[0m]"
-echo -e "- Report summary: [\e[1;35m$WEB/vpn.txt\e[0m]"
+echo -e "- Report summary: [\e[1;35m$WEB/vpn.txt\e[0m]"