2013-01-04 08:27:05 +00:00
|
|
|
#
|
|
|
|
# Monitorix - A lightweight system monitoring tool.
|
|
|
|
#
|
2015-03-03 16:56:14 +00:00
|
|
|
# Copyright (C) 2005-2015 by Jordi Sanfeliu <jordi@fibranet.cat>
|
2013-01-04 08:27:05 +00:00
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
#
|
|
|
|
|
|
|
|
package Monitorix;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use Exporter 'import';
|
2013-01-31 17:48:29 +00:00
|
|
|
use POSIX qw(setuid setgid setsid);
|
2013-05-17 10:57:48 +01:00
|
|
|
use Socket;
|
2014-06-17 18:29:25 +01:00
|
|
|
our @EXPORT = qw(logger trim min max celsius_to uptime2str setup_riglim httpd_setup get_nvidia_data get_ati_data flush_accounting_rules);
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
sub logger {
|
|
|
|
my ($msg) = @_;
|
|
|
|
|
|
|
|
$msg = localtime() . " - " . $msg;
|
|
|
|
print("$msg\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
sub trim {
|
|
|
|
my $str = shift;
|
|
|
|
|
|
|
|
if($str) {
|
|
|
|
$str =~ s/^\s+//;
|
|
|
|
$str =~ s/\s+$//;
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-24 14:32:54 +01:00
|
|
|
sub min {
|
|
|
|
my ($min, @args) = @_;
|
|
|
|
foreach(@args) {
|
|
|
|
$min = $_ if $_ < $min;
|
|
|
|
}
|
|
|
|
return $min;
|
|
|
|
}
|
|
|
|
|
2013-01-28 12:18:03 +00:00
|
|
|
sub max {
|
|
|
|
my ($max, @args) = @_;
|
2013-01-29 11:45:33 +00:00
|
|
|
foreach(@args) {
|
2013-01-28 12:18:03 +00:00
|
|
|
$max = $_ if $_ > $max;
|
|
|
|
}
|
|
|
|
return $max;
|
|
|
|
}
|
|
|
|
|
2013-03-27 18:24:56 +00:00
|
|
|
sub celsius_to {
|
2013-03-27 17:42:09 +00:00
|
|
|
my ($config, $celsius) = @_;
|
|
|
|
|
2013-03-27 17:58:15 +00:00
|
|
|
$celsius = $celsius || 0;
|
2013-03-27 18:58:09 +00:00
|
|
|
if(lc($config->{temperature_scale}) eq "f") {
|
2013-03-27 17:42:09 +00:00
|
|
|
return ($celsius * (9 / 5)) + 32;
|
|
|
|
}
|
|
|
|
return $celsius;
|
|
|
|
}
|
|
|
|
|
2013-06-12 16:20:04 +01:00
|
|
|
sub uptime2str {
|
2013-06-12 16:33:05 +01:00
|
|
|
my $uptime = shift || 0;
|
2013-06-12 16:20:04 +01:00
|
|
|
my $str;
|
|
|
|
|
|
|
|
my $d = int($uptime / (60 * 60 * 24));
|
|
|
|
my $h = int($uptime / (60 * 60)) % 24;
|
|
|
|
my $m = int($uptime / 60) % 60;
|
|
|
|
|
|
|
|
my $d_string = $d ? sprintf("%d days,", $d) : "";
|
|
|
|
my $h_string = $h ? sprintf("%d", $h) : "";
|
|
|
|
my $m_string = $h ? sprintf("%sh %dm", $h, $m) : sprintf("%d min", $m);
|
|
|
|
|
|
|
|
return "$d_string $m_string";
|
|
|
|
}
|
|
|
|
|
2014-06-17 18:29:25 +01:00
|
|
|
sub setup_riglim {
|
|
|
|
my $myself = (caller(0))[3];
|
|
|
|
my ($rigid, $limit) = @_;
|
|
|
|
my @riglim;
|
|
|
|
|
2014-06-17 18:32:50 +01:00
|
|
|
my ($upper, $lower) = split(':', trim($limit) || "0:0");
|
2014-06-18 10:22:44 +01:00
|
|
|
if(trim($rigid || 0) eq 0) {
|
|
|
|
push(@riglim, "--lower-limit=$lower") if defined($lower);
|
|
|
|
} else {
|
2014-06-18 09:17:57 +01:00
|
|
|
push(@riglim, "--upper-limit=" . ($upper || 0));
|
|
|
|
push(@riglim, "--lower-limit=" . ($lower || 0));
|
|
|
|
push(@riglim, "--rigid") if trim($rigid || 0) eq 2;
|
|
|
|
}
|
2014-06-17 18:29:25 +01:00
|
|
|
return \@riglim;
|
|
|
|
}
|
|
|
|
|
2013-01-31 17:48:29 +00:00
|
|
|
sub httpd_setup {
|
2013-05-15 11:46:04 +01:00
|
|
|
my $myself = (caller(0))[3];
|
2013-01-31 17:48:29 +00:00
|
|
|
my ($config, $debug) = @_;
|
|
|
|
my $pid;
|
|
|
|
|
2013-02-07 14:57:42 +00:00
|
|
|
my (undef, undef, $uid) = getpwnam($config->{httpd_builtin}->{user});
|
|
|
|
my (undef, undef, $gid) = getgrnam($config->{httpd_builtin}->{group});
|
2013-05-17 10:57:48 +01:00
|
|
|
my $host = $config->{httpd_builtin}->{host};
|
2013-02-07 14:57:42 +00:00
|
|
|
my $port = $config->{httpd_builtin}->{port};
|
|
|
|
|
|
|
|
if(!defined($uid)) {
|
2013-05-15 11:46:04 +01:00
|
|
|
logger("$myself: ERROR: invalid user defined.");
|
2013-02-07 14:57:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!defined($gid)) {
|
2013-05-15 11:46:04 +01:00
|
|
|
logger("$myself: ERROR: invalid group defined.");
|
2013-02-07 14:57:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(!defined($port)) {
|
2013-05-15 11:46:04 +01:00
|
|
|
logger("$myself: ERROR: invalid port defined.");
|
2013-02-07 14:57:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-01-31 17:48:29 +00:00
|
|
|
if($pid = fork()) {
|
|
|
|
$config->{httpd_pid} = $pid;
|
|
|
|
return; # parent returns
|
|
|
|
}
|
|
|
|
|
2013-02-15 10:54:38 +00:00
|
|
|
# create the HTTPd logfile
|
2013-02-15 10:55:20 +00:00
|
|
|
open(OUT, ">> " . $config->{httpd_builtin}->{log_file});
|
2013-02-15 10:54:38 +00:00
|
|
|
close(OUT);
|
|
|
|
chown($uid, $gid, $config->{httpd_builtin}->{log_file});
|
|
|
|
|
2013-01-31 17:48:29 +00:00
|
|
|
setgid($gid);
|
|
|
|
setuid($uid);
|
|
|
|
setsid();
|
|
|
|
$SIG{$_} = 'DEFAULT' for keys %SIG; # reset all sighandlers
|
|
|
|
$0 = "monitorix-httpd listening on $port"; # change process' name
|
|
|
|
chdir($config->{base_dir});
|
|
|
|
|
2013-05-15 11:46:04 +01:00
|
|
|
# check if 'htpasswd' file does exists and it's accessible
|
2014-07-29 09:57:46 +01:00
|
|
|
if(lc($config->{httpd_builtin}->{auth}->{enabled}) eq "y") {
|
2013-05-15 11:46:04 +01:00
|
|
|
if(! -r ($config->{httpd_builtin}->{auth}->{htpasswd} || "")) {
|
|
|
|
logger("$myself: '$config->{httpd_builtin}->{auth}->{htpasswd}' $!");
|
|
|
|
}
|
2014-06-30 17:29:38 +01:00
|
|
|
} else {
|
|
|
|
if(!grep {$_ eq $config->{httpd_builtin}->{host}}
|
|
|
|
("localhost", "127.0.0.1")) {
|
2014-07-08 07:45:31 +01:00
|
|
|
logger("WARNING: the built-in HTTP server has authentication disabled.");
|
2014-06-30 17:29:38 +01:00
|
|
|
}
|
2013-05-15 11:46:04 +01:00
|
|
|
}
|
|
|
|
|
2013-05-17 10:57:48 +01:00
|
|
|
my $server = HTTPServer->new();
|
|
|
|
$server->host($host);
|
|
|
|
$server->port($port);
|
2013-02-11 11:36:31 +00:00
|
|
|
$server->run();
|
|
|
|
exit(0);
|
2013-01-31 17:48:29 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
sub get_nvidia_data {
|
2013-02-20 14:32:41 +00:00
|
|
|
my $myself = (caller(0))[3];
|
2013-01-04 08:27:05 +00:00
|
|
|
my ($gpu) = @_;
|
|
|
|
my $total = 0;
|
|
|
|
my $used = 0;
|
|
|
|
my $mem = 0;
|
|
|
|
my $cpu = 0;
|
|
|
|
my $temp = 0;
|
|
|
|
my $check_mem = 0;
|
|
|
|
my $check_cpu = 0;
|
|
|
|
my $check_temp = 0;
|
|
|
|
my $l;
|
|
|
|
|
2013-02-20 14:32:41 +00:00
|
|
|
my @data = ();
|
|
|
|
if(open(IN, "nvidia-smi -q -i $gpu -d MEMORY,UTILIZATION,TEMPERATURE |")) {
|
|
|
|
@data = <IN>;
|
|
|
|
close(IN);
|
|
|
|
} else {
|
|
|
|
logger("$myself: ERROR: 'nvidia-smi' command is not installed.");
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
for($l = 0; $l < scalar(@data); $l++) {
|
|
|
|
if($data[$l] =~ /Memory Usage/) {
|
2014-07-28 11:41:52 +01:00
|
|
|
if($data[$l] !~ /BAR1 Memory Usage/) {
|
|
|
|
$check_mem = 1;
|
|
|
|
next;
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
|
|
|
if($check_mem) {
|
|
|
|
if($data[$l] =~ /Total/) {
|
|
|
|
my (undef, $tmp) = split(':', $data[$l]);
|
|
|
|
if($tmp eq "\n") {
|
|
|
|
$l++;
|
|
|
|
$tmp = $data[$l];
|
|
|
|
}
|
|
|
|
my ($value, undef) = split(' ', $tmp);
|
|
|
|
$value =~ s/[-]/./;
|
|
|
|
$value =~ s/[^0-9.]//g;
|
|
|
|
if(int($value) > 0) {
|
|
|
|
$total = int($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if($data[$l] =~ /Used/) {
|
|
|
|
my (undef, $tmp) = split(':', $data[$l]);
|
|
|
|
if($tmp eq "\n") {
|
|
|
|
$l++;
|
|
|
|
$tmp = $data[$l];
|
|
|
|
}
|
|
|
|
my ($value, undef) = split(' ', $tmp);
|
|
|
|
$value =~ s/[-]/./;
|
|
|
|
$value =~ s/[^0-9.]//g;
|
|
|
|
if(int($value) > 0) {
|
|
|
|
$used = int($value);
|
|
|
|
}
|
|
|
|
$check_mem = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if($data[$l] =~ /Utilization/) {
|
|
|
|
$check_cpu = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if($check_cpu) {
|
|
|
|
if($data[$l] =~ /Gpu/) {
|
|
|
|
my (undef, $tmp) = split(':', $data[$l]);
|
|
|
|
if($tmp eq "\n") {
|
|
|
|
$l++;
|
|
|
|
$tmp = $data[$l];
|
|
|
|
}
|
|
|
|
my ($value, undef) = split(' ', $tmp);
|
|
|
|
$value =~ s/[-]/./;
|
|
|
|
$value =~ s/[^0-9.]//g;
|
2013-07-08 11:04:12 +01:00
|
|
|
$value ||= 0; # zero if not numeric
|
2013-01-04 08:27:05 +00:00
|
|
|
if(int($value) > 0) {
|
|
|
|
$cpu = int($value);
|
|
|
|
}
|
|
|
|
}
|
2013-07-08 11:04:12 +01:00
|
|
|
# not used
|
2013-01-04 08:27:05 +00:00
|
|
|
if($data[$l] =~ /Memory/) {
|
|
|
|
my (undef, $tmp) = split(':', $data[$l]);
|
|
|
|
if($tmp eq "\n") {
|
|
|
|
$l++;
|
|
|
|
$tmp = $data[$l];
|
|
|
|
}
|
|
|
|
my ($value, undef) = split(' ', $tmp);
|
|
|
|
$value =~ s/[-]/./;
|
|
|
|
$value =~ s/[^0-9.]//g;
|
2013-07-08 11:04:12 +01:00
|
|
|
$value ||= 0; # zero if not numeric
|
2013-01-04 08:27:05 +00:00
|
|
|
if(int($value) > 0) {
|
|
|
|
$mem = int($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$check_cpu = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if($data[$l] =~ /Temperature/) {
|
|
|
|
$check_temp = 1;
|
|
|
|
next;
|
|
|
|
}
|
|
|
|
if($check_temp) {
|
2014-07-28 11:41:52 +01:00
|
|
|
if($data[$l] =~ /Gpu.*?(?:Current Temp)?/i) {
|
2013-01-04 08:27:05 +00:00
|
|
|
my (undef, $tmp) = split(':', $data[$l]);
|
|
|
|
if($tmp eq "\n") {
|
|
|
|
$l++;
|
|
|
|
$tmp = $data[$l];
|
|
|
|
}
|
|
|
|
my ($value, undef) = split(' ', $tmp);
|
|
|
|
$value =~ s/[-]/./;
|
|
|
|
$value =~ s/[^0-9.]//g;
|
|
|
|
if(int($value) > 0) {
|
|
|
|
$temp = int($value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$check_temp = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
# NVIDIA driver v285.+ not supported (needs new output parsing).
|
|
|
|
# This is to avoid a divide by zero message.
|
|
|
|
if($total) {
|
|
|
|
$mem = ($used * 100) / $total;
|
|
|
|
} else {
|
|
|
|
$mem = $used = $total = 0;
|
|
|
|
}
|
|
|
|
return join(" ", $mem, $cpu, $temp);
|
|
|
|
}
|
|
|
|
|
2013-04-09 11:57:00 +01:00
|
|
|
sub get_ati_data {
|
|
|
|
my $myself = (caller(0))[3];
|
|
|
|
my ($gpu) = @_;
|
|
|
|
my $temp = 0;
|
|
|
|
|
|
|
|
my @data = ();
|
2013-04-09 13:48:24 +01:00
|
|
|
if(open(IN, "aticonfig --odgt --adapter=$gpu |")) {
|
2013-04-09 11:57:00 +01:00
|
|
|
@data = <IN>;
|
|
|
|
close(IN);
|
|
|
|
} else {
|
|
|
|
logger("$myself: ERROR: 'aticonfig' command is not installed.");
|
|
|
|
}
|
|
|
|
foreach(@data) {
|
|
|
|
if(/Sensor \d: Temperature - (\d+\.\d+) C/) {
|
|
|
|
$temp = $1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $temp || 0;
|
|
|
|
}
|
|
|
|
|
2013-01-04 08:27:05 +00:00
|
|
|
# flushes out all Monitorix iptables/ipfw rules
|
|
|
|
sub flush_accounting_rules {
|
|
|
|
my ($config, $debug) = @_;
|
2014-06-26 10:50:17 +01:00
|
|
|
my $table = $config->{ip_default_table};
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
if($config->{os} eq "Linux") {
|
|
|
|
my $num = 0;
|
2015-02-17 14:36:42 +00:00
|
|
|
my $num6 = 0;
|
|
|
|
my $cmd = "iptables" . $config->{iptables_wait_lock};
|
|
|
|
my $cmd6 = "ip6tables" . $config->{iptables_wait_lock};
|
2013-01-04 08:27:05 +00:00
|
|
|
|
|
|
|
logger("Flushing out iptables rules.") if $debug;
|
2013-01-25 12:02:53 +00:00
|
|
|
{
|
2013-01-04 08:27:05 +00:00
|
|
|
my @names;
|
2015-02-16 17:00:45 +00:00
|
|
|
|
|
|
|
# IPv4
|
2015-02-17 14:36:42 +00:00
|
|
|
if(open(IN, "$cmd -t $table -nxvL INPUT --line-numbers |")) {
|
2013-01-25 12:02:53 +00:00
|
|
|
my @rules;
|
|
|
|
while(<IN>) {
|
|
|
|
my ($rule, undef, undef, $name) = split(' ', $_);
|
|
|
|
if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) {
|
|
|
|
push(@rules, $rule);
|
|
|
|
push(@names, $name);
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
2013-01-25 12:02:53 +00:00
|
|
|
close(IN);
|
|
|
|
@rules = reverse(@rules);
|
|
|
|
foreach(@rules) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd -t $table -D INPUT $_");
|
2013-01-25 12:02:53 +00:00
|
|
|
$num++;
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-17 14:36:42 +00:00
|
|
|
if(open(IN, "$cmd -t $table -nxvL OUTPUT --line-numbers |")) {
|
2013-01-25 12:02:53 +00:00
|
|
|
my @rules;
|
|
|
|
while(<IN>) {
|
|
|
|
my ($rule, undef, undef, $name) = split(' ', $_);
|
|
|
|
if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) {
|
|
|
|
push(@rules, $rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
@rules = reverse(@rules);
|
|
|
|
foreach(@rules) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd -t $table -D OUTPUT $_");
|
2013-01-25 12:02:53 +00:00
|
|
|
$num++;
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
|
|
|
foreach(@names) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd -t $table -X $_");
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
2015-02-16 17:00:45 +00:00
|
|
|
|
|
|
|
# IPv6
|
|
|
|
undef(@names);
|
2015-02-17 14:36:42 +00:00
|
|
|
if(open(IN, "$cmd6 -t $table -nxvL INPUT --line-numbers |")) {
|
2015-02-16 17:00:45 +00:00
|
|
|
my @rules;
|
|
|
|
while(<IN>) {
|
|
|
|
my ($rule, undef, undef, $name) = split(' ', $_);
|
|
|
|
if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) {
|
|
|
|
push(@rules, $rule);
|
|
|
|
push(@names, $name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
@rules = reverse(@rules);
|
|
|
|
foreach(@rules) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd6 -t $table -D INPUT $_");
|
|
|
|
$num6++;
|
2015-02-16 17:00:45 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-17 14:36:42 +00:00
|
|
|
if(open(IN, "$cmd6 -t $table -nxvL OUTPUT --line-numbers |")) {
|
2015-02-16 17:00:45 +00:00
|
|
|
my @rules;
|
|
|
|
while(<IN>) {
|
|
|
|
my ($rule, undef, undef, $name) = split(' ', $_);
|
|
|
|
if($name =~ /monitorix_IN/ || /monitorix_OUT/ || /monitorix_nginx_IN/) {
|
|
|
|
push(@rules, $rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
@rules = reverse(@rules);
|
|
|
|
foreach(@rules) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd6 -t $table -D OUTPUT $_");
|
|
|
|
$num6++;
|
2015-02-16 17:00:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach(@names) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd6 -t $table -X $_");
|
2015-02-16 17:00:45 +00:00
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
2015-02-17 14:36:42 +00:00
|
|
|
if(open(IN, "$cmd -t $table -nxvL FORWARD --line-numbers |")) {
|
2013-01-08 16:22:05 +00:00
|
|
|
my @rules;
|
|
|
|
my @names;
|
|
|
|
while(<IN>) {
|
|
|
|
my ($rule, undef, undef, $name) = split(' ', $_);
|
|
|
|
if($name =~ /monitorix_daily_/ || /monitorix_total_/) {
|
|
|
|
push(@rules, $rule);
|
|
|
|
push(@names, $name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
@rules = reverse(@rules);
|
|
|
|
foreach(@rules) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd -t $table -D FORWARD $_");
|
2013-01-08 16:22:05 +00:00
|
|
|
$num++;
|
|
|
|
}
|
|
|
|
foreach(@names) {
|
2015-02-17 14:36:42 +00:00
|
|
|
system("$cmd -t $table -F $_");
|
|
|
|
system("$cmd -t $table -X $_");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(open(IN, "$cmd6 -t $table -nxvL FORWARD --line-numbers |")) {
|
|
|
|
my @rules;
|
|
|
|
my @names;
|
|
|
|
while(<IN>) {
|
|
|
|
my ($rule, undef, undef, $name) = split(' ', $_);
|
|
|
|
if($name =~ /monitorix_daily_/ || /monitorix_total_/) {
|
|
|
|
push(@rules, $rule);
|
|
|
|
push(@names, $name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(IN);
|
|
|
|
@rules = reverse(@rules);
|
|
|
|
foreach(@rules) {
|
|
|
|
system("$cmd6 -t $table -D FORWARD $_");
|
|
|
|
$num6++;
|
|
|
|
}
|
|
|
|
foreach(@names) {
|
|
|
|
system("$cmd6 -t $table -F $_");
|
|
|
|
system("$cmd6 -t $table -X $_");
|
2013-01-08 16:22:05 +00:00
|
|
|
}
|
|
|
|
}
|
2013-01-04 08:27:05 +00:00
|
|
|
logger("$num iptables rules have been flushed.") if $debug;
|
2015-02-17 14:36:42 +00:00
|
|
|
logger("$num6 ip6tables rules have been flushed.") if $debug;
|
2013-01-04 08:27:05 +00:00
|
|
|
}
|
|
|
|
if(grep {$_ eq $config->{os}} ("FreeBSD", "OpenBSD", "NetBSD")) {
|
|
|
|
logger("Flushing out ipfw rules.") if $debug;
|
|
|
|
system("ipfw delete $config->{port}->{rule} 2>/dev/null");
|
|
|
|
system("ipfw delete $config->{nginx}->{rule} 2>/dev/null");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|