-
Notifications
You must be signed in to change notification settings - Fork 4
/
class.libraries.php
1467 lines (1381 loc) · 58 KB
/
class.libraries.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
/*
* phpMyOrdering - All rights reserved.
*
* Author: Jason Gerfen
* Email: <[email protected]>
*
* Description: class.libraries.php - Miscellaneous functions
*
*/
class MiscFunctions
{
function GenDate()
{
return date( "Y-m-d" );
}
function GenTime()
{
return time();
}
function GenTimeRead()
{
return date( "G:i:s A" );
}
function GenSub30Date( $date )
{
return mktime( 0, 0, 0, date( "m" ) - 1, date( "d" ), date( "Y" ) );
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelected( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$value['name'] = $this->TrimString( $value['name'], 25 );
$list .= "<option value=\"" . $value['name'] . "\">" . $value['name'] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedSubnets( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$value['subnet-name'] = $this->TrimString( $value['subnet-name'], 25 );
$list .= "<option value=\"" . $value['subnet-name'] . "\">" . $value['subnet-name'] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedPools( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$modified = $this->TrimString( $value['pool-name'], 25 );
$list .= "<option value=\"" . $value['pool-name'] . "\">" . $modified . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedPoolOpts( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
for( $x = 0; $x < count( $array ); $x++ ) {
//foreach( $array as $key => $value ) {
$array[$x] = $this->TrimString( $array[$x], 25 );
$list .= "<option value=\"" . $array[$x] . "\">" . $array[$x] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedPXE( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$value['name'] = $this->TrimString( $value['name'], 25 );
$list .= "<option value=\"" . $value['pxe-group-name'] . "\">" . $value['pxe-group-name'] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array (config.dns.php only)
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedDNS( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$value['key-name'] = $this->TrimString( $value['key-name'], 25 );
$list .= "<option value=\"" . $value['key-name'] . "\">" . $value['key-name'] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedLevels( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$value['level'] = $this->TrimString( $value['level'], 25 );
$list .= "<option value=\"" . $value['level'] . "\">" . $value['level'] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedGroups( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$value['group'] = $this->TrimString( $value['group'], 25 );
$list .= "<option value=\"" . $value['group'] . "\">" . $value['group'] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedUsers( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
$value['username'] = $this->TrimString( $value['username'], 25 );
$list .= "<option value=\"" . $value['username'] . "\">" . $value['username'] . "</option>";
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a simple drop down menu from array
* @array => Nested array of data to use in form
* @selected => Option to show if $_POST or $_GET processed
* @name => Name of drop down menu
*/
function GenDropMenuWSelectedClassOpts( $array, $selected, $name )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
if( count( $array[0] ) !== 0 ) {
$list .= "<select name=\"". $name . "\" style=\"width: 100%\">";
if( !empty( $selected ) ) {
$list .= "<option value=\"" . $selected . "\">" . $selected . "</option>";
}
$list .= "<option>---------------</option>";
foreach( $array as $key => $value ) {
if( $value['Field'] !== "id" ) {
$value['Field'] = $this->TrimString( $value['Field'], 25 );
if( $value['Type'] === "tinyint(1)" ) { $value['Type'] = "Boolean (1|0)"; }
$list .= "<option value=\"" . $value['Field'] . "\">" . $value['Field'] . " (" . $value['Type'] . ")</option>";
}
}
$list .= "</select>";
}
return $list;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxDNSSEC( $array, $name, $skin )
{ //print_r( $array );
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\">";
if( count( $array ) === 0 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No DNS Keys Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['key-name'] = $this->TrimString( $value['key-name'], 20 );
$value['algorithm'] = $this->TrimString( $value['algorithm'], 15 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['key-name'] . " - " . $value['algorithm'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxDNS( $array, $name, $skin )
{ //echo count( $array );
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\">";
if( count( $array ) === 0 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No DNS Zones Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['zone'] = $this->TrimString( $value['zone'], 20 );
$value['primary'] = $this->TrimString( $value['primary'], 20 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['zone'] . " | " . $value['type'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxSubnets( $array, $name, $skin )
{ //echo count( $array );
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\">";
if( count( $array ) <= 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Subnets Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['subnet-name'] = $this->TrimString( $value['subnet-name'], 15 );
$value['subnet'] = $this->TrimString( $value['subnet'], 20 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['subnet-name'] . " | " . $value['subnet'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Perform nested array in_array() function
*/
function array_search_recursive( $needle, $haystack )
{ //echo "$needle<pre>"; print_r( $haystack ); echo "</pre><hr>";
if( count( $haystack ) !== 0 ) {
foreach( $haystack as $k => $v ) {
if( $v['subnet-name'] === $needle ) {
return TRUE;
break;
}
}
}
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenSubnetCheckBoxes( $array, $name, $skin, $checked )
{ //echo "<pre>"; print_r( $checked ); echo "</pre>";
if( count( $array ) <= 1 ) {
$frm .= "No Subnets Defined";
} else {
foreach( $array as $key => $value ) {
if( $this->array_search_recursive( $value['subnet-name'], $checked ) === TRUE ) {
$frm .= "<tr><td nowrap><b>" .$value['subnet-name'] . "</b>:</td><td><input type=\"checkbox\" name=\"" . $name . "\" value=\"" . $value['subnet-name'] . "\" checked></td></tr>";
} else {
$frm .= "<tr><td nowrap><b>" .$value['subnet-name'] . "</b>:</td><td><input type=\"checkbox\" name=\"" . $name . "\" value=\"" . $value['subnet-name'] . "\"></td></tr>";
}
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxSharedNetworks( $array, $name, $skin )
{
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\">";
if( count( $array ) < 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Shared Networks Defined</option>";
} else {
foreach( $array as $key => $value ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['shared-network-name'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxPools( $array, $name, $skin )
{ //echo "<pre>"; print_r( $array ); echo "</pre>";
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\">";
if( count( $array ) < 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Pools Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['pool-name'] = $this->TrimString( $value['pool-name'], 15 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['pool-name'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxClasses( $array, $name, $skin )
{
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\">";
if( count( $array[0] ) <= 0 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Classes Defined</option>";
} else {
foreach( $array as $key => $value ) {
$val = $this->TrimString( $value['class-name'], 35 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['class-name'] . "\">" . $val . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxPXE( $array, $name, $skin )
{ //echo count( $array );
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\">";
if( count( $array ) < 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No PXE Groups Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['pxe-group-name'] = $this->TrimString( $value['pxe-group-name'], 15 );
$value['pxe-server'] = $this->TrimString( $value['pxe-server'], 30 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['pxe-group-name'] . " | " . $value['pxe-server'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxHOSTS( $array, $name, $skin )
{ //echo count( $array );
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\" multiple>";
if( count( $array ) < 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Static Hosts Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['hostname'] = $this->TrimString( $value['hostname'], 30 );
$value['ip-address'] = $this->TrimString( $value['ip-address'], 25 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['hostname'] . " | " . $value['ip-address'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
/*
* Generate a jump menu list box
* @array => Nested array of data to use in form
* @name => Name of drop down menu
*/
function GenJumpMenuBoxLEASES( $array, $name, $skin )
{ //echo count( $array );
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\" multiple>";
if( count( $array ) < 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Leases Found</option>";
} else {
foreach( $array as $key => $value ) {
$value['ip'] = $this->TrimString( $value['ip'], 30 );
$value['start'] = $this->TrimString( $value['start'], 25 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['ip'] . " | " . $value['start'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
function GenJumpMenuBoxGROUPS( $array, $name, $skin )
{
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\" multiple>";
if( count( $array ) < 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Groups Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['group'] = $this->TrimString( $value['group'], 15 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['group'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
function GenJumpMenuBoxUSERS( $array, $name, $skin )
{
$frm .= "<select name=\"" . $name . "\" size=\"8\" onClick=\"jumpMenu('parent',this,0)\" multiple>";
if( count( $array ) < 1 ) {
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=NULL\">No Users Defined</option>";
} else {
foreach( $array as $key => $value ) {
$value['username'] = $this->TrimString( $value['username'], 30 );
$value['first'] = $this->TrimString( $value['first'], 12 );
$value['last'] = $this->TrimString( $value['last'], 12 );
$frm .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?skin=" . $skin . "&id=" . $value['id'] . "\">" . $value['username'] . " | " . $value['first'] . " " . $value['last'] . "</option>";
}
}
$frm .= "</select>";
$data = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"3\">
<tr>
<td valign=\"top\">$frm</td>
<tr>
</table>";
return $data;
}
function GenDropMenuURL( $table, $field, $order, $id )
{
global $defined;
$db = new dbConn();
$val = new ValidateStrings();
if( ( empty( $table ) ) || ( empty( $field ) ) ) {
return -1;
}
$conn = $db->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
if( empty( $order ) ) {
$query = "SELECT `$field` FROM `$table`";
} else {
$query = "SELECT `$field` FROM `$table` ORDER BY `$order`";
}
$query = $val->ValidateSQL( $query, $conn );
if( ( $value = $db->dbQuery( $query, $conn ) ) === -1 ) {
return -1;
}
if( ( $db->dbNumRows( $value ) === -1 ) || ( $db->dbNumRows( $value ) === 0 ) ) {
return -1;
} else {
$list = "<option name=\"----------\" value=\"----------\">----------</option>";
foreach( $db->dbArrayResults( $value ) as $key => $val ) {
foreach( $val as $key => $val ) {
if( strlen( $val ) >= 40 ) {
$list .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?" . $id . "=" . $val . "\">" . substr_replace( $val, '...', 40 ) . "</option>";
} else {
$list .= "<option value=\"" . $_SERVER['PHP_SELF'] . "?" . $id . "=" . $val . "\">$val</option>";
}
}
}
$data = $list;
}
$db->dbFreeData( $conn );
$db->dbCloseConn( $conn );
return $data;
}
function GenGroupList( $group )
{
global $defined;
$db = new dbConn();
$conn = $db->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
$query = "SELECT * FROM `groups` WHERE `group` = \"$group\" LIMIT 1";
if( ( $value = $db->dbQuery( $query, $conn ) ) === -1 ) {
return -1;
}
if( ( $db->dbNumRows( $value ) === -1 ) || ( $db->dbNumRows( $value ) === 0 ) ) {
return -1;
} else {
$data = $db->dbArrayResults( $value );
}
$db->dbFreeData( $conn );
$db->dbCloseConn( $conn );
return $data;
}
function GenUserList( $user )
{
global $defined;
$db = new dbConn();
$conn = $db->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
$query = "SELECT * FROM `users` WHERE `username` = \"$user\" LIMIT 1";
if( ( $value = $db->dbQuery( $query, $conn ) ) === -1 ) {
return -1;
}
if( ( $db->dbNumRows( $value ) === -1 ) || ( $db->dbNumRows( $value ) === 0 ) ) {
return -1;
} else {
$data = $db->dbArrayResults( $value );
}
$db->dbFreeData( $conn );
$db->dbCloseConn( $conn );
return $data;
}
/*
* Generate new URI with $_GET params
* @get => Current list of $_GET vars
*/
function BuildGETParams( $get )
{
$val = new ValidateStrings();
$data = "?";
foreach( $get as $key => $value ) {
$data .= $val->ValidateXSS( $key ) . "=" . $val->ValidateXSS( $value ) . "&";
}
$data = substr_replace( $data, '', -1, count( $data ) );
return $data;
}
function DetArrayType( $array ) {
$val = 0;
$keys = array_keys( $array[0] );
foreach( $keys as $key ) {
if( !is_int( $key ) ) {
$val = 1;
}
}
return $val;
}
/*
* return a reversed dns lookup
*/
function GenRevAddr( $ip ) {
$adapter = @dns_get_record( implode( '.', array_reverse( explode( '.', $ip ) ) ) . '.in-addr.arpa.', DNS_PTR );
if( empty( $adapter ) ) {
$adapter = "ERROR DETERMINING REVERSE HOST RECORD";
}
return $adapter;
}
/*
* test the status up/down of dhcpd service
*/
function GetDHCPDStatus()
{
global $defined;
$cmd = $defined['ps'] . ' -aux';
$res = shell_exec( $cmd );
if( eregi( 'dhcpd', $res ) ) {
return 0;
} else {
return -1;
}
}
/*
* process lease file
*/
function GetCurrentLeases( $file )
{
global $defined;
$db = new dbConn;
$val = new ValidateStrings;
// initialize a db connection handle
$dbconn = $db->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
// get timestamp, filesize and md5 data
$check = "SELECT * FROM `conf_leases_properties`";
$res = $db->dbQuery( $val->ValidateSQL( $check, $dbconn ), $dbconn );
$chk = $db->dbArrayResults( $res );
// see if results are empty to place data
if( count( $chk ) === 0 ) {
$date = $this->GenDate();
$check = "INSERT INTO `conf_leases_properties` ( `date`, `size`, `hash` ) VALUES ( \"" . $date . "\", \"" . filesize( $file ) . "\", \"" . md5( $file ) . "\" )";
$db->dbQuery( $val->ValidateSQL( $check, $dbconn ), $dbconn );
}
// perform check on file data
if( file_exists( $file ) ) {
if( ( $chk[0]['size'] !== filesize( $file ) ) && ( $chk[0]['hash'] !== md5( $file ) ) ) {
// execute update on lease data
if( !empty( $file ) ) {
if( ( $tmp = $this->SafeReadFileNoDir( $file ) ) !== -1 ) {
foreach( $tmp as $key => $value ) {
$setflag = "UPDATE `conf_leases_properties` SET `recreate` = \"FALSE\" WHERE `id` = 1 LIMIT 1";
$db->dbQuery( $val->ValidateSQL( $setflag, $dbconn ), $dbconn );
$group = $this->DetermineGroup( $value['ip'] );
$value['uid'] = addslashes( $value['uid'] );
$insert = "INSERT INTO `conf_leases` ( `ip`, `start`, `end`, `cltt`, `current-state`, `next-state`, `hardware`, `hostname`, `abandoned`, `circut-id`, `remote-id`, `ddns-text`, `ddns-fwd-name`, `ddns-client-fqdn`, `ddns-rev-name`, `uid`, `group` ) VALUES ( \"" . $value['ip'] . "\", \"" . $value['starts'] . "\", \"" . $value['ends'] . "\", \"" . $value['cltt'] . "\", \"" . $value['current_state'] . "\", \"" . $value['next_state'] . "\", \"" . $value['hardware'] . "\", \"" . $value['hostname'] . "\", \"" . $value['abandoned'] . "\", \"" . $value['circut_id'] . "\", \"" . $value['remote_id'] . "\", \"" . $value['ddns_text'] . "\", \"" . $value['ddns_fwd_name'] . "\", \"" . $value['ddns_client_fqdn'] . "\", \"" . $value['ddns_rev_name'] . "\", \"" . mysql_real_escape_string( $value['uid'] ) . "\", \"" . $group . "\" )";
$update = "UPDATE `conf_leases` SET `ip` = \"" . $value['ip'] . "\", `start` = \"" . $value['starts'] . "\", `end` = \"" . $value['ends'] . "\", `cltt` = \"" . $value['cltt'] . "\", `current-state` = \"" . $value['current_state'] . "\", `next-state` = \"" . $value['next_state'] . "\", `hardware` = \"" . $value['hardware'] . "\", `hostname` = \"" . $value['hostname'] . "\", `abandoned` = \"" . $value['abandoned'] . "\", `circut-id` = \"" . $value['circut_id'] . "\", `remote-id` = \"" . $value['remote_id'] . "\", `ddns-text` = \"" . $value['ddns_text'] . "\", `ddns-fwd-name` = \"" . $value['ddns_fwd_name'] . "\", `ddns-client-fqdn` = \"" . $value['ddns_client_fqdn'] . "\", `ddns-rev-name` = \"" . $value['ddns_rev_name'] . "\", `uid` = \"" . mysql_real_escape_string( $value['uid'] ) . "\", `group` = \"" . $group . "\" WHERE `ip` = \"" . $value['ip'] . "\" LIMIT 1";
if( ( $res = $db->dbQuery( $val->ValidateSQL( $insert, $dbconn ), $dbconn ) ) === -1 ) {
if( eregi( "duplicate", $db->dbCatchError() ) ) {
$res = $db->dbQuery( $val->ValidateSQL( $update, $dbconn ), $dbconn );
}
}
}
} else {
$data = -3;
}
} else {
$data = -2;
}
} else {
$data = -1;
}
}
return $data;
}
/*
* Attempt to determine which group the lease belongs to
* based on the group ownership of the subnet config data
*/
function DetermineGroup( $ip )
{
global $defined;
$db = new dbConn;
$val = new ValidateStrings;
// initialize a db connection handle
$dbconn = $db->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
// break ip apart
preg_match( '/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\.([0-9]{1,3})/', $ip, $octet );
$last_octet = $octet[2];
// Attempt lookup on ip vs. subnet group ownership
$sql = "SELECT `group`,`subnet`,`subnet-mask` FROM `conf_subnets` WHERE `subnet` LIKE \"" . $octet[1] . ".%\"";
if( ( $value = $db->dbQuery( $val->ValidateSQL( $sql, $dbconn ), $dbconn ) ) !== -1 ) {
$array = $db->dbArrayResults( $value );
}
// look for multiple results and filter further if necessary
if( count( $array ) > 1 ) {
foreach( $array as $key => $data ) {
preg_match( '/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\.([0-9]{1,3})/', $data['subnet-mask'], $msk );
preg_match( '/([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\.([0-9]{1,3})/', $data['subnet'], $sub );
$max = 256 - $msk[2]; $min = $sub[2];
if( $min == $max ) { $max = 255; }
// is the ip within a specified range?
// if so assign the group id belong to that particular subnet to our lease
if( ( $last_octet <= $max ) && ( $last_octet >= $min ) ) {
return $data['group'];
}
}
}
return;
}
/*
* attempt to get list of networks machine is configured for
*/
function GetAdapters()
{
global $defined;
$cmd = $defined['netstat'] . ' -inWa';
$res = shell_exec( $cmd );
if( $this->SafeWriteFile( $defined['confpath'], 'adapters.conf', $res ) === 0 ) {
$tmp = $this->SafeReadFile( $defined['confpath'], 'adapters.conf' );
@unlink( $defined['confpath'] . 'adapters.conf' );
// process for list of adapters
$array = preg_split( '/[\r\n]+/', $tmp );
// list of adapters and their attributes
for( $i = 0; $i < count( $array ); $i++ ) {
if( !empty( $array[$i] ) ) {
$adapters[] = preg_split( '/[\t\s]+/', $array[$i] );
}
}
// process list of adapters for changes
if( $adapters !== -1 ) {
// loop over results
for( $x = 0; $x <= count( $adapters ); $x++ ) {
// filter non adapters and headers
if( !eregi( "kernel|iface", $adapters[$x][0] ) ) {
if( !empty( $adapters[$x][0] ) ) {
// now grab properties of each
$arr[$adapters[$x][0]] = $this->GetAdaptersProperties( $adapters[$x][0] );
}
}
}
} else {
return -1;
}
} else {
return -1;
}
}
/*
* extended properties for adapters
*/
function GetAdaptersProperties( $adapter )
{
if( !empty( $adapter ) ) {
global $defined;
$cmd = array(); $res = array(); $array = array();
// define our commands to eliminate shitty filters
$cmd['encap'] = $defined['ifconfig'] . " " . $adapter . " | awk '/encap/ { print $3 }'";
$cmd['hwaddr'] = $defined['ifconfig'] . " " . $adapter . " | awk '/HWaddr/ { print $5 }'";
$cmd['ipv4'] = $defined['ifconfig'] . " " . $adapter . " | awk '/inet addr/ { print $2 }'";
$cmd['broadcast'] = $defined['ifconfig'] . " " . $adapter . " | awk '/Bcast/ { print $3 }'";
$cmd['mask'] = $defined['ifconfig'] . " " . $adapter . " | awk '/Mask/ { print $4 }'";
$cmd['ipv6'] = $defined['ifconfig'] . " " . $adapter . " | awk '/inet6 addr/ { print $3 }'";
$cmd['flags'] = $defined['ifconfig'] . " " . $adapter . " | awk '/BROADCAST/ { print $1 $2 $3 $4 }'";
$cmd['RX_packets'] = $defined['ifconfig'] . " " . $adapter . " | awk '/RX packets/ { print $2 }'";
$cmd['RX_errors'] = $defined['ifconfig'] . " " . $adapter . " | awk '/RX packets/ { print $3 }'";
$cmd['RX_dropped'] = $defined['ifconfig'] . " " . $adapter . " | awk '/RX packets/ { print $4 }'";
$cmd['RX_overruns'] = $defined['ifconfig'] . " " . $adapter . " | awk '/RX packets/ { print $5 }'";
$cmd['RX_frame'] = $defined['ifconfig'] . " " . $adapter . " | awk '/RX packets/ { print $6 }'";
$cmd['TX_packets'] = $defined['ifconfig'] . " " . $adapter . " | awk '/TX packets/ { print $2 }'";
$cmd['TX_errors'] = $defined['ifconfig'] . " " . $adapter . " | awk '/TX packets/ { print $3 }'";
$cmd['TX_dropped'] = $defined['ifconfig'] . " " . $adapter . " | awk '/TX packets/ { print $4 }'";
$cmd['TX_overruns'] = $defined['ifconfig'] . " " . $adapter . " | awk '/TX packets/ { print $5 }'";
$cmd['TX_carrier'] = $defined['ifconfig'] . " " . $adapter . " | awk '/TX packets/ { print $6 }'";
$cmd['RX_total'] = $defined['ifconfig'] . " " . $adapter . " | awk '/RX bytes/ { print $2 }'";
$cmd['TX_total'] = $defined['ifconfig'] . " " . $adapter . " | awk '/RX bytes/ { print $6 }'";
// loop over commands and store in an array
foreach( $cmd as $key => $value ) {
$x = shell_exec( $value );
$res[$adapter][$key] = rtrim( $x );
}
// now send it off for processing
$array = $this->FilterSplitDetails( $res );
}
// and last but not least put them in the damn db
$this->ProcessAdapterDetails( $array );
}
/*
* stick our results in the db
*/
function ProcessAdapterDetails( $array )
{
global $defined;
$db = new dbConn;
$val = new ValidateStrings;
$lib = new MiscFunctions;
$insert = ''; $update = ''; $key = ''; $value = array();
// initialize a db connection handle
$dbconn = $db->dbConnect( $defined['dbhost'], $defined['username'], $defined['password'], $defined['dbname'] );
// begin loop
foreach( $array as $key => $value ) {
// sql statements
$insert = "INSERT INTO `conf_adapters` ( `name`, `encap`, `hwaddr`, `ipv4`, `broadcast`, `mask`, `ipv6`, `flags`, `rx_packets`, `rx_errors`, `rx_dropped`, `rx_overruns`, `rx_frame`, `tx_packets`, `tx_errors`, `tx_dropped`, `tx_overruns`, `tx_carrier`, `rx_bytes`, `tx_bytes` ) VALUES ( \"" . $key . "\", \"" . $value['encap'] . "\", \"" . $value['hwaddr'] . "\", \"" . $value['ipv4'] . "\", \"" . $value['broadcast'] . "\", \"" . $value['mask'] . "\", \"" . $value['ipv6'] . "\", \"" . $value['flags'] . "\", \"" . $value['RX_packets'] . "\", \"" . $value['RX_errors'] . "\", \"" . $value['RX_dropped'] . "\", \"" . $value['RX_overruns'] . "\", \"" . $value['RX_frame'] . "\", \"" . $value['TX_packets'] . "\", \"" . $value['TX_errors'] . "\", \"" . $value['TX_dropped'] . "\", \"" . $value['TX_overruns'] . "\", \"" . $value['TX_carrier'] . "\", \"" . $value['RX_total'] . "\", \"" . $value['TX_total'] . "\" )";
$update = "UPDATE `conf_adapters_details` SET `name` = \"" . $key . "\", `encap` = \"" . $value['encap'] . "\", `hwaddr` = \"" . $value['hwaddr'] . "\", `ipv4` = \"" . $value['ipv4'] . "\", `broadcast` = \"" . $value['broadcast'] . "\", `mask` = \"" . $value['mask'] . "\", `ipv6` = \"" . $value['ipv6'] . "\", `flags` = \"" . $value['flags'] . "\", `rx_packets` = \"" . $value['RX_packets'] . "\", `rx_errors` = \"" . $value['RX_errors'] . "\", `rx_dropped` = \"" . $value['RX_dropped'] . "\", `rx_overruns` = \"" . $value['RX_overruns'] . "\", `rx_frame` = \"" . $value['RX_frame'] . "\", `tx_packets` = \"" . $value['TX_packets'] . "\", `tx_errors` = \"" . $value['TX_errors'] . "\", `tx_dropped` = \"" . $value['TX_dropped'] . "\", `tx_overruns` = \"" . $value['TX_overruns'] . "\", `tx_carrier` = \"" . $value['TX_carrier'] . "\", `rx_bytes` = \"" . $value['RX_total'] . "\", `tx_bytes` = \"" . $value['TX_total'] . "\" WHERE `name` = \"" . $key . "\" LIMIT 1";
// determine if an traffic table update should occur
if( $value['RX_total'] !== 0 ) {
// time machine calcs
// (only run once an hour)
$now = $this->GenTime();
// grab some current traffic data
$res = $db->dbQuery( $val->ValidateSQL( "SELECT `time` FROM `conf_traffic` WHERE `time` < \"" . $now . "\" AND `bytes` > 0 AND `interface` = \"" . $key . "\" LIMIT 1", $dbconn ), $dbconn );
$times = $db->dbArrayResults( $res );
// get a value we can compare against an hour
$test = abs( $now - $times[0]['time'] );
// insert some data
if( ( $test > 3600 ) && ( !empty( $value['RX_total'] ) ) ) {
$traffic = "INSERT INTO `conf_traffic` ( `interface`, `bytes`, `time` ) VALUES ( \"" . $key . "\", \"" . $value['RX_total'] . "\", UNIX_TIMESTAMP() )";
$db->dbQuery( $val->ValidateSQL( $traffic, $dbconn ), $dbconn );
}
}
// do the db stuff for our adapters
if( $db->dbQuery( $val->ValidateSQL( $insert, $dbconn ), $dbconn ) !== 0 ) {
if( eregi( "duplicate", $db->dbCatchError() ) ) {
$db->dbQuery( $val->ValidateSQL( $update, $dbconn ), $dbconn );
}
}
}
}
/*
* Filter and split adapter details array
*/
function FilterSplitDetails( $array )
{
foreach( $array as $key => $value ) {
foreach( $value as $index => $data ) {
if( !eregi( "ipv6|hwaddr|flags", $index ) ) {
list( $blank, $data ) = split( ":", $data );
}
$return[$key][$index] = $data;
}
}
return $return;
}
/*
* trim string length
*/
function TrimString( $string, $len )
{ //echo "STRING: " . $string . " LENGTH: " . strlen( $string ) . " ALLOWED LENGTH: " . $len . " FIXED: " . substr( $string, 0, $len - 5 ) . "<br>";
$strlen = strlen( $string );
if( $strlen < $len ) {
return $string;
} else {
return substr( $string, 0, $len - 5 ) . "...";
}
}
/*
* Generate an HTML table from array
*/
function GenTableFromAssocArray( $array )
{
if( count( $array ) === 0 ) {
$table = -1;
} else {
$table = "<table border=0 width=80% cellspacing=5>";
foreach( $array as $key => $value ) {
$table .= "<tr align=center><td nowrap><b>$key</b></td><td> => <td>$value</td></tr>";
}
$table .= "</table>";
}
return $table;
}
/*
* Generate an HTML table from array
*/
function GenTableFromAssocArrayDuplicateHost( $array, $match )
{
if( count( $array ) === 0 ) {
$table = -1;
} else {
$table = "<table border=0 width=80% cellspacing=5>";
$table .= "<tr><td nowrap><b>Overwrite existing?</b></td><td><input type=checkbox name=modify value=modify></td></tr>";