Commit | Line | Data |
---|---|---|
b325120a | 1 | <?php |
e673ee24 DO |
2 | /* |
3 | * | |
4 | * This file is a library of operation handlers for RackTables. | |
5 | * | |
6 | */ | |
7 | ||
08408472 AA |
8 | // This array is deprecated. Please do not add new message constants to it. |
9 | // use the new showError, showWarning, showSuccess functions instead | |
b6a7d936 | 10 | $msgcode = array(); |
17c32f4c | 11 | |
08408472 AA |
12 | // This function is DEPRECATED. Show messages through showError and showSuccess, |
13 | // you dont need to return anything from an ophandler to redirect user back to the page containing submit form | |
14 | function buildWideRedirectURL ($log = NULL, $nextpage = NULL, $nexttab = NULL, $moreArgs = array()) | |
17c32f4c | 15 | { |
790a60e8 | 16 | global $page, $pageno, $tabno; |
b6a7d936 DO |
17 | if ($nextpage === NULL) |
18 | $nextpage = $pageno; | |
19 | if ($nexttab === NULL) | |
20 | $nexttab = $tabno; | |
790a60e8 | 21 | $url = "index.php?page=${nextpage}&tab=${nexttab}"; |
b6a7d936 DO |
22 | if (isset ($page[$nextpage]['bypass'])) |
23 | $url .= '&' . $page[$nextpage]['bypass'] . '=' . $_REQUEST[$page[$nextpage]['bypass']]; | |
17c32f4c | 24 | |
b6a7d936 | 25 | if (count($moreArgs)>0) |
17c32f4c | 26 | { |
b6a7d936 DO |
27 | foreach($moreArgs as $arg=>$value) |
28 | { | |
29 | if (gettype($value) == 'array') | |
30 | { | |
31 | foreach ($value as $v) | |
32 | { | |
33 | $url .= '&'.urlencode($arg.'[]').'='.urlencode($v); | |
34 | } | |
35 | } | |
36 | else | |
37 | $url .= '&'.urlencode($arg).'='.urlencode($value); | |
38 | } | |
17c32f4c | 39 | } |
b6a7d936 | 40 | |
08408472 AA |
41 | if (! empty ($log)) |
42 | { | |
43 | if (empty ($_SESSION['log'])) | |
44 | $_SESSION['log'] = $log; | |
45 | elseif ($_SESSION['log']['v'] == $log['v']) | |
46 | $_SESSION['log'] = array_merge_recursive($log, $_SESSION['log']); | |
47 | elseif ($log['v'] == 1 and $_SESSION['log']['v'] == 2) | |
48 | foreach ($log['m'] as $msg) | |
49 | setMessage($msg['message'], $msg['code'], FALSE); | |
50 | elseif ($log['v'] == 2 and $_SESSION['log']['v'] == 1) | |
51 | { | |
52 | foreach ($_SESSION['log'] as $msg) | |
53 | { | |
54 | if (! is_array ($msg)) | |
55 | continue; | |
56 | var_dump ($msg); | |
57 | $new_v2_item = array('c' => '', 'a' => array()); | |
58 | switch ($msg['code']) | |
59 | { | |
60 | case 'error': | |
61 | $new_v2_item['c'] = 100; | |
62 | break; | |
63 | case 'success': | |
64 | $new_v2_item['c'] = 0; | |
65 | break; | |
66 | case 'warning': | |
67 | $new_v2_item['c'] = 200; | |
68 | break; | |
69 | default: | |
70 | $new_v2_item['c'] = 300; | |
71 | } | |
72 | $new_v2_item['a'][] = $msg['message']; | |
73 | $log['m'][] = $new_v2_item; | |
74 | } | |
75 | $_SESSION['log'] = $log; // substitute v1 log structure with merged v2 | |
76 | } | |
77 | } | |
b6a7d936 | 78 | return $url; |
17c32f4c DO |
79 | } |
80 | ||
08408472 AA |
81 | // This function is DEPRECATED. Show messages through showError and showSuccess, |
82 | // you dont need to return anything from an ophandler to redirect user back to the page containing submit form | |
05d3c190 | 83 | function buildRedirectURL ($callfunc, $status, $log_args = array(), $nextpage = NULL, $nexttab = NULL, $url_args = array()) |
17c32f4c | 84 | { |
b6a7d936 DO |
85 | global $pageno, $tabno, $msgcode; |
86 | if ($nextpage === NULL) | |
87 | $nextpage = $pageno; | |
88 | if ($nexttab === NULL) | |
89 | $nexttab = $tabno; | |
05d3c190 | 90 | return buildWideRedirectURL (oneLiner ($msgcode[$callfunc][$status], $log_args), $nextpage, $nexttab, $url_args); |
17c32f4c DO |
91 | } |
92 | ||
00e93d63 | 93 | $msgcode['addPortForwarding']['OK'] = 48; |
b6a7d936 | 94 | $msgcode['addPortForwarding']['ERR'] = 100; |
e673ee24 DO |
95 | function addPortForwarding () |
96 | { | |
0cc24e9a DY |
97 | assertUIntArg ('object_id'); |
98 | assertIPv4Arg ('localip'); | |
99 | assertIPv4Arg ('remoteip'); | |
100 | assertUIntArg ('localport'); | |
101 | assertStringArg ('proto'); | |
102 | assertStringArg ('description', TRUE); | |
103b1e1e | 103 | $remoteport = isset ($_REQUEST['remoteport']) ? $_REQUEST['remoteport'] : ''; |
59a83bd8 | 104 | if (!strlen ($remoteport)) |
f75eb878 | 105 | $remoteport = $_REQUEST['localport']; |
e673ee24 | 106 | |
9bea3a8b DO |
107 | $error = newPortForwarding |
108 | ( | |
103b1e1e | 109 | $_REQUEST['object_id'], |
9bea3a8b DO |
110 | $_REQUEST['localip'], |
111 | $_REQUEST['localport'], | |
112 | $_REQUEST['remoteip'], | |
113 | $remoteport, | |
114 | $_REQUEST['proto'], | |
115 | $_REQUEST['description'] | |
116 | ); | |
e673ee24 DO |
117 | |
118 | if ($error == '') | |
135080d8 | 119 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 120 | else |
135080d8 | 121 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 DO |
122 | } |
123 | ||
00e93d63 | 124 | $msgcode['delPortForwarding']['OK'] = 49; |
a5c589d2 | 125 | $msgcode['delPortForwarding']['ERR'] = 111; |
e673ee24 DO |
126 | function delPortForwarding () |
127 | { | |
0cc24e9a DY |
128 | assertUIntArg ('object_id'); |
129 | assertIPv4Arg ('localip'); | |
130 | assertIPv4Arg ('remoteip'); | |
131 | assertUIntArg ('localport'); | |
132 | assertUIntArg ('remoteport'); | |
133 | assertStringArg ('proto'); | |
e673ee24 | 134 | |
a5c589d2 | 135 | $result = deletePortForwarding |
103b1e1e DO |
136 | ( |
137 | $_REQUEST['object_id'], | |
138 | $_REQUEST['localip'], | |
139 | $_REQUEST['localport'], | |
140 | $_REQUEST['remoteip'], | |
141 | $_REQUEST['remoteport'], | |
142 | $_REQUEST['proto'] | |
143 | ); | |
a5c589d2 | 144 | buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR'); |
e673ee24 DO |
145 | } |
146 | ||
00e93d63 | 147 | $msgcode['updPortForwarding']['OK'] = 51; |
a5c589d2 | 148 | $msgcode['updPortForwarding']['ERR'] = 109; |
e673ee24 DO |
149 | function updPortForwarding () |
150 | { | |
0cc24e9a DY |
151 | assertUIntArg ('object_id'); |
152 | assertIPv4Arg ('localip'); | |
153 | assertIPv4Arg ('remoteip'); | |
154 | assertUIntArg ('localport'); | |
155 | assertUIntArg ('remoteport'); | |
156 | assertStringArg ('proto'); | |
157 | assertStringArg ('description'); | |
e673ee24 | 158 | |
a5c589d2 | 159 | $result = updatePortForwarding |
103b1e1e DO |
160 | ( |
161 | $_REQUEST['object_id'], | |
162 | $_REQUEST['localip'], | |
163 | $_REQUEST['localport'], | |
164 | $_REQUEST['remoteip'], | |
165 | $_REQUEST['remoteport'], | |
166 | $_REQUEST['proto'], | |
167 | $_REQUEST['description'] | |
168 | ); | |
a5c589d2 | 169 | buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR'); |
e673ee24 DO |
170 | } |
171 | ||
00e93d63 | 172 | $msgcode['addPortForObject']['OK'] = 48; |
b6a7d936 DO |
173 | $msgcode['addPortForObject']['ERR1'] = 101; |
174 | $msgcode['addPortForObject']['ERR2'] = 100; | |
e673ee24 DO |
175 | function addPortForObject () |
176 | { | |
0cc24e9a | 177 | assertStringArg ('port_name', TRUE); |
9b6e7bd1 | 178 | genericAssertion ('port_l2address', 'l2address0'); |
59a83bd8 | 179 | if (!strlen ($_REQUEST['port_name'])) |
135080d8 | 180 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
6405ecd3 DO |
181 | $error = commitAddPort |
182 | ( | |
183 | $_REQUEST['object_id'], | |
184 | trim ($_REQUEST['port_name']), | |
185 | $_REQUEST['port_type_id'], | |
186 | trim ($_REQUEST['port_label']), | |
187 | trim ($_REQUEST['port_l2address']) | |
188 | ); | |
103b1e1e | 189 | if ($error != '') |
135080d8 | 190 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); |
e673ee24 | 191 | else |
135080d8 | 192 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['port_name'])); |
e673ee24 DO |
193 | } |
194 | ||
00e93d63 | 195 | $msgcode['editPortForObject']['OK'] = 7; |
b6a7d936 DO |
196 | $msgcode['editPortForObject']['ERR1'] = 101; |
197 | $msgcode['editPortForObject']['ERR2'] = 100; | |
e673ee24 DO |
198 | function editPortForObject () |
199 | { | |
0cc24e9a DY |
200 | assertUIntArg ('port_id'); |
201 | assertUIntArg ('port_type_id'); | |
e8acfc2d | 202 | assertStringArg ('reservation_comment', TRUE); |
9b6e7bd1 | 203 | genericAssertion ('l2address', 'l2address0'); |
d0a69ce8 | 204 | // tolerate empty value now to produce custom informative message later |
0cc24e9a | 205 | assertStringArg ('name', TRUE); |
59a83bd8 | 206 | if (!strlen ($_REQUEST['name'])) |
135080d8 | 207 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
103b1e1e | 208 | |
e8acfc2d | 209 | $error = commitUpdatePort ($_REQUEST['object_id'], $_REQUEST['port_id'], $_REQUEST['name'], $_REQUEST['port_type_id'], $_REQUEST['label'], $_REQUEST['l2address'], $_REQUEST['reservation_comment']); |
103b1e1e | 210 | if ($error != '') |
135080d8 | 211 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); |
e673ee24 | 212 | else |
135080d8 | 213 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name'])); |
e673ee24 DO |
214 | } |
215 | ||
b6a7d936 DO |
216 | $msgcode['linkPortForObject']['OK'] = 8; |
217 | $msgcode['linkPortForObject']['ERR'] = 100; | |
e673ee24 DO |
218 | function linkPortForObject () |
219 | { | |
0cc24e9a DY |
220 | assertUIntArg ('port_id'); |
221 | assertUIntArg ('remote_port_id'); | |
0c7c9f8b | 222 | assertStringArg ('cable', TRUE); |
e673ee24 | 223 | |
cd3775e9 | 224 | // FIXME: ensure, that at least one of these ports belongs to the current object |
0c7c9f8b | 225 | $error = linkPorts ($_REQUEST['port_id'], $_REQUEST['remote_port_id'], $_REQUEST['cable']); |
e673ee24 | 226 | if ($error != '') |
135080d8 | 227 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
d0dadd80 DO |
228 | global $sic; |
229 | $local_port_info = getPortInfo ($sic['port_id']); | |
230 | $remote_port_info = getPortInfo ($sic['remote_port_id']); | |
cd3775e9 DO |
231 | $remote_object = spotEntity ('object', $remote_port_info['object_id']); |
232 | return buildRedirectURL | |
233 | ( | |
234 | __FUNCTION__, | |
235 | 'OK', | |
236 | array | |
237 | ( | |
238 | $local_port_info['name'], | |
239 | $remote_port_info['name'], | |
240 | $remote_object['dname'], | |
241 | ) | |
242 | ); | |
e673ee24 DO |
243 | } |
244 | ||
b6a7d936 DO |
245 | $msgcode['addMultiPorts']['OK'] = 10; |
246 | $msgcode['addMultiPorts']['ERR'] = 123; | |
e673ee24 DO |
247 | function addMultiPorts () |
248 | { | |
0cc24e9a DY |
249 | assertStringArg ('format'); |
250 | assertStringArg ('input'); | |
ff0eaf57 | 251 | assertStringArg ('port_type'); |
e673ee24 DO |
252 | $format = $_REQUEST['format']; |
253 | $port_type = $_REQUEST['port_type']; | |
254 | $object_id = $_REQUEST['object_id']; | |
255 | // Input lines are escaped, so we have to explode and to chop by 2-char | |
256 | // \n and \r respectively. | |
7f42d792 | 257 | $lines1 = explode ("\n", $_REQUEST['input']); |
e673ee24 DO |
258 | foreach ($lines1 as $line) |
259 | { | |
260 | $parts = explode ('\r', $line); | |
261 | reset ($parts); | |
59a83bd8 | 262 | if (!strlen ($parts[0])) |
e673ee24 DO |
263 | continue; |
264 | else | |
265 | $lines2[] = rtrim ($parts[0]); | |
266 | } | |
267 | $ports = array(); | |
268 | foreach ($lines2 as $line) | |
269 | { | |
270 | switch ($format) | |
271 | { | |
272 | case 'fisxii': | |
84986395 | 273 | $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line)); |
e673ee24 DO |
274 | list ($slot, $port) = explode ('/', $words[0]); |
275 | $ports[] = array | |
276 | ( | |
277 | 'name' => "e ${slot}/${port}", | |
278 | 'l2address' => $words[8], | |
279 | 'label' => "slot ${slot} port ${port}" | |
280 | ); | |
281 | break; | |
282 | case 'c3600asy': | |
84986395 | 283 | $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', trim (substr ($line, 3)))); |
e673ee24 DO |
284 | /* |
285 | How Async Lines are Numbered in Cisco 3600 Series Routers | |
286 | http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00801ca70b.shtml | |
287 | ||
288 | Understanding 16- and 32-Port Async Network Modules | |
289 | http://www.cisco.com/en/US/products/hw/routers/ps274/products_tech_note09186a00800a93f0.shtml | |
290 | */ | |
291 | $async = $words[0]; | |
292 | $slot = floor (($async - 1) / 32); | |
293 | $octalgroup = floor (($async - 1 - $slot * 32) / 8); | |
294 | $cable = $async - $slot * 32 - $octalgroup * 8; | |
295 | $og_label[0] = 'async 0-7'; | |
296 | $og_label[1] = 'async 8-15'; | |
297 | $og_label[2] = 'async 16-23'; | |
298 | $og_label[3] = 'async 24-31'; | |
299 | $ports[] = array | |
300 | ( | |
301 | 'name' => "async ${async}", | |
302 | 'l2address' => '', | |
303 | 'label' => "slot ${slot} " . $og_label[$octalgroup] . " cable ${cable}" | |
304 | ); | |
305 | break; | |
306 | case 'fiwg': | |
84986395 | 307 | $words = explode (' ', preg_replace ('/[[:space:]]+/', ' ', $line)); |
e673ee24 DO |
308 | $ifnumber = $words[0] * 1; |
309 | $ports[] = array | |
310 | ( | |
311 | 'name' => "e ${ifnumber}", | |
312 | 'l2address' => "${words[8]}", | |
313 | 'label' => "${ifnumber}" | |
314 | ); | |
315 | break; | |
351d4dbf | 316 | case 'ssv1': |
5b585342 | 317 | $words = explode (' ', $line); |
59a83bd8 | 318 | if (!strlen ($words[0]) or !strlen ($words[1])) |
351d4dbf DO |
319 | continue; |
320 | $ports[] = array | |
321 | ( | |
322 | 'name' => $words[0], | |
323 | 'l2address' => $words[1], | |
324 | 'label' => '' | |
325 | ); | |
326 | break; | |
e673ee24 | 327 | default: |
135080d8 | 328 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
329 | break; |
330 | } | |
331 | } | |
332 | // Create ports, if they don't exist. | |
333 | $added_count = $updated_count = $error_count = 0; | |
334 | foreach ($ports as $port) | |
335 | { | |
e9d357e1 DO |
336 | $port_ids = getPortIDs ($object_id, $port['name']); |
337 | if (!count ($port_ids)) | |
e673ee24 DO |
338 | { |
339 | $result = commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']); | |
340 | if ($result == '') | |
341 | $added_count++; | |
342 | else | |
343 | $error_count++; | |
344 | } | |
e9d357e1 | 345 | elseif (count ($port_ids) == 1) // update only single-socket ports |
e673ee24 | 346 | { |
e9d357e1 | 347 | $result = commitUpdatePort ($object_id, $port_ids[0], $port['name'], $port_type, $port['label'], $port['l2address']); |
e673ee24 DO |
348 | if ($result == '') |
349 | $updated_count++; | |
350 | else | |
351 | $error_count++; | |
352 | } | |
353 | } | |
135080d8 | 354 | return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $updated_count, $error_count)); |
e673ee24 DO |
355 | } |
356 | ||
a1fc539a | 357 | $msgcode['addBulkPorts']['OK'] = 82; |
a1fc539a RF |
358 | function addBulkPorts () |
359 | { | |
647635ad DO |
360 | assertStringArg ('port_type_id'); |
361 | assertStringArg ('port_name'); | |
362 | assertStringArg ('port_label', TRUE); | |
329aa3e5 | 363 | assertUIntArg ('port_numbering_start', TRUE); |
647635ad | 364 | assertUIntArg ('port_numbering_count'); |
a1fc539a RF |
365 | |
366 | $object_id = $_REQUEST['object_id']; | |
367 | $port_name = $_REQUEST['port_name']; | |
368 | $port_type_id = $_REQUEST['port_type_id']; | |
369 | $port_label = $_REQUEST['port_label']; | |
370 | $port_numbering_start = $_REQUEST['port_numbering_start']; | |
371 | $port_numbering_count = $_REQUEST['port_numbering_count']; | |
372 | ||
a1fc539a RF |
373 | $added_count = $error_count = 0; |
374 | if(strrpos($port_name, "%u") === false ) | |
375 | $port_name .= '%u'; | |
2b5a8c1b | 376 | for ($i=0,$c=$port_numbering_start; $i<$port_numbering_count; $i++,$c++) |
a1fc539a | 377 | { |
2b5a8c1b | 378 | $result = commitAddPort ($object_id, @sprintf($port_name,$c), $port_type_id, @sprintf($port_label,$c), ''); |
a1fc539a RF |
379 | if ($result == '') |
380 | $added_count++; | |
381 | else | |
382 | $error_count++; | |
383 | } | |
384 | return buildRedirectURL (__FUNCTION__, 'OK', array ($added_count, $error_count)); | |
385 | } | |
386 | ||
00e93d63 | 387 | $msgcode['updIPv4Allocation']['OK'] = 51; |
32832c0e | 388 | $msgcode['updIPv4Allocation']['ERR'] = 109; |
b4c1ef87 | 389 | function updIPv4Allocation () |
e673ee24 | 390 | { |
0cc24e9a DY |
391 | assertIPv4Arg ('ip'); |
392 | assertUIntArg ('object_id'); | |
393 | assertStringArg ('bond_name', TRUE); | |
96597d19 | 394 | genericAssertion ('bond_type', 'enum/inet4alloc'); |
e673ee24 | 395 | |
32832c0e DO |
396 | $result = updateBond ($_REQUEST['ip'], $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); |
397 | return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK'); | |
e673ee24 DO |
398 | } |
399 | ||
00e93d63 | 400 | $msgcode['updIPv6Allocation']['OK'] = 51; |
21ee3351 AA |
401 | $msgcode['updIv6PAllocation']['ERR'] = 109; |
402 | function updIPv6Allocation () | |
403 | { | |
404 | $ipv6 = assertIPv6Arg ('ip'); | |
405 | assertUIntArg ('object_id'); | |
406 | assertStringArg ('bond_name', TRUE); | |
96597d19 | 407 | genericAssertion ('bond_type', 'enum/inet6alloc'); |
21ee3351 AA |
408 | |
409 | $result = updateIPv6Bond ($ipv6, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type']); | |
410 | return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK'); | |
411 | } | |
412 | ||
00e93d63 | 413 | $msgcode['delIPv4Allocation']['OK'] = 49; |
32832c0e | 414 | $msgcode['delIPv4Allocation']['ERR'] = 111; |
b4c1ef87 | 415 | function delIPv4Allocation () |
e673ee24 | 416 | { |
0cc24e9a DY |
417 | assertIPv4Arg ('ip'); |
418 | assertUIntArg ('object_id'); | |
e673ee24 | 419 | |
32832c0e DO |
420 | $result = unbindIpFromObject ($_REQUEST['ip'], $_REQUEST['object_id']); |
421 | return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK'); | |
e673ee24 DO |
422 | } |
423 | ||
00e93d63 | 424 | $msgcode['delIPv6Allocation']['OK'] = 49; |
21ee3351 AA |
425 | $msgcode['delIPv6Allocation']['ERR'] = 111; |
426 | function delIPv6Allocation () | |
427 | { | |
428 | assertUIntArg ('object_id'); | |
429 | $ipv6 = assertIPv6Arg ('ip'); | |
430 | $result = unbindIPv6FromObject ($ipv6, $_REQUEST['object_id']); | |
431 | return buildRedirectURL (__FUNCTION__, $result === FALSE ? 'ERR' : 'OK'); | |
432 | } | |
433 | ||
00e93d63 | 434 | $msgcode['addIPv4Allocation']['OK'] = 48; |
b6a7d936 DO |
435 | $msgcode['addIPv4Allocation']['ERR1'] = 170; |
436 | $msgcode['addIPv4Allocation']['ERR2'] = 100; | |
b4c1ef87 | 437 | function addIPv4Allocation () |
e673ee24 | 438 | { |
0cc24e9a DY |
439 | assertIPv4Arg ('ip'); |
440 | assertUIntArg ('object_id'); | |
441 | assertStringArg ('bond_name', TRUE); | |
96597d19 | 442 | genericAssertion ('bond_type', 'enum/inet4alloc'); |
da958e52 | 443 | |
b4c1ef87 | 444 | // Strip masklen. |
84986395 | 445 | $ip = preg_replace ('@/[[:digit:]]+$@', '', $_REQUEST['ip']); |
2be3fd23 | 446 | if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv4AddressNetworkId ($ip)) |
135080d8 | 447 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($ip)); |
5222f192 | 448 | |
fc2e1602 | 449 | if (FALSE === bindIpToObject ($ip, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type'])) |
135080d8 | 450 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); |
53ef3908 | 451 | $address = getIPv4Address ($ip); |
59a83bd8 | 452 | if ($address['reserved'] == 'yes' or strlen ($address['name'])) |
b4c1ef87 DO |
453 | { |
454 | $release = getConfigVar ('IPV4_AUTO_RELEASE'); | |
455 | if ($release >= 1) | |
456 | $address['reserved'] = 'no'; | |
457 | if ($release >= 2) | |
458 | $address['name'] = ''; | |
459 | updateAddress ($ip, $address['name'], $address['reserved']); | |
460 | } | |
135080d8 | 461 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
462 | } |
463 | ||
00e93d63 | 464 | $msgcode['addIPv6Allocation']['OK'] = 48; |
21ee3351 AA |
465 | $msgcode['addIPv6Allocation']['ERR1'] = 170; |
466 | $msgcode['addIPv6Allocation']['ERR2'] = 100; | |
467 | function addIPv6Allocation () | |
468 | { | |
469 | assertUIntArg ('object_id'); | |
470 | assertStringArg ('bond_name', TRUE); | |
96597d19 | 471 | genericAssertion ('bond_type', 'enum/inet6alloc'); |
21ee3351 AA |
472 | |
473 | // Strip masklen. | |
474 | $ipv6 = new IPv6Address; | |
475 | if (! $ipv6->parse (preg_replace ('@/\d+$@', '', $_REQUEST['ip']))) | |
476 | throw new InvalidRequestArgException('ip', $_REQUEST['ip'], 'parameter is not a valid ipv6 address'); | |
477 | ||
478 | if (getConfigVar ('IPV4_JAYWALK') != 'yes' and NULL === getIPv6AddressNetworkId ($ipv6)) | |
479 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($ip)); | |
480 | ||
481 | if (FALSE === bindIPv6ToObject ($ipv6, $_REQUEST['object_id'], $_REQUEST['bond_name'], $_REQUEST['bond_type'])) | |
482 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($error)); | |
483 | $address = getIPv6Address ($ipv6); | |
484 | if ($address['reserved'] == 'yes' or strlen ($address['name'])) | |
485 | { | |
486 | $release = getConfigVar ('IPV4_AUTO_RELEASE'); | |
487 | if ($release >= 1) | |
488 | $address['reserved'] = 'no'; | |
489 | if ($release >= 2) | |
490 | $address['name'] = ''; | |
491 | updateAddress ($ipv6, $address['name'], $address['reserved']); | |
492 | } | |
493 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
494 | } | |
495 | ||
00e93d63 | 496 | $msgcode['addIPv4Prefix']['OK'] = 48; |
b6a7d936 | 497 | $msgcode['addIPv4Prefix']['ERR'] = 100; |
42023f03 | 498 | function addIPv4Prefix () |
e673ee24 | 499 | { |
0cc24e9a DY |
500 | assertStringArg ('range'); |
501 | assertStringArg ('name', TRUE); | |
e673ee24 | 502 | |
fa05e3de DO |
503 | $is_bcast = isset ($_REQUEST['is_bcast']) ? $_REQUEST['is_bcast'] : 'off'; |
504 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); | |
357eb2ea DO |
505 | global $sic; |
506 | $error = createIPv4Prefix ($_REQUEST['range'], $sic['name'], $is_bcast == 'on', $taglist); | |
e673ee24 | 507 | if ($error != '') |
135080d8 | 508 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 509 | else |
135080d8 | 510 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
511 | } |
512 | ||
00e93d63 | 513 | $msgcode['addIPv6Prefix']['OK'] = 48; |
21ee3351 | 514 | $msgcode['addIPv6Prefix']['ERR'] = 100; |
21ee3351 AA |
515 | function addIPv6Prefix () |
516 | { | |
517 | assertStringArg ('range'); | |
518 | assertStringArg ('name', TRUE); | |
519 | ||
520 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); | |
521 | global $sic; | |
522 | $error = createIPv6Prefix ($_REQUEST['range'], $sic['name'], $taglist); | |
523 | if ($error != '') | |
524 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); | |
525 | else | |
526 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
527 | } | |
528 | ||
00e93d63 | 529 | $msgcode['delIPv4Prefix']['OK'] = 49; |
b6a7d936 | 530 | $msgcode['delIPv4Prefix']['ERR'] = 100; |
42023f03 | 531 | function delIPv4Prefix () |
e673ee24 | 532 | { |
0cc24e9a | 533 | assertUIntArg ('id'); |
42023f03 | 534 | $error = destroyIPv4Prefix ($_REQUEST['id']); |
e673ee24 | 535 | if ($error != '') |
135080d8 | 536 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 537 | else |
135080d8 | 538 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
539 | } |
540 | ||
00e93d63 | 541 | $msgcode['delIPv6Prefix']['OK'] = 49; |
21ee3351 AA |
542 | $msgcode['delIPv6Prefix']['ERR'] = 100; |
543 | function delIPv6Prefix () | |
544 | { | |
545 | assertUIntArg ('id'); | |
546 | $error = destroyIPv6Prefix ($_REQUEST['id']); | |
547 | if ($error != '') | |
548 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); | |
549 | else | |
550 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
551 | } | |
552 | ||
00e93d63 | 553 | $msgcode['updIPv4Prefix']['OK'] = 51; |
6cfedb71 | 554 | $msgcode['updIPv4Prefix']['ERR'] = 109; |
04d619d0 | 555 | function updIPv4Prefix () |
e673ee24 | 556 | { |
0cc24e9a DY |
557 | assertUIntArg ('id'); |
558 | assertStringArg ('name', TRUE); | |
559 | assertStringArg ('comment', TRUE); | |
99ab184f | 560 | global $sic; |
6cfedb71 DO |
561 | $result = updateIPv4Network_real ($sic['id'], $sic['name'], $sic['comment']); |
562 | return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR'); | |
e673ee24 DO |
563 | } |
564 | ||
00e93d63 | 565 | $msgcode['updIPv6Prefix']['OK'] = 51; |
21ee3351 AA |
566 | $msgcode['updIPv6Prefix']['ERR'] = 109; |
567 | function updIPv6Prefix () | |
568 | { | |
569 | assertUIntArg ('id'); | |
570 | assertStringArg ('name', TRUE); | |
571 | assertStringArg ('comment', TRUE); | |
572 | global $sic; | |
573 | $result = updateIPv6Network_real ($sic['id'], $sic['name'], $sic['comment']); | |
574 | return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR'); | |
575 | } | |
576 | ||
00e93d63 | 577 | $msgcode['editAddress']['OK'] = 51; |
b6a7d936 | 578 | $msgcode['editAddress']['ERR'] = 100; |
e673ee24 DO |
579 | function editAddress () |
580 | { | |
0cc24e9a | 581 | assertStringArg ('name', TRUE); |
e673ee24 | 582 | |
e673ee24 DO |
583 | if (isset ($_REQUEST['reserved'])) |
584 | $reserved = $_REQUEST['reserved']; | |
585 | else | |
586 | $reserved = 'off'; | |
da958e52 | 587 | $error = updateAddress ($_REQUEST['ip'], $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no'); |
e673ee24 | 588 | if ($error != '') |
135080d8 | 589 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e673ee24 | 590 | else |
135080d8 | 591 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
592 | } |
593 | ||
00e93d63 | 594 | $msgcode['editv6Address']['OK'] = 51; |
21ee3351 AA |
595 | $msgcode['editv6Address']['ERR'] = 100; |
596 | function editv6Address () | |
597 | { | |
598 | $ipv6 = assertIPArg ('ip'); | |
599 | assertStringArg ('name', TRUE); | |
600 | ||
601 | if (isset ($_REQUEST['reserved'])) | |
602 | $reserved = $_REQUEST['reserved']; | |
603 | else | |
604 | $reserved = 'off'; | |
605 | $error = updateAddress ($ipv6, $_REQUEST['name'], $reserved == 'on' ? 'yes' : 'no'); | |
606 | if ($error != '') | |
607 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); | |
608 | else | |
609 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
610 | } | |
611 | ||
00e93d63 | 612 | $msgcode['createUser']['OK'] = 5; |
b6a7d936 | 613 | $msgcode['createUser']['ERR'] = 102; |
cced6b7d | 614 | function createUser () |
e673ee24 | 615 | { |
0cc24e9a DY |
616 | assertStringArg ('username'); |
617 | assertStringArg ('realname', TRUE); | |
618 | assertStringArg ('password'); | |
e673ee24 | 619 | $username = $_REQUEST['username']; |
93bdb7ba | 620 | $password = sha1 ($_REQUEST['password']); |
e673ee24 | 621 | $result = commitCreateUserAccount ($username, $_REQUEST['realname'], $password); |
f857f71f | 622 | if ($result != TRUE) |
135080d8 | 623 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($username)); |
f857f71f DO |
624 | if (isset ($_REQUEST['taglist'])) |
625 | produceTagsForLastRecord ('user', $_REQUEST['taglist']); | |
626 | return buildRedirectURL (__FUNCTION__, 'OK', array ($username)); | |
e673ee24 DO |
627 | } |
628 | ||
00e93d63 DO |
629 | $msgcode['updateUser']['OK'] = 7; |
630 | $msgcode['updateUser']['ERR2'] = 104; | |
cced6b7d | 631 | function updateUser () |
e673ee24 | 632 | { |
0cc24e9a DY |
633 | assertStringArg ('username'); |
634 | assertStringArg ('realname', TRUE); | |
635 | assertStringArg ('password'); | |
e673ee24 DO |
636 | $username = $_REQUEST['username']; |
637 | $new_password = $_REQUEST['password']; | |
a9ec91cf | 638 | $userinfo = spotEntity ('user', $_REQUEST['user_id']); |
e673ee24 | 639 | // Update user password only if provided password is not the same as current password hash. |
b82cce3f | 640 | if ($new_password != $userinfo['user_password_hash']) |
93bdb7ba | 641 | $new_password = sha1 ($new_password); |
103b1e1e | 642 | $result = commitUpdateUserAccount ($_REQUEST['user_id'], $username, $_REQUEST['realname'], $new_password); |
32832c0e | 643 | if ($result !== FALSE) |
135080d8 | 644 | return buildRedirectURL (__FUNCTION__, 'OK', array ($username)); |
e673ee24 | 645 | else |
135080d8 | 646 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($username)); |
e673ee24 DO |
647 | } |
648 | ||
b6a7d936 DO |
649 | $msgcode['updateDictionary']['OK'] = 51; |
650 | $msgcode['updateDictionary']['ERR'] = 109; | |
e673ee24 DO |
651 | function updateDictionary () |
652 | { | |
0cc24e9a DY |
653 | assertUIntArg ('dict_key'); |
654 | assertStringArg ('dict_value'); | |
32832c0e | 655 | if (FALSE !== commitUpdateDictionary ($_REQUEST['chapter_no'], $_REQUEST['dict_key'], $_REQUEST['dict_value'])) |
135080d8 | 656 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 657 | else |
135080d8 | 658 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
659 | } |
660 | ||
00e93d63 DO |
661 | $msgcode['updateChapter']['OK'] = 51; |
662 | $msgcode['updateChapter']['ERR'] = 109; | |
e673ee24 DO |
663 | function updateChapter () |
664 | { | |
0cc24e9a DY |
665 | assertUIntArg ('chapter_no'); |
666 | assertStringArg ('chapter_name'); | |
32832c0e | 667 | if (FALSE !== commitUpdateChapter ($_REQUEST['chapter_no'], $_REQUEST['chapter_name'])) |
135080d8 | 668 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 669 | else |
135080d8 | 670 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
671 | } |
672 | ||
00e93d63 DO |
673 | $msgcode['delChapter']['OK'] = 49; |
674 | $msgcode['delChapter']['ERR'] = 111; | |
e673ee24 DO |
675 | function delChapter () |
676 | { | |
0cc24e9a | 677 | assertUIntArg ('chapter_no'); |
e673ee24 | 678 | if (commitDeleteChapter ($_REQUEST['chapter_no'])) |
135080d8 | 679 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 680 | else |
135080d8 | 681 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
682 | } |
683 | ||
00e93d63 DO |
684 | $msgcode['changeAttribute']['OK'] = 51; |
685 | $msgcode['changeAttribute']['ERR'] = 109; | |
e673ee24 DO |
686 | function changeAttribute () |
687 | { | |
0cc24e9a DY |
688 | assertUIntArg ('attr_id'); |
689 | assertStringArg ('attr_name'); | |
32832c0e | 690 | if (FALSE !== commitUpdateAttribute ($_REQUEST['attr_id'], $_REQUEST['attr_name'])) |
135080d8 | 691 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 692 | else |
135080d8 | 693 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
694 | } |
695 | ||
b6a7d936 | 696 | $msgcode['supplementAttrMap']['OK'] = 48; |
7028a42c | 697 | $msgcode['supplementAttrMap']['ERR1'] = 154; |
00e93d63 | 698 | $msgcode['supplementAttrMap']['ERR2'] = 110; |
e673ee24 DO |
699 | function supplementAttrMap () |
700 | { | |
0cc24e9a DY |
701 | assertUIntArg ('attr_id'); |
702 | assertUIntArg ('objtype_id'); | |
7028a42c DO |
703 | $attrMap = getAttrMap(); |
704 | if ($attrMap[$_REQUEST['attr_id']]['type'] != 'dict') | |
d5add09a | 705 | $chapter_id = NULL; |
7028a42c DO |
706 | else |
707 | { | |
d5add09a DO |
708 | try |
709 | { | |
710 | assertUIntArg ('chapter_no'); | |
711 | } | |
712 | catch (InvalidRequestArgException $e) | |
713 | { | |
7028a42c | 714 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ('chapter not selected')); |
d5add09a DO |
715 | } |
716 | $chapter_id = $_REQUEST['chapter_no']; | |
7028a42c | 717 | } |
654e4636 | 718 | if (commitSupplementAttrMap ($_REQUEST['attr_id'], $_REQUEST['objtype_id'], $chapter_id) !== FALSE) |
135080d8 | 719 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 720 | else |
7028a42c | 721 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
e673ee24 DO |
722 | } |
723 | ||
00e93d63 | 724 | $msgcode['clearSticker']['OK'] = 49; |
b6a7d936 | 725 | $msgcode['clearSticker']['ERR'] = 120; |
22bb04da | 726 | function clearSticker () |
e673ee24 | 727 | { |
0cc24e9a | 728 | assertUIntArg ('attr_id'); |
654e4636 | 729 | if (commitResetAttrValue ($_REQUEST['object_id'], $_REQUEST['attr_id']) !== FALSE) |
135080d8 | 730 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 731 | else |
135080d8 | 732 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
733 | } |
734 | ||
e97e8866 | 735 | $msgcode['updateObjectAllocation']['OK'] = 63; |
4fbb5a00 DY |
736 | function updateObjectAllocation () |
737 | { | |
e97e8866 DO |
738 | if (!isset ($_REQUEST['got_atoms'])) |
739 | { | |
740 | unset($_GET['page']); | |
741 | unset($_GET['tab']); | |
742 | unset($_GET['op']); | |
743 | unset($_POST['page']); | |
744 | unset($_POST['tab']); | |
745 | unset($_POST['op']); | |
746 | return buildWideRedirectURL (array(), NULL, NULL, array_merge ($_GET, $_POST)); | |
747 | } | |
748 | $object_id = $_REQUEST['object_id']; | |
749 | $workingRacksData = array(); | |
750 | foreach ($_REQUEST['rackmulti'] as $cand_id) | |
4fbb5a00 | 751 | { |
e97e8866 | 752 | if (!isset ($workingRacksData[$cand_id])) |
4fbb5a00 | 753 | { |
e97e8866 | 754 | $rackData = spotEntity ('rack', $cand_id); |
e97e8866 DO |
755 | amplifyCell ($rackData); |
756 | $workingRacksData[$cand_id] = $rackData; | |
4fbb5a00 | 757 | } |
e97e8866 | 758 | } |
2135fd83 | 759 | |
e97e8866 DO |
760 | foreach ($workingRacksData as &$rd) |
761 | applyObjectMountMask ($rd, $object_id); | |
4fbb5a00 | 762 | |
e97e8866 DO |
763 | $oldMolecule = getMoleculeForObject ($object_id); |
764 | $changecnt = 0; | |
765 | $log = array(); | |
766 | foreach ($workingRacksData as $rack_id => $rackData) | |
4fbb5a00 | 767 | { |
e97e8866 DO |
768 | $logrecord = processGridForm ($rackData, 'F', 'T', $object_id); |
769 | $log[] = $logrecord; | |
770 | if ($logrecord['code'] == 300) | |
771 | continue; | |
772 | $changecnt++; | |
773 | // Reload our working copy after form processing. | |
774 | $rackData = spotEntity ('rack', $cand_id); | |
775 | amplifyCell ($rackData); | |
776 | applyObjectMountMask ($rackData, $object_id); | |
777 | $workingRacksData[$rack_id] = $rackData; | |
4fbb5a00 | 778 | } |
e97e8866 DO |
779 | if (!$changecnt) |
780 | return buildRedirectURL (__FUNCTION__, 'OK', $changecnt); | |
781 | // Log a record. | |
782 | $newMolecule = getMoleculeForObject ($object_id); | |
783 | $oc = count ($oldMolecule); | |
784 | $nc = count ($newMolecule); | |
785 | $omid = $oc ? createMolecule ($oldMolecule) : 'NULL'; | |
786 | $nmid = $nc ? createMolecule ($newMolecule) : 'NULL'; | |
787 | global $remote_username; | |
788 | $comment = empty ($_REQUEST['comment']) ? 'NULL' : "'${_REQUEST['comment']}'"; | |
789 | $query = | |
790 | "insert into MountOperation(object_id, old_molecule_id, new_molecule_id, user_name, comment) " . | |
791 | "values (${object_id}, ${omid}, ${nmid}, '${remote_username}', ${comment})"; | |
792 | global $dbxlink; | |
793 | $result = $dbxlink->query ($query); | |
794 | if ($result == NULL) | |
795 | $log[] = array ('code' => 500, 'message' => 'SQL query failed during history logging.'); | |
796 | else | |
797 | $log[] = array ('code' => 200, 'message' => 'History logged.'); | |
798 | return buildWideRedirectURL ($log); | |
4fbb5a00 DY |
799 | } |
800 | ||
00e93d63 DO |
801 | $msgcode['updateObject']['OK'] = 51; |
802 | $msgcode['updateObject']['ERR'] = 109; | |
22bb04da DO |
803 | function updateObject () |
804 | { | |
0cc24e9a | 805 | assertUIntArg ('num_attrs', TRUE); |
0cc24e9a DY |
806 | assertStringArg ('object_name', TRUE); |
807 | assertStringArg ('object_label', TRUE); | |
808 | assertStringArg ('object_barcode', TRUE); | |
809 | assertStringArg ('object_asset_no', TRUE); | |
22bb04da DO |
810 | if (isset ($_REQUEST['object_has_problems']) and $_REQUEST['object_has_problems'] == 'on') |
811 | $has_problems = 'yes'; | |
812 | else | |
813 | $has_problems = 'no'; | |
814 | ||
815 | if (commitUpdateObject ( | |
816 | $_REQUEST['object_id'], | |
817 | $_REQUEST['object_name'], | |
818 | $_REQUEST['object_label'], | |
819 | $_REQUEST['object_barcode'], | |
22bb04da DO |
820 | $has_problems, |
821 | $_REQUEST['object_asset_no'], | |
822 | $_REQUEST['object_comment'] | |
823 | ) !== TRUE) | |
135080d8 | 824 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
22bb04da | 825 | |
cdd3efe9 | 826 | // Update optional attributes |
f59e8cf5 | 827 | $oldvalues = getAttrValues ($_REQUEST['object_id']); |
0dfb8a2a | 828 | $result = array(); |
0f63538a DO |
829 | $num_attrs = isset ($_REQUEST['num_attrs']) ? $_REQUEST['num_attrs'] : 0; |
830 | for ($i = 0; $i < $num_attrs; $i++) | |
0dfb8a2a | 831 | { |
0cc24e9a | 832 | assertUIntArg ("${i}_attr_id"); |
0dfb8a2a DO |
833 | $attr_id = $_REQUEST["${i}_attr_id"]; |
834 | ||
01d82bd2 RF |
835 | // Field is empty, delete attribute and move on. OR if the field type is a dictionary and it is the --NOT SET-- value of 0 |
836 | if (!strlen ($_REQUEST["${i}_value"]) || ($oldvalues[$attr_id]['type']=='dict' && $_REQUEST["${i}_value"] == 0)) | |
0dfb8a2a | 837 | { |
103b1e1e | 838 | commitResetAttrValue ($_REQUEST['object_id'], $attr_id); |
0dfb8a2a DO |
839 | continue; |
840 | } | |
841 | ||
842 | // The value could be uint/float, but we don't know ATM. Let SQL | |
843 | // server check this and complain. | |
0cc24e9a | 844 | assertStringArg ("${i}_value"); |
0dfb8a2a DO |
845 | $value = $_REQUEST["${i}_value"]; |
846 | switch ($oldvalues[$attr_id]['type']) | |
847 | { | |
848 | case 'uint': | |
849 | case 'float': | |
850 | case 'string': | |
851 | $oldvalue = $oldvalues[$attr_id]['value']; | |
852 | break; | |
853 | case 'dict': | |
854 | $oldvalue = $oldvalues[$attr_id]['key']; | |
855 | break; | |
856 | default: | |
0dfb8a2a | 857 | } |
59a83bd8 | 858 | if ($value === $oldvalue) // ('' == 0), but ('' !== 0) |
0dfb8a2a DO |
859 | continue; |
860 | ||
861 | // Note if the queries succeed or not, it determines which page they see. | |
103b1e1e | 862 | $result[] = commitUpdateAttrValue ($_REQUEST['object_id'], $attr_id, $value); |
0dfb8a2a | 863 | } |
103b1e1e | 864 | if (in_array (FALSE, $result)) |
135080d8 | 865 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
0dfb8a2a | 866 | |
cdd3efe9 AD |
867 | // Invalidate thumb cache of all racks objects could occupy. |
868 | foreach (getResidentRacksData ($_REQUEST['object_id'], FALSE) as $rack_id) | |
869 | resetThumbCache ($rack_id); | |
870 | ||
135080d8 | 871 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 DO |
872 | } |
873 | ||
42d73cbf DY |
874 | function addMultipleObjects() |
875 | { | |
7abce0b7 | 876 | $log = emptyLog(); |
42d73cbf | 877 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
42d73cbf DY |
878 | $max = getConfigVar ('MASSCOUNT'); |
879 | for ($i = 0; $i < $max; $i++) | |
880 | { | |
881 | if (!isset ($_REQUEST["${i}_object_type_id"])) | |
882 | { | |
57777e4a | 883 | $log = mergeLogs ($log, oneLiner (184, array ($i + 1))); |
42d73cbf DY |
884 | break; |
885 | } | |
0cc24e9a DY |
886 | assertUIntArg ("${i}_object_type_id", TRUE); |
887 | assertStringArg ("${i}_object_name", TRUE); | |
888 | assertStringArg ("${i}_object_label", TRUE); | |
889 | assertStringArg ("${i}_object_asset_no", TRUE); | |
890 | assertStringArg ("${i}_object_barcode", TRUE); | |
7abce0b7 | 891 | $name = $_REQUEST["${i}_object_name"]; |
42d73cbf DY |
892 | |
893 | // It's better to skip silently, than to print a notice. | |
7abce0b7 | 894 | if ($_REQUEST["${i}_object_type_id"] == 0) |
42d73cbf | 895 | continue; |
fee7977b | 896 | if (($object_id = commitAddObject |
7abce0b7 DO |
897 | ( |
898 | $name, | |
899 | $_REQUEST["${i}_object_label"], | |
900 | $_REQUEST["${i}_object_barcode"], | |
901 | $_REQUEST["${i}_object_type_id"], | |
902 | $_REQUEST["${i}_object_asset_no"], | |
903 | $taglist | |
fee7977b DO |
904 | )) !== FALSE){ |
905 | $info = spotEntity ('object', $object_id); | |
906 | // FIXME: employ amplifyCell() instead of calling loader functions directly | |
907 | amplifyCell ($info); | |
00e93d63 | 908 | $log = mergeLogs ($log, oneLiner (5, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>'))); |
fee7977b | 909 | }else{ |
00e93d63 | 910 | $log = mergeLogs ($log, oneLiner (147, array ($name))); |
fee7977b | 911 | } |
42d73cbf | 912 | } |
7abce0b7 | 913 | return buildWideRedirectURL ($log); |
42d73cbf DY |
914 | } |
915 | ||
916 | function addLotOfObjects() | |
917 | { | |
7abce0b7 | 918 | $log = emptyLog(); |
42d73cbf | 919 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
0cc24e9a DY |
920 | assertUIntArg ('global_type_id', TRUE); |
921 | assertStringArg ('namelist', TRUE); | |
42d73cbf | 922 | $global_type_id = $_REQUEST['global_type_id']; |
59a83bd8 | 923 | if ($global_type_id == 0 or !strlen ($_REQUEST['namelist'])) |
57777e4a | 924 | $log = mergeLogs ($log, oneLiner (186)); |
42d73cbf DY |
925 | else |
926 | { | |
927 | // The name extractor below was stolen from ophandlers.php:addMultiPorts() | |
7f42d792 | 928 | $names1 = explode ("\n", $_REQUEST['namelist']); |
42d73cbf DY |
929 | $names2 = array(); |
930 | foreach ($names1 as $line) | |
931 | { | |
932 | $parts = explode ('\r', $line); | |
933 | reset ($parts); | |
59a83bd8 | 934 | if (!strlen ($parts[0])) |
42d73cbf DY |
935 | continue; |
936 | else | |
937 | $names2[] = rtrim ($parts[0]); | |
938 | } | |
57777e4a | 939 | foreach ($names2 as $name) |
9d535a0c DO |
940 | if (($object_id = commitAddObject ($name, '', '', $global_type_id, '', $taglist)) !== FALSE) |
941 | { | |
942 | $info = spotEntity ('object', $object_id); | |
943 | amplifyCell ($info); | |
00e93d63 | 944 | $log = mergeLogs ($log, oneLiner (5, array ('<a href="' . makeHref (array ('page' => 'object', 'tab' => 'default', 'object_id' => $object_id)) . '">' . $info['dname'] . '</a>'))); |
9d535a0c | 945 | } |
42d73cbf | 946 | else |
00e93d63 | 947 | $log = mergeLogs ($log, oneLiner (147, array ($name))); |
42d73cbf | 948 | } |
7abce0b7 | 949 | return buildWideRedirectURL ($log); |
42d73cbf DY |
950 | } |
951 | ||
00e93d63 | 952 | $msgcode['deleteObject']['OK'] = 6; |
52b34485 AD |
953 | function deleteObject () |
954 | { | |
0cc24e9a | 955 | assertUIntArg ('object_id'); |
4bb5b87f | 956 | $oinfo = spotEntity ('object', $_REQUEST['object_id']); |
c78a40ec | 957 | |
f0e2c99f | 958 | $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE); |
4bb5b87f | 959 | commitDeleteObject ($_REQUEST['object_id']); |
f0e2c99f DO |
960 | foreach ($racklist as $rack_id) |
961 | resetThumbCache ($rack_id); | |
abd1e9ac DO |
962 | return buildRedirectURL (__FUNCTION__, 'OK', array ($oinfo['dname'])); |
963 | } | |
52b34485 | 964 | |
00e93d63 | 965 | $msgcode['resetObject']['OK'] = 57; |
abd1e9ac DO |
966 | function resetObject () |
967 | { | |
abd1e9ac DO |
968 | $oinfo = spotEntity ('object', $_REQUEST['object_id']); |
969 | ||
970 | $racklist = getResidentRacksData ($_REQUEST['object_id'], FALSE); | |
971 | commitResetObject ($_REQUEST['object_id']); | |
972 | foreach ($racklist as $rack_id) | |
973 | resetThumbCache ($rack_id); | |
00e93d63 | 974 | return buildRedirectURL (__FUNCTION__, 'OK'); |
52b34485 AD |
975 | } |
976 | ||
00e93d63 DO |
977 | $msgcode['useupPort']['OK'] = 49; |
978 | $msgcode['useupPort']['ERR'] = 111; | |
e673ee24 DO |
979 | function useupPort () |
980 | { | |
0cc24e9a | 981 | assertUIntArg ('port_id'); |
32832c0e | 982 | if (FALSE !== commitUseupPort ($_REQUEST['port_id'])) |
135080d8 | 983 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e673ee24 | 984 | else |
135080d8 | 985 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
e673ee24 DO |
986 | } |
987 | ||
00e93d63 | 988 | $msgcode['updateUI']['OK'] = 51; |
4fe32e78 DY |
989 | function updateUI () |
990 | { | |
0cc24e9a | 991 | assertUIntArg ('num_vars'); |
4fe32e78 | 992 | |
103b1e1e | 993 | for ($i = 0; $i < $_REQUEST['num_vars']; $i++) |
4fe32e78 | 994 | { |
0cc24e9a DY |
995 | assertStringArg ("${i}_varname"); |
996 | assertStringArg ("${i}_varvalue", TRUE); | |
4fe32e78 | 997 | $varname = $_REQUEST["${i}_varname"]; |
4fe32e78 | 998 | $varvalue = $_REQUEST["${i}_varvalue"]; |
4fe32e78 | 999 | |
c461c579 | 1000 | // If form value = value in DB, don't bother updating DB |
ed941e67 | 1001 | if (!isConfigVarChanged($varname, $varvalue)) |
4fe32e78 | 1002 | continue; |
3a089a44 DO |
1003 | // any exceptions will be handled by process.php |
1004 | setConfigVar ($varname, $varvalue, TRUE); | |
3540d15c DY |
1005 | } |
1006 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
1007 | } | |
1008 | ||
1009 | $msgcode['saveMyPreferences']['OK'] = 56; | |
3540d15c DY |
1010 | function saveMyPreferences () |
1011 | { | |
1012 | assertUIntArg ('num_vars'); | |
1013 | ||
1014 | for ($i = 0; $i < $_REQUEST['num_vars']; $i++) | |
1015 | { | |
1016 | assertStringArg ("${i}_varname"); | |
1017 | assertStringArg ("${i}_varvalue", TRUE); | |
1018 | $varname = $_REQUEST["${i}_varname"]; | |
1019 | $varvalue = $_REQUEST["${i}_varvalue"]; | |
1020 | ||
1021 | // If form value = value in DB, don't bother updating DB | |
ed941e67 | 1022 | if (!isConfigVarChanged($varname, $varvalue)) |
3540d15c | 1023 | continue; |
3a089a44 | 1024 | setUserConfigVar ($varname, $varvalue); |
3540d15c DY |
1025 | } |
1026 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
1027 | } | |
1028 | ||
1029 | $msgcode['resetMyPreference']['OK'] = 56; | |
3540d15c DY |
1030 | function resetMyPreference () |
1031 | { | |
1032 | assertStringArg ("varname"); | |
3a089a44 | 1033 | resetUserConfigVar ($_REQUEST["varname"]); |
135080d8 | 1034 | return buildRedirectURL (__FUNCTION__, 'OK'); |
4fe32e78 DY |
1035 | } |
1036 | ||
b6a7d936 | 1037 | $msgcode['resetUIConfig']['OK'] = 57; |
b07f617c DO |
1038 | function resetUIConfig() |
1039 | { | |
b07f617c DO |
1040 | setConfigVar ('MASSCOUNT','15'); |
1041 | setConfigVar ('MAXSELSIZE','30'); | |
b07f617c DO |
1042 | setConfigVar ('ROW_SCALE','2'); |
1043 | setConfigVar ('PORTS_PER_ROW','12'); | |
1044 | setConfigVar ('IPV4_ADDRS_PER_PAGE','256'); | |
1045 | setConfigVar ('DEFAULT_RACK_HEIGHT','42'); | |
b5ce46aa DO |
1046 | setConfigVar ('DEFAULT_SLB_VS_PORT',''); |
1047 | setConfigVar ('DEFAULT_SLB_RS_PORT',''); | |
72281138 | 1048 | setConfigVar ('DETECT_URLS','no'); |
4b8d413e | 1049 | setConfigVar ('RACK_PRESELECT_THRESHOLD','1'); |
b108de49 | 1050 | setConfigVar ('DEFAULT_IPV4_RS_INSERVICE','no'); |
8dfb997c | 1051 | setConfigVar ('AUTOPORTS_CONFIG','4 = 1*33*kvm + 2*24*eth%u;15 = 1*446*kvm'); |
194e3748 DO |
1052 | setConfigVar ('SHOW_EXPLICIT_TAGS','yes'); |
1053 | setConfigVar ('SHOW_IMPLICIT_TAGS','yes'); | |
1054 | setConfigVar ('SHOW_AUTOMATIC_TAGS','no'); | |
a477e405 | 1055 | setConfigVar ('DEFAULT_OBJECT_TYPE','4'); |
2754cefc | 1056 | setConfigVar ('IPV4_AUTO_RELEASE','1'); |
a53dc9df | 1057 | setConfigVar ('SHOW_LAST_TAB', 'no'); |
f0ed1181 | 1058 | setConfigVar ('EXT_IPV4_VIEW', 'yes'); |
efee2692 | 1059 | setConfigVar ('TREE_THRESHOLD', '25'); |
2be3fd23 | 1060 | setConfigVar ('IPV4_JAYWALK', 'no'); |
9318d2ef | 1061 | setConfigVar ('ADDNEW_AT_TOP', 'yes'); |
64347dcf | 1062 | setConfigVar ('IPV4_TREE_SHOW_USAGE', 'yes'); |
37e59768 DO |
1063 | setConfigVar ('PREVIEW_TEXT_MAXCHARS', '10240'); |
1064 | setConfigVar ('PREVIEW_TEXT_ROWS', '25'); | |
1065 | setConfigVar ('PREVIEW_TEXT_COLS', '80'); | |
1066 | setConfigVar ('PREVIEW_IMAGE_MAXPXS', '320'); | |
f3d274bf | 1067 | setConfigVar ('VENDOR_SIEVE', ''); |
35bf153d | 1068 | setConfigVar ('IPV4LB_LISTSRC', '{$typeid_4}'); |
8fee82b4 DO |
1069 | setConfigVar ('IPV4OBJ_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_12} or {$typeid_445} or {$typeid_447} or {$typeid_798}'); |
1070 | setConfigVar ('IPV4NAT_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8} or {$typeid_798}'); | |
35bf153d DO |
1071 | setConfigVar ('ASSETWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}'); |
1072 | setConfigVar ('NAMEWARN_LISTSRC','{$typeid_4} or {$typeid_7} or {$typeid_8}'); | |
f5883ec1 | 1073 | setConfigVar ('RACKS_PER_ROW','12'); |
590e1281 | 1074 | setConfigVar ('FILTER_PREDICATE_SIEVE',''); |
23cdc7e9 DO |
1075 | setConfigVar ('FILTER_DEFAULT_ANDOR','or'); |
1076 | setConfigVar ('FILTER_SUGGEST_ANDOR','yes'); | |
1077 | setConfigVar ('FILTER_SUGGEST_TAGS','yes'); | |
1078 | setConfigVar ('FILTER_SUGGEST_PREDICATES','yes'); | |
1079 | setConfigVar ('FILTER_SUGGEST_EXTRA','no'); | |
8fee82b4 | 1080 | setConfigVar ('DEFAULT_SNMP_COMMUNITY','public'); |
f06fe423 | 1081 | setConfigVar ('IPV4_ENABLE_KNIGHT','yes'); |
9e51318b DO |
1082 | setConfigVar ('TAGS_TOPLIST_SIZE','50'); |
1083 | setConfigVar ('TAGS_QUICKLIST_SIZE','20'); | |
1084 | setConfigVar ('TAGS_QUICKLIST_THRESHOLD','50'); | |
f44fdef9 | 1085 | setConfigVar ('ENABLE_MULTIPORT_FORM', 'no'); |
2400d7ec DO |
1086 | setConfigVar ('DEFAULT_PORT_IIF_ID', '1'); |
1087 | setConfigVar ('DEFAULT_PORT_OIF_IDS', '1=24; 3=1078; 4=1077; 5=1079; 6=1080; 8=1082; 9=1084'); | |
4a47d34b | 1088 | setConfigVar ('IPV4_TREE_RTR_AS_CELL', 'yes'); |
cd3775e9 | 1089 | setConfigVar ('PROXIMITY_RANGE', 0); |
ca4eb604 | 1090 | setConfigVar ('IPV4_TREE_SHOW_VLAN', 'yes'); |
407ed7bb DO |
1091 | setConfigVar ('VLANSWITCH_LISTSRC', ''); |
1092 | setConfigVar ('VLANIPV4NET_LISTSRC', ''); | |
2fb1f79b DO |
1093 | setConfigVar ('DEFAULT_VDOM_ID', ''); |
1094 | setConfigVar ('DEFAULT_VST_ID', ''); | |
01b9a31a | 1095 | setConfigVar ('STATIC_FILTER', 'yes'); |
37cb9e18 DO |
1096 | setConfigVar ('8021Q_DEPLOY_MINAGE', '300'); |
1097 | setConfigVar ('8021Q_DEPLOY_MAXAGE', '3600'); | |
1098 | setConfigVar ('8021Q_DEPLOY_RETRY', '10800'); | |
2582446d | 1099 | setConfigVar ('8021Q_WRI_AFTER_CONFT_LISTSRC', 'false'); |
4492050b | 1100 | setConfigVar ('8021Q_INSTANT_DEPLOY', 'no'); |
b49a479e DO |
1101 | setConfigVar ('CDP_RUNNERS_LISTSRC', ''); |
1102 | setConfigVar ('LLDP_RUNNERS_LISTSRC', ''); | |
0328f6d6 | 1103 | setConfigVar ('HNDP_RUNNERS_LISTSRC', ''); |
95857b5c | 1104 | setConfigVar ('SHRINK_TAG_TREE_ON_CLICK', 'yes'); |
1ebbf889 | 1105 | setConfigVar ('MAX_UNFILTERED_ENTITIES', '0'); |
61e79d63 | 1106 | setConfigVar ('SYNCDOMAIN_MAX_PROCESSES', '0'); |
135080d8 | 1107 | return buildRedirectURL (__FUNCTION__, 'OK'); |
b07f617c DO |
1108 | } |
1109 | ||
00e93d63 DO |
1110 | $msgcode['addRealServer']['OK'] = 48; |
1111 | $msgcode['addRealServer']['ERR'] = 110; | |
732e4578 | 1112 | // Add single record. |
ca461127 DO |
1113 | function addRealServer () |
1114 | { | |
0cc24e9a DY |
1115 | assertUIntArg ('pool_id'); |
1116 | assertIPv4Arg ('remoteip'); | |
1117 | assertStringArg ('rsport', TRUE); | |
1118 | assertStringArg ('rsconfig', TRUE); | |
103b1e1e DO |
1119 | if (!addRStoRSPool ( |
1120 | $_REQUEST['pool_id'], | |
1121 | $_REQUEST['remoteip'], | |
1122 | $_REQUEST['rsport'], | |
1123 | getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), | |
1124 | $_REQUEST['rsconfig'] | |
1125 | )) | |
135080d8 | 1126 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
d6517a21 | 1127 | else |
135080d8 | 1128 | return buildRedirectURL (__FUNCTION__, 'OK'); |
d6517a21 DO |
1129 | } |
1130 | ||
b6a7d936 DO |
1131 | $msgcode['addRealServers']['OK'] = 37; |
1132 | $msgcode['addRealServers']['ERR1'] = 131; | |
1133 | $msgcode['addRealServers']['ERR2'] = 127; | |
732e4578 DO |
1134 | // Parse textarea submitted and try adding a real server for each line. |
1135 | function addRealServers () | |
1136 | { | |
0cc24e9a DY |
1137 | assertStringArg ('format'); |
1138 | assertStringArg ('rawtext'); | |
732e4578 DO |
1139 | $ngood = $nbad = 0; |
1140 | $rsconfig = ''; | |
1141 | // Keep in mind, that the text will have HTML entities (namely '>') escaped. | |
7f42d792 | 1142 | foreach (explode ("\n", dos2unix ($_REQUEST['rawtext'])) as $line) |
732e4578 | 1143 | { |
59a83bd8 | 1144 | if (!strlen ($line)) |
732e4578 DO |
1145 | continue; |
1146 | $match = array (); | |
1147 | switch ($_REQUEST['format']) | |
1148 | { | |
1149 | case 'ipvs_2': // address and port only | |
1150 | if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) /', $line, $match)) | |
1151 | continue; | |
103b1e1e | 1152 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), '')) |
732e4578 DO |
1153 | $ngood++; |
1154 | else | |
1155 | $nbad++; | |
1156 | break; | |
1157 | case 'ipvs_3': // address, port and weight | |
1158 | if (!preg_match ('/^ -> ([0-9\.]+):([0-9]+) +[a-zA-Z]+ +([0-9]+) /', $line, $match)) | |
1159 | continue; | |
103b1e1e | 1160 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), 'weight ' . $match[3])) |
732e4578 DO |
1161 | $ngood++; |
1162 | else | |
1163 | $nbad++; | |
1164 | break; | |
e69c2aa3 DO |
1165 | case 'ssv_2': // IP address and port |
1166 | if (!preg_match ('/^([0-9\.]+) ([0-9]+)$/', $line, $match)) | |
1167 | continue; | |
103b1e1e | 1168 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], $match[2], getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), '')) |
e69c2aa3 DO |
1169 | $ngood++; |
1170 | else | |
1171 | $nbad++; | |
1172 | break; | |
948c37e3 DO |
1173 | case 'ssv_1': // IP address |
1174 | if (!preg_match ('/^([0-9\.]+)$/', $line, $match)) | |
1175 | continue; | |
1176 | if (addRStoRSPool ($_REQUEST['pool_id'], $match[1], 0, getConfigVar ('DEFAULT_IPV4_RS_INSERVICE'), '')) | |
1177 | $ngood++; | |
1178 | else | |
1179 | $nbad++; | |
1180 | break; | |
732e4578 | 1181 | default: |
135080d8 | 1182 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
732e4578 DO |
1183 | break; |
1184 | } | |
1185 | } | |
1186 | if ($nbad == 0 and $ngood > 0) | |
135080d8 | 1187 | return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood)); |
732e4578 | 1188 | else |
135080d8 | 1189 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($ngood, $nbad)); |
732e4578 DO |
1190 | } |
1191 | ||
00e93d63 | 1192 | $msgcode['addVService']['OK'] = 48; |
d6517a21 DO |
1193 | function addVService () |
1194 | { | |
0cc24e9a DY |
1195 | assertIPv4Arg ('vip'); |
1196 | assertUIntArg ('vport'); | |
a9ec91cf | 1197 | genericAssertion ('proto', 'enum/ipproto'); |
0cc24e9a DY |
1198 | assertStringArg ('name', TRUE); |
1199 | assertStringArg ('vsconfig', TRUE); | |
1200 | assertStringArg ('rsconfig', TRUE); | |
a9ec91cf | 1201 | usePreparedExecuteBlade |
c63a8d6e | 1202 | ( |
a9ec91cf DO |
1203 | 'INSERT INTO IPv4VS (vip, vport, proto, name, vsconfig, rsconfig) VALUES (INET_ATON(?), ?, ?, ?, ?, ?)', |
1204 | array | |
1205 | ( | |
1206 | $_REQUEST['vip'], | |
1207 | $_REQUEST['vport'], | |
1208 | $_REQUEST['proto'], | |
1209 | !mb_strlen ($_REQUEST['name']) ? NULL : $_REQUEST['name'], | |
1210 | !strlen ($_REQUEST['vsconfig']) ? NULL : $_REQUEST['vsconfig'], | |
1211 | !strlen ($_REQUEST['rsconfig']) ? NULL : $_REQUEST['rsconfig'], | |
1212 | ) | |
c63a8d6e | 1213 | ); |
a9ec91cf DO |
1214 | produceTagsForLastRecord ('ipv4vs', isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array()); |
1215 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
fb1c4a54 DO |
1216 | } |
1217 | ||
00e93d63 DO |
1218 | $msgcode['deleteVService']['OK'] = 49; |
1219 | $msgcode['deleteVService']['ERR'] = 111; | |
d6517a21 DO |
1220 | function deleteVService () |
1221 | { | |
0cc24e9a | 1222 | assertUIntArg ('vs_id'); |
e02e1941 | 1223 | if (!commitDeleteVS ($_REQUEST['vs_id'])) |
135080d8 | 1224 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
3241551e | 1225 | else |
135080d8 | 1226 | return buildRedirectURL (__FUNCTION__, 'OK'); |
3241551e DO |
1227 | } |
1228 | ||
1f54e1ba DO |
1229 | $msgcode['updateSLBDefConfig']['OK'] = 43; |
1230 | $msgcode['updateSLBDefConfig']['ERR'] = 109; | |
1231 | function updateSLBDefConfig () | |
1232 | { | |
1233 | $data = array( | |
1234 | 'vs' => $_REQUEST['vsconfig'], | |
1235 | 'rs' => $_REQUEST['rsconfig'] | |
1236 | ); | |
1237 | if (!commitUpdateSLBDefConf ($data)) | |
1238 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
1239 | else | |
1240 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
1241 | } | |
1242 | ||
00e93d63 DO |
1243 | $msgcode['updateRealServer']['OK'] = 51; |
1244 | $msgcode['updateRealServer']['ERR'] = 109; | |
fb1c4a54 DO |
1245 | function updateRealServer () |
1246 | { | |
0cc24e9a DY |
1247 | assertUIntArg ('rs_id'); |
1248 | assertIPv4Arg ('rsip'); | |
1249 | assertStringArg ('rsport', TRUE); | |
1250 | assertStringArg ('rsconfig', TRUE); | |
a5c589d2 | 1251 | if (FALSE === commitUpdateRS ( |
103b1e1e DO |
1252 | $_REQUEST['rs_id'], |
1253 | $_REQUEST['rsip'], | |
1254 | $_REQUEST['rsport'], | |
1255 | $_REQUEST['rsconfig'] | |
1256 | )) | |
135080d8 | 1257 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
fb1c4a54 | 1258 | else |
135080d8 | 1259 | return buildRedirectURL (__FUNCTION__, 'OK'); |
ca461127 DO |
1260 | } |
1261 | ||
00e93d63 DO |
1262 | $msgcode['updateLoadBalancer']['OK'] = 51; |
1263 | $msgcode['updateLoadBalancer']['ERR'] = 109; | |
c1ca768c | 1264 | function updateLoadBalancer () |
3241551e | 1265 | { |
0cc24e9a DY |
1266 | assertUIntArg ('object_id'); |
1267 | assertUIntArg ('pool_id'); | |
1268 | assertUIntArg ('vs_id'); | |
1269 | assertStringArg ('vsconfig', TRUE); | |
1270 | assertStringArg ('rsconfig', TRUE); | |
1f54e1ba DO |
1271 | if (! empty($_REQUEST['prio'])) |
1272 | assertUIntArg('prio', TRUE); | |
1273 | ||
a5c589d2 | 1274 | if (FALSE === commitUpdateLB ( |
103b1e1e DO |
1275 | $_REQUEST['object_id'], |
1276 | $_REQUEST['pool_id'], | |
1277 | $_REQUEST['vs_id'], | |
1278 | $_REQUEST['vsconfig'], | |
1f54e1ba DO |
1279 | $_REQUEST['rsconfig'], |
1280 | $_REQUEST['prio'] | |
103b1e1e | 1281 | )) |
135080d8 | 1282 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
d6517a21 | 1283 | else |
135080d8 | 1284 | return buildRedirectURL (__FUNCTION__, 'OK'); |
d6517a21 DO |
1285 | } |
1286 | ||
00e93d63 DO |
1287 | $msgcode['updateVService']['OK'] = 51; |
1288 | $msgcode['updateVService']['ERR'] = 109; | |
d6517a21 DO |
1289 | function updateVService () |
1290 | { | |
0cc24e9a DY |
1291 | assertUIntArg ('vs_id'); |
1292 | assertIPv4Arg ('vip'); | |
1293 | assertUIntArg ('vport'); | |
1d84140d | 1294 | genericAssertion ('proto', 'enum/ipproto'); |
0cc24e9a DY |
1295 | assertStringArg ('name', TRUE); |
1296 | assertStringArg ('vsconfig', TRUE); | |
1297 | assertStringArg ('rsconfig', TRUE); | |
a5c589d2 | 1298 | if (FALSE === commitUpdateVS ( |
103b1e1e DO |
1299 | $_REQUEST['vs_id'], |
1300 | $_REQUEST['vip'], | |
1301 | $_REQUEST['vport'], | |
1302 | $_REQUEST['proto'], | |
1303 | $_REQUEST['name'], | |
1304 | $_REQUEST['vsconfig'], | |
1305 | $_REQUEST['rsconfig'] | |
1306 | )) | |
135080d8 | 1307 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
3241551e | 1308 | else |
135080d8 | 1309 | return buildRedirectURL (__FUNCTION__, 'OK'); |
3241551e DO |
1310 | } |
1311 | ||
00e93d63 DO |
1312 | $msgcode['addLoadBalancer']['OK'] = 48; |
1313 | $msgcode['addLoadBalancer']['ERR'] = 110; | |
3241551e DO |
1314 | function addLoadBalancer () |
1315 | { | |
0cc24e9a DY |
1316 | assertUIntArg ('pool_id'); |
1317 | assertUIntArg ('object_id'); | |
1318 | assertUIntArg ('vs_id'); | |
1319 | assertStringArg ('vsconfig', TRUE); | |
1320 | assertStringArg ('rsconfig', TRUE); | |
1f54e1ba DO |
1321 | if (! empty($_REQUEST['prio'])) |
1322 | assertUIntArg('prio', TRUE); | |
1323 | ||
103b1e1e DO |
1324 | if (!addLBtoRSPool ( |
1325 | $_REQUEST['pool_id'], | |
1326 | $_REQUEST['object_id'], | |
1327 | $_REQUEST['vs_id'], | |
1328 | $_REQUEST['vsconfig'], | |
1f54e1ba DO |
1329 | $_REQUEST['rsconfig'], |
1330 | $_REQUEST['prio'] | |
103b1e1e | 1331 | )) |
135080d8 | 1332 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
3241551e | 1333 | else |
135080d8 | 1334 | return buildRedirectURL (__FUNCTION__, 'OK'); |
3241551e DO |
1335 | } |
1336 | ||
00e93d63 | 1337 | $msgcode['addRSPool']['OK'] = 48; |
b6a7d936 | 1338 | $msgcode['addRSPool']['ERR'] = 100; |
5ad76f01 DO |
1339 | function addRSPool () |
1340 | { | |
0cc24e9a DY |
1341 | assertStringArg ('name', TRUE); |
1342 | assertStringArg ('vsconfig', TRUE); | |
1343 | assertStringArg ('rsconfig', TRUE); | |
c63a8d6e DO |
1344 | $error = commitCreateRSPool |
1345 | ( | |
103b1e1e DO |
1346 | $_REQUEST['name'], |
1347 | $_REQUEST['vsconfig'], | |
c63a8d6e DO |
1348 | $_REQUEST['rsconfig'], |
1349 | isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array() | |
1350 | ); | |
1351 | if ($error != '') | |
135080d8 | 1352 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
5ad76f01 | 1353 | else |
135080d8 | 1354 | return buildRedirectURL (__FUNCTION__, 'OK'); |
5ad76f01 DO |
1355 | } |
1356 | ||
00e93d63 DO |
1357 | $msgcode['deleteRSPool']['OK'] = 49; |
1358 | $msgcode['deleteRSPool']['ERR'] = 111; | |
5ad76f01 DO |
1359 | function deleteRSPool () |
1360 | { | |
0cc24e9a | 1361 | assertUIntArg ('pool_id'); |
654e4636 | 1362 | if (commitDeleteRSPool ($_REQUEST['pool_id']) === FALSE) |
135080d8 | 1363 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
5ad76f01 | 1364 | else |
135080d8 | 1365 | return buildRedirectURL (__FUNCTION__, 'OK'); |
5ad76f01 DO |
1366 | } |
1367 | ||
00e93d63 DO |
1368 | $msgcode['updateRSPool']['OK'] = 51; |
1369 | $msgcode['updateRSPool']['ERR'] = 109; | |
5ad76f01 DO |
1370 | function updateRSPool () |
1371 | { | |
0cc24e9a DY |
1372 | assertStringArg ('name', TRUE); |
1373 | assertStringArg ('vsconfig', TRUE); | |
1374 | assertStringArg ('rsconfig', TRUE); | |
1f54e1ba DO |
1375 | if (FALSE === commitUpdateRSPool |
1376 | ( | |
1377 | $_REQUEST['pool_id'], | |
1378 | $_REQUEST['name'], | |
1379 | $_REQUEST['vsconfig'], | |
1380 | $_REQUEST['rsconfig'] | |
1381 | ) | |
1382 | ) | |
135080d8 | 1383 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
5ad76f01 | 1384 | else |
135080d8 | 1385 | return buildRedirectURL (__FUNCTION__, 'OK'); |
5ad76f01 DO |
1386 | } |
1387 | ||
00e93d63 DO |
1388 | $msgcode['updateRSInService']['OK'] = 26; |
1389 | $msgcode['updateRSInService']['ERR'] = 141; | |
1f7d18fa DO |
1390 | function updateRSInService () |
1391 | { | |
0cc24e9a | 1392 | assertUIntArg ('rscount'); |
841a7a7a | 1393 | $pool_id = $_REQUEST['pool_id']; |
a6e91ac2 DO |
1394 | $orig = spotEntity ('ipv4rspool', $pool_id); |
1395 | amplifyCell ($orig); | |
1f7d18fa DO |
1396 | $nbad = $ngood = 0; |
1397 | for ($i = 1; $i <= $_REQUEST['rscount']; $i++) | |
1398 | { | |
1399 | $rs_id = $_REQUEST["rsid_${i}"]; | |
1400 | if (isset ($_REQUEST["inservice_${i}"]) and $_REQUEST["inservice_${i}"] == 'on') | |
1401 | $newval = 'yes'; | |
1402 | else | |
1403 | $newval = 'no'; | |
1404 | if ($newval != $orig['rslist'][$rs_id]['inservice']) | |
1405 | { | |
a5c589d2 | 1406 | if (FALSE !== commitSetInService ($rs_id, $newval)) |
1f7d18fa DO |
1407 | $ngood++; |
1408 | else | |
1409 | $nbad++; | |
1410 | } | |
1411 | } | |
1412 | if (!$nbad) | |
135080d8 | 1413 | return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood)); |
1f7d18fa | 1414 | else |
135080d8 | 1415 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood)); |
1f7d18fa DO |
1416 | } |
1417 | ||
b6a7d936 DO |
1418 | $msgcode['importPTRData']['OK'] = 26; |
1419 | $msgcode['importPTRData']['ERR'] = 141; | |
8d9c16e7 DO |
1420 | // FIXME: check, that each submitted address belongs to the prefix we |
1421 | // are operating on. | |
03eb5209 DO |
1422 | function importPTRData () |
1423 | { | |
0cc24e9a | 1424 | assertUIntArg ('addrcount'); |
03eb5209 | 1425 | $nbad = $ngood = 0; |
03eb5209 DO |
1426 | for ($i = 0; $i < $_REQUEST['addrcount']; $i++) |
1427 | { | |
3f3bd41e | 1428 | $inputname = "import_${i}"; |
03eb5209 DO |
1429 | if (!isset ($_REQUEST[$inputname]) or $_REQUEST[$inputname] != 'on') |
1430 | continue; | |
0cc24e9a DY |
1431 | assertIPv4Arg ("addr_${i}"); |
1432 | assertStringArg ("descr_${i}", TRUE); | |
1433 | assertStringArg ("rsvd_${i}"); | |
3f3bd41e DO |
1434 | // Non-existent addresses will not have this argument set in request. |
1435 | $rsvd = 'no'; | |
03eb5209 DO |
1436 | if ($_REQUEST["rsvd_${i}"] == 'yes') |
1437 | $rsvd = 'yes'; | |
3f3bd41e | 1438 | if (updateAddress ($_REQUEST["addr_${i}"], $_REQUEST["descr_${i}"], $rsvd) == '') |
03eb5209 DO |
1439 | $ngood++; |
1440 | else | |
1441 | $nbad++; | |
1442 | } | |
1443 | if (!$nbad) | |
135080d8 | 1444 | return buildRedirectURL (__FUNCTION__, 'OK', array ($ngood)); |
03eb5209 | 1445 | else |
135080d8 | 1446 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($nbad, $ngood)); |
03eb5209 DO |
1447 | } |
1448 | ||
b6a7d936 DO |
1449 | $msgcode['generateAutoPorts']['OK'] = 21; |
1450 | $msgcode['generateAutoPorts']['ERR'] = 142; | |
f3f0161f DO |
1451 | function generateAutoPorts () |
1452 | { | |
103b1e1e | 1453 | global $pageno; |
6297d584 | 1454 | $info = spotEntity ('object', $_REQUEST['object_id']); |
f3f0161f | 1455 | // Navigate away in case of success, stay at the place otherwise. |
103b1e1e | 1456 | if (executeAutoPorts ($_REQUEST['object_id'], $info['objtype_id'])) |
135080d8 | 1457 | return buildRedirectURL (__FUNCTION__, 'OK', array(), $pageno, 'ports'); |
f3f0161f | 1458 | else |
135080d8 | 1459 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
f3f0161f DO |
1460 | } |
1461 | ||
00e93d63 | 1462 | $msgcode['saveEntityTags']['OK'] = 26; |
b6a7d936 | 1463 | $msgcode['saveEntityTags']['ERR1'] = 143; |
24cbe8af | 1464 | // Filter out implicit tags before storing the new tag set. |
3355ca56 | 1465 | function saveEntityTags () |
24cbe8af | 1466 | { |
1d356026 DO |
1467 | global $pageno, $etype_by_pageno; |
1468 | if (!isset ($etype_by_pageno[$pageno])) | |
1469 | throw new RackTablesError ('key not found in etype_by_pageno', RackTablesError::INTERNAL); | |
be2ae2a2 | 1470 | $realm = $etype_by_pageno[$pageno]; |
1d356026 | 1471 | $entity_id = getBypassValue(); |
e04931c8 | 1472 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
6e49bd1f | 1473 | // Build a chain from the submitted data, minimize it, |
ab379543 | 1474 | // then wipe existing records and store the new set instead. |
01b6b4d6 | 1475 | destroyTagsForEntity ($realm, $entity_id); |
eb27afad DO |
1476 | // TODO: these actions are very close to what rebuildTagChainForEntity() does, |
1477 | // so why not use it? | |
6e49bd1f | 1478 | $newchain = getExplicitTagsOnly (buildTagChainFromIds ($taglist)); |
ab379543 | 1479 | $n_succeeds = $n_errors = 0; |
6e49bd1f | 1480 | foreach ($newchain as $taginfo) |
eb6ea26f | 1481 | if (addTagForEntity ($realm, $entity_id, $taginfo['id'])) |
ab379543 DO |
1482 | $n_succeeds++; |
1483 | else | |
1484 | $n_errors++; | |
ab379543 | 1485 | if ($n_errors) |
9a61c175 | 1486 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($n_succeeds, $n_errors)); |
ab379543 | 1487 | else |
135080d8 | 1488 | return buildRedirectURL (__FUNCTION__, 'OK', array ($n_succeeds)); |
2034d968 DO |
1489 | } |
1490 | ||
00e93d63 | 1491 | $msgcode['updateTag']['OK'] = 7; |
a5c589d2 | 1492 | $msgcode['updateTag']['ERR2'] = 109; |
49fb1027 DO |
1493 | function updateTag () |
1494 | { | |
0cc24e9a DY |
1495 | assertUIntArg ('tag_id'); |
1496 | assertUIntArg ('parent_id', TRUE); | |
00e93d63 | 1497 | genericAssertion ('tag_name', 'tag'); |
49fb1027 DO |
1498 | if (($parent_id = $_REQUEST['parent_id']) <= 0) |
1499 | $parent_id = 'NULL'; | |
a5c589d2 | 1500 | if (FALSE !== commitUpdateTag ($_REQUEST['tag_id'], $tagname, $parent_id)) |
135080d8 | 1501 | return buildRedirectURL (__FUNCTION__, 'OK', array ($tagname)); |
590e1281 DO |
1502 | // Use old name in the message, cause update failed. |
1503 | global $taglist; | |
a5c589d2 | 1504 | return buildRedirectURL (__FUNCTION__, 'ERR2', array ($taglist[$_REQUEST['tag_id']]['tag'])); |
49fb1027 DO |
1505 | } |
1506 | ||
b6a7d936 DO |
1507 | $msgcode['rollTags']['OK'] = 67; |
1508 | $msgcode['rollTags']['ERR'] = 149; | |
eb6ea26f DO |
1509 | function rollTags () |
1510 | { | |
0cc24e9a DY |
1511 | assertStringArg ('sum', TRUE); |
1512 | assertUIntArg ('realsum'); | |
eb6ea26f | 1513 | if ($_REQUEST['sum'] != $_REQUEST['realsum']) |
135080d8 | 1514 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
abef7149 DO |
1515 | // Even if the user requested an empty tag list, don't bail out, but process existing |
1516 | // tag chains with "zero" extra. This will make sure, that the stuff processed will | |
1517 | // have its chains refined to "normal" form. | |
1518 | $extratags = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); | |
1519 | $n_ok = 0; | |
1520 | // Minimizing the extra chain early, so that tag rebuilder doesn't have to | |
1521 | // filter out the same tag again and again. It will have own noise to cancel. | |
1522 | $extrachain = getExplicitTagsOnly (buildTagChainFromIds ($extratags)); | |
61a1d996 | 1523 | foreach (listCells ('rack', $_REQUEST['row_id']) as $rack) |
abef7149 | 1524 | { |
61a1d996 | 1525 | if (rebuildTagChainForEntity ('rack', $rack['id'], $extrachain)) |
abef7149 | 1526 | $n_ok++; |
61a1d996 DO |
1527 | amplifyCell ($rack); |
1528 | foreach ($rack['mountedObjects'] as $object_id) | |
abef7149 DO |
1529 | if (rebuildTagChainForEntity ('object', $object_id, $extrachain)) |
1530 | $n_ok++; | |
1531 | } | |
135080d8 | 1532 | return buildRedirectURL (__FUNCTION__, 'OK', array ($n_ok)); |
eb6ea26f DO |
1533 | } |
1534 | ||
00e93d63 | 1535 | $msgcode['changeMyPassword']['OK'] = 51; |
b6a7d936 DO |
1536 | $msgcode['changeMyPassword']['ERR1'] = 150; |
1537 | $msgcode['changeMyPassword']['ERR2'] = 151; | |
1538 | $msgcode['changeMyPassword']['ERR3'] = 152; | |
1539 | $msgcode['changeMyPassword']['ERR4'] = 153; | |
9457ca59 | 1540 | function changeMyPassword () |
cced6b7d | 1541 | { |
b82cce3f | 1542 | global $remote_username, $user_auth_src; |
204284ba | 1543 | if ($user_auth_src != 'database') |
135080d8 | 1544 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
0cc24e9a DY |
1545 | assertStringArg ('oldpassword'); |
1546 | assertStringArg ('newpassword1'); | |
1547 | assertStringArg ('newpassword2'); | |
b82cce3f | 1548 | $remote_userid = getUserIDByUsername ($remote_username); |
0b2c74cb | 1549 | $userinfo = spotEntity ('user', $remote_userid); |
b82cce3f | 1550 | if ($userinfo['user_password_hash'] != sha1 ($_REQUEST['oldpassword'])) |
135080d8 | 1551 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
cced6b7d | 1552 | if ($_REQUEST['newpassword1'] != $_REQUEST['newpassword2']) |
135080d8 | 1553 | return buildRedirectURL (__FUNCTION__, 'ERR3'); |
32832c0e | 1554 | if (FALSE !== commitUpdateUserAccount ($remote_userid, $userinfo['user_name'], $userinfo['user_realname'], sha1 ($_REQUEST['newpassword1']))) |
135080d8 | 1555 | return buildRedirectURL (__FUNCTION__, 'OK'); |
cced6b7d | 1556 | else |
135080d8 | 1557 | return buildRedirectURL (__FUNCTION__, 'ERR4'); |
cced6b7d DO |
1558 | } |
1559 | ||
b6a7d936 DO |
1560 | $msgcode['saveRackCode']['OK'] = 43; |
1561 | $msgcode['saveRackCode']['ERR1'] = 154; | |
1562 | $msgcode['saveRackCode']['ERR2'] = 155; | |
cced6b7d DO |
1563 | function saveRackCode () |
1564 | { | |
cced6b7d | 1565 | assertStringArg ('rackcode'); |
e6a4adb9 | 1566 | // For the test to succeed, unescape LFs, strip CRs. |
7f42d792 | 1567 | $newcode = dos2unix ($_REQUEST['rackcode']); |
cf25e649 DO |
1568 | $parseTree = getRackCode ($newcode); |
1569 | if ($parseTree['result'] != 'ACK') | |
135080d8 | 1570 | return buildRedirectURL (__FUNCTION__, 'ERR1', array ($parseTree['load'])); |
bb09f49c DO |
1571 | if (FALSE !== saveScript ('RackCode', $newcode)) |
1572 | { | |
1573 | saveScript ('RackCodeCache', base64_encode (serialize ($parseTree))); | |
135080d8 | 1574 | return buildRedirectURL (__FUNCTION__, 'OK'); |
bb09f49c DO |
1575 | } |
1576 | return buildRedirectURL (__FUNCTION__, 'ERR2'); | |
cced6b7d DO |
1577 | } |
1578 | ||
3f052a67 | 1579 | $msgcode['setPortVLAN']['ERR'] = 164; |
46f92ff7 DO |
1580 | // This handler's context is pre-built, but not authorized. It is assumed, that the |
1581 | // handler will take existing context and before each commit check authorization | |
1582 | // on the base chain plus necessary context added. | |
1583 | function setPortVLAN () | |
1584 | { | |
0cc24e9a | 1585 | assertUIntArg ('portcount'); |
3f052a67 DO |
1586 | try |
1587 | { | |
1588 | $data = getSwitchVLANs ($_REQUEST['object_id']); | |
1589 | } | |
1590 | catch (RTGatewayError $re) | |
1591 | { | |
1592 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($re->getMessage())); | |
1593 | } | |
46f92ff7 DO |
1594 | list ($vlanlist, $portlist) = $data; |
1595 | // Here we just build up 1 set command for the gateway with all of the ports | |
1596 | // included. The gateway is expected to filter unnecessary changes silently | |
1597 | // and to provide a list of responses with either error or success message | |
1598 | // for each of the rest. | |
1599 | $nports = $_REQUEST['portcount']; | |
1600 | $prefix = 'set '; | |
db55cf54 | 1601 | $log = emptyLog(); |
46f92ff7 DO |
1602 | $setcmd = ''; |
1603 | for ($i = 0; $i < $nports; $i++) | |
3f052a67 DO |
1604 | { |
1605 | genericAssertion ('portname_' . $i, 'string'); | |
1606 | genericAssertion ('vlanid_' . $i, 'string'); | |
1607 | if ($_REQUEST['portname_' . $i] != $portlist[$i]['portname']) | |
1608 | throw new InvalidRequestArgException ('portname_' . $i, $_REQUEST['portname_' . $i], 'expected to be ' . $portlist[$i]['portname']); | |
46f92ff7 | 1609 | if |
46f92ff7 DO |
1610 | ( |
1611 | $_REQUEST['vlanid_' . $i] == $portlist[$i]['vlanid'] || | |
1612 | $portlist[$i]['vlaind'] == 'TRUNK' | |
1613 | ) | |
1614 | continue; | |
3f052a67 DO |
1615 | $portname = $_REQUEST['portname_' . $i]; |
1616 | $oldvlanid = $portlist[$i]['vlanid']; | |
1617 | $newvlanid = $_REQUEST['vlanid_' . $i]; | |
1618 | if | |
1619 | ( | |
1620 | !permitted (NULL, NULL, NULL, array (array ('tag' => '$fromvlan_' . $oldvlanid))) or | |
1621 | !permitted (NULL, NULL, NULL, array (array ('tag' => '$tovlan_' . $newvlanid))) | |
1622 | ) | |
46f92ff7 | 1623 | { |
1d84140d | 1624 | $log = mergeLogs ($log, oneLiner (159, array ($portname, $oldvlanid, $newvlanid))); |
3f052a67 | 1625 | continue; |
46f92ff7 | 1626 | } |
3f052a67 DO |
1627 | $setcmd .= $prefix . $portname . '=' . $newvlanid; |
1628 | $prefix = ';'; | |
1629 | } | |
46f92ff7 | 1630 | // Feed the gateway and interpret its (non)response. |
1d84140d DO |
1631 | if ($setcmd == '') |
1632 | $log = mergeLogs ($log, oneLiner (201)); | |
46f92ff7 | 1633 | else |
1d84140d DO |
1634 | { |
1635 | try | |
1636 | { | |
1637 | $log = mergeLogs ($log, setSwitchVLANs ($_REQUEST['object_id'], $setcmd)); | |
1638 | } | |
1639 | catch (RTGatewayError $e) | |
1640 | { | |
1641 | $log = mergeLogs ($log, oneLiner (164, $e->getMessage())); | |
1642 | } | |
1643 | } | |
46f92ff7 DO |
1644 | return buildWideRedirectURL ($log); |
1645 | } | |
1646 | ||
12b0c847 DO |
1647 | $msgcode['submitSLBConfig']['OK'] = 66; |
1648 | $msgcode['submitSLBConfig']['ERR'] = 164; | |
2987fc1f DO |
1649 | function submitSLBConfig () |
1650 | { | |
2987fc1f | 1651 | $newconfig = buildLVSConfig ($_REQUEST['object_id']); |
12b0c847 DO |
1652 | try |
1653 | { | |
1654 | gwSendFileToObject ($_REQUEST['object_id'], 'slbconfig', html_entity_decode ($newconfig, ENT_QUOTES, 'UTF-8')); | |
1655 | } | |
3a089a44 | 1656 | catch (RTGatewayError $e) |
12b0c847 | 1657 | { |
3a089a44 | 1658 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($e->getMessage())); |
12b0c847 DO |
1659 | } |
1660 | return buildRedirectURL (__FUNCTION__, 'OK', array ('slbconfig')); | |
2987fc1f DO |
1661 | } |
1662 | ||
00e93d63 | 1663 | $msgcode['updateRow']['OK'] = 7; |
b6a7d936 | 1664 | $msgcode['updateRow']['ERR'] = 100; |
345fd640 AD |
1665 | function updateRow () |
1666 | { | |
0cc24e9a DY |
1667 | assertUIntArg ('row_id'); |
1668 | assertStringArg ('name'); | |
345fd640 | 1669 | |
39eadd27 | 1670 | if (FALSE !== commitUpdateRow ($_REQUEST['row_id'], $_REQUEST['name'])) |
135080d8 | 1671 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['name'])); |
345fd640 | 1672 | else |
135080d8 | 1673 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($_REQUEST['name'])); |
345fd640 AD |
1674 | } |
1675 | ||
00e93d63 | 1676 | $msgcode['addRack']['OK'] = 51; |
b6a7d936 | 1677 | $msgcode['addRack']['ERR2'] = 172; |
f19c75d6 DO |
1678 | function addRack () |
1679 | { | |
f19c75d6 DO |
1680 | $taglist = isset ($_REQUEST['taglist']) ? $_REQUEST['taglist'] : array(); |
1681 | if (isset ($_REQUEST['got_data'])) | |
1682 | { | |
0cc24e9a DY |
1683 | assertStringArg ('rack_name'); |
1684 | assertUIntArg ('rack_height1'); | |
1685 | assertStringArg ('rack_comment', TRUE); | |
00e93d63 DO |
1686 | commitAddRack ($_REQUEST['rack_name'], $_REQUEST['rack_height1'], $_REQUEST['row_id'], $_REQUEST['rack_comment'], $taglist); |
1687 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name'])); | |
f19c75d6 DO |
1688 | } |
1689 | elseif (isset ($_REQUEST['got_mdata'])) | |
1690 | { | |
0cc24e9a DY |
1691 | assertUIntArg ('rack_height2'); |
1692 | assertStringArg ('rack_names', TRUE); | |
db55cf54 | 1693 | $log = emptyLog(); |
f19c75d6 | 1694 | // copy-and-paste from renderAddMultipleObjectsForm() |
7f42d792 | 1695 | $names1 = explode ("\n", $_REQUEST['rack_names']); |
f19c75d6 DO |
1696 | $names2 = array(); |
1697 | foreach ($names1 as $line) | |
1698 | { | |
1699 | $parts = explode ('\r', $line); | |
1700 | reset ($parts); | |
59a83bd8 | 1701 | if (!strlen ($parts[0])) |
f19c75d6 DO |
1702 | continue; |
1703 | else | |
1704 | $names2[] = rtrim ($parts[0]); | |
1705 | } | |
b3029d5c | 1706 | global $msgcode; |
f19c75d6 | 1707 | foreach ($names2 as $cname) |
1d84140d DO |
1708 | { |
1709 | commitAddRack ($cname, $_REQUEST['rack_height2'], $_REQUEST['row_id'], '', $taglist); | |
1710 | $log['m'][] = array ('c' => $msgcode[__FUNCTION__]['OK'], 'a' => array ($cname)); | |
1711 | } | |
f19c75d6 DO |
1712 | return buildWideRedirectURL ($log); |
1713 | } | |
1714 | else | |
135080d8 | 1715 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
f19c75d6 DO |
1716 | } |
1717 | ||
00e93d63 | 1718 | $msgcode['deleteRack']['OK'] = 6; |
b6a7d936 DO |
1719 | $msgcode['deleteRack']['ERR'] = 100; |
1720 | $msgcode['deleteRack']['ERR1'] = 206; | |
c8187437 DY |
1721 | function deleteRack () |
1722 | { | |
0cc24e9a | 1723 | assertUIntArg ('rack_id'); |
6538d363 | 1724 | $rackData = spotEntity ('rack', $_REQUEST['rack_id']); |
61a1d996 DO |
1725 | amplifyCell ($rackData); |
1726 | if (count ($rackData['mountedObjects'])) | |
c8187437 | 1727 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
61a1d996 DO |
1728 | if (TRUE !== commitDeleteRack ($_REQUEST['rack_id'])) |
1729 | return buildRedirectURL (__FUNCTION__, 'ERR', array(), 'rackspace', 'default'); | |
1730 | return buildRedirectURL (__FUNCTION__, 'OK', array ($rackData['name']), 'rackspace', 'default'); | |
c8187437 DY |
1731 | } |
1732 | ||
00e93d63 DO |
1733 | $msgcode['updateRack']['OK'] = 7; |
1734 | $msgcode['updateRack']['ERR'] = 109; | |
7056988c DO |
1735 | function updateRack () |
1736 | { | |
0cc24e9a DY |
1737 | assertUIntArg ('rack_row_id'); |
1738 | assertUIntArg ('rack_height'); | |
1739 | assertStringArg ('rack_name'); | |
1740 | assertStringArg ('rack_comment', TRUE); | |
7056988c | 1741 | |
7056988c | 1742 | resetThumbCache ($_REQUEST['rack_id']); |
0c2b7c4a | 1743 | if (TRUE === commitUpdateRack ($_REQUEST['rack_id'], $_REQUEST['rack_name'], $_REQUEST['rack_height'], $_REQUEST['rack_row_id'], $_REQUEST['rack_comment'])) |
135080d8 | 1744 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['rack_name'])); |
0c2b7c4a | 1745 | else |
135080d8 | 1746 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
7056988c DO |
1747 | } |
1748 | ||
4fbb5a00 DY |
1749 | function updateRackDesign () |
1750 | { | |
6cfedb71 | 1751 | $rackData = spotEntity ('rack', $_REQUEST['rack_id']); |
61a1d996 | 1752 | amplifyCell ($rackData); |
4fbb5a00 DY |
1753 | applyRackDesignMask($rackData); |
1754 | markupObjectProblems ($rackData); | |
1755 | $response = processGridForm ($rackData, 'A', 'F'); | |
51690ad4 | 1756 | return buildWideRedirectURL (array($response)); |
4fbb5a00 DY |
1757 | } |
1758 | ||
1759 | function updateRackProblems () | |
1760 | { | |
6cfedb71 | 1761 | $rackData = spotEntity ('rack', $_REQUEST['rack_id']); |
61a1d996 | 1762 | amplifyCell ($rackData); |
4fbb5a00 DY |
1763 | applyRackProblemMask($rackData); |
1764 | markupObjectProblems ($rackData); | |
1765 | $response = processGridForm ($rackData, 'F', 'U'); | |
51690ad4 | 1766 | return buildWideRedirectURL (array($response)); |
4fbb5a00 DY |
1767 | } |
1768 | ||
7056988c DO |
1769 | function querySNMPData () |
1770 | { | |
8228bdb4 DO |
1771 | assertStringArg ('community', TRUE); |
1772 | ||
1773 | $snmpsetup = array (); | |
011b6699 | 1774 | if ($_REQUEST['community'] != '') |
1d84140d DO |
1775 | $snmpsetup['community'] = $_REQUEST['community']; |
1776 | else | |
1777 | { | |
8228bdb4 DO |
1778 | assertStringArg ('sec_name'); |
1779 | assertStringArg ('sec_level'); | |
1780 | assertStringArg ('auth_protocol'); | |
1781 | assertStringArg ('auth_passphrase', TRUE); | |
1782 | assertStringArg ('priv_protocol'); | |
1783 | assertStringArg ('priv_passphrase', TRUE); | |
1784 | ||
1785 | $snmpsetup['sec_name'] = $_REQUEST['sec_name']; | |
1786 | $snmpsetup['sec_level'] = $_REQUEST['sec_level']; | |
1787 | $snmpsetup['auth_protocol'] = $_REQUEST['auth_protocol']; | |
1788 | $snmpsetup['auth_passphrase'] = $_REQUEST['auth_passphrase']; | |
1789 | $snmpsetup['priv_protocol'] = $_REQUEST['priv_protocol']; | |
1790 | $snmpsetup['priv_passphrase'] = $_REQUEST['priv_passphrase']; | |
1791 | } | |
8228bdb4 | 1792 | return doSNMPmining ($_REQUEST['object_id'], $snmpsetup); |
7056988c DO |
1793 | } |
1794 | ||
00e93d63 | 1795 | $msgcode['addFileWithoutLink']['OK'] = 5; |
6cfedb71 | 1796 | $msgcode['addFileWithoutLink']['ERR2'] = 110; |
e1ae3fb4 AD |
1797 | // File-related functions |
1798 | function addFileWithoutLink () | |
1799 | { | |
0cc24e9a | 1800 | assertStringArg ('comment', TRUE); |
e1ae3fb4 AD |
1801 | |
1802 | // Make sure the file can be uploaded | |
1803 | if (get_cfg_var('file_uploads') != 1) | |
00e93d63 | 1804 | throw new RackTablesError ('file uploads not allowed, change "file_uploads" parameter in php.ini', RackTablesError::MISCONFIGURED); |
e1ae3fb4 AD |
1805 | |
1806 | $fp = fopen($_FILES['file']['tmp_name'], 'rb'); | |
4bb95650 | 1807 | global $sic; |
6cfedb71 DO |
1808 | if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment'])) |
1809 | return buildRedirectURL (__FUNCTION__, 'ERR2'); | |
f857f71f DO |
1810 | if (isset ($_REQUEST['taglist'])) |
1811 | produceTagsForLastRecord ('file', $_REQUEST['taglist']); | |
6cfedb71 | 1812 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($_FILES['file']['name']))); |
e1ae3fb4 AD |
1813 | } |
1814 | ||
00e93d63 | 1815 | $msgcode['addFileToEntity']['OK'] = 5; |
b6a7d936 | 1816 | $msgcode['addFileToEntity']['ERR2'] = 181; |
6cfedb71 | 1817 | $msgcode['addFileToEntity']['ERR3'] = 110; |
e1ae3fb4 AD |
1818 | function addFileToEntity () |
1819 | { | |
1d356026 DO |
1820 | global $pageno, $etype_by_pageno; |
1821 | if (!isset ($etype_by_pageno[$pageno])) | |
1822 | throw new RackTablesError ('key not found in etype_by_pageno', RackTablesError::INTERNAL); | |
9a61c175 | 1823 | $realm = $etype_by_pageno[$pageno]; |
1d356026 | 1824 | $entity_id = getBypassValue(); |
0cc24e9a | 1825 | assertStringArg ('comment', TRUE); |
e1ae3fb4 AD |
1826 | |
1827 | // Make sure the file can be uploaded | |
1828 | if (get_cfg_var('file_uploads') != 1) | |
9a61c175 | 1829 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
e1ae3fb4 AD |
1830 | |
1831 | $fp = fopen($_FILES['file']['tmp_name'], 'rb'); | |
4bb95650 | 1832 | global $sic; |
6cfedb71 DO |
1833 | if (FALSE === commitAddFile ($_FILES['file']['name'], $_FILES['file']['type'], $_FILES['file']['size'], $fp, $sic['comment'])) |
1834 | return buildRedirectURL (__FUNCTION__, 'ERR3'); | |
1835 | if (FALSE === commitLinkFile (lastInsertID(), $realm, $entity_id)) | |
1836 | return buildRedirectURL (__FUNCTION__, 'ERR3'); | |
e1ae3fb4 | 1837 | |
6cfedb71 | 1838 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($_FILES['file']['name']))); |
e1ae3fb4 AD |
1839 | } |
1840 | ||
b6a7d936 | 1841 | $msgcode['linkFileToEntity']['OK'] = 71; |
6cfedb71 | 1842 | $msgcode['linkFileToEntity']['ERR2'] = 110; |
e1ae3fb4 AD |
1843 | function linkFileToEntity () |
1844 | { | |
0cc24e9a | 1845 | assertUIntArg ('file_id'); |
1d356026 DO |
1846 | global $pageno, $etype_by_pageno; |
1847 | if (!isset ($etype_by_pageno[$pageno])) | |
1848 | throw new RackTablesError ('key not found in etype_by_pageno', RackTablesError::INTERNAL); | |
121496b6 | 1849 | |
d3b5008b | 1850 | $fi = spotEntity ('file', $_REQUEST['file_id']); |
1d356026 | 1851 | if (FALSE === commitLinkFile ($_REQUEST['file_id'], $etype_by_pageno[$pageno], getBypassValue())) |
6cfedb71 | 1852 | return buildRedirectURL (__FUNCTION__, 'ERR2'); |
e1ae3fb4 | 1853 | |
6cfedb71 | 1854 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($fi['name']))); |
e1ae3fb4 AD |
1855 | } |
1856 | ||
00e93d63 | 1857 | $msgcode['replaceFile']['OK'] = 7; |
b6a7d936 DO |
1858 | $msgcode['replaceFile']['ERR1'] = 181; |
1859 | $msgcode['replaceFile']['ERR2'] = 207; | |
6cfedb71 | 1860 | $msgcode['replaceFile']['ERR3'] = 109; |
fd1fb420 AD |
1861 | function replaceFile () |
1862 | { | |
db55cf54 | 1863 | global $sic; |
fd1fb420 AD |
1864 | |
1865 | // Make sure the file can be uploaded | |
1866 | if (get_cfg_var('file_uploads') != 1) | |
db55cf54 | 1867 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
d3b5008b | 1868 | $shortInfo = spotEntity ('file', $sic['file_id']); |
fd1fb420 AD |
1869 | |
1870 | $fp = fopen($_FILES['file']['tmp_name'], 'rb'); | |
db55cf54 DO |
1871 | if ($fp === FALSE) |
1872 | return buildRedirectURL (__FUNCTION__, 'ERR2'); | |
6cfedb71 DO |
1873 | if (FALSE === commitReplaceFile ($sic['file_id'], $fp)) |
1874 | return buildRedirectURL (__FUNCTION__, 'ERR3'); | |
fd1fb420 | 1875 | |
d3346ce2 DO |
1876 | usePreparedExecuteBlade |
1877 | ( | |
1878 | 'UPDATE File SET thumbnail = NULL WHERE id = ?', | |
1879 | $sic['file_id'] | |
1880 | ); | |
1881 | ||
db55cf54 | 1882 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name']))); |
fd1fb420 AD |
1883 | } |
1884 | ||
b6a7d936 | 1885 | $msgcode['updateFile']['OK'] = 70; |
6cfedb71 | 1886 | $msgcode['updateFile']['ERR'] = 109; |
e1ae3fb4 AD |
1887 | function updateFile () |
1888 | { | |
0cc24e9a DY |
1889 | assertStringArg ('file_name'); |
1890 | assertStringArg ('file_type'); | |
1891 | assertStringArg ('file_comment', TRUE); | |
f3d274bf | 1892 | global $sic; |
6cfedb71 DO |
1893 | if (FALSE === commitUpdateFile ($sic['file_id'], $sic['file_name'], $sic['file_type'], $sic['file_comment'])) |
1894 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
7221c918 | 1895 | return buildRedirectURL (__FUNCTION__, 'OK', array ($_REQUEST['file_name'])); |
e1ae3fb4 AD |
1896 | } |
1897 | ||
b6a7d936 | 1898 | $msgcode['unlinkFile']['OK'] = 72; |
00e93d63 | 1899 | $msgcode['unlinkFile']['ERR'] = 111; |
e1ae3fb4 AD |
1900 | function unlinkFile () |
1901 | { | |
0cc24e9a | 1902 | assertUIntArg ('link_id'); |
00e93d63 | 1903 | return buildRedirectURL (__FUNCTION__, commitUnlinkFile ($_REQUEST['link_id']) === FALSE ? 'ERR' : 'OK'); |
e1ae3fb4 AD |
1904 | } |
1905 | ||
00e93d63 | 1906 | $msgcode['deleteFile']['OK'] = 6; |
1d84140d | 1907 | $msgcode['deleteFile']['ERR'] = 111; |
e1ae3fb4 AD |
1908 | function deleteFile () |
1909 | { | |
0cc24e9a | 1910 | assertUIntArg ('file_id'); |
d3b5008b | 1911 | $shortInfo = spotEntity ('file', $_REQUEST['file_id']); |
e1ae3fb4 AD |
1912 | $error = commitDeleteFile ($_REQUEST['file_id']); |
1913 | ||
1914 | if ($error != '') | |
135080d8 | 1915 | return buildRedirectURL (__FUNCTION__, 'ERR', array ($error)); |
e1ae3fb4 | 1916 | |
f8874cdb | 1917 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name']))); |
e1ae3fb4 AD |
1918 | } |
1919 | ||
00e93d63 | 1920 | $msgcode['updateFileText']['OK'] = 7; |
b6a7d936 | 1921 | $msgcode['updateFileText']['ERR1'] = 179; |
00e93d63 | 1922 | $msgcode['updateFileText']['ERR2'] = 155; |
8628ae44 DO |
1923 | function updateFileText () |
1924 | { | |
0cc24e9a DY |
1925 | assertStringArg ('mtime_copy'); |
1926 | assertStringArg ('file_text', TRUE); // it's Ok to save empty | |
d3b5008b | 1927 | $shortInfo = spotEntity ('file', $_REQUEST['file_id']); |
70cb9b56 DO |
1928 | if ($shortInfo['mtime'] != $_REQUEST['mtime_copy']) |
1929 | return buildRedirectURL (__FUNCTION__, 'ERR1'); | |
f8874cdb | 1930 | global $sic; |
6cfedb71 DO |
1931 | if (FALSE === commitReplaceFile ($sic['file_id'], $sic['file_text'])) |
1932 | return buildRedirectURL (__FUNCTION__, 'ERR2'); | |
1933 | return buildRedirectURL (__FUNCTION__, 'OK', array (htmlspecialchars ($shortInfo['name']))); | |
8628ae44 DO |
1934 | } |
1935 | ||
2dfa1b73 DO |
1936 | $msgcode['addPortInterfaceCompat']['OK'] = 48; |
1937 | $msgcode['addPortInterfaceCompat']['ERR'] = 110; | |
1938 | function addPortInterfaceCompat () | |
1939 | { | |
0cc24e9a DY |
1940 | assertUIntArg ('iif_id'); |
1941 | assertUIntArg ('oif_id'); | |
2dfa1b73 DO |
1942 | if (commitSupplementPIC ($_REQUEST['iif_id'], $_REQUEST['oif_id'])) |
1943 | return buildRedirectURL (__FUNCTION__, 'OK'); | |
1944 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
1945 | } | |
1946 | ||
2400d7ec DO |
1947 | $ifcompatpack = array |
1948 | ( | |
1949 | '1000cwdm80' => array (1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216), | |
1950 | '1000dwdm80' => array // ITU channels 20~61 | |
1951 | ( | |
1952 | 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225, 1226, | |
1953 | 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, | |
1954 | 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, | |
1955 | 1247, 1248, 1249, 1250, 1251, 1252, 1253, 1254, 1255, 1256, | |
1956 | 1257, 1258 | |
1957 | ), | |
1958 | '10000dwdm80' => array // same channels for 10GE | |
1959 | ( | |
1960 | 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, 1267, 1268, | |
1961 | 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, | |
1962 | 1279, 1280, 1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, | |
1963 | 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, | |
1964 | 1299, 1300 | |
1965 | ), | |
1966 | ); | |
1967 | ||
3d9ac3d4 | 1968 | $msgcode['addPortInterfaceCompatPack']['OK'] = 44; |
2400d7ec DO |
1969 | function addPortInterfaceCompatPack () |
1970 | { | |
00e93d63 DO |
1971 | genericAssertion ('standard', 'enum/wdmstd'); |
1972 | genericAssertion ('iif_id', 'iif'); | |
3d9ac3d4 | 1973 | global $ifcompatpack; |
3d9ac3d4 DO |
1974 | $ngood = $nbad = 0; |
1975 | foreach ($ifcompatpack[$_REQUEST['standard']] as $oif_id) | |
1976 | if (commitSupplementPIC ($_REQUEST['iif_id'], $oif_id)) | |
1977 | $ngood++; | |
1978 | else | |
1979 | $nbad++; | |
1980 | return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood)); | |
2400d7ec DO |
1981 | } |
1982 | ||
3d9ac3d4 DO |
1983 | $msgcode['delPortInterfaceCompatPack']['OK'] = 44; |
1984 | $msgcode['delPortInterfaceCompatPack']['ERR'] = 123; | |
2400d7ec DO |
1985 | function delPortInterfaceCompatPack () |
1986 | { | |
0cc24e9a DY |
1987 | assertStringArg ('standard'); |
1988 | assertUIntArg ('iif_id'); | |
10005279 DO |
1989 | global $ifcompatpack, $sic; |
1990 | if (!array_key_exists ($sic['standard'], $ifcompatpack) or !array_key_exists ($sic['iif_id'], getPortIIFOptions())) | |
3d9ac3d4 DO |
1991 | return buildRedirectURL (__FUNCTION__, 'ERR'); |
1992 | $ngood = $nbad = 0; | |
10005279 DO |
1993 | foreach ($ifcompatpack[$sic['standard']] as $oif_id) |
1994 | if (usePreparedDeleteBlade ('PortInterfaceCompat', array ('iif_id' => $sic['iif_id'], 'oif_id' => $oif_id))) | |
3d9ac3d4 DO |
1995 | $ngood++; |
1996 | else | |
1997 | $nbad++; | |
1998 | return buildRedirectURL (__FUNCTION__, 'OK', array ($nbad, $ngood)); | |
2400d7ec DO |
1999 | } |
2000 | ||
38cd7704 | 2001 | $msgcode['add8021QOrder']['OK'] = 48; |
00e93d63 | 2002 | $msgcode['add8021QOrder']['ERR'] = 110; |
38cd7704 | 2003 | function add8021QOrder () |
8198f2c6 | 2004 | { |
80ec1f4f DO |
2005 | assertUIntArg ('vdom_id'); |
2006 | assertUIntArg ('object_id'); | |
38cd7704 | 2007 | assertUIntArg ('vst_id'); |
c1aa3ada DO |
2008 | global $sic; |
2009 | $result = usePreparedExecuteBlade | |
8198f2c6 | 2010 | ( |
c1aa3ada DO |
2011 | 'INSERT INTO VLANSwitch (domain_id, object_id, template_id, last_change, out_of_sync) ' . |
2012 | 'VALUES (?, ?, ?, NOW(), "yes")', | |
2013 | array ($sic['vdom_id'], $sic['object_id'], $sic['vst_id']) | |
8198f2c6 | 2014 | ); |
c1aa3ada | 2015 | return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR'); |
8198f2c6 DO |
2016 | } |
2017 | ||
38cd7704 | 2018 | $msgcode['del8021QOrder']['OK'] = 49; |
00e93d63 | 2019 | $msgcode['del8021QOrder']['ERR'] = 111; |
38cd7704 | 2020 | function del8021QOrder () |
8198f2c6 | 2021 | { |
80ec1f4f | 2022 | assertUIntArg ('object_id'); |
4191d7ab AA |
2023 | assertUIntArg ('vdom_id'); |
2024 | assertUIntArg ('vst_id'); | |
8198f2c6 | 2025 | global $sic; |
38cd7704 | 2026 | $result = usePreparedDeleteBlade ('VLANSwitch', array ('object_id' => $sic['object_id'])); |
4191d7ab AA |
2027 | $focus_hints = array |
2028 | ( | |
2029 | 'prev_objid' => $_REQUEST['object_id'], | |
2030 | 'prev_vstid' => $_REQUEST['vst_id'], | |
2031 | 'prev_vdid' => $_REQUEST['vdom_id'], | |
2032 | ); | |
2033 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR', array(), NULL, NULL, $focus_hints); | |
8198f2c6 DO |
2034 | } |
2035 | ||
8198f2c6 | 2036 | $msgcode['delVLANDescription']['OK'] = 49; |
c48f2e18 DO |
2037 | $msgcode['delVLANDescription']['ERR1'] = 105; |
2038 | $msgcode['delVLANDescription']['ERR2'] = 111; | |
8198f2c6 DO |
2039 | function delVLANDescription () |
2040 | { | |
80ec1f4f | 2041 | assertUIntArg ('vlan_id'); |
8198f2c6 | 2042 | global $sic; |
c48f2e18 | 2043 | if ($sic['vlan_id'] == VLAN_DFL_ID) |
048b0420 | 2044 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
8198f2c6 | 2045 | $result = commitReduceVLANDescription ($sic['vdom_id'], $sic['vlan_id']); |
c48f2e18 | 2046 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR2'); |
8198f2c6 DO |
2047 | } |
2048 | ||
2049 | $msgcode['updVLANDescription']['OK'] = 51; | |
c48f2e18 DO |
2050 | $msgcode['updVLANDescription']['ERR1'] = 105; |
2051 | $msgcode['updVLANDescription']['ERR2'] = 109; | |
8198f2c6 DO |
2052 | function updVLANDescription () |
2053 | { | |
80ec1f4f DO |
2054 | assertUIntArg ('vlan_id'); |
2055 | assertStringArg ('vlan_type'); | |
2056 | assertStringArg ('vlan_descr', TRUE); | |
8198f2c6 | 2057 | global $sic; |
c48f2e18 | 2058 | if ($sic['vlan_id'] == VLAN_DFL_ID) |
048b0420 | 2059 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
8198f2c6 DO |
2060 | $result = commitUpdateVLANDescription |
2061 | ( | |
2062 | $sic['vdom_id'], | |
2063 | $sic['vlan_id'], | |
0dabdc53 | 2064 | $sic['vlan_type'], |
8198f2c6 DO |
2065 | $sic['vlan_descr'] |
2066 | ); | |
6cfedb71 | 2067 | return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR2'); |
8198f2c6 DO |
2068 | } |
2069 | ||
2070 | $msgcode['createVLANDomain']['OK'] = 48; | |
2071 | $msgcode['createVLANDomain']['ERR'] = 110; | |
2072 | function createVLANDomain () | |
2073 | { | |
80ec1f4f | 2074 | assertStringArg ('vdom_descr'); |
8198f2c6 DO |
2075 | global $sic; |
2076 | $result = usePreparedInsertBlade | |
2077 | ( | |
2078 | 'VLANDomain', | |
2079 | array | |
2080 | ( | |
2081 | 'description' => $sic['vdom_descr'], | |
2082 | ) | |
2083 | ); | |
10c7f49e DO |
2084 | $result = $result and usePreparedInsertBlade |
2085 | ( | |
2086 | 'VLANDescription', | |
2087 | array | |
2088 | ( | |
2089 | 'domain_id' => lastInsertID(), | |
2090 | 'vlan_id' => VLAN_DFL_ID, | |
2091 | 'vlan_type' => 'compulsory', | |
c48f2e18 | 2092 | 'vlan_descr' => 'default', |
10c7f49e DO |
2093 | ) |
2094 | ); | |
8198f2c6 DO |
2095 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); |
2096 | } | |
2097 | ||
2098 | $msgcode['destroyVLANDomain']['OK'] = 49; | |
2099 | $msgcode['destroyVLANDomain']['ERR'] = 111; | |
2100 | function destroyVLANDomain () | |
2101 | { | |
80ec1f4f | 2102 | assertUIntArg ('vdom_id'); |
8198f2c6 | 2103 | global $sic; |
bbae3611 | 2104 | $result = FALSE !== usePreparedDeleteBlade ('VLANDomain', array ('id' => $sic['vdom_id'])); |
8198f2c6 DO |
2105 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); |
2106 | } | |
2107 | ||
2108 | $msgcode['updateVLANDomain']['OK'] = 51; | |
2109 | $msgcode['updateVLANDomain']['ERR'] = 109; | |
2110 | function updateVLANDomain () | |
2111 | { | |
80ec1f4f DO |
2112 | assertUIntArg ('vdom_id'); |
2113 | assertStringArg ('vdom_descr'); | |
8198f2c6 | 2114 | global $sic; |
d3192636 | 2115 | $result = FALSE !== commitUpdateVLANDomain ($sic['vdom_id'], $sic['vdom_descr']); |
8198f2c6 DO |
2116 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); |
2117 | } | |
2118 | ||
4492050b DO |
2119 | $msgcode['save8021QPorts']['OK1'] = 63; |
2120 | $msgcode['save8021QPorts']['OK2'] = 41; | |
706d9175 DO |
2121 | $msgcode['save8021QPorts']['ERR2'] = 109; |
2122 | function save8021QPorts () | |
8198f2c6 | 2123 | { |
a7492e95 | 2124 | global $sic, $dbxlink; |
70cff23f | 2125 | assertUIntArg ('mutex_rev', TRUE); // counts from 0 |
de8aa722 DO |
2126 | assertStringArg ('form_mode'); |
2127 | if ($sic['form_mode'] != 'save' and $sic['form_mode'] != 'duplicate') | |
2128 | throw new InvalidRequestArgException ('form_mode', $sic['form_mode']); | |
2129 | $extra = array(); | |
a7492e95 | 2130 | $dbxlink->beginTransaction(); |
2996cbbb DO |
2131 | try |
2132 | { | |
a7492e95 DO |
2133 | if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE')) |
2134 | throw new InvalidArgException ('object_id', $object_id, 'VLAN domain is not set for this object'); | |
9c45ea37 | 2135 | if ($vswitch['mutex_rev'] != $sic['mutex_rev']) |
1a43ce88 | 2136 | throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form data'); |
de8aa722 | 2137 | $after = $before = apply8021QOrder ($vswitch['template_id'], getStored8021QConfig ($sic['object_id'], 'desired')); |
af204724 | 2138 | $changes = array(); |
de8aa722 | 2139 | switch ($sic['form_mode']) |
706d9175 | 2140 | { |
de8aa722 DO |
2141 | case 'save': |
2142 | assertUIntArg ('nports'); | |
2143 | if ($sic['nports'] == 1) | |
706d9175 | 2144 | { |
de8aa722 DO |
2145 | assertStringArg ('pn_0'); |
2146 | $extra = array ('port_name' => $sic['pn_0']); | |
2147 | } | |
2148 | for ($i = 0; $i < $sic['nports']; $i++) | |
2149 | { | |
2150 | assertStringArg ('pn_' . $i); | |
2151 | assertStringArg ('pm_' . $i); | |
2152 | // An access port only generates form input for its native VLAN, | |
2153 | // which we derive allowed VLAN list from. | |
2154 | $native = isset ($sic['pnv_' . $i]) ? $sic['pnv_' . $i] : 0; | |
2155 | switch ($sic["pm_${i}"]) | |
2156 | { | |
2157 | case 'trunk': | |
b36fc896 | 2158 | # assertArrayArg ('pav_' . $i); |
de8aa722 DO |
2159 | $allowed = isset ($sic['pav_' . $i]) ? $sic['pav_' . $i] : array(); |
2160 | break; | |
2161 | case 'access': | |
2162 | if ($native == 'same') | |
2163 | continue 2; | |
2164 | assertUIntArg ('pnv_' . $i); | |
2165 | $allowed = array ($native); | |
2166 | break; | |
2167 | default: | |
2168 | throw new InvalidRequestArgException ("pm_${i}", $_REQUEST["pm_${i}"], 'unknown port mode'); | |
2169 | } | |
2170 | $changes[$sic['pn_' . $i]] = array | |
2171 | ( | |
2172 | 'mode' => $sic['pm_' . $i], | |
2173 | 'allowed' => $allowed, | |
2174 | 'native' => $native, | |
2175 | ); | |
706d9175 | 2176 | } |
de8aa722 DO |
2177 | break; |
2178 | case 'duplicate': | |
2179 | assertStringArg ('from_port'); | |
2180 | # assertArrayArg ('to_ports'); | |
2181 | if (!array_key_exists ($sic['from_port'], $before)) | |
2182 | throw new InvalidArgException ('from_port', $sic['from_port'], 'this port does not exist'); | |
2183 | foreach ($sic['to_ports'] as $tpn) | |
2184 | if (!array_key_exists ($tpn, $before)) | |
2185 | throw new InvalidArgException ('to_ports[]', $tpn, 'this port does not exist'); | |
2186 | elseif ($tpn != $sic['from_port']) | |
2187 | $changes[$tpn] = $before[$sic['from_port']]; | |
2188 | break; | |
706d9175 | 2189 | } |
af204724 DO |
2190 | $domain_vlanlist = getDomainVLANs ($vswitch['domain_id']); |
2191 | $changes = filter8021QChangeRequests | |
a7492e95 | 2192 | ( |
af204724 | 2193 | $domain_vlanlist, |
9165e8f7 | 2194 | $before, |
af204724 | 2195 | apply8021QOrder ($vswitch['template_id'], $changes) |
a7492e95 | 2196 | ); |
bb2024b9 | 2197 | $changes = authorize8021QChangeRequests ($before, $changes); |
af204724 DO |
2198 | foreach ($changes as $port_name => $port) |
2199 | $after[$port_name] = $port; | |
b3a27170 | 2200 | $new_uplinks = filter8021QChangeRequests ($domain_vlanlist, $after, produceUplinkPorts ($domain_vlanlist, $after)); |
7455e4c0 | 2201 | $npulled = replace8021QPorts ('desired', $vswitch['object_id'], $before, $changes); |
b3a27170 | 2202 | $nsaved_uplinks = replace8021QPorts ('desired', $vswitch['object_id'], $before, $new_uplinks); |
2996cbbb DO |
2203 | } |
2204 | catch (Exception $e) | |
861292ee | 2205 | { |
a7492e95 | 2206 | $dbxlink->rollBack(); |
706d9175 | 2207 | return buildRedirectURL (__FUNCTION__, 'ERR2', array(), NULL, NULL, $extra); |
861292ee | 2208 | } |
b3a27170 | 2209 | if ($npulled + $nsaved_uplinks) |
c1aa3ada DO |
2210 | $result = usePreparedExecuteBlade |
2211 | ( | |
2212 | 'UPDATE VLANSwitch SET mutex_rev=mutex_rev+1, last_change=NOW(), out_of_sync="yes" WHERE object_id=?', | |
2213 | array ($sic['object_id']) | |
2214 | ); | |
a7492e95 | 2215 | $dbxlink->commit(); |
4492050b | 2216 | $log = oneLiner (63, array ($npulled + $nsaved_uplinks)); |
b3a27170 | 2217 | if ($nsaved_uplinks) |
4492050b | 2218 | { |
b3a27170 | 2219 | initiateUplinksReverb ($vswitch['object_id'], $new_uplinks); |
4492050b DO |
2220 | $log = mergeLogs ($log, oneLiner (41)); |
2221 | } | |
2222 | if ($npulled + $nsaved_uplinks > 0 and getConfigVar ('8021Q_INSTANT_DEPLOY') == 'yes') | |
2223 | { | |
2224 | try | |
2225 | { | |
2226 | if (FALSE === $done = exec8021QDeploy ($sic['object_id'], TRUE)) | |
2227 | $log = mergeLogs ($log, oneLiner (191)); | |
2228 | else | |
2229 | $log = mergeLogs ($log, oneLiner (63, array ($done))); | |
2230 | } | |
2231 | catch (Exception $e) | |
2232 | { | |
2233 | $log = mergeLogs ($log, oneLiner (109)); | |
2234 | } | |
2235 | } | |
2236 | return buildWideRedirectURL ($log, NULL, NULL, $extra); | |
8198f2c6 DO |
2237 | } |
2238 | ||
8846b060 DO |
2239 | $msgcode['bindVLANtoIPv4']['OK'] = 48; |
2240 | $msgcode['bindVLANtoIPv4']['ERR'] = 110; | |
2241 | function bindVLANtoIPv4 () | |
2242 | { | |
2243 | assertUIntArg ('id'); // network id | |
2244 | global $sic; | |
2245 | $result = commitSupplementVLANIPv4 ($sic['vlan_ck'], $sic['id']); | |
2246 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2247 | } | |
2248 | ||
21ee3351 AA |
2249 | $msgcode['bindVLANtoIPv6']['OK'] = 48; |
2250 | $msgcode['bindVLANtoIPv6']['ERR'] = 110; | |
2251 | function bindVLANtoIPv6 () | |
2252 | { | |
2253 | assertUIntArg ('id'); // network id | |
2254 | global $sic; | |
2255 | $result = commitSupplementVLANIPv6 ($sic['vlan_ck'], $_REQUEST['id']); | |
2256 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2257 | } | |
2258 | ||
8846b060 DO |
2259 | $msgcode['unbindVLANfromIPv4']['OK'] = 49; |
2260 | $msgcode['unbindVLANfromIPv4']['ERR'] = 111; | |
2261 | function unbindVLANfromIPv4 () | |
2262 | { | |
2263 | assertUIntArg ('id'); // network id | |
2264 | global $sic; | |
2265 | $result = commitReduceVLANIPv4 ($sic['vlan_ck'], $sic['id']); | |
2266 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2267 | } | |
2268 | ||
21ee3351 AA |
2269 | $msgcode['unbindVLANfromIPv6']['OK'] = 49; |
2270 | $msgcode['unbindVLANfromIPv6']['ERR'] = 111; | |
2271 | function unbindVLANfromIPv6 () | |
2272 | { | |
2273 | assertUIntArg ('id'); // network id | |
2274 | global $sic; | |
2275 | $result = commitReduceVLANIPv6 ($sic['vlan_ck'], $sic['id']); | |
2276 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2277 | } | |
2278 | ||
228c430c | 2279 | $msgcode['process8021QSyncRequest']['OK'] = 63; |
ec523868 | 2280 | $msgcode['process8021QSyncRequest']['ERR'] = 191; |
228c430c | 2281 | function process8021QSyncRequest () |
be28b696 | 2282 | { |
2e84a05b DO |
2283 | // behave depending on current operation: exec8021QPull or exec8021QPush |
2284 | global $sic, $op; | |
ec523868 DO |
2285 | if (FALSE === $done = exec8021QDeploy ($sic['object_id'], $op == 'exec8021QPush')) |
2286 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
2287 | return buildRedirectURL (__FUNCTION__, 'OK', array ($done)); | |
be28b696 DO |
2288 | } |
2289 | ||
f9428bc6 AA |
2290 | $msgcode['process8021QRecalcRequest']['CHANGED'] = 87; |
2291 | $msgcode['process8021QRecalcRequest']['NO_CHANGES'] = 300; | |
00e93d63 | 2292 | $msgcode['process8021QRecalcRequest']['ERR'] = 157; |
f9428bc6 AA |
2293 | function process8021QRecalcRequest () |
2294 | { | |
f9428bc6 | 2295 | global $sic; |
fb3e3731 AA |
2296 | if (! permitted (NULL, NULL, NULL, array (array ('tag' => '$op_recalc8021Q')))) |
2297 | return buildRedirectURL (__FUNCTION__, 'ERR'); | |
f9428bc6 AA |
2298 | $counters = recalc8021QPorts ($sic['object_id']); |
2299 | if ($counters['ports']) | |
2300 | return buildRedirectURL (__FUNCTION__, 'CHANGED', array ($counters['ports'], $counters['switches'])); | |
2301 | else | |
2302 | return buildRedirectURL (__FUNCTION__, 'NO_CHANGES', array ('No changes were made')); | |
2303 | } | |
2304 | ||
be28b696 | 2305 | $msgcode['resolve8021QConflicts']['OK'] = 63; |
bcd14540 DO |
2306 | $msgcode['resolve8021QConflicts']['ERR1'] = 179; |
2307 | $msgcode['resolve8021QConflicts']['ERR2'] = 109; | |
be28b696 | 2308 | function resolve8021QConflicts () |
07de6bb3 | 2309 | { |
a7492e95 | 2310 | global $sic, $dbxlink; |
70cff23f | 2311 | assertUIntArg ('mutex_rev', TRUE); // counts from 0 |
de47b574 DO |
2312 | assertUIntArg ('nrows'); |
2313 | // Divide submitted radio buttons into 3 groups: | |
19d1e731 | 2314 | // left (saved version wins) |
07de6bb3 | 2315 | // asis (ignore) |
19d1e731 DO |
2316 | // right (running version wins) |
2317 | $F = array(); | |
339534a0 | 2318 | for ($i = 0; $i < $sic['nrows']; $i++) |
07de6bb3 | 2319 | { |
de47b574 | 2320 | if (!array_key_exists ("i_${i}", $sic)) |
07de6bb3 | 2321 | continue; |
de47b574 DO |
2322 | // let's hope other inputs are in place |
2323 | switch ($sic["i_${i}"]) | |
07de6bb3 DO |
2324 | { |
2325 | case 'left': | |
07de6bb3 | 2326 | case 'right': |
bcd14540 | 2327 | $F[$sic["pn_${i}"]] = array |
07de6bb3 | 2328 | ( |
ca9e1c9d | 2329 | 'mode' => $sic["rm_${i}"], |
de47b574 DO |
2330 | 'allowed' => $sic["ra_${i}"], |
2331 | 'native' => $sic["rn_${i}"], | |
bcd14540 | 2332 | 'decision' => $sic["i_${i}"], |
07de6bb3 DO |
2333 | ); |
2334 | break; | |
2335 | default: | |
2336 | // don't care | |
2337 | } | |
2338 | } | |
a7492e95 | 2339 | $dbxlink->beginTransaction(); |
07de6bb3 DO |
2340 | try |
2341 | { | |
a7492e95 | 2342 | if (NULL === $vswitch = getVLANSwitchInfo ($sic['object_id'], 'FOR UPDATE')) |
ec4d604c | 2343 | throw new InvalidArgException ('object_id', $sic['object_id'], 'VLAN domain is not set for this object'); |
9c45ea37 | 2344 | if ($vswitch['mutex_rev'] != $sic['mutex_rev']) |
1a43ce88 | 2345 | throw new InvalidRequestArgException ('mutex_rev', $sic['mutex_rev'], 'expired form (table data has changed)'); |
9c2201ba DO |
2346 | $D = getStored8021QConfig ($vswitch['object_id'], 'desired'); |
2347 | $C = getStored8021QConfig ($vswitch['object_id'], 'cached'); | |
2348 | $R = getRunning8021QConfig ($vswitch['object_id']); | |
d5e306b2 | 2349 | $plan = get8021QSyncOptions ($vswitch, $D, $C, $R['portdata']); |
bcd14540 DO |
2350 | $ndone = 0; |
2351 | foreach ($F as $port_name => $port) | |
2352 | { | |
9c2201ba DO |
2353 | if (!array_key_exists ($port_name, $plan)) |
2354 | continue; | |
2355 | elseif ($plan[$port_name]['status'] == 'merge_conflict') | |
bcd14540 | 2356 | { |
9c2201ba DO |
2357 | // for R neither mutex nor revisions can be emulated, but revision change can be |
2358 | if (!same8021QConfigs ($port, $R['portdata'][$port_name])) | |
1a43ce88 | 2359 | throw new InvalidRequestArgException ("port ${port_name}", '(hidden)', 'expired form (switch data has changed)'); |
1f8f67c2 | 2360 | if ($port['decision'] == 'right') // D wins, frame R by writing value of R to C |
9c2201ba | 2361 | $ndone += upd8021QPort ('cached', $vswitch['object_id'], $port_name, $port); |
1f8f67c2 | 2362 | elseif ($port['decision'] == 'left') // R wins, cross D up |
9c2201ba DO |
2363 | $ndone += upd8021QPort ('cached', $vswitch['object_id'], $port_name, $D[$port_name]); |
2364 | // otherwise there was no decision made | |
2365 | } | |
1f8f67c2 DO |
2366 | elseif |
2367 | ( | |
2368 | $plan[$port_name]['status'] == 'delete_conflict' or | |
2369 | $plan[$port_name]['status'] == 'martian_conflict' | |
2370 | ) | |
9c2201ba | 2371 | { |
1f8f67c2 | 2372 | if ($port['decision'] == 'left') // confirm deletion of local copy |
9c2201ba | 2373 | $ndone += del8021QPort ($vswitch['object_id'], $port_name); |
bcd14540 | 2374 | } |
9c2201ba | 2375 | // otherwise ignore a decision, which doesn't address a conflict |
bcd14540 | 2376 | } |
07de6bb3 | 2377 | } |
1a43ce88 | 2378 | catch (InvalidRequestArgException $e) |
07de6bb3 | 2379 | { |
a7492e95 | 2380 | $dbxlink->rollBack(); |
bcd14540 | 2381 | return buildRedirectURL (__FUNCTION__, 'ERR1'); |
ec4d604c | 2382 | } |
bcd14540 | 2383 | catch (Exception $e) |
ec4d604c | 2384 | { |
bcd14540 DO |
2385 | $dbxlink->rollBack(); |
2386 | return buildRedirectURL (__FUNCTION__, 'ERR2'); | |
ec4d604c | 2387 | } |
a7492e95 | 2388 | $dbxlink->commit(); |
bcd14540 | 2389 | return buildRedirectURL (__FUNCTION__, 'OK', array ($ndone)); |
07de6bb3 DO |
2390 | } |
2391 | ||
e0d188ef DO |
2392 | $msgcode['addVLANSwitchTemplate']['OK'] = 48; |
2393 | $msgcode['addVLANSwitchTemplate']['ERR'] = 110; | |
2394 | function addVLANSwitchTemplate() | |
2395 | { | |
2396 | assertStringArg ('vst_descr'); | |
2397 | global $sic; | |
2398 | $max_local_vlans = NULL; | |
2399 | if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans'])) | |
2400 | { | |
2401 | assertUIntArg ('vst_maxvlans'); | |
2402 | $max_local_vlans = $sic['vst_maxvlans']; | |
2403 | } | |
2404 | $result = usePreparedInsertBlade | |
2405 | ( | |
2406 | 'VLANSwitchTemplate', | |
2407 | array | |
2408 | ( | |
2409 | 'max_local_vlans' => $max_local_vlans, | |
2410 | 'description' => $sic['vst_descr'], | |
2411 | ) | |
2412 | ); | |
2413 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2414 | } | |
2415 | ||
2416 | $msgcode['delVLANSwitchTemplate']['OK'] = 49; | |
2417 | $msgcode['delVLANSwitchTemplate']['ERR'] = 111; | |
2418 | function delVLANSwitchTemplate() | |
2419 | { | |
2420 | assertUIntArg ('vst_id'); | |
2421 | global $sic; | |
2422 | $result = FALSE !== usePreparedDeleteBlade ('VLANSwitchTemplate', array ('id' => $sic['vst_id'])); | |
2423 | return buildRedirectURL (__FUNCTION__, $result ? 'OK' : 'ERR'); | |
2424 | } | |
2425 | ||
2426 | $msgcode['updVLANSwitchTemplate']['OK'] = 51; | |
2427 | $msgcode['updVLANSwitchTemplate']['ERR'] = 109; | |
2428 | function updVLANSwitchTemplate() | |
2429 | { | |
2430 | assertUIntArg ('vst_id'); | |
2431 | assertStringArg ('vst_descr'); | |
2432 | global $sic; | |
2433 | $max_local_vlans = NULL; | |
2434 | if (array_key_exists ('vst_maxvlans', $sic) && mb_strlen ($sic['vst_maxvlans'])) | |
2435 | { | |
2436 | assertUIntArg ('vst_maxvlans'); | |
2437 | $max_local_vlans = $sic['vst_maxvlans']; | |
2438 | } | |
2439 | $result = commitUpdateVST ($sic['vst_id'], $max_local_vlans, $sic['vst_descr']); | |
6cfedb71 | 2440 | return buildRedirectURL (__FUNCTION__, $result !== FALSE ? 'OK' : 'ERR'); |
e0d188ef DO |
2441 | } |
2442 | ||
09ec2e59 AA |
2443 | $msgcode['cloneVSTRule']['OK'] = 48; |
2444 | $msgcode['cloneVSTRule']['ERR'] = 179; | |
2445 | function cloneVSTRule() | |
e0d188ef | 2446 | { |
09ec2e59 AA |
2447 | global $dbxlink; |
2448 | $message = ''; | |
09ec2e59 AA |
2449 | assertUIntArg ('mutex_rev', TRUE); |
2450 | $dst_vst = getVLANSwitchTemplate ($_REQUEST['vst_id']); | |
2451 | if ($dst_vst['mutex_rev'] != $_REQUEST['mutex_rev']) | |
2452 | $message = "User ${dst_vst['saved_by']} saved this template after you started to edit it. Please concern differencies"; | |
2453 | else | |
eb51ceff | 2454 | { |
eb51ceff DO |
2455 | assertUIntArg ('from_id'); |
2456 | $src_vst = getVLANSwitchTemplate ($_REQUEST['from_id']); | |
09ec2e59 AA |
2457 | if (! commitUpdateVSTRules ($_REQUEST['vst_id'], $src_vst['rules'])) |
2458 | $message = 'DB error'; | |
eb51ceff | 2459 | } |
09ec2e59 AA |
2460 | $result = !(BOOL) $message; |
2461 | if ($result) | |
2462 | $message = 'Supplement succeeded'; | |
2463 | return buildWideRedirectURL (array (array ('code' => $result ? 'success' : 'error', 'message' => $message))); | |
e0d188ef DO |
2464 | } |
2465 | ||
405ac32c | 2466 | $msgcode['updVSTRule']['OK'] = 43; |
e0d188ef DO |
2467 | function updVSTRule() |
2468 | { | |
405ac32c | 2469 | global $port_role_options, $sic; |
09ec2e59 | 2470 | assertUIntArg ('mutex_rev', TRUE); |
405ac32c DO |
2471 | genericAssertion ('template_json', 'json'); |
2472 | $data = json_decode ($sic['template_json'], TRUE); | |
2473 | $rule_no = 0; | |
2474 | try | |
09ec2e59 | 2475 | { |
09ec2e59 AA |
2476 | foreach ($data as $rule) |
2477 | { | |
2478 | $rule_no++; | |
405ac32c DO |
2479 | if |
2480 | ( | |
2481 | ! isInteger ($rule['rule_no']) | |
2482 | or ! isPCRE ($rule['port_pcre']) | |
2483 | or ! isset ($rule['port_role']) | |
2484 | or ! array_key_exists ($rule['port_role'], $port_role_options) | |
2485 | or ! isset ($rule['wrt_vlans']) | |
2486 | or ! preg_match ('/^[ 0-9\-,]*$/', $rule['wrt_vlans']) | |
2487 | or ! isset ($rule['description']) | |
2488 | ) | |
2489 | throw new InvalidRequestArgException ('form', '(JSON)', "invalid rule #$rule_no"); | |
09ec2e59 | 2490 | } |
405ac32c | 2491 | commitUpdateVSTRules ($_REQUEST['vst_id'], $_REQUEST['mutex_rev'], $data); |
09ec2e59 | 2492 | } |
405ac32c | 2493 | catch (Exception $e) |
09ec2e59 | 2494 | { |
405ac32c DO |
2495 | // Every case, which is soft-processed in process.php, will have the working copy available for a retry. |
2496 | if ($e instanceof InvalidRequestArgException or $e instanceof RTDatabaseError) | |
2497 | $_SESSION['vst_edited'] = $data; | |
2498 | throw $e; | |
09ec2e59 | 2499 | } |
405ac32c | 2500 | return buildRedirectURL (__FUNCTION__, 'OK'); |
e0d188ef DO |
2501 | } |
2502 | ||
5b5b1cab DO |
2503 | $msgcode['importDPData']['OK'] = 44; |
2504 | function importDPData() | |
b3247480 DO |
2505 | { |
2506 | global $sic; | |
2507 | assertUIntArg ('nports'); | |
2508 | $nignored = $ndone = 0; | |
1dc057f8 | 2509 | $POIFC = getPortOIFCompat(); |
b3247480 DO |
2510 | for ($i = 0; $i < $sic['nports']; $i++) |
2511 | if (array_key_exists ("do_${i}", $sic)) | |
2512 | { | |
2513 | assertUIntArg ("pid1_${i}"); | |
2514 | assertUIntArg ("pid2_${i}"); | |
2515 | $porta = getPortInfo ($_REQUEST["pid1_${i}"]); | |
2516 | $portb = getPortInfo ($_REQUEST["pid2_${i}"]); | |
2517 | if | |
2518 | ( | |
2519 | $porta['linked'] or | |
2520 | $portb['linked'] or | |
2521 | ($porta['object_id'] != $sic['object_id'] and $portb['object_id'] != $sic['object_id']) | |
2522 | ) | |
2523 | { | |
2524 | $nignored++; | |
2525 | continue; | |
2526 | } | |
1dc057f8 DO |
2527 | foreach ($POIFC as $item) |
2528 | if ($item['type1'] == $porta['oif_id'] and $item['type2'] == $portb['oif_id']) | |
2529 | { | |
2530 | linkPorts ($_REQUEST["pid1_${i}"], $_REQUEST["pid2_${i}"]); | |
2531 | $ndone++; | |
524170a8 | 2532 | continue 2; // next port |
1dc057f8 DO |
2533 | } |
2534 | $nignored++; | |
b3247480 DO |
2535 | } |
2536 | return buildRedirectURL (__FUNCTION__, 'OK', array ($nignored, $ndone)); | |
2537 | } | |
2538 | ||
9a90adc4 DO |
2539 | $msgcode['addObjectlog']['OK'] = 0; |
2540 | function addObjectlog () | |
2541 | { | |
9a90adc4 DO |
2542 | assertStringArg ('logentry'); |
2543 | global $remote_username, $sic; | |
2544 | $oi = spotEntity ('object', $sic['object_id']); | |
2545 | usePreparedExecuteBlade ('INSERT INTO ObjectLog SET object_id=?, user=?, date=NOW(), content=?', array ($sic['object_id'], $remote_username, $sic['logentry'])); | |
2546 | $ob_url = makeHref (array ('page' => 'object', 'tab' => 'objectlog', 'object_id' => $sic['object_id'])); | |
2547 | return buildRedirectURL (__FUNCTION__, 'OK', array ("Log entry for <a href=" . ${ob_url} . ">${oi['dname']}</a> added by ${remote_username}")); | |
2548 | } | |
2549 | ||
cde28cf0 DO |
2550 | function tableHandler ($opspec) |
2551 | { | |
2552 | global $sic; | |
2553 | if (!array_key_exists ('table', $opspec)) | |
2554 | throw new InvalidArgException ('opspec', '(malformed array structure)', '"table" not set'); | |
2555 | $columns = array(); | |
2556 | foreach ($opspec['arglist'] as $argspec) | |
2557 | { | |
2558 | genericAssertion ($argspec['url_argname'], $argspec['assertion']); | |
4eba4f82 DO |
2559 | // "table_colname" is normally used for an override, if it is not |
2560 | // set, use the URL argument name | |
2561 | $table_colname = array_key_exists ('table_colname', $argspec) ? | |
2562 | $argspec['table_colname'] : | |
2563 | $argspec['url_argname']; | |
2564 | $arg_value = $sic[$argspec['url_argname']]; | |
2565 | if | |
2566 | ( | |
2567 | ($argspec['assertion'] == 'uint0' and $arg_value == 0) | |
2568 | or ($argspec['assertion'] == 'string0' and $arg_value == '') | |
2569 | ) | |
2570 | switch (TRUE) | |
2571 | { | |
2572 | case !array_key_exists ('if_empty', $argspec): // no action requested | |
2573 | break; | |
2574 | case $argspec['if_empty'] == 'NULL': | |
2575 | $arg_value = NULL; | |
2576 | break; | |
2577 | // A trick below is likely to break non-INSERT queries. | |
2578 | // case $argspec['if_empty'] == 'omit': | |
2579 | // continue 2; | |
2580 | default: | |
2581 | throw new InvalidArgException ('opspec', '(malformed array structure)', '"if_empty" not recognized'); | |
2582 | } | |
2583 | $columns[$table_colname] = $arg_value; | |
cde28cf0 DO |
2584 | } |
2585 | switch ($opspec['action']) | |
2586 | { | |
2587 | case 'INSERT': | |
2588 | $retcode = TRUE === usePreparedInsertBlade ($opspec['table'], $columns) ? 48 : 110; | |
2589 | break; | |
10005279 DO |
2590 | case 'DELETE': |
2591 | $conjunction = array_key_exists ('conjunction', $opspec) ? $opspec['conjunction'] : 'AND'; | |
2592 | $retcode = FALSE !== usePreparedDeleteBlade ($opspec['table'], $columns, $conjunction) ? 49 : 111; | |
2593 | break; | |
cde28cf0 DO |
2594 | default: |
2595 | throw new InvalidArgException ('opspec/action', '(malformed array structure)'); | |
2596 | } | |
2597 | return buildWideRedirectURL (oneLiner ($retcode)); | |
2598 | } | |
2599 | ||
e673ee24 | 2600 | ?> |