Skip to content

Commit 6766d1f

Browse files
committed
Racks, multicast, SNMP, threshold, bugfixes
1 parent 5990627 commit 6766d1f

File tree

136 files changed

+13211
-1420
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+13211
-1420
lines changed

app/admin/admin-menu-config.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,19 @@
2929
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-server", "name"=>"Sections", "href"=>"sections", "description"=>"Section management");
3030
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-sitemap","name"=>"Subnets", "href"=>"subnets", "description"=>"Subnet management");
3131
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-desktop","name"=>"Devices", "href"=>"devices", "description"=>"Device management");
32+
if($User->settings->enableRACK == 1)
33+
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-bars", "name"=>"Racks", "href"=>"racks", "description"=>"Rack management");
3234
if($User->settings->enableFirewallZones == 1)
33-
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-fire","name"=>"Firewall Zones", "href"=>"firewall-zones", "description"=>"Firewall zone management");
35+
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-fire","name"=>"Firewall Zones", "href"=>"firewall-zones", "description"=>"Firewall zone management");
3436
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-cloud", "name"=>"VLAN", "href"=>"vlans", "description"=>"VLAN management");
35-
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-cloud", "name"=>"Nameservers", "href"=>"nameservers", "description"=>"Recursive nameserver sets for subnets");
37+
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-cloud", "name"=>"Nameservers", "href"=>"nameservers", "description"=>"Recursive nameserver sets for subnets");
3638
if($User->settings->enableVRF==1)
3739
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-cloud", "name"=>"VRF", "href"=>"vrfs", "description"=>"VRF management");
38-
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-upload", "name"=>"Import / Export", "href"=>"import-export", "description"=>"Import/Export IP related data (VRF, VLAN, Subnets, IP, Devices)");
40+
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-upload", "name"=>"Import / Export", "href"=>"import-export", "description"=>"Import/Export IP related data (VRF, VLAN, Subnets, IP, Devices)");
3941
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-cloud-download", "name"=>"RIPE import", "href"=>"ripe-import", "description"=>"Import subnets from RIPE");
4042
if($User->settings->enableIPrequests==1) {
4143
$request_cnt = $requests>0 ? "<span class='ipreqMenu'>$requests</span>" : "";
42-
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-plus", "name"=>"IP requests $request_cnt", "href"=>"requests", "description"=>"Manage IP requests");
44+
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-plus", "name"=>"IP requests $request_cnt", "href"=>"requests", "description"=>"Manage IP requests");
4345
}
4446
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-filter", "name"=>"Filter IP fields", "href"=>"filter-fields", "description"=>"Select which default address fields to display");
4547
$admin_menu['IP related management'][] = array("show"=>true, "icon"=>"fa-magic", "name"=>"Custom fields", "href"=>"custom-fields", "description"=>"Manage custom fields");

app/admin/admin-menu.php

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
foreach($tool as $t) {
2020
# active?
2121
$active = $_GET['section']==$t['href'] ? "active" : "";
22+
# exception
23+
if ($t['href']=="devices") {
24+
if ($_GET['section']=="device-types" || $_GET['section']=="snmp") {
25+
$active = "active";
26+
}
27+
}
2228
# print
2329
print "<li class='list-group-item $active'>";
2430
print "<a href='".create_link("administration", $t['href'])."'><i class='fa fa-angle-right pull-right icon-gray'></i>"._($t['name'])."</a>";

app/admin/api/edit-result.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# verify that user is logged in
1717
$User->check_user_session();
1818

19+
# strip input tags
20+
$_POST = $Admin->strip_input_tags($_POST);
21+
1922
# validate csrf cookie
2023
$_POST['csrf_cookie']==$_SESSION['csrf_cookie'] ? : $Result->show("danger", _("Invalid CSRF cookie"), true);
2124

app/admin/authentication-methods/edit-result.php

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
# verify that user is logged in
1818
$User->check_user_session();
1919

20+
# strip input tags
21+
$_POST = $Admin->strip_input_tags($_POST);
22+
2023
# validate csrf cookie
2124
$_POST['csrf_cookie']==$_SESSION['csrf_cookie'] ? : $Result->show("danger", _("Invalid CSRF cookie"), true);
2225

app/admin/custom-fields/edit-result.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# verify that user is logged in
1717
$User->check_user_session();
1818

19+
# strip input tags
20+
$_POST = $Admin->strip_input_tags($_POST);
21+
1922
# validate csrf cookie
2023
$_POST['csrf_cookie']==$_SESSION['csrf_cookie'] ? : $Result->show("danger", _("Invalid CSRF cookie"), true);
2124

app/admin/custom-fields/index.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
"vlans"=>"VLAN",
1515
"vrf"=>"VRF",
1616
"users"=>"User",
17-
"devices"=>"devices");
17+
"devices"=>"Device",
18+
"racks"=>"Rack");
1819

1920
# create array
2021
foreach($custom_tables as $k=>$f) {

app/admin/device-types/edit-result.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# verify that user is logged in
1717
$User->check_user_session();
1818

19+
# strip input tags
20+
$_POST = $Admin->strip_input_tags($_POST);
21+
1922
# validate csrf cookie
2023
$_POST['csrf_cookie']==$_SESSION['csrf_cookie'] ? : $Result->show("danger", _("Invalid CSRF cookie"), true);
2124

app/admin/device-types/index.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<hr>
1616

1717
<div class="btn-group">
18-
<a href="<?php print create_link("administration", "devices"); ?>" class="btn btn-sm btn-default"><i class='fa fa-angle-left'></i> <?php print _('Back'); ?></a>
18+
<a href="<?php print create_link("administration", "devices"); ?>" class="btn btn-sm btn-default"><i class='fa fa-angle-left'></i> <?php print _('Manage devices'); ?></a>
1919
<button class='btn btn-sm btn-default editDevType' data-action='add' data-tid='' style='margin-bottom:10px;'><i class='fa fa-plus'></i> <?php print _('Add device type'); ?></button>
2020
</div>
2121

app/admin/devices/edit-result.php

+24-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
$User = new User ($Database);
1313
$Admin = new Admin ($Database);
1414
$Tools = new Tools ($Database);
15+
$Racks = new phpipam_rack ($Database);
1516
$Result = new Result ();
1617

1718
# verify that user is logged in
@@ -20,10 +21,8 @@
2021
# validate csrf cookie
2122
$_POST['csrf_cookie']==$_SESSION['csrf_cookie'] ? : $Result->show("danger", _("Invalid CSRF cookie"), true);
2223

23-
2424
# get modified details
25-
$device = $_POST;
26-
25+
$device = $Admin->strip_input_tags($_POST);
2726

2827
# ID must be numeric
2928
if($_POST['action']!="add" && !is_numeric($_POST['switchId'])) { $Result->show("danger", _("Invalid ID"), true); }
@@ -43,6 +42,21 @@
4342
# Hostname must be present
4443
if($device['hostname'] == "") { $Result->show("danger", _('Hostname is mandatory').'!', true); }
4544

45+
# rack checks
46+
if (strlen(@$device['rack']>0)) {
47+
if ($User->settings->enableRACK!="1") {
48+
unset($device['rack']);
49+
}
50+
else {
51+
# validate position and size
52+
if (!is_numeric($device['rack'])) { $Result->show("danger", _('Invalid rack identifier').'!', true); }
53+
if (!is_numeric($device['rack_start'])) { $Result->show("danger", _('Invalid rack start position').'!', true); }
54+
if (!is_numeric($device['rack_size'])) { $Result->show("danger", _('Invalid rack size').'!', true); }
55+
# validate rack
56+
$rack = $Racks->fetch_rack_details ($device['rack']);
57+
if ($rack===false) { $Result->show("danger", _('Rack does not exist').'!', true); }
58+
}
59+
}
4660

4761
# fetch custom fields
4862
$custom = $Tools->fetch_custom_fields('devices');
@@ -77,6 +91,13 @@
7791
if(isset($update)) {
7892
$values = array_merge($values, $update);
7993
}
94+
# rack
95+
if (strlen(@$device['rack']>0)) {
96+
$values['rack'] = $device['rack'];
97+
$values['rack_start'] = $device['rack_start'];
98+
$values['rack_size'] = $device['rack_size'];
99+
100+
}
80101

81102
# update device
82103
if(!$Admin->object_modify("devices", $_POST['action'], "id", $values)) {}
+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
/**
4+
* Edit snmp result
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+
$Result = new Result ();
15+
16+
# verify that user is logged in
17+
$User->check_user_session();
18+
19+
# validate csrf cookie
20+
$_POST['csrf_cookie']==$_SESSION['csrf_cookie'] ? : $Result->show("danger", _("Invalid CSRF cookie"), true);
21+
22+
# get modified details
23+
$device = $Admin->strip_input_tags($_POST);
24+
25+
# ID, port snd community must be numeric
26+
if(!is_numeric($_POST['device_id'])) { $Result->show("danger", _("Invalid ID"), true); }
27+
if(!is_numeric($_POST['snmp_version'])) { $Result->show("danger", _("Invalid version"), true); }
28+
if($_POST['snmp_version']!=0) {
29+
if(!is_numeric($_POST['snmp_port'])) { $Result->show("danger", _("Invalid port"), true); }
30+
if(!is_numeric($_POST['snmp_timeout'])) { $Result->show("danger", _("Invalid timeout"), true); }
31+
}
32+
33+
# version can be 0, 1 or 2
34+
if ($_POST['snmp_version']<0 || $_POST['snmp_version']>3) { $Result->show("danger", _("Invalid version"), true); }
35+
36+
# validate device
37+
$device = $Admin->fetch_object ("devices", "id", $_POST['device_id']);
38+
if($device===false) { $Result->show("danger", _("Invalid device"), true); }
39+
40+
# validate device ip
41+
if ($Admin->validate_ip($device->ip_addr)===false) { $Result->show("danger", _("Invalid device IP address"), true); }
42+
43+
# set snmp queries
44+
foreach($_POST as $key=>$line) {
45+
if (strlen(strstr($key,"query-"))>0) {
46+
$key2 = str_replace("query-", "", $key);
47+
$temp[] = $key2;
48+
unset($_POST[$key]);
49+
}
50+
}
51+
# glue sections together
52+
$_POST['snmp_queries'] = sizeof($temp)>0 ? implode(";", $temp) : null;
53+
54+
# set update values
55+
$values = array("id"=>$_POST['device_id'],
56+
"snmp_version"=>$_POST['snmp_version'],
57+
"snmp_community"=>$_POST['snmp_community'],
58+
"snmp_port"=>$_POST['snmp_port'],
59+
"snmp_timeout"=>$_POST['snmp_timeout'],
60+
"snmp_queries"=>$_POST['snmp_queries']
61+
);
62+
63+
# update device
64+
if(!$Admin->object_modify("devices", "edit", "id", $values)) { $Result->show("danger", _("SNMP edit failed").'!', false); }
65+
else { $Result->show("success", _("SNMP edit successfull").'!', false); }
66+
67+
?>

app/admin/devices/edit-snmp-test.php

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
<?php
2+
3+
/**
4+
* Edit snmp result
5+
***************************/
6+
7+
/* functions */
8+
require( dirname(__FILE__) . '/../../../functions/functions.php');
9+
10+
// no errors
11+
error_reporting(E_ERROR);
12+
13+
# initialize user object
14+
$Database = new Database_PDO;
15+
$User = new User ($Database);
16+
$Admin = new Admin ($Database);
17+
$Result = new Result ();
18+
19+
# verify that user is logged in
20+
$User->check_user_session();
21+
22+
# validate csrf cookie
23+
$_POST['csrf_cookie']==$_SESSION['csrf_cookie'] ? : $Result->show("danger", _("Invalid CSRF cookie"), true, false, false, true);
24+
25+
# get modified details
26+
$device = $Admin->strip_input_tags($_POST);
27+
28+
# ID, port snd community must be numeric
29+
if(!is_numeric($_POST['device_id'])) { $Result->show("danger", _("Invalid ID"), true, false, false, true); }
30+
if(!is_numeric($_POST['snmp_version'])) { $Result->show("danger", _("Invalid version"), true, false, false, true); }
31+
if($_POST['snmp_version']!=0) {
32+
if(!is_numeric($_POST['snmp_port'])) { $Result->show("danger", _("Invalid port"), true, false, false, true); }
33+
if(!is_numeric($_POST['snmp_timeout'])) { $Result->show("danger", _("Invalid timeout"), true, false, false, true); }
34+
}
35+
36+
# version can be 0, 1 or 2
37+
if ($_POST['snmp_version']<0 || $_POST['snmp_version']>2) { $Result->show("danger", _("Invalid version"), true, false, false, true); }
38+
39+
# validate device
40+
$device = $Admin->fetch_object ("devices", "id", $_POST['device_id']);
41+
if($device===false) { $Result->show("danger", _("Invalid device"), true, false, false, true); }
42+
43+
# set new snmp variables
44+
$device->snmp_community = $_POST['snmp_community'];
45+
$device->snmp_version = $_POST['snmp_version'];
46+
$device->snmp_port = $_POST['snmp_port'];
47+
$device->snmp_timeout = $_POST['snmp_timeout'];
48+
49+
# init snmp class
50+
$Snmp = new phpipamSNMP ($Database, $device);
51+
52+
53+
# set queries
54+
foreach($_POST as $k=>$p) {
55+
if(strpos($k, "query-")!==false) {
56+
if($p=="on") {
57+
$queries[] = substr($k, 6);
58+
}
59+
}
60+
}
61+
62+
# reindex queries and get details
63+
foreach ($Snmp->snmp_queries as $q) {
64+
if (in_array($q->id, $queries)) {
65+
$queries_parsed[] = $q;
66+
}
67+
}
68+
69+
# save all queries
70+
$device->snmp_queries = implode(";", $queries);
71+
72+
# open connection
73+
if (isset($queries_parsed)) {
74+
// loop
75+
foreach($queries_parsed as $kk=>$q) {
76+
// remove old
77+
$method = false;
78+
79+
try {
80+
# try to get details
81+
if ($q->method == "info") { $method = "get_sysinfo"; }
82+
elseif ($q->method == "arp") { $method = "get_arp_table";; }
83+
elseif ($q->method == "route") { $method = "get_routing_table"; }
84+
85+
# execute
86+
if ($method!==false) {
87+
$debug[$kk]['method'] = $method;
88+
$debug[$kk]['oid'] = $q->oid;
89+
$debug[$kk]['result'] = $Snmp->$method($device, $q->id);
90+
# print
91+
if ($method=="get_sysinfo") {
92+
$res[] = $Result->show("success", "<strong>$method</strong>: OK<hr> <pre>".$Snmp->last_result."</pre>", false, false, true);
93+
}
94+
else {
95+
$res[] = $Result->show("success", "<strong>$method</strong>: OK", false, false, true);
96+
}
97+
}
98+
else {
99+
$res[] = $Result->show("warning", "<strong>$method</strong><hr> "._("Invalid method"), false, false, true);
100+
}
101+
} catch ( Exception $e ) {
102+
$res[] = $Result->show("danger", "<strong>$method</strong><hr> ".$e->getMessage(), false, false, true);
103+
}
104+
}
105+
106+
// debug
107+
$res[] = "<hr>";
108+
$res[] = "<div class='text-right'>";
109+
$res[] = " <a class='btn btn-sm btn-default pull-right' id='toggle_debug'>Toggle debug</a>";
110+
$res[] = "</div>";
111+
$res[] = " <pre id='debug' style='display:none;'>";
112+
$res[] = print_r($debug, true);
113+
$res[] = "</pre>";
114+
115+
//print
116+
$Result->show("Query result", implode("<br>", $res), false, true, false, true);
117+
}
118+
else {
119+
$Result->show("warning", _("No queries"), false, true, false, true);
120+
}
121+
?>
122+
123+
124+
<script type="text/javascript">
125+
$(document).ready(function(){
126+
$('#toggle_debug').click(function() { $('#debug').toggle() });
127+
});

0 commit comments

Comments
 (0)