forked from phpipam/phpipam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·347 lines (302 loc) · 13.4 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
<?php
ob_start();
/* 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>"); }
else { require('config.php'); }
/* site functions */
require('functions/functions.php');
# set default page
if(!isset($_GET['page'])) { $_GET['page'] = "dashboard"; }
# 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']=="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("table-page-size", 50, time()+2592000, "/", false, false, 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="Description" content="">
<meta name="title" content="<?php print $title = $User->get_site_title ($_GET); ?>">
<meta name="robots" content="noindex, nofollow">
<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/<?php print SCRIPT_PREFIX; ?>/images/favicon.png">
<link rel="stylesheet" type="text/css" href="css/<?php print SCRIPT_PREFIX; ?>/bootstrap/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/<?php print SCRIPT_PREFIX; ?>/bootstrap/bootstrap-custom.css">
<link rel="stylesheet" type="text/css" href="css/<?php print SCRIPT_PREFIX; ?>/font-awesome/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="css/<?php print SCRIPT_PREFIX; ?>/bootstrap/bootstrap-switch.min.css">
<?php if ($User->settings->enableThreshold=="1") { ?>
<link rel="stylesheet" type="text/css" href="css/<?php print SCRIPT_PREFIX; ?>/slider.css">
<?php } ?>
<!-- js -->
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/jclock.jquery.js"></script>
<?php if($_GET['page']=="login" || $_GET['page']=="request_ip") { ?>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/login.js"></script>
<?php } ?>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/magic.min.js"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/bootstrap.min.js"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/bootstrap-switch.min.js"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/bdt/jquery.sortelements.js"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/bdt/jquery.bdt.js"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/stickytableheaders/jquery.stickytableheaders.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
if ($("[rel=tooltip]").length) { $("[rel=tooltip]").tooltip(); }
});
</script>
<?php if ($User->settings->enableThreshold=="1") { ?>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/bootstrap-slider.js"></script>
<?php } ?>
<!--[if lt IE 9]>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/dieIE.js"></script>
<![endif]-->
<?php if ($User->settings->enableLocations=="1" && isset($gmaps_api_key) && strlen($gmaps_api_key)>0) { ?>
<script type="text/javascript" src="https://maps.google.com/maps/api/js<?php print "?key=".$gmaps_api_key; ?>"></script>
<script type="text/javascript" src="js/<?php print SCRIPT_PREFIX; ?>/gmaps.js"></script>
<?php } ?>
</head>
<!-- body -->
<body>
<!-- wrapper -->
<div class="wrapper">
<!-- jQuery error -->
<div class="jqueryError">
<div class='alert alert-danger' style="width:400px;margin:auto">jQuery error!</div>
<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>
<!-- 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/".SCRIPT_PREFIX."/images/logo/logo.png")) {
print "<img style='width:220px;margin:10px;margin-top:20px;' src='css/".SCRIPT_PREFIX."/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 = 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) ? " <btn class='removeMaintaneance btn btn-xs btn-default'>"._("Remove")."</btn>" : "";
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" && strlen($_GET['section'])==0) {
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']) && (strlen(@$_GET['section']) == 0) ) { 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/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 (!in_array($_GET['section'], $tools_menu_items)) { 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 (!in_array($_GET['section'], $admin_menu_items)) { 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 ob_end_flush(); ?>
<?php } ?>