diff --git a/AUTHORS.md b/AUTHORS.md index ea14efa06..99b1fb4ab 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -23,7 +23,7 @@ Contributors to LibreNMS: - Stuart Henderson (sthen) - Filippo Giunchedi (filippog) - Lasse Leegaard (lasseleegaard) -- Mickael Marchand (mmarchand) +- Mickael Marchand (mmarchand) - Mohammad Al-Shami (mohshami) - Rudy Hardeman (zarya) - Arjit Chaudhary (arjit.c@gmail.com) (arjitc) diff --git a/build-base.php b/build-base.php index 10c8927d5..c82d6adbb 100644 --- a/build-base.php +++ b/build-base.php @@ -14,24 +14,24 @@ if ($sql_fh === false) { exit(1); } -$connection = mysql_connect($config['db_host'], $config['db_user'], $config['db_pass']); +$connection = mysqli_connect($config['db_host'], $config['db_user'], $config['db_pass']); if ($connection === false) { - echo 'ERROR: Cannot connect to database: '.mysql_error()."\n"; + echo 'ERROR: Cannot connect to database: '.mysqli_error($connection)."\n"; exit(1); } -$select = mysql_select_db($config['db_name']); +$select = mysqli_select_db($config['db_name']); if ($select === false) { - echo 'ERROR: Cannot select database: '.mysql_error()."\n"; + echo 'ERROR: Cannot select database: '.mysqli_error($connection)."\n"; exit(1); } while (!feof($sql_fh)) { $line = fgetss($sql_fh); if (!empty($line)) { - $creation = mysql_query($line); + $creation = mysqli_query($connection, $line); if (!$creation) { - echo 'WARNING: Cannot execute query ('.$line.'): '.mysql_error()."\n"; + echo 'WARNING: Cannot execute query ('.$line.'): '.mysqli_error($connection)."\n"; } } } diff --git a/config.php.default b/config.php.default index 479482113..1ed5d8c7e 100755 --- a/config.php.default +++ b/config.php.default @@ -1,12 +1,13 @@ You can configure all options for alerting and transports via the WebUI, config options in this document are crossed out but left for reference. + This document only covers the usage of it. See the [DEVELOPMENT.md](https://github.com/f0o/glowing-tyrion/blob/master/DEVELOPMENT.md) for code-documentation. # Rules @@ -125,34 +127,41 @@ Alert sent to: {foreach %contacts}%value <%key> {/foreach} # Transports -Transports are located within `$config['install_dir']/includes/alerts/transports.*.php` and defined as well as configured via `$config['alert']['transports']['Example'] = 'Some Options'`. +Transports are located within `$config['install_dir']/includes/alerts/transports.*.php` and defined as well as configured via ~~`$config['alert']['transports']['Example'] = 'Some Options'`~~. Contacts will be gathered automatically and passed to the configured transports. -By default the Contacts will be only gathered when the alert triggers and will ignore future changes in contacts for the incident. If you want contacts to be re-gathered before each dispatch, please set `$config['alert']['fixed-contacts'] = false;` in your config.php. +By default the Contacts will be only gathered when the alert triggers and will ignore future changes in contacts for the incident. If you want contacts to be re-gathered before each dispatch, please set ~~`$config['alert']['fixed-contacts'] = false;`~~ in your config.php. The contacts will always include the `SysContact` defined in the Device's SNMP configuration and also every LibreNMS-User that has at least `read`-permissions on the entity that is to be alerted. At the moment LibreNMS only supports Port or Device permissions. You can exclude the `SysContact` by setting: +~~ ```php $config['alert']['syscontact'] = false; ``` +~ To include users that have `Global-Read` or `Administrator` permissions it is required to add these additions to the `config.php` respectively: +~ ```php $config['alert']['globals'] = true; //Include Global-Read into alert-contacts $config['alert']['admins'] = true; //Include Adminstrators into alert-contacts ``` +~~ ## E-Mail > You can configure these options within the WebUI now, please avoid setting these options within config.php -E-Mail transport is enabled with adding the following to your `config.php`: +E-Mail transport is enabled with adding the following to your `config.php`: +~ ```php $config['alert']['transports']['mail'] = true; ``` +~~ The E-Mail transports uses the same email-configuration like the rest of LibreNMS. As a small reminder, here is it's configuration directives including defaults: +~~ ```php $config['email_backend'] = 'mail'; // Mail backend. Allowed: "mail" (PHP's built-in), "sendmail", "smtp". $config['email_from'] = NULL; // Mail from. Default: "ProjectName" @@ -169,13 +178,14 @@ $config['email_smtp_password'] = NULL; // Password f $config['alert']['default_only'] = false; //Only issue to default_mail $config['alert']['default_mail'] = ''; //Default email ``` +~~ ## API > You can configure these options within the WebUI now, please avoid setting these options within config.php API transports definitions are a bit more complex than the E-Mail configuration. -The basis for configuration is `$config['alert']['transports']['api'][METHOD]` where `METHOD` can be `get`,`post` or `put`. +The basis for configuration is ~~`$config['alert']['transports']['api'][METHOD]`~~ where `METHOD` can be `get`,`post` or `put`. This basis has to contain an array with URLs of each API to call. The URL can have the same placeholders as defined in the [Template-Syntax](#templates-syntax). If the `METHOD` is `get`, all placeholders will be URL-Encoded. @@ -183,9 +193,11 @@ The API transport uses cURL to call the APIs, therefore you might need to instal __Note__: it is highly recommended to define own [Templates](#templates) when you want to use the API transport. The default template might exceed URL-length for GET requests and therefore cause all sorts of errors. Example: +~~ ```php $config['alert']['transports']['api']['get'][] = "https://api.thirdparti.es/issue?apikey=abcdefg&subject=%title"; ``` +~~ ## Nagios Compatible @@ -193,19 +205,23 @@ $config['alert']['transports']['api']['get'][] = "https://api.thirdparti.es/issu The nagios transport will feed a FIFO at the defined location with the same format that nagios would. This allows you to use other Alerting-Systems to work with LibreNMS, for example [Flapjack](http://flapjack.io). +~~ ```php $config['alert']['transports']['nagios'] = "/path/to/my.fifo"; //Flapjack expects it to be at '/var/cache/nagios3/event_stream.fifo' ``` +~~ ## IRC > You can configure these options within the WebUI now, please avoid setting these options within config.php The IRC transports only works together with the LibreNMS IRC-Bot. -Configuration of the LibreNMS IRC-Bot is described [here](https://github.com/librenms/librenms/blob/master/doc/Extensions/IRC-Bot.md). +Configuration of the LibreNMS IRC-Bot is described [here](https://github.com/librenms/librenms/blob/master/doc/Extensions/IRC-Bot.md). +~~ ```php $config['alert']['transports']['irc'] = true; ``` +~~ ## Slack @@ -213,12 +229,14 @@ $config['alert']['transports']['irc'] = true; The Slack transport will POST the alert message to your Slack Incoming WebHook, you are able to specify multiple webhooks along with the relevant options to go with it. All options are optional, the only required value is for url, without this then no call to Slack will be made. Below is an example of how to send alerts to two channels with different customised options: +~~ ```php $config['alert']['transports']['slack'][] = array('url' => "https://hooks.slack.com/services/A12B34CDE/F56GH78JK/L901LmNopqrSTUVw2w3XYZAB4C", 'channel' => '#Alerting'); $config['alert']['transports']['slack'][] = array('url' => "https://hooks.slack.com/services/A12B34CDE/F56GH78JK/L901LmNopqrSTUVw2w3XYZAB4C", 'channel' => '@john', 'username' => 'LibreNMS', 'icon_emoji' => ':ghost:'); ``` +~~ ## HipChat @@ -249,6 +267,7 @@ for details on acceptable values. Below are two examples of sending messages to a HipChat room. +~~ ```php $config['alert']['transports']['hipchat'][] = array("url" => "https://api.hipchat.com/v1/rooms/message?auth_token=9109jawregoaih", "room_id" => "1234567", @@ -261,6 +280,7 @@ $config['alert']['transports']['hipchat'][] = array("url" => "https://api.hipcha "notify" => 1, "message_format" => "text"); ``` +~~ > Note: The default message format for HipChat messages is HTML. It is > recommended that you specify the `text` message format to prevent unexpected @@ -277,9 +297,11 @@ All you need is to create a Service with type Generic API on your PagerDuty dash Now copy your API-Key from the newly created Service and setup the transport like: +~~ ```php $config['alert']['transports']['pagerduty'] = 'MYAPIKEYGOESHERE'; ``` +~~ That's it! @@ -293,15 +315,18 @@ Firstly you need to create a new Application (called LibreNMS, for example) in y Now copy your API Token/Key from the newly created Application and setup the transport in your config.php like: +~~ ```php $config['alert']['transports']['pushover'][] = array( "appkey" => 'APPLICATIONAPIKEYGOESHERE', "userkey" => 'USERKEYGOESHERE', ); ``` +~~ To modify the Critical alert sound, add the 'sound_critical' parameter, example: +~~ ```php $config['alert']['transports']['pushover'][] = array( "appkey" => 'APPLICATIONAPIKEYGOESHERE', @@ -309,26 +334,31 @@ $config['alert']['transports']['pushover'][] = array( "sound_critical" => 'siren', ); ``` +~~ ## Boxcar Enabling Boxcar support is super easy. Copy your access token from the Boxcar app or from the Boxcar.io website and setup the transport in your config.php like: +~~ ```php $config['alert']['transports']['boxcar'][] = array( "access_token" => 'ACCESSTOKENGOESHERE', ); ``` +~~ To modify the Critical alert sound, add the 'sound_critical' parameter, example: +~~ ```php $config['alert']['transports']['boxcar'][] = array( "access_token" => 'ACCESSTOKENGOESHERE', "sound_critical" => 'detonator-charge', ); ``` +~~ # Entities diff --git a/doc/Extensions/Billing-Module.md b/doc/Extensions/Billing-Module.md index 18908a0e3..e46b5195d 100644 --- a/doc/Extensions/Billing-Module.md +++ b/doc/Extensions/Billing-Module.md @@ -11,8 +11,8 @@ $config['enable_billing'] = 1; # Enable Billing Edit `/etc/cron.d/librenms` and add the following: ```bash -*/5 * * * * root /opt/librenms/poll-billing.php >> /dev/null 2>&1 -01 * * * * root /opt/librenms/billing-calculate.php >> /dev/null 2>&1 +*/5 * * * * librenms /opt/librenms/poll-billing.php >> /dev/null 2>&1 +01 * * * * librenms /opt/librenms/billing-calculate.php >> /dev/null 2>&1 ``` -Create billing graphs as required. \ No newline at end of file +Create billing graphs as required. diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index f70b9f3e7..dfc2fd143 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -19,6 +19,22 @@ $config['log_dir'] = "/opt/librenms/logs"; ``` Log files created by LibreNMS will be stored within this directory. +#### Database config + +These are the configuration options you will need to use to specify to get started. + +```php +$config['db_host'] = "127.0.0.1"; +$config['db_user'] = ""; +$config['db_pass'] = ""; +$config['db_name'] = ""; +``` + +You can also select between the mysql and mysqli php extensions: + +```php +$config['db']['extension'] = 'mysqli'; +``` #### Progams @@ -260,10 +276,6 @@ Please see [Billing](http://docs.librenms.org/Extensions/Billing-Module/) sectio ```php $config['enable_bgp'] = 1; # Enable BGP session collection and display -$config['enable_rip'] = 1; # Enable RIP session collection and display -$config['enable_ospf'] = 1; # Enable OSPF session collection and display -$config['enable_isis'] = 1; # Enable ISIS session collection and display -$config['enable_eigrp'] = 1; # Enable EIGRP session collection and display $config['enable_syslog'] = 0; # Enable Syslog $config['enable_inventory'] = 1; # Enable Inventory $config['enable_pseudowires'] = 1; # Enable Pseudowires diff --git a/html/ajax_form.php b/html/ajax_form.php index b668551dd..999a43a4d 100644 --- a/html/ajax_form.php +++ b/html/ajax_form.php @@ -28,7 +28,7 @@ if (!$_SESSION['authenticated']) { } if (preg_match('/^[a-zA-Z0-9\-]+$/', $_POST['type']) == 1) { - if (file_exists('forms/'.$_POST['type'].'.inc.php')) { - include_once 'forms/'.$_POST['type'].'.inc.php'; + if (file_exists('includes/forms/'.$_POST['type'].'.inc.php')) { + include_once 'includes/forms/'.$_POST['type'].'.inc.php'; } } diff --git a/html/includes/common/syslog.inc.php b/html/includes/common/syslog.inc.php index c4ab66576..d77936133 100644 --- a/html/includes/common/syslog.inc.php +++ b/html/includes/common/syslog.inc.php @@ -1,7 +1,6 @@ diff --git a/html/forms/ack-alert.inc.php b/html/includes/forms/ack-alert.inc.php similarity index 100% rename from html/forms/ack-alert.inc.php rename to html/includes/forms/ack-alert.inc.php diff --git a/html/forms/alert-templates.inc.php b/html/includes/forms/alert-templates.inc.php similarity index 100% rename from html/forms/alert-templates.inc.php rename to html/includes/forms/alert-templates.inc.php diff --git a/html/forms/attach-alert-template.inc.php b/html/includes/forms/attach-alert-template.inc.php similarity index 100% rename from html/forms/attach-alert-template.inc.php rename to html/includes/forms/attach-alert-template.inc.php diff --git a/html/forms/callback-clear.inc.php b/html/includes/forms/callback-clear.inc.php similarity index 88% rename from html/forms/callback-clear.inc.php rename to html/includes/forms/callback-clear.inc.php index 236c28c90..38d990639 100644 --- a/html/forms/callback-clear.inc.php +++ b/html/includes/forms/callback-clear.inc.php @@ -12,4 +12,8 @@ * the source code distribution for details. */ +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + dbUpdate(array('value' => '2'), 'callback', '`name` = "enabled"', array()); diff --git a/html/forms/callback-statistics.inc.php b/html/includes/forms/callback-statistics.inc.php similarity index 91% rename from html/forms/callback-statistics.inc.php rename to html/includes/forms/callback-statistics.inc.php index 7e934b22d..36a2c4d9d 100644 --- a/html/forms/callback-statistics.inc.php +++ b/html/includes/forms/callback-statistics.inc.php @@ -12,6 +12,10 @@ * the source code distribution for details. */ +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + if ($_POST['state'] == 'true') { $state = 1; } diff --git a/html/forms/config-item-disable.inc.php b/html/includes/forms/config-item-disable.inc.php similarity index 93% rename from html/forms/config-item-disable.inc.php rename to html/includes/forms/config-item-disable.inc.php index 73ebfa5a2..a3475049f 100644 --- a/html/forms/config-item-disable.inc.php +++ b/html/includes/forms/config-item-disable.inc.php @@ -13,6 +13,11 @@ */ // FUA + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + if (!is_numeric($_POST['config_id'])) { echo 'error with data'; exit; diff --git a/html/forms/config-item-update.inc.php b/html/includes/forms/config-item-update.inc.php similarity index 92% rename from html/forms/config-item-update.inc.php rename to html/includes/forms/config-item-update.inc.php index bb8c12559..6f7b40e4e 100644 --- a/html/forms/config-item-update.inc.php +++ b/html/includes/forms/config-item-update.inc.php @@ -13,6 +13,11 @@ */ // FUA + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + if (!is_numeric($_POST['config_id']) || empty($_POST['data'])) { echo 'error with data'; exit; diff --git a/html/forms/config-item.inc.php b/html/includes/forms/config-item.inc.php similarity index 100% rename from html/forms/config-item.inc.php rename to html/includes/forms/config-item.inc.php diff --git a/html/forms/create-alert-item.inc.php b/html/includes/forms/create-alert-item.inc.php similarity index 100% rename from html/forms/create-alert-item.inc.php rename to html/includes/forms/create-alert-item.inc.php diff --git a/html/forms/create-device-group.inc.php b/html/includes/forms/create-device-group.inc.php similarity index 100% rename from html/forms/create-device-group.inc.php rename to html/includes/forms/create-device-group.inc.php diff --git a/html/forms/create-map-item.inc.php b/html/includes/forms/create-map-item.inc.php similarity index 100% rename from html/forms/create-map-item.inc.php rename to html/includes/forms/create-map-item.inc.php diff --git a/html/forms/delete-alert-map.inc.php b/html/includes/forms/delete-alert-map.inc.php similarity index 100% rename from html/forms/delete-alert-map.inc.php rename to html/includes/forms/delete-alert-map.inc.php diff --git a/html/forms/delete-alert-rule.inc.php b/html/includes/forms/delete-alert-rule.inc.php similarity index 100% rename from html/forms/delete-alert-rule.inc.php rename to html/includes/forms/delete-alert-rule.inc.php diff --git a/html/forms/delete-alert-template.inc.php b/html/includes/forms/delete-alert-template.inc.php similarity index 100% rename from html/forms/delete-alert-template.inc.php rename to html/includes/forms/delete-alert-template.inc.php diff --git a/html/forms/delete-device-group.inc.php b/html/includes/forms/delete-device-group.inc.php similarity index 100% rename from html/forms/delete-device-group.inc.php rename to html/includes/forms/delete-device-group.inc.php diff --git a/html/forms/discovery-module-update.inc.php b/html/includes/forms/discovery-module-update.inc.php similarity index 90% rename from html/forms/discovery-module-update.inc.php rename to html/includes/forms/discovery-module-update.inc.php index 61a0a28b6..168afe561 100644 --- a/html/forms/discovery-module-update.inc.php +++ b/html/includes/forms/discovery-module-update.inc.php @@ -1,6 +1,11 @@ 'error', + 'message' => 'Need to be admin', + ); + echo _json_encode($response); + exit; +} + // FIXME: Make this part of the API instead of a standalone function if (!is_numeric($_POST['device_id'])) { $status = 'error'; diff --git a/html/forms/schedule-maintenance.inc.php b/html/includes/forms/schedule-maintenance.inc.php similarity index 100% rename from html/forms/schedule-maintenance.inc.php rename to html/includes/forms/schedule-maintenance.inc.php diff --git a/html/forms/sensor-alert-reset.inc.php b/html/includes/forms/sensor-alert-reset.inc.php similarity index 91% rename from html/forms/sensor-alert-reset.inc.php rename to html/includes/forms/sensor-alert-reset.inc.php index eb6b2b967..2c027e647 100644 --- a/html/forms/sensor-alert-reset.inc.php +++ b/html/includes/forms/sensor-alert-reset.inc.php @@ -13,6 +13,11 @@ */ // FUA + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + for ($x = 0; $x < count($_POST['sensor_id']); $x++) { dbUpdate(array('sensor_limit' => $_POST['sensor_limit'][$x], 'sensor_limit_low' => $_POST['sensor_limit_low'][$x], 'sensor_alert' => $_POST['sensor_alert'][$x]), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'][$x])); } diff --git a/html/forms/sensor-alert-update.inc.php b/html/includes/forms/sensor-alert-update.inc.php similarity index 94% rename from html/forms/sensor-alert-update.inc.php rename to html/includes/forms/sensor-alert-update.inc.php index b0596db89..16c5742a6 100644 --- a/html/forms/sensor-alert-update.inc.php +++ b/html/includes/forms/sensor-alert-update.inc.php @@ -13,6 +13,11 @@ */ // FUA + +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + if (isset($_POST['sub_type']) && !empty($_POST['sub_type'])) { dbUpdate(array('sensor_custom' => 'No'), 'sensors', '`sensor_id` = ?', array($_POST['sensor_id'])); } diff --git a/html/forms/storage-update.inc.php b/html/includes/forms/storage-update.inc.php similarity index 88% rename from html/forms/storage-update.inc.php rename to html/includes/forms/storage-update.inc.php index 200a8f3d6..9c711db36 100644 --- a/html/forms/storage-update.inc.php +++ b/html/includes/forms/storage-update.inc.php @@ -12,6 +12,15 @@ * the source code distribution for details. */ +if (is_admin() === false) { + $response = array( + 'status' => 'error', + 'message' => 'Need to be admin', + ); + echo _json_encode($response); + exit; +} + $status = 'error'; $message = 'Error updating storage information'; diff --git a/html/forms/token-item-create.inc.php b/html/includes/forms/token-item-create.inc.php similarity index 94% rename from html/forms/token-item-create.inc.php rename to html/includes/forms/token-item-create.inc.php index b7c04944b..61810287a 100644 --- a/html/forms/token-item-create.inc.php +++ b/html/includes/forms/token-item-create.inc.php @@ -12,6 +12,10 @@ * the source code distribution for details. */ +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + if (!is_numeric($_POST['user_id']) || !isset($_POST['token'])) { echo 'ERROR: error with data, please ensure a valid user and token have been specified.'; exit; diff --git a/html/forms/token-item-disable.inc.php b/html/includes/forms/token-item-disable.inc.php similarity index 93% rename from html/forms/token-item-disable.inc.php rename to html/includes/forms/token-item-disable.inc.php index 987464ef1..1f962c020 100644 --- a/html/forms/token-item-disable.inc.php +++ b/html/includes/forms/token-item-disable.inc.php @@ -12,6 +12,10 @@ * the source code distribution for details. */ +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + if (!is_numeric($_POST['token_id'])) { echo 'error with data'; exit; diff --git a/html/forms/token-item-remove.inc.php b/html/includes/forms/token-item-remove.inc.php similarity index 92% rename from html/forms/token-item-remove.inc.php rename to html/includes/forms/token-item-remove.inc.php index e2f111efd..4d494672c 100644 --- a/html/forms/token-item-remove.inc.php +++ b/html/includes/forms/token-item-remove.inc.php @@ -12,6 +12,10 @@ * the source code distribution for details. */ +if(is_admin() === false) { + die('ERROR: You need to be admin'); +} + if (!is_numeric($_POST['token_id'])) { echo 'error with data'; exit; diff --git a/html/forms/update-alert-rule.inc.php b/html/includes/forms/update-alert-rule.inc.php similarity index 100% rename from html/forms/update-alert-rule.inc.php rename to html/includes/forms/update-alert-rule.inc.php diff --git a/html/forms/update-config-item.inc.php b/html/includes/forms/update-config-item.inc.php similarity index 100% rename from html/forms/update-config-item.inc.php rename to html/includes/forms/update-config-item.inc.php diff --git a/html/forms/update-dashboard-config.inc.php b/html/includes/forms/update-dashboard-config.inc.php similarity index 100% rename from html/forms/update-dashboard-config.inc.php rename to html/includes/forms/update-dashboard-config.inc.php diff --git a/html/forms/update-ports.inc.php b/html/includes/forms/update-ports.inc.php similarity index 92% rename from html/forms/update-ports.inc.php rename to html/includes/forms/update-ports.inc.php index 24754e246..5c0e327a9 100644 --- a/html/forms/update-ports.inc.php +++ b/html/includes/forms/update-ports.inc.php @@ -1,5 +1,14 @@ 'error', + 'message' => 'Need to be admin', + ); + echo _json_encode($response); + exit; +} + $status = 'error'; $message = 'Error with config'; diff --git a/html/includes/table/customers.inc.php b/html/includes/table/customers.inc.php new file mode 100644 index 000000000..f3c931ad1 --- /dev/null +++ b/html/includes/table/customers.inc.php @@ -0,0 +1,105 @@ +'.$port['ifTrunk'].''; + } + else if ($port['ifVlan']) { + $vlan = 'VLAN '.$port['ifVlan'].''; + } + else { + $vlan = ''; + } + } + + $response[] = array( + 'port_descr_descr' => $customer_name, + 'device_id' => generate_device_link($device), + 'ifDescr' => generate_port_link($port, makeshortif($port['ifDescr'])), + 'port_descr_speed' => $port['port_descr_speed'], + 'port_descr_circuit' => $port['port_descr_circuit'], + 'port_descr_notes' => $port['port_descr_notes'], + + ); + + unset($customer_name); + } + + + $graph_array['type'] = 'customer_bits'; + $graph_array['height'] = '100'; + $graph_array['width'] = '220'; + $graph_array['to'] = $config['time']['now']; + $graph_array['id'] = $customer['port_descr_descr']; + + $return_data = true; + include 'includes/print-graphrow.inc.php'; + $response[] = array( + 'port_descr_descr' => $graph_data[0], + 'device_id' => $graph_data[1], + 'ifDescr' => '', + 'port_descr_speed' => '', + 'port_descr_circuit' => $graph_data[2], + 'port_descr_notes' => $graph_data[3], + ); +} + +$output = array( + 'current' => $current, + 'rowCount' => $rowCount, + 'rows' => $response, + 'total' => $total, +); + +echo _json_encode($output); \ No newline at end of file diff --git a/html/install.php b/html/install.php index 4b9749498..d401f5723 100644 --- a/html/install.php +++ b/html/install.php @@ -352,6 +352,7 @@ $config_file = <<<"EOD" \$config\['db_user'\] = "$dbuser"; \$config\['db_pass'\] = "$dbpass"; \$config\['db_name'\] = "$dbname"; +\$config\['db'\]\['extension'\] = "mysqli";// mysql or mysqli ### Memcached config - We use this to store realtime usage \$config\['memcached'\]\['enable'\] = FALSE; diff --git a/html/network-map.php b/html/network-map.php index 7907eee54..040464c78 100644 --- a/html/network-map.php +++ b/html/network-map.php @@ -212,7 +212,6 @@ if (isset($_GET['format']) && preg_match("/^[a-z]*$/", $_GET['format'])) { } if ($where == '') { -# $maptool = $config['unflatten'] . ' -f -l 5 | ' . $config['sfdp'] . ' -Gpack -Goverlap=prism -Gcharset=latin1 | dot'; $maptool = $config['sfdp'] . ' -Gpack -Goverlap=prism -Gcharset=latin1 -Gsize=20,20'; $maptool = $config['dot']; } diff --git a/html/pages/customers.inc.php b/html/pages/customers.inc.php index cfb974432..40277817e 100644 --- a/html/pages/customers.inc.php +++ b/html/pages/customers.inc.php @@ -1,87 +1,34 @@ '; - -echo " - - - Customer - Device - Interface - Speed - Circuit - Notes - - "; - -$i = 1; - $pagetitle[] = 'Customers'; -if (!is_array($config['customers_descr'])) { - $config['customers_descr'] = array($config['customers_descr']); -} +?> -$descr_type = "'".implode("', '", $config['customers_descr'])."'"; +
+ + + + + + + + + + + +
CustomerDeviceInterfaceSpeedCircuitNotes
+
-foreach (dbFetchRows('SELECT * FROM `ports` WHERE `port_descr_type` IN (?) GROUP BY `port_descr_descr` ORDER BY `port_descr_descr`', array(array($descr_type))) as $customer) { - $i++; + diff --git a/html/pages/front/default.php b/html/pages/front/default.php index 58cc05dea..69ea03e9f 100644 --- a/html/pages/front/default.php +++ b/html/pages/front/default.php @@ -174,7 +174,6 @@ echo ' if ($config['enable_syslog']) { $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY timestamp DESC LIMIT 20"; - $query = mysql_query($sql); echo '
@@ -214,9 +213,6 @@ else { $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); - $alertdata = mysql_query($alertquery); - echo '
diff --git a/html/pages/front/globe.php b/html/pages/front/globe.php index f4d8d300e..ac87ed568 100644 --- a/html/pages/front/globe.php +++ b/html/pages/front/globe.php @@ -68,7 +68,6 @@ echo '
//From default.php - This code is not part of above license. if ($config['enable_syslog']) { $sql = "SELECT *, DATE_FORMAT(timestamp, '".$config['dateformat']['mysql']['compact']."') AS date from syslog ORDER BY seq DESC LIMIT 20"; - $query = mysql_query($sql); echo('
@@ -106,8 +105,6 @@ else { P.device_id AND P.user_id = " . $_SESSION['user_id'] . " ORDER BY `datetime` DESC LIMIT 0,15"; } - $data = mysql_query($query); - echo('
diff --git a/includes/alerts.inc.php b/includes/alerts.inc.php index f223b5991..1d5c5c91c 100644 --- a/includes/alerts.inc.php +++ b/includes/alerts.inc.php @@ -261,7 +261,7 @@ function RunRules($device) { $extra = gzcompress(json_encode(array('contacts' => GetContacts($qry), 'rule'=>$qry)),9); if( dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'details' => $extra),'alert_log') ) { if( !dbUpdate(array('state' => 1, 'open' => 1),'alerts','device_id = ? && rule_id = ?', array($device,$rule['id'])) ) { - dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1),'alerts'); + dbInsert(array('state' => 1, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1,'alerted' => 0),'alerts'); } echo " ALERT "; } @@ -274,7 +274,7 @@ function RunRules($device) { else { if( dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id']),'alert_log') ){ if( !dbUpdate(array('state' => 0, 'open' => 1),'alerts','device_id = ? && rule_id = ?', array($device,$rule['id'])) ) { - dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1),'alerts'); + dbInsert(array('state' => 0, 'device_id' => $device, 'rule_id' => $rule['id'], 'open' => 1, 'alerted' => 0),'alerts'); } echo " OK "; } diff --git a/includes/common.php b/includes/common.php index d5ba05fb0..c4788d064 100644 --- a/includes/common.php +++ b/includes/common.php @@ -319,7 +319,13 @@ function truncate($substring, $max = 50, $rep = '...') { function mres($string) { // short function wrapper because the real one is stupidly long and ugly. aesthetics. - return mysql_real_escape_string($string); + global $config, $database_link; + if ($config['db']['extension'] == 'mysqli') { + return mysqli_real_escape_string($database_link,$string); + } + else { + return mysql_real_escape_string($string); + } } function getifhost($id) { diff --git a/includes/dbFacile.mysql.php b/includes/dbFacile.mysql.php new file mode 100644 index 000000000..0d1d7150c --- /dev/null +++ b/includes/dbFacile.mysql.php @@ -0,0 +1,554 @@ +convert("\nSQL[%y".$fullSql.'%n] '); + } + else { + $sql_debug[] = $fullSql; + } + } + + /* + if($this->logFile) + $time_start = microtime(true); + */ + + $result = mysql_query($fullSql); + // sets $this->result + /* + if($this->logFile) { + $time_end = microtime(true); + fwrite($this->logFile, date('Y-m-d H:i:s') . "\n" . $fullSql . "\n" . number_format($time_end - $time_start, 8) . " seconds\n\n"); + } + */ + + if ($result === false && (error_reporting() & 1)) { + // aye. this gets triggers on duplicate Contact insert + // trigger_error('QDB - Error in query: ' . $fullSql . ' : ' . mysql_error(), E_USER_WARNING); + } + + return $result; + +}//end dbQuery() + + +/* + * Passed an array and a table name, it attempts to insert the data into the table. + * Check for boolean false to determine whether insert failed + * */ + + +function dbInsert($data, $table) { + global $fullSql; + global $db_stats; + // the following block swaps the parameters if they were given in the wrong order. + // it allows the method to work for those that would rather it (or expect it to) + // follow closer with SQL convention: + // insert into the TABLE this DATA + if (is_string($data) && is_array($table)) { + $tmp = $data; + $data = $table; + $table = $tmp; + // trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE); + } + + $sql = 'INSERT INTO `'.$table.'` (`'.implode('`,`', array_keys($data)).'`) VALUES ('.implode(',', dbPlaceHolders($data)).')'; + + $time_start = microtime(true); + dbBeginTransaction(); + $result = dbQuery($sql, $data); + if ($result) { + $id = mysql_insert_id(); + dbCommitTransaction(); + // return $id; + } + else { + if ($table != 'Contact') { + trigger_error('QDB - Insert failed.', E_USER_WARNING); + } + + dbRollbackTransaction(); + // $id = false; + } + + // logfile($fullSql); + $time_end = microtime(true); + $db_stats['insert_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['insert']++; + + return $id; + +}//end dbInsert() + + +/* + * Passed an array and a table name, it attempts to insert the data into the table. + * $data is an array (rows) of key value pairs. keys are fields. Rows need to have same fields. + * Check for boolean false to determine whether insert failed + * */ + + +function dbBulkInsert($data, $table) { + global $db_stats; + // the following block swaps the parameters if they were given in the wrong order. + // it allows the method to work for those that would rather it (or expect it to) + // follow closer with SQL convention: + // insert into the TABLE this DATA + if (is_string($data) && is_array($table)) { + $tmp = $data; + $data = $table; + $table = $tmp; + } + if (count($data) === 0) { + return false; + } + if (count($data[0]) === 0) { + return false; + } + + $sql = 'INSERT INTO `'.$table.'` (`'.implode('`,`', array_keys($data[0])).'`) VALUES '; + $values =''; + + foreach ($data as $row) { + if ($values != '') { + $values .= ','; + } + $rowvalues=''; + foreach ($row as $key => $value) { + if ($rowvalues != '') { + $rowvalues .= ','; + } + $rowvalues .= "'".mres($value)."'"; + } + $values .= "(".$rowvalues.")"; + } + + $time_start = microtime(true); + $result = dbQuery($sql.$values); + + // logfile($fullSql); + $time_end = microtime(true); + $db_stats['insert_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['insert']++; + + return $result; + +}//end dbBulkInsert() + + +/* + * Passed an array, table name, WHERE clause, and placeholder parameters, it attempts to update a record. + * Returns the number of affected rows + * */ + + +function dbUpdate($data, $table, $where=null, $parameters=array()) { + global $fullSql; + global $db_stats; + // the following block swaps the parameters if they were given in the wrong order. + // it allows the method to work for those that would rather it (or expect it to) + // follow closer with SQL convention: + // update the TABLE with this DATA + if (is_string($data) && is_array($table)) { + $tmp = $data; + $data = $table; + $table = $tmp; + // trigger_error('QDB - The first two parameters passed to update() were in reverse order, but it has been allowed', E_USER_NOTICE); + } + + // need field name and placeholder value + // but how merge these field placeholders with actual $parameters array for the WHERE clause + $sql = 'UPDATE `'.$table.'` set '; + foreach ($data as $key => $value) { + $sql .= '`'.$key.'` '.'=:'.$key.','; + } + + $sql = substr($sql, 0, -1); + // strip off last comma + if ($where) { + $sql .= ' WHERE '.$where; + $data = array_merge($data, $parameters); + } + + $time_start = microtime(true); + if (dbQuery($sql, $data)) { + $return = mysql_affected_rows(); + } + else { + // echo("$fullSql"); + trigger_error('QDB - Update failed.', E_USER_WARNING); + $return = false; + } + + $time_end = microtime(true); + $db_stats['update_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['update']++; + + return $return; + +}//end dbUpdate() + + +function dbDelete($table, $where=null, $parameters=array()) { + $sql = 'DELETE FROM `'.$table.'`'; + if ($where) { + $sql .= ' WHERE '.$where; + } + + if (dbQuery($sql, $parameters)) { + return mysql_affected_rows(); + } + else { + return false; + } + +}//end dbDelete() + + +/* + * Fetches all of the rows (associatively) from the last performed query. + * Most other retrieval functions build off this + * */ + + +function dbFetchRows($sql, $parameters=array()) { + global $db_stats; + + $time_start = microtime(true); + $result = dbQuery($sql, $parameters); + + if (mysql_num_rows($result) > 0) { + $rows = array(); + while ($row = mysql_fetch_assoc($result)) { + $rows[] = $row; + } + + mysql_free_result($result); + return $rows; + } + + mysql_free_result($result); + + $time_end = microtime(true); + $db_stats['fetchrows_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchrows']++; + + // no records, thus return empty array + // which should evaluate to false, and will prevent foreach notices/warnings + return array(); + +}//end dbFetchRows() + + +/* + * This is intended to be the method used for large result sets. + * It is intended to return an iterator, and act upon buffered data. + * */ + + +function dbFetch($sql, $parameters=array()) { + return dbFetchRows($sql, $parameters); + /* + // for now, don't do the iterator thing + $result = dbQuery($sql, $parameters); + if($result) { + // return new iterator + return new dbIterator($result); + } else { + return null; // ?? + } + */ + +}//end dbFetch() + + +/* + * Like fetch(), accepts any number of arguments + * The first argument is an sprintf-ready query stringTypes + * */ + + +function dbFetchRow($sql=null, $parameters=array()) { + global $db_stats; + + $time_start = microtime(true); + $result = dbQuery($sql, $parameters); + if ($result) { + $row = mysql_fetch_assoc($result); + mysql_free_result($result); + $time_end = microtime(true); + + $db_stats['fetchrow_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchrow']++; + + return $row; + } + else { + return null; + } + + $time_start = microtime(true); + +}//end dbFetchRow() + + +/* + * Fetches the first call from the first row returned by the query + * */ + + +function dbFetchCell($sql, $parameters=array()) { + global $db_stats; + $time_start = microtime(true); + $row = dbFetchRow($sql, $parameters); + if ($row) { + return array_shift($row); + // shift first field off first row + } + + $time_end = microtime(true); + + $db_stats['fetchcell_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchcell']++; + + return null; + +}//end dbFetchCell() + + +/* + * This method is quite different from fetchCell(), actually + * It fetches one cell from each row and places all the values in 1 array + * */ + + +function dbFetchColumn($sql, $parameters=array()) { + global $db_stats; + $time_start = microtime(true); + $cells = array(); + foreach (dbFetch($sql, $parameters) as $row) { + $cells[] = array_shift($row); + } + + $time_end = microtime(true); + + $db_stats['fetchcol_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchcol']++; + + return $cells; + +}//end dbFetchColumn() + + +/* + * Should be passed a query that fetches two fields + * The first will become the array key + * The second the key's value + */ + + +function dbFetchKeyValue($sql, $parameters=array()) { + $data = array(); + foreach (dbFetch($sql, $parameters) as $row) { + $key = array_shift($row); + if (sizeof($row) == 1) { + // if there were only 2 fields in the result + // use the second for the value + $data[$key] = array_shift($row); + } + else { + // if more than 2 fields were fetched + // use the array of the rest as the value + $data[$key] = $row; + } + } + + return $data; + +}//end dbFetchKeyValue() + + +/* + * This combines a query and parameter array into a final query string for execution + * PDO drivers don't need to use this + */ + + +function dbMakeQuery($sql, $parameters) { + // bypass extra logic if we have no parameters + if (sizeof($parameters) == 0) { + return $sql; + } + + $parameters = dbPrepareData($parameters); + // separate the two types of parameters for easier handling + $questionParams = array(); + $namedParams = array(); + foreach ($parameters as $key => $value) { + if (is_numeric($key)) { + $questionParams[] = $value; + } + else { + $namedParams[':'.$key] = $value; + } + } + + // sort namedParams in reverse to stop substring squashing + krsort($namedParams); + + // split on question-mark and named placeholders + $result = preg_split('/(\?|:[a-zA-Z0-9_-]+)/', $sql, -1, (PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)); + + // every-other item in $result will be the placeholder that was found + $query = ''; + $res_size = sizeof($result); + for ($i = 0; $i < $res_size; $i += 2) { + $query .= $result[$i]; + + $j = ($i + 1); + if (array_key_exists($j, $result)) { + $test = $result[$j]; + if ($test == '?') { + $query .= array_shift($questionParams); + } + else { + $query .= $namedParams[$test]; + } + } + } + + return $query; + +}//end dbMakeQuery() + + +function dbPrepareData($data) { + $values = array(); + + foreach ($data as $key => $value) { + $escape = true; + // don't quote or esc if value is an array, we treat it + // as a "decorator" that tells us not to escape the + // value contained in the array + if (is_array($value) && !is_object($value)) { + $escape = false; + $value = array_shift($value); + } + + // it's not right to worry about invalid fields in this method because we may be operating on fields + // that are aliases, or part of other tables through joins + // if(!in_array($key, $columns)) // skip invalid fields + // continue; + if ($escape) { + $values[$key] = "'".mysql_real_escape_string($value)."'"; + } + else { + $values[$key] = $value; + } + } + + return $values; + +}//end dbPrepareData() + + +/* + * Given a data array, this returns an array of placeholders + * These may be question marks, or ":email" type + */ + + +function dbPlaceHolders($values) { + $data = array(); + foreach ($values as $key => $value) { + if (is_numeric($key)) { + $data[] = '?'; + } + else { + $data[] = ':'.$key; + } + } + + return $data; + +}//end dbPlaceHolders() + + +function dbBeginTransaction() { + mysql_query('begin'); + +}//end dbBeginTransaction() + + +function dbCommitTransaction() { + mysql_query('commit'); + +}//end dbCommitTransaction() + + +function dbRollbackTransaction() { + mysql_query('rollback'); + +}//end dbRollbackTransaction() + + +/* + class dbIterator implements Iterator { + private $result; + private $i; + + public function __construct($r) { + $this->result = $r; + $this->i = 0; + } + public function rewind() { + mysql_data_seek($this->result, 0); + $this->i = 0; + } + public function current() { + $a = mysql_fetch_assoc($this->result); + return $a; + } + public function key() { + return $this->i; + } + public function next() { + $this->i++; + $a = mysql_data_seek($this->result, $this->i); + if($a === false) { + $this->i = 0; + } + return $a; + } + public function valid() { + return ($this->current() !== false); + } + } + */ diff --git a/includes/dbFacile.mysqli.php b/includes/dbFacile.mysqli.php new file mode 100644 index 000000000..2408ca990 --- /dev/null +++ b/includes/dbFacile.mysqli.php @@ -0,0 +1,559 @@ +convert("\nSQL[%y".$fullSql.'%n] '); + } + else { + $sql_debug[] = $fullSql; + } + } + + /* + if($this->logFile) + $time_start = microtime(true); + */ + + $result = mysqli_query($database_link, $fullSql); + // sets $this->result + /* + if($this->logFile) { + $time_end = microtime(true); + fwrite($this->logFile, date('Y-m-d H:i:s') . "\n" . $fullSql . "\n" . number_format($time_end - $time_start, 8) . " seconds\n\n"); + } + */ + + if ($result === false && (error_reporting() & 1)) { + // aye. this gets triggers on duplicate Contact insert + // trigger_error('QDB - Error in query: ' . $fullSql . ' : ' . mysql_error(), E_USER_WARNING); + } + + return $result; + +}//end dbQuery() + + +/* + * Passed an array and a table name, it attempts to insert the data into the table. + * Check for boolean false to determine whether insert failed + * */ + + +function dbInsert($data, $table) { + global $fullSql, $database_link; + global $db_stats; + // the following block swaps the parameters if they were given in the wrong order. + // it allows the method to work for those that would rather it (or expect it to) + // follow closer with SQL convention: + // insert into the TABLE this DATA + if (is_string($data) && is_array($table)) { + $tmp = $data; + $data = $table; + $table = $tmp; + // trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE); + } + + $sql = 'INSERT INTO `'.$table.'` (`'.implode('`,`', array_keys($data)).'`) VALUES ('.implode(',', dbPlaceHolders($data)).')'; + + $time_start = microtime(true); + dbBeginTransaction(); + $result = dbQuery($sql, $data); + if ($result) { + $id = mysqli_insert_id($database_link); + dbCommitTransaction(); + // return $id; + } + else { + if ($table != 'Contact') { + trigger_error('QDB - Insert failed.', E_USER_WARNING); + } + + dbRollbackTransaction(); + // $id = false; + } + + // logfile($fullSql); + $time_end = microtime(true); + $db_stats['insert_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['insert']++; + + return $id; + +}//end dbInsert() + + +/* + * Passed an array and a table name, it attempts to insert the data into the table. + * $data is an array (rows) of key value pairs. keys are fields. Rows need to have same fields. + * Check for boolean false to determine whether insert failed + * */ + + +function dbBulkInsert($data, $table) { + global $db_stats; + // the following block swaps the parameters if they were given in the wrong order. + // it allows the method to work for those that would rather it (or expect it to) + // follow closer with SQL convention: + // insert into the TABLE this DATA + if (is_string($data) && is_array($table)) { + $tmp = $data; + $data = $table; + $table = $tmp; + } + if (count($data) === 0) { + return false; + } + if (count($data[0]) === 0) { + return false; + } + + $sql = 'INSERT INTO `'.$table.'` (`'.implode('`,`', array_keys($data[0])).'`) VALUES '; + $values =''; + + foreach ($data as $row) { + if ($values != '') { + $values .= ','; + } + $rowvalues=''; + foreach ($row as $key => $value) { + if ($rowvalues != '') { + $rowvalues .= ','; + } + $rowvalues .= "'".mres($value)."'"; + } + $values .= "(".$rowvalues.")"; + } + + $time_start = microtime(true); + $result = dbQuery($sql.$values); + + // logfile($fullSql); + $time_end = microtime(true); + $db_stats['insert_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['insert']++; + + return $result; + +}//end dbBulkInsert() + + +/* + * Passed an array, table name, WHERE clause, and placeholder parameters, it attempts to update a record. + * Returns the number of affected rows + * */ + + +function dbUpdate($data, $table, $where=null, $parameters=array()) { + global $fullSql, $database_link; + global $db_stats; + // the following block swaps the parameters if they were given in the wrong order. + // it allows the method to work for those that would rather it (or expect it to) + // follow closer with SQL convention: + // update the TABLE with this DATA + if (is_string($data) && is_array($table)) { + $tmp = $data; + $data = $table; + $table = $tmp; + // trigger_error('QDB - The first two parameters passed to update() were in reverse order, but it has been allowed', E_USER_NOTICE); + } + + // need field name and placeholder value + // but how merge these field placeholders with actual $parameters array for the WHERE clause + $sql = 'UPDATE `'.$table.'` set '; + foreach ($data as $key => $value) { + $sql .= '`'.$key.'` '.'=:'.$key.','; + } + + $sql = substr($sql, 0, -1); + // strip off last comma + if ($where) { + $sql .= ' WHERE '.$where; + $data = array_merge($data, $parameters); + } + + $time_start = microtime(true); + if (dbQuery($sql, $data)) { + $return = mysqli_affected_rows($database_link); + } + else { + // echo("$fullSql"); + trigger_error('QDB - Update failed.', E_USER_WARNING); + $return = false; + } + + $time_end = microtime(true); + $db_stats['update_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['update']++; + + return $return; + +}//end dbUpdate() + + +function dbDelete($table, $where=null, $parameters=array()) { + global $database_link; + $sql = 'DELETE FROM `'.$table.'`'; + if ($where) { + $sql .= ' WHERE '.$where; + } + + if (dbQuery($sql, $parameters)) { + return mysqli_affected_rows($database_link); + } + else { + return false; + } + +}//end dbDelete() + + +/* + * Fetches all of the rows (associatively) from the last performed query. + * Most other retrieval functions build off this + * */ + + +function dbFetchRows($sql, $parameters=array()) { + global $db_stats; + + $time_start = microtime(true); + $result = dbQuery($sql, $parameters); + + if (mysqli_num_rows($result) > 0) { + $rows = array(); + while ($row = mysqli_fetch_assoc($result)) { + $rows[] = $row; + } + + mysqli_free_result($result); + return $rows; + } + + mysqli_free_result($result); + + $time_end = microtime(true); + $db_stats['fetchrows_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchrows']++; + + // no records, thus return empty array + // which should evaluate to false, and will prevent foreach notices/warnings + return array(); + +}//end dbFetchRows() + + +/* + * This is intended to be the method used for large result sets. + * It is intended to return an iterator, and act upon buffered data. + * */ + + +function dbFetch($sql, $parameters=array()) { + return dbFetchRows($sql, $parameters); + /* + // for now, don't do the iterator thing + $result = dbQuery($sql, $parameters); + if($result) { + // return new iterator + return new dbIterator($result); + } else { + return null; // ?? + } + */ + +}//end dbFetch() + + +/* + * Like fetch(), accepts any number of arguments + * The first argument is an sprintf-ready query stringTypes + * */ + + +function dbFetchRow($sql=null, $parameters=array()) { + global $db_stats; + + $time_start = microtime(true); + $result = dbQuery($sql, $parameters); + if ($result) { + $row = mysqli_fetch_assoc($result); + mysqli_free_result($result); + $time_end = microtime(true); + + $db_stats['fetchrow_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchrow']++; + + return $row; + } + else { + return null; + } + + $time_start = microtime(true); + +}//end dbFetchRow() + + +/* + * Fetches the first call from the first row returned by the query + * */ + + +function dbFetchCell($sql, $parameters=array()) { + global $db_stats; + $time_start = microtime(true); + $row = dbFetchRow($sql, $parameters); + if ($row) { + return array_shift($row); + // shift first field off first row + } + + $time_end = microtime(true); + + $db_stats['fetchcell_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchcell']++; + + return null; + +}//end dbFetchCell() + + +/* + * This method is quite different from fetchCell(), actually + * It fetches one cell from each row and places all the values in 1 array + * */ + + +function dbFetchColumn($sql, $parameters=array()) { + global $db_stats; + $time_start = microtime(true); + $cells = array(); + foreach (dbFetch($sql, $parameters) as $row) { + $cells[] = array_shift($row); + } + + $time_end = microtime(true); + + $db_stats['fetchcol_sec'] += number_format(($time_end - $time_start), 8); + $db_stats['fetchcol']++; + + return $cells; + +}//end dbFetchColumn() + + +/* + * Should be passed a query that fetches two fields + * The first will become the array key + * The second the key's value + */ + + +function dbFetchKeyValue($sql, $parameters=array()) { + $data = array(); + foreach (dbFetch($sql, $parameters) as $row) { + $key = array_shift($row); + if (sizeof($row) == 1) { + // if there were only 2 fields in the result + // use the second for the value + $data[$key] = array_shift($row); + } + else { + // if more than 2 fields were fetched + // use the array of the rest as the value + $data[$key] = $row; + } + } + + return $data; + +}//end dbFetchKeyValue() + + +/* + * This combines a query and parameter array into a final query string for execution + * PDO drivers don't need to use this + */ + + +function dbMakeQuery($sql, $parameters) { + // bypass extra logic if we have no parameters + if (sizeof($parameters) == 0) { + return $sql; + } + + $parameters = dbPrepareData($parameters); + // separate the two types of parameters for easier handling + $questionParams = array(); + $namedParams = array(); + foreach ($parameters as $key => $value) { + if (is_numeric($key)) { + $questionParams[] = $value; + } + else { + $namedParams[':'.$key] = $value; + } + } + + // sort namedParams in reverse to stop substring squashing + krsort($namedParams); + + // split on question-mark and named placeholders + $result = preg_split('/(\?|:[a-zA-Z0-9_-]+)/', $sql, -1, (PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)); + + // every-other item in $result will be the placeholder that was found + $query = ''; + $res_size = sizeof($result); + for ($i = 0; $i < $res_size; $i += 2) { + $query .= $result[$i]; + + $j = ($i + 1); + if (array_key_exists($j, $result)) { + $test = $result[$j]; + if ($test == '?') { + $query .= array_shift($questionParams); + } + else { + $query .= $namedParams[$test]; + } + } + } + + return $query; + +}//end dbMakeQuery() + + +function dbPrepareData($data) { + global $database_link; + $values = array(); + + foreach ($data as $key => $value) { + $escape = true; + // don't quote or esc if value is an array, we treat it + // as a "decorator" that tells us not to escape the + // value contained in the array + if (is_array($value) && !is_object($value)) { + $escape = false; + $value = array_shift($value); + } + + // it's not right to worry about invalid fields in this method because we may be operating on fields + // that are aliases, or part of other tables through joins + // if(!in_array($key, $columns)) // skip invalid fields + // continue; + if ($escape) { + $values[$key] = "'".mysqli_real_escape_string($database_link,$value)."'"; + } + else { + $values[$key] = $value; + } + } + + return $values; + +}//end dbPrepareData() + + +/* + * Given a data array, this returns an array of placeholders + * These may be question marks, or ":email" type + */ + + +function dbPlaceHolders($values) { + $data = array(); + foreach ($values as $key => $value) { + if (is_numeric($key)) { + $data[] = '?'; + } + else { + $data[] = ':'.$key; + } + } + + return $data; + +}//end dbPlaceHolders() + + +function dbBeginTransaction() { + global $database_link; + mysqli_query($database_link, 'begin'); + +}//end dbBeginTransaction() + + +function dbCommitTransaction() { + global $database_link; + mysqli_query($database_link, 'commit'); + +}//end dbCommitTransaction() + + +function dbRollbackTransaction() { + global $database_link; + mysqli_query($database_link, 'rollback'); + +}//end dbRollbackTransaction() + + +/* + class dbIterator implements Iterator { + private $result; + private $i; + + public function __construct($r) { + $this->result = $r; + $this->i = 0; + } + public function rewind() { + mysql_data_seek($this->result, 0); + $this->i = 0; + } + public function current() { + $a = mysql_fetch_assoc($this->result); + return $a; + } + public function key() { + return $this->i; + } + public function next() { + $this->i++; + $a = mysql_data_seek($this->result, $this->i); + if($a === false) { + $this->i = 0; + } + return $a; + } + public function valid() { + return ($this->current() !== false); + } + } + */ diff --git a/includes/dbFacile.php b/includes/dbFacile.php index 0d1d7150c..7e7989bca 100644 --- a/includes/dbFacile.php +++ b/includes/dbFacile.php @@ -1,554 +1,9 @@ convert("\nSQL[%y".$fullSql.'%n] '); - } - else { - $sql_debug[] = $fullSql; - } - } - - /* - if($this->logFile) - $time_start = microtime(true); - */ - - $result = mysql_query($fullSql); - // sets $this->result - /* - if($this->logFile) { - $time_end = microtime(true); - fwrite($this->logFile, date('Y-m-d H:i:s') . "\n" . $fullSql . "\n" . number_format($time_end - $time_start, 8) . " seconds\n\n"); - } - */ - - if ($result === false && (error_reporting() & 1)) { - // aye. this gets triggers on duplicate Contact insert - // trigger_error('QDB - Error in query: ' . $fullSql . ' : ' . mysql_error(), E_USER_WARNING); - } - - return $result; - -}//end dbQuery() - - -/* - * Passed an array and a table name, it attempts to insert the data into the table. - * Check for boolean false to determine whether insert failed - * */ - - -function dbInsert($data, $table) { - global $fullSql; - global $db_stats; - // the following block swaps the parameters if they were given in the wrong order. - // it allows the method to work for those that would rather it (or expect it to) - // follow closer with SQL convention: - // insert into the TABLE this DATA - if (is_string($data) && is_array($table)) { - $tmp = $data; - $data = $table; - $table = $tmp; - // trigger_error('QDB - Parameters passed to insert() were in reverse order, but it has been allowed', E_USER_NOTICE); - } - - $sql = 'INSERT INTO `'.$table.'` (`'.implode('`,`', array_keys($data)).'`) VALUES ('.implode(',', dbPlaceHolders($data)).')'; - - $time_start = microtime(true); - dbBeginTransaction(); - $result = dbQuery($sql, $data); - if ($result) { - $id = mysql_insert_id(); - dbCommitTransaction(); - // return $id; - } - else { - if ($table != 'Contact') { - trigger_error('QDB - Insert failed.', E_USER_WARNING); - } - - dbRollbackTransaction(); - // $id = false; - } - - // logfile($fullSql); - $time_end = microtime(true); - $db_stats['insert_sec'] += number_format(($time_end - $time_start), 8); - $db_stats['insert']++; - - return $id; - -}//end dbInsert() - - -/* - * Passed an array and a table name, it attempts to insert the data into the table. - * $data is an array (rows) of key value pairs. keys are fields. Rows need to have same fields. - * Check for boolean false to determine whether insert failed - * */ - - -function dbBulkInsert($data, $table) { - global $db_stats; - // the following block swaps the parameters if they were given in the wrong order. - // it allows the method to work for those that would rather it (or expect it to) - // follow closer with SQL convention: - // insert into the TABLE this DATA - if (is_string($data) && is_array($table)) { - $tmp = $data; - $data = $table; - $table = $tmp; - } - if (count($data) === 0) { - return false; - } - if (count($data[0]) === 0) { - return false; - } - - $sql = 'INSERT INTO `'.$table.'` (`'.implode('`,`', array_keys($data[0])).'`) VALUES '; - $values =''; - - foreach ($data as $row) { - if ($values != '') { - $values .= ','; - } - $rowvalues=''; - foreach ($row as $key => $value) { - if ($rowvalues != '') { - $rowvalues .= ','; - } - $rowvalues .= "'".mres($value)."'"; - } - $values .= "(".$rowvalues.")"; - } - - $time_start = microtime(true); - $result = dbQuery($sql.$values); - - // logfile($fullSql); - $time_end = microtime(true); - $db_stats['insert_sec'] += number_format(($time_end - $time_start), 8); - $db_stats['insert']++; - - return $result; - -}//end dbBulkInsert() - - -/* - * Passed an array, table name, WHERE clause, and placeholder parameters, it attempts to update a record. - * Returns the number of affected rows - * */ - - -function dbUpdate($data, $table, $where=null, $parameters=array()) { - global $fullSql; - global $db_stats; - // the following block swaps the parameters if they were given in the wrong order. - // it allows the method to work for those that would rather it (or expect it to) - // follow closer with SQL convention: - // update the TABLE with this DATA - if (is_string($data) && is_array($table)) { - $tmp = $data; - $data = $table; - $table = $tmp; - // trigger_error('QDB - The first two parameters passed to update() were in reverse order, but it has been allowed', E_USER_NOTICE); - } - - // need field name and placeholder value - // but how merge these field placeholders with actual $parameters array for the WHERE clause - $sql = 'UPDATE `'.$table.'` set '; - foreach ($data as $key => $value) { - $sql .= '`'.$key.'` '.'=:'.$key.','; - } - - $sql = substr($sql, 0, -1); - // strip off last comma - if ($where) { - $sql .= ' WHERE '.$where; - $data = array_merge($data, $parameters); - } - - $time_start = microtime(true); - if (dbQuery($sql, $data)) { - $return = mysql_affected_rows(); - } - else { - // echo("$fullSql"); - trigger_error('QDB - Update failed.', E_USER_WARNING); - $return = false; - } - - $time_end = microtime(true); - $db_stats['update_sec'] += number_format(($time_end - $time_start), 8); - $db_stats['update']++; - - return $return; - -}//end dbUpdate() - - -function dbDelete($table, $where=null, $parameters=array()) { - $sql = 'DELETE FROM `'.$table.'`'; - if ($where) { - $sql .= ' WHERE '.$where; - } - - if (dbQuery($sql, $parameters)) { - return mysql_affected_rows(); - } - else { - return false; - } - -}//end dbDelete() - - -/* - * Fetches all of the rows (associatively) from the last performed query. - * Most other retrieval functions build off this - * */ - - -function dbFetchRows($sql, $parameters=array()) { - global $db_stats; - - $time_start = microtime(true); - $result = dbQuery($sql, $parameters); - - if (mysql_num_rows($result) > 0) { - $rows = array(); - while ($row = mysql_fetch_assoc($result)) { - $rows[] = $row; - } - - mysql_free_result($result); - return $rows; - } - - mysql_free_result($result); - - $time_end = microtime(true); - $db_stats['fetchrows_sec'] += number_format(($time_end - $time_start), 8); - $db_stats['fetchrows']++; - - // no records, thus return empty array - // which should evaluate to false, and will prevent foreach notices/warnings - return array(); - -}//end dbFetchRows() - - -/* - * This is intended to be the method used for large result sets. - * It is intended to return an iterator, and act upon buffered data. - * */ - - -function dbFetch($sql, $parameters=array()) { - return dbFetchRows($sql, $parameters); - /* - // for now, don't do the iterator thing - $result = dbQuery($sql, $parameters); - if($result) { - // return new iterator - return new dbIterator($result); - } else { - return null; // ?? - } - */ - -}//end dbFetch() - - -/* - * Like fetch(), accepts any number of arguments - * The first argument is an sprintf-ready query stringTypes - * */ - - -function dbFetchRow($sql=null, $parameters=array()) { - global $db_stats; - - $time_start = microtime(true); - $result = dbQuery($sql, $parameters); - if ($result) { - $row = mysql_fetch_assoc($result); - mysql_free_result($result); - $time_end = microtime(true); - - $db_stats['fetchrow_sec'] += number_format(($time_end - $time_start), 8); - $db_stats['fetchrow']++; - - return $row; - } - else { - return null; - } - - $time_start = microtime(true); - -}//end dbFetchRow() - - -/* - * Fetches the first call from the first row returned by the query - * */ - - -function dbFetchCell($sql, $parameters=array()) { - global $db_stats; - $time_start = microtime(true); - $row = dbFetchRow($sql, $parameters); - if ($row) { - return array_shift($row); - // shift first field off first row - } - - $time_end = microtime(true); - - $db_stats['fetchcell_sec'] += number_format(($time_end - $time_start), 8); - $db_stats['fetchcell']++; - - return null; - -}//end dbFetchCell() - - -/* - * This method is quite different from fetchCell(), actually - * It fetches one cell from each row and places all the values in 1 array - * */ - - -function dbFetchColumn($sql, $parameters=array()) { - global $db_stats; - $time_start = microtime(true); - $cells = array(); - foreach (dbFetch($sql, $parameters) as $row) { - $cells[] = array_shift($row); - } - - $time_end = microtime(true); - - $db_stats['fetchcol_sec'] += number_format(($time_end - $time_start), 8); - $db_stats['fetchcol']++; - - return $cells; - -}//end dbFetchColumn() - - -/* - * Should be passed a query that fetches two fields - * The first will become the array key - * The second the key's value - */ - - -function dbFetchKeyValue($sql, $parameters=array()) { - $data = array(); - foreach (dbFetch($sql, $parameters) as $row) { - $key = array_shift($row); - if (sizeof($row) == 1) { - // if there were only 2 fields in the result - // use the second for the value - $data[$key] = array_shift($row); - } - else { - // if more than 2 fields were fetched - // use the array of the rest as the value - $data[$key] = $row; - } - } - - return $data; - -}//end dbFetchKeyValue() - - -/* - * This combines a query and parameter array into a final query string for execution - * PDO drivers don't need to use this - */ - - -function dbMakeQuery($sql, $parameters) { - // bypass extra logic if we have no parameters - if (sizeof($parameters) == 0) { - return $sql; - } - - $parameters = dbPrepareData($parameters); - // separate the two types of parameters for easier handling - $questionParams = array(); - $namedParams = array(); - foreach ($parameters as $key => $value) { - if (is_numeric($key)) { - $questionParams[] = $value; - } - else { - $namedParams[':'.$key] = $value; - } - } - - // sort namedParams in reverse to stop substring squashing - krsort($namedParams); - - // split on question-mark and named placeholders - $result = preg_split('/(\?|:[a-zA-Z0-9_-]+)/', $sql, -1, (PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE)); - - // every-other item in $result will be the placeholder that was found - $query = ''; - $res_size = sizeof($result); - for ($i = 0; $i < $res_size; $i += 2) { - $query .= $result[$i]; - - $j = ($i + 1); - if (array_key_exists($j, $result)) { - $test = $result[$j]; - if ($test == '?') { - $query .= array_shift($questionParams); - } - else { - $query .= $namedParams[$test]; - } - } - } - - return $query; - -}//end dbMakeQuery() - - -function dbPrepareData($data) { - $values = array(); - - foreach ($data as $key => $value) { - $escape = true; - // don't quote or esc if value is an array, we treat it - // as a "decorator" that tells us not to escape the - // value contained in the array - if (is_array($value) && !is_object($value)) { - $escape = false; - $value = array_shift($value); - } - - // it's not right to worry about invalid fields in this method because we may be operating on fields - // that are aliases, or part of other tables through joins - // if(!in_array($key, $columns)) // skip invalid fields - // continue; - if ($escape) { - $values[$key] = "'".mysql_real_escape_string($value)."'"; - } - else { - $values[$key] = $value; - } - } - - return $values; - -}//end dbPrepareData() - - -/* - * Given a data array, this returns an array of placeholders - * These may be question marks, or ":email" type - */ - - -function dbPlaceHolders($values) { - $data = array(); - foreach ($values as $key => $value) { - if (is_numeric($key)) { - $data[] = '?'; - } - else { - $data[] = ':'.$key; - } - } - - return $data; - -}//end dbPlaceHolders() - - -function dbBeginTransaction() { - mysql_query('begin'); - -}//end dbBeginTransaction() - - -function dbCommitTransaction() { - mysql_query('commit'); - -}//end dbCommitTransaction() - - -function dbRollbackTransaction() { - mysql_query('rollback'); - -}//end dbRollbackTransaction() - - -/* - class dbIterator implements Iterator { - private $result; - private $i; - - public function __construct($r) { - $this->result = $r; - $this->i = 0; - } - public function rewind() { - mysql_data_seek($this->result, 0); - $this->i = 0; - } - public function current() { - $a = mysql_fetch_assoc($this->result); - return $a; - } - public function key() { - return $this->i; - } - public function next() { - $this->i++; - $a = mysql_data_seek($this->result, $this->i); - if($a === false) { - $this->i = 0; - } - return $a; - } - public function valid() { - return ($this->current() !== false); - } - } - */ +if (file_exists($config['install_dir'].'/includes/dbFacile.'.$config['db']['extension'].'.php')) { + require_once $config['install_dir'].'/includes/dbFacile.'.$config['db']['extension'].'.php'; +} +else { + echo $config['db']['extension'] . " extension not found\n"; + exit; +} diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 577b8730d..7807ba179 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -43,6 +43,9 @@ $config['temp_dir'] = '/tmp'; $config['install_dir'] = '/opt/'.$config['project_id']; $config['log_dir'] = $config['install_dir'].'/logs'; +// MySQL extension to use +$config['db']['extension'] = 'mysql';//mysql and mysqli available + // What is my own hostname (used to identify this host in its own database) $config['own_hostname'] = 'localhost'; @@ -53,7 +56,6 @@ $config['fping_options']['retries'] = 3; $config['fping_options']['timeout'] = 500; $config['fping_options']['count'] = 3; $config['fping_options']['millisec'] = 20; -$config['fping6'] = '/usr/bin/fping6'; $config['snmpwalk'] = '/usr/bin/snmpwalk'; $config['snmpget'] = '/usr/bin/snmpget'; $config['snmpbulkwalk'] = '/usr/bin/snmpbulkwalk'; @@ -65,10 +67,7 @@ $config['nagios_plugins'] = '/usr/lib/nagios/plugins'; $config['ipmitool'] = '/usr/bin/ipmitool'; $config['virsh'] = '/usr/bin/virsh'; $config['dot'] = '/usr/bin/dot'; -$config['unflatten'] = '/usr/bin/unflatten'; -$config['neato'] = '/usr/bin/neato'; $config['sfdp'] = '/usr/bin/sfdp'; -$config['svn'] = '/usr/bin/svn'; // Memcached - Keep immediate statistics $config['memcached']['enable'] = false; @@ -102,7 +101,6 @@ if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT'])) { } } -$config['project_url'] = 'https://github.com/librenms/'; $config['project_home'] = 'http://www.librenms.org/'; $config['project_issues'] = 'https://github.com/librenms/librenms/issues'; $config['site_style'] = 'light'; @@ -110,7 +108,6 @@ $config['site_style'] = 'light'; $config['stylesheet'] = 'css/styles.css'; $config['mono_font'] = 'DejaVuSansMono'; $config['favicon'] = ''; -$config['header_color'] = '#1F334E'; $config['page_refresh'] = '300'; // Refresh the page every xx seconds, 0 to disable $config['front_page'] = 'pages/front/default.php'; @@ -383,14 +380,6 @@ $config['version_check'] = 0; // Poller/Discovery Modules $config['enable_bgp'] = 1; // Enable BGP session collection and display -$config['enable_rip'] = 1; -// Enable RIP session collection and display -$config['enable_ospf'] = 1; -// Enable OSPF session collection and display -$config['enable_isis'] = 1; -// Enable ISIS session collection and display -$config['enable_eigrp'] = 1; -// Enable EIGRP session collection and display $config['enable_syslog'] = 0; // Enable Syslog $config['enable_inventory'] = 1; @@ -406,8 +395,6 @@ $config['enable_sla'] = 0; // Ports extension modules $config['port_descr_parser'] = 'includes/port-descr-parser.inc.php'; // Parse port descriptions into fields -$config['enable_ports_Xbcmc'] = 1; -// Enable ifXEntry broadcast/multicast $config['enable_ports_etherlike'] = 0; // Enable Polling EtherLike-MIB (doubles interface processing time) $config['enable_ports_junoseatmvp'] = 0; @@ -491,8 +478,6 @@ $config['bad_if_regexp'][] = '/^sl[0-9]/'; // Rewrite Interfaces $config['rewrite_if_regexp']['/^cpu interface/'] = 'Mgmt'; -$config['processor_filter'][] = 'An electronic chip that makes the computer work.'; - $config['ignore_mount_removable'] = 1; // Ignore removable disk storage $config['ignore_mount_network'] = 1; @@ -592,7 +577,6 @@ $config['ignore_mount_removable'] = 1; $config['ignore_mount_network'] = 1; // Ignore network mounted storage // Syslog Settings -$config['syslog_age'] = '1 month'; // Entries older than this will be removed $config['syslog_filter'][] = 'last message repeated'; $config['syslog_filter'][] = 'Connection from UDP: ['; diff --git a/includes/definitions.inc.php b/includes/definitions.inc.php index 171db75a4..0fc20c740 100644 --- a/includes/definitions.inc.php +++ b/includes/definitions.inc.php @@ -5,14 +5,30 @@ require_once $config['install_dir'].'/includes/dbFacile.php'; require_once $config['install_dir'].'/includes/mergecnf.inc.php'; // Connect to database -$database_link = mysql_pconnect($config['db_host'], $config['db_user'], $config['db_pass']); +if ($config['db']['extension'] == 'mysqli') { + $database_link = mysqli_connect('p:'.$config['db_host'], $config['db_user'], $config['db_pass']); +} +else { + $database_link = mysql_pconnect($config['db_host'], $config['db_user'], $config['db_pass']); +} + if (!$database_link) { echo '

MySQL Error

'; - echo mysql_error(); + if ($config['db']['extension'] == 'mysqli') { + echo mysqli_error($database_link); + } + else { + echo mysql_error(); + } die; } -$database_db = mysql_select_db($config['db_name'], $database_link); +if ($config['db']['extension'] == 'mysqli') { + $database_db = mysqli_select_db($database_link, $config['db_name']); +} +else { + $database_db = mysql_select_db($config['db_name'], $database_link); +} $clone = $config; foreach (dbFetchRows('select config_name,config_value from config') as $obj) { diff --git a/includes/discovery/cisco-entity-sensor.inc.php b/includes/discovery/cisco-entity-sensor.inc.php index 881c6dd36..e7053a20d 100644 --- a/includes/discovery/cisco-entity-sensor.inc.php +++ b/includes/discovery/cisco-entity-sensor.inc.php @@ -163,8 +163,21 @@ if ($device['os_group'] == 'cisco') { } //end if if ($ok) { - // echo("\n".$valid['sensor'].", $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current"); discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity']); + #Cisco IOS-XR : add a fake sensor to graph as dbm + if ($type == "power" and $device['os'] == "iosxr" and preg_match ("/Transceiver (R|T)x/i", $descr) ) { + // convert Watts to dbm + $type = "dbm"; + $limit_low = 10 * log10($limit_low*1000); + $warn_limit_low = 10 * log10($warn_limit_low*1000); + $warn_limit = 10 * log10($warn_limit*1000); + $limit = 10 * log10($limit*1000); + $current = round(10 * log10($current*1000),3); + $multiplier = 1; + $divisor = 1; + //echo("\n".$valid['sensor'].", $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current"); + discover_sensor($valid['sensor'], $type, $device, $oid, $index, 'cisco-entity-sensor', $descr, $divisor, $multiplier, $limit_low, $warn_limit_low, $warn_limit, $limit, $current, 'snmp', $entPhysicalIndex, $entry['entSensorMeasuredEntity']); + } } $cisco_entity_temperature = 1; diff --git a/includes/discovery/discovery-arp.inc.php b/includes/discovery/discovery-arp.inc.php index 813fdd56b..fd5442b06 100644 --- a/includes/discovery/discovery-arp.inc.php +++ b/includes/discovery/discovery-arp.inc.php @@ -12,7 +12,6 @@ // Author: Paul Gear // License: GPLv3 // -require_once '../../includes/print-interface.inc.php'; echo 'ARP Discovery: '; diff --git a/includes/discovery/functions.inc.php b/includes/discovery/functions.inc.php index c5177ff22..512f39cff 100644 --- a/includes/discovery/functions.inc.php +++ b/includes/discovery/functions.inc.php @@ -545,9 +545,6 @@ function discover_storage(&$valid, $device, $index, $type, $mib, $descr, $size, ), 'storage' ); - if ($debug) { - mysql_error(); - } echo '+'; } diff --git a/includes/discovery/hr-device.inc.php b/includes/discovery/hr-device.inc.php index d7a261eb1..aa168da8c 100644 --- a/includes/discovery/hr-device.inc.php +++ b/includes/discovery/hr-device.inc.php @@ -56,11 +56,9 @@ $sql = "SELECT * FROM `hrDevice` WHERE `device_id` = '".$device['device_id']."' foreach (dbFetchRows($sql) as $test_hrDevice) { if (!$valid_hrDevice[$test_hrDevice['hrDeviceIndex']]) { echo '-'; - mysql_query("DELETE FROM `hrDevice` WHERE hrDevice_id = '".$test_hrDevice['hrDevice_id']."'"); dbDelete('hrDevice', '`hrDevice_id` = ?', array($test_hrDevice['hrDevice_id'])); if ($debug) { print_r($test_hrDevice); - echo mysql_affected_rows().' row deleted'; } } } diff --git a/includes/discovery/mempools/zywall.inc.php b/includes/discovery/mempools/zywall.inc.php new file mode 100644 index 000000000..94a506fd8 --- /dev/null +++ b/includes/discovery/mempools/zywall.inc.php @@ -0,0 +1,22 @@ + + * + * 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 ($device['os'] == 'zywall') { + echo 'Zywall mempool: '; + $oid = '.1.3.6.1.4.1.890.1.6.22.1.2.0'; + $usage = snmp_get($device,$oid, '-Ovq'); + if (is_numeric($usage)) { + discover_mempool($valid_mempool, $device, $oid, 'zywall', 'Memory', '1', null, null); + } +} diff --git a/includes/discovery/ports-stack.inc.php b/includes/discovery/ports-stack.inc.php index 81b927d3b..dfa03b111 100644 --- a/includes/discovery/ports-stack.inc.php +++ b/includes/discovery/ports-stack.inc.php @@ -20,9 +20,6 @@ foreach ($stack_poll_array as $port_id_high => $entry_high) { else { dbUpdate(array('ifStackStatus' => $ifStackStatus), 'ports_stack', 'device_id=? AND port_id_high=? AND `port_id_low`=?', array($device['device_id'], $port_id_high, $port_id_low)); echo 'U'; - if ($debug) { - echo mysql_error(); - } } unset($stack_db_array[$port_id_high][$port_id_low]); @@ -30,9 +27,6 @@ foreach ($stack_poll_array as $port_id_high => $entry_high) { else { dbInsert(array('device_id' => $device['device_id'], 'port_id_high' => $port_id_high, 'port_id_low' => $port_id_low, 'ifStackStatus' => $ifStackStatus), 'ports_stack'); echo '+'; - if ($debug) { - echo mysql_error(); - } } }//end foreach }//end foreach diff --git a/includes/discovery/processors/zywall.inc.php b/includes/discovery/processors/zywall.inc.php new file mode 100644 index 000000000..045e9f512 --- /dev/null +++ b/includes/discovery/processors/zywall.inc.php @@ -0,0 +1,23 @@ + + * + * 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 ($device['os'] == 'zywall') { + echo 'Zywall Processors: '; + $descr = 'Processor'; + $oid = '.1.3.6.1.4.1.890.1.6.22.1.1.0'; + $usage = snmp_get($device, $oid, '-OQUvs'); + if (is_numeric($usage)) { + discover_processor($valid['processor'], $device, $oid, '0', 'zywall', $descr, 1, $usage, null, null); + } +} diff --git a/includes/functions.php b/includes/functions.php index 13498595b..10499c086 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -583,7 +583,8 @@ function createHost($host, $community = NULL, $snmpver, $port = 161, $transport 'transport' => $transport, 'status' => '1', 'snmpver' => $snmpver, - 'poller_group' => $poller_group + 'poller_group' => $poller_group, + 'status_reason' => '', ); $device = array_merge($device, $v3); diff --git a/includes/polling/functions.inc.php b/includes/polling/functions.inc.php index 4eb12609b..d148fa021 100644 --- a/includes/polling/functions.inc.php +++ b/includes/polling/functions.inc.php @@ -44,6 +44,13 @@ function poll_sensor($device, $class, $unit) { else if ($class == 'state') { $sensor_value = trim(str_replace('"', '', snmp_walk($device, $sensor['sensor_oid'], '-Oevq', 'SNMPv2-MIB'))); } + else if ($class == 'dbm') { + $sensor_value = trim(str_replace('"', '', snmp_get($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB$mib"))); + //iosxr does not expose dbm values through SNMP so we convert Watts to dbm to have a nice graph to show + if ($device['os'] == "iosxr") { + $sensor_value = round(10*log10($sensor_value/1000),3); + } + } else { if ($sensor['sensor_type'] == 'apc') { $sensor_value = trim(str_replace('"', '', snmp_walk($device, $sensor['sensor_oid'], '-OUqnv', "SNMPv2-MIB:PowerNet-MIB$mib"))); diff --git a/includes/polling/os/windows.inc.php b/includes/polling/os/windows.inc.php index 9a9330e61..c31e1741e 100644 --- a/includes/polling/os/windows.inc.php +++ b/includes/polling/os/windows.inc.php @@ -120,7 +120,7 @@ else if ($poll_device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.2') { } if (strstr($poll_device['sysDescr'], 'Build 9600')) { - $version = 'Server 2012 R2 (NT 6.3)'; + $version = 'Server 2012 R2 Datacenter (NT 6.3)'; } } @@ -162,7 +162,7 @@ else if ($poll_device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.3') { } if (strstr($poll_device['sysDescr'], 'Build 9600')) { - $version = 'Server 2012 R2 Datacenter (NT 6.3)'; + $version = 'Server 2012 R2 (NT 6.3)'; } }//end if diff --git a/includes/polling/os/zywall.inc.php b/includes/polling/os/zywall.inc.php index 9b67f5f78..dbf822e6f 100644 --- a/includes/polling/os/zywall.inc.php +++ b/includes/polling/os/zywall.inc.php @@ -1,3 +1,6 @@ 0) { - $bill_data['bill_quota'] = $bill_data['bill_gb'] * $config['billing']['base'] * $config['billing']['base']; - dbUpdate(array('bill_quota' => $bill_data['bill_quota']), 'bills', '`bill_id` = ?', array($bill_data['bill_id'])); - echo("Quota -> ".$bill_data['bill_quota']); - } - - if($bill_data['bill_cdr'] > 0) { - $bill_data['bill_cdr'] = $bill_data['bill_cdr'] * 1000; - dbUpdate(array('bill_cdr' => $bill_data['bill_cdr']), 'bills', '`bill_id` = ?', array($bill_data['bill_id'])); - echo("CDR -> ".$bill_data['bill_cdr']); - } - echo("\n"); -} - -mysql_query("ALTER TABLE `bills` DROP `bill_gb`"); - -?> diff --git a/upgrade-scripts/fix-events.php b/upgrade-scripts/fix-events.php deleted file mode 100755 index 02d235b3e..000000000 --- a/upgrade-scripts/fix-events.php +++ /dev/null @@ -1,20 +0,0 @@ - 1) { - echo (round((($i / $count) * 100), 2)."% \r"); - } -} - - -function getDirectoryTree($outerDir, &$files=array()) -{ - $dirs = array_diff(scandir($outerDir), array( '.', '..' )); - foreach ($dirs as $d) { - if (is_dir($outerDir.'/'.$d)) { - getDirectoryTree($outerDir.'/'.$d, $files); - } - else { - if (preg_match('/^[\d]+.rrd$/', $d)) { - array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'.$d)); - } - } - } - - return $files; - -}//end getDirectoryTree() - - -function fixRdd($file) -{ - global $config; - global $rrdcached; - $fileC = shell_exec("{$config['rrdtool']} dump $file $rrdcached"); - - // --------------------------------------------------------------------------------------------------------- - $first = << - INDISCARDS - DERIVE - 600 - 0.0000000000e+00 - 1.2500000000e+10 - - UNKN - 0.0000000000e+00 - 0 - - - OUTDISCARDS - DERIVE - 600 - 0.0000000000e+00 - 1.2500000000e+10 - - UNKN - 0.0000000000e+00 - 0 - - - INUNKNOWNPROTOS - DERIVE - 600 - 0.0000000000e+00 - 1.2500000000e+10 - - UNKN - 0.0000000000e+00 - 0 - - - INBROADCASTPKTS - DERIVE - 600 - 0.0000000000e+00 - 1.2500000000e+10 - - UNKN - 0.0000000000e+00 - 0 - - - OUTBROADCASTPKTS - DERIVE - 600 - 0.0000000000e+00 - 1.2500000000e+10 - - UNKN - 0.0000000000e+00 - 0 - - - INMULTICASTPKTS - DERIVE - 600 - 0.0000000000e+00 - 1.2500000000e+10 - - UNKN - 0.0000000000e+00 - 0 - - - OUTMULTICASTPKTS - DERIVE - 600 - 0.0000000000e+00 - 1.2500000000e+10 - - UNKN - 0.0000000000e+00 - 0 - - - -FIRST; - - $second = << - 0.0000000000e+00 - NaN - NaN - 0 - - - 0.0000000000e+00 - NaN - NaN - 0 - - - 0.0000000000e+00 - NaN - NaN - 0 - - - 0.0000000000e+00 - NaN - NaN - 0 - - - 0.0000000000e+00 - NaN - NaN - 0 - - - 0.0000000000e+00 - NaN - NaN - 0 - - - 0.0000000000e+00 - NaN - NaN - 0 - - -SECOND; - - $third = << NaN NaN NaN NaN NaN NaN NaN -THIRD; - - // --------------------------------------------------------------------------------------------------------- - if (!preg_match('/DISCARDS/', $fileC)) { - $fileC = str_replace('', $first, $fileC); - $fileC = str_replace('', $second, $fileC); - $fileC = str_replace('', $third, $fileC); - $tmpfname = tempnam('/tmp', 'OBS'); - file_put_contents($tmpfname, $fileC); - @unlink($file); - $newfile = preg_replace('/(\d+)\.rrd/', 'port-\\1.rrd', $file); - @unlink($newfile); - shell_exec($config['rrdtool']." restore $tmpfname $newfile"); - unlink($tmpfname); - } - -}//end fixRdd() - - -echo "\n"; diff --git a/upgrade-scripts/fix-sensor-rrd.php b/upgrade-scripts/fix-sensor-rrd.php deleted file mode 100755 index e508dbf2d..000000000 --- a/upgrade-scripts/fix-sensor-rrd.php +++ /dev/null @@ -1,81 +0,0 @@ - 1) { - echo (round((($i / $count) * 100), 2)."% \r"); - } -} - - -function sensor_getDirectoryTree($outerDir, &$files=array()) -{ - - $dirs = array_diff(scandir($outerDir), array( '.', '..' )); - foreach ($dirs as $d) { - if (is_dir($outerDir.'/'.$d)) { - sensor_getDirectoryTree($outerDir.'/'.$d, $files); - } - else { - if ((preg_match('/^fan-.*.rrd$/', $d)) - || (preg_match('/^current-.*.rrd$/', $d)) - || (preg_match('/^freq-.*.rrd$/', $d)) - || (preg_match('/^humidity-.*.rrd$/', $d)) - || (preg_match('/^volt-.*.rrd$/', $d)) - || (preg_match('/^temp-.*.rrd$/', $d)) - ) { - array_push($files, preg_replace('/\/+/', '/', $outerDir.'/'.$d)); - } - } - } - - return $files; - -} - - -function sensor_fixRdd($file) -{ - global $config; - global $rrdcached; - $fileC = shell_exec("{$config['rrdtool']} dump $file $rrdcached"); - if (preg_match('/ fan/', $fileC)) { - shell_exec("{$config['rrdtool']} tune $file $rrdcached -r fan:sensor"); - rename($file, str_replace('/fan-', '/fanspeed-', $file)); - } - else if (preg_match('/ volt/', $fileC)) { - shell_exec("{$config['rrdtool']} tune $file $rrdcached -r volt:sensor"); - rename($file, str_replace('/volt-', '/voltage-', $file)); - } - else if (preg_match('/ current/', $fileC)) { - shell_exec("{$config['rrdtool']} tune $file $rrdcached -r current:sensor"); - } - else if (preg_match('/ freq/', $fileC)) { - shell_exec("{$config['rrdtool']} tune $file $rrdcached -r freq:sensor"); - rename($file, str_replace('/freq-', '/frequency-', $file)); - } - else if (preg_match('/ humidity/', $fileC)) { - shell_exec("{$config['rrdtool']} tune $file $rrdcached -r humidity:sensor"); - } - else if (preg_match('/ temp/', $fileC)) { - shell_exec("{$config['rrdtool']} tune $file $rrdcached -r temp:sensor"); - rename($file, str_replace('/temp-', '/temperature-', $file)); - } - -} - - -echo "\n";