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!

[Script] Suspend website access ONLY

Discussion in 'General Discussion' started by stdout, Nov 26, 2008.

  1. stdout

    stdout Well-Known Member

    Joined:
    Apr 10, 2003
    Messages:
    189
    Likes Received:
    6
    Trophy Points:
    168
    Location:
    Nelspruit, Mpumalanga, South Africa
    cPanel Access Level:
    Root Administrator
    Do you have a user abusing resources? Need him disabled but don't want to interrupt his mail/ftp services?
    Then "websuspend" is for you. This script ONLY suspends website access, allowing the offending user to correct his script through FTP or the Filemanager. Unlike "/scripts/suspendacct", it's a lot more friendlier towards the clients.

    There's no point suspending a customer completely because of a bug in his script, instead simply shut down his website!

    This script logs to ~/suspend.log allowing techs to know when the suspension occurred and for what reason.

    Here's a sample of the script's output.

    Here is the script:

    This is for "suspend" - copy it to /usr/bin or /root.
    Code:
    #!/usr/bin/perl
    
    my $suspendlog = "/root/suspend.log";
    my $syshostname = $ENV{'HOSTNAME'};
    my $currtime = localtime(time);
    
    if ($ARGV[0] ne "") {
     $userinfo = `grep $ARGV[0] /etc/passwd`;
     ($username,undef,undef,undef,undef,$homedir) = split(/:/,$userinfo);
     $domain = `grep DNS= /var/cpanel/users/$username | cut -d= -f2`;
     chomp($domain);
     foreach $argnum (1 .. $#ARGV) { $susreason .= $ARGV[$argnum] ." ";  }
    
     if ($susreason eq "") { $susreason = "no reason specified\n"; }
     if (($username ne "" && $homedir ne "")) { &suspend(); }
    }
    else { print "syntax: ./suspend <username> <suspension reason>\n"; }
    
    sub suspend() {
      system("mv $homedir/public_html/.htaccess $homedir/public_html/.htaccess.suspend 2> /dev/null");
    
      open(NEWHTACCESS,">> $homedir/public_html/.htaccess");
       print NEWHTACCESS "RedirectMatch .* http://$syshostname/suspended.page/\nOptions -Includes -Indexes -ExecCGI\n\n";
      close(NEWHTACCESS);
    
      open(SUSPENDLOG,">>$suspendlog");
       print SUSPENDLOG "$currtime - account $username ($domain) suspended with reason: $susreason\n";
      close(SUSPENDLOG);
    
      print "suspended website access on $domain ($username) with reason: $susreason\n";
    }
    This is for "unsuspend" - copy it to /usr/bin or /root.
    Code:
    #!/usr/bin/perl
    
    my $suspendlog = "/root/suspend.log";
    my $currtime = localtime(time);
    
    if ($ARGV[0] ne "") {
     $userinfo = `grep $ARGV[0] /etc/passwd`;
     ($username,undef,undef,undef,undef,$homedir) = split(/:/,$userinfo);
    
     if (($username ne "" && $homedir ne "")) { &unsuspend(); }
    }
    else { print "syntax: ./unsuspend <username>\n"; }
    
    sub unsuspend() {
      system("rm -f $homedir/public_html/.htaccess 2> /dev/null");
      system("mv $homedir/public_html/.htaccess.suspend $homedir/public_html/.htaccess 2> /dev/null");
    
      open(SUSPENDLOG,">>$suspendlog");
       print SUSPENDLOG "$currtime - account $username has been unsuspended\n";
      close(SUSPENDLOG);
    
      print "the account $username has been unsuspended\n";
    }
    Spot a bug? Let me know!
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. jasonhk

    jasonhk Well-Known Member

    Joined:
    Nov 11, 2005
    Messages:
    48
    Likes Received:
    0
    Trophy Points:
    156
    Hey Dylan

    Just a little change to give users a better suspended message..

    I made a new /usr/local/apache/htdocs/resource.suspend. It's basically a copy of the /usr/local/apache/htdocs/suspended.page

    Just changed the wording to show:

    "This account Has Been suspended due to server resource overusage
    Mail and FTP will still function. Please correct your script, upload via FTP and contact support to reactive your website. "

    You will just need to change the redirect in the htacccess of the suspend script :)
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice