From patchwork Tue Oct 11 22:01:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Robin Roevens X-Patchwork-Id: 6054 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4Mn8tT4qdGz3wgN for ; Tue, 11 Oct 2022 22:03:29 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4Mn8tP4JnDz2ZG; Tue, 11 Oct 2022 22:03:25 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4Mn8tN6zDsz2yl8; Tue, 11 Oct 2022 22:03:24 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4Mn8tL5xJXz2xmP for ; Tue, 11 Oct 2022 22:03:22 +0000 (UTC) Received: from knopi.disroot.org (knopi.disroot.org [178.21.23.139]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mail01.ipfire.org (Postfix) with ESMTPS id 4Mn8tK72b1z2Mm for ; Tue, 11 Oct 2022 22:03:21 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by disroot.org (Postfix) with ESMTP id 8C5444DB02 for ; Wed, 12 Oct 2022 00:03:21 +0200 (CEST) X-Virus-Scanned: SPAM Filter at disroot.org Received: from knopi.disroot.org ([127.0.0.1]) by localhost (disroot.org [127.0.0.1]) (amavisd-new, port 10024) with UTF8SMTP id RHjHDbx8xx43 for ; Wed, 12 Oct 2022 00:03:20 +0200 (CEST) Received: from chojin.sicho.home (amaterasu.sicho.home [192.168.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (no client certificate requested) (Authenticated sender) by hachiman (MailScanner Milter) with SMTP id F2C81751F4; Wed, 12 Oct 2022 00:02:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=disroot.org; s=mail; t=1665525746; bh=GM0fcuh6JCsI8ywioRsQ6Ly6B7KpqMUcdyXx5ewMjoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=h1OnDxXF9izQanATMUTcUqUbHCk89Ej/cMFbi6j/4pJyBIT73AljWs4IQ0YPs+0sf OMH2pRAOIF+NdQ3nui7+UOdn0u24rCBAkr4p+xrITUe5Psf4ObtcQewPCTLriFFXtQ V9WFaAcjEY+qLADavNjowhZR0PssbtAPYVoO4fBUuYoU4c7GtiLiVlaCQO+/x+LwpA 2UAkYcKAvZmDi36npb2P3uK9kKxN5zdT+QsTd6QEbh92KqOnzTtnwqq18zyaADkatn 7iGd9YF0gVDbcO5Ft/ngxzUx7xI/Lq9nFduwtjbWuMB3CrTeciG4GzoMJ/KbIk444m UqYUpwtJ11OpA== From: Robin Roevens To: development@lists.ipfire.org Subject: [PATCH v3 2/5] services.cgi: Fix status/actions on services with name != addon name Date: Wed, 12 Oct 2022 00:01:54 +0200 Message-Id: <20221011220157.17385-3-robin.roevens@disroot.org> In-Reply-To: <20221011220157.17385-1-robin.roevens@disroot.org> References: <20221011220157.17385-1-robin.roevens@disroot.org> Mime-Version: 1.0 X-sicho-MailScanner-ID: F2C81751F4.A8A80 X-sicho-MailScanner: Found to be clean X-sicho-MailScanner-From: robin.roevens@disroot.org X-sicho-MailScanner-Watermark: 1666130530.91022@YqXNQAJJcSA960NnnXQ+Vg ARC-Seal: i=1; s=202003rsa; d=lists.ipfire.org; t=1665525802; a=rsa-sha256; cv=none; b=o+XZ7Yb2cWHyzeF0aIJKzXK53GhJQwQJDnmEastSw5h7wqORAMDLB00fF6kd578rl+d/1Y IW/wrPgoORGXBQq+5hHYUUwtcXq6qpaOe44w4/80qHae9NOaPZa0/kvQDPUZAMCPLIFaqq YaIEVsFtqhFr1MnlWYFXriaUsUsJ7xKDslmu+8uEQpOQM/V78Wu6/4QSSX3V3S9afg9vHT EIgSgjF9px6NGGTjrMs7TeEpXaA7BGcvupamJZ9N0C7PD7Gtn8wPQzVQkhZua0z13SjOXN FZXIpKt6ubCXrVODnuZDxj94WK4aOmlynBj1vVJMkWreboPMi/3Z71Ym18rvmg== ARC-Authentication-Results: i=1; mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=h1OnDxXF; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org; dmarc=pass (policy=quarantine) header.from=disroot.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=lists.ipfire.org; s=202003rsa; t=1665525802; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Ac48KXQ5M8yw6OVWDjJcLBVLTpyM7FeRFwTNgLoSLbg=; b=Z9ONjetXhne0IMSasMD2MjBuIHAEMKxQrvlKBJnEZF2ktsoiGwJVYWyRWOlrxjAu/MiLSJ GUCd6o88xW9TrnlMWL92pvYl8Vid45uUU89iNF8leOzlSRuK1f+uYCkzi4FmUJ+owcYBX/ Sy1CBF0ttewQn4fwmpAh3JPTgUn9hiU8++DY/X4/osOw8W0AF95Zmcy4WVq4yVZgYJe3OX zb3tDg8QBHtdLqDAp3A8SuOai9J2SqGqYlHOi5TDjJIYYCOkz2Q3KmlEO61pWSsnnwdg+Z PDO2L8zT1FgZxjm23tMOK/8oW9b0X0ks8Gqn7K9DA+J4eYYbiJifwYYSLoCNRQ== Authentication-Results: mail01.ipfire.org; dkim=pass header.d=disroot.org header.s=mail header.b=h1OnDxXF; spf=pass (mail01.ipfire.org: domain of robin.roevens@disroot.org designates 178.21.23.139 as permitted sender) smtp.mailfrom=robin.roevens@disroot.org; dmarc=pass (policy=quarantine) header.from=disroot.org X-Rspamd-Server: mail01.haj.ipfire.org X-Spamd-Result: default: False [-5.32 / 11.00]; BAYES_HAM(-3.00)[99.99%]; IP_REPUTATION_HAM(-1.14)[asn: 50673(-0.32), country: NL(-0.01), ip: 178.21.23.139(-0.81)]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM(-1.00)[-1.000]; DKIM_REPUTATION(-0.82)[-0.82134715129011]; SPF_REPUTATION_HAM(-0.61)[-0.61440594065069]; DMARC_POLICY_ALLOW(-0.50)[disroot.org,quarantine]; MV_CASE(0.50)[]; R_DKIM_ALLOW(0.27)[disroot.org:s=mail]; MIME_HTML_ONLY(0.20)[]; R_SPF_ALLOW(-0.20)[+a:c]; MX_GOOD(-0.01)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; ARC_NA(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[development@lists.ipfire.org]; FROM_EQ_ENVFROM(0.00)[]; RCVD_TLS_LAST(0.00)[]; RCVD_COUNT_THREE(0.00)[4]; ARC_SIGNED(0.00)[lists.ipfire.org:s=202003rsa:i=1]; ASN(0.00)[asn:50673, ipnet:178.21.23.0/24, country:NL]; DKIM_TRACE(0.00)[disroot.org:+]; RCPT_COUNT_TWO(0.00)[2]; SUBJECT_HAS_EXCLAIM(0.00)[]; MIME_TRACE(0.00)[0:~]; TO_DN_SOME(0.00)[] X-Rspamd-Queue-Id: 4Mn8tK72b1z2Mm X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" * addonctrl's new functionality to control explicit addon services was implemented. * Change 'Addon' column header to 'Addon Service' to be clear that it's not addons but services listed here. * Services not matching the name of the addon now display the addon name between parentheses, so the user knows where the service comes from. * When no valid runlevel symlink is found by addonctrl for a service, the 'enable on boot' checkbox is replaced by a small exclamation point with alt-text "No valid runlevel symlink was found for the initscript of this service." to inform user why a service can't be enabled. * Added German and Dutch translation for above message. Fixes: Bug#12935 Signed-off-by: Robin Roevens Reviewed-by: Michael Tremer --- html/cgi-bin/services.cgi | 114 ++++++++++++++++---------------------- langs/de/cgi-bin/de.pl | 1 + langs/en/cgi-bin/en.pl | 1 + langs/nl/cgi-bin/nl.pl | 1 + 4 files changed, 51 insertions(+), 66 deletions(-) diff --git a/html/cgi-bin/services.cgi b/html/cgi-bin/services.cgi index 29926ecc3..de946d755 100644 --- a/html/cgi-bin/services.cgi +++ b/html/cgi-bin/services.cgi @@ -20,7 +20,7 @@ ############################################################################### use strict; - +use feature "switch"; # enable only the following on debugging purpose #use warnings; #use CGI::Carp 'fatalsToBrowser'; @@ -141,15 +141,22 @@ END &Header::openbox('100%', 'left', "Addon - $Lang::tr{services}"); my $paramstr=$ENV{QUERY_STRING}; my @param=split(/!/, $paramstr); - if ($param[1] ne ''){ - &General::system("/usr/local/bin/addonctrl", "$param[0]", "$param[1]"); + # Make sure action parameter is actually one of the allowed service actions + given ($param[1]) { + when ( ['start', 'stop', 'enable', 'disable'] ) { + # Make sure pak-name and service name don't contain any illegal character + if ( $param[0] !~ /[^a-zA-Z_0-9\-]/ && + $param[2] !~ /[^a-zA-Z_0-9\-]/ ) { + &General::system("/usr/local/bin/addonctrl", "$param[0]", "$param[1]", "$param[2]"); + } + } } print < - + @@ -170,33 +177,35 @@ END foreach my $pak (keys %paklist) { my %metadata = &Pakfire::getmetadata($pak, "installed"); + my $service; + if ("$metadata{'Services'}") { - foreach my $service (split(/ /, "$metadata{'Services'}")) { - push(@addon_services, $service); - } - } - } + foreach $service (split(/ /, "$metadata{'Services'}")) { + $lines++; + if ($lines % 2) { + print ""; + $col="bgcolor='$color{'color22'}'"; + } else { + print ""; + $col="bgcolor='$color{'color20'}'"; + } - foreach (@addon_services) { - $lines++; - if ($lines % 2){ - print ""; - $col="bgcolor='$color{'color22'}'"; - }else{ - print ""; - $col="bgcolor='$color{'color20'}'"; + # Add addon name to displayname of service if servicename differs from addon + my $displayname = ($pak ne $service) ? "$service ($pak)" : $service; + print " "; + + my $status = isautorun($pak,$service,$col); + print "$status "; + print ""; + print " "; + my $status = isrunningaddon($pak,$service,$col); + $status =~ s/\\[[0-1]\;[0-9]+m//g; + + chomp($status); + print "$status"; + print ""; + } } - print " "; - my $status = isautorun($_,$col); - print "$status "; - print ""; - print " "; - my $status = isrunningaddon($_,$col); - $status =~ s/\\[[0-1]\;[0-9]+m//g; - - chomp($status); - print "$status"; - print ""; } print "
AddonAddon $Lang::tr{service} Boot $Lang::tr{'action'} $Lang::tr{'status'}
$displayname$Lang::tr{$Lang::tr{
$_$Lang::tr{$Lang::tr{
\n"; @@ -215,51 +224,24 @@ END } sub isautorun (@) { - my ($cmd, $col) = @_; - - # Init directory. - my $initdir = "/etc/rc.d/rc3.d/"; - - my $status = ""; + my ($pak, $service, $col) = @_; + my @testcmd = &General::system_output("/usr/local/bin/addonctrl", "$pak", "boot-status", "$service"); + my $testcmd = @testcmd[0]; + my $status = "$Lang::tr{"; - # Check if autorun for the given cmd is enabled. - if ( &find_init("$cmd", "$initdir") ) { + # Check if autorun for the given service is enabled. + if ( $testcmd =~ /enabled\ on\ boot/ ) { # Adjust status. - $status = "$Lang::tr{"; - } else { + $status = "$Lang::tr{"; + } elsif ( $testcmd =~ /disabled\ on\ boot/ ) { # Adjust status. - $status = "$Lang::tr{"; + $status = "$Lang::tr{"; } # Return the status. return $status; } -sub find_init (@) { - my ($cmd, $dir) = @_; - - # Open given init directory. - opendir (INITDIR, "$dir") || die "Cannot opendir $dir: $!"; - - # Read-in init files from directory. - my @inits = readdir(INITDIR); - - # Close directory handle. - closedir(INITDIR); - - # Loop through the directory. - foreach my $init (@inits) { - # Check if the current processed file belongs to the given command. - if ($init =~ /S\d+\d+$cmd\z/) { - # Found, return "1" - True. - return "1"; - } - } - - # Nothing found, return nothing. - return; -} - sub isrunning (@) { my ($cmd, $col) = @_; my $status = "$Lang::tr{'stopped'}"; @@ -313,7 +295,7 @@ sub isrunning (@) { } sub isrunningaddon (@) { - my ($cmd, $col) = @_; + my ($pak, $service, $col) = @_; my $status = "$Lang::tr{'stopped'}"; my $pid = ''; @@ -321,7 +303,7 @@ sub isrunningaddon (@) { my $exename; my @memory; - my @testcmd = &General::system_output("/usr/local/bin/addonctrl", "$cmd", "status"); + my @testcmd = &General::system_output("/usr/local/bin/addonctrl", "$pak", "status", "$service"); my $testcmd = @testcmd[0]; if ( $testcmd =~ /is\ running/ && $testcmd !~ /is\ not\ running/){ diff --git a/langs/de/cgi-bin/de.pl b/langs/de/cgi-bin/de.pl index 798abcffc..db7d117b0 100644 --- a/langs/de/cgi-bin/de.pl +++ b/langs/de/cgi-bin/de.pl @@ -2251,6 +2251,7 @@ 'server string' => 'Server String', 'service' => 'Dienst', 'service added' => 'Benutzerdefinierter Netzwerkdienst wurde hinzugefügt', +'service boot setting unavailable' => 'Für das Initscript dieses Dienstes wurde kein gültiger Runlevel-Symlink gefunden.', 'service name' => 'Name des Dienstes:', 'service removed' => 'Benutzerdefinierter Netzwerkdienst wurde entfernt', 'service updated' => 'Benutzerdefinierter Netzwerkdienst wurde aktualisiert', diff --git a/langs/en/cgi-bin/en.pl b/langs/en/cgi-bin/en.pl index f770e7cd9..60dca5be4 100644 --- a/langs/en/cgi-bin/en.pl +++ b/langs/en/cgi-bin/en.pl @@ -2306,6 +2306,7 @@ 'server string' => 'Server String', 'service' => 'Service', 'service added' => 'Custom network service added', +'service boot setting unavailable' => 'No valid runlevel symlink was found for the initscript of this service.', 'service name' => 'Service name:', 'service removed' => 'Custom network service removed', 'service updated' => 'Custom network service updated', diff --git a/langs/nl/cgi-bin/nl.pl b/langs/nl/cgi-bin/nl.pl index 49dabec99..4fd6955cc 100644 --- a/langs/nl/cgi-bin/nl.pl +++ b/langs/nl/cgi-bin/nl.pl @@ -1899,6 +1899,7 @@ 'server string' => 'Server String', 'service' => 'Dienst', 'service added' => 'Aangepaste netwerkdienst toegevoegd', +'service boot setting unavailable' => 'Er werd voor het initscript van deze service geen geldige runlevel symlink gevonden.', 'service name' => 'Dienstennaam:', 'service removed' => 'Aangepaste netwerkdienst verwijderd', 'service updated' => 'Aangepaste netwerkdienst bijgewerkt',