Skip to content

Commit

Permalink
Preparing for release 2.3
Browse files Browse the repository at this point in the history
Adding coprights, adding support for php7.x, updating copyright years
  • Loading branch information
cigamit committed Sep 25, 2019
1 parent 7a89d47 commit 5c58d79
Show file tree
Hide file tree
Showing 25 changed files with 561 additions and 194 deletions.
2 changes: 1 addition & 1 deletion mikrotik.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2017 The Cacti Group |
| Copyright (C) 2004-2019 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
Expand Down
26 changes: 13 additions & 13 deletions mikrotik_users.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2017 The Cacti Group |
| Copyright (C) 2004-2019 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
Expand Down Expand Up @@ -80,7 +80,7 @@ function form_actions() {
WHERE ' . array_to_sql_or($selected_items, 'data_local.snmp_index') . "
AND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");

if (sizeof($data_sources)) {
if (cacti_sizeof($data_sources)) {
foreach ($data_sources as $data_source) {
$data_sources_to_act_on[] = $data_source['local_data_id'];
}
Expand All @@ -92,7 +92,7 @@ function form_actions() {
WHERE ' . array_to_sql_or($selected_items, 'graph_local.snmp_index') . "
AND snmp_query_id='" . mikrotik_data_query_by_hash('ce63249e6cc3d52bc69659a3f32194fe') . "'");

if (sizeof($graphs)) {
if (cacti_sizeof($graphs)) {
foreach ($graphs as $graph) {
$graphs_to_act_on[] = $graph['local_graph_id'];
}
Expand All @@ -117,7 +117,7 @@ function form_actions() {
$user_list = '';

/* loop through each of the user templates selected on the previous page and get more info about them */
foreach ($_POST as $var => $val) {
while (list($var,$val) = each($_POST)) {
if (preg_match('/^chk_([A-Z0-9]+)$/', $var, $matches)) {
/* ================= input validation ================= */
$matches[1] = sanitize_search_string($matches[1]);
Expand Down Expand Up @@ -146,7 +146,7 @@ function form_actions() {
";
$save_html = "<input type='button' value='" . __esc('Cancel', 'mikrotik') . "' onClick='cactiReturnTo()'>&nbsp;<input type='submit' value='" . __esc('Continue', 'mikrotik') . "' title='" . __esc('Delete Device(s)', 'mikrotik') . "'>";
}
}else{
} else {
print "<tr><td><span class='textError'>" . __('You must select at least one User.', 'mikrotik') . "</span></td></tr>\n";
$save_html = "<input type='button' value='" . __esc('Return', 'mikrotik') . "' onClick='cactiReturnTo()'>";
}
Expand Down Expand Up @@ -213,7 +213,7 @@ function mikrotik_user() {
/* if the number of rows is -1, set it to the default */
if (get_request_var('rows') != '-1') {
$rows = get_request_var('rows');
}else{
} else {
$rows = read_config_option('num_rows_table');
}

Expand Down Expand Up @@ -274,7 +274,7 @@ function clearFilter() {
<select id='rows' onChange='applyFilter()'>
<option value='-1'<?php if (get_request_var('rows') == '-1') {?> selected<?php }?>><?php print __('Default', 'mikrotik');?></option>
<?php
if (sizeof($item_rows)) {
if (cacti_sizeof($item_rows)) {
foreach ($item_rows as $key => $value) {
print "<option value='" . $key . "'"; if (get_request_var('rows') == $key) { print ' selected'; } print '>' . htmlspecialchars($value) . "</option>\n";
}
Expand Down Expand Up @@ -309,19 +309,19 @@ function clearFilter() {
/* form the 'where' clause for our main sql query */
if (strlen(get_request_var('filter'))) {
$sql_where = "WHERE (name LIKE '%%" . get_request_var('filter') . "%%') AND name!=''";
}else{
} else {
$sql_where = "WHERE name!=''";
}

if (get_request_var('status') == 1) {
$sql_where .= ' AND present=1';
}elseif (get_request_var('status') == 2) {
} elseif (get_request_var('status') == 2) {
$sql_where .= ' AND present=0';
}

if (get_request_var('type') == '0') {
$sql_where .= (strlen($sql_where) ? ' AND':'WHERE') . ' userType=0';
}elseif (get_request_var('type') == '1') {
} elseif (get_request_var('type') == '1') {
$sql_where .= (strlen($sql_where) ? ' AND':'WHERE') . ' userType=1';
}

Expand Down Expand Up @@ -359,7 +359,7 @@ function clearFilter() {

html_header_sort_checkbox($display_text, get_request_var('sort_column'), get_request_var('sort_direction'), false);

if (sizeof($users)) {
if (cacti_sizeof($users)) {
foreach ($users as $user) {
form_alternate_row('line' . $user['name'], true);
form_selectable_cell("<span class='noLinkEditMain'>" . filter_value($user['name'], get_request_var('filter')) . '</span>', $user['name'], 250);
Expand All @@ -370,13 +370,13 @@ function clearFilter() {
form_checkbox_cell($user['name'], $user['name']);
form_end_row();
}
}else{
} else {
print '<tr><td><em>' . __('No Users Found', 'mikrotik') . '</em></td></tr>';
}

html_end_box(false);

if (sizeof($users)) {
if (cacti_sizeof($users)) {
print $nav;
}

Expand Down
70 changes: 35 additions & 35 deletions poller_graphs.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2017 The Cacti Group |
| Copyright (C) 2004-2019 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
Expand Down Expand Up @@ -83,7 +83,7 @@

/* Do not process if not enabled */
if (read_config_option('mikrotik_enabled') == '' || db_fetch_cell("SELECT status FROM plugin_config WHERE directory='mikrotik'") != 1) {
echo "WARNING: The MiktroTik Collection is Down! Exiting\n";
print "WARNING: The MiktroTik Collection is Down! Exiting\n";
exit(0);
}

Expand All @@ -93,12 +93,12 @@
debug("Last Run Was '" . date('Y-m-d H:i:s', $last_run) . "', Frequency is '" . ($frequency/60) . "' Minutes");

if ($frequency == 0) {
echo "NOTE: Graph Automation is Disabled\n";
}elseif (($frequency > 0 && ($start - $last_run) > $frequency) || ($frequency > 0 && $forcerun)) {
print "NOTE: Graph Automation is Disabled\n";
} elseif (($frequency > 0 && ($start - $last_run) > $frequency) || ($frequency > 0 && $forcerun)) {
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;

echo "NOTE: Starting Automation Process\n";
print "NOTE: Starting Automation Process\n";
db_execute("REPLACE INTO settings (name,value) VALUES ('mikrotik_automation_lastrun', '$start')");

debug('Removing invalid stations graphs');
Expand All @@ -117,8 +117,8 @@

/* log to the logfile */
cacti_log('MIKROTIK GRAPH STATS: ' . $cacti_stats , true, 'SYSTEM');
}else{
echo "NOTE: Its Not Time to Run Automation\n";
} else {
print "NOTE: Its Not Time to Run Automation\n";
}

exit(0);
Expand All @@ -139,16 +139,16 @@ function add_graphs() {
// $host_id = db_fetch_cell("SELECT id FROM host WHERE host_template_id=$host_template");
// if (empty($host_id)) {
// debug('MikroTik Summary Device Not Found, Adding');
// }else{
// } else {
// debug("Host Exists Hostname is '" . db_fetch_cell("SELECT description FROM host WHERE id=$host_id"). "'");
// }
//
//
// add_summary_graphs($host_id, $host_template);
// }else{
// } else {
// cacti_log('WARNING: Unable to find MikroTik Summary Host Template', true, 'MIKROTIK');
// }
// }else{
// } else {
// cacti_log('NOTE: MikroTik Summary Host Template Not Specified', true, 'MIKROTIK');
// }

Expand All @@ -170,7 +170,7 @@ function add_host_based_graphs() {
ON host.id=plugin_mikrotik_system.host_id
WHERE host_status IN(0,3) AND host.disabled=''");

if (sizeof($hosts)) {
if (cacti_sizeof($hosts)) {
foreach($hosts as $h) {
debug('Processing Host: ' . $h['description'] . ' [' . $h['hostname'] . ']');

Expand All @@ -189,15 +189,15 @@ function add_host_based_graphs() {
if ($hash == '7dd90372956af1dc8ec7b859a678f227') {
$exclusion = read_config_option('mikrotik_user_exclusion');
add_host_dq_graphs($h['host_id'], $query, 'userName', $exclusion, false);
}else{
} else {
add_host_dq_graphs($h['host_id'], $query);
}
}
}

$health = db_fetch_row_prepared('SELECT * FROM plugin_mikrotik_system_health WHERE host_id = ?', array($h['host_id']));
debug('Processing Health');
if (sizeof($health)) {
if (cacti_sizeof($health)) {
foreach($device_health_hashes as $column => $hash) {
if (!empty($health[$column]) && $health[$column] != 'NULL') {
$template = mikrotik_template_by_hash($hash);
Expand All @@ -209,7 +209,7 @@ function add_host_based_graphs() {
}
}
}
}else{
} else {
debug('No Hosts Found');
}
}
Expand All @@ -232,7 +232,7 @@ function add_host_dq_graphs($host_id, $dq, $field = '', $regex = '', $include =
WHERE snmp_query_id=' . $dq);

debug('Adding Graphs');
if (sizeof($graph_templates)) {
if (cacti_sizeof($graph_templates)) {
foreach($graph_templates as $gt) {
mikrotik_dq_graphs($host_id, $dq, $gt['graph_template_id'], $gt['id'], $field, $regex, $include);
}
Expand Down Expand Up @@ -260,14 +260,14 @@ function mikrotik_gt_graph($host_id, $graph_template_id) {
AND graph_template_id=$graph_template_id");

if (!$exists) {
echo "NOTE: Adding Graph: '$name' for Host: " . $host_id . "\n";
print "NOTE: Adding Graph: '$name' for Host: " . $host_id . "\n";

$command = "$php_bin -q $base/cli/add_graphs.php" .
" --graph-template-id=$graph_template_id" .
" --graph-type=cg" .
" --host-id=" . $host_id;

echo str_replace("\n", " ", passthru($command)) . "\n";
print str_replace("\n", " ", passthru($command)) . "\n";
}
}

Expand All @@ -282,7 +282,7 @@ function add_summary_graphs($host_id, $host_template) {
/* add the host */
debug('Adding Host');
$result = exec("$php_bin -q $base/cli/add_device.php --description='Summary Device' --ip=summary --template=$host_template --version=0 --avail=none", $return_code);
}else{
} else {
debug('Reindexing Host');
$result = exec("$php_bin -q $base/cli/poller_reindex_hosts.php -id=$host_id -qid=All", $return_code);
}
Expand All @@ -293,13 +293,13 @@ function add_summary_graphs($host_id, $host_template) {
FROM host_snmp_query
WHERE host_id=$host_id");

if (sizeof($data_queries)) {
if (cacti_sizeof($data_queries)) {
foreach($data_queries as $dq) {
$graph_templates = db_fetch_assoc("SELECT *
FROM snmp_query_graph
WHERE snmp_query_id=" . $dq['snmp_query_id']);

if (sizeof($graph_templates)) {
if (cacti_sizeof($graph_templates)) {
foreach($graph_templates as $gt) {
mikrotik_dq_graphs($host_id, $dq['snmp_query_id'], $gt['graph_template_id'], $gt['id']);
}
Expand All @@ -312,7 +312,7 @@ function add_summary_graphs($host_id, $host_template) {
FROM host_graph
WHERE host_id=$host_id");

if (sizeof($graph_templates)) {
if (cacti_sizeof($graph_templates)) {
foreach($graph_templates as $gt) {
/* see if the graph exists already */
$exists = db_fetch_cell("SELECT count(*)
Expand All @@ -321,14 +321,14 @@ function add_summary_graphs($host_id, $host_template) {
AND graph_template_id=" . $gt["graph_template_id"]);

if (!$exists) {
echo "NOTE: Adding item: '$field_value' for Host: " . $host_id;
print "NOTE: Adding item: '$field_value' for Host: " . $host_id;

$command = "$php_bin -q $base/cli/add_graphs.php" .
" --graph-template-id=" . $gt["graph_template_id"] .
" --graph-type=cg" .
" --host-id=" . $host_id;

echo str_replace("\n", " ", passthru($command)) . "\n";
print str_replace("\n", " ", passthru($command)) . "\n";
}
}
}
Expand All @@ -352,20 +352,20 @@ function mikrotik_dq_graphs($host_id, $query_id, $graph_template_id, $query_type
AND host_id=$host_id
AND snmp_query_id=$query_id");

if (sizeof($items)) {
if (cacti_sizeof($items)) {
foreach($items as $item) {
$field_value = $item['field_value'];
$index = $item['snmp_index'];

if ($regex == '') {
/* add graph below */
}else if ($include == false && preg_match("/$regex/", $field_value)) {
echo "NOTE: Bypassing item due to Regex rule: '$regex', Field Value: '" . $field_value . "' for Host: '" . $host_id . "'\n";
} else if ($include == false && preg_match("/$regex/", $field_value)) {
print "NOTE: Bypassing item due to Regex rule: '$regex', Field Value: '" . $field_value . "' for Host: '" . $host_id . "'\n";
continue;
}else if ($include == true && preg_match("/$regex/", $field_value)) {
} else if ($include == true && preg_match("/$regex/", $field_value)) {
/* add graph below, we should never be here */
}else{
echo "NOTE: Not Bypassing item due to Regex rule: '$regex', Field Value: '" . $field_value . "' for Host: '" . $host_id . "'\n";
} else {
print "NOTE: Not Bypassing item due to Regex rule: '$regex', Field Value: '" . $field_value . "' for Host: '" . $host_id . "'\n";
}

/* check to see if the graph exists or not */
Expand All @@ -383,7 +383,7 @@ function mikrotik_dq_graphs($host_id, $query_id, $graph_template_id, $query_type
" --snmp-query-id=$query_id --snmp-field=$field" .
" --snmp-value=" . cacti_escapeshellarg($field_value);

echo "NOTE: Adding item: '$field_value' " . str_replace("\n", " ", passthru($command)) . "\n";
print "NOTE: Adding item: '$field_value' " . str_replace("\n", " ", passthru($command)) . "\n";
}
}
}
Expand Down Expand Up @@ -423,7 +423,7 @@ function remove_invalid_station_graphs() {
WHERE graph_template_id = ?',
array($graph_template_id));

if (sizeof($graph_template_input)) {
if (cacti_sizeof($graph_template_input)) {
foreach ($graph_template_input as $item) {
db_execute_prepared('DELETE FROM graph_template_input_defs
WHERE graph_template_input_id = ?', array($item['id']));
Expand Down Expand Up @@ -495,7 +495,7 @@ function debug($message) {
global $debug;

if ($debug) {
echo 'DEBUG: ' . trim($message) . "\n";
print 'DEBUG: ' . trim($message) . "\n";
}
}

Expand All @@ -507,12 +507,12 @@ function display_version() {
}

$info = plugin_mikrotik_version();
echo "MikroTik Graph Automator, Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n";
print "MikroTik Graph Automator, Version " . $info['version'] . ", " . COPYRIGHT_YEARS . "\n";
}

function display_help() {
display_version();

echo "\nThe MikroTik process that creates graphs for Cacti.\n\n";
echo "usage: poller_graphs.php [-f] [-d]\n";
print "\nThe MikroTik process that creates graphs for Cacti.\n\n";
print "usage: poller_graphs.php [-f] [-d]\n";
}
2 changes: 1 addition & 1 deletion poller_mikrotik.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2017 The Cacti Group |
| Copyright (C) 2004-2019 The Cacti Group |
| |
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
Expand Down
Loading

0 comments on commit 5c58d79

Please sign in to comment.