From: Michael Tremer Date: Sat, 23 Mar 2024 17:55:52 +0000 (+0100) Subject: services.cgi: Use the new service status function X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bdb8ef8db2d53a20fe1b9015f30899cd68124112;p=people%2Fmfischer%2Fipfire-2.x.git services.cgi: Use the new service status function Signed-off-by: Michael Tremer --- diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index e1e901c4e..3cf9ca311 100644 --- a/html/cgi-bin/services.cgi +++ b/html/cgi-bin/services.cgi @@ -45,22 +45,6 @@ undef (@dummy); my %cgiparams=(); -# Maps a nice printable name to the changing part of the pid file, which -# is also the name of the program -my %servicenames =( - $Lang::tr{'dhcp server'} => 'dhcpd', - $Lang::tr{'web server'} => 'httpd', - $Lang::tr{'cron server'} => 'fcron', - $Lang::tr{'dns proxy server'} => 'unbound', - $Lang::tr{'logging server'} => 'syslogd', - $Lang::tr{'kernel logging server'} => 'klogd', - $Lang::tr{'ntp server'} => 'ntpd', - $Lang::tr{'secure shell server'} => 'sshd', - $Lang::tr{'vpn'} => 'charon', - $Lang::tr{'web proxy'} => 'squid', - $Lang::tr{'intrusion detection system'} => 'suricata', - 'OpenVPN' => 'openvpn' -); my %link =( $Lang::tr{'dhcp server'} => "$Lang::tr{'dhcp server'}", @@ -102,41 +86,70 @@ if ( $querry[0] =~ "processescpu"){ &Header::openbigbox('100%', 'left'); &Header::openbox('100%', 'left', $Lang::tr{'services'}); - print < - - - - - - - -END -; - my $key = ''; - my $col=""; - foreach $key (sort keys %servicenames){ - $lines++; - if ($lines % 2){ - $col="bgcolor='$color{'color22'}'"; - print ""; - }else{ - $col="bgcolor='$color{'color20'}'"; - print ""; - } - my $shortname = $servicenames{$key}; - my $status = &isrunning($shortname,$col); - - print "$status\n"; - print "\n"; - } + &Header::ServiceStatus({ + # DHCP Server + $Lang::tr{'dhcp server'} => { + "process" => "dhcpd", + }, + + # Web Server + $Lang::tr{'web server'} => { + "process" => "httpd", + }, + + # Cron Server + $Lang::tr{'cron server'} => { + "process" => "fcron", + }, + + # DNS Proxy + $Lang::tr{'dns proxy server'} => { + "process" => "unbound", + }, + + # Syslog + $Lang::tr{'logging server'} => { + "process" => "syslogd", + }, + + # Kernel Logger + $Lang::tr{'kernel logging server'} => { + "process" => "klogd", + }, + + # Time Server + $Lang::tr{'ntp server'} => { + "process" => "ntpd", + }, + + # SSH Server + $Lang::tr{'secure shell server'} => { + "process" => "sshd", + }, + + # IPsec + $Lang::tr{'vpn'} => { + "process" => "charon", + }, + + # Web Proxy + $Lang::tr{'web proxy'} => { + "process" => "squid", + }, + + # IPS + $Lang::tr{'intrusion prevention system'} => { + "process" => "suricata", + }, + + # OpenVPN Roadwarrior + $Lang::tr{'ovpn roadwarrior server'} => { + "process" => "openvpn", + "pidfile" => "/var/run/openvpn.pid", + } + }); - print "
$Lang::tr{'service'}$Lang::tr{'status'}PID$Lang::tr{'memory'}
"; - print $link{$key}; - print "
"; - print $link{$key}; - print "
\n"; &Header::closebox(); &Header::openbox('100%', 'left', "$Lang::tr{addon} - $Lang::tr{services}"); @@ -168,6 +181,7 @@ END ; my $lines=0; # Used to count the outputlines to make different bgcolor + my $col; my @paks; my @addon_services; @@ -177,7 +191,7 @@ END foreach my $pak (sort keys %paklist) { my %metadata = &Pakfire::getmetadata($pak, "installed"); - + my $service; if ("$metadata{'Services'}") { @@ -195,7 +209,7 @@ END my $displayname = ($pak ne $service) ? "$service ($pak)" : $service; if ( -e "/srv/web/ipfire/cgi-bin/$pak.cgi" ) { $displayname = ($pak ne $service) ? "$service ($pak)" : "$service"; - } + } print "$displayname "; @@ -245,58 +259,6 @@ sub isautorun (@) { return $status; } -sub isrunning (@) { - my ($cmd, $col) = @_; - my $status = "$Lang::tr{'stopped'}"; - my $pid = ''; - my $testcmd = ''; - my $exename; - my $memory; - - $cmd =~ /(^[a-z]+)/; - - # Check if the exename needs to be overwritten. - # This happens if the expected process name string - # differs from the real one. This may happened if - # a service uses multiple processes or threads. - if (exists($overwrite_exename_hash{$1})) { - # Grab the string which will be reported by - # the process from the corresponding hash. - $exename = $overwrite_exename_hash{$1}; - } else { - # Directly expect the launched command as - # process name. - $exename = $1; - } - - if (open(FILE, "/var/run/${cmd}.pid")){ - $pid = ; chomp $pid; - close FILE; - if (open(FILE, "/proc/${pid}/status")){ - while (){ - if (/^Name:\W+(.*)/) { - $testcmd = $1; - } - } - close FILE; - } - if (open(FILE, "/proc/${pid}/status")) { - while () { - my ($key, $val) = split(":", $_, 2); - if ($key eq 'VmRSS') { - $memory = $val; - last; - } - } - close(FILE); - } - if ($testcmd =~ /$exename/){ - $status = "$Lang::tr{'running'}$pid$memory"; - } - } - return $status; -} - sub isrunningaddon (@) { my ($pak, $service, $col) = @_;