source: trunk/push-web @ 362

Last change on this file since 362 was 362, checked in by g7moreau, 8 years ago
  • Preserve times (and to not graph png figure again it not necessary)
  • Property svn:executable set to *
File size: 5.8 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   </p>
146   <img class="map" src="switch-map.png">
147 </div>
148
149 <div id="RAW_data" class="selectableTabContent" style="display:none">
150  <p>
151   The main raw results of Klask are accessible directly,
152   via <tt>wget</tt> or <tt>curl</tt> tools for example,
153   for any specific treatment:
154   <ul>
155    <li><a href="hostname-db.txt">Computers DB</a> (command <tt>klask exportdb --format txt</tt>),</li>
156    <li><a href="switch-db.txt">Switches DB</a> (command <tt>klask exportsw --format txt</tt>),</li>
157    <li><a href="ipfree-db.txt">IP available</a> (command <tt>klask ip-free --format txt</tt>),</li>
158    <li><a href="badvlan-db.txt">VLAN mismatch</a> (command <tt>klask bad-vlan-id --format txt</tt>),</li>
159    <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>
160   </ul>
161  </p>
162 </div>
163</div>
164
165<p class="copyright">
166Klask (version $(klask version | grep ^Version | cut -f 2 -d ' ')) - $(klask version | grep ^Copyright | cut -f 1 -d '<')
167</p>
168</body>
169</html>
170END
171
172cmp --silent ${TMP}/switch-map.txt.new ${TMP}/switch-map.txt || mv -f ${TMP}/switch-map.txt.new ${TMP}/switch-map.txt
173
174if [ "${REMOTE_SERVER}" = "localhost" ]
175then
176   rsync --times \
177      /usr/share/klask/sorttable-klask.js \
178      /usr/share/klask/style-klask.css \
179      ${TMP}/index.html \
180      ${TMP}/*-db.txt \
181      ${TMP}/switch-map.txt \
182      ${REMOTE_FOLDER}/
183
184   [ -x ${DOT} ] && (cd ${REMOTE_FOLDER};
185      [ switch-map.txt -nt switch-map.svg ] && ${DOT} -T svg switch-map.txt > switch-map.svg;
186      [ switch-map.txt -nt switch-map.png ] && ${DOT} -T png switch-map.txt > switch-map.png)
187
188else
189   rsync --times \
190      /usr/share/klask/sorttable-klask.js \
191      /usr/share/klask/style-klask.css \
192      ${TMP}/index.html \
193      ${TMP}/*-db.txt \
194      ${TMP}/switch-map.txt \
195      ${REMOTE_USER}@${REMOTE_SERVER}:${REMOTE_FOLDER}/
196
197
198   ssh ${REMOTE_USER}@${REMOTE_SERVER} "(cd ${REMOTE_FOLDER};
199      [ switch-map.txt -nt switch-map.svg ] && ${DOT} -T svg switch-map.txt > switch-map.svg;
200      [ switch-map.txt -nt switch-map.png ] && ${DOT} -T png switch-map.txt > switch-map.png)"
201fi
Note: See TracBrowser for help on using the repository browser.