Skip to content

Commit 44cb08e

Browse files
committed
Locations module phpipam#103 - initial
1 parent c514aa1 commit 44cb08e

35 files changed

+3559
-131
lines changed

app/admin/admin-menu-config.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-cogs","name"=>"SNMP", "href"=>"snmp", "description"=>"SNMP management");
3939
if($User->settings->enableRACK == 1)
4040
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-bars", "name"=>"Racks", "href"=>"racks", "description"=>"Rack management");
41+
if($User->settings->enableLocations == 1)
42+
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-map", "name"=>"Locations", "href"=>"locations", "description"=>"Locations");
43+
4144
if($User->settings->enableFirewallZones == 1)
4245
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-fire","name"=>"Firewall Zones", "href"=>"firewall-zones", "description"=>"Firewall zone management");
4346
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-cloud", "name"=>"VLAN", "href"=>"vlans", "description"=>"VLAN management");
@@ -92,7 +95,8 @@
9295
'vlans',
9396
'vrfs',
9497
'widgets',
95-
'nat'
98+
'nat',
99+
'locations'
96100
);
97101

98102

app/admin/devices/edit-result.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@
8787
"ip_addr"=>@$device['ip_addr'],
8888
"type"=>@$device['type'],
8989
"description"=>@$device['description'],
90-
"sections"=>@$device['sections']
90+
"sections"=>@$device['sections'],
91+
"location"=>@$device['location_item']
9192
);
9293
# custom fields
9394
if(isset($update)) {

app/admin/devices/edit.php

+25
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@
3636
# set readonly flag
3737
$readonly = $_POST['action']=="delete" ? "readonly" : "";
3838

39+
40+
# all locations
41+
if($User->settings->enableLocations=="1")
42+
$locations = $Tools->fetch_all_objects ("locations");
43+
3944
// set show for rack
4045
if (is_null($device['rack'])) { $display='display:none'; }
4146
else { $display=''; }
@@ -98,6 +103,26 @@
98103
</td>
99104
</tr>
100105

106+
<!-- Location -->
107+
<?php if($User->settings->enableLocations=="1") { ?>
108+
<tr>
109+
<td><?php print _('Location'); ?></td>
110+
<td>
111+
<select name="location_item" class="form-control input-sm input-w-auto">
112+
<option value="0"><?php print _("None"); ?></option>
113+
<?php
114+
if($locations!==false) {
115+
foreach($locations as $l) {
116+
if($device['location'] == $l->id) { print "<option value='$l->id' selected='selected'>$l->name</option>"; }
117+
else { print "<option value='$l->id'>$l->name</option>"; }
118+
}
119+
}
120+
?>
121+
</select>
122+
</td>
123+
</tr>
124+
<?php } ?>
125+
101126
<!-- Rack -->
102127
<?php if($User->settings->enableRACK=="1") { ?>
103128
<tr>

app/admin/locations/edit-result.php

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
/* functions */
4+
require( dirname(__FILE__) . '/../../../functions/functions.php');
5+
6+
# initialize user object
7+
$Database = new Database_PDO;
8+
$User = new User ($Database);
9+
$Admin = new Admin ($Database);
10+
$Result = new Result ();
11+
12+
# verify that user is logged in
13+
$User->check_user_session();
14+
15+
# strip input tags
16+
$_POST = $Admin->strip_input_tags($_POST);
17+
18+
# validate csrf cookie
19+
$User->csrf_cookie ("validate", "location", $_POST['csrf_cookie']) === false ? $Result->show("danger", _("Invalid CSRF cookie"), true) : "";
20+
21+
# validations
22+
if($_POST['action']=="delete" || $_POST['action']=="edit") {
23+
if($Admin->fetch_object ('locations', "id", $_POST['id'])===false) {
24+
$Result->show("danger", _("Invalid Location object identifier"), false);
25+
}
26+
}
27+
if($_POST['action']=="add" || $_POST['action']=="edit") {
28+
// name
29+
if(strlen($_POST['name'])<3) { $Result->show("danger", _("Name must have at least 3 characters"), true); }
30+
// lat, long
31+
if($_POST['action']!=="delete") {
32+
// lat
33+
if(strlen($_POST['lat'])>0) {
34+
if(!preg_match('/^(\-?\d+(\.\d+)?).\s*(\-?\d+(\.\d+)?)$/', $_POST['lat'])) { $Result->show("danger", _("Invalid Latitude"), true); }
35+
}
36+
// long
37+
if(strlen($_POST['long'])>0) {
38+
if(!preg_match('/^(\-?\d+(\.\d+)?).\s*(\-?\d+(\.\d+)?)$/', $_POST['long'])) { $Result->show("danger", _("Invalid Longitude"), true); }
39+
}
40+
}
41+
}
42+
43+
// set values
44+
$values = array(
45+
"id"=>@$_POST['id'],
46+
"name"=>$_POST['name'],
47+
"lat"=>$_POST['lat'],
48+
"long"=>$_POST['long'],
49+
"description"=>$_POST['description']
50+
);
51+
52+
# execute update
53+
if(!$Admin->object_modify ("locations", $_POST['action'], "id", $values)) { $Result->show("danger", _("Location $_POST[action] failed"), false); }
54+
else { $Result->show("success", _("Location $_POST[action] successful"), false); }
55+
56+
?>

app/admin/locations/edit.php

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
/**
4+
* Print all available locations
5+
************************************************/
6+
7+
/* functions */
8+
require( dirname(__FILE__) . '/../../../functions/functions.php');
9+
10+
# initialize user object
11+
$Database = new Database_PDO;
12+
$User = new User ($Database);
13+
$Admin = new Admin ($Database);
14+
$Tools = new Tools ($Database);
15+
$Result = new Result ();
16+
17+
# verify that user is logged in
18+
$User->check_user_session();
19+
20+
# create csrf token
21+
$csrf = $User->csrf_cookie ("create", "location");
22+
23+
# get Location object
24+
if($_POST['action']!="add") {
25+
$location = $Admin->fetch_object ("locations", "id", $_POST['id']);
26+
$location!==false ? : $Result->show("danger", _("Invalid ID"), true, true);
27+
}
28+
29+
# disable edit on delete
30+
$readonly = $_POST['action']=="delete" ? "readonly" : "";
31+
$link = $readonly ? false : true;
32+
33+
?>
34+
35+
36+
<!-- header -->
37+
<div class="pHeader"><?php print ucwords(_("$_POST[action]")); ?> <?php print _('Location'); ?></div>
38+
39+
<!-- content -->
40+
<div class="pContent">
41+
42+
<form id="editLocation">
43+
<table id="editLocation" class="table table-noborder table-condensed">
44+
45+
<tbody>
46+
<!-- name -->
47+
<tr>
48+
<th><?php print _('Name'); ?></th>
49+
<td>
50+
<input type="text" class="form-control input-sm" name="name" value="<?php print $location->name; ?>" placeholder='<?php print _('Name'); ?>' <?php print $readonly; ?>>
51+
<input type="hidden" name="csrf_cookie" value="<?php print $csrf; ?>">
52+
<input type="hidden" name="id" value="<?php print $location->id; ?>">
53+
<input type="hidden" name="action" value="<?php print $_POST['action']; ?>">
54+
</td>
55+
<td>
56+
<span class="text-muted"><?php print _("Set Location name"); ?></span>
57+
</td>
58+
</tr>
59+
60+
<!-- Latitude -->
61+
<tr>
62+
<th><?php print _('Latitude'); ?></th>
63+
<td>
64+
<input type="text" class="form-control input-sm" name="lat" value="<?php print $location->lat; ?>" placeholder='<?php print _('Latitude'); ?>' <?php print $readonly; ?>>
65+
</td>
66+
<td>
67+
<span class="text-muted"><?php print _("GPS Latitude"); ?></span>
68+
</td>
69+
</tr>
70+
71+
<!-- Longitude -->
72+
<tr>
73+
<th><?php print _('Longiture'); ?></th>
74+
<td>
75+
<input type="text" class="form-control input-sm" name="long" value="<?php print $location->long; ?>" placeholder='<?php print _('Latitude'); ?>' <?php print $readonly; ?>>
76+
</td>
77+
<td>
78+
<span class="text-muted"><?php print _("GPS Longitude"); ?></span>
79+
</td>
80+
</tr>
81+
82+
<!-- description -->
83+
<tr>
84+
<th><?php print _('Description'); ?></th>
85+
<td colspan="2">
86+
<textarea class="form-control input-sm" name="description" placeholder='<?php print _('Port'); ?>' <?php print $readonly; ?>><?php print $location->description; ?></textarea>
87+
</td>
88+
</tr>
89+
90+
</tbody>
91+
92+
</table>
93+
</form>
94+
</div>
95+
96+
97+
<!-- footer -->
98+
<div class="pFooter">
99+
<div class="btn-group">
100+
<button class="btn btn-sm btn-default hidePopupsReload"><?php print _('Cancel'); ?></button>
101+
<button class="btn btn-sm btn-default <?php if($_POST['action']=="delete") { print "btn-danger"; } else { print "btn-success"; } ?>" id="editLocationSubmit"><i class="fa <?php if($_POST['action']=="add") { print "fa-plus"; } else if ($_POST['action']=="delete") { print "fa-trash-o"; } else { print "fa-check"; } ?>"></i> <?php print ucwords(_($_POST['action'])); ?></button>
102+
</div>
103+
<!-- result -->
104+
<div class="editLocationResult"></div>
105+
</div>

app/admin/locations/index.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
# verify that user is logged in
4+
$User->check_user_session();
5+
6+
# Make sure user is admin
7+
$User->is_admin(true);
8+
9+
# show all nat objects
10+
include(dirname(__FILE__)."/../../tools/locations/index.php");
11+
?>

app/admin/racks/edit-result.php

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
$values = array("id"=>@$rack['rackid'],
6767
"name"=>@$rack['name'],
6868
"size"=>@$rack['size'],
69+
"location"=>@$rack['location'],
6970
"description"=>@$rack['description']
7071
);
7172
# custom fields

app/admin/racks/edit.php

+24
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@
3636
$rack->size = 42;
3737
}
3838

39+
# all locations
40+
if($User->settings->enableLocations=="1")
41+
$locations = $Tools->fetch_all_objects ("locations");
42+
3943
# set readonly flag
4044
$readonly = $_POST['action']=="delete" ? "readonly" : "";
4145
?>
@@ -80,6 +84,26 @@
8084
</td>
8185
</tr>
8286

87+
<!-- Location -->
88+
<?php if($User->settings->enableLocations=="1") { ?>
89+
<tr>
90+
<td><?php print _('Location'); ?></td>
91+
<td>
92+
<select name="location" class="form-control input-sm input-w-auto">
93+
<option value="0"><?php print _("None"); ?></option>
94+
<?php
95+
if($locations!==false) {
96+
foreach($locations as $l) {
97+
if($rack->location == $l->id) { print "<option value='$l->id' selected='selected'>$l->name</option>"; }
98+
else { print "<option value='$l->id'>$l->name</option>"; }
99+
}
100+
}
101+
?>
102+
</select>
103+
</td>
104+
</tr>
105+
<?php } ?>
106+
83107
<!-- Description -->
84108
<tr>
85109
<td><?php print _('Description'); ?></td>

app/admin/settings/index.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,18 @@
325325
</td>
326326
</tr>
327327

328-
<!-- Rack -->
328+
<!-- Locations -->
329+
<tr>
330+
<td class="title"><?php print _('Locations module'); ?></td>
331+
<td>
332+
<input type="checkbox" class="input-switch" value="1" name="enableLocations" <?php if($settings['enableLocations'] == 1) print 'checked'; ?>>
333+
</td>
334+
<td class="info2">
335+
<?php print _('Enable or disable locations module'); ?>
336+
</td>
337+
</tr>
338+
339+
<!-- SNMP -->
329340
<tr>
330341
<td class="title"><?php print _('SNMP module'); ?></td>
331342
<td>

app/admin/settings/settings-save.php

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
"enableIPrequests"=>$Admin->verify_checkbox(@$_POST['enableIPrequests']),
6868
"enableMulticast"=>$Admin->verify_checkbox(@$_POST['enableMulticast']),
6969
"enableRACK"=>$Admin->verify_checkbox(@$_POST['enableRACK']),
70+
"enableLocations"=>$Admin->verify_checkbox(@$_POST['enableLocations']),
7071
"enableSNMP"=>$Admin->verify_checkbox(@$_POST['enableSNMP']),
7172
"enableThreshold"=>$Admin->verify_checkbox(@$_POST['enableThreshold']),
7273
"enableVRF"=>$Admin->verify_checkbox(@$_POST['enableVRF']),

app/admin/subnets/edit-result.php

+1
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@
261261
"DNSrecursive"=>$Admin->verify_checkbox(@$_POST['DNSrecursive']),
262262
"DNSrecords"=>$Admin->verify_checkbox(@$_POST['DNSrecords']),
263263
"nameserverId"=>$_POST['nameserverId'],
264+
"location"=>@$_POST['location_item'],
264265
"device"=>$_POST['device'],
265266
"isFull"=>$Admin->verify_checkbox($_POST['isFull'])
266267
);

app/admin/subnets/edit.php

+24
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
$subnet_old_details['vlanId'] = $_POST['vlanId'];
9090
}
9191

92+
# all locations
93+
if($User->settings->enableLocations=="1")
94+
$locations = $Tools->fetch_all_objects ("locations");
95+
9296
# set readonly flag
9397
$readonly = $_POST['action']=="edit" || $_POST['action']=="delete" ? true : false;
9498
?>
@@ -325,6 +329,26 @@
325329

326330
?>
327331

332+
<!-- Location -->
333+
<?php if($User->settings->enableLocations=="1") { ?>
334+
<tr>
335+
<td><?php print _('Location'); ?></td>
336+
<td>
337+
<select name="location_item" class="form-control input-sm input-w-auto">
338+
<option value="0"><?php print _("None"); ?></option>
339+
<?php
340+
if($locations!==false) {
341+
foreach($locations as $l) {
342+
if($subnet_old_details['location'] == $l->id) { print "<option value='$l->id' selected='selected'>$l->name</option>"; }
343+
else { print "<option value='$l->id'>$l->name</option>"; }
344+
}
345+
}
346+
?>
347+
</select>
348+
</td>
349+
</tr>
350+
<?php } ?>
351+
328352
<?php if($_POST['action']!="delete") { ?>
329353
<!-- mark full -->
330354
<tr>

app/sections/menu/menu-administration.php

+9
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@
7979
"icon"=>"fa-database"
8080
);
8181
}
82+
// locations
83+
if($User->settings->enableLocations == 1) {
84+
$admin_items["locations"] = array (
85+
"name"=>"Locations",
86+
"href"=>array("tools", "locations"),
87+
"title"=>"Show locations",
88+
"icon"=>"fa-map"
89+
);
90+
}
8291
// rack
8392
if($User->settings->enableRACK == 1) {
8493
$admin_items["racks"] = array (

app/sections/menu/menu-tools.php

+9
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@
5858
"icon"=>"fa-database"
5959
);
6060
}
61+
// locations
62+
if($User->settings->enableLocations == 1) {
63+
$tool_items["locations"] = array (
64+
"name"=>"Locations",
65+
"href"=>array("tools", "locations"),
66+
"title"=>"Show locations",
67+
"icon"=>"fa-map"
68+
);
69+
}
6170
// rack
6271
if($User->settings->enableRACK == 1) {
6372
$tool_items["racks"] = array (

0 commit comments

Comments
 (0)