Page to kill all user's processes?

electric

Well-Known Member
Nov 5, 2001
785
9
318
Hello,

We are trying to create a cpanel page that the user can run to kill all their running processes.

First, here is what we have to show all the user's currently running processes:

PHP:
<?php
include("/usr/local/cpanel/php/cpanel.php");
$cpanel = new CPANEL();
print $cpanel->header( "Show Current Processes" );
?>
<div class="container">

<?php
$user = exec('whoami');

    echo "<pre>";
$cmd = "ps -U ".$user." -u ".$user." --format pid,vsz,pmem,pcpu,start_time,etime,cmd";
system($cmd);
     echo "</pre>";
?>

</div>

<?php
print $cpanel->footer();
$cpanel->end();
?>
We put that into a "test.live.php" file, and it works when called directly from the user's cpanel. (Just manually type it into the browser URL bar.)

But then we want to give the user the ability to kill their own account's processes, so we created this... which does NOT work:

PHP:
<?php
$user = exec('whoami');

if (isset($_GET["task"]) && ($_GET["task"] == "killall"))  {
     $cmd = "killall --user " . $user;
     //$cmd = "pkill -U " . $user;
      echo  $cmd;
    echo "<div class='row'>";
     echo "All running processes for your hosting account have been terminated.";
     echo "</div>";
     echo "<div class='row'><br /><br /><br /><br /></div>";
     echo "<div class='row'>";
     echo '<a href="test.live.php">Show all currently running processes for your web hosting account.</a>';
     echo "</div>";
     exec($cmd);
}
?>

</div>

<?php
print $cpanel->footer();
$cpanel->end();
?>
It seems the "exec($cmd);" code does not properly execute. We've tried system() and passthru(), but neither of those work either.

Any ideas how to make this work, so the user can kill their own processes?
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,908
2,218
463
Hello,

The issue with killing all processes associated with the user is that it's going to kill the cPanel process associated with the request to the page. This will lead to an error message such as:

Code:
Child failed to make LIVEAPI connection to cPanel.
Can you try updating the second script so that ignores the cPanel related processes (e.g. processes starting with cpaneld, /usr/local/cpanel/3rdparty/php/56/bin/php-cgi, or /usr/local/cpanel/cpanel)?

Thank you.