forked from xneelo/ipplan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipplanlib.php
More file actions
executable file
·1648 lines (1399 loc) · 65.4 KB
/
ipplanlib.php
File metadata and controls
executable file
·1648 lines (1399 loc) · 65.4 KB
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
// IPplan v4.92b
// Aug 24, 2001
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
// IPplan version - defined here in core lib, not in config.php
// Format: YYYY.M.D.revision (e.g., 2026.1.9.4 = 4th release on Jan 9, 2026)
define("IPPLAN_VERSION", "2026.1.9.15");
define("DEFAULTROUTE", "0.0.0.0");
define("ALLNETS", "255.255.255.255");
/*********** Browser Detection *********/
/**
* Check if the browser is Internet Explorer or IE Mode (Edge IE Mode)
* Current Branch themes are not supported in IE, so we force classic theme
*/
function isInternetExplorer() {
if (!isset($_SERVER['HTTP_USER_AGENT'])) {
return false;
}
$ua = $_SERVER['HTTP_USER_AGENT'];
// Check for IE 10 and below
if (preg_match('/MSIE\s/', $ua)) {
return true;
}
// Check for IE 11
if (preg_match('/Trident\/.*rv:/', $ua)) {
return true;
}
// Check for Edge IE Mode (sends IE11 user agent)
if (strpos($ua, 'Trident') !== false) {
return true;
}
return false;
}
/*********** Theme helper functions *********/
/**
* Get the current theme identifier
* Returns theme key like 'current-branch-dark', 'classic', etc.
*/
function getCurrentTheme() {
// Force classic theme for Internet Explorer (Current Branch themes not supported)
if (isInternetExplorer()) {
return 'classic';
}
// Check if forced to classic
if (defined('FORCE_CLASSIC_THEME') && FORCE_CLASSIC_THEME) {
return 'classic';
}
// Check cookie for user preference
if (isset($_COOKIE['ipplanTheme']) && !empty($_COOKIE['ipplanTheme'])) {
$theme = $_COOKIE['ipplanTheme'];
// Handle legacy cookie values - convert old 2026- prefix to current-branch-
if (strpos($theme, '2026-') === 0) {
$theme = str_replace('2026-', 'current-branch-', $theme);
}
return $theme;
}
// Fall back to default theme
if (defined('DEFAULT_THEME')) {
return DEFAULT_THEME;
}
// Ultimate fallback
return 'current-branch-dark';
}
/**
* Check if current theme uses the Current Branch sidebar layout
*/
function isCurrentBranchTheme($theme = null) {
if ($theme === null) {
$theme = getCurrentTheme();
}
// Check for current-branch- prefix or legacy 2026- prefix
return (strpos($theme, 'current-branch-') === 0 || strpos($theme, '2026-') === 0);
}
/**
* Backward compatibility alias for isCurrentBranchTheme
* @deprecated Use isCurrentBranchTheme() instead
*/
function is2026Theme($theme = null) {
return isCurrentBranchTheme($theme);
}
/**
* Get CSS file for a theme
*/
function getThemeCssFile($theme = null) {
global $config_themes;
if ($theme === null) {
$theme = getCurrentTheme();
}
if (isset($config_themes[$theme])) {
return $config_themes[$theme];
}
// Fallback to default.css
return 'default.css';
}
/**
* Generate IE warning banner HTML
* Displayed on all pages when Internet Explorer is detected
*/
function getIEWarningBanner() {
if (!isInternetExplorer()) {
return '';
}
return '<div style="background: #fff3cd; color: #856404; padding: 8px 16px; text-align: center; font-size: 13px; border-bottom: 1px solid #ffc107;">
' . my_("Internet Explorer detected. Only the Classic theme is supported in this browser.") . '
</div>';
}
/*********** start of global code which runs for each script *********/
// compress output of all pages - could break things!
// breaks if there is space after last php close tag in script!
// must flush with ob_flush if sending from system() call
// Note: ob_gzhandler can cause issues on IIS/Windows - use NOCOMPRESS to disable
if (!defined("NOCOMPRESS")) {
// Only use gzip if zlib is available and we're not on IIS (which can have issues)
if (function_exists('ob_gzhandler') && extension_loaded('zlib')) {
// Check if running on IIS - may need to disable compression
$isIIS = (isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'IIS') !== false);
if (!$isIIS) {
ob_start("ob_gzhandler");
} else {
// On IIS, use regular output buffering without gzip
ob_start();
}
} else {
ob_start();
}
}
// set the error reporting level for IPplan (PHP 8.2+)
error_reporting(E_ALL ^ E_NOTICE ^ E_DEPRECATED);
// set to the user defined error handler
set_error_handler("myErrorHandler");
/*********** end of global code which runs for each script *********/
// baseaddr is an int, not an ip address
// Test base address to see if it is on valid subnet boundary
function TestBaseAddr($baseaddr, $subnetsize) {
$newsize = $subnetsize-1;
return ($baseaddr & $newsize);
}
// scan a single host to see if it is up
function ScanHost($host, $timeout=2) {
// try port 80, if we connect OK, else if error 111, also OK
$fp = @fsockopen($host, 80, $errno, $errstr, $timeout);
if (!$fp) {
// linux likes code 111, solaris likes 146
if ($errno == 111 or $errno == 146) // connection refused
return 1;
else
return 0;
} else {
fclose ($fp);
return 1;
}
}
// scan ip-range
// expects a range of addresses to scan in nmap range notation
function NmapScan ($range) {
$NMAP = NMAP;
$command = "$NMAP -sP -q -n -oG - ".escapeshellarg($range);
exec($command, $resarr, $retval);
#echo $command;
// error due to safe mode?
if ($retval) {
return FALSE;
}
else {
$ret=array();
foreach ($resarr as $line) {
if(preg_match ("/^Host: ([\d\.]*) \(\).*Status: Up$/", $line, $m)) {
$ret[$m[1]] = 1;
}
}
return $ret;
}
}
// creates a range of addresses to scan in nmap format given start and end
// ip addresses - something like 10.10.1.64-127
function NmapRange($nmapstart, $nmapend) {
#echo $nmapstart." ".$nmapend;
list($so1, $so2, $so3, $so4) = explode(".", $nmapstart);
list($eo1, $eo2, $eo3, $eo4) = explode(".", $nmapend);
$res="";
$res=sprintf("%s.%s.%s.%s",
$so1==$eo1 ? $so1 : $so1."-".$eo1,
$so2==$eo2 ? $so2 : $so2."-".$eo2,
$so3==$eo3 ? $so3 : $so3."-".$eo3,
$so4==$eo4 ? $so4 : $so4."-".$eo4);
return $res;
}
// test for ip addresses between 1.0.0.0 and 255.255.255.255
function testIP($a, $allowzero=FALSE) {
$t = explode(".", $a);
if (sizeof($t) != 4)
return 1;
for ($i = 0; $i < 4; $i++) {
// first octet may not be 0
if ($t[0] == 0 && $allowzero == FALSE)
return 1;
if ($t[$i] < 0 or $t[$i] > 255)
return 1;
if (!is_numeric($t[$i]))
return 1;
};
return 0;
}
// test if string is a valid regex expression
function preg_ispreg($str) {
$prefix = "";
$sufix = "";
if ($str[0] != '^')
$prefix = '^';
if ($str[strlen($str) - 1] != '$')
$sufix = '$';
$estr = preg_replace("'^/'", "\\/", preg_replace("'([^/])/'", "\\1\\/", $str));
if (@preg_match("/".$prefix.$estr.$sufix."/", $str, $matches))
return strcmp($str, $matches[0]) != 0;
return true;
}
// fill subnet - add 0 or 255 as required
// options - 1 for 0, 2 for 255
function completeIP($a, $opt) {
$t = explode(".", $a);
for ($i = 4; $i > sizeof($t); $i--) {
if ($opt == 1)
$a = $a.".0";
else
$a = $a.".255";
}
return $a;
}
// php function ip2long is broken!!! (mod_php4.0.4p1)
function inet_aton($a) {
$inet = 0.0;
if (count($t = explode(".", $a)) != 4) return 0;
//$t = explode(".", $a);
for ($i = 0; $i < 4; $i++) {
$inet *= 256.0;
$inet += $t[$i];
};
return $inet;
}
// php function ip2long is broken!!! (mod_php4.0.4p1)
function inet_aton3($a) {
$inet = 0.0;
if (count($t = explode(".", $a)) != 4) return 0;
//$t = explode(".", $a);
for ($i = 1; $i < 4; $i++) {
$inet *= 256.0;
$inet += $t[$i];
};
return $inet;
}
// php function long2ip is broken!!! (mod_php4.0.4p1)
function inet_ntoa($n) {
$t=array(0,0,0,0);
$msk = 16777216.0;
$n += 0.0;
if ($n < 1)
return('0.0.0.0');
for ($i = 0; $i < 4; $i++) {
$k = (int) ($n / $msk);
$n -= $msk * $k;
$t[$i]= $k;
$msk /=256.0;
};
$a=join('.', $t);
return($a);
}
// returns the number of bits in the mask cisco style
function inet_bits($n) {
if ($n == 1)
return 32;
else
return 32-strlen(decbin($n-1));
}
/*********** Pagination / Rows Per Page *********/
/**
* Get the effective rows per page value
* Checks user preference cookie first, falls back to MAXTABLESIZE config default
* Also checks for page-specific override via 'rpp' GET parameter
* When 'rpp' is passed via URL, it also updates the user's cookie preference
*
* @return int The number of rows to display per page
*/
function getRowsPerPage() {
// Valid options - must be powers of 2
$validOptions = array(64, 128, 256, 512);
// Check for page-specific override via GET parameter
if (isset($_GET['rpp']) && in_array((int)$_GET['rpp'], $validOptions)) {
$rpp = (int)$_GET['rpp'];
// Also update the cookie so this becomes the user's default
setcookie("ipplanRowsPerPage", "$rpp", time() + 10000000, "/");
$_COOKIE['ipplanRowsPerPage'] = $rpp;
return $rpp;
}
// Check user preference cookie
if (isset($_COOKIE['ipplanRowsPerPage'])) {
$userPref = (int)$_COOKIE['ipplanRowsPerPage'];
if (in_array($userPref, $validOptions)) {
return $userPref;
}
}
// Fall back to config default
return MAXTABLESIZE;
}
/**
* Display a "Records per page" dropdown selector
* Preserves existing URL parameters when changing rows per page
*
* @param object $container The HTML container to insert into
* @param string $position Position: 'top' (float right), 'bottom' (float right), 'inline' (default, no float)
* @return void
*/
function displayRowsPerPageSelector($container, $position = 'inline') {
$options = array(64, 128, 256, 512);
$current = getRowsPerPage();
// Build the current URL with existing parameters, minus 'rpp' and 'block'
$params = $_GET;
unset($params['rpp']);
unset($params['block']); // Reset to first page when changing rows per page
$baseUrl = $_SERVER['PHP_SELF'];
$queryString = http_build_query($params);
$separator = $queryString ? '&' : '';
// Style based on position
if ($position === 'inline') {
// For use inside table-cell layout (display: table-cell wrapper)
$containerStyle = 'display: table-cell; vertical-align: middle; text-align: right; padding-left: 30px;';
} else if ($position === 'top' || $position === 'bottom') {
$containerStyle = 'float: right; margin: 0;';
} else {
$containerStyle = 'margin: 10px 0; display: inline-block;';
}
$html = '<div class="rows-per-page-selector" style="' . $containerStyle . '">';
$html .= '<label style="margin-right: 8px; font-size: 12px;">' . my_("Records per page:") . '</label>';
$html .= '<select onchange="window.location.href=\'' . htmlspecialchars($baseUrl) . '?' . htmlspecialchars($queryString) . $separator . 'rpp=\'+this.value" style="padding: 3px 6px; font-size: 12px;">';
foreach ($options as $opt) {
$selected = ($opt == $current) ? ' selected' : '';
$html .= '<option value="' . $opt . '"' . $selected . '>' . $opt . '</option>';
}
$html .= '</select>';
$html .= '</div>';
insert($container, block($html));
}
/**
* Display a list header with title on left and rows per page selector on right
* Uses display:table to match the natural width of the content below (like a table)
*
* @param object $w The HTML container to insert into
* @param string $title The title/heading to display (e.g., domain name)
* @param bool $showRowsSelector Whether to show the rows per page dropdown
* @return void
*/
function displayListHeader($w, $title, $showRowsSelector = true) {
$html = '<div class="list-header-wrapper" style="display: table; width: auto; min-width: 100%; margin: 10px 0;">';
$html .= '<div style="display: table-row;">';
$html .= '<div style="display: table-cell; vertical-align: middle;"><strong>' . $title . '</strong></div>';
if ($showRowsSelector) {
// Build selector inline
$options = array(64, 128, 256, 512);
$current = getRowsPerPage();
$params = $_GET;
unset($params['rpp']);
unset($params['block']);
$baseUrl = $_SERVER['PHP_SELF'];
$queryString = http_build_query($params);
$separator = $queryString ? '&' : '';
$html .= '<div style="display: table-cell; vertical-align: middle; text-align: right; padding-left: 30px;">';
$html .= '<label style="margin-right: 8px; font-size: 12px;">' . my_("Records per page:") . '</label>';
$html .= '<select onchange="window.location.href=\'' . htmlspecialchars($baseUrl) . '?' . htmlspecialchars($queryString) . $separator . 'rpp=\'+this.value" style="padding: 3px 6px; font-size: 12px;">';
foreach ($options as $opt) {
$selected = ($opt == $current) ? ' selected' : '';
$html .= '<option value="' . $opt . '"' . $selected . '>' . $opt . '</option>';
}
$html .= '</select>';
$html .= '</div>';
}
$html .= '</div></div>';
insert($w, block($html));
}
/**
* Display a list footer with optional content on left and rows per page selector on right
* Uses display:table to match the natural width of the content above (like a table)
*
* @param object $w The HTML container to insert into
* @param string $leftContent Optional HTML content for the left side (e.g., action buttons)
* @param bool $showRowsSelector Whether to show the rows per page dropdown
* @return void
*/
function displayListFooter($w, $leftContent = '', $showRowsSelector = true) {
$html = '<div class="list-footer-wrapper" style="display: table; width: auto; min-width: 100%; margin: 10px 0;">';
$html .= '<div style="display: table-row;">';
$html .= '<div style="display: table-cell; vertical-align: middle;">' . $leftContent . '</div>';
if ($showRowsSelector) {
// Build selector inline
$options = array(64, 128, 256, 512);
$current = getRowsPerPage();
$params = $_GET;
unset($params['rpp']);
unset($params['block']);
$baseUrl = $_SERVER['PHP_SELF'];
$queryString = http_build_query($params);
$separator = $queryString ? '&' : '';
$html .= '<div style="display: table-cell; vertical-align: middle; text-align: right; padding-left: 30px;">';
$html .= '<label style="margin-right: 8px; font-size: 12px;">' . my_("Records per page:") . '</label>';
$html .= '<select onchange="window.location.href=\'' . htmlspecialchars($baseUrl) . '?' . htmlspecialchars($queryString) . $separator . 'rpp=\'+this.value" style="padding: 3px 6px; font-size: 12px;">';
foreach ($options as $opt) {
$selected = ($opt == $current) ? ' selected' : '';
$html .= '<option value="' . $opt . '"' . $selected . '>' . $opt . '</option>';
}
$html .= '</select>';
$html .= '</div>';
}
$html .= '</div></div>';
insert($w, block($html));
}
/**
* Display page navigation showing record counts (e.g., "1-128", "129-256")
* This is a cleaner alternative to DisplayBlock that shows actual record numbers
*
* @param object $w The HTML container to insert into
* @param int $totalRecords Total number of records
* @param int $currentBlock Current block number (0-based)
* @param string $baseParams URL parameters to preserve (e.g., "&cust=1&domain=example.com")
* @return void
*/
function displayPaginationNav($w, $totalRecords, $currentBlock, $baseParams) {
$rowsPerPage = getRowsPerPage();
$totalBlocks = ceil($totalRecords / $rowsPerPage);
if ($totalBlocks <= 1) {
return; // No pagination needed
}
$html = '<div class="pagination-nav" style="margin: 10px 0; font-size: 12px;">';
$html .= my_("Pages:") . ' ';
for ($i = 0; $i < $totalBlocks; $i++) {
$startRec = ($i * $rowsPerPage) + 1;
$endRec = min(($i + 1) * $rowsPerPage, $totalRecords);
$label = $startRec . '-' . $endRec;
$url = $_SERVER["PHP_SELF"] . "?block=" . $i . $baseParams;
if ($i == $currentBlock) {
$html .= '<strong>[' . $label . ']</strong> ';
} else {
$html .= '<a href="' . htmlspecialchars($url) . '">' . $label . '</a> ';
}
// Add separator between links
if ($i < $totalBlocks - 1) {
$html .= '| ';
}
}
$html .= '</div>';
insert($w, block($html));
}
// display various blocks of subnet
// if $fldindex is set use this as column in dfb to skip
// Note: For cleaner record-count based pagination, use displayPaginationNav() instead
function DisplayBlock($w, $row, $totcnt, $anchor, $fldindex="") {
$rowsPerPage = getRowsPerPage();
$cnt=intval($totcnt/$rowsPerPage);
$vars=$_SERVER["PHP_SELF"]."?block=".$cnt.$anchor;
if ($totcnt % $rowsPerPage == 0) {
insert($w,anchor($vars, $fldindex ? $row[$fldindex] : inet_ntoa($row["baseaddr"])));
}
if ($totcnt % $rowsPerPage == $rowsPerPage-1) {
insert($w,text(" - "));
insert($w,anchor($vars, $fldindex ? $row[$fldindex] : inet_ntoa($row["baseaddr"])));
insert($w,textbr());
}
return $vars;
}
/*********** Error Handling for Resource-Intensive Operations *********/
/**
* Custom shutdown handler to catch fatal errors like memory exhaustion or timeout
* Call registerResourceErrorHandler() at the start of resource-intensive operations
*/
function resourceErrorShutdownHandler() {
$error = error_get_last();
if ($error !== null) {
$errorTypes = array(E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR);
if (in_array($error['type'], $errorTypes)) {
// Check for memory or timeout related errors
$isResourceError = (
stripos($error['message'], 'memory') !== false ||
stripos($error['message'], 'timeout') !== false ||
stripos($error['message'], 'execution time') !== false ||
stripos($error['message'], 'exhausted') !== false
);
if ($isResourceError) {
// Clear any output buffers
while (ob_get_level()) {
ob_end_clean();
}
$memLimit = ini_get('memory_limit');
$maxExecTime = ini_get('max_execution_time');
// Output a helpful error page
echo '<!DOCTYPE html><html><head><title>Resource Limit Exceeded - IPplan</title>';
echo '<style>body{font-family:Arial,sans-serif;margin:40px;background:#f5f5f5;}';
echo '.error-box{background:#fff;border:1px solid #dc3545;border-radius:8px;padding:30px;max-width:700px;margin:0 auto;box-shadow:0 2px 10px rgba(0,0,0,0.1);}';
echo '.error-title{color:#dc3545;margin:0 0 20px 0;font-size:24px;}';
echo '.error-message{color:#333;line-height:1.6;}';
echo '.settings-box{background:#f8f9fa;border:1px solid #dee2e6;border-radius:4px;padding:15px;margin:20px 0;font-family:monospace;font-size:13px;}';
echo '.solution-list{margin:15px 0;padding-left:20px;}';
echo '.solution-list li{margin:8px 0;}';
echo '.back-link{display:inline-block;margin-top:20px;padding:10px 20px;background:#0097a7;color:#fff;text-decoration:none;border-radius:4px;}';
echo '.back-link:hover{background:#00838f;}';
echo '</style></head><body>';
echo '<div class="error-box">';
echo '<h1 class="error-title">⚠️ Resource Limit Exceeded</h1>';
echo '<div class="error-message">';
echo '<p>The operation exceeded PHP resource limits. This typically happens when:</p>';
echo '<ul class="solution-list">';
echo '<li>Importing a large DNS zone with many records</li>';
echo '<li>Processing a very large dataset</li>';
echo '<li>PHP memory or execution time limits are too low</li>';
echo '</ul>';
echo '<div class="settings-box">';
echo '<strong>Current PHP Settings:</strong><br>';
echo 'memory_limit = ' . htmlspecialchars($memLimit) . '<br>';
echo 'max_execution_time = ' . htmlspecialchars($maxExecTime) . ' seconds';
echo '</div>';
echo '<p><strong>Solutions:</strong></p>';
echo '<ul class="solution-list">';
echo '<li>Ask your system administrator to increase <code>memory_limit</code> in php.ini (e.g., to 256M or 512M)</li>';
echo '<li>Ask your system administrator to increase <code>max_execution_time</code> in php.ini (e.g., to 300 or 600)</li>';
echo '<li>For IIS: Modify these settings in the PHP configuration for your site</li>';
echo '<li>Try importing smaller portions of data if possible</li>';
echo '</ul>';
echo '<a href="javascript:history.back()" class="back-link">← Go Back</a>';
echo '</div></div></body></html>';
exit;
}
}
}
}
/**
* Register the resource error handler for operations that may hit memory/timeout limits
* Call this at the start of resource-intensive operations like DNS zone transfers
*/
function registerResourceErrorHandler() {
register_shutdown_function('resourceErrorShutdownHandler');
}
// displays customer drop down box - requires a working form
// $submit parameter allows drop down to just be displayed, normal
// behaviour will be to submit to self
function myCustomerDropDown($ds, $f1, $cust, $grps, $submit=TRUE) {
// need to see cookie!
global $ipplanCustomer, $displayall;
$custset=0;
$cust=floor($cust); // dont trust $cust as it could
// come from form post
$ipplanCustomer=floor($ipplanCustomer);
// display customer drop down list, nothing to display, just exit
if (!$result=$ds->GetCustomerGrp(0))
return 0;
// do this here else will do extra queries for every customer
$adminuser=$ds->TestGrpsAdmin($grps);
insert($f1,textbrbr(my_("Customer/autonomous system")));
$lst=array();
while($row=$result->FetchRow()) {
// ugly kludge with global variable!
// remove all from list if global searching is not available
if (!$displayall and strtolower($row["custdescrip"])=="all")
continue;
// strip out customers user may not see due to not being member
// of customers admin group. $grps array could be empty if anonymous
// access is allowed!
if(!$adminuser) {
if(!empty($grps)) {
if(!in_array($row["admingrp"], $grps))
continue;
}
}
$col=$row["customer"];
// make customer first customer in database
if (!$cust) {
$cust=$col;
$custset=1; // remember that customer was blank
}
// only make customer same as cookie if customer actually
// still exists in database, else will cause loop!
if ($custset) {
if ($col == $ipplanCustomer)
$cust=$ipplanCustomer;
}
$lst["$col"]=$row["custdescrip"];
}
if ($submit)
insert($f1,selectbox($lst,
array("name"=>"cust", "onChange"=>"submit()"),
$cust));
else
insert($f1,selectbox($lst,
array("name"=>"cust"),
$cust));
return $cust;
}
// displays area drop down box - requires a working form
// does not matter if areaindex is out of range, will pick "No range"
function myAreaDropDown($ds, $f1, $cust, $areaindex, $displayall=FALSE) {
global $notinrange; // ugly global var
$cust=floor($cust); // dont trust $cust as it could
// come from form post
$areaindex=floor($areaindex);
if ($displayall) {
// display all - only used on createrange
$result=$ds->GetArea($cust, 0);
}
else {
// display only those areas that have ranges - all other cases
$result=$ds->GetArea($cust, -1);
}
// don't bother if there are no records, will always display "No area"
insert($f1,textbrbr(my_("Area (optional)")));
$lst=array();
$lst["0"]=my_("No area selected");
if ($notinrange) {
$lst["-1"]=my_("All subnets not part of range");
}
while($result and $row = $result->FetchRow()) {
$col=$row["areaindex"];
$lst["$col"]=inet_ntoa($row["areaaddr"])." - ".$row["descrip"];
}
insert($f1,selectbox($lst,
array("name"=>"areaindex","onChange"=>"submit()"),
$areaindex));
return $areaindex;
}
// displays range drop down box - requires a working form
function myRangeDropDown($ds, $f2, $cust, $areaindex) {
$cust=floor($cust); // dont trust $cust as it could
// come from form post
$areaindex=floor($areaindex);
// display range drop down list
if ($areaindex)
$result=$ds->GetRangeInArea($cust, $areaindex);
else
$result=$ds->GetRange($cust, 0);
// don't bother if there are no records, will always display "No range"
insert($f2,textbrbr(my_("Range (optional)")));
$lst=array();
$lst["0"]=my_("No range selected");
while($row = $result->FetchRow()) {
$col=$row["rangeindex"];
$lst["$col"]=inet_ntoa($row["rangeaddr"])."/".inet_ntoa(inet_aton(ALLNETS)-$row["rangesize"]+1).
"/".inet_bits($row["rangesize"])." - ".$row["descrip"];
}
insert($f2,selectbox($lst,
array("name"=>"rangeindex")));
}
// displays error messages and terminates the programs execution
// should only be used for terminal errors that cannot recover (database etc)
// will also ignore previous output generated for the HTML page
// takes optional terminate parameter - if FALSE, script does not terminate
// used for displaying non-fatal form errors
// $message is can be a number of errors seperated by \n
function myError($w, $p, $message, $terminate=TRUE) {
// Changed by Stephen, 12/24/2004
// $w now equals the DIV container for the class.
// $p now equals the pointer to the HTML container.
// display error message
if (!empty($message)) {
$message=nl2br(htmlspecialchars($message));
insert($w,span($message, array("class"=>"textError")));
}
if ($terminate) {
printhtml($p);
exit;
}
}
// wrapper around gettext function to check if gettext is available first
// gettext is used to internationalize a program
// see http://www.gnu.org/software/gettext
// http://zez.org/article/articleview/42/
// http://www.php-er.com/chapters/Gettext_Functions.html
function my_($message) {
return extension_loaded("gettext") ? gettext($message) : $message;
}
// set the language to use
// cookie is in form <2 letter country code>;<path to ipplan root>
function myLanguage($langcookie) {
if(extension_loaded("gettext")) {
// split language and path from cookie
list($lang,$path) = explode(":", $langcookie, 2);
// initialize gettext for Windows
if (strpos(strtoupper(PHP_OS),'WIN') !== false) {
putenv("LANG=$lang");
$locale=setlocale(LC_ALL, $lang);
// Specify location of translation tables
bindtextdomain ("messages", $path."\locale");
}
// and the rest
else {
// Set language environment variable
// not required anymore
//putenv("LANG=$lang");
$locale=setlocale(LC_ALL, $lang);
if (!$locale and $lang!= "en_EN" and DEBUG) {
echo "Setting locale failed - the language choosen is probably not installed correctly\n";
}
// Specify location of translation tables
bindtextdomain ("messages", $path."/locale");
}
// Choose domain
textdomain ("messages");
}
}
// returns the directory tree base URL for menu construction
// if constant BASE_URL is defined, use that instead
function base_url() {
$BASE_URL = BASE_URL;
if (empty($BASE_URL)) {
// dirname strips trailing slash!
$tmp = dirname($_SERVER["PHP_SELF"]);
//$tmp = dirname($_SERVER["SCRIPT_NAME"]);
$tmp = preg_replace("/\\/user$/i", "", $tmp);
$tmp = preg_replace("/\\/admin$/i", "", $tmp);
// Normalize backslashes to forward slashes (Windows compatibility)
$tmp = str_replace('\\', '/', $tmp);
// installed in root of a virtual server? then return empty path
// Handle various edge cases for root installations
if ($tmp == "/" || $tmp == "" || $tmp == "." || $tmp == '//') return "";
return $tmp;
}
else {
return $BASE_URL;
}
}
// returns the base path under which IPplan is installed
function base_dir() {
// dirname strips trailing slash!
$tmp = dirname(__FILE__);
//$tmp = dirname($_SERVER["SCRIPT_FILENAME"]);
$tmp = preg_replace("/\\/user$/i", "", $tmp);
$tmp = preg_replace("/\\/admin$/i", "", $tmp);
return $tmp;
}
// returns a complete URI for use with Location: header. Returns relative URI
// if complete URI cannot be worked out
function location_uri($relative_url) {
// running Apache or something or server that has HTTP_HOST set?
if (isset($_SERVER['HTTP_HOST'])) {
return "http" . (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"]=='on'?"s":"")
."://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/".$relative_url;
}
// no, we will hope for best with a relative URI - this is against HTTP specs, but too bad
else {
return $relative_url;
}
}
// finds URL's in a string and converts them to links
function linkURL($txt) {
return preg_replace(
'/(http|ftp|telnet)+(s)?:(\/\/)((\w|\.)+)(\/)?(\S+)?/i',
'<a href="\0">\4</a>', $txt);
}
// This function returns the username of the current user
// as reported by PHP, with special handling for IIS.
// First, copy PHP server vars into a new var called MY_SERVER_VARS
// (vars might get updated if running on IIS)
function getAuthUsername() {
// If user has logged out, don't report username even if browser sends cached credentials
if (isset($_COOKIE["ipplanNoAuth"]) && $_COOKIE["ipplanNoAuth"] == "yes") {
return "";
}
$MY_SERVER_VARS = $_SERVER;
// Special handling for IIS - use HTTP_AUTHORIZATION instead of PHP_AUTH_*
// (see http://www.php.net/features.http-auth - example 34.3)
if ( (!(isset($MY_SERVER_VARS[AUTH_VAR]))) &&
(isset($MY_SERVER_VARS["HTTP_AUTHORIZATION"]))) {
if (preg_match("/^Basic /", $MY_SERVER_VARS["HTTP_AUTHORIZATION"]) ) {
list($MY_SERVER_VARS[AUTH_VAR],$MY_SERVER_VARS["PHP_AUTH_PW"]) =
explode(':',base64_decode(substr($MY_SERVER_VARS["HTTP_AUTHORIZATION"], 6)));
}
}
// If it's not IIS, then the username should already be in AUTH_VAR
return (isset($MY_SERVER_VARS[AUTH_VAR]) ? $MY_SERVER_VARS[AUTH_VAR] : "");
}
// draw title block
function myheading($q, $title, $displaymenu=true) {
// Generate the correct prefix for URLs in menu.
$BASE_URL = base_url();
$BASE_DIR = base_dir();
$myDirPath = $BASE_DIR . '/menus/';
$myWwwPath = $BASE_URL . '/menus/';
// Get current theme
$currentTheme = getCurrentTheme();
$isCurrentBranch = isCurrentBranchTheme($currentTheme);
$themeCssFile = getThemeCssFile($currentTheme);
// create the html page HEAD section
insert($q, $header=wheader("IPPlan - $title"));
insert($header, generic("meta",array("http-equiv"=>"Content-Type","content"=>"text/html; charset=UTF-8")));
insert($header, generic("meta",array("name"=>"viewport","content"=>"width=device-width, initial-scale=1")));
// Load theme CSS
insert($header, generic("link",array("rel"=>"stylesheet","href"=>"$BASE_URL/themes/$themeCssFile")));
// For Current Branch themes, use sidebar layout
if ($isCurrentBranch) {
return myheading_current_branch($q, $header, $title, $displaymenu, $BASE_URL, $BASE_DIR);
}
// Classic theme layout (original code path)
insert($q, $w=container("div",array("class"=>"matte")));
// Add IE warning banner if needed
$ieBanner = getIEWarningBanner();
if ($ieBanner) {
insert($w, block($ieBanner));
}
// Load PHPLayersMenu for classic themes
if ($displaymenu) {
require_once $myDirPath . 'lib/PHPLIB.php';
require_once $myDirPath . 'lib/layersmenu-common.inc.php';
require_once $myDirPath . 'lib/layersmenu.inc.php';
require_once $BASE_DIR . '/menudefs.php';
eval("\$ADMIN_MENU = \"$ADMIN_MENU\";");
insert($header, generic("link",array("rel"=>"stylesheet","href"=>"$myWwwPath"."layersmenu-gtk2.css")));
insert($w, script("",array("language"=>"JavaScript","type"=>"text/javascript","src"=> $myWwwPath."libjs/layersmenu-browser_detection.js")));
insert($w, script("",array("language"=>"JavaScript","type"=>"text/javascript","src"=> $myWwwPath . 'libjs/layersmenu-library.js')));
insert($w, script("",array("language"=>"JavaScript","type"=>"text/javascript","src"=> $myWwwPath . 'libjs/layersmenu.js')));
$mid= new LayersMenu(6, 7, 2, 1);
$mid->setDirroot ($BASE_DIR.'/menus/');
$mid->setLibjsdir($BASE_DIR.'/menus/libjs/');
$mid->setImgdir ($BASE_DIR.'/menus/menuimages/');
$mid->setImgwww ($BASE_URL.'/menus/menuimages/');
$mid->setIcondir ($BASE_DIR.'/menus/menuicons/');
$mid->setIconwww ($BASE_URL.'/menus/menuicons/');
$mid->setTpldir ($BASE_DIR.'/menus/templates/');
$mid->SetMenuStructureString($ADMIN_MENU);
$mid->setIconsize(16, 16);
$mid->parseStructureForMenu('hormenu1');