-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.php
302 lines (271 loc) · 12.3 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
<?php
$SUPRESS_NOTLOGGEDIN_MESSAGE = true;
require_once('php/session.php');
require_once('php/functions.php');
require_once('config.php');
require_once('php/switchoperations.php');
require_once('lang.php');
/* READ INPUT */
$cSwitch = null; // current switch
$switch = "";
$port = "";
$vlan = "";
$voip = "";
$desc = "";
if (isset($_POST['port']))
$port = removeInvalidChars($_POST['port']);
elseif (isset($_GET['port']))
$port = removeInvalidChars($_GET['port']);
if (isset($_POST['vlan']))
$vlan = intval($_POST['vlan']);
elseif (isset($_GET['vlan']))
$vlan = intval($_GET['vlan']);
if (isset($_POST['voip']))
$voip = $_POST['voip'];
elseif (isset($_GET['voip']))
$voip = $_GET['voip'];
if (isset($_POST['description']))
$desc = removeInvalidChars($_POST['description']);
elseif (isset($_GET['description']))
$desc = removeInvalidChars($_GET['description']);
if (isset($_POST['switch']))
$switch = removeInvalidChars($_POST['switch']);
elseif (isset($_GET['switch']))
$switch = removeInvalidChars($_GET['switch']);
/*** GET SWITCH OBJECT ***/
$cSwitch = getSwitchByAddr($switch);
/*** CHANGE PORT SETTINGS IF REQUESTED ***/
$cmdOutput = "";
$info = "";
$infoClass = "";
if($cSwitch != null && isset($_POST['action']) && $_POST['action'] === 'SETVALUES') {
if(startsWith($port, VISIBLE_PORTS) && !startsWith($port, HIDDEN_PORTS)) {
$cmdOutput = setValues($cSwitch['addr'], $port, $vlan, $desc, $voip);
$info = translate('New settings sent to switch.', false);
$infoClass = "ok";
}
}
/*** READ PORT INFO ***/
$interfaces = array();
if($cSwitch != null) {
$new_interfaces = getAllPortsOnSwitch($cSwitch['addr'], true, true);
if($new_interfaces === "ERR:AUTH") {
$cSwitch = null;
$infoClass = "error";
$info = translate('Switch authentication failed.', false);
}
elseif($new_interfaces === "ERR:CONN") {
$cSwitch = null;
$infoClass = "error";
$info = translate('Error while establishing connection to switch.', false);
}
else {
$interfaces = $new_interfaces;
foreach($interfaces as $interface) {
if($interface['port'] == $port) {
$vlan = $interface['vlan'];
$desc = $interface['desc'];
if($interface['voip'] != "none" && $interface['voip'] != "")
$voip = "enabled";
else
$voip = "disabled";
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title><?php translate('Switchconfig'); ?></title>
<?php require('head.inc.php'); ?>
<script language='javascript' type='text/javascript' src='js/explode.js'></script>
</head>
<body>
<script>
function beginFadeOutAnimation() {
document.body.classList.add('loading');
document.getElementById('imgSwitch').classList.remove('delayIn');
document.getElementById('imgSwitch').style.opacity = 0;
document.getElementById('imgLoading').style.opacity = 1;
document.getElementById('submit_changeform').innerHTML = "<?php translate('Please wait...'); ?>";
// disable fields while loading/applying changes
document.getElementById('switch').setAttribute('readOnly', true);
document.getElementById('port').setAttribute('readOnly', true);
document.getElementById('vlan').setAttribute('readOnly', true);
document.getElementById('voip').setAttribute('readOnly', true);
document.getElementById('description').setAttribute('readOnly', true);
document.getElementById('submit_changeform').setAttribute('disabled', true);
document.getElementById('function_intstatuslist').setAttribute('disabled', true);
document.getElementById('function_intmatrix').setAttribute('disabled', true);
document.getElementById('function_snippets').setAttribute('disabled', true);
document.getElementById('function_search').setAttribute('disabled', true);
}
</script>
<?php if(!empty($cmdOutput)) { ?>
<span id='sshDebugOutput'>
[DEBUG] SSH SWITCH OUTPUT:
<?php echo $cmdOutput . "\n" ?>
</span>
<?php } ?>
<div id='container'>
<h1 id='title'><div id='logo'></div></h1>
<div id='splash' class='login'>
<div id='subtitle'>
<div id='imgContainer'>
<img id='imgLoading' src='img/loading.svg'></img>
<?php if($infoClass == 'ok') { ?>
<img id='imgSwitch' src='img/switch.png' class='easteregg-trigger delayIn' onclick='boom()' title='initiate self destruction'></img>
<img id='imgTick' class='delayOut' src='img/tick_anim.svg'></img>
<?php } else { ?>
<img id='imgSwitch' src='img/switch.png' class='easteregg-trigger' onclick='boom()' title='initiate self destruction'></img>
<?php } ?>
</div>
<?php translate('This web application allows you to configure Cisco switches through a graphical interface.'); ?>
</div>
<?php if($info != '') { ?>
<tr><td><div class='infobox <?php echo $infoClass; ?>'><?php echo $info; ?></div></td></tr>
<?php } ?>
<form method='GET' name='switchform' onsubmit='beginFadeOutAnimation();'>
<div class='form-row'>
<select name='switch' value='' id='switch' height='1' class='fullwidth hand' autofocus='true' onchange='this.form.submit(); beginFadeOutAnimation();'>
<?php if($cSwitch == null) { ?>
<option value='' selected='true' disabled='true'>>>> <?php translate("Please select"); ?> <<<</option>
<?php } ?>
<?php
$last_group = '';
foreach(SWITCHES as $s) {
if($s['group'] != $last_group) {
echo "</optgroup>\n";
echo "<optgroup label='" . $s['group'] . "'>\n";
$last_group = $s['group'];
}
$select = "";
if($cSwitch != null && $s['addr'] == $cSwitch['addr']) $select = "selected";
echo "<option value='" . $s['addr'] . "' $select>" . $s['name'] . "</option>\n";
}
?>
</select>
<span class='tip'><label for='switch'><?php translate('Switch'); ?></label></span>
<?php
$mapresult = $cSwitch==null ? false : switchOnMapAvail(MAPS, $cSwitch['addr']);
if($mapresult !== false) {
echo "<a href='maps.php?map=" . $mapresult . "&highlightswitch=".$cSwitch['addr']."#".$cSwitch['addr']."'><img src='img/location.svg' title='Zeige Switch auf Karte' class='tipicon pointer pulse'></img></a>\n";
}
?>
</div>
</form>
<form method='GET' name='portform' onsubmit='beginFadeOutAnimation();'>
<div class='form-row tooltip'>
<input type='hidden' name='switch' value='<?php echo $cSwitch==null ? '' : $cSwitch['addr']; ?>'></input>
<select name='port' value='' id='port' height='1' class='fullwidth hand' onchange='this.form.submit(); beginFadeOutAnimation();' <?php if($cSwitch == null) echo "disabled"; ?>>
<?php
if($port == "" && $cSwitch != null)
echo "<option value='' selected='true' disabled='true'>>>> ".translate("Please select",false)." <<<</option>";
$icon = null;
$status = "";
$queried_port_found = false;
foreach($interfaces as $interface) {
if($interface['vlan'] != 'trunk' // don't show trunk ports
&& startsWith($interface['port'], VISIBLE_PORTS) // show only desired ports
&& !startsWith($interface['port'], HIDDEN_PORTS)) {
$selected = "";
if($interface['port'] == $port) {
$selected = "selected";
$status = $interface['stat'];
$icon = getStatusImgPath($interface['stat']);
$queried_port_found = true;
}
echo "<option value='" . $interface['port'] . "' $selected>" . $interface['port'] . "</option>\n";
}
}
if($port != "" && $cSwitch != null && $queried_port_found == false) {
echo "<option value='' selected>>>> ".translate("Invalid Port!",false)." <<<</option>";
$port = ""; $vlan = ""; $desc = "";
}
?>
</select>
<span class='tip'><label for='port'><?php translate('Port'); ?></label></span>
<?php if($icon) echo "<img src='".$icon."' title='".htmlspecialchars($status)."' class='tipicon'>"; ?>
<span class='tooltiptext'>
<div><b><?php translate('Icons'); ?></b></div>
<div class='demoStatusIcon'>
<img src='img/connected.svg'></img>
<span> <?php translate('Connected'); ?></span>
</div>
<div class='demoStatusIcon'>
<img src='img/notconnected.svg'></img>
<span> <?php translate('Not Connected'); ?></span>
</div>
<div class='demoStatusIcon'>
<img src='img/disabled.svg'></img>
<span> <?php translate('Other State'); ?></span>
</div>
</span>
</div>
</form>
<form method='POST' name='setvaluesform' onsubmit='beginFadeOutAnimation();'>
<input type='hidden' name='action' value='SETVALUES'></input>
<input type='hidden' name='switch' value='<?php echo $cSwitch==null ? '' : $cSwitch['addr']; ?>'></input>
<input type='hidden' name='port' value='<?php echo $port; ?>'></input>
<div class='multirow'>
<div class='form-row' style='flex-basis:66%'>
<select name='vlan' value='' id='vlan' class='hand' <?php if($cSwitch == null || $port == "") echo "disabled"; ?>>
<?php $selected = false; ?>
<?php foreach(VISIBLE_VLAN as $v) { ?>
<option value='<?php echo $v['id']; ?>' <?php if($vlan==$v['id']){echo "selected";$selected=true;} ?>><?php echo $v['name']; ?></option>
<?php } ?>
<?php if ($vlan == "") {
echo "<option value='' selected></option>";
} elseif ($selected == false) {
echo "<option value='$vlan' selected>[$vlan] (".translate('custom',false).")</option>";
} ?>
</select>
<span class='tip'><label for='vlan'><?php translate('VLAN'); ?></label></span>
</div>
<div class='form-row tooltip' style='flex-basis:33%'>
<select name='voip' value='' id='voip' class='hand' <?php if ($cSwitch == null || $port == "") echo "disabled"; ?>>
<option value='disabled' <?php if($voip == "disabled") echo "selected"; ?>><?php translate('Off'); ?></option>
<option value='enabled' <?php if($voip == "enabled") echo "selected"; ?>><?php translate('On'); ?></option>
</select>
<span class='tip'><label for='voip'><?php translate('VoIP'); ?></label></span>
<span class='tooltiptext'>
<b><?php translate('VoIP-Options'); ?></b>
<div style="text-align: left;">
<b>[<?php translate('On'); ?>]</b> <?php translate('Set voice VLAN and PoE on'); ?>
<br>
<b>[<?php translate('Off'); ?>]</b> <?php translate('No voice VLAN and PoE off'); ?>
</div>
</span>
</div>
</div>
<div class='form-row tooltip'>
<input type='text' name='description' id='description' maxlength='35' class='fullwidth' value='<?php echo $desc ?>' <?php if($cSwitch == null || $port == "") echo "disabled"; ?>></input>
<span class='tip'><label for='description'><?php translate('Description'); ?></label></span>
<?php if(PORT_DESCRIPTION_HINT != '') { ?>
<span class='tooltiptext'>
<?php echo PORT_DESCRIPTION_HINT; ?>
</span>
<?php } ?>
</div>
<div class='form-row last'>
<button type='submit' class='slubbutton' id='submit_changeform' <?php if($cSwitch == null || $port == "") echo "disabled"; ?>><?php translate('Save'); ?></button>
</div>
</form>
<hr>
<div class='stretched-toolbar'>
<?php
$options_disabled = $cSwitch==null ? "disabled='true'" : "";
$switchportparams = "switch=".urlencode($cSwitch==null ? '' : $cSwitch['addr']) . "&port=".urlencode(empty($port) ? '' : $port);
?>
<a href='intstatuslist.php?<?php echo($switchportparams); ?>' id='function_intstatuslist' class='slubbutton secondary notypo' onclick='beginFadeOutAnimation()' <?php echo $options_disabled; ?>><img src='img/intstatuslist.svg'><?php translate('Port List'); ?></a>
<a href='intmatrix.php?<?php echo($switchportparams); ?>' id='function_intmatrix' class='slubbutton secondary notypo' onclick='beginFadeOutAnimation()' <?php echo $options_disabled; ?>><img src='img/intmatrix.svg'><?php translate('Port Matrix'); ?></a>
<a href='search.php?<?php echo($switchportparams); ?>' id='function_search' class='slubbutton secondary notypo' onclick='beginFadeOutAnimation()' <?php echo $options_disabled; ?>><img src='img/search.svg'><?php translate('MAC Search'); ?></a>
<a href='snippets.php?<?php echo($switchportparams); ?>' id='function_snippets' class='slubbutton secondary notypo' onclick='beginFadeOutAnimation()' <?php echo $options_disabled; ?>><img src='img/snippets.svg'><?php translate('Snippets'); ?></a>
</div>
</div>
<?php require('foot.inc.php'); ?>
</div>
<?php require('menu.inc.php'); ?>
</body>
</html>