Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Page to kill all user's processes?

Discussion in 'cPanel Developers' started by electric, Oct 6, 2017.

Tags:
  1. electric

    electric Well-Known Member

    Joined:
    Nov 5, 2001
    Messages:
    727
    Likes Received:
    3
    Trophy Points:
    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?
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    38,658
    Likes Received:
    1,424
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    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.
     
Loading...

Share This Page