| 1 | #!/bin/bash |
|---|
| 2 | # |
|---|
| 3 | # 2007/10/23 gabriel |
|---|
| 4 | # 2010/11/03 gabriel |
|---|
| 5 | # 2011/03/30 gabriel - make it generic |
|---|
| 6 | |
|---|
| 7 | SITE_NAME='' |
|---|
| 8 | REMOTE_SERVER=localhost |
|---|
| 9 | REMOTE_USER='' |
|---|
| 10 | REMOTE_FOLDER=/var/www/klask/ |
|---|
| 11 | |
|---|
| 12 | GRAPH_MODULO=9 |
|---|
| 13 | GRAPH_SHIFT=1 |
|---|
| 14 | |
|---|
| 15 | if [ -f /etc/klask/push-web.conf ] |
|---|
| 16 | then |
|---|
| 17 | . /etc/klask/push-web.conf |
|---|
| 18 | fi |
|---|
| 19 | |
|---|
| 20 | TMP='/tmp/klask-push-web' |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | # local command |
|---|
| 24 | MKDIR=/bin/mkdir |
|---|
| 25 | DATE=/bin/date |
|---|
| 26 | CAT=/bin/cat |
|---|
| 27 | TAIL=/usr/bin/tail |
|---|
| 28 | HEAD=/usr/bin/head |
|---|
| 29 | SSH=/usr/bin/ssh |
|---|
| 30 | SCP=/usr/bin/scp |
|---|
| 31 | KLASK=/usr/sbin/klask |
|---|
| 32 | RSYNC=/usr/bin/rsync |
|---|
| 33 | |
|---|
| 34 | # remote command |
|---|
| 35 | DOT=/usr/bin/dot |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | $MKDIR -p ${TMP} |
|---|
| 39 | if [ ! -d ${TMP} ] |
|---|
| 40 | then |
|---|
| 41 | echo "Error: Folder ${TMP} do not exist !" |
|---|
| 42 | exit 1 |
|---|
| 43 | fi |
|---|
| 44 | cd ${TMP} |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | LOCALTIME=$($DATE "+%Y-%m-%d %H:%M") |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | $KLASK exportsw --format dot --modulo ${GRAPH_MODULO} --shift ${GRAPH_SHIFT} > ${TMP}/switch-map.txt |
|---|
| 51 | |
|---|
| 52 | |
|---|
| 53 | $KLASK exportdb > ${TMP}/hostname-db.txt |
|---|
| 54 | $KLASK exportsw > ${TMP}/switch-db.txt |
|---|
| 55 | $KLASK ip-free > ${TMP}/ipfree-db.txt |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | $CAT <<END > ${TMP}/index.html |
|---|
| 59 | <html> |
|---|
| 60 | <head> |
|---|
| 61 | <link rel="stylesheet" type="text/css" href="style-klask.css" /> |
|---|
| 62 | <meta http-equiv="refresh" content="1800"> |
|---|
| 63 | <noscript> |
|---|
| 64 | </noscript> |
|---|
| 65 | <script src="sorttable-klask.js"></script> |
|---|
| 66 | <script> |
|---|
| 67 | function delayedRefresh() { |
|---|
| 68 | setTimeout( "refresh()", 1800*1000 ); |
|---|
| 69 | } |
|---|
| 70 | |
|---|
| 71 | function refresh() { |
|---|
| 72 | history.go(0); |
|---|
| 73 | } |
|---|
| 74 | </script> |
|---|
| 75 | </head> |
|---|
| 76 | <body onload="delayedRefresh"> |
|---|
| 77 | <h1> |
|---|
| 78 | <b><a href="http://servforge.legi.grenoble-inp.fr/projects/klask">Klask</a></b> |
|---|
| 79 | - Un outil pour <a href="switch-map.png">cartographier</a> (<a href="switch-map.svg">svg</a>) le réseau [${LOCALTIME}] - site ${SITE_NAME} |
|---|
| 80 | </h1> |
|---|
| 81 | |
|---|
| 82 | <p> |
|---|
| 83 | Ce portail présente : |
|---|
| 84 | toutes les <b>IP détectées</b>, |
|---|
| 85 | les <a href="ip-free.html">IP non détectées</a> depuis plus de deux années, |
|---|
| 86 | les <a href="bad-vlan-id.html">machines configurées dans un mauvais VLAN</a>. |
|---|
| 87 | </p> |
|---|
| 88 | |
|---|
| 89 | <p> |
|---|
| 90 | Les résultats brut de Klask sont accessibles directement via wget ou curl, par exemple, pour un traitement spécifique : |
|---|
| 91 | <a href="hostname-db.txt">Machines</a>, |
|---|
| 92 | <a href="switch-db.txt">Commutateurs</a>, |
|---|
| 93 | <a href="ipfree-db.txt">IP disponibles</a>, |
|---|
| 94 | <a href="switch-map.txt">Carte</a>. |
|---|
| 95 | </p> |
|---|
| 96 | END |
|---|
| 97 | |
|---|
| 98 | $KLASK exportdb --format html >> ${TMP}/index.html |
|---|
| 99 | |
|---|
| 100 | $CAT <<END >> ${TMP}/index.html |
|---|
| 101 | </body> |
|---|
| 102 | </html> |
|---|
| 103 | END |
|---|
| 104 | |
|---|
| 105 | |
|---|
| 106 | $CAT <<END > ${TMP}/ip-free.html |
|---|
| 107 | <html> |
|---|
| 108 | <head> |
|---|
| 109 | <link rel="stylesheet" type="text/css" href="style-klask.css" /> |
|---|
| 110 | <meta http-equiv="refresh" content="1800"> |
|---|
| 111 | <script src="sorttable-klask.js"></script> |
|---|
| 112 | </head> |
|---|
| 113 | <body> |
|---|
| 114 | <h1> |
|---|
| 115 | <b><a href="http://servforge.legi.grenoble-inp.fr/projects/klask">Klask</a></b> |
|---|
| 116 | - Un outil pour <a href="switch-map.png">cartographier</a> (<a href="switch-map.svg">svg</a>) le réseau [${LOCALTIME}] - site ${SITE_NAME} |
|---|
| 117 | </h1> |
|---|
| 118 | |
|---|
| 119 | <p> |
|---|
| 120 | Ce portail présente : |
|---|
| 121 | toutes les <a href="index.html">IP détectées</a>, |
|---|
| 122 | les <b>IP non détectées</b> depuis plus de deux années, |
|---|
| 123 | les <a href="bad-vlan-id.html">machines configurées dans un mauvais VLAN</a>. |
|---|
| 124 | </p> |
|---|
| 125 | |
|---|
| 126 | <p> |
|---|
| 127 | Les résultats brut de Klask sont accessibles directement via wget ou curl, par exemple, pour un traitement spécifique : |
|---|
| 128 | <a href="hostname-db.txt">Machines</a>, |
|---|
| 129 | <a href="switch-db.txt">Commutateurs</a>, |
|---|
| 130 | <a href="ipfree-db.txt">IP disponibles</a>, |
|---|
| 131 | <a href="switch-map.txt">Carte</a>. |
|---|
| 132 | </p> |
|---|
| 133 | END |
|---|
| 134 | |
|---|
| 135 | $KLASK ip-free --format html >> ${TMP}/ip-free.html |
|---|
| 136 | |
|---|
| 137 | $CAT <<END >> ${TMP}/ip-free.html |
|---|
| 138 | </body> |
|---|
| 139 | </html> |
|---|
| 140 | END |
|---|
| 141 | |
|---|
| 142 | |
|---|
| 143 | $CAT <<END > ${TMP}/bad-vlan-id.html |
|---|
| 144 | <html> |
|---|
| 145 | <head> |
|---|
| 146 | <link rel="stylesheet" type="text/css" href="style-klask.css" /> |
|---|
| 147 | <meta http-equiv="refresh" content="1800"> |
|---|
| 148 | <script src="sorttable-klask.js"></script> |
|---|
| 149 | </head> |
|---|
| 150 | <body> |
|---|
| 151 | <h1> |
|---|
| 152 | <b><a href="http://servforge.legi.grenoble-inp.fr/projects/klask">Klask</a></b> |
|---|
| 153 | - Un outil pour <a href="switch-map.png">cartographier</a> (<a href="switch-map.svg">svg</a>) le réseau [${LOCALTIME}] - site ${SITE_NAME} |
|---|
| 154 | </h1> |
|---|
| 155 | |
|---|
| 156 | <p> |
|---|
| 157 | Ce portail présente : |
|---|
| 158 | toutes les <a href="index.html">IP détectées</a>, |
|---|
| 159 | les <a href="ip-free.html">IP non détectées</a> depuis plus de deux années, |
|---|
| 160 | les <b>machines configurées dans un mauvais VLAN</b>. |
|---|
| 161 | </p> |
|---|
| 162 | |
|---|
| 163 | <p> |
|---|
| 164 | Les résultats brut de Klask sont accessibles directement via wget ou curl, par exemple, pour un traitement spécifique : |
|---|
| 165 | <a href="hostname-db.txt">Machines</a>, |
|---|
| 166 | <a href="switch-db.txt">Commutateurs</a>, |
|---|
| 167 | <a href="ipfree-db.txt">IP disponibles</a>, |
|---|
| 168 | <a href="switch-map.txt">Carte</a>. |
|---|
| 169 | </p> |
|---|
| 170 | END |
|---|
| 171 | |
|---|
| 172 | $KLASK bad-vlan-id --format html >> ${TMP}/bad-vlan-id.html |
|---|
| 173 | |
|---|
| 174 | $CAT <<END >> ${TMP}/bad-vlan-id.html |
|---|
| 175 | </body> |
|---|
| 176 | </html> |
|---|
| 177 | END |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | if [ "${REMOTE_SERVER}" = "localhost" ] |
|---|
| 181 | then |
|---|
| 182 | $RSYNC \ |
|---|
| 183 | /usr/share/klask/sorttable-klask.js \ |
|---|
| 184 | /usr/share/klask/style-klask.css \ |
|---|
| 185 | ${TMP}/index.html \ |
|---|
| 186 | ${TMP}/ip-free.html \ |
|---|
| 187 | ${TMP}/bad-vlan-id.html \ |
|---|
| 188 | ${TMP}/*-db.txt \ |
|---|
| 189 | ${TMP}/switch-map.txt \ |
|---|
| 190 | ${REMOTE_FOLDER}/ |
|---|
| 191 | |
|---|
| 192 | [ -x ${DOT} ] && (cd ${REMOTE_FOLDER}; ${DOT} -T svg switch-map.txt > switch-map.svg; ${DOT} -T png switch-map.txt > switch-map.png) |
|---|
| 193 | |
|---|
| 194 | else |
|---|
| 195 | $RSYNC \ |
|---|
| 196 | /usr/share/klask/sorttable-klask.js \ |
|---|
| 197 | /usr/share/klask/style-klask.css \ |
|---|
| 198 | ${TMP}/index.html \ |
|---|
| 199 | ${TMP}/ip-free.html \ |
|---|
| 200 | ${TMP}/bad-vlan-id.html \ |
|---|
| 201 | ${TMP}/*-db.txt \ |
|---|
| 202 | ${TMP}/switch-map.txt \ |
|---|
| 203 | ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_FOLDER}/ |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | $SSH ${REMOTE_USER}@${REMOTE_SERVER} "(cd ${REMOTE_FOLDER}; ${DOT} -T svg switch-map.txt > switch-map.svg; ${DOT} -T png switch-map.txt > switch-map.png)" |
|---|
| 207 | fi |
|---|