source: trunk/push-web @ 363

Last change on this file since 363 was 363, checked in by g7moreau, 6 years ago
  • Very small detail
  • Property svn:executable set to *
File size: 6.0 KB
Line 
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
8export PATH=/bin:/sbin:/usr/bin:/usr/sbin
9export LANG=C
10
11SITE_NAME=''
12REMOTE_SERVER=localhost
13REMOTE_USER=''
14REMOTE_FOLDER=/var/www/klask/
15
16GRAPH_MODULO=9
17GRAPH_SHIFT=1
18
19if [ -f /etc/klask/push-web.conf ]
20then
21   . /etc/klask/push-web.conf
22fi
23
24TMP='/tmp/klask-push-web'
25
26
27# remote command
28DOT=/usr/bin/dot
29
30
31mkdir -p ${TMP}
32if [ ! -d ${TMP} ]
33then
34   echo "Error: Folder ${TMP} do not exist !"
35   exit 1
36fi
37cd ${TMP}
38
39
40LOCALTIME=$(date "+%Y-%m-%d %H:%M")
41
42
43klask exportsw --format dot --modulo ${GRAPH_MODULO} --shift ${GRAPH_SHIFT} > ${TMP}/switch-map.txt.new
44
45
46klask exportdb    > ${TMP}/hostname-db.txt
47klask exportsw    > ${TMP}/switch-db.txt
48klask ip-free     > ${TMP}/ipfree-db.txt
49klask bad-vlan-id > ${TMP}/badvlan-db.txt
50
51
52cat <<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>
63function delayedRefresh() {
64 setTimeout( "refresh()", 1800*1000 );
65 }
66
67function refresh() {
68 history.go(0);
69 }
70 
71function 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>
89Tool 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>
111END
112
113klask exportdb --format html >> ${TMP}/index.html
114
115cat <<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>
123END
124
125klask ip-free --format html >> ${TMP}/index.html
126
127cat <<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>
135END
136
137klask bad-vlan-id --format html >> ${TMP}/index.html
138
139cat <<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">
169Klask (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>
175END
176
177cmp --silent ${TMP}/switch-map.txt.new ${TMP}/switch-map.txt || mv -f ${TMP}/switch-map.txt.new ${TMP}/switch-map.txt
178
179if [ "${REMOTE_SERVER}" = "localhost" ]
180then
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
193else
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)"
206fi
Note: See TracBrowser for help on using the repository browser.