From: Michael Tremer Date: Thu, 11 Apr 2024 20:10:23 +0000 (+0200) Subject: ovpnmain.cgi: Refactor connection statistics page X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dbb46d1aa5e2a638eda8a8794577f05dfcd6e6eb;p=people%2Fms%2Fipfire-2.x.git ovpnmain.cgi: Refactor connection statistics page No functional changes Signed-off-by: Michael Tremer --- diff --git a/html/cgi-bin/ovpnmain.cgi b/html/cgi-bin/ovpnmain.cgi index 2b6deb67c..7819db3db 100755 --- a/html/cgi-bin/ovpnmain.cgi +++ b/html/cgi-bin/ovpnmain.cgi @@ -3093,111 +3093,137 @@ END &Header::showhttpheaders(); &Header::openpage($Lang::tr{'ovpn con stat'}, 1, ''); &Header::openbigbox('100%', 'LEFT', '', ''); - &Header::openbox('100%', 'LEFT', $Lang::tr{'ovpn con stat'}); -# -# $Lang::tr{'protocol'} -# protocol temp removed - print < - - $Lang::tr{'common name'} - $Lang::tr{'real address'} - $Lang::tr{'country'} - $Lang::tr{'virtual address'} - $Lang::tr{'loged in at'} - $Lang::tr{'bytes sent'} - $Lang::tr{'bytes received'} - $Lang::tr{'last activity'} - + &Header::opensection(); + + print < + + $Lang::tr{'common name'} + $Lang::tr{'real address'} + $Lang::tr{'country'} + $Lang::tr{'virtual address'} + $Lang::tr{'loged in at'} + $Lang::tr{'bytes sent'} + $Lang::tr{'bytes received'} + $Lang::tr{'last activity'} + END -; + my $filename = "/var/run/ovpnserver.log"; open(FILE, $filename) or die 'Unable to open config file.'; my @current = ; close(FILE); - my @users =(); + + my @users = (); my $status; my $uid = 0; - my $cn; my @match = (); - my $proto = "udp"; - my $address; my %userlookup = (); - foreach my $line (@current) - { + + foreach my $line (@current) { chomp($line); - if ( $line =~ /^Updated,(.+)/){ - @match = split( /^Updated,(.+)/, $line); - $status = $match[1]; - } -#gian - if ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { - @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); - if ($match[1] ne "Common Name") { - $cn = $match[1]; - $userlookup{$match[2]} = $uid; - $users[$uid]{'CommonName'} = $match[1]; - $users[$uid]{'RealAddress'} = $match[2]; - $users[$uid]{'BytesReceived'} = &General::formatBytes($match[3]); - $users[$uid]{'BytesSent'} = &General::formatBytes($match[4]); - $users[$uid]{'Since'} = $match[5]; - $users[$uid]{'Proto'} = $proto; - - # get country code for "RealAddress"... - my $ccode = &Location::Functions::lookup_country_code((split ':', $users[$uid]{'RealAddress'})[0]); - my $flag_icon = &Location::Functions::get_flag_icon($ccode); - $users[$uid]{'Country'} = "$ccode"; - $uid++; - } - } - if ( $line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { - @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); - if ($match[1] ne "Virtual Address") { - $address = $match[3]; - #find the uid in the lookup table - $uid = $userlookup{$address}; - $users[$uid]{'VirtualAddress'} = $match[1]; - $users[$uid]{'LastRef'} = $match[4]; + + if ($line =~ /^Updated,(.+)/) { + @match = split(/^Updated,(.+)/, $line); + $status = $match[1]; + + } elsif ( $line =~ /^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/) { + @match = split(m/^(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(\d+),(\d+),(.+)/, $line); + + # Skip the header + next if ($match[1] eq "Common Name"); + + $userlookup{$match[2]} = $uid; + $users[$uid]{'CommonName'} = $match[1]; + $users[$uid]{'RealAddress'} = $match[2]; + $users[$uid]{'BytesReceived'} = &General::formatBytes($match[3]); + $users[$uid]{'BytesSent'} = &General::formatBytes($match[4]); + $users[$uid]{'Since'} = $match[5]; + + my $address = (split ':', $users[$uid]{'RealAddress'})[0]; + $users[$uid]{'Country'} = &Location::Functions::lookup_country_code($address); + $uid++; + + } elsif ($line =~ /^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/) { + @match = split(m/^(\d+\.\d+\.\d+\.\d+),(.+),(\d+\.\d+\.\d+\.\d+\:\d+),(.+)/, $line); + + # Skip the header + next if ($match[1] eq "Virtual Address"); + + my $address = $match[3]; + #find the uid in the lookup table + $uid = $userlookup{$address}; + $users[$uid]{'VirtualAddress'} = $match[1]; + $users[$uid]{'LastRef'} = $match[4]; } - } } - my $user2 = @users; - if ($user2 >= 1){ - for (my $idx = 1; $idx <= $user2; $idx++){ - if ($idx % 2) { - print ""; - $col="bgcolor='$Header::color{'color22'}'"; - } else { - print ""; - $col="bgcolor='$Header::color{'color20'}'"; - } - print "$users[$idx-1]{'CommonName'}"; - print "$users[$idx-1]{'RealAddress'}"; - print "$users[$idx-1]{'Country'}"; - print "$users[$idx-1]{'VirtualAddress'}"; - print "$users[$idx-1]{'Since'}"; - print "$users[$idx-1]{'BytesSent'}"; - print "$users[$idx-1]{'BytesReceived'}"; - print "$users[$idx-1]{'LastRef'}"; - } + + foreach my $id (keys @users) { + my $user = $users[$id]; + + my $flag_icon = &Location::Functions::get_flag_icon($user->{"Country"}); + + print < + + $user->{"CommonName"} + + + + $user->{"RealAddress"} + + + + + $user->{"Country"} + + + + + $user->{"VirtualAddress"} + + + + $user->{"Since"} + + + + $user->{"BytesSent"} + + + + $user->{"BytesReceived"} + + + + $user->{"LastRef"} + + +END } - print ""; - print < - - - - - $Lang::tr{'the statistics were last updated at'} $status +print < + +

+ $Lang::tr{'the statistics were last updated at'} $status +

END ; - &Header::closebox(); - print ""; + + &Header::closesection(); + + print < + $Lang::tr{'back'} +

+END + &Header::closebigbox(); &Header::closepage(); + exit(0); ###