diff --git a/AUTHORS.md b/AUTHORS.md index 8263114812..230f379a47 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -71,4 +71,5 @@ Contributors to LibreNMS: - Tony Murray (murrant) - Peter Lamperud (vizay) - Louis Bailleul (alucardfh) +- Rick Hodger (Tatermen) [1]: http://observium.org/ "Observium web site" diff --git a/Makefile b/Makefile index 92d8dddf1e..1b168dd169 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ typeahead: $(GIT_SUBTREE) --prefix=lib/typeahead https://github.com/twitter/typeahead.js.git master gridster: - $(GIT_SUBTREE) --prefix=lib/gridster https://github.com/ducksboard/gridster.js.git master + $(GIT_SUBTREE) --prefix=lib/gridster https://github.com/dsmorse/gridster.js.git master jquery-mapael: $(GIT_SUBTREE) --prefix=lib/jQuery-Mapael https://github.com/neveldo/jQuery-Mapael.git master diff --git a/daily.php b/daily.php index 8569f1c9aa..546335a8bd 100644 --- a/daily.php +++ b/daily.php @@ -13,10 +13,8 @@ require 'includes/functions.php'; $options = getopt('f:'); if ($options['f'] === 'update') { - $pool_size = dbFetchCell('SELECT @@innodb_buffer_pool_size'); - // The following query is from the excellent mysqltuner.pl by Major Hayden https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl - $pool_used = dbFetchCell('SELECT SUM(DATA_LENGTH+INDEX_LENGTH) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ("information_schema", "performance_schema", "mysql") AND ENGINE = "InnoDB" GROUP BY ENGINE ORDER BY ENGINE ASC'); - if ($pool_used > $pool_size) { + $innodb_buffer = innodb_buffer_check(); + if ($innodb_buffer['used'] > $innodb_buffer['size']) { if (!empty($config['alert']['default_mail'])) { $subject = $config['project_name'] . ' auto-update action required'; $message = ' @@ -26,19 +24,14 @@ We have just tried to update your installation but it looks like the InnoDB buff Because of this we have stopped the auto-update running to ensure your system is ok. -You currently have a configured innodb_buffer_pool_size of ' . $pool_size / 1024 / 1024 . ' MiB but is currently using ' . $pool_used / 1024 / 1024 . ' MiB +You currently have a configured innodb_buffer_pool_size of ' . $innodb_buffer['size'] / 1024 / 1024 . ' MiB but is currently using ' . $innodb_buffer['used'] / 1024 / 1024 . ' MiB Take a look at https://dev.mysql.com/doc/refman/5.6/en/innodb-buffer-pool.html for further details. The ' . $config['project_name'] . ' team.'; send_mail($config['alert']['default_mail'],$subject,$message,$html=false); - } else { - echo 'InnoDB Buffersize too small.'.PHP_EOL; - echo 'Current size: '.($pool_size / 1024 / 1024).' MiB'.PHP_EOL; - echo 'Minimum Required: '.($pool_used / 1024 / 1024).' MiB'.PHP_EOL; - echo 'To ensure integrity, we\'re not going to pull any updates until the buffersize has been adjusted.'.PHP_EOL; - echo 'Config proposal: "innodb_buffer_pool_size = '.pow(2,ceil(log(($pool_used / 1024 / 1024),2))).'M"'.PHP_EOL; - } + } + echo warn_innodb_buffer($innodb_buffer); exit(2); } else { @@ -103,3 +96,7 @@ if ($options['f'] === 'device_perf') { } } } + +if ($options['f'] === 'notifications') { + include_once 'notifications.php'; +} diff --git a/daily.sh b/daily.sh index ddc4f2e9f5..effb4a5023 100755 --- a/daily.sh +++ b/daily.sh @@ -16,3 +16,4 @@ php daily.php -f authlog php daily.php -f perf_times php daily.php -f callback php daily.php -f device_perf +php daily.php -f notifications diff --git a/html/css/styles.css b/html/css/styles.css index 46abbc37ff..150e1eace8 100644 --- a/html/css/styles.css +++ b/html/css/styles.css @@ -1764,4 +1764,7 @@ tr.search:nth-child(odd) { label { font-weight: normal; -} \ No newline at end of file +} +.nav>li>a.dropdown-toggle { + padding: 15px 6px; +} diff --git a/html/includes/authentication/active_directory.inc.php b/html/includes/authentication/active_directory.inc.php index a1dd80f86a..633ac0c040 100644 --- a/html/includes/authentication/active_directory.inc.php +++ b/html/includes/authentication/active_directory.inc.php @@ -86,7 +86,16 @@ function auth_usermanagement() { function adduser($username) { // Check to see if user is already added in the database if (!user_exists_in_db($username)) { - return dbInsert(array('username' => $username, 'user_id' => get_userid($username), 'level' => "0", 'can_modify_passwd' => 0, 'twofactor' => 0), 'users'); + $userid = dbInsert(array('username' => $username, 'user_id' => get_userid($username), 'level' => "0", 'can_modify_passwd' => 0, 'twofactor' => 0), 'users'); + if ($userid == false) { + return false; + } + else { + foreach (dbFetchRows('select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc',array($userid)) as $notif) { + dbInsert(array('notifications_id'=>$notif['notifications_id'],'user_id'=>$userid,'key'=>'read','value'=>1),'notifications_attribs'); + } + } + return $userid; } else { return false; diff --git a/html/includes/authentication/http-auth.inc.php b/html/includes/authentication/http-auth.inc.php index 221de3adca..6914801812 100644 --- a/html/includes/authentication/http-auth.inc.php +++ b/html/includes/authentication/http-auth.inc.php @@ -44,11 +44,20 @@ function auth_usermanagement() { } -function adduser($username, $password, $level, $email='', $realname='', $can_modify_passwd='1') { +function adduser($username, $password, $level, $email='', $realname='', $can_modify_passwd=1, $description='', $twofactor=0) { if (!user_exists($username)) { $hasher = new PasswordHash(8, false); $encrypted = $hasher->HashPassword($password); - return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname), 'users'); + $userid = dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); + if ($userid == false) { + return false; + } + else { + foreach (dbFetchRows('select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc',array($userid)) as $notif) { + dbInsert(array('notifications_id'=>$notif['notifications_id'],'user_id'=>$userid,'key'=>'read','value'=>1),'notifications_attribs'); + } + } + return $userid; } else { return false; diff --git a/html/includes/authentication/mysql.inc.php b/html/includes/authentication/mysql.inc.php index c16e716f83..0248d66b30 100644 --- a/html/includes/authentication/mysql.inc.php +++ b/html/includes/authentication/mysql.inc.php @@ -104,7 +104,16 @@ function adduser($username, $password, $level, $email='', $realname='', $can_mod if (!user_exists($username)) { $hasher = new PasswordHash(8, false); $encrypted = $hasher->HashPassword($password); - return dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); + $userid = dbInsert(array('username' => $username, 'password' => $encrypted, 'level' => $level, 'email' => $email, 'realname' => $realname, 'can_modify_passwd' => $can_modify_passwd, 'descr' => $description, 'twofactor' => $twofactor), 'users'); + if ($userid == false) { + return false; + } + else { + foreach (dbFetchRows('select notifications.* from notifications where not exists( select 1 from notifications_attribs where notifications.notifications_id = notifications_attribs.notifications_id and notifications_attribs.user_id = ?) order by notifications.notifications_id desc',array($userid)) as $notif) { + dbInsert(array('notifications_id'=>$notif['notifications_id'],'user_id'=>$userid,'key'=>'read','value'=>1),'notifications_attribs'); + } + } + return $userid; } else { return false; diff --git a/html/includes/common/worldmap.inc.php b/html/includes/common/worldmap.inc.php index c179b6db27..cceb080b93 100644 --- a/html/includes/common/worldmap.inc.php +++ b/html/includes/common/worldmap.inc.php @@ -150,18 +150,18 @@ var greenMarker = L.AwesomeMarkers.icon({ // Checking user permissions if (is_admin() || is_read()) { // Admin or global read-only - show all devices - $sql = "SELECT DISTINCT(`device_id`),`hostname`,`os`,`status`,`lat`,`lng` FROM `devices` + $sql = "SELECT DISTINCT(`device_id`),`devices`.`location`,`hostname`,`os`,`status`,`lat`,`lng` FROM `devices` LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location` - WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != '' + WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`devices`.`location` REGEXP '\[[0-9\.\, ]+\]')) AND `status` IN (".$widget_settings['status'].") ORDER BY `status` ASC, `hostname`"; } else { // Normal user - grab devices that user has permissions to - $sql = "SELECT DISTINCT(`devices`.`device_id`) as `device_id`,`hostname`,`os`,`status`,`lat`,`lng` + $sql = "SELECT DISTINCT(`devices`.`device_id`) as `device_id`,`devices`.`location`,`hostname`,`os`,`status`,`lat`,`lng` FROM `devices_perms`, `devices` LEFT JOIN `locations` ON `devices`.`location`=`locations`.`location` - WHERE `disabled`=0 AND `ignore`=0 AND `lat` != '' AND `lng` != '' + WHERE `disabled`=0 AND `ignore`=0 AND ((`lat` != '' AND `lng` != '') OR (`devices`.`location` REGEXP '\[[0-9\.\, ]+\]')) AND `devices`.`device_id` = `devices_perms`.`device_id` AND `devices_perms`.`user_id` = ? AND `status` IN (".$widget_settings['status'].") ORDER BY `status` ASC, `hostname`"; @@ -170,6 +170,11 @@ var greenMarker = L.AwesomeMarkers.icon({ foreach (dbFetchRows($sql, $param) as $map_devices) { $icon = 'greenMarker'; $z_offset = 0; + $tmp_loc = parse_location($map_devices['location']); + if (!empty($tmp_loc['lat']) && !empty($tmp_loc['lng'])) { + $map_devices['lat'] = $tmp_loc['lat']; + $map_devices['lng'] = $tmp_loc['lng']; + } if ($map_devices['status'] == 0) { $icon = 'redMarker'; $z_offset = 10000; // move marker to foreground diff --git a/html/includes/dev-overview-data.inc.php b/html/includes/dev-overview-data.inc.php index 4adae6a31b..de602c18fd 100644 --- a/html/includes/dev-overview-data.inc.php +++ b/html/includes/dev-overview-data.inc.php @@ -78,7 +78,10 @@ if ($device['location']) { } } -$loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device['location'])); +$loc = parse_location($device['location']); +if (!is_array($loc)) { + $loc = dbFetchRow("SELECT `lat`,`lng` FROM `locations` WHERE `location`=? LIMIT 1", array($device['location'])); +} if (is_array($loc)) { echo ' Lat / Lng diff --git a/html/includes/forms/notifications.inc.php b/html/includes/forms/notifications.inc.php new file mode 100644 index 0000000000..d787389e52 --- /dev/null +++ b/html/includes/forms/notifications.inc.php @@ -0,0 +1,56 @@ + + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . */ + +/** + * Notification Page + * @author Daniel Preussker + * @copyright 2015 Daniel Preussker, QuxLabs UG + * @license GPL + * @package LibreNMS + * @subpackage Notifications + */ + +$status = 'error'; +$message = 'unknown error'; +if (isset($_REQUEST['notification_id']) && isset($_REQUEST['action'])) { + if ($_REQUEST['action'] == 'read' && dbInsert(array('notifications_id'=>$_REQUEST['notification_id'],'user_id'=>$_SESSION['user_id'],'key'=>'read','value'=>1),'notifications_attribs')) { + $status = 'ok'; + $message = 'Set as Read'; + } + elseif ($_SESSION['userlevel'] == 10 && $_REQUEST['action'] == 'stick' && dbInsert(array('notifications_id'=>$_REQUEST['notification_id'],'user_id'=>$_SESSION['user_id'],'key'=>'sticky','value'=>1),'notifications_attribs')) { + $status = 'ok'; + $message = 'Set as Sticky'; + } + elseif ($_SESSION['userlevel'] == 10 && $_REQUEST['action'] == 'unstick' && dbUpdate(array('key'=>'sticky','value'=>0),'notifications_attribs','notifications_id = ? && user_id = ?',array($_REQUEST['notification_id'],$_SESSION['user_id']))) { + $status = 'ok'; + $message = 'Removed Sticky'; + } +} +elseif ($_REQUEST['action'] == 'create' && $_SESSION['userlevel'] == 10 && (isset($_REQUEST['title']) && isset($_REQUEST['body']))) { + if (dbInsert(array('title'=>$_REQUEST['title'],'body'=>$_REQUEST['body'],'checksum'=>hash('sha512',$_SESSION['user_id'].'.LOCAL.'.$_REQUEST['title']),'source'=>$_SESSION['user_id']),'notifications')) { + $status = 'ok'; + $message = 'Created'; + } +} +else { + $status = 'error'; + $message = 'ERROR: Missing Params'; +} + +die(json_encode(array( + 'status' => $status, + 'message' => $message, +))); + diff --git a/html/includes/forms/query-ripenccapi.inc.php b/html/includes/forms/query-ripenccapi.inc.php index dd62474f53..0e21b12fe9 100644 --- a/html/includes/forms/query-ripenccapi.inc.php +++ b/html/includes/forms/query-ripenccapi.inc.php @@ -12,11 +12,12 @@ $status = 'error'; $message = 'unknown error'; -$parameter = mres($_POST['parameter']); -if (isset($parameter)) { +$data_param = mres($_POST['data_param']); +$query_param = mres($_POST['query_param']); +if (isset($data_param) && isset($query_param)) { $status = 'ok'; $message = 'Queried'; - $output = get_ripe_api_whois_data_json($parameter); + $output = get_ripe_api_whois_data_json($data_param, $query_param); } else { $status = 'error'; @@ -25,6 +26,7 @@ else { die(json_encode(array( 'status' => $status, 'message' => $message, - 'parameter' => $parameter, + 'data_param' => $data_param, + 'query_param' => $query_param, 'output' => $output ))); diff --git a/html/includes/functions.inc.php b/html/includes/functions.inc.php index d68457fb12..dc23186a9e 100644 --- a/html/includes/functions.inc.php +++ b/html/includes/functions.inc.php @@ -1253,8 +1253,8 @@ function generate_dynamic_config_panel($title,$end_panel=true,$config_groups,$it return $output; }//end generate_dynamic_config_panel() -function get_ripe_api_whois_data_json($ripe_parameter) { - $ripe_whois_url = 'https://stat.ripe.net/data/whois/data.json?resource=' . $ripe_parameter; +function get_ripe_api_whois_data_json($ripe_data_param, $ripe_query_param) { + $ripe_whois_url = 'https://stat.ripe.net/data/'. $ripe_data_param . '/data.json?resource=' . $ripe_query_param; return json_decode(file_get_contents($ripe_whois_url) , true); }//end get_ripe_api_whois_data_json() diff --git a/html/includes/print-menubar.php b/html/includes/print-menubar.php index e61990ea03..61116e193e 100644 --- a/html/includes/print-menubar.php +++ b/html/includes/print-menubar.php @@ -47,7 +47,7 @@ else {