diff --git a/callback.php b/callback.php new file mode 100644 index 0000000000..2c82b3ef95 --- /dev/null +++ b/callback.php @@ -0,0 +1,103 @@ + + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +$enabled = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'enabled'"); +if ($enabled == 1) { + + if (dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'") == '') { + dbInsert(array('name'=>'uuid','value'=>guidv4(openssl_random_pseudo_bytes(16))), 'callback'); + } + $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'"); + + $queries = array( + 'alert_rules'=>'SELECT COUNT(`severity`) AS `total`,`severity` FROM `alert_rules` WHERE `disabled`=0 GROUP BY `severity`', + 'alert_templates'=>'SELECT COUNT(`id`) AS `total` FROM `alert_templates`', + 'api_tokens'=>'SELECT COUNT(`id`) AS `total` FROM `api_tokens` WHERE `disabled`=0', + 'applications'=>'SELECT COUNT(`app_type`) AS `total`,`app_type` FROM `applications` GROUP BY `app_type`', + 'bgppeer_state'=>'SELECT COUNT(`bgpPeerState`) AS `total`,`bgpPeerState` FROM `bgpPeers` GROUP BY `bgpPeerState`', + 'bgppeer_status'=>'SELECT COUNT(`bgpPeerAdminStatus`) AS `total`,`bgpPeerAdminStatus` FROM `bgpPeers` GROUP BY `bgpPeerAdminStatus`', + 'bills'=>'SELECT COUNT(`bill_type`) AS `total`,`bill_type` FROM `bills` GROUP BY `bill_type`', + 'cef'=>'SELECT COUNT(`device_id`) AS `total` FROM `cef_switching`', + 'cisco_asa'=>'SELECT COUNT(`oid`) AS `total`,`oid` FROM `ciscoASA` WHERE `disabled` = 0 GROUP BY `oid`', + 'mempool'=>'SELECT COUNT(`cmpName`) AS `total`,`cmpName` FROM `cmpMemPool` GROUP BY `cmpName`', + 'current'=>'SELECT COUNT(`current_type`) AS `total`,`current_type` FROM `current` GROUP BY `current_type`', + 'dbschema'=>'SELECT COUNT(`version`) AS `total`, `version` FROM `dbSchema`', + 'snmp_version'=>'SELECT COUNT(`snmpver`) AS `total`,`snmpver` FROM `devices` GROUP BY `snmpver`', + 'os'=>'SELECT COUNT(`os`) AS `total`,`os` FROM `devices` GROUP BY `os`', + 'type'=>'SELECT COUNT(`type`) AS `total`,`type` FROM `devices` GROUP BY `type`', + 'full_type'=>'SELECT COUNT(`device_id`) AS `total`, CONCAT_WS(', ', `os`,`hardware`,`type`) FROM `devices` GROUP BY `os`,`hardware`,`type`', + 'ipsec'=>'SELECT COUNT(`device_id`) AS `total` FROM `ipsec_tunnels`', + 'ipv4_addresses'=>'SELECT COUNT(`ipv4_address_id`) AS `total` FROM `ipv4_addresses`', + 'ipv4_macaddress'=>'SELECT COUNT(`port_id`) AS `total` FROM ipv4_mac', + 'ipv4_networks'=>'SELECT COUNT(`ipv4_network_id`) AS `total` FROM ipv4_networks', + 'ipv6_addresses'=>'SELECT COUNT(`ipv6_address_id`) AS `total` FROM `ipv6_addresses`', + 'ipv6_networks'=>'SELECT COUNT(`ipv6_network_id`) AS `total` FROM `ipv6_networks`', + 'xdp'=>'SELECT COUNT(`id`) AS `total`,`protocol` FROM `links` GROUP BY `protocol`', + 'ospf'=>'SELECT COUNT(`device_id`) AS `total`,`ospfVersionNumber` FROM `ospf_instances` GROUP BY `ospfVersionNumber`', + 'ospf_links'=>'SELECT COUNT(`device_id`) AS `total`,`ospfIfType` FROM `ospf_ports` GROUP BY `ospfIfType`', + 'arch'=>'SELECT COUNT(`pkg_id`) AS `total`,`arch` FROM `packages` GROUP BY `arch`', + 'pollers'=>'SELECT COUNT(`id`) AS `total` FROM `pollers`', + 'port_type'=>'SELECT COUNT(`port_id`) AS `total`,`ifType` FROM `ports` GROUP BY `ifType`', + 'port_ifspeed'=>'SELECT COUNT(`ifSpeed`) AS `total`,ROUND(`ifSpeed`/1000/1000) FROM `ports` GROUP BY `ifSpeed`', + 'port_vlans'=>'SELECT COUNT(`device_id`) AS `total`,`state` FROM `ports_vlans` GROUP BY `state`', + 'processes'=>'SELECT COUNT(`device_id`) AS `total` FROM `processes`', + 'processors'=>'SELECT COUNT(`processor_id`) AS `total`,`processor_type` FROM `processors` GROUP BY `processor_type`', + 'pseudowires'=>'SELECT COUNT(`pseudowire_id`) AS `total` FROM `pseudowires`', + 'sensors'=>'SELECT COUNT(`sensor_id`) AS `total`,`sensor_class` FROM `sensors` GROUP BY `sensor_class`', + 'storage'=>'SELECT COUNT(`storage_id`) AS `total`,`storage_type` FROM `storage` GROUP BY `storage_type`', + 'toner'=>'SELECT COUNT(`toner_id`) AS `total`,`toner_type` FROM `toner` GROUP BY `toner_type`', + 'vlans'=>'SELECT COUNT(`vlan_id`) AS `total`,`vlan_type` FROM `vlans` GROUP BY `vlan_type`', + 'vminfo'=>'SELECT COUNT(`id`) AS `total`,`vm_type` FROM `vminfo` GROUP BY `vm_type`', + 'vmware'=>'SELECT COUNT(`id`) AS `total` FROM `vmware_vminfo`', + 'vrfs'=>'SELECT COUNT(`vrf_id`) AS `total` FROM `vrfs`'); + + + foreach ($queries as $name => $query) { + $data = dbFetchRows($query); + $response[$name] = $data; + } + $output = array('uuid'=>$uuid,'data'=>$response); + $data = json_encode($output); + $submit = array('data'=>$data); + + $fields = ''; + foreach ($submit as $key => $value) { + $fields .= $key . '=' . $value . '&'; + } + rtrim($fields, '&'); + + $post = curl_init(); + set_curl_proxy($post); + curl_setopt($post, CURLOPT_URL, $config['callback_post']); + curl_setopt($post, CURLOPT_POST, count($submit)); + curl_setopt($post, CURLOPT_POSTFIELDS, $fields); + curl_setopt($post, CURLOPT_RETURNTRANSFER, 1); + $result = curl_exec($post); +} elseif ($enabled == 2) { + + $uuid = dbFetchCell("SELECT `value` FROM `callback` WHERE `name` = 'uuid'"); + $fields = "uuid=$uuid"; + + $clear = curl_init(); + set_curl_proxy($clear); + curl_setopt($clear, CURLOPT_URL, $config['callback_clear']); + curl_setopt($clear, CURLOPT_POST, count($clear)); + curl_setopt($clear, CURLOPT_POSTFIELDS, $fields); + curl_setopt($clear, CURLOPT_RETURNTRANSFER, 1); + $result = curl_exec($clear); + dbDelete('callback', '`name`="uuid"', array()); + dbUpdate(array('value' => '0'), 'callback', '`name` = "enabled"', array()); +} + +?> diff --git a/config.php.default b/config.php.default index c98b8677ba..479482113b 100755 --- a/config.php.default +++ b/config.php.default @@ -41,3 +41,6 @@ $config['auth_mechanism'] = "mysql"; # default, other options: ldap, http-auth $config['poller-wrapper']['alerter'] = FALSE; # Uncomment the next line to disable daily updates #$config['update'] = 0; + +# Uncomment to submit callback stats via proxy +#$config['callback_proxy'] = "hostname:port"; diff --git a/daily.php b/daily.php index 38ac1584ef..03176a47d3 100644 --- a/daily.php +++ b/daily.php @@ -55,5 +55,8 @@ if ($options['f'] === 'perf_times') { } } } +if ($options['f'] === 'callback') { + require_once "callback.php"; +} ?> diff --git a/daily.sh b/daily.sh index ca8c87077a..4168d73448 100644 --- a/daily.sh +++ b/daily.sh @@ -11,3 +11,4 @@ php daily.php -f syslog php daily.php -f eventlog php daily.php -f authlog php daily.php -f perf_times +php daily.php -f callback diff --git a/doc/General/Callback-Stats-and-Privacy.md b/doc/General/Callback-Stats-and-Privacy.md new file mode 100644 index 0000000000..e0d32c7a78 --- /dev/null +++ b/doc/General/Callback-Stats-and-Privacy.md @@ -0,0 +1,32 @@ +## Stats data and your privacy ## + +This document has been put together to explain what LibreNMS does when it calls back home to report some anonymous statistics. + +Let's start off by saying, all of the code that processes the data and submits it is included in the standard LibreNMS branch you've installed, the code that accepts this data and in turn generates some pretty graphs is all open source and available on Git Hub. Please feel free to review the code, comment on it and suggest changes / improvements. Also, don't forget - by default installations DO NOT call back home, you need to opt into this. + +Above all we respect users privacy which is why this system has been designed like it has. + +Now onto the bit you're interested in, what is submitted and what we do with that data. + +#### What is submitted #### +- All data is anonymous. +- Generic statistics are taken from the database, these include things like device total, type and os, port types, speeds and total, total bgp peers. Take a look at the code for full details. +- A random UUID is generated on your own install. +- That's it! +- Your IP isn't logged, even via our web service accepting the data. We don't need to know who you are so don't ask. + +#### What we do with the data #### +- We store it, not for long - 3 months at the moment although this could change. +- We use it to generate pretty graphs for people to see. +- We use it to help prioritise issues and features that need to be worked on. + +#### Questions? #### +- Q. How often is data submitted? A. We submit the data once a day according to running daily.sh via cron. If you disable this then opting in will not have any affect. +- Q. Where can I see the data I submitted? A. You can't see the data raw, but we collate all of the data together and provide a dynamic site so you can see the results of all contributed stats [here](https://stats.librenms.org) +- Q. I want my data removed. A. That's easy, simply press 'Clear remote stats' in the About LibreNMS page of your control panel, the next time the call back script is run it will remove all the data we have. +- Q. I clicked the 'Clear remote stats' button by accident. A. No problem, before daily.sh runs again - just opt back in, all of your existing data will stay. + +Hopefully this answers the questions you might have on why and what we are doing here, if not, please pop into our irc channel or google mailing list and ask any questions you like. + +If you're happy with all of this - please consider switching the call back system on, you can do this within the About LibreNMS page within your control panel. In the Statistics section you will find a toggle switch to enable / disable the feature. If you've previously had it switched on and want to opt out and remove your data, click the 'Clear remote stats' button and on the next submission all the data you've sent us will be removed! + diff --git a/doc/General/Changelog.md b/doc/General/Changelog.md index cc025fef6f..4233ecd178 100644 --- a/doc/General/Changelog.md +++ b/doc/General/Changelog.md @@ -3,6 +3,11 @@ ####Bug fixes - Fixed ack of worse/better alerts (PR720) - Fixed ORIG_PATH_INFO warnings (PR727) + - Added missing CPU id for Cisco SB (PR744) + - Changed Processors table name to lower case in processors discovery (PR751) + - Fixed alerts path issue (PR756, PR760) + - Supress further port alerts when interface goes down (PR745) + - Fixed login so redirects via 303 when POST data sent (PR775) ####Improvements - New theme support added (light,dark and mono) (PR682,PR683,PR701) @@ -13,6 +18,15 @@ - Update to Foritgate support (PR709) - Added support for UBNT AirOS and AirFibre (PR721,PR730,PR731) - Added support device groups + alerts to be mapped to devices or groups (PR722) + - Added basic Cambium support (PR738) + - Added basic F5 support (PR670) + - Shorten interface names on map (PR752) + - Added PowerCode support (PR762) + - Added Autodiscovery via OSPF (PR772) + - Added visual graph of alert log (PR777) + - Added Callback system to send anonymous stats (PR768) + - More tables converted to use bootgrid (PR729, PR761) + - New Global Cache to store common queries added (PR780) ### Mar 2015 diff --git a/doc/Installation/Installation-(Debian-Ubuntu).md b/doc/Installation/Installation-(Debian-Ubuntu).md index d85aa6ff4a..4df0bfee4c 100644 --- a/doc/Installation/Installation-(Debian-Ubuntu).md +++ b/doc/Installation/Installation-(Debian-Ubuntu).md @@ -42,7 +42,7 @@ This host is where the web server and SNMP poller run. It could be the same mac Install the required software: - apt-get install libapache2-mod-php5 php5-cli php5-mysql php5-gd php5-snmp php-pear snmp graphviz php5-mcrypt php5-json apache2 fping imagemagick whois mtr-tiny nmap python-mysqldb snmpd mysql-client php-net-ipv4 php-net-ipv6 rrdtool git + apt-get install libapache2-mod-php5 php5-cli php5-mysql php5-gd php5-snmp php-pear php5-curl snmp graphviz php5-mcrypt php5-json apache2 fping imagemagick whois mtr-tiny nmap python-mysqldb snmpd mysql-client php-net-ipv4 php-net-ipv6 rrdtool git The packages listed above are an all-inclusive list of packages that were necessary on a clean install of Ubuntu 12.04/14.04. diff --git a/doc/Installation/Installation-(RHEL-CentOS).md b/doc/Installation/Installation-(RHEL-CentOS).md index 4dd28a6f8c..e8a17014d4 100644 --- a/doc/Installation/Installation-(RHEL-CentOS).md +++ b/doc/Installation/Installation-(RHEL-CentOS).md @@ -47,7 +47,7 @@ Install necessary software. The packages listed below are an all-inclusive list Note if not using HTTPd (Apache): RHEL requires `httpd` to be installed regardless of of `nginx`'s (or any other web-server's) presence. rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm - yum install php php-cli php-gd php-mysql php-snmp php-pear httpd net-snmp graphviz graphviz-php mysql ImageMagick jwhois nmap mtr rrdtool MySQL-python net-snmp-utils vixie-cron php-mcrypt fping git + yum install php php-cli php-gd php-mysql php-snmp php-pear php-curl httpd net-snmp graphviz graphviz-php mysql ImageMagick jwhois nmap mtr rrdtool MySQL-python net-snmp-utils vixie-cron php-mcrypt fping git pear install Net_IPv4-1.3.4 pear install Net_IPv6-1.2.2b2 diff --git a/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md b/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md index 0af3cc363b..1966542830 100644 --- a/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md +++ b/doc/Installation/Installation-Lighttpd-(Debian-Ubuntu).md @@ -37,7 +37,7 @@ Change `127.0.0.1` to the IP address that your MySQL server should listen on. R Install necessary software. The packages listed below are an all-inclusive list of packages that were necessary on a clean install of Debian 7. - apt-get install lighttpd php5-cli php5-mysql php5-gd php5-snmp php5-cgi php-pear snmp graphviz mysql-server mysql-client rrdtool sendmail fping imagemagick whois mtr-tiny nmap ipmitool php5-mcrypt php5-json python-mysqldb snmpd php-net-ipv4 php-net-ipv6 rrdtool git + apt-get install lighttpd php5-cli php5-mysql php5-gd php5-snmp php5-cgi php-pear php5-curl snmp graphviz mysql-server mysql-client rrdtool sendmail fping imagemagick whois mtr-tiny nmap ipmitool php5-mcrypt php5-json python-mysqldb snmpd php-net-ipv4 php-net-ipv6 rrdtool git ### Cloning ### diff --git a/html/ajax_table.php b/html/ajax_table.php index 7f906e64ad..dc5af2c6e6 100644 --- a/html/ajax_table.php +++ b/html/ajax_table.php @@ -39,6 +39,7 @@ if (isset($_POST['sort']) && is_array($_POST['sort'])) { } $searchPhrase = mres($_POST['searchPhrase']); $id = mres($_POST['id']); +$response = array(); if (isset($id)) { if (file_exists("includes/table/$id.inc.php")) { diff --git a/html/css/styles.css b/html/css/styles.css index 0b5b5faeb2..61a546dfb0 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -1605,3 +1605,8 @@ tr.search:nth-child(odd) { width: 90%; height: 600px; } + +.threeqtr-width { + display:block; + width: 75%; +} diff --git a/html/forms/callback-clear.inc.php b/html/forms/callback-clear.inc.php new file mode 100644 index 0000000000..236c28c90d --- /dev/null +++ b/html/forms/callback-clear.inc.php @@ -0,0 +1,15 @@ + + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +dbUpdate(array('value' => '2'), 'callback', '`name` = "enabled"', array()); diff --git a/html/forms/callback-statistics.inc.php b/html/forms/callback-statistics.inc.php new file mode 100644 index 0000000000..22f65e71d1 --- /dev/null +++ b/html/forms/callback-statistics.inc.php @@ -0,0 +1,25 @@ + + * + * 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 3 of the License, or (at your + * option) any later version. Please see LICENSE.txt at the top level of + * the source code distribution for details. + */ + +if ($_POST['state'] == 'true') { + $state = 1; +} elseif ($_POST['state'] == 'false') { + $state = 0; +} else { + $state = 0; +} + +if( dbUpdate(array('value' => $state), 'callback', '`name` = "enabled"', array()) == 0) { + dbInsert(array('value' => $state,'name' => 'enabled'), 'callback'); +} diff --git a/html/images/icons/battery charge.png b/html/images/icons/battery charge.png new file mode 100644 index 0000000000..ae40aaf3c9 Binary files /dev/null and b/html/images/icons/battery charge.png differ diff --git a/html/images/icons/charge.png b/html/images/icons/charge.png new file mode 100644 index 0000000000..ae40aaf3c9 Binary files /dev/null and b/html/images/icons/charge.png differ diff --git a/html/includes/authenticate.inc.php b/html/includes/authenticate.inc.php index 42dc82b33e..e64465a35e 100644 --- a/html/includes/authenticate.inc.php +++ b/html/includes/authenticate.inc.php @@ -108,6 +108,10 @@ if ((isset($_SESSION['username'])) || (isset($_COOKIE['sess_id'],$_COOKIE['token setcookie("auth", $_COOKIE['auth'], time()+60*60*24*$config['auth_remember'], "/", null, false, true); } $permissions = permissions_cache($_SESSION['user_id']); + if (isset($_POST['username'])) { + header('Location: '.$_SERVER['REQUEST_URI'],TRUE,303); + exit; + } } elseif (isset($_SESSION['username'])) { diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index b11033b78f..6a94719f1d 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -744,4 +744,12 @@ function shorten_interface_type($string) { ); } +function clean_bootgrid($string) { + + $output = str_replace(array("\r","\n"), "", $string); + $output = addslashes($output); + return $output; + +} + ?> diff --git a/html/includes/hostbox-basic.inc.php b/html/includes/hostbox-basic.inc.php deleted file mode 100644 index c46713d7c6..0000000000 --- a/html/includes/hostbox-basic.inc.php +++ /dev/null @@ -1,51 +0,0 @@ - - - ' . $image . ' - ' . generate_device_link($device) . '' - ); - -echo(''); -if ($port_count) { echo(' '.$port_count); } -echo('
'); -if ($sensor_count) { echo(' '.$sensor_count); } -echo(''); -echo(' ' . $device['hardware'] . ' ' . $device['features'] . ''); -echo(' ' . $device['os_text'] . ' ' . $device['version'] . ''); -echo(' ' . formatUptime($device['uptime'], 'short') . '
'); - -if (get_dev_attrib($device,'override_sysLocation_bool')) { $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); } -echo(' ' . truncate($device['location'],32, '') . ''); -require 'hostbox-menu.inc.php'; - -echo(' '); - -?> diff --git a/html/includes/hostbox.inc.php b/html/includes/hostbox.inc.php deleted file mode 100644 index 8d3115bb69..0000000000 --- a/html/includes/hostbox.inc.php +++ /dev/null @@ -1,60 +0,0 @@ - - - ' . $image . ' - ' . generate_device_link($device) . ' -
' . $device['sysName'] . '' - ); - -echo(''); -if ($port_count) { echo(' '.$port_count); } -echo('
'); -if ($sensor_count) { echo(' '.$sensor_count); } -echo(''); -echo(' ' . $device['hardware'] . '
' . $device['features'] . ''); -echo(' ' . $device['os_text'] . '
' . $device['version'] . ''); -echo(' ' . formatUptime($device['uptime'], 'short') . '
'); - -if (get_dev_attrib($device,'override_sysLocation_bool')) { $device['location'] = get_dev_attrib($device,'override_sysLocation_string'); } -echo(' ' . truncate($device['location'],32, '') . ''); -require 'hostbox-menu.inc.php'; - -echo(' '); - -?> diff --git a/html/includes/object-cache.inc.php b/html/includes/object-cache.inc.php index 45abaf45af..b6b9a50840 100644 --- a/html/includes/object-cache.inc.php +++ b/html/includes/object-cache.inc.php @@ -1,5 +1,7 @@ = 5) -{ - $devices['count'] = dbFetchCell("SELECT COUNT(*) FROM devices"); - $devices['up'] = dbFetchCell("SELECT COUNT(*) FROM devices WHERE `status` = '1' AND `ignore` = '0' AND `disabled` = '0'"); - $devices['down'] = dbFetchCell("SELECT COUNT(*) FROM devices WHERE `status` = '0' AND `ignore` = '0' AND `disabled` = '0'"); - $devices['ignored'] = dbFetchCell("SELECT COUNT(*) FROM devices WHERE `ignore` = '1' AND `disabled` = '0'"); - $devices['disabled'] = dbFetchCell("SELECT COUNT(*) FROM devices WHERE `disabled` = '1'"); - - $ports['count'] = dbFetchCell("SELECT COUNT(*) FROM ports WHERE `deleted` = '0'"); - $ports['up'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'up'"); - $ports['down'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up'"); - $ports['shutdown'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifAdminStatus` = 'down'"); - $ports['errored'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')"); - $ports['ignored'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND (I.`ignore` = '1' OR D.`ignore` = '1')"); - - $services['count'] = dbFetchCell("SELECT COUNT(*) FROM services"); - $services['up'] = dbFetchCell("SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '1'"); - $services['down'] = dbFetchCell("SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '0'"); - $services['ignored'] = dbFetchCell("SELECT COUNT(*) FROM services WHERE `service_ignore` = '1' AND `service_disabled` = '0'"); - $services['disabled'] = dbFetchCell("SELECT COUNT(*) FROM services WHERE `service_disabled` = '1'"); -} -else -{ - $devices['count'] = dbFetchCell("SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id`", array($_SESSION['user_id'])); - $devices['up'] = dbFetchCell("SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`status` = '1' AND D.`ignore` = '0' AND D.`disabled` = '0'", array($_SESSION['user_id'])); - $devices['down'] = dbFetchCell("SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`status` = '0' AND D.`ignore` = '0' AND D.`disabled` = '0'", array($_SESSION['user_id'])); - $devices['ignored'] = dbFetchCell("SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`ignore` = '1' AND D.`disabled` = '0'", array($_SESSION['user_id'])); - $devices['disabled'] = dbFetchCell("SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`disabled` = '1'", array($_SESSION['user_id'])); - - $ports['count'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id`", array($_SESSION['user_id'])); - $ports['up'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'up'", array($_SESSION['user_id'])); - $ports['down'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up'", array($_SESSION['user_id'])); - $ports['shutdown'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifAdminStatus` = 'down'", array($_SESSION['user_id'])); - $ports['errored'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')", array($_SESSION['user_id'])); - $ports['ignored'] = dbFetchCell("SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND (I.`ignore` = '1' OR D.`ignore` = '1')", array($_SESSION['user_id'])); - - $services['count'] = dbFetchCell("SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id`", array($_SESSION['user_id'])); - $services['up'] = dbFetchCell("SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '1'", array($_SESSION['user_id'])); - $services['down'] = dbFetchCell("SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0'", array($_SESSION['user_id'])); - $services['ignored'] = dbFetchCell("SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '1' AND S.`service_disabled` = '0'", array($_SESSION['user_id'])); - $services['disabled'] = dbFetchCell("SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_disabled` = '1'", array($_SESSION['user_id'])); -} +$devices = new ObjCache('devices'); +$ports = new ObjCache('ports'); +$services = new ObjCache('services'); if ($devices['down']) { $devices['bgcolour'] = "#ffcccc"; } else { $devices['bgcolour'] = "transparent"; } if ($ports['down']) { $ports['bgcolour'] = "#ffcccc"; } else { $ports['bgcolour'] = "#e5e5e5"; } diff --git a/html/includes/print-debug.php b/html/includes/print-debug.php index 5c23a35368..f35cd05bfe 100644 --- a/html/includes/print-debug.php +++ b/html/includes/print-debug.php @@ -47,7 +47,7 @@ foreach ($sql_debug as $sql_error) { + + + diff --git a/html/pages/front/default.php b/html/pages/front/default.php index 12bdc52e90..ac09f29088 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -199,10 +199,10 @@ if ($config['enable_syslog']) if ($_SESSION['userlevel'] >= '10') { $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id RIGHT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15"; + $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id ORDER BY `time_logged` DESC LIMIT 0,15"; } else { $query = "SELECT *,DATE_FORMAT(datetime, '%D %b %T') as humandate FROM `eventlog` AS E, devices_perms AS P WHERE E.host = P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; - $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id RIGHT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id'] . " ORDER BY `time_logged` DESC LIMIT 0,15"; + $alertquery = "SELECT devices.device_id,name,state,time_logged FROM alert_log LEFT JOIN devices ON alert_log.device_id=devices.device_id LEFT JOIN alert_rules ON alert_log.rule_id=alert_rules.id RIGHT JOIN devices_perms ON alert_log.device_id = devices_perms.device_id AND devices_perms.user_id = " . $_SESSION['user_id'] . " ORDER BY `time_logged` DESC LIMIT 0,15"; } $data = mysql_query($query); diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index 8b02112383..5e7df42666 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -1,139 +1,91 @@ - +
+
+ ARP Entries +
+ + + + + + + + + + + + +
-
-
- - + diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php index a557159f4b..39aeb028d3 100644 --- a/html/pages/search/ipv6.inc.php +++ b/html/pages/search/ipv6.inc.php @@ -1,96 +1,83 @@ - +
+
+ IPv6 Addresses +
+ + + + + + + + + + +
- -
- - + diff --git a/includes/alerts.inc.php b/includes/alerts.inc.php index 60f877b40f..aa5c8687ce 100644 --- a/includes/alerts.inc.php +++ b/includes/alerts.inc.php @@ -68,7 +68,7 @@ function GetRules($device) { $where .= " || alert_map.target = ?"; $params[] = 'g'.$group; } - return dbFetchRows('SELECT alert_rules.* FROM alert_rules LEFT JOIN alert_map ON alert_rules.id=alert_map.rule WHERE (alert_rules.device_id = -1 || alert_rules.device_id = ? ) || ( alert_map.target = ? '.$where.' )',$params); + return dbFetchRows('SELECT alert_rules.* FROM alert_rules LEFT JOIN alert_map ON alert_rules.id=alert_map.rule WHERE alert_rules.disabled = 0 && ( (alert_rules.device_id = -1 || alert_rules.device_id = ? ) || alert_map.target = ? '.$where.' )',$params); } /** diff --git a/includes/caches/devices.inc.php b/includes/caches/devices.inc.php new file mode 100644 index 0000000000..b8b5574eb8 --- /dev/null +++ b/includes/caches/devices.inc.php @@ -0,0 +1,52 @@ += 5 ) { + + $data['count'] = array( + 'query' => "SELECT COUNT(*) FROM devices", + ); + + $data['up'] = array( + 'query' => "SELECT COUNT(*) FROM devices WHERE `status` = '1' AND `ignore` = '0' AND `disabled` = '0'", + ); + + $data['down'] = array( + 'query' => "SELECT COUNT(*) FROM devices WHERE `status` = '0' AND `ignore` = '0' AND `disabled` = '0'", + ); + + $data['ignored'] = array( + 'query' => "SELECT COUNT(*) FROM devices WHERE `ignore` = '1' AND `disabled` = '0'", + ); + + $data['disabled'] = array( + 'query' => "SELECT COUNT(*) FROM devices WHERE `disabled` = '1'", + ); + +} else { + + $data['count'] = array( + 'query' => "SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id`", + 'params' => array($_SESSION['user_id']) + ); + + $data['up'] = array( + 'query' => "SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`status` = '1' AND D.`ignore` = '0' AND D.`disabled` = '0'", + 'params' => array($_SESSION['user_id']) + ); + + $data['down'] = array( + 'query' => "SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`status` = '0' AND D.`ignore` = '0' AND D.`disabled` = '0'", + 'params' => array($_SESSION['user_id']) + ); + + $data['ignored'] = array( + 'query' => "SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`ignore` = '1' AND D.`disabled` = '0'", + 'params' => array($_SESSION['user_id']) + ); + + $data['disabled'] = array( + 'query' => "SELECT COUNT(*) FROM devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND D.`disabled` = '1'", + 'params' => array($_SESSION['user_id']) + ); + +} diff --git a/includes/caches/ports.inc.php b/includes/caches/ports.inc.php new file mode 100644 index 0000000000..a9d4508f5b --- /dev/null +++ b/includes/caches/ports.inc.php @@ -0,0 +1,61 @@ += 5 ) { + + $data['count'] = array( + 'query' => "SELECT COUNT(*) FROM ports WHERE `deleted` = '0'", + ); + + $data['up'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'up'", + ); + + $data['down'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up'", + ); + + $data['shutdown'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifAdminStatus` = 'down'", + ); + + $data['errored'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')", + ); + + $data['ignored'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D WHERE I.`deleted` = '0' AND D.`device_id` = I.`device_id` AND (I.`ignore` = '1' OR D.`ignore` = '1')", + ); + +} else { + + $data['count'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id`", + 'params' => array($_SESSION['user_id']) + ); + + $data['up'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'up'", + 'params' => array($_SESSION['user_id']) + ); + + $data['down'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifOperStatus` = 'down' AND I.`ifAdminStatus` = 'up'", + 'params' => array($_SESSION['user_id']) + ); + + $data['shutdown'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND I.`ifAdminStatus` = 'down'", + 'params' => array($_SESSION['user_id']) + ); + + $data['errored'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND I.`ignore` = '0' AND D.`ignore` = '0' AND (I.`ifInErrors_delta` > '0' OR I.`ifOutErrors_delta` > '0')", + 'params' => array($_SESSION['user_id']) + ); + + $data['ignored'] = array( + 'query' => "SELECT COUNT(*) FROM ports AS I, devices AS D, devices_perms AS P WHERE I.`deleted` = '0' AND P.`user_id` = ? AND P.`device_id` = D.`device_id` AND I.`device_id` = D.`device_id` AND (I.`ignore` = '1' OR D.`ignore` = '1')", + 'params' => array($_SESSION['user_id']) + ); + +} \ No newline at end of file diff --git a/includes/caches/services.inc.php b/includes/caches/services.inc.php new file mode 100644 index 0000000000..6cb4179e75 --- /dev/null +++ b/includes/caches/services.inc.php @@ -0,0 +1,38 @@ += 5 ) { + + $data['count'] = array( 'query' => "SELECT COUNT(*) FROM services"); + $data['up'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '1'"); + $data['down'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '0' AND `service_disabled` = '0' AND `service_status` = '0'"); + $data['ignored'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_ignore` = '1' AND `service_disabled` = '0'"); + $data['disabled'] = array( 'query' => "SELECT COUNT(*) FROM services WHERE `service_disabled` = '1'"); + +} else { + + $data['count'] = array( + 'query' => "SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id`", + 'params' => array($_SESSION['user_id']) + ); + + $data['up'] = array( + 'query' => "SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '1'", + 'params' => array($_SESSION['user_id']) + ); + + $data['down'] = array( + 'query' => "SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '0' AND S.`service_disabled` = '0' AND S.`service_status` = '0'", + 'params' => array($_SESSION['user_id']) + ); + + $data['ignored'] = array( + 'query' => "SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_ignore` = '1' AND S.`service_disabled` = '0'", + 'params' => array($_SESSION['user_id']) + ); + + $data['disabled'] = array( + 'query' => "SELECT COUNT(*) FROM services AS S, devices AS D, devices_perms AS P WHERE P.`user_id` = ? AND P.`device_id` = D.`device_id` AND S.`device_id` = D.`device_id` AND S.`service_disabled` = '1'", + 'params' => array($_SESSION['user_id']) + ); + +} \ No newline at end of file diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 796c15a8da..7cee0e712b 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -599,4 +599,8 @@ $config['distributed_poller_group'] = 0; $config['distributed_poller_memcached_host'] = 'example.net'; $config['distributed_poller_memcached_port'] = '11211'; +// Stats callback system +$config['callback_post'] = 'https://stats.librenms.org/log.php'; +$config['callback_clear'] = 'https://stats.librenms.org/clear.php'; + ?> diff --git a/includes/discovery/discovery-protocols.inc.php b/includes/discovery/discovery-protocols.inc.php index 028731a5af..b7723a01e5 100755 --- a/includes/discovery/discovery-protocols.inc.php +++ b/includes/discovery/discovery-protocols.inc.php @@ -144,6 +144,33 @@ if ($lldp_array) } } +echo("OSPF Discovery: "); + +if ($config['autodiscovery']['ospf'] === TRUE) { + echo "enabled\n"; + foreach (dbFetchRows("SELECT DISTINCT(`ospfNbrIpAddr`),`device_id` FROM `ospf_nbrs`") as $nbr) { + $ip = $nbr['ospfNbrIpAddr']; + $device_id = $nbr['device_id']; + if (match_network($config['autodiscovery']['nets-exclude'], $ip)) { + echo("x"); + continue; + } + if (!match_network($config['nets'], $ip)) { + echo("i"); + continue; + } + $name = gethostbyaddr($ip); + $remote_device_id = discover_new_device($name); + if (isset($remote_device_id) && $remote_device_id > 0) { + log_event("Device $name ($ip) autodiscovered through OSPF", $remote_device_id, 'system'); + } else { + log_event("OSPF discovery of $name ($ip) failed - check ping and SNMP access", $device_id, 'system'); + } + } +} else { + echo "disabled\n"; +} + if ($debug) { print_r($link_exists); } $sql = "SELECT * FROM `links` AS L, `ports` AS I WHERE L.local_port_id = I.port_id AND I.device_id = '".$device['device_id']."'"; diff --git a/includes/functions.php b/includes/functions.php index e3905e3119..701229ecfa 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -1129,4 +1129,28 @@ function convert_delay($delay) { return($delay_sec); } -?> +function guidv4($data) { + // http://stackoverflow.com/questions/2040240/php-function-to-generate-v4-uuid#15875555 + // From: Jack http://stackoverflow.com/users/1338292/ja%CD%A2ck + assert(strlen($data) == 16); + + $data[6] = chr(ord($data[6]) & 0x0f | 0x40); // set version to 0100 + $data[8] = chr(ord($data[8]) & 0x3f | 0x80); // set bits 6-7 to 10 + + return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); +} + +function set_curl_proxy($post) +{ + global $config; + if (isset($_ENV['https_proxy'])) { + $tmp = rtrim($_ENV['https_proxy'], "/"); + $proxystr = str_replace(array("http://", "https://"), "", $tmp); + $config['callback_proxy'] = $proxystr; + echo "Setting proxy to ".$proxystr." (from https_proxy=".$_ENV['https_proxy'].")\n"; + } + if (isset($config['callback_proxy'])) { + echo "Using ".$config['callback_proxy']." as proxy\n"; + curl_setopt($post, CURLOPT_PROXY, $config['callback_proxy']); + } +} diff --git a/includes/object-cache.inc.php b/includes/object-cache.inc.php new file mode 100644 index 0000000000..bada138f0a --- /dev/null +++ b/includes/object-cache.inc.php @@ -0,0 +1,113 @@ + + * 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 3 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, see . */ + +/** + * Object-Cache + * @author f0o + * @copyright 2015 f0o, LibreNMS + * @license GPL + * @package LibreNMS + * @subpackage Cache + */ + +class ObjCache implements ArrayAccess { + private $data = array(); + private $obj = ""; + + /** + * Initialize ObjCache + * @param string $obj Name of Object + * @return void + */ + public function __construct( $obj ) { + global $config; + $this->obj = $obj; + if( isset($GLOBALS['_ObjCache'][$obj]) ) { + $this->data = $GLOBALS['_ObjCacheSkell'][$obj]; + } else { + if( !is_array($GLOBALS['_ObjCacheSkell']) ) { + $GLOBALS['_ObjCacheSkell'] = array(); + } + if( !is_array($GLOBALS['_ObjCache']) ) { + $GLOBALS['_ObjCache'] = array(); + } + if( file_exists($config['install_dir'].'/includes/caches/'.$obj.'.inc.php') ) { + $data = array(); + include($config['install_dir'].'/includes/caches/'.$obj.'.inc.php'); + $this->data = $data; + $GLOBALS['_ObjCacheSkell'][$obj] = $this->data; + if( !is_array($GLOBALS['_ObjCache'][$obj]) ) { + $GLOBALS['_ObjCache'][$obj] = $this->data; + } + } + } + } + + /** + * Check if data exists + * @param string $obj Name of Data-Object + * @return boolean + */ + public function offsetExists( $obj ) { + if( isset($this->data[$obj]) ) { + return true; + } + return false; + } + + /** + * Get Data-Object + * @param string $obj Name of Data-Object + * @return mixed + */ + public function offsetGet( $obj ) { + if( isset($this->data[$obj]) ) { + if( isset($this->data[$obj]['value']) ) { + return $this->data[$obj]['value']; + } elseif( isset($GLOBALS['_ObjCache'][$this->obj][$obj]['value']) ) { + return $GLOBALS['_ObjCache'][$this->obj][$obj]['value']; + } else { + $GLOBALS['_ObjCache'][$this->obj][$obj]['value'] = dbFetchCell($this->data[$obj]['query'],$this->data[$obj]['params']); + return $GLOBALS['_ObjCache'][$this->obj][$obj]['value']; + } + } + } + + /** + * Overrides internal Cache-Object + * @param string $obj Name of Data-Object + * @param mixed $value Value + * @return boolean + */ + public function offsetSet( $obj, $value ) { + if( !is_array($this->data[$obj]) ) { + $this->data[$obj] = array(); + } + $this->data[$obj]['value'] = $value; + return $this->data[$obj]['value']; + } + + /** + * Reset Data-Object + * @param string $obj Name of Data-Object + * @return mixed + */ + public function offsetUnset( $obj ) { + unset($this->data[$obj]['value']); + return true; + } + +} diff --git a/sql-schema/046.sql b/sql-schema/046.sql new file mode 100644 index 0000000000..6e9731270f --- /dev/null +++ b/sql-schema/046.sql @@ -0,0 +1 @@ +CREATE TABLE `callback` ( `callback_id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` CHAR( 64 ) NOT NULL , `value` CHAR( 64 ) NOT NULL ) ENGINE = INNODB; diff --git a/sql-schema/047.sql b/sql-schema/047.sql new file mode 100644 index 0000000000..ef57c40203 --- /dev/null +++ b/sql-schema/047.sql @@ -0,0 +1 @@ +ALTER TABLE `alert_log` ADD INDEX ( `time_logged` );