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