/
ophandlers.php
3830 lines (3611 loc) · 116 KB
/
ophandlers.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
# This file is a part of RackTables, a datacenter and server room management
# framework. See accompanying file "COPYING" for the full copyright and
# licensing information.
/*
"Ophandler" in RackTables stands for "operation handler", or a function
that handles execution of "operation" (in the meaning explained in
navigation.php). Most of the ophandlers are meant to perform one specific
action, for example, to set a name of an object. Each such action often
requires a set of parameters (e. g. ID of the object and the new name),
and it is responsibility of each ophandler function to verify that all
necessary parameters are provided by the user and have proper values. There
is a number of helper functions to make such verification simpler.
Errors occuring in ophandlers are typically indicated with exceptions of
assorted classes. Namely, an "InvalidRequestArgException" class means that
at least one of the parameters provided by the user is not acceptable. This
is a "soft" error, which gets displayed in the standard message area of
otherwise usual interface. A different case is "InvalidArgException", which
means that one of the internal functions detected its argument(s) invalid
or corrupted, and that argument(s) did not come from user's input (and thus
cannot be fixed without fixing a bug in the code). Such "hard" errors don't
get special early handling and end up in the default catching block. The
latter may print a detailed stack trace instead of the interface HTML to
help a developer debug the issue.
As long as an ophandler makes through its request (extracting arguments,
performing validation and actually updating records in the database), it
may queue up messages (often referred to as "green" and "red" bars) by
means of showError() and showSuccess() functions. The messages are not
displayed immediately, because successfull ophandlers are expected to
return only the new URL, where the user will be immediately redirected to
(it is also possible to return an empty string to mean that the current
logical location remains the same). The page at the "next" location is
supposed to translate message buffer into the standard message area.
A very special case of an ophandler is tableHandler(). This generic
function handles the most trivial actions, which map to a single INSERT,
UPDATE or DELETE SQL statement with a fixed number of arguments. The rules
of argument validation and mapping are listed in $opspec_list (operation
specifications list) array.
*/
// This array is deprecated. Please do not add new message constants to it.
// use the new showError, showWarning, showSuccess functions instead
global $msgcode;
$msgcode = array();
global $opspec_list;
$opspec_list = array();
$opspec_list['object-edit-unlinkObjects'] = array
(
'table' => 'EntityLink',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'link_id', 'table_colname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['object-ports-useup'] = array
(
'table' => 'Port',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('fix_argname' => 'reservation_comment', 'fix_argvalue' => NULL),
),
'where_arglist' => array
(
array ('url_argname' => 'port_id', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('url_argname' => 'object_id', 'assertion' => 'uint'), # preserve context
),
);
$opspec_list['object-ports-delPort'] = array
(
'table' => 'Port',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'port_id', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('url_argname' => 'object_id', 'assertion' => 'uint'),
),
);
$opspec_list['object-ports-deleteAll'] = array
(
'table' => 'Port',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'object_id', 'assertion' => 'uint'),
),
);
$opspec_list['location-log-del'] = array
(
'table' => 'ObjectLog',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'log_id', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('url_argname' => 'location_id', 'table_colname' => 'object_id', 'assertion' => 'uint'),
),
);
$opspec_list['object-log-del'] = array
(
'table' => 'ObjectLog',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'log_id', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('url_argname' => 'object_id', 'assertion' => 'uint'),
),
);
$opspec_list['rack-log-del'] = array
(
'table' => 'ObjectLog',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'log_id', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('url_argname' => 'rack_id', 'table_colname' => 'object_id', 'assertion' => 'uint'),
),
);
$opspec_list['row-log-del'] = array
(
'table' => 'ObjectLog',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'log_id', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('url_argname' => 'row_id', 'table_colname' => 'object_id', 'assertion' => 'uint'),
),
);
$opspec_list['ipv4vs-editlblist-delLB'] =
$opspec_list['ipv4rspool-editlblist-delLB'] =
$opspec_list['object-editrspvs-delLB'] = array
(
'table' => 'IPv4LB',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'object_id', 'assertion' => 'uint'),
array ('url_argname' => 'pool_id', 'table_colname' => 'rspool_id', 'assertion' => 'uint'),
array ('url_argname' => 'vs_id', 'assertion' => 'uint'),
),
);
$opspec_list['ipv4vs-editlblist-updLB'] =
$opspec_list['ipv4rspool-editlblist-updLB'] =
$opspec_list['object-editrspvs-updLB'] = array
(
'table' => 'IPv4LB',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'vsconfig', 'assertion' => 'string0', 'translator' => 'nullIfEmptyStr'),
array ('url_argname' => 'rsconfig', 'assertion' => 'string0', 'translator' => 'nullIfEmptyStr'),
array ('url_argname' => 'prio', 'assertion' => 'string0', 'translator' => 'nullIfEmptyStr'),
),
'where_arglist' => array
(
array ('url_argname' => 'object_id', 'assertion' => 'uint'),
array ('url_argname' => 'pool_id', 'table_colname' => 'rspool_id', 'assertion' => 'uint'),
array ('url_argname' => 'vs_id', 'assertion' => 'uint'),
),
);
$opspec_list['ipv4rspool-editrslist-delRS'] = array
(
'table' => 'IPv4RS',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['parentmap-edit-add'] = array
(
'table' => 'ObjectParentCompat',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'parent_objtype_id', 'assertion' => 'uint'),
array ('url_argname' => 'child_objtype_id', 'assertion' => 'uint'),
),
);
$opspec_list['parentmap-edit-del'] = array
(
'table' => 'ObjectParentCompat',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'parent_objtype_id', 'assertion' => 'uint'),
array ('url_argname' => 'child_objtype_id', 'assertion' => 'uint'),
),
);
$opspec_list['portifcompat-edit-add'] = array
(
'table' => 'PortInterfaceCompat',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'iif_id', 'assertion' => 'uint'),
array ('url_argname' => 'oif_id', 'assertion' => 'uint'),
),
);
$opspec_list['portifcompat-edit-del'] = array
(
'table' => 'PortInterfaceCompat',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'iif_id', 'assertion' => 'uint'),
array ('url_argname' => 'oif_id', 'assertion' => 'uint'),
),
);
$opspec_list['portoifs-edit-add'] = array
(
'table' => 'PortOuterInterface',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'oif_name', 'assertion' => 'string'),
),
);
$opspec_list['portoifs-edit-del'] = array
(
'table' => 'PortOuterInterface',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['portoifs-edit-upd'] = array
(
'table' => 'PortOuterInterface',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'oif_name', 'assertion' => 'string'),
),
'where_arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['attrs-editmap-del'] = array
(
'table' => 'AttributeMap',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'attr_id', 'assertion' => 'uint'),
array ('url_argname' => 'objtype_id', 'assertion' => 'uint'),
),
);
$opspec_list['attrs-editattrs-add'] = array
(
'table' => 'Attribute',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'attr_type', 'table_colname' => 'type', 'assertion' => 'enum/attr_type'),
array ('url_argname' => 'attr_name', 'table_colname' => 'name', 'assertion' => 'string'),
),
);
$opspec_list['attrs-editattrs-del'] = array
(
'table' => 'Attribute',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'attr_id', 'table_colname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['attrs-editattrs-upd'] = array
(
'table' => 'Attribute',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'attr_name', 'table_colname' => 'name', 'assertion' => 'string'),
),
'where_arglist' => array
(
array ('url_argname' => 'attr_id', 'table_colname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['dict-chapters-add'] = array
(
'table' => 'Chapter',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'chapter_name', 'table_colname' => 'name', 'assertion' => 'string')
),
);
$opspec_list['chapter-edit-add'] = array
(
'table' => 'Dictionary',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'chapter_no', 'table_colname' => 'chapter_id', 'assertion' => 'uint'),
array ('url_argname' => 'dict_value', 'assertion' => 'string'),
),
);
$opspec_list['chapter-edit-del'] = array
(
'table' => 'Dictionary',
'action' => 'DELETE',
'arglist' => array
(
// Technically dict_key is enough to delete, but including chapter_id into
// WHERE clause makes sure that the action actually happends for the same
// chapter that authorization was granted for.
array ('url_argname' => 'chapter_no', 'table_colname' => 'chapter_id', 'assertion' => 'uint'),
array ('url_argname' => 'dict_key', 'assertion' => 'uint'),
array ('fix_argname' => 'dict_sticky', 'fix_argvalue' => 'no'), # protect system rows
),
);
$opspec_list['chapter-edit-upd'] = array
(
'table' => 'Dictionary',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'dict_value', 'assertion' => 'string'),
),
'where_arglist' => array
(
# same as above for listing chapter_no
array ('url_argname' => 'chapter_no', 'table_colname' => 'chapter_id', 'assertion' => 'uint'),
array ('url_argname' => 'dict_key', 'assertion' => 'uint'),
array ('fix_argname' => 'dict_sticky', 'fix_argvalue' => 'no'), # protect system rows
),
);
$opspec_list['tagtree-edit-createTag'] = array
(
'table' => 'TagTree',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'tag_name', 'table_colname' => 'tag', 'assertion' => 'tag'),
array ('url_argname' => 'parent_id', 'assertion' => 'uint0', 'translator' => 'nullIfZero'),
array ('url_argname' => 'is_assignable', 'assertion' => 'enum/yesno'),
array ('url_argname' => 'color', 'assertion' => 'htmlcolor0', 'translator' => 'HTMLColorForDatabase'),
),
);
$opspec_list['tagtree-edit-destroyTag'] = array
(
'table' => 'TagTree',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'tag_id', 'table_colname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['8021q-vstlist-add'] = array
(
'table' => 'VLANSwitchTemplate',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'vst_descr', 'table_colname' => 'description', 'assertion' => 'string'),
// workaround SQL_STRICT
array ('fix_argname' => 'mutex_rev', 'fix_argvalue' => 0),
array ('fix_argname' => 'saved_by', 'fix_argvalue' => ""),
),
);
$opspec_list['8021q-vstlist-del'] = array
(
'table' => 'VLANSwitchTemplate',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'vst_id', 'table_colname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['8021q-vstlist-upd'] = array
(
'table' => 'VLANSwitchTemplate',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'vst_descr', 'table_colname' => 'description', 'assertion' => 'string'),
),
'where_arglist' => array
(
array ('url_argname' => 'vst_id', 'table_colname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['8021q-vdlist-del'] = array
(
'table' => 'VLANDomain',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'vdom_id', 'table_colname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['vlandomain-vlanlist-add'] = array
(
'table' => 'VLANDescription',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'vdom_id', 'table_colname' => 'domain_id', 'assertion' => 'uint'),
array ('url_argname' => 'vlan_id', 'assertion' => 'vlan'),
array ('url_argname' => 'vlan_type', 'assertion' => 'enum/vlan_type'),
array ('url_argname' => 'vlan_descr', 'assertion' => 'string0', 'translator' => 'nullIfEmptyStr'),
),
);
$opspec_list['vlandomain-vlanlist-del'] = array
(
'table' => 'VLANDescription',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'vdom_id', 'table_colname' => 'domain_id', 'assertion' => 'uint'),
array ('url_argname' => 'vlan_id', 'assertion' => 'vlan'),
),
);
$opspec_list['vlan-edit-upd'] = // both locations are using the same tableHandler op
$opspec_list['vlandomain-vlanlist-upd'] = array
(
'table' => 'VLANDescription',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'vlan_type', 'assertion' => 'enum/vlan_type'),
array ('url_argname' => 'vlan_descr', 'assertion' => 'string0', 'translator' => 'nullIfEmptyStr'),
),
'where_arglist' => array
(
array ('url_argname' => 'vdom_id', 'table_colname' => 'domain_id', 'assertion' => 'uint'),
array ('url_argname' => 'vlan_id', 'assertion' => 'vlan'),
),
);
$opspec_list['dict-chapters-upd'] = array
(
'table' => 'Chapter',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'chapter_name', 'table_colname' => 'name', 'assertion' => 'string'),
),
'where_arglist' => array
(
array ('url_argname' => 'chapter_no', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('fix_argname' => 'sticky', 'fix_argvalue' => 'no'), # protect system chapters
),
);
$opspec_list['dict-chapters-del'] = array
(
'table' => 'Chapter',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'chapter_no', 'table_colname' => 'id', 'assertion' => 'uint'),
array ('fix_argname' => 'sticky', 'fix_argvalue' => 'no'), # protect system chapters
),
);
$opspec_list['cables-heaps-add'] = array
(
'table' => 'PatchCableHeap',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'end1_conn_id', 'assertion' => 'uint'),
array ('url_argname' => 'pctype_id', 'assertion' => 'uint'),
array ('url_argname' => 'end2_conn_id', 'assertion' => 'uint'),
array ('fix_argname' => 'amount', 'fix_argvalue' => 0),
array ('url_argname' => 'length', 'assertion' => 'decimal'),
array ('url_argname' => 'description', 'assertion' => 'string0'),
),
);
$opspec_list['cables-heaps-del'] = array
(
'table' => 'PatchCableHeap',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['cables-heaps-upd'] = array
(
'table' => 'PatchCableHeap',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'end1_conn_id', 'assertion' => 'uint'),
array ('url_argname' => 'pctype_id', 'assertion' => 'uint'),
array ('url_argname' => 'end2_conn_id', 'assertion' => 'uint'),
array ('url_argname' => 'length', 'assertion' => 'decimal'),
array ('url_argname' => 'description', 'assertion' => 'string0'),
),
'where_arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
),
);
$opspec_list['cableconf-connectors-add'] = array
(
'table' => 'PatchCableConnector',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'connector', 'assertion' => 'string'),
array ('fix_argname' => 'origin', 'fix_argvalue' => 'custom'),
),
);
$opspec_list['cableconf-connectors-del'] = array
(
'table' => 'PatchCableConnector',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
array ('fix_argname' => 'origin', 'fix_argvalue' => 'custom'),
),
);
$opspec_list['cableconf-connectors-upd'] = array
(
'table' => 'PatchCableConnector',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'connector', 'assertion' => 'string'),
),
'where_arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
array ('fix_argname' => 'origin', 'fix_argvalue' => 'custom'),
),
);
$opspec_list['cableconf-cabletypes-add'] = array
(
'table' => 'PatchCableType',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'pctype', 'assertion' => 'string'),
array ('fix_argname' => 'origin', 'fix_argvalue' => 'custom'),
),
);
$opspec_list['cableconf-cabletypes-del'] = array
(
'table' => 'PatchCableType',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
array ('fix_argname' => 'origin', 'fix_argvalue' => 'custom'),
),
);
$opspec_list['cableconf-cabletypes-upd'] = array
(
'table' => 'PatchCableType',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('url_argname' => 'pctype', 'assertion' => 'string'),
),
'where_arglist' => array
(
array ('url_argname' => 'id', 'assertion' => 'uint'),
array ('fix_argname' => 'origin', 'fix_argvalue' => 'custom'),
),
);
$opspec_list['cableconf-conncompat-add'] = array
(
'table' => 'PatchCableConnectorCompat',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'pctype_id', 'assertion' => 'uint'),
array ('url_argname' => 'connector_id', 'assertion' => 'uint'),
),
);
$opspec_list['cableconf-conncompat-del'] = array
(
'table' => 'PatchCableConnectorCompat',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'pctype_id', 'assertion' => 'uint'),
array ('url_argname' => 'connector_id', 'assertion' => 'uint'),
),
);
$opspec_list['cableconf-oifcompat-add'] = array
(
'table' => 'PatchCableOIFCompat',
'action' => 'INSERT',
'arglist' => array
(
array ('url_argname' => 'pctype_id', 'assertion' => 'uint'),
array ('url_argname' => 'oif_id', 'assertion' => 'uint'),
),
);
$opspec_list['cableconf-oifcompat-del'] = array
(
'table' => 'PatchCableOIFCompat',
'action' => 'DELETE',
'arglist' => array
(
array ('url_argname' => 'pctype_id', 'assertion' => 'uint'),
array ('url_argname' => 'oif_id', 'assertion' => 'uint'),
),
);
$opspec_list['plugins-edit-disable'] = array
(
'table' => 'Plugin',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('fix_argname' => 'state', 'fix_argvalue' => 'disabled'),
),
'where_arglist' => array
(
array ('url_argname' => 'name', 'assertion' => 'string'),
),
);
$opspec_list['plugins-edit-enable'] = array
(
'table' => 'Plugin',
'action' => 'UPDATE',
'set_arglist' => array
(
array ('fix_argname' => 'state', 'fix_argvalue' => 'enabled'),
),
'where_arglist' => array
(
array ('url_argname' => 'name', 'assertion' => 'string'),
),
);
function setFuncMessages ($funcname, $messages)
{
global $msgcode;
foreach ($messages as $symbol => $code)
$msgcode[$funcname][$symbol] = $code;
}
function addPortForwarding ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 48));
$proto = genericAssertion ('proto', 'enum/natv4proto');
if ($proto != 'ALL')
{
assertUIntArg ('localport');
assertUIntArg ('remoteport');
}
assertStringArg ('description', TRUE);
$remoteport = isset ($_REQUEST['remoteport']) ? $_REQUEST['remoteport'] : '';
if ($remoteport == '')
$remoteport = $_REQUEST['localport'];
try
{
newPortForwarding
(
getBypassValue(),
genericAssertion ('localip', 'inet4'),
$_REQUEST['localport'],
genericAssertion ('remoteip', 'inet4'),
$remoteport,
$proto,
$_REQUEST['description']
);
}
catch (InvalidArgException $iae)
{
throw $iae->newIRAE();
}
showFuncMessage (__FUNCTION__, 'OK');
}
function delPortForwarding ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 49));
$proto = genericAssertion ('proto', 'enum/natv4proto');
if ($proto != 'ALL')
{
assertUIntArg ('localport');
assertUIntArg ('remoteport');
}
deletePortForwarding
(
getBypassValue(),
genericAssertion ('localip', 'inet4'),
$_REQUEST['localport'],
genericAssertion ('remoteip', 'inet4'),
$_REQUEST['remoteport'],
$proto
);
showFuncMessage (__FUNCTION__, 'OK');
}
function updPortForwarding ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 51));
$proto = genericAssertion ('proto', 'enum/natv4proto');
if ($proto != 'ALL')
{
assertUIntArg ('localport');
assertUIntArg ('remoteport');
}
assertStringArg ('description', TRUE);
updatePortForwarding
(
getBypassValue(),
genericAssertion ('localip', 'inet4'),
$_REQUEST['localport'],
genericAssertion ('remoteip', 'inet4'),
$_REQUEST['remoteport'],
$proto,
$_REQUEST['description']
);
showFuncMessage (__FUNCTION__, 'OK');
}
function addPortForObject ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 48));
genericAssertion ('port_name', 'string');
try
{
commitAddPort
(
getBypassValue(),
trim ($_REQUEST['port_name']),
genericAssertion ('port_type_id', 'string'),
trim ($_REQUEST['port_label']),
trim (genericAssertion ('port_l2address', 'l2address0'))
);
}
catch (InvalidRequestArgException $irae)
{
throw $irae;
}
catch (InvalidArgException $iae)
{
throw $iae->newIRAE();
}
showFuncMessage (__FUNCTION__, 'OK', array ($_REQUEST['port_name']));
}
function editPortForObject ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 6));
global $sic;
$port_id = assertUIntArg ('port_id');
try
{
commitUpdatePort
(
getBypassValue(),
$port_id,
genericAssertion ('name', 'string'),
assertStringArg ('port_type_id'),
genericAssertion ('label', 'string0'),
genericAssertion ('l2address', 'l2address0'),
assertStringArg ('reservation_comment', TRUE)
);
}
catch (InvalidRequestArgException $irae)
{
throw $irae;
}
catch (InvalidArgException $iae)
{
throw $iae->newIRAE();
}
if (array_key_exists ('cable', $_REQUEST))
commitUpdatePortLink ($port_id, $sic['cable']);
showFuncMessage (__FUNCTION__, 'OK', array ($_REQUEST['name']));
}
function addMultiPorts ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 10));
assertStringArg ('input');
$format = genericAssertion ('format', 'string');
$port_type = genericAssertion ('port_type', 'string');
$object_id = getBypassValue();
$ports = array();
foreach (textareaCooked ($_REQUEST['input']) as $line)
{
switch ($format)
{
case 'ssv1':
$words = explode (' ', $line);
if ($words[0] == '') // empty L2 address is OK
continue;
$ports[] = array
(
'name' => $words[0],
'l2address' => array_fetch ($words, 1, ''),
'label' => ''
);
break;
default:
throw new RackTablesError ("unknown data format '${format}'", RackTablesError::INTERNAL);
}
}
// Create ports, if they don't exist.
$added_count = $updated_count = $error_count = 0;
foreach ($ports as $port)
{
$port_ids = getPortIDs ($object_id, $port['name']);
try
{
if (!count ($port_ids))
{
commitAddPort ($object_id, $port['name'], $port_type, $port['label'], $port['l2address']);
$added_count++;
}
elseif (count ($port_ids) == 1) // update only single-socket ports
{
$rsvc = getPortReservationComment (array_first ($port_ids));
commitUpdatePort ($object_id, $port_ids[0], $port['name'], $port_type, $port['label'], $port['l2address'], $rsvc);
$updated_count++;
}
}
catch (InvalidArgException $iae)
{
showError ($iae->getMessage());
}
}
showFuncMessage (__FUNCTION__, 'OK', array ($added_count, $updated_count, $error_count));
}
function addBulkPorts ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 82));
assertStringArg ('port_name', TRUE);
assertStringArg ('port_label', TRUE);
$object_id = getBypassValue();
$port_name = $_REQUEST['port_name'];
$port_type_id = genericAssertion ('port_type_id', 'string');
$port_label = $_REQUEST['port_label'];
$port_numbering_start = genericAssertion ('port_numbering_start', 'uint0');
$port_numbering_count = genericAssertion ('port_numbering_count', 'uint');
$added_count = $error_count = 0;
if (strrpos ($port_name, '%u') === FALSE)
$port_name .= '%u';
if (strrpos ($port_label, '%u') === FALSE)
$port_label .= '%u';
for ($i = 0, $c = $port_numbering_start; $i < $port_numbering_count; $i++, $c++)
{
commitAddPort ($object_id, @sprintf ($port_name, $c), $port_type_id, @sprintf ($port_label, $c), '');
$added_count++;
}
showFuncMessage (__FUNCTION__, 'OK', array ($added_count, $error_count));
}
function updIPAllocation ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 51));
$ip_bin = assertIPArg ('ip');
assertStringArg ('bond_name', TRUE);
updateIPBond
(
$ip_bin,
genericAssertion ('object_id', 'uint'),
$_REQUEST['bond_name'],
genericAssertion ('bond_type', 'enum/alloc_type')
);
showFuncMessage (__FUNCTION__, 'OK');
return buildRedirectURL (NULL, NULL, array ('hl_ip' => ip_format ($ip_bin)));
}
function delIPAllocation ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 49));
unbindIPFromObject (genericAssertion ('ip', 'inet'), genericAssertion ('object_id', 'uint'));
showFuncMessage (__FUNCTION__, 'OK');
}
function addIPAllocation ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 48, 'ERR1' => 170));
$ip_bin = assertIPArg ('ip');
$alloc_type = genericAssertion ('bond_type', 'enum/alloc_type');
// check if address is alread allocated
$address = getIPAddress($ip_bin);
if(!empty($address['allocs']) && ( ($address['allocs'][0]['type'] != 'shared') || ($alloc_type != 'shared') ) )
showWarning("IP ".ip_format($ip_bin)." already in use by ".$address['allocs'][0]['object_name']." - ".$address['allocs'][0]['name']);
if (getConfigVar ('IPV4_JAYWALK') != 'yes' && NULL === getIPAddressNetworkId ($ip_bin))
{
showFuncMessage (__FUNCTION__, 'ERR1', array (ip_format ($ip_bin)));
return;
}
if($address['reserved'] && $address['name'] != '')
{
showWarning("IP ".ip_format($ip_bin)." reservation \"".$address['name']."\" is removed");
//TODO ask to take reserved IP or not !
}
bindIPToObject
(
$ip_bin,
genericAssertion ('object_id', 'uint'),
genericAssertion ('bond_name', 'string0'),
$alloc_type
);
showFuncMessage (__FUNCTION__, 'OK');
return buildRedirectURL (NULL, NULL, array ('hl_ip' => ip_format ($ip_bin)));
}
function addIPv4Prefix ()
{
global $sic;
$vlan_ck = empty ($sic['vlan_ck']) ? NULL : genericAssertion ('vlan_ck', 'uint-vlan1');
$net_id = createIPv4Prefix
(
genericAssertion ('range', 'string'),
genericAssertion ('name', 'string0'),
isCheckSet ('is_connected'),
genericAssertion ('taglist', 'array0')
);
$net_cell = spotEntity ('ipv4net', $net_id);
if (isset ($vlan_ck))
{
if (considerConfiguredConstraint ($net_cell, 'VLANNET_LISTSRC'))
commitSupplementVLANIPv4 ($vlan_ck, $net_id);
else
showError ("VLAN binding to network " . mkCellA ($net_cell) . " is restricted in config");
}
showSuccess ('IP network ' . mkCellA ($net_cell) . ' has been created');
}
function addIPv6Prefix ()
{
global $sic;
$vlan_ck = empty ($sic['vlan_ck']) ? NULL : genericAssertion ('vlan_ck', 'uint-vlan1');
$net_id = createIPv6Prefix
(
genericAssertion ('range', 'string'),
genericAssertion ('name', 'string0'),
isCheckSet ('is_connected'),
genericAssertion ('taglist', 'array0')
);
$net_cell = spotEntity ('ipv6net', $net_id);
if (isset ($vlan_ck))
{
if (considerConfiguredConstraint ($net_cell, 'VLANNET_LISTSRC'))
commitSupplementVLANIPv6 ($vlan_ck, $net_id);
else
showError ("VLAN binding to network " . mkCellA ($net_cell) . " is restricted in config");
}
showSuccess ('IP network ' . mkCellA ($net_cell) . ' has been created');
}
function delIPv4Prefix ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 49));
$netinfo = spotEntity ('ipv4net', genericAssertion ('id', 'uint'));
loadIPAddrList ($netinfo);
if (! isIPNetworkEmpty ($netinfo))
{
showError ("There are allocations within prefix, delete forbidden");
return;
}
if (array_key_exists ($netinfo['ip_bin'], $netinfo['addrlist']))
updateV4Address ($netinfo['ip_bin'], '', 'no');
$last_ip = ip_last ($netinfo);
if (array_key_exists ($last_ip, $netinfo['addrlist']))
updateV4Address ($last_ip, '', 'no');
destroyIPv4Prefix ($netinfo['id']);
showFuncMessage (__FUNCTION__, 'OK');
global $pageno;
if ($pageno == 'ipv4net')
return buildRedirectURL ('index', 'default');
}
function delIPv6Prefix ()
{
setFuncMessages (__FUNCTION__, array ('OK' => 49));
$netinfo = spotEntity ('ipv6net', genericAssertion ('id', 'uint'));
loadIPAddrList ($netinfo);
if (! isIPNetworkEmpty ($netinfo))
{
showError ("There are allocations within prefix, delete forbidden");
return;
}