Private
Server IP : 195.201.23.43  /  Your IP : 18.218.26.136
Web Server : Apache
System : Linux webserver2.vercom.be 5.4.0-192-generic #212-Ubuntu SMP Fri Jul 5 09:47:39 UTC 2024 x86_64
User : kdecoratie ( 1041)
PHP Version : 7.1.33-63+ubuntu20.04.1+deb.sury.org+1
Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/share/webmin/status/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME SHELL ]     

Current File : /usr/share/webmin/status/traffic-monitor.pl
# traffic-monitor.pl
# Check if network traffic is too high

sub get_traffic_status
{
local %traffic;
&read_file("$module_config_directory/traffic", \%traffic);
local $ifaces = &get_traffic_list();
local @i = @{$ifaces->{$_[0]->{'iface'}}};
if (@i) {
	local @l = split(/\s+/, $traffic{$_[0]->{'iface'}.'-'.$_[0]->{'dir'}});
	local $now = time();
	local $diff;
	if ($_[0]->{'dir'} == 0) {
		$diff = ($i[0]+$i[2]) - ($l[0]+$l[2]);
		}
	elsif ($_[0]->{'dir'} == 1) {
		$diff = $i[0] - $l[0];
		}
	else {
		$diff = $i[2] - $l[2];
		}
	if ($now <= $l[4]) {
		return { 'up' => 1 };
		}
	local $up = $diff / ($now - $l[4]) > $_[0]->{'bytes'} ? 0 : 1;
	@l = ( $i[0], $i[1], $i[2], $i[3], $now );
	$traffic{$_[0]->{'iface'}.'-'.$_[0]->{'dir'}} = join(" ", @l);
	&write_file("$module_config_directory/traffic", \%traffic);
	return { 'up' => $up };
	}
else {
	# Interface is gone!
	return { 'up' => -1 };
	}
}

sub show_traffic_dialog
{
print &ui_table_row(undef, $text{'traffic_desc'}, 4);

local $ifaces = &get_traffic_list();
print &ui_table_row($text{'traffic_iface'},
	&ui_select("iface", $_[0]->{'iface'},
		   [ map { [ $_ ] } sort { $a cmp $b } keys %$ifaces ]));

print &ui_table_row($text{'traffic_bytes'},
	&ui_textbox("bytes", $_[0]->{'bytes'}, 6));

print &ui_table_row($text{'traffic_dir'},
	&ui_radio("dir", int($_[0]->{'dir'}),
		[ [ 0, $text{'traffic_dir0'} ],
		  [ 1, $text{'traffic_dir1'} ],
		  [ 2, $text{'traffic_dir2'} ] ]), 3);
}

sub parse_traffic_dialog
{
local $ifaces = &get_traffic_list();
(keys %$ifaces) || &error($text{'traffic_eifaces'});
$in{'bytes'} =~ /^\d+$/ || &error($text{'traffic_ebytes'});
$_[0]->{'iface'} = $in{'iface'};
$_[0]->{'bytes'} = $in{'bytes'};
$_[0]->{'dir'} = $in{'dir'};
}

# get_traffic_list()
# Returns a map from interface names to arrays of bytes in, packets in,
# bytes out, packets out
sub get_traffic_list
{
local %rv;
if ($gconfig{'os_type'} eq 'freebsd') {
	# Get interfaces from netstat command
	open(NETSTAT, "netstat -nib |");
	while(<NETSTAT>) {
		if (/^(\S+)\s+(\d+)\s+(\S+)\s+(\d+\.\d+\.\d+\.\d+)\s+(\d+)\s+(\S+)\s+(\d+)\s+(\d+)\s+(\S+)\s+(\d+)/ && !$rv{$1}) {
			$rv{$1} = [ $7, $5, $10, $8 ];
			}
		}
	close(NETSTAT);
	}
else {
	# Get interfaces from Linux proc file
	open(TR, "</proc/net/dev");
	while(<TR>) {
		if (/^\s*([a-z0-9]+):\s*(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
			$rv{$1} = [ $2, $3, $10, $11 ];
			}
		}
	close(TR);
	}
return \%rv;
}

Private