| 1 | #!/bin/bash |
---|
| 2 | # |
---|
| 3 | # 2007/10/23 Gabriel Moreau |
---|
| 4 | # 2010/11/03 Gabriel Moreau |
---|
| 5 | # 2011/03/30 Gabriel Moreau - make it generic |
---|
| 6 | # 2017/11/04 Gabriel Moreau - all reworks - use tab |
---|
| 7 | |
---|
| 8 | export PATH=/bin:/sbin:/usr/bin:/usr/sbin |
---|
| 9 | export LANG=C |
---|
| 10 | |
---|
| 11 | SITE_NAME='' |
---|
| 12 | REMOTE_SERVER=localhost |
---|
| 13 | REMOTE_USER='' |
---|
| 14 | REMOTE_FOLDER=/var/www/klask/ |
---|
| 15 | |
---|
| 16 | GRAPH_MODULO=9 |
---|
| 17 | GRAPH_SHIFT=1 |
---|
| 18 | |
---|
| 19 | if [ -f /etc/klask/push-web.conf ] |
---|
| 20 | then |
---|
| 21 | . /etc/klask/push-web.conf |
---|
| 22 | fi |
---|
| 23 | |
---|
| 24 | TMP='/tmp/klask-push-web' |
---|
| 25 | |
---|
| 26 | |
---|
| 27 | # remote command |
---|
| 28 | DOT=/usr/bin/dot |
---|
| 29 | |
---|
| 30 | |
---|
| 31 | mkdir -p ${TMP} |
---|
| 32 | if [ ! -d ${TMP} ] |
---|
| 33 | then |
---|
| 34 | echo "Error: Folder ${TMP} do not exist !" |
---|
| 35 | exit 1 |
---|
| 36 | fi |
---|
| 37 | cd ${TMP} |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | LOCALTIME=$(date "+%Y-%m-%d %H:%M") |
---|
| 41 | |
---|
| 42 | |
---|
| 43 | klask exportsw --format dot --modulo ${GRAPH_MODULO} --shift ${GRAPH_SHIFT} > ${TMP}/switch-map.txt.new |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | klask exportdb > ${TMP}/hostname-db.txt |
---|
| 47 | klask exportsw > ${TMP}/switch-db.txt |
---|
| 48 | klask ip-free > ${TMP}/ipfree-db.txt |
---|
| 49 | klask bad-vlan-id > ${TMP}/badvlan-db.txt |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | cat <<END > ${TMP}/index.html |
---|
| 53 | <!DOCTYPE html> |
---|
| 54 | <html lang="en"> |
---|
| 55 | <head> |
---|
| 56 | <link rel="stylesheet" type="text/css" href="style-klask.css" /> |
---|
| 57 | <!-- <meta http-equiv="refresh" content="1800"> --> |
---|
| 58 | <title>Klask mapping net-tools</title> |
---|
| 59 | <noscript> |
---|
| 60 | </noscript> |
---|
| 61 | <script src="sorttable-klask.js"></script> |
---|
| 62 | <script> |
---|
| 63 | function delayedRefresh() { |
---|
| 64 | setTimeout( "refresh()", 1800*1000 ); |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | function refresh() { |
---|
| 68 | history.go(0); |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | function selectTab(event, tabName) { |
---|
| 72 | var i; |
---|
| 73 | var x = document.getElementsByClassName("selectableTabContent"); |
---|
| 74 | var tablinks = document.getElementsByClassName("selectableTabButton"); |
---|
| 75 | for (i = 0; i < x.length; i++) { |
---|
| 76 | x[i].style.display = "none"; |
---|
| 77 | } |
---|
| 78 | for (i = 0; i < x.length; i++) { |
---|
| 79 | tablinks[i].id = ""; |
---|
| 80 | } |
---|
| 81 | document.getElementById(tabName).style.display = "block"; |
---|
| 82 | event.currentTarget.id = "selected"; |
---|
| 83 | } |
---|
| 84 | </script> |
---|
| 85 | </head> |
---|
| 86 | <body> <!-- onload="delayedRefresh" --> |
---|
| 87 | <h1> |
---|
| 88 | <b><a href="http://servforge.legi.grenoble-inp.fr/projects/klask" class="circle">Klask</a></b> |
---|
| 89 | Tool for <a href="switch-map.png">mapping</a> the local network - site ${SITE_NAME} |
---|
| 90 | <a class="refresh" href="./">${LOCALTIME}</a> |
---|
| 91 | </h1> |
---|
| 92 | |
---|
| 93 | <div id="navbar"> |
---|
| 94 | <ul> |
---|
| 95 | <li class="selectableTabButton" onclick="selectTab(event, 'IP_detected')" id="selected">IP detected</li> |
---|
| 96 | <li class="selectableTabButton" onclick="selectTab(event, 'IP_available')">IP available</li> |
---|
| 97 | <li class="selectableTabButton" onclick="selectTab(event, 'VLAN_mismatch')">VLAN mismatch</li> |
---|
| 98 | <li class="selectableTabButton" onclick="selectTab(event, 'MAP')">MAP (png)</li> |
---|
| 99 | <li class="selectableTabButton" onclick="selectTab(event, 'RAW_data')">RAW data</li> |
---|
| 100 | </ul> |
---|
| 101 | </div> |
---|
| 102 | |
---|
| 103 | <div id="content"> |
---|
| 104 | |
---|
| 105 | <div id="IP_detected" class="selectableTabContent"> |
---|
| 106 | <p> |
---|
| 107 | List of all IP addresses detected on the local network (on all VLANs) |
---|
| 108 | since the origin of the database |
---|
| 109 | (except those that have been deleted manually and voluntarily). |
---|
| 110 | </p> |
---|
| 111 | END |
---|
| 112 | |
---|
| 113 | klask exportdb --format html >> ${TMP}/index.html |
---|
| 114 | |
---|
| 115 | cat <<END >> ${TMP}/index.html |
---|
| 116 | </div> |
---|
| 117 | |
---|
| 118 | <div id="IP_available" class="selectableTabContent" style="display:none"> |
---|
| 119 | <p> |
---|
| 120 | List all free IP addresses (which have never been used or not used for two years). |
---|
| 121 | These IP addresses are available to assign to all new computers. |
---|
| 122 | </p> |
---|
| 123 | END |
---|
| 124 | |
---|
| 125 | klask ip-free --format html >> ${TMP}/index.html |
---|
| 126 | |
---|
| 127 | cat <<END >> ${TMP}/index.html |
---|
| 128 | </div> |
---|
| 129 | |
---|
| 130 | <div id="VLAN_mismatch" class="selectableTabContent" style="display:none"> |
---|
| 131 | <p> |
---|
| 132 | List all computers connected to switches where the VLAN is misconfigured. |
---|
| 133 | Returns the port and VLAN to configure on these switches. |
---|
| 134 | </p> |
---|
| 135 | END |
---|
| 136 | |
---|
| 137 | klask bad-vlan-id --format html >> ${TMP}/index.html |
---|
| 138 | |
---|
| 139 | cat <<END >> ${TMP}/index.html |
---|
| 140 | </div> |
---|
| 141 | |
---|
| 142 | <div id="MAP" class="selectableTabContent" style="display:none"> |
---|
| 143 | <p> |
---|
| 144 | Direct link to local network map in the formats <a href="switch-map.png">png</a> and <a href="switch-map.svg">svg</a>. |
---|
| 145 | Because the map could be big, |
---|
| 146 | you will have a better web experience with |
---|
| 147 | <a href="https://addons.mozilla.org/en-US/firefox/addon/image-zoom/">Image Zoom<a> plugin (or equivalent) installed. |
---|
| 148 | </p> |
---|
| 149 | <img class="map" src="switch-map.png"> |
---|
| 150 | </div> |
---|
| 151 | |
---|
| 152 | <div id="RAW_data" class="selectableTabContent" style="display:none"> |
---|
| 153 | <p> |
---|
| 154 | The main raw results of Klask are accessible directly, |
---|
| 155 | via <tt>wget</tt> or <tt>curl</tt> tools for example, |
---|
| 156 | for any specific treatment: |
---|
| 157 | <ul> |
---|
| 158 | <li><a href="hostname-db.txt">Computers DB</a> (command <tt>klask exportdb --format txt</tt>),</li> |
---|
| 159 | <li><a href="switch-db.txt">Switches DB</a> (command <tt>klask exportsw --format txt</tt>),</li> |
---|
| 160 | <li><a href="ipfree-db.txt">IP available</a> (command <tt>klask ip-free --format txt</tt>),</li> |
---|
| 161 | <li><a href="badvlan-db.txt">VLAN mismatch</a> (command <tt>klask bad-vlan-id --format txt</tt>),</li> |
---|
| 162 | <li>Map format: <a href="switch-map.txt">dot source</a> (graphviz), <a href="switch-map.png">png</a>, <a href="switch-map.svg">svg</a>.</li> |
---|
| 163 | </ul> |
---|
| 164 | </p> |
---|
| 165 | </div> |
---|
| 166 | </div> |
---|
| 167 | |
---|
| 168 | <p class="copyright"> |
---|
| 169 | Klask (version $(klask version | grep ^Version | cut -f 2 -d ' ')) - $(klask version | grep ^Copyright | cut -f 1 -d '<') |
---|
| 170 | </p> |
---|
| 171 | <!-- Try to prefect switch map image --> |
---|
| 172 | <link rel="prefetch" href="switch-map.png"> |
---|
| 173 | </body> |
---|
| 174 | </html> |
---|
| 175 | END |
---|
| 176 | |
---|
| 177 | cmp --silent ${TMP}/switch-map.txt.new ${TMP}/switch-map.txt || mv -f ${TMP}/switch-map.txt.new ${TMP}/switch-map.txt |
---|
| 178 | |
---|
| 179 | if [ "${REMOTE_SERVER}" = "localhost" ] |
---|
| 180 | then |
---|
| 181 | rsync --times \ |
---|
| 182 | /usr/share/klask/sorttable-klask.js \ |
---|
| 183 | /usr/share/klask/style-klask.css \ |
---|
| 184 | ${TMP}/index.html \ |
---|
| 185 | ${TMP}/*-db.txt \ |
---|
| 186 | ${TMP}/switch-map.txt \ |
---|
| 187 | ${REMOTE_FOLDER}/ |
---|
| 188 | |
---|
| 189 | [ -x ${DOT} ] && (cd ${REMOTE_FOLDER}; |
---|
| 190 | [ switch-map.txt -nt switch-map.svg ] && ${DOT} -T svg switch-map.txt > switch-map.svg; |
---|
| 191 | [ switch-map.txt -nt switch-map.png ] && ${DOT} -T png switch-map.txt > switch-map.png) |
---|
| 192 | |
---|
| 193 | else |
---|
| 194 | rsync --times \ |
---|
| 195 | /usr/share/klask/sorttable-klask.js \ |
---|
| 196 | /usr/share/klask/style-klask.css \ |
---|
| 197 | ${TMP}/index.html \ |
---|
| 198 | ${TMP}/*-db.txt \ |
---|
| 199 | ${TMP}/switch-map.txt \ |
---|
| 200 | ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_FOLDER}/ |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | ssh ${REMOTE_USER}@${REMOTE_SERVER} "(cd ${REMOTE_FOLDER}; |
---|
| 204 | [ switch-map.txt -nt switch-map.svg ] && ${DOT} -T svg switch-map.txt > switch-map.svg; |
---|
| 205 | [ switch-map.txt -nt switch-map.png ] && ${DOT} -T png switch-map.txt > switch-map.png)" |
---|
| 206 | fi |
---|