From cc0f449fc9e9a5908f68fd5f96f1e7ca52053164 Mon Sep 17 00:00:00 2001 From: Michael Newton Date: Fri, 7 Aug 2015 11:10:43 -0700 Subject: [PATCH 01/26] changes needed to run under web server subdirectory --- html/css/styles.css | 2 +- html/includes/authenticate.inc.php | 2 +- html/includes/common/alerts.inc.php | 4 +-- html/includes/common/eventlog.inc.php | 2 +- html/includes/modal/alert_schedule.inc.php | 4 +-- html/includes/modal/alert_template.inc.php | 4 +-- .../modal/attach_alert_template.inc.php | 4 +-- html/includes/modal/delete_alert_map.inc.php | 2 +- html/includes/modal/delete_alert_rule.inc.php | 2 +- .../modal/delete_alert_template.inc.php | 2 +- .../modal/delete_device_group.inc.php | 2 +- html/includes/modal/new_alert_map.inc.php | 4 +-- html/includes/modal/new_alert_rule.inc.php | 4 +-- html/includes/modal/new_device_group.inc.php | 4 +-- html/includes/modal/poller_groups.inc.php | 6 ++-- .../modal/remove_alert_schedule.inc.php | 2 +- html/includes/print-alert-rules.php | 4 +-- html/includes/print-interface.inc.php | 2 +- html/includes/print-menubar.php | 6 ++-- html/includes/vars.inc.php | 2 ++ html/index.php | 2 +- html/install.php | 3 +- html/pages/about.inc.php | 4 +-- html/pages/alert-log.inc.php | 2 +- html/pages/alert-schedule.inc.php | 2 +- html/pages/api-access.inc.php | 6 ++-- html/pages/bill.inc.php | 2 +- html/pages/bills.inc.php | 2 +- html/pages/device/edit/device.inc.php | 2 +- html/pages/device/edit/health.inc.php | 8 +++--- html/pages/device/edit/modules.inc.php | 4 +-- html/pages/device/edit/ports.inc.php | 4 +-- html/pages/device/port.inc.php | 10 +++---- html/pages/device/processes.inc.php | 2 +- html/pages/devices.inc.php | 2 +- html/pages/front/tiles.php | 10 +++---- html/pages/health/mempool.inc.php | 2 +- html/pages/health/processor.inc.php | 2 +- html/pages/health/storage.inc.php | 2 +- html/pages/iftype.inc.php | 2 +- html/pages/inventory.inc.php | 2 +- html/pages/poll-log.inc.php | 2 +- html/pages/pollers.inc.php | 2 +- html/pages/ports.inc.php | 2 +- html/pages/preferences.inc.php | 8 +++--- html/pages/search/arp.inc.php | 2 +- html/pages/search/ipv4.inc.php | 2 +- html/pages/search/ipv6.inc.php | 2 +- html/pages/search/mac.inc.php | 2 +- html/pages/search/packages.inc.php | 2 +- html/pages/settings/alerting.inc.php | 28 +++++++++---------- html/pages/syslog.inc.php | 2 +- includes/common.php | 4 +-- 53 files changed, 99 insertions(+), 98 deletions(-) diff --git a/html/css/styles.css b/html/css/styles.css index 455bf51a1..8e5faa412 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -63,7 +63,7 @@ ul ul ul { list-style: square outside; } } .submit { - background-image: url('/images/submitbg.png'); + background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAATCAIAAAA4QDsKAAAABGdBTUEAALGPC/xhBQAAAEZJREFUeJyVjMEJACEQA2dlSxD7r2/xcdhAfNwJig/PfJIhISaJocQk/9ccwTDAEYAQ4K99sylfXm+gtbFl1p4WNUouUaMDPUI2q6SigUIAAAAASUVORK5CYII='); background-position: 0 100%; border-color: #B2B2B2 #525252 #525252 #B2B2B2; } diff --git a/html/includes/authenticate.inc.php b/html/includes/authenticate.inc.php index 316fcde5c..f1f5087d2 100644 --- a/html/includes/authenticate.inc.php +++ b/html/includes/authenticate.inc.php @@ -33,7 +33,7 @@ if ($vars['page'] == 'logout' && $_SESSION['authenticated']) { setcookie('auth', '', (time() - 60 * 60 * 24 * $config['auth_remember']), '/'); session_destroy(); $auth_message = 'Logged Out'; - header('Location: /'); + header('Location: ' . $config['base_url']); exit; } diff --git a/html/includes/common/alerts.inc.php b/html/includes/common/alerts.inc.php index 7f347f916..d4d033812 100644 --- a/html/includes/common/alerts.inc.php +++ b/html/includes/common/alerts.inc.php @@ -31,7 +31,7 @@ var grid = $("#alerts").bootgrid({ device_id: \'' . $device['device_id'] .'\' }; }, - url: "/ajax_table.php", + url: "ajax_table.php", formatters: { "status": function(column,row) { return "

" + row.msg + "

"; @@ -70,7 +70,7 @@ var grid = $("#alerts").bootgrid({ var state = $(this).data("state"); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "ack-alert", alert_id: alert_id, state: state }, success: function(msg){ $("#message").html(\'
\'+msg+\'
\'); diff --git a/html/includes/common/eventlog.inc.php b/html/includes/common/eventlog.inc.php index 91a1fd8b1..bbfb9de89 100644 --- a/html/includes/common/eventlog.inc.php +++ b/html/includes/common/eventlog.inc.php @@ -24,7 +24,7 @@ var grid = $("#eventlog").bootgrid({ type: "' .mres($vars['type']) .'", }; }, - url: "/ajax_table.php" + url: "ajax_table.php" }); diff --git a/html/includes/modal/alert_schedule.inc.php b/html/includes/modal/alert_schedule.inc.php index b726a219f..01474b7c9 100644 --- a/html/includes/modal/alert_schedule.inc.php +++ b/html/includes/modal/alert_schedule.inc.php @@ -102,7 +102,7 @@ $('#schedule-maintenance').on('show.bs.modal', function (event) { if (schedule_id > 0) { $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "schedule-maintenance", sub_type: "parse-maintenance", schedule_id: schedule_id }, dataType: "json", success: function(output) { @@ -124,7 +124,7 @@ $('#sched-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: $('form.schedule-maintenance-form').serialize(), dataType: "json", success: function(data){ diff --git a/html/includes/modal/alert_template.inc.php b/html/includes/modal/alert_template.inc.php index bd034952e..71574ba6f 100644 --- a/html/includes/modal/alert_template.inc.php +++ b/html/includes/modal/alert_template.inc.php @@ -107,7 +107,7 @@ $('#alert-template').on('show.bs.modal', function (event) { $('#template_id').val(template_id); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "parse-alert-template", template_id: template_id }, dataType: "json", success: function(output) { @@ -125,7 +125,7 @@ $('#create-template').click('', function(e) { var name = $("#name").val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "alert-templates", template: template , name: name, template_id: template_id}, dataType: "html", success: function(msg){ diff --git a/html/includes/modal/attach_alert_template.inc.php b/html/includes/modal/attach_alert_template.inc.php index 3e16014cc..409c6405c 100644 --- a/html/includes/modal/attach_alert_template.inc.php +++ b/html/includes/modal/attach_alert_template.inc.php @@ -60,7 +60,7 @@ $('#attach-alert-template').on('show.bs.modal', function(e) { $("#template_id").val(template_id); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "parse-template-rules", template_id: template_id }, dataType: "json", success: function(output) { @@ -88,7 +88,7 @@ $('#alert-template-attach').click('', function(event) { var rules = items.join(','); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: { type: "attach-alert-template", template_id: template_id, rule_id: rules }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_alert_map.inc.php b/html/includes/modal/delete_alert_map.inc.php index 930e1b7f8..ee0d0fd13 100644 --- a/html/includes/modal/delete_alert_map.inc.php +++ b/html/includes/modal/delete_alert_map.inc.php @@ -50,7 +50,7 @@ $('#alert-map-removal').click('', function(event) { var map_id = $("#map_id").val(); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: { type: "delete-alert-map", map_id: map_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_alert_rule.inc.php b/html/includes/modal/delete_alert_rule.inc.php index fdbe70077..fa5951b5b 100644 --- a/html/includes/modal/delete_alert_rule.inc.php +++ b/html/includes/modal/delete_alert_rule.inc.php @@ -50,7 +50,7 @@ $('#alert-rule-removal').click('', function(event) { var alert_id = $("#alert_id").val(); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: { type: "delete-alert-rule", alert_id: alert_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_alert_template.inc.php b/html/includes/modal/delete_alert_template.inc.php index 5161ea5be..41413a1b9 100644 --- a/html/includes/modal/delete_alert_template.inc.php +++ b/html/includes/modal/delete_alert_template.inc.php @@ -50,7 +50,7 @@ $('#alert-template-removal').click('', function(event) { var template_id = $("#template_id").val(); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: { type: "delete-alert-template", template_id: template_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_device_group.inc.php b/html/includes/modal/delete_device_group.inc.php index 42e504cd9..77c0e70e8 100644 --- a/html/includes/modal/delete_device_group.inc.php +++ b/html/includes/modal/delete_device_group.inc.php @@ -50,7 +50,7 @@ $('#device-group-removal').click('', function(event) { var group_id = $("#group_id").val(); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: { type: "delete-device-group", group_id: group_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/new_alert_map.inc.php b/html/includes/modal/new_alert_map.inc.php index b414d730d..c9ec494d4 100644 --- a/html/includes/modal/new_alert_map.inc.php +++ b/html/includes/modal/new_alert_map.inc.php @@ -57,7 +57,7 @@ $('#create-map').on('show.bs.modal', function (event) { $('#map_id').val(map_id); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "parse-alert-map", map_id: map_id }, dataType: "json", success: function(output) { @@ -166,7 +166,7 @@ $('#map-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: $('form.maps-form').serialize(), success: function(msg){ $("#message").html('
'+msg+'
'); diff --git a/html/includes/modal/new_alert_rule.inc.php b/html/includes/modal/new_alert_rule.inc.php index 5d4ff6076..7868a0b00 100644 --- a/html/includes/modal/new_alert_rule.inc.php +++ b/html/includes/modal/new_alert_rule.inc.php @@ -184,7 +184,7 @@ $('#create-alert').on('show.bs.modal', function (event) { } $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "parse-alert-rule", alert_id: alert_id }, dataType: "json", success: function(output) { @@ -347,7 +347,7 @@ $('#rule-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: $('form.alerts-form').serialize(), success: function(msg){ if(msg.indexOf("ERROR:") <= -1) { diff --git a/html/includes/modal/new_device_group.inc.php b/html/includes/modal/new_device_group.inc.php index d1dc5d6f4..79fee676d 100644 --- a/html/includes/modal/new_device_group.inc.php +++ b/html/includes/modal/new_device_group.inc.php @@ -119,7 +119,7 @@ $('#create-group').on('show.bs.modal', function (event) { }); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "parse-device-group", group_id: group_id }, dataType: "json", success: function(output) { @@ -192,7 +192,7 @@ $('#group-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: $('form.group-form').serialize(), success: function(msg){ if(msg.indexOf("ERROR:") <= -1) { diff --git a/html/includes/modal/poller_groups.inc.php b/html/includes/modal/poller_groups.inc.php index ccbfe2245..9482c9994 100644 --- a/html/includes/modal/poller_groups.inc.php +++ b/html/includes/modal/poller_groups.inc.php @@ -93,7 +93,7 @@ $('#group-removal').click('', function(e) { group_id = $("#group_id").val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: $('form.remove_group_form').serialize() , success: function(msg) { $("#thanks").html('
'+msg+'
'); @@ -115,7 +115,7 @@ $('#poller-groups').on('show.bs.modal', function (event) { $('#group_id').val(group_id); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "parse-poller-groups", group_id: group_id }, dataType: "json", success: function(output) { @@ -133,7 +133,7 @@ $('#create-group').click('', function(e) { var group_id = $('#group_id').val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "poller-groups", group_name: group_name, descr: descr, group_id: group_id }, dataType: "html", success: function(msg){ diff --git a/html/includes/modal/remove_alert_schedule.inc.php b/html/includes/modal/remove_alert_schedule.inc.php index 0e168ae77..f95464db9 100644 --- a/html/includes/modal/remove_alert_schedule.inc.php +++ b/html/includes/modal/remove_alert_schedule.inc.php @@ -52,7 +52,7 @@ $('#sched-maintenance-removal').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: $('form.schedule-maintenance-del').serialize(), dataType: "json", success: function(data){ diff --git a/html/includes/print-alert-rules.php b/html/includes/print-alert-rules.php index f6296b3eb..670a57815 100644 --- a/html/includes/print-alert-rules.php +++ b/html/includes/print-alert-rules.php @@ -268,7 +268,7 @@ $('#ack-alert').click('', function(e) { var alert_id = $(this).data("alert_id"); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: { type: "ack-alert", alert_id: alert_id }, success: function(msg){ $("#message").html('
'+msg+'
'); @@ -294,7 +294,7 @@ $('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event var orig_class = $(this).data("orig_class"); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: { type: "update-alert-rule", alert_id: alert_id, state: state }, dataType: "html", success: function(msg) { diff --git a/html/includes/print-interface.inc.php b/html/includes/print-interface.inc.php index 26f33fb50..bfb5d1bd7 100644 --- a/html/includes/print-interface.inc.php +++ b/html/includes/print-interface.inc.php @@ -30,7 +30,7 @@ else { } if (dbFetchCell('SELECT COUNT(*) FROM `mac_accounting` WHERE `port_id` = ?', array($port['port_id']))) { - $mac = " 'macaccounting'))."'>"; + $mac = " 'macaccounting'))."'>"; } else { $mac = ''; diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index 54b51213f..c436d5b7d 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -489,12 +489,12 @@ if ($_SESSION['userlevel'] >= '10') {
  • - + '.$tab['name'].'
  • '; diff --git a/html/pages/ports.inc.php b/html/pages/ports.inc.php index edeea9fbe..9a310ea27 100644 --- a/html/pages/ports.inc.php +++ b/html/pages/ports.inc.php @@ -55,7 +55,7 @@ foreach ($menu_options as $option => $text) { echo('
    '); ?> - Export CSV | + Export CSV | Update URL | Error: How did you even get here?!
    '; + echo '
    Error: How did you even get here?!
    '; } else { $twofactor = json_decode($twofactor['twofactor'], true); @@ -94,13 +94,13 @@ else { } else { session_destroy(); - echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; + echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; } }//end if } else { $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); - echo ''; + echo ''; echo '

    Two-Factor Authentication

    '; if (!empty($twofactor['twofactor'])) { $twofactor = json_decode($twofactor['twofactor'], true); @@ -154,7 +154,7 @@ else { echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; } else { - echo '
    Added TwoFactor credentials. Please reload page.
    '; + echo '
    Added TwoFactor credentials. Please reload page.
    '; } } else { diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index 45cd6888a..9f2ed062f 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -91,7 +91,7 @@ echo '"'.$_POST['address'].'"+'; address: '' }; }, - url: "/ajax_table.php" + url: "ajax_table.php" }); diff --git a/html/pages/search/ipv4.inc.php b/html/pages/search/ipv4.inc.php index 843acbd1b..3d4393ff8 100644 --- a/html/pages/search/ipv4.inc.php +++ b/html/pages/search/ipv4.inc.php @@ -86,7 +86,7 @@ if ($_POST['interface'] == 'Vlan%') { address: '' }; }, - url: "/ajax_table.php" + url: "ajax_table.php" }); diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php index 2b9115013..2ce8900b2 100644 --- a/html/pages/search/ipv6.inc.php +++ b/html/pages/search/ipv6.inc.php @@ -87,7 +87,7 @@ if ($_POST['interface'] == 'Vlan%') { address: '' }; }, - url: "/ajax_table.php" + url: "ajax_table.php" }); diff --git a/html/pages/search/mac.inc.php b/html/pages/search/mac.inc.php index f606e4436..a73e132b4 100644 --- a/html/pages/search/mac.inc.php +++ b/html/pages/search/mac.inc.php @@ -88,7 +88,7 @@ echo '"'.$_POST['address'].'"+'; address: '' }; }, - url: "/ajax_table.php" + url: "ajax_table.php" }); diff --git a/html/pages/search/packages.inc.php b/html/pages/search/packages.inc.php index e1ef1675d..0848fc372 100644 --- a/html/pages/search/packages.inc.php +++ b/html/pages/search/packages.inc.php @@ -158,7 +158,7 @@ foreach( $ordered as $name=>$entry ) { if( sizeof($arch) > 0 && sizeof($vers) > 0 ) { ?> - + ',$vers); ?> ',$arch); ?> ',$devs); ?> diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index 9282284ee..fbe28993a 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -823,7 +823,7 @@ echo '
    var config_value = $('#new_conf_value').val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: {type: "config-item", config_group: "alerting", config_sub_group: "transports", config_name: config_name, config_value: config_value}, dataType: "json", success: function(data){ @@ -859,7 +859,7 @@ echo '
    var config_extra = $('#slack_extra').val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: {type: "config-item", action: 'add-slack', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value}, dataType: "json", success: function(data){ @@ -897,7 +897,7 @@ echo '
    var config_from = $('#new_from').val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: {type: "config-item", action: 'add-hipchat', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value, config_room_id: config_room_id, config_from: config_from}, dataType: "json", success: function(data){ @@ -936,7 +936,7 @@ echo '
    var config_userkey = $('#new_userkey').val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: {type: "config-item", action: 'add-pushover', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value, config_userkey: config_userkey}, dataType: "json", success: function(data){ @@ -974,7 +974,7 @@ echo '
    var config_extra = $('#boxcar_extra').val(); $.ajax({ type: "POST", - url: "/ajax_form.php", + url: "ajax_form.php", data: {type: "config-item", action: 'add-boxcar', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value}, dataType: "json", success: function(data){ @@ -1008,7 +1008,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "config-item", action: 'remove', config_id: config_id}, dataType: "json", success: function (data) { @@ -1029,7 +1029,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "config-item", action: 'remove-slack', config_id: config_id}, dataType: "json", success: function (data) { @@ -1050,7 +1050,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "config-item", action: 'remove-hipchat', config_id: config_id}, dataType: "json", success: function (data) { @@ -1071,7 +1071,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "config-item", action: 'remove-pushover', config_id: config_id}, dataType: "json", success: function (data) { @@ -1092,7 +1092,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "config-item", action: 'remove-boxcar', config_id: config_id}, dataType: "json", success: function (data) { @@ -1114,7 +1114,7 @@ echo '
    var config_id = $(this).data("config_id"); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "update-config-item", config_id: config_id, config_value: state}, dataType: "json", success: function (data) { @@ -1135,7 +1135,7 @@ echo '
    var config_value = $this.val(); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "update-config-item", config_id: config_id, config_value: config_value}, dataType: "json", success: function (data) { @@ -1167,7 +1167,7 @@ echo '
    var config_value = $this.val(); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "update-config-item", config_id: config_id, config_value: config_value}, dataType: "json", success: function (data) { @@ -1200,7 +1200,7 @@ echo '
    var config_type = $this.data("type"); $.ajax({ type: 'POST', - url: '/ajax_form.php', + url: 'ajax_form.php', data: {type: "update-config-item", action: 'update-textarea', config_type: config_type, config_id: config_id, config_value: config_value}, dataType: "json", success: function (data) { diff --git a/html/pages/syslog.inc.php b/html/pages/syslog.inc.php index 0fa66c665..bd708c175 100644 --- a/html/pages/syslog.inc.php +++ b/html/pages/syslog.inc.php @@ -87,7 +87,7 @@ var grid = $("#syslog").bootgrid({ from: '', }; }, - url: "/ajax_table.php" + url: "ajax_table.php" }); $(function () { diff --git a/includes/common.php b/includes/common.php index d5ba05fb0..0749fe9bb 100644 --- a/includes/common.php +++ b/includes/common.php @@ -76,7 +76,7 @@ function print_error($text) { print $console_color->convert("%r".$text."%n\n", false); } else { - echo('
    '.$text.'
    '); + echo('
    '.$text.'
    '); } } @@ -85,7 +85,7 @@ function print_message($text) { print Console_Color2::convert("%g".$text."%n\n", false); } else { - echo('
    '.$text.'
    '); + echo('
    '.$text.'
    '); } } From 4b49c148b637b70c9ca329754a338185b3f5dc59 Mon Sep 17 00:00:00 2001 From: laf Date: Sat, 8 Aug 2015 19:27:18 +0000 Subject: [PATCH 02/26] Added mysqli support --- build-base.php | 12 +- html/includes/common/syslog.inc.php | 1 - html/pages/front/default.php | 4 - html/pages/front/globe.php | 3 - includes/common.php | 8 +- includes/dbFacile.mysql.php | 554 ++++++++++++++++++++++++ includes/dbFacile.mysqli.php | 559 +++++++++++++++++++++++++ includes/dbFacile.php | 559 +------------------------ includes/defaults.inc.php | 3 + includes/definitions.inc.php | 22 +- includes/discovery/functions.inc.php | 3 - includes/discovery/hr-device.inc.php | 2 - includes/discovery/ports-stack.inc.php | 6 - includes/sql-schema/update.php | 14 +- 14 files changed, 1167 insertions(+), 583 deletions(-) create mode 100644 includes/dbFacile.mysql.php create mode 100644 includes/dbFacile.mysqli.php 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/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/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/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 11d8d9475..a6f94795a 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'; 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/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/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/sql-schema/update.php b/includes/sql-schema/update.php index aa5e307bf..66816b49f 100644 --- a/includes/sql-schema/update.php +++ b/includes/sql-schema/update.php @@ -108,11 +108,21 @@ foreach ($filelist as $file) { } if ($line[0] != '#') { - $update = mysql_query($line); + if ($config['db']['extension'] == 'mysqli') { + + } + else { + $update = mysql_query($database_link, $line); + } if (!$update) { $err++; if ($debug) { - echo mysql_error()."\n"; + if ($config['db']['extension'] == 'mysqli') { + echo mysqli_error($database_link)."\n"; + } + else { + echo mysql_error()."\n"; + } } } } From 880cccf57b71b60eb6195627565194d2b9d456d5 Mon Sep 17 00:00:00 2001 From: laf Date: Sun, 9 Aug 2015 14:36:31 +0000 Subject: [PATCH 03/26] Added some docs, update config.php.default and web installer to use mysqli by default --- config.php.default | 1 + doc/Support/Configuration.md | 16 ++++++++++++++++ html/install.php | 1 + 3 files changed, 18 insertions(+) diff --git a/config.php.default b/config.php.default index 479482113..7bc2c7873 100755 --- a/config.php.default +++ b/config.php.default @@ -7,6 +7,7 @@ $config['db_host'] = "localhost"; $config['db_user'] = "USERNAME"; $config['db_pass'] = "PASSWORD"; $config['db_name'] = "librenms"; +$config['db']['extension'] = 'mysqli';// mysql or mysqli ### Memcached config - We use this to store realtime usage $config['memcached']['enable'] = FALSE; diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index e2288aef2..5ac1a25c2 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 diff --git a/html/install.php b/html/install.php index d3611b560..aedab8030 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; From 261cd020f397a44069bcafad017322ae0dbd2d21 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 10 Aug 2015 15:13:27 +0000 Subject: [PATCH 04/26] Moved forms folder to includes and added some safety checks for non-admin users --- html/ajax_form.php | 4 ++-- html/{ => includes}/forms/ack-alert.inc.php | 0 html/{ => includes}/forms/alert-templates.inc.php | 0 html/{ => includes}/forms/attach-alert-template.inc.php | 0 html/{ => includes}/forms/callback-clear.inc.php | 4 ++++ html/{ => includes}/forms/callback-statistics.inc.php | 4 ++++ html/{ => includes}/forms/config-item-disable.inc.php | 5 +++++ html/{ => includes}/forms/config-item-update.inc.php | 5 +++++ html/{ => includes}/forms/config-item.inc.php | 0 html/{ => includes}/forms/create-alert-item.inc.php | 0 html/{ => includes}/forms/create-device-group.inc.php | 0 html/{ => includes}/forms/create-map-item.inc.php | 0 html/{ => includes}/forms/delete-alert-map.inc.php | 0 html/{ => includes}/forms/delete-alert-rule.inc.php | 0 html/{ => includes}/forms/delete-alert-template.inc.php | 0 html/{ => includes}/forms/delete-device-group.inc.php | 0 .../{ => includes}/forms/discovery-module-update.inc.php | 5 +++++ html/{ => includes}/forms/health-update.inc.php | 5 +++++ html/{ => includes}/forms/parse-alert-map.inc.php | 0 html/{ => includes}/forms/parse-alert-rule.inc.php | 0 html/{ => includes}/forms/parse-alert-template.inc.php | 0 html/{ => includes}/forms/parse-device-group.inc.php | 0 html/{ => includes}/forms/parse-poller-groups.inc.php | 0 html/{ => includes}/forms/parse-template-rules.inc.php | 0 html/{ => includes}/forms/poller-group-remove.inc.php | 4 ++++ html/{ => includes}/forms/poller-groups.inc.php | 0 html/{ => includes}/forms/poller-module-update.inc.php | 4 ++++ html/{ => includes}/forms/rediscover-device.inc.php | 9 +++++++++ html/{ => includes}/forms/schedule-maintenance.inc.php | 0 html/{ => includes}/forms/sensor-alert-reset.inc.php | 5 +++++ html/{ => includes}/forms/sensor-alert-update.inc.php | 5 +++++ html/{ => includes}/forms/storage-update.inc.php | 9 +++++++++ html/{ => includes}/forms/token-item-create.inc.php | 4 ++++ html/{ => includes}/forms/token-item-disable.inc.php | 4 ++++ html/{ => includes}/forms/token-item-remove.inc.php | 4 ++++ html/{ => includes}/forms/update-alert-rule.inc.php | 0 html/{ => includes}/forms/update-config-item.inc.php | 0 .../{ => includes}/forms/update-dashboard-config.inc.php | 0 html/{ => includes}/forms/update-ports.inc.php | 9 +++++++++ 39 files changed, 87 insertions(+), 2 deletions(-) rename html/{ => includes}/forms/ack-alert.inc.php (100%) rename html/{ => includes}/forms/alert-templates.inc.php (100%) rename html/{ => includes}/forms/attach-alert-template.inc.php (100%) rename html/{ => includes}/forms/callback-clear.inc.php (88%) rename html/{ => includes}/forms/callback-statistics.inc.php (91%) rename html/{ => includes}/forms/config-item-disable.inc.php (93%) rename html/{ => includes}/forms/config-item-update.inc.php (92%) rename html/{ => includes}/forms/config-item.inc.php (100%) rename html/{ => includes}/forms/create-alert-item.inc.php (100%) rename html/{ => includes}/forms/create-device-group.inc.php (100%) rename html/{ => includes}/forms/create-map-item.inc.php (100%) rename html/{ => includes}/forms/delete-alert-map.inc.php (100%) rename html/{ => includes}/forms/delete-alert-rule.inc.php (100%) rename html/{ => includes}/forms/delete-alert-template.inc.php (100%) rename html/{ => includes}/forms/delete-device-group.inc.php (100%) rename html/{ => includes}/forms/discovery-module-update.inc.php (90%) rename html/{ => includes}/forms/health-update.inc.php (93%) rename html/{ => includes}/forms/parse-alert-map.inc.php (100%) rename html/{ => includes}/forms/parse-alert-rule.inc.php (100%) rename html/{ => includes}/forms/parse-alert-template.inc.php (100%) rename html/{ => includes}/forms/parse-device-group.inc.php (100%) rename html/{ => includes}/forms/parse-poller-groups.inc.php (100%) rename html/{ => includes}/forms/parse-template-rules.inc.php (100%) rename html/{ => includes}/forms/poller-group-remove.inc.php (92%) rename html/{ => includes}/forms/poller-groups.inc.php (100%) rename html/{ => includes}/forms/poller-module-update.inc.php (90%) rename html/{ => includes}/forms/rediscover-device.inc.php (86%) rename html/{ => includes}/forms/schedule-maintenance.inc.php (100%) rename html/{ => includes}/forms/sensor-alert-reset.inc.php (91%) rename html/{ => includes}/forms/sensor-alert-update.inc.php (94%) rename html/{ => includes}/forms/storage-update.inc.php (88%) rename html/{ => includes}/forms/token-item-create.inc.php (94%) rename html/{ => includes}/forms/token-item-disable.inc.php (93%) rename html/{ => includes}/forms/token-item-remove.inc.php (92%) rename html/{ => includes}/forms/update-alert-rule.inc.php (100%) rename html/{ => includes}/forms/update-config-item.inc.php (100%) rename html/{ => includes}/forms/update-dashboard-config.inc.php (100%) rename html/{ => includes}/forms/update-ports.inc.php (92%) 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/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'; From 8cf23acdba404a22a05f555498692cf9aff6193e Mon Sep 17 00:00:00 2001 From: Michael Newton Date: Mon, 10 Aug 2015 09:55:19 -0700 Subject: [PATCH 05/26] updating authors --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index a532b9606..3adcbd3ca 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -45,6 +45,7 @@ Contributors to LibreNMS: - Aaron Daniels (adaniels21487) - David M. Syzdek (syzdek) - Gerben Meijer (infernix) +- Michael Newton (miken32) [1]: http://observium.org/ "Observium web site" From aa57c952f9500eb1c7db2ed9e45fbc56960e72be Mon Sep 17 00:00:00 2001 From: Michael Newton Date: Mon, 10 Aug 2015 10:43:11 -0700 Subject: [PATCH 06/26] adding documentation --- doc/Extensions/Sub-Directory.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 doc/Extensions/Sub-Directory.md diff --git a/doc/Extensions/Sub-Directory.md b/doc/Extensions/Sub-Directory.md new file mode 100644 index 000000000..d79c07a45 --- /dev/null +++ b/doc/Extensions/Sub-Directory.md @@ -0,0 +1,22 @@ +To run LibreNMS under a subdirectory on your Apache server, the directives for the LibreNMS directory are placed in the base server configuration, or in a virtual host +container of your choosing. If using a virtual host, place the directives in the file where the virtual host is configured. If using the base server on RHEL distributions +(CentOS, Scientific Linux, etc.) the directives can be placed in `/etc/httpd/conf.d/librenms.conf`. For Debian distributions (Ubuntu, etc.) place the directives in +`/etc/apache2/sites-available/default`. + +```apache +#This directive is never put inside a virtual host +AllowEncodedSlashes On + +#These directives can be inside a virtual host or in the base server configuration +Alias /librenms /opt/librenms/html + + + AllowOverride All + Options FollowSymLinks MultiViews + +``` + +The `RewriteBase` directive in `html/.htaccess` must be rewritten to reference the subdirectory name. Assuming LibreNMS is running at http://example.com/librenms/, +you will need to change `RewriteBase /` to `RewriteBase /librenms`. + +Finally, ensure `$config["base_url"]` -- if configured -- is correct as well. From 6ea5b88025833b9b0eab639052b966e7461b8e1e Mon Sep 17 00:00:00 2001 From: Michael Newton Date: Mon, 10 Aug 2015 10:44:00 -0700 Subject: [PATCH 07/26] I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md. --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 3adcbd3ca..1fa25c6eb 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -47,5 +47,6 @@ Contributors to LibreNMS: - Gerben Meijer (infernix) - Michael Newton (miken32) + [1]: http://observium.org/ "Observium web site" From e02912ec02a6a2f78c41eda1455ca3b29166a9f3 Mon Sep 17 00:00:00 2001 From: laf Date: Mon, 10 Aug 2015 23:45:41 +0000 Subject: [PATCH 08/26] Removed unused files --- upgrade-scripts/fix-billing-2758.inc.php | 87 ---------- upgrade-scripts/fix-events.php | 20 --- upgrade-scripts/fix-port-rrd.php | 202 ----------------------- upgrade-scripts/fix-sensor-rrd.php | 81 --------- 4 files changed, 390 deletions(-) delete mode 100644 upgrade-scripts/fix-billing-2758.inc.php delete mode 100755 upgrade-scripts/fix-events.php delete mode 100755 upgrade-scripts/fix-port-rrd.php delete mode 100755 upgrade-scripts/fix-sensor-rrd.php diff --git a/upgrade-scripts/fix-billing-2758.inc.php b/upgrade-scripts/fix-billing-2758.inc.php deleted file mode 100644 index 89716c694..000000000 --- a/upgrade-scripts/fix-billing-2758.inc.php +++ /dev/null @@ -1,87 +0,0 @@ - 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"; From 53c15fc7dfb7f9ac76df6916eb0aa5ee1b9a1bc9 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 11 Aug 2015 10:38:25 +0000 Subject: [PATCH 09/26] Updated customers page to use bootgrid --- html/includes/table/customers.inc.php | 105 +++++++++++++++++++++++++ html/pages/customers.inc.php | 107 +++++++------------------- 2 files changed, 132 insertions(+), 80 deletions(-) create mode 100644 html/includes/table/customers.inc.php 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/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++; + From 9925e3522440b76599584d4ce4ef33ea86c2aeb3 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 11 Aug 2015 11:38:05 +0000 Subject: [PATCH 10/26] Couple more mysql strict fixes --- includes/alerts.inc.php | 4 ++-- includes/functions.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) 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/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); From c652cb652e9db5be3bad4978b9cd67369dce0c01 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 11 Aug 2015 12:32:54 +0000 Subject: [PATCH 11/26] Added serial,version, cpu and mem for zywall --- includes/discovery/mempools/zywall.inc.php | 22 +++++++++++++++++++ includes/discovery/processors/zywall.inc.php | 23 ++++++++++++++++++++ includes/polling/os/zywall.inc.php | 3 +++ 3 files changed, 48 insertions(+) create mode 100644 includes/discovery/mempools/zywall.inc.php create mode 100644 includes/discovery/processors/zywall.inc.php diff --git a/includes/discovery/mempools/zywall.inc.php b/includes/discovery/mempools/zywall.inc.php new file mode 100644 index 000000000..ad220d853 --- /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, 10, 'zywall', 'Memory', '1', null, null); + } +} 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/polling/os/zywall.inc.php b/includes/polling/os/zywall.inc.php index 9b67f5f78..ad834f634 100644 --- a/includes/polling/os/zywall.inc.php +++ b/includes/polling/os/zywall.inc.php @@ -1,3 +1,6 @@ Date: Tue, 11 Aug 2015 16:35:29 +0200 Subject: [PATCH 12/26] IOS-XR does not provide dbm values for transceivers so we calculate them from mWatts entries Fix #1641 --- includes/discovery/cisco-entity-sensor.inc.php | 15 ++++++++++++++- includes/polling/functions.inc.php | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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/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"))); From efee54043ab8227ca39601cb82b876c3fdc685c8 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 11 Aug 2015 16:05:04 +0000 Subject: [PATCH 13/26] Swapped 2012 Datacenter / Non-DC around --- includes/polling/os/windows.inc.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 5b7e09b72996a3ff90a236ec486cbd5a9dcb37e7 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 11 Aug 2015 16:29:59 +0000 Subject: [PATCH 14/26] Updated alerting docs to cross out config.php options to push people towards Webui --- doc/Extensions/Alerting.md | 40 +++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/doc/Extensions/Alerting.md b/doc/Extensions/Alerting.md index 8b0f25675..aec8ee6e5 100644 --- a/doc/Extensions/Alerting.md +++ b/doc/Extensions/Alerting.md @@ -36,6 +36,8 @@ Table of Content: LibreNMS includes a highly customizable alerting system. The system requires a set of user-defined rules to evaluate the situation of each device, port, service or any other entity. +> 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 From f260fccacf1ec6880808cefb18679a51080a137f Mon Sep 17 00:00:00 2001 From: Mickael Marchand Date: Tue, 11 Aug 2015 19:34:34 +0200 Subject: [PATCH 15/26] I agree to the conditions of the Contributor Agreement contained in doc/General/Contributing.md --- AUTHORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From b1fcc3c84bfb537ab54719364e7e76ea2503a5d6 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 11 Aug 2015 20:11:04 +0000 Subject: [PATCH 16/26] updated firmware to version --- includes/polling/os/zywall.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/polling/os/zywall.inc.php b/includes/polling/os/zywall.inc.php index ad834f634..dbf822e6f 100644 --- a/includes/polling/os/zywall.inc.php +++ b/includes/polling/os/zywall.inc.php @@ -2,5 +2,5 @@ $hardware = $poll_device['sysDescr']; -$firmware = snmp_get($device, '.1.3.6.1.4.1.890.1.15.3.1.6.0', '-Osqv'); +$version = snmp_get($device, '.1.3.6.1.4.1.890.1.15.3.1.6.0', '-Osqv'); $serial = snmp_get($device, '1.3.6.1.4.1.890.1.15.3.1.12.0', '-Osqv'); From 936fb32a9ed48e6fc03642ee370c64affe339eb2 Mon Sep 17 00:00:00 2001 From: laf Date: Tue, 11 Aug 2015 20:20:02 +0000 Subject: [PATCH 17/26] Used oid instead of static --- includes/discovery/mempools/zywall.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/discovery/mempools/zywall.inc.php b/includes/discovery/mempools/zywall.inc.php index ad220d853..94a506fd8 100644 --- a/includes/discovery/mempools/zywall.inc.php +++ b/includes/discovery/mempools/zywall.inc.php @@ -17,6 +17,6 @@ if ($device['os'] == 'zywall') { $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, 10, 'zywall', 'Memory', '1', null, null); + discover_mempool($valid_mempool, $device, $oid, 'zywall', 'Memory', '1', null, null); } } From 945ca7f2eafdc4fb35fcf2a5bc5e16546761a356 Mon Sep 17 00:00:00 2001 From: Neil Lathwood Date: Tue, 11 Aug 2015 21:25:23 +0100 Subject: [PATCH 18/26] Revert "changes needed to run under web server subdirectory" --- AUTHORS.md | 2 -- doc/Extensions/Sub-Directory.md | 22 --------------- html/css/styles.css | 2 +- html/includes/authenticate.inc.php | 2 +- html/includes/common/alerts.inc.php | 4 +-- html/includes/common/eventlog.inc.php | 2 +- html/includes/modal/alert_schedule.inc.php | 4 +-- html/includes/modal/alert_template.inc.php | 4 +-- .../modal/attach_alert_template.inc.php | 4 +-- html/includes/modal/delete_alert_map.inc.php | 2 +- html/includes/modal/delete_alert_rule.inc.php | 2 +- .../modal/delete_alert_template.inc.php | 2 +- .../modal/delete_device_group.inc.php | 2 +- html/includes/modal/new_alert_map.inc.php | 4 +-- html/includes/modal/new_alert_rule.inc.php | 4 +-- html/includes/modal/new_device_group.inc.php | 4 +-- html/includes/modal/poller_groups.inc.php | 6 ++-- .../modal/remove_alert_schedule.inc.php | 2 +- html/includes/print-alert-rules.php | 4 +-- html/includes/print-interface.inc.php | 2 +- html/includes/print-menubar.php | 6 ++-- html/includes/vars.inc.php | 2 -- html/index.php | 2 +- html/install.php | 3 +- html/pages/about.inc.php | 4 +-- html/pages/alert-log.inc.php | 2 +- html/pages/alert-schedule.inc.php | 2 +- html/pages/api-access.inc.php | 6 ++-- html/pages/bill.inc.php | 2 +- html/pages/bills.inc.php | 2 +- html/pages/device/edit/device.inc.php | 2 +- html/pages/device/edit/health.inc.php | 8 +++--- html/pages/device/edit/modules.inc.php | 4 +-- html/pages/device/edit/ports.inc.php | 4 +-- html/pages/device/port.inc.php | 10 +++---- html/pages/device/processes.inc.php | 2 +- html/pages/devices.inc.php | 2 +- html/pages/front/tiles.php | 10 +++---- html/pages/health/mempool.inc.php | 2 +- html/pages/health/processor.inc.php | 2 +- html/pages/health/storage.inc.php | 2 +- html/pages/iftype.inc.php | 2 +- html/pages/inventory.inc.php | 2 +- html/pages/poll-log.inc.php | 2 +- html/pages/pollers.inc.php | 2 +- html/pages/ports.inc.php | 2 +- html/pages/preferences.inc.php | 8 +++--- html/pages/search/arp.inc.php | 2 +- html/pages/search/ipv4.inc.php | 2 +- html/pages/search/ipv6.inc.php | 2 +- html/pages/search/mac.inc.php | 2 +- html/pages/search/packages.inc.php | 2 +- html/pages/settings/alerting.inc.php | 28 +++++++++---------- html/pages/syslog.inc.php | 2 +- includes/common.php | 4 +-- 55 files changed, 98 insertions(+), 123 deletions(-) delete mode 100644 doc/Extensions/Sub-Directory.md diff --git a/AUTHORS.md b/AUTHORS.md index ac6443655..99b1fb4ab 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -45,8 +45,6 @@ Contributors to LibreNMS: - Aaron Daniels (adaniels21487) - David M. Syzdek (syzdek) - Gerben Meijer (infernix) -- Michael Newton (miken32) - [1]: http://observium.org/ "Observium web site" diff --git a/doc/Extensions/Sub-Directory.md b/doc/Extensions/Sub-Directory.md deleted file mode 100644 index d79c07a45..000000000 --- a/doc/Extensions/Sub-Directory.md +++ /dev/null @@ -1,22 +0,0 @@ -To run LibreNMS under a subdirectory on your Apache server, the directives for the LibreNMS directory are placed in the base server configuration, or in a virtual host -container of your choosing. If using a virtual host, place the directives in the file where the virtual host is configured. If using the base server on RHEL distributions -(CentOS, Scientific Linux, etc.) the directives can be placed in `/etc/httpd/conf.d/librenms.conf`. For Debian distributions (Ubuntu, etc.) place the directives in -`/etc/apache2/sites-available/default`. - -```apache -#This directive is never put inside a virtual host -AllowEncodedSlashes On - -#These directives can be inside a virtual host or in the base server configuration -Alias /librenms /opt/librenms/html - - - AllowOverride All - Options FollowSymLinks MultiViews - -``` - -The `RewriteBase` directive in `html/.htaccess` must be rewritten to reference the subdirectory name. Assuming LibreNMS is running at http://example.com/librenms/, -you will need to change `RewriteBase /` to `RewriteBase /librenms`. - -Finally, ensure `$config["base_url"]` -- if configured -- is correct as well. diff --git a/html/css/styles.css b/html/css/styles.css index d68b1fa1f..80d53766e 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -63,7 +63,7 @@ ul ul ul { list-style: square outside; } } .submit { - background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAATCAIAAAA4QDsKAAAABGdBTUEAALGPC/xhBQAAAEZJREFUeJyVjMEJACEQA2dlSxD7r2/xcdhAfNwJig/PfJIhISaJocQk/9ccwTDAEYAQ4K99sylfXm+gtbFl1p4WNUouUaMDPUI2q6SigUIAAAAASUVORK5CYII='); + background-image: url('/images/submitbg.png'); background-position: 0 100%; border-color: #B2B2B2 #525252 #525252 #B2B2B2; } diff --git a/html/includes/authenticate.inc.php b/html/includes/authenticate.inc.php index f1f5087d2..316fcde5c 100644 --- a/html/includes/authenticate.inc.php +++ b/html/includes/authenticate.inc.php @@ -33,7 +33,7 @@ if ($vars['page'] == 'logout' && $_SESSION['authenticated']) { setcookie('auth', '', (time() - 60 * 60 * 24 * $config['auth_remember']), '/'); session_destroy(); $auth_message = 'Logged Out'; - header('Location: ' . $config['base_url']); + header('Location: /'); exit; } diff --git a/html/includes/common/alerts.inc.php b/html/includes/common/alerts.inc.php index b135ee48f..0dabec69d 100644 --- a/html/includes/common/alerts.inc.php +++ b/html/includes/common/alerts.inc.php @@ -31,7 +31,7 @@ var alerts_grid = $("#alerts").bootgrid({ device_id: \'' . $device['device_id'] .'\' }; }, - url: "ajax_table.php", + url: "/ajax_table.php", formatters: { "status": function(column,row) { return "

    " + row.msg + "

    "; @@ -70,7 +70,7 @@ var alerts_grid = $("#alerts").bootgrid({ var state = $(this).data("state"); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "ack-alert", alert_id: alert_id, state: state }, success: function(msg){ $("#message").html(\'
    \'+msg+\'
    \'); diff --git a/html/includes/common/eventlog.inc.php b/html/includes/common/eventlog.inc.php index 7ce1590c0..8640559e8 100644 --- a/html/includes/common/eventlog.inc.php +++ b/html/includes/common/eventlog.inc.php @@ -24,7 +24,7 @@ var eventlog_grid = $("#eventlog").bootgrid({ type: "' .mres($vars['type']) .'", }; }, - url: "ajax_table.php" + url: "/ajax_table.php" }); diff --git a/html/includes/modal/alert_schedule.inc.php b/html/includes/modal/alert_schedule.inc.php index 01474b7c9..b726a219f 100644 --- a/html/includes/modal/alert_schedule.inc.php +++ b/html/includes/modal/alert_schedule.inc.php @@ -102,7 +102,7 @@ $('#schedule-maintenance').on('show.bs.modal', function (event) { if (schedule_id > 0) { $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "schedule-maintenance", sub_type: "parse-maintenance", schedule_id: schedule_id }, dataType: "json", success: function(output) { @@ -124,7 +124,7 @@ $('#sched-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: $('form.schedule-maintenance-form').serialize(), dataType: "json", success: function(data){ diff --git a/html/includes/modal/alert_template.inc.php b/html/includes/modal/alert_template.inc.php index 71574ba6f..bd034952e 100644 --- a/html/includes/modal/alert_template.inc.php +++ b/html/includes/modal/alert_template.inc.php @@ -107,7 +107,7 @@ $('#alert-template').on('show.bs.modal', function (event) { $('#template_id').val(template_id); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "parse-alert-template", template_id: template_id }, dataType: "json", success: function(output) { @@ -125,7 +125,7 @@ $('#create-template').click('', function(e) { var name = $("#name").val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "alert-templates", template: template , name: name, template_id: template_id}, dataType: "html", success: function(msg){ diff --git a/html/includes/modal/attach_alert_template.inc.php b/html/includes/modal/attach_alert_template.inc.php index 409c6405c..3e16014cc 100644 --- a/html/includes/modal/attach_alert_template.inc.php +++ b/html/includes/modal/attach_alert_template.inc.php @@ -60,7 +60,7 @@ $('#attach-alert-template').on('show.bs.modal', function(e) { $("#template_id").val(template_id); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "parse-template-rules", template_id: template_id }, dataType: "json", success: function(output) { @@ -88,7 +88,7 @@ $('#alert-template-attach').click('', function(event) { var rules = items.join(','); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: { type: "attach-alert-template", template_id: template_id, rule_id: rules }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_alert_map.inc.php b/html/includes/modal/delete_alert_map.inc.php index ee0d0fd13..930e1b7f8 100644 --- a/html/includes/modal/delete_alert_map.inc.php +++ b/html/includes/modal/delete_alert_map.inc.php @@ -50,7 +50,7 @@ $('#alert-map-removal').click('', function(event) { var map_id = $("#map_id").val(); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: { type: "delete-alert-map", map_id: map_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_alert_rule.inc.php b/html/includes/modal/delete_alert_rule.inc.php index fa5951b5b..fdbe70077 100644 --- a/html/includes/modal/delete_alert_rule.inc.php +++ b/html/includes/modal/delete_alert_rule.inc.php @@ -50,7 +50,7 @@ $('#alert-rule-removal').click('', function(event) { var alert_id = $("#alert_id").val(); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: { type: "delete-alert-rule", alert_id: alert_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_alert_template.inc.php b/html/includes/modal/delete_alert_template.inc.php index 41413a1b9..5161ea5be 100644 --- a/html/includes/modal/delete_alert_template.inc.php +++ b/html/includes/modal/delete_alert_template.inc.php @@ -50,7 +50,7 @@ $('#alert-template-removal').click('', function(event) { var template_id = $("#template_id").val(); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: { type: "delete-alert-template", template_id: template_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/delete_device_group.inc.php b/html/includes/modal/delete_device_group.inc.php index 77c0e70e8..42e504cd9 100644 --- a/html/includes/modal/delete_device_group.inc.php +++ b/html/includes/modal/delete_device_group.inc.php @@ -50,7 +50,7 @@ $('#device-group-removal').click('', function(event) { var group_id = $("#group_id").val(); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: { type: "delete-device-group", group_id: group_id }, dataType: "html", success: function(msg) { diff --git a/html/includes/modal/new_alert_map.inc.php b/html/includes/modal/new_alert_map.inc.php index c9ec494d4..b414d730d 100644 --- a/html/includes/modal/new_alert_map.inc.php +++ b/html/includes/modal/new_alert_map.inc.php @@ -57,7 +57,7 @@ $('#create-map').on('show.bs.modal', function (event) { $('#map_id').val(map_id); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "parse-alert-map", map_id: map_id }, dataType: "json", success: function(output) { @@ -166,7 +166,7 @@ $('#map-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: $('form.maps-form').serialize(), success: function(msg){ $("#message").html('
    '+msg+'
    '); diff --git a/html/includes/modal/new_alert_rule.inc.php b/html/includes/modal/new_alert_rule.inc.php index 7868a0b00..5d4ff6076 100644 --- a/html/includes/modal/new_alert_rule.inc.php +++ b/html/includes/modal/new_alert_rule.inc.php @@ -184,7 +184,7 @@ $('#create-alert').on('show.bs.modal', function (event) { } $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "parse-alert-rule", alert_id: alert_id }, dataType: "json", success: function(output) { @@ -347,7 +347,7 @@ $('#rule-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: $('form.alerts-form').serialize(), success: function(msg){ if(msg.indexOf("ERROR:") <= -1) { diff --git a/html/includes/modal/new_device_group.inc.php b/html/includes/modal/new_device_group.inc.php index 79fee676d..d1dc5d6f4 100644 --- a/html/includes/modal/new_device_group.inc.php +++ b/html/includes/modal/new_device_group.inc.php @@ -119,7 +119,7 @@ $('#create-group').on('show.bs.modal', function (event) { }); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "parse-device-group", group_id: group_id }, dataType: "json", success: function(output) { @@ -192,7 +192,7 @@ $('#group-submit').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: $('form.group-form').serialize(), success: function(msg){ if(msg.indexOf("ERROR:") <= -1) { diff --git a/html/includes/modal/poller_groups.inc.php b/html/includes/modal/poller_groups.inc.php index 9482c9994..ccbfe2245 100644 --- a/html/includes/modal/poller_groups.inc.php +++ b/html/includes/modal/poller_groups.inc.php @@ -93,7 +93,7 @@ $('#group-removal').click('', function(e) { group_id = $("#group_id").val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: $('form.remove_group_form').serialize() , success: function(msg) { $("#thanks").html('
    '+msg+'
    '); @@ -115,7 +115,7 @@ $('#poller-groups').on('show.bs.modal', function (event) { $('#group_id').val(group_id); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "parse-poller-groups", group_id: group_id }, dataType: "json", success: function(output) { @@ -133,7 +133,7 @@ $('#create-group').click('', function(e) { var group_id = $('#group_id').val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "poller-groups", group_name: group_name, descr: descr, group_id: group_id }, dataType: "html", success: function(msg){ diff --git a/html/includes/modal/remove_alert_schedule.inc.php b/html/includes/modal/remove_alert_schedule.inc.php index f95464db9..0e168ae77 100644 --- a/html/includes/modal/remove_alert_schedule.inc.php +++ b/html/includes/modal/remove_alert_schedule.inc.php @@ -52,7 +52,7 @@ $('#sched-maintenance-removal').click('', function(e) { e.preventDefault(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: $('form.schedule-maintenance-del').serialize(), dataType: "json", success: function(data){ diff --git a/html/includes/print-alert-rules.php b/html/includes/print-alert-rules.php index 670a57815..f6296b3eb 100644 --- a/html/includes/print-alert-rules.php +++ b/html/includes/print-alert-rules.php @@ -268,7 +268,7 @@ $('#ack-alert').click('', function(e) { var alert_id = $(this).data("alert_id"); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: { type: "ack-alert", alert_id: alert_id }, success: function(msg){ $("#message").html('
    '+msg+'
    '); @@ -294,7 +294,7 @@ $('input[name="alert-rule"]').on('switchChange.bootstrapSwitch', function(event var orig_class = $(this).data("orig_class"); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: { type: "update-alert-rule", alert_id: alert_id, state: state }, dataType: "html", success: function(msg) { diff --git a/html/includes/print-interface.inc.php b/html/includes/print-interface.inc.php index bfb5d1bd7..26f33fb50 100644 --- a/html/includes/print-interface.inc.php +++ b/html/includes/print-interface.inc.php @@ -30,7 +30,7 @@ else { } if (dbFetchCell('SELECT COUNT(*) FROM `mac_accounting` WHERE `port_id` = ?', array($port['port_id']))) { - $mac = "
    'macaccounting'))."'>"; + $mac = " 'macaccounting'))."'>"; } else { $mac = ''; diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index c436d5b7d..54b51213f 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -489,12 +489,12 @@ if ($_SESSION['userlevel'] >= '10') {
  • - + '.$tab['name'].'
  • '; diff --git a/html/pages/ports.inc.php b/html/pages/ports.inc.php index 9a310ea27..edeea9fbe 100644 --- a/html/pages/ports.inc.php +++ b/html/pages/ports.inc.php @@ -55,7 +55,7 @@ foreach ($menu_options as $option => $text) { echo('
    '); ?> - Export CSV | + Export CSV | Update URL | Error: How did you even get here?!
    '; + echo '
    Error: How did you even get here?!
    '; } else { $twofactor = json_decode($twofactor['twofactor'], true); @@ -94,13 +94,13 @@ else { } else { session_destroy(); - echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; + echo '
    Error: Supplied TwoFactor Token is wrong, you\'ve been logged out.
    '; } }//end if } else { $twofactor = dbFetchRow('SELECT twofactor FROM users WHERE username = ?', array($_SESSION['username'])); - echo ''; + echo ''; echo '

    Two-Factor Authentication

    '; if (!empty($twofactor['twofactor'])) { $twofactor = json_decode($twofactor['twofactor'], true); @@ -154,7 +154,7 @@ else { echo '
    Error inserting TwoFactor details. Please try again later and contact Administrator if error persists.
    '; } else { - echo '
    Added TwoFactor credentials. Please reload page.
    '; + echo '
    Added TwoFactor credentials. Please reload page.
    '; } } else { diff --git a/html/pages/search/arp.inc.php b/html/pages/search/arp.inc.php index 9f2ed062f..45cd6888a 100644 --- a/html/pages/search/arp.inc.php +++ b/html/pages/search/arp.inc.php @@ -91,7 +91,7 @@ echo '"'.$_POST['address'].'"+'; address: '' }; }, - url: "ajax_table.php" + url: "/ajax_table.php" }); diff --git a/html/pages/search/ipv4.inc.php b/html/pages/search/ipv4.inc.php index 3d4393ff8..843acbd1b 100644 --- a/html/pages/search/ipv4.inc.php +++ b/html/pages/search/ipv4.inc.php @@ -86,7 +86,7 @@ if ($_POST['interface'] == 'Vlan%') { address: '' }; }, - url: "ajax_table.php" + url: "/ajax_table.php" }); diff --git a/html/pages/search/ipv6.inc.php b/html/pages/search/ipv6.inc.php index 2ce8900b2..2b9115013 100644 --- a/html/pages/search/ipv6.inc.php +++ b/html/pages/search/ipv6.inc.php @@ -87,7 +87,7 @@ if ($_POST['interface'] == 'Vlan%') { address: '' }; }, - url: "ajax_table.php" + url: "/ajax_table.php" }); diff --git a/html/pages/search/mac.inc.php b/html/pages/search/mac.inc.php index a73e132b4..f606e4436 100644 --- a/html/pages/search/mac.inc.php +++ b/html/pages/search/mac.inc.php @@ -88,7 +88,7 @@ echo '"'.$_POST['address'].'"+'; address: '' }; }, - url: "ajax_table.php" + url: "/ajax_table.php" }); diff --git a/html/pages/search/packages.inc.php b/html/pages/search/packages.inc.php index 0848fc372..e1ef1675d 100644 --- a/html/pages/search/packages.inc.php +++ b/html/pages/search/packages.inc.php @@ -158,7 +158,7 @@ foreach( $ordered as $name=>$entry ) { if( sizeof($arch) > 0 && sizeof($vers) > 0 ) { ?> - + ',$vers); ?> ',$arch); ?> ',$devs); ?> diff --git a/html/pages/settings/alerting.inc.php b/html/pages/settings/alerting.inc.php index fbe28993a..9282284ee 100644 --- a/html/pages/settings/alerting.inc.php +++ b/html/pages/settings/alerting.inc.php @@ -823,7 +823,7 @@ echo '
    var config_value = $('#new_conf_value').val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: {type: "config-item", config_group: "alerting", config_sub_group: "transports", config_name: config_name, config_value: config_value}, dataType: "json", success: function(data){ @@ -859,7 +859,7 @@ echo '
    var config_extra = $('#slack_extra').val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: {type: "config-item", action: 'add-slack', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value}, dataType: "json", success: function(data){ @@ -897,7 +897,7 @@ echo '
    var config_from = $('#new_from').val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: {type: "config-item", action: 'add-hipchat', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value, config_room_id: config_room_id, config_from: config_from}, dataType: "json", success: function(data){ @@ -936,7 +936,7 @@ echo '
    var config_userkey = $('#new_userkey').val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: {type: "config-item", action: 'add-pushover', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value, config_userkey: config_userkey}, dataType: "json", success: function(data){ @@ -974,7 +974,7 @@ echo '
    var config_extra = $('#boxcar_extra').val(); $.ajax({ type: "POST", - url: "ajax_form.php", + url: "/ajax_form.php", data: {type: "config-item", action: 'add-boxcar', config_group: "alerting", config_sub_group: "transports", config_extra: config_extra, config_value: config_value}, dataType: "json", success: function(data){ @@ -1008,7 +1008,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "config-item", action: 'remove', config_id: config_id}, dataType: "json", success: function (data) { @@ -1029,7 +1029,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "config-item", action: 'remove-slack', config_id: config_id}, dataType: "json", success: function (data) { @@ -1050,7 +1050,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "config-item", action: 'remove-hipchat', config_id: config_id}, dataType: "json", success: function (data) { @@ -1071,7 +1071,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "config-item", action: 'remove-pushover', config_id: config_id}, dataType: "json", success: function (data) { @@ -1092,7 +1092,7 @@ echo '
    var config_id = $(this).data('config_id'); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "config-item", action: 'remove-boxcar', config_id: config_id}, dataType: "json", success: function (data) { @@ -1114,7 +1114,7 @@ echo '
    var config_id = $(this).data("config_id"); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "update-config-item", config_id: config_id, config_value: state}, dataType: "json", success: function (data) { @@ -1135,7 +1135,7 @@ echo '
    var config_value = $this.val(); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "update-config-item", config_id: config_id, config_value: config_value}, dataType: "json", success: function (data) { @@ -1167,7 +1167,7 @@ echo '
    var config_value = $this.val(); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "update-config-item", config_id: config_id, config_value: config_value}, dataType: "json", success: function (data) { @@ -1200,7 +1200,7 @@ echo '
    var config_type = $this.data("type"); $.ajax({ type: 'POST', - url: 'ajax_form.php', + url: '/ajax_form.php', data: {type: "update-config-item", action: 'update-textarea', config_type: config_type, config_id: config_id, config_value: config_value}, dataType: "json", success: function (data) { diff --git a/html/pages/syslog.inc.php b/html/pages/syslog.inc.php index bd708c175..0fa66c665 100644 --- a/html/pages/syslog.inc.php +++ b/html/pages/syslog.inc.php @@ -87,7 +87,7 @@ var grid = $("#syslog").bootgrid({ from: '', }; }, - url: "ajax_table.php" + url: "/ajax_table.php" }); $(function () { diff --git a/includes/common.php b/includes/common.php index 0749fe9bb..d5ba05fb0 100644 --- a/includes/common.php +++ b/includes/common.php @@ -76,7 +76,7 @@ function print_error($text) { print $console_color->convert("%r".$text."%n\n", false); } else { - echo('
    '.$text.'
    '); + echo('
    '.$text.'
    '); } } @@ -85,7 +85,7 @@ function print_message($text) { print Console_Color2::convert("%g".$text."%n\n", false); } else { - echo('
    '.$text.'
    '); + echo('
    '.$text.'
    '); } } From 5b58baccc04a39d9f4c600a805eb8525f6b1db1c Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Wed, 12 Aug 2015 17:10:15 +0200 Subject: [PATCH 19/26] Removed a line which was commented out. --- html/network-map.php | 1 - 1 file changed, 1 deletion(-) 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']; } From af80d4539b8c343ebd59c7e40e45636977e26f6a Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Wed, 12 Aug 2015 17:10:32 +0200 Subject: [PATCH 20/26] Removed unused default variables. --- includes/defaults.inc.php | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/includes/defaults.inc.php b/includes/defaults.inc.php index 577b8730d..e11046fce 100644 --- a/includes/defaults.inc.php +++ b/includes/defaults.inc.php @@ -53,7 +53,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 +64,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 +98,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 +105,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 +377,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 +392,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 +475,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 +574,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: ['; From c2c8aa82761cd0151614b42d6323b2cb9a918e49 Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Wed, 12 Aug 2015 17:11:08 +0200 Subject: [PATCH 21/26] Removed documentation for configuration options which are not implemented --- doc/Support/Configuration.md | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/Support/Configuration.md b/doc/Support/Configuration.md index f70b9f3e7..c9c58a28a 100644 --- a/doc/Support/Configuration.md +++ b/doc/Support/Configuration.md @@ -260,10 +260,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 From 8bb231453495e256f9563285028fd0b8ab351d5f Mon Sep 17 00:00:00 2001 From: laf Date: Wed, 12 Aug 2015 15:48:04 +0000 Subject: [PATCH 22/26] Erm, no idea what that is doing in there! --- includes/discovery/discovery-arp.inc.php | 1 - 1 file changed, 1 deletion(-) 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: '; From d988693564c4e15a5e6c9449fa68d7ff8508f259 Mon Sep 17 00:00:00 2001 From: Dan Langille Date: Wed, 12 Aug 2015 15:13:58 -0400 Subject: [PATCH 23/26] Correct path to defaults.inc.php --- config.php.default | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config.php.default b/config.php.default index 479482113..b3ab1ee29 100755 --- a/config.php.default +++ b/config.php.default @@ -1,6 +1,6 @@ Date: Wed, 12 Aug 2015 19:55:37 +0000 Subject: [PATCH 24/26] Last fix --- includes/sql-schema/update.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/sql-schema/update.php b/includes/sql-schema/update.php index 66816b49f..6497d1ca5 100644 --- a/includes/sql-schema/update.php +++ b/includes/sql-schema/update.php @@ -109,10 +109,10 @@ foreach ($filelist as $file) { if ($line[0] != '#') { if ($config['db']['extension'] == 'mysqli') { - + $update = mysqli_query($database_link, $line); } else { - $update = mysql_query($database_link, $line); + $update = mysql_query($line); } if (!$update) { $err++; From a4fcfe2c3455cb5bae53d437ccb4edff831f07bb Mon Sep 17 00:00:00 2001 From: "Tuxis Internet Engineering V.O.F." Date: Thu, 13 Aug 2015 11:36:08 +0200 Subject: [PATCH 25/26] Update Billing-Module.md This doesn't need to run as root... --- doc/Extensions/Billing-Module.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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. From 3ae60e8b40db31e5742c635a9f3013a1df1d23a1 Mon Sep 17 00:00:00 2001 From: Mike Rostermund Date: Thu, 13 Aug 2015 12:28:06 +0200 Subject: [PATCH 26/26] Fix spelling error in comment --- config_to_json.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config_to_json.php b/config_to_json.php index 45e3394bc..5d5b0a4d7 100644 --- a/config_to_json.php +++ b/config_to_json.php @@ -22,7 +22,7 @@ function iscli() { } -// check if we are running throw the CLI, otherwise abort +// check if we are running through the CLI, otherwise abort if (iscli()) { include_once $defaults_file; include_once $config_file;