From face8319f2dcec6c9ffcf0a4c3c588143b8a6d1b Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sat, 4 Oct 2025 00:45:21 +0300 Subject: [PATCH 1/2] Fix to safely kill only targeted scripts --- setup.pl | 10 ++++++++-- setup.sh | 10 ++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/setup.pl b/setup.pl index 6ee5bc909..a3eadb9a4 100755 --- a/setup.pl +++ b/setup.pl @@ -616,11 +616,17 @@ else { print STOP "else\n"; print STOP " echo Stopping Webmin server in $wadir\n"; print STOP "fi\n"; - print STOP "pids=\`ps axww -o pid= -o command= | awk -v wd=\"$wadir/\" '\$0 ~ wd && \$0 !~ /miniserv\\.pl/ {print \$1}'\`\n"; + print STOP "targets=\"stats.pl shellserver.pl\"\n"; + print STOP "collect_pids() {\n"; + print STOP " for s in \$targets; do\n"; + print STOP " ps axww | grep \"$wadir/\" | grep \"/\$s\" | grep -v grep\n"; + print STOP " done | awk '{print \$1}' | sort -u\n"; + print STOP "}\n"; + print STOP "pids=\$(collect_pids)\n"; print STOP "[ -n \"\$pids\" ] && kill \$pids 2>/dev/null || true\n"; print STOP "if [ \"\$1\" = \"--kill\" ]; then\n"; print STOP " sleep 1\n"; - print STOP " pids=\`ps axww -o pid= -o command= | awk -v wd=\"$wadir/\" '\$0 ~ wd && \$0 !~ /miniserv\\.pl/ {print \$1}'\`\n"; + print STOP " pids=\$(collect_pids)\n"; print STOP " [ -n \"\$pids\" ] && kill -KILL \$pids 2>/dev/null || true\n"; print STOP "fi\n"; print STOP "pidfile=\`grep \"^pidfile=\" $config_directory/miniserv.conf | sed -e 's/pidfile=//g'\`\n"; diff --git a/setup.sh b/setup.sh index ea9311839..b03a92608 100755 --- a/setup.sh +++ b/setup.sh @@ -695,11 +695,17 @@ echo " echo Force stopping Webmin server in $wadir" >>$config_dir/.stop-init echo "else" >>$config_dir/.stop-init echo " echo Stopping Webmin server in $wadir" >>$config_dir/.stop-init echo "fi" >>$config_dir/.stop-init -echo "pids=\`ps axww -o pid= -o command= | awk -v wd=\"$wadir/\" '\$0 ~ wd && \$0 !~ /miniserv\\.pl/ {print \$1}'\`" >>$config_dir/.stop-init +echo "targets=\"stats.pl shellserver.pl\"" >>$config_dir/.stop-init +echo "collect_pids() {" >>$config_dir/.stop-init +echo " for s in \$targets; do" >>$config_dir/.stop-init +echo " ps axww | grep \"$wadir/\" | grep \"/\$s\" | grep -v grep" >>$config_dir/.stop-init +echo " done | awk '{print \$1}' | sort -u" >>$config_dir/.stop-init +echo "}" >>$config_dir/.stop-init +echo "pids=\$(collect_pids)" >>$config_dir/.stop-init echo "[ -n \"\$pids\" ] && kill \$pids 2>/dev/null || true" >>$config_dir/.stop-init echo "if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/.stop-init echo " sleep 1" >>$config_dir/.stop-init -echo " pids=\`ps axww -o pid= -o command= | awk -v wd=\"$wadir/\" '\$0 ~ wd && \$0 !~ /miniserv\\.pl/ {print \$1}'\`" >>$config_dir/.stop-init +echo " pids=\$(collect_pids)" >>$config_dir/.stop-init echo " [ -n \"\$pids\" ] && kill -KILL \$pids 2>/dev/null || true" >>$config_dir/.stop-init echo "fi" >>$config_dir/.stop-init echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/.stop-init From 28c7939636f259cb3fcbcabe4c6b434b9b958a56 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sat, 4 Oct 2025 01:12:05 +0300 Subject: [PATCH 2/2] Fix to check if helper command is running as root --- bin/webmin | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bin/webmin b/bin/webmin index 83fc14532..35ba4813f 100755 --- a/bin/webmin +++ b/bin/webmin @@ -9,6 +9,13 @@ use Getopt::Long qw(:config permute pass_through); use Term::ANSIColor qw(:constants); use Pod::Usage; +# Check if root +if ($> != 0) { + die BRIGHT_RED, "Error: ", RESET, BRIGHT_YELLOW,"webmin", RESET, + " command must be run as root\n"; + exit 1; + } + my $a0 = $ARGV[0]; sub main {