forked from phpipam/phpipam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·375 lines (327 loc) · 14.8 KB
/
index.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
<?php
/* config */
if (!file_exists("config.php")) { die("<br><hr>-- config.php file missing! Please copy default config file `config.dist.php` to `config.php` and set configuration! --<hr><br>phpipam installation documentation: <a href='http://phpipam.net/documents/installation/'>http://phpipam.net/documents/installation/</a>"); }
/* site functions */
require_once( 'functions/functions.php' );
/* API check - pricess API if requested */
if ($Rewrite->is_api ()) {
require ("api/index.php");
}
else {
header("Cache-Control: no-cache, must-revalidate"); //HTTP 1.1
header("Pragma: no-cache"); //HTTP 1.0
header("Expires: Sat, 26 Jul 2016 05:00:00 GMT"); //Date in the past
# if not install fetch settings etc
if($_GET['page']!="install" ) {
# database object
$Database = new Database_PDO;
# check if this is a new installation
require('functions/checks/check_db_install.php');
# initialize objects
$Result = new Result;
$User = new User ($Database);
$Sections = new Sections ($Database);
$Subnets = new Subnets ($Database);
$Tools = new Tools ($Database);
$Addresses = new Addresses ($Database);
$Log = new Logging ($Database);
# reset url for base
$url = $User->createURL ();
}
/** include proper subpage **/
if($_GET['page']=="install") { require("app/install/index.php"); }
elseif($_GET['page']=="2fa") { require("app/login/2fa/index.php"); }
elseif($_GET['page']=="upgrade") { require("app/upgrade/index.php"); }
elseif($_GET['page']=="login") { require("app/login/index.php"); }
elseif($_GET['page']=="temp_share") { require("app/temp_share/index.php"); }
elseif($_GET['page']=="request_ip") { require("app/login/index.php"); }
elseif($_GET['page']=="opensearch") { require("app/tools/search/opensearch.php"); }
elseif($_GET['page']=="saml2") { require("app/saml2/index.php"); }
elseif($_GET['page']=="saml2-idp") { require("app/saml2/idp.php"); }
else {
# verify that user is logged in
$User->check_user_session();
# make upgrade and php build checks
include('functions/checks/check_db_upgrade.php'); # check if database needs upgrade
include('functions/checks/check_php_build.php'); # check for support for PHP modules and database connection
if(@$_GET['switch'] && $_SESSION['realipamusername'] && @$_GET['switch'] == "back"){
$_SESSION['ipamusername'] = $_SESSION['realipamusername'];
unset($_SESSION['realipamusername']);
print '<script>window.location.href = "'.create_link(null).'";</script>';
}
# set default pagesize
if(!isset($_COOKIE['table-page-size'])) {
setcookie_samesite("table-page-size", 50, 2592000, false);
}
?>
<!DOCTYPE HTML>
<html lang="en">
<head>
<base href="<?php print $url.BASE; ?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Cache-Control" content="no-cache, must-revalidate">
<meta name="title" content="<?php print $title = $User->get_site_title ($_GET); ?>">
<?php if(defined('IS_DEMO')) { ?>
<meta name="Description" content="phpIPAM demo page. phpIPAM is an open-source web IP address management application. Its goal is to provide light and simple IP address management application. It is ajax-based using jQuery libraries, it uses php scripts and javascript and some HTML5/CSS3 features. More info on phpipam website.">
<meta name="robots" content="index, follow">
<?php } else { ?>
<meta name="robots" content="noindex, nofollow">
<meta name="Description" content="">
<?php } ?>
<meta http-equiv="X-UA-Compatible" content="IE=9" >
<meta name="viewport" content="width=device-width, initial-scale=0.7, maximum-scale=1, user-scalable=yes">
<!-- chrome frame support -->
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<!-- title -->
<title><?php print $title; ?></title>
<!-- OpenSearch -->
<link rel="search" type="application/opensearchdescription+xml" href="/?page=opensearch" title="Search <?php print $User->settings->siteTitle; ?>">
<!-- css -->
<link rel="shortcut icon" type="image/png" href="css/images/favicon.png?v=<?php print SCRIPT_PREFIX; ?>">
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap.min.css?v=<?php print SCRIPT_PREFIX; ?>">
<link rel="stylesheet" type="text/css" href="css/font-awesome/font-awesome.min.css?v=<?php print SCRIPT_PREFIX; ?>">
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-switch.min.css?v=<?php print SCRIPT_PREFIX; ?>">
<link rel="stylesheet" type="text/css" href="css/bootstrap-table/bootstrap-table.min.css?v=<?php print SCRIPT_PREFIX; ?>">
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-custom.css?v=<?php print SCRIPT_PREFIX; ?>">
<?php if ($User->user->ui_theme!="white") { ?>
<link rel="stylesheet" type="text/css" href="css/bootstrap/bootstrap-custom-<?php print $User->user->ui_theme; ?>.css?v=<?php print SCRIPT_PREFIX; ?>">
<?php } ?>
<?php if ($User->settings->enableThreshold=="1") { ?>
<link rel="stylesheet" type="text/css" href="css/slider.css?v=<?php print SCRIPT_PREFIX; ?>">
<?php } ?>
<!-- js -->
<script src="js/jquery-3.7.1.min.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<script src="js/jclock.jquery.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<?php if($_GET['page']=="login" || $_GET['page']=="request_ip") { ?>
<script src="js/login.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<?php } ?>
<script src="js/magic.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<script src="js/bootstrap.min.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<script src="js/bootstrap-switch.min.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<!-- bootstrap table -->
<script src="js/bootstrap-table/bootstrap-table.min.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<script src="js/bootstrap-table/bootstrap-table-cookie.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<!--[if lt IE 9]>
<script src="js/dieIE.js"></script>
<![endif]-->
<?php if ($User->settings->enableLocations=="1") { ?>
<link rel="stylesheet" href="css/leaflet.css"/>
<script src="js/leaflet.js"></script>
<link rel="stylesheet" href="css/leaflet.fullscreen.css"/>
<script src="js/leaflet.fullscreen.min.js"></script>
<?php } ?>
<!-- jQuery UI -->
<script src="js/jquery-ui-1.12.1.custom.min.js?v=<?php print SCRIPT_PREFIX; ?>"></script>
<?php if(defined('IS_DEMO')) { ?>
<!-- GA -->
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-11778671-10']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
<?php } ?>
</head>
<!-- body -->
<body>
<!-- wrapper -->
<div class="wrapper">
<!-- jQuery error -->
<div class="jqueryError">
<div class='alert alert-danger' style="width:450px;margin:auto">jQuery error!
<div class="jqueryErrorText"></div><br>
<a href="<?php print create_link(null); ?>" class="btn btn-sm btn-default" id="hideError" style="margin-top:0px;">Hide</a>
</div>
</div>
<!-- Popups -->
<div id="popupOverlay" class="popupOverlay">
<div id="popup" class="popup popup_w400"></div>
<div id="popup" class="popup popup_w500"></div>
<div id="popup" class="popup popup_w700"></div>
<div id="popup" class="popup popup_wmasks"></div>
<div id="popup" class="popup popup_max"></div>
</div>
<div id="popupOverlay2">
<div id="popup" class="popup popup_w400"></div>
<div id="popup" class="popup popup_w500"></div>
<div id="popup" class="popup popup_w700"></div>
<div id="popup" class="popup popup_wmasks"></div>
<div id="popup" class="popup popup_max"></div>
</div>
<!-- loader -->
<div class="loading"><?php print _('Loading');?>...<br><i class="fa fa-spinner fa-spin"></i></div>
<!-- header -->
<div class="row" id="header">
<!-- logo -->
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
<?php
if(file_exists( dirname(__FILE__)."/css/images/logo/logo.png")) {
// set width
$logo_width = isset($config['logo_width']) ? $config['logo_width'] : 220;
print "<img style='max-width:".$logo_width."px;margin:10px;margin-top:20px;' src='css/images/logo/logo.png'>";
}
?>
</div>
<!-- title -->
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<div class="hero-pusher hidden-xs hidden-sm"></div>
<div class="hero-unit">
<a href="<?php print create_link(null); ?>"><?php print $User->settings->siteTitle; ?></a>
<p class="muted">
<?php
$title = str_replace(" / ", "<span class='divider'>/</span>", $title);
$tmp = pf_explode($User->settings->siteTitle, $title);
unset($tmp[0]);
print implode($User->settings->siteTitle, $tmp);
?>
</p>
</div>
</div>
<!-- usermenu -->
<div class="col-lg-3 col-lg-offset-0 col-md-3 col-md-offset-0 col-sm-6 col-sm-offset-6 col-xs-12 " id="user_menu">
<?php include('app/sections/user-menu.php'); ?>
</div>
</div>
<!-- maintaneance mode -->
<?php
$text_append_maint = $User->is_admin(false) ? "<a class='btn btn-xs btn-default open_popup' data-script='app/admin/settings/remove-maintaneance.php' data-class='400' data-action='edit'>"._("Remove")."</a>" : "";
if($User->settings->maintaneanceMode == "1") { $Result->show("warning text-center nomargin", "<i class='fa fa-info'></i> "._("System is running in maintenance mode")." !".$text_append_maint, false); }
?>
<!-- page sections / menu -->
<div class="content">
<div id="sections_overlay">
<?php if($_GET['page']!="login" && $_GET['page']!="request_ip" && $_GET['page']!="upgrade" && $_GET['page']!="install" && $User->user->passChange!="Yes") include('app/sections/index.php');?>
</div>
</div>
<!-- content -->
<div class="content_overlay">
<div class="container-fluid" id="mainContainer">
<?php
/* error */
if($_GET['page'] == "error") {
print "<div id='error' class='container'>";
include_once('app/error.php');
print "</div>";
}
/* password reset required */
elseif($User->user->passChange=="Yes") {
print "<div id='dashboard' class='container'>";
include_once("app/tools/pass-change/form.php");
print "</div>";
}
/* dashboard */
elseif(!isset($_GET['page']) || $_GET['page'] == "dashboard") {
print "<div id='dashboard'>";
include_once("app/dashboard/index.php");
print "</div>";
}
/* widgets */
elseif($_GET['page']=="widgets") {
print "<div id='dashboard' class='container'>";
include_once("app/dashboard/widgets/index.php");
print "</div>";
}
/* all sections */
elseif($_GET['page']=="subnets" && is_blank($_GET['section'])) {
print "<div id='dashboard' class='container'>";
include_once("app/sections/all-sections.php");
print "</div>";
}
/* content */
else {
print "<table id='subnetsMenu'>";
print "<tr>";
# fix for empty section
if( isset($_GET['section']) && (is_blank(@$_GET['section'])) ) { unset($_GET['section']); }
# hide left menu
if( ($_GET['page']=="tools"||$_GET['page']=="administration") && !isset($_GET['section'])) {
//we dont display left menu on empty tools and administration
}
else {
# left menu
print "<td id='subnetsLeft'>";
print "<div id='leftMenu' class='menu-$_GET[page]'>";
if($_GET['page'] == "subnets" || $_GET['page'] == "vlan" ||
$_GET['page'] == "vrf" || $_GET['page'] == "folder") { include("app/subnets/subnets-menu.php"); }
else if ($_GET['page'] == "tools") { include("app/tools/tools-menu.php"); }
else if ($_GET['page'] == "administration") { include("app/admin/admin-menu.php"); }
print "</div>";
print "</td>";
}
# content
print "<td id='subnetsContent'>";
print "<div class='row menu-$_GET[page]' id='content'>";
# subnets
if ($_GET['page']=="subnets") {
if(@$_GET['sPage'] == "address-details") { include("app/subnets/addresses/address-details-index.php"); }
elseif(!isset($_GET['subnetId'])) { include("app/sections/section-subnets.php"); }
else { include("app/subnets/index.php"); }
}
# vrf
elseif ($_GET['page']=="vrf") { include("app/tools/vrf/index.php"); }
# vlan
elseif ($_GET['page']=="vlan") { include("app/vlan/index.php"); }
# folder
elseif ($_GET['page']=="folder") { include("app/folder/index.php"); }
# tools
elseif ($_GET['page']=="tools") {
if (!isset($_GET['section'])) { include("app/tools/index.php"); }
else {
if (!isset($tools_menu_items[$_GET['section']])) { header("Location: ".create_link("error","400")); die(); }
elseif (!file_exists("app/tools/$_GET[section]/index.php") && !file_exists("app/tools/custom/$_GET[section]/index.php"))
{ header("Location: ".create_link("error","404")); die(); }
else {
if(file_exists("app/tools/$_GET[section]/index.php")) {
include("app/tools/$_GET[section]/index.php");
}
else {
include("app/tools/custom/$_GET[section]/index.php");
}
}
}
}
# admin
elseif ($_GET['page']=="administration") {
# Admin object
$Admin = new Admin ($Database);
if (!isset($_GET['section'])) { include("app/admin/index.php"); }
elseif (@$_GET['subnetId']=="section-changelog") { include("app/sections/section-changelog.php"); }
else {
if (!isset($admin_menu_items[$_GET['section']])) { header("Location: ".create_link("error","400")); die(); }
elseif(!file_exists("app/admin/$_GET[section]/index.php")) { header("Location: ".create_link("error","404")); die(); }
else { include("app/admin/$_GET[section]/index.php"); }
}
}
# default - error
else {
{ header("Location: ".create_link("error","400")); die(); }
}
print "</div>";
print "</td>";
print "</tr>";
print "</table>";
}
?>
</div>
</div>
<!-- Base for IE -->
<div class="iebase hidden"><?php print BASE; ?></div>
<!-- pusher -->
<div class="pusher"></div>
<!-- end wrapper -->
</div>
<!-- weather prettyLinks are user, for JS! -->
<div id="prettyLinks" style="display:none"><?php print $User->settings->prettyLinks; ?></div>
<!-- Page footer -->
<div class="footer"><?php include('app/footer.php'); ?></div>
<!-- export div -->
<div class="exportDIV"></div>
<!-- end body -->
</body>
</html>
<?php } ?>
<?php } ?>