forked from Cacti/plugin_flowview
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fixprivate.php
83 lines (67 loc) · 3.72 KB
/
fixprivate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2024 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 |
| as published by the Free Software Foundation; either version 2 |
| 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. |
+-------------------------------------------------------------------------+
| Cacti: The Complete RRDtool-based Graphing Solution |
+-------------------------------------------------------------------------+
| This code is designed, written, and maintained by the Cacti Group. See |
| about.php and/or the AUTHORS file for specific developer information. |
+-------------------------------------------------------------------------+
| http://www.cacti.net/ |
+-------------------------------------------------------------------------+
*/
chdir('../../');
include('./include/cli_check.php');
include_once($config['base_path'] . '/plugins/flowview/setup.php');
include_once($config['base_path'] . '/plugins/flowview/functions.php');
include_once($config['base_path'] . '/lib/time.php');
flowview_connect();
$tables = flowview_db_fetch_assoc('SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_NAME LIKE "plugin_flowview_raw%"');
if (cacti_sizeof($tables)) {
foreach($tables as $table) {
print "Checking Table: " . $table['TABLE_NAME'] . PHP_EOL;
$src_ips = flowview_db_fetch_assoc('SELECT DISTINCT INET6_NTOA(src_addr) AS src_addr
FROM ' . $table['TABLE_NAME'] . '
WHERE INET6_NTOA(src_addr) LIKE "192.%"
AND INET6_NTOA(src_addr) NOT LIKE "192.168.%"');
if (cacti_sizeof($src_ips)) {
print "There are " . cacti_sizeof($src_ips) . " Source DNS records to fix" . PHP_EOL;
foreach($src_ips as $ip) {
$dns = flowview_get_dns_from_ip($ip['src_addr']);
$parts = array_reverse(explode('.', $dns));
$rdns = $parts[1] . '.' . $parts[0];
print "Repair: " . $ip['src_addr'] . ", To: " . $dns . ", RDNS: " . $rdns . PHP_EOL;
$sql = 'UPDATE ' . $table['TABLE_NAME'] . ' SET src_domain = ' . db_qstr($dns) . ', src_rdomain = ' . db_qstr($rdns) . ' WHERE INET6_NTOA(src_addr) = ' . db_qstr($ip['src_addr']);
flowview_db_execute($sql);
//print $sql . PHP_EOL;
}
}
$dst_ips = flowview_db_fetch_assoc('SELECT DISTINCT INET6_NTOA(dst_addr) AS dst_addr
FROM ' . $table['TABLE_NAME'] . '
WHERE INET6_NTOA(dst_addr) LIKE "192.%"
AND INET6_NTOA(dst_addr) NOT LIKE "192.168.%"');
if (cacti_sizeof($dst_ips)) {
print "There are " . cacti_sizeof($src_ips) . " Destination DNS records to fix" . PHP_EOL;
foreach($dst_ips as $ip) {
$dns = flowview_get_dns_from_ip($ip['dst_addr']);
$parts = array_reverse(explode('.', $dns));
$rdns = $parts[1] . '.' . $parts[0];
print "Repair: " . $ip['dst_addr'] . ", To: " . $dns . ", RDNS: " . $rdns . PHP_EOL;
$sql = 'UPDATE ' . $table['TABLE_NAME'] . ' SET dst_domain = ' . db_qstr($dns) . ', dst_rdomain = ' . db_qstr($rdns) . ' WHERE INET6_NTOA(dst_addr) = ' . db_qstr($ip['dst_addr']);
flowview_db_execute($sql);
//print $sql . PHP_EOL;
}
}
}
}