qadelq
asked on
unsuspend/suspend
hi
how do i suspend an account using a script php ?
i want to change the paramater $suspenduser with the name of account $accdomain in suspend($host,$user,$acces shash,$use ssl,$suspe nduser) in the file accounting.php.inc
for exmple :
$host="localhost";
$user"user";
$accesshash="accesshash";
$suspenduser="user.mysite. com";
In whm you can choose betwen th name of the account or the user, so i want to use th account
any idea is good
how do i suspend an account using a script php ?
i want to change the paramater $suspenduser with the name of account $accdomain in suspend($host,$user,$acces
for exmple :
$host="localhost";
$user"user";
$accesshash="accesshash";
$suspenduser="user.mysite.
In whm you can choose betwen th name of the account or the user, so i want to use th account
any idea is good
ASKER
i think that you dont indrstand me
ok
if you look at suspend/unsuspend account page in whm there are two optoins to suspend an account one by domain and an other by users.
i have a script suspending account by users in accounting.php.inc file:
<?php
global $cpanelaccterr;
function suspend ($host,$user,$accesshash,$ usessl,$su spenduser) {
$result = whmreq("/scripts/remote_su spend?user =${suspend user}",$ho st,$user,$ accesshash ,$usessl);
if ($cpanelaccterr != "") { return; }
return $result;
}
function unsuspend ($host,$user,$accesshash,$ usessl,$su spenduser) {
$result = whmreq("/scripts/remote_un suspend?us er=${suspe nduser}",$ host,$user ,$accessha sh,$usessl );
if ($cpanelaccterr != "") { return; }
return $result;
}
function whmreq ($request,$host,$user,$acc esshash,$u sessl) {
$cleanaccesshash = preg_replace("'(\r|\n)'"," ",$accessh ash);
$authstr = $user . ":" . $cleanaccesshash;
$cpanelaccterr = "";
if (function_exists("curl_ini t")) {
$ch = curl_init();
if ($usessl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_URL, "https://${host}:2087" . $request);
} else {
curl_setopt($ch, CURLOPT_URL, "http://${host}:2086" . $request);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$curlheaders[0] = "Authorization: WHM $authstr";
curl_setopt($ch,CURLOPT_HT TPHEADER,$ curlheader s);
$data=curl_exec ($ch);
curl_close ($ch);
} elseif (function_exists("socket_c reate")) {
if ($usessl) {
$cpanelaccterr = "SSL Support requires curl";
return;
}
$service_port = 2086;
$address = gethostbyname($host);
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
$cpanelaccterr = "socket_create() failed";
return;
}
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
$cpanelaccterr = "socket_connect() failed";
return;
}
$in = "GET $request HTTP/1.0\n";
socket_write($socket,$in,s trlen($in) );
$in = "Connection: close\n";
socket_write($socket,$in,s trlen($in) );
$in = "Authorization: WHM $authstr\n\n\n";
socket_write($socket,$in,s trlen($in) );
$inheader = 1;
while(($buf = socket_read($socket, 512)) != false) {
if (!$inheader) {
$data .= $buf;
}
if(preg_match("'\r\n\r\n$' s", $buf)) {
$inheader = 0;
}
if(preg_match("'\n\n$'s", $buf)) {
$inheader = 0;
}
if(preg_match("'\r\n$'s", $buf)) {
$inheader = 0;
}
}
} else {
$cpanelaccterr = "php not compiled with --enable-sockets OR curl";
return;
}
return $data;
}
$host = "localhost";
$user = "myuser";
$accesshash = 'myaccesshash';
// new account
$acctdomain ='user.mysite.com';
$suspenduser = "accuser";
$acctpass = 'pwd';
$acctplan = 'pkg'; // see Accounting.php.inc what should be in here
$spd=suspend ($host,$user,$accesshash,$ usessl,$su spenduser)
?>
when i execute this script the account "user.mysite.com" appear in the list suspended accounts in whm, but i want to replace $suspenduser by $acctdomain
thanks
ok
if you look at suspend/unsuspend account page in whm there are two optoins to suspend an account one by domain and an other by users.
i have a script suspending account by users in accounting.php.inc file:
<?php
global $cpanelaccterr;
function suspend ($host,$user,$accesshash,$
$result = whmreq("/scripts/remote_su
if ($cpanelaccterr != "") { return; }
return $result;
}
function unsuspend ($host,$user,$accesshash,$
$result = whmreq("/scripts/remote_un
if ($cpanelaccterr != "") { return; }
return $result;
}
function whmreq ($request,$host,$user,$acc
$cleanaccesshash = preg_replace("'(\r|\n)'","
$authstr = $user . ":" . $cleanaccesshash;
$cpanelaccterr = "";
if (function_exists("curl_ini
$ch = curl_init();
if ($usessl) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($ch, CURLOPT_URL, "https://${host}:2087" . $request);
} else {
curl_setopt($ch, CURLOPT_URL, "http://${host}:2086" . $request);
}
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$curlheaders[0] = "Authorization: WHM $authstr";
curl_setopt($ch,CURLOPT_HT
$data=curl_exec ($ch);
curl_close ($ch);
} elseif (function_exists("socket_c
if ($usessl) {
$cpanelaccterr = "SSL Support requires curl";
return;
}
$service_port = 2086;
$address = gethostbyname($host);
$socket = socket_create (AF_INET, SOCK_STREAM, 0);
if ($socket < 0) {
$cpanelaccterr = "socket_create() failed";
return;
}
$result = socket_connect ($socket, $address, $service_port);
if ($result < 0) {
$cpanelaccterr = "socket_connect() failed";
return;
}
$in = "GET $request HTTP/1.0\n";
socket_write($socket,$in,s
$in = "Connection: close\n";
socket_write($socket,$in,s
$in = "Authorization: WHM $authstr\n\n\n";
socket_write($socket,$in,s
$inheader = 1;
while(($buf = socket_read($socket, 512)) != false) {
if (!$inheader) {
$data .= $buf;
}
if(preg_match("'\r\n\r\n$'
$inheader = 0;
}
if(preg_match("'\n\n$'s", $buf)) {
$inheader = 0;
}
if(preg_match("'\r\n$'s", $buf)) {
$inheader = 0;
}
}
} else {
$cpanelaccterr = "php not compiled with --enable-sockets OR curl";
return;
}
return $data;
}
$host = "localhost";
$user = "myuser";
$accesshash = 'myaccesshash';
// new account
$acctdomain ='user.mysite.com';
$suspenduser = "accuser";
$acctpass = 'pwd';
$acctplan = 'pkg'; // see Accounting.php.inc what should be in here
$spd=suspend ($host,$user,$accesshash,$
?>
when i execute this script the account "user.mysite.com" appear in the list suspended accounts in whm, but i want to replace $suspenduser by $acctdomain
thanks
Sorry. I thought whm was a mistype.
I'm not a CPanel expert, so can you please explain the difference between the user and the domain? I though they are the same thing in this regard?
I'm not a CPanel expert, so can you please explain the difference between the user and the domain? I though they are the same thing in this regard?
ASKER
thanks for your replay
I when create new acount in whm , the requirment 1- user ( username) 2- domain ( yuordomain.com) , but I when want to suspend or terminat , the whm requirment the user in order to terminate or suspend the acount (please note the example above) , therefore I want susped or termenate the acount depnded on the acctdomain ( domain) .
I when create new acount in whm , the requirment 1- user ( username) 2- domain ( yuordomain.com) , but I when want to suspend or terminat , the whm requirment the user in order to terminate or suspend the acount (please note the example above) , therefore I want susped or termenate the acount depnded on the acctdomain ( domain) .
Is the user uniquely tied to the domain?
Having looked at the code you supplied, you need to take a look at
/scripts/remote_suspend
and
/scripts/remote_unsuspend
These are the scripts which do the suspending and unsuspending. I don't know if they are PHP or not. They expect a user parameter. They may accept a domain parameter.
Having looked at the code you supplied, you need to take a look at
/scripts/remote_suspend
and
/scripts/remote_unsuspend
These are the scripts which do the suspending and unsuspending. I don't know if they are PHP or not. They expect a user parameter. They may accept a domain parameter.
ASKER
please explain
The code you supplied doesn't actually make the required changes to the status. Instead it calls 1 of 2 scripts ...
scripts/remote_suspend
from
$result = whmreq("/scripts/remote_su spend?user =${suspend user}",$ho st,$user,$ accesshash ,$usessl);
and
scripts_remote_unsuspend
from
$result = whmreq("/scripts/remote_un suspend?us er=${suspe nduser}",$ host,$user ,$accessha sh,$usessl );
As you can see the parameters are all user orientated, but the scripts themselves may well support domain.
You will need to see if they do. Can you supply those scripts here?
scripts/remote_suspend
from
$result = whmreq("/scripts/remote_su
and
scripts_remote_unsuspend
from
$result = whmreq("/scripts/remote_un
As you can see the parameters are all user orientated, but the scripts themselves may well support domain.
You will need to see if they do. Can you supply those scripts here?
ASKER
ok
1- suspendacct
#!/usr/bin/perl
# cpanel9 - scripts Copyright(c) 1997-2004 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited
BEGIN {
push(@INC,'/scripts');
}
use cPScript::SafetyBits;
use cPScript::iContact qw( );
use SafeFile;
use AcctLock;
use POSIX;
my $system = (POSIX::uname())[0];
$user = $ARGV[0];
$reason = $ARGV[1];
$disallowun = $ARGV[2];
if ($user eq "" || $user eq "root") {
print "Syntax Error: usage: suspendacct <user>\n";
exit;
}
my $homedir = gethomedir($user);
my $shell = getshell($user);
print "Changing Shell to /bin/false...";
system("chsh","-s","/bin/f alse","$us er");
print "Done\n";
AcctLock::acctlock();
print "Locking Password...";
if (-e "/usr/sbin/pw") {
system("/usr/sbin/pw","loc k","$user" );
} else {
system("passwd","-l","$use r");
}
print "Done\n";
AcctLock::acctunlock();
$owner = getowner($user);
$owner =~ s/\n//g;
if ($owner eq "" || $owner eq "root" || $user eq $owner) {
chomp($host = `hostname`);
} else {
$host = getdomain($owner);
}
$domain = getdomain($user);
if (! -e "/var/cpanel/suspended") {
mkdir("/var/cpanel/suspend ed",0755);
}
open(USERS,">/var/cpanel/s uspended/$ {user}");
print USERS $reason;
close(USERS);
if ($disallowun eq "1") {
open(USERS,">/var/cpanel/s uspended/$ {user}.loc k");
close(USERS);
}
if ($system =~ /freebsd/i) {
system("killall","-9","-u" ,"$user"," -m",".");
} else {
system("skill","-9","$user ");
}
open(CPU,"/var/cpanel/user s/${user}" );
while(<CPU>) {
if (/^DNS.?.?.?.?=(\S+)/) {
push(@DNS,$1);
}
}
close(CPU);
mkdir("/usr/local/cpanel/3 rdparty/ma ilman/susp ended.list s",0755);
foreach my $dns (@DNS) {
$dns = makevaliddns($dns);
next if ($dns eq "-1");
system("mv /usr/local/cpanel/3rdparty /mailman/l ists/*_$dn s /usr/local/cpanel/3rdparty /mailman/s uspended.l ists 2>/dev/null");
if (-f "${homedir}/etc/${dns}/sha dow" && ! -l "${homedir}/etc/${dns}/sha dow") {
print "Suspending email account logins for ${dns} .... ";
suspendshadowfile("${homed ir}/etc/${ dns}/shado w");
print "Done\n";
}
}
$msg = <<"EOM";
+========================= ========== +
| Account Info |
+========================= ========== +
| Domain: $domain
| UserName: $user
+========================= ========== +
Account suspended by $ENV{'REMOTE_USER'} ($ENV{'USER'})
EOM
cPScript::iContact::iconta ct('applic ation' => 'suspendacct',
'level' => 3,
'subject' => qq{Account Suspended on $host ($domain)},
'message' => $msg,
'msgtype' => '');
if ($shell eq "/bin/false") {
print "Account Already Suspended\n";
exit;
}
if (! -e "/var/cpanel/suspendinfo") {
mkdir("/var/cpanel/suspend info",0700 );
}
open(CPINFO,">","/var/cpan el/suspend info/${use r}");
print CPINFO "shell=${shell}\n";
close(CPINFO);
open(CPU,">>/var/cpanel/us ers/${user }");
my $now = time();
print CPU "SUSPENDTIME=$now\n";
close(CPU);
if (! -e "/var/spool/cron.suspended ") {
mkdir("/var/spool/cron.sus pended",07 00);
}
if (-f "/var/spool/cron/${user}") {
link("/var/spool/cron/${us er}",
"/var/spool/cron.suspended /${user}") ;
unlink("/var/spool/cron/${ user}");
}
cPScript::SafetyBits::safe _chmod(000 0,$user,"$ {homedir}/ public_ftp ");
rename("$homedir/public_ht ml/.htacce ss","$home dir/public _html/.hta ccess.susp end");
unlink("$homedir/public_ht ml/.htacce ss");
open(HTACCESS,">>$homedir/ public_htm l/.htacces s");
print HTACCESS "RedirectMatch .* http://${host}/suspended.page/\n";
print HTACCESS "Options -Includes -Indexes -ExecCGI\n";
close(HTACCESS);
system("sync");
my $ftpfile = "/etc/proftpd/$user";
if(-e $ftpfile && -e "/var/cpanel/suspended/$us er") {
print "Suspending FTP accounts...\n";
rename($ftpfile, "$ftpfile.suspended")
or warn "Could not rename $ftpfile to $ftpfile.suspended";
}
system("/usr/local/cpanel/ bin/ftpupd ate",$user );
system '/usr/local/cpanel/bin/upd ateauthtab ';
print ${user} . "'s account has been suspended\n";
sub gethomedir {
my($user) = @_;
my($homedir);
open(PASSWD,"/etc/passwd") ;
while(<PASSWD>) {
if (/^$user:/) {
(undef,undef,undef,undef,u ndef,$home dir,undef) = split(/:/, $_, 7);
return $homedir;
}
}
close(PASSWD);
}
sub getshell {
my($user) = @_;
my($shell);
open(PASSWD,"/etc/passwd") ;
while(<PASSWD>) {
s/\n//g;
if (/^$user:/) {
(undef,undef,undef,undef,u ndef,undef ,$shell) = split(/:/, $_, 7);
return $shell;
}
}
close(PASSWD);
}
sub getowner {
my($user) = @_;
my($owner);
open(CPUO,"/var/cpanel/use rs/$user") || return 'root';
while(<CPUO>) {
s/\n//g;
if (/^OWNER=(\S+)/) {
$owner = $1;
}
}
close(CPUO);
if ($owner eq "" || $owner eq "0") { $owner = 'root'; }
return($owner);
}
sub getdomain {
my($user) = $_[0];
open(CPU,"/var/cpanel/user s/$user");
while(<CPU>) {
s/\n//g;
if (/^DNS=(\S+)/) {
close(CPU);
return $1;
}
}
close(CPU);
return "";
}
sub makevaliddns {
my($domain) = @_;
$domain =~ s/[^\w\.\-]*[_]*//g;
if (length($domain) < 3) {
return(-1);
}
if ($domain =~ /^\./) {
return(-1);
}
return($domain);
}
sub suspendshadowfile {
my($file) = @_;
my($shadowlock);
$shadowlock = SafeFile::safeopen(\*SHF," <",$file);
my @CT = <SHF>;
SafeFile::safeclose(\*SHF, $shadowloc k);
$shadowlock = SafeFile::safeopen(\*SHF," >",$file);
foreach (@CT) {
my @DC=split(/:/,$_);
chomp($DC[$#DC]);
if ($DC[1] !~ /^\*LOCKED\*/) {
$DC[1] = "*LOCKED*" . $DC[1];
}
print SHF join(":",@DC) . "\n";
}
SafeFile::safeclose(\*SHF, $shadowloc k);
}
========================== ========== ========== ==
========================== ========== ========== ====
2- unsuspendacct
#!/usr/bin/perl
# cpanel9 - scripts Copyright(c) 1997-2004 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited
BEGIN {
push(@INC,"/scripts");
}
use cPScript::SafetyBits;
use cPScript::iContact qw( );
use SafeFile;
use AcctLock;
open(CF,"/var/cpanel/cpane l.config") ;
while(<CF>) {
next if (/^\#/);
s/\n//g;
($var,$value) = split(/=/, $_);
$CPCONF{$var} = $value;
}
close(CF);
$user = $ARGV[0];
if ($user eq "" || $user eq "root") {
print "Syntax Error: usage: unsuspendacct <user>\n";
exit;
}
if (-e "/etc/wwwacct.conf") {
open(CONF,"/etc/wwwacct.co nf");
while(<CONF>) {
$_ =~ s/\n//g;
if ($_ !~ /^;/) {
if ($_ =~ /DEFSHELL/) {
(undef,$shell) = split(/ /, $_);
last;
}
}
}
close(CONF);
}
if ($owner eq "" || $owner eq "root") {
chomp($host = `hostname`);
} else {
$host = getdomain($owner);
}
if ((! -e $shell) || (! $shell)) {
$shell = "/bin/bash";
}
my $homedir = gethomedir($user);
if ($CPCONF{'acls'} eq "1") {
if (my $pid = fork()) {
waitpid($pid,0);
} else {
setuids($user);
system("setfacl","-kb","-m ","group:n obody:x",
"-m","group:mail:x",
"-m","group:cpanel:x",
"-m","group:mailnull:x",
'-m','group:65535:x',
'-m','group:ftp:x',
"--","${homedir}");
chmod(0750,${homedir});
exit();
}
} else {
cPScript::SafetyBits::safe _chmod(071 1,$user,$h omedir);
}
if (-e "/var/cpanel/fileprotect") {
my $httpgid = (getgrnam('nobody'))[2];
my $useruid = (getpwnam($user))[2];
cPScript::SafetyBits::safe _userchgid ($useruid, $httpgid," ${homedir} /public_ht ml");
cPScript::SafetyBits::safe _chmod(075 0,$useruid ,"${homedi r}/public_ html");
} else {
cPScript::SafetyBits::safe _chmod(075 5,$user,"$ {homedir}/ public_htm l");
}
cPScript::SafetyBits::safe _chmod(075 5,$user,"$ {homedir}/ public_ftp ");
my(%SUINFO);
open(SUINFO,"<","/var/cpan el/suspend info/${use r}");
while(<SUINFO>) {
chomp();
my($name,$value) = split(/=/, $_);
$SUINFO{$name} = $value;
}
close(SUINFO);
unlink("/var/cpanel/suspen dinfo/${us er}");
if ($SUINFO{'shell'} eq "") {
system("chsh","-s","/usr/l ocal/cpane l/bin/nosh ell","$use r");
} else {
system("chsh","-s",$SUINFO {'shell'}, $user);
}
AcctLock::acctlock();
if (-e "/usr/sbin/pw") {
system("/usr/sbin/pw","unl ock","$use r");
} else {
system("passwd","-u","$use r");
}
AcctLock::acctunlock();
open(CPU,"/var/cpanel/user s/${user}" );
while(<CPU>) {
if (/^DNS.?.?.?.?=(\S+)/) {
if (/^DNS.?.?.?.?=(\S+)/) {
push(@DNS,$1);
}
}
close(CPU);
mkdir("/usr/local/cpanel/3 rdparty/ma ilman/susp ended.list s",0755);
foreach my $dns (@DNS) {
$dns = makevaliddns($dns);
next if ($dns eq "-1");
system("mv /usr/local/cpanel/3rdparty /mailman/s uspended.l ists/*_$dn s /usr/local/cpanel/3rdparty /mailman/l ists 2>/dev/null");
if (-f "${homedir}/etc/${dns}/sha dow" && ! -l "${homedir}/etc/${dns}/sha dow") {
print "Unsuspending email account logins for ${dns} .... ";
unsuspendshadowfile("${hom edir}/etc/ ${dns}/sha dow");
print "Done\n";
}
}
unlink("$homedir/public_ht ml/.htacce ss");
rename("$homedir/public_ht ml/.htacce ss.suspend ","$homedi r/public_h tml/.htacc ess");
unlink("/var/cpanel/suspen ded/${user }");
unlink("/var/cpanel/suspen ded/${user }.lock");
system("sync");
my $ftpfile = "/etc/proftpd/$user";
if(-e "$ftpfile.suspended" && !-e "/var/cpanel/suspended/$us er") {
print "Unsuspending FTP accounts...\n";
rename("$ftpfile.suspended ", $ftpfile)
or warn "Could not rename $ftpfile.suspended to $ftpfile";
}
system("/usr/local/cpanel/ bin/ftpupd ate",$user );
system '/usr/local/cpanel/bin/upd ateauthtab ';
print "${user}'s account is now active\n";
$domain = getdomain($user);
if (-f "/var/spool/cron.suspended /${user}") {
unlink("/var/spool/cron/${ user}");
link("/var/spool/cron.susp ended/${us er}",
"/var/spool/cron/${user}") ;
unlink("/var/spool/cron.su spended/${ user}");
}
$msg = <<"EOM";
+========================= ========== +
| Account Info |
+========================= ========== +
| Domain: $domain
| UserName: $user
+========================= ========== +
Account Unsuspended by $ENV{'REMOTE_USER'} ($ENV{'USER'})
EOM
cPScript::iContact::iconta ct('applic ation' => 'unsuspendacct',
'level' => 3,
'subject' => qq{Account Unsuspended on $host ($domain)},
'message' => $msg,
'msgtype' => '');
sub gethomedir {
my($user) = @_;
my($homedir);
open(PASSWD,"/etc/passwd") ;
while(<PASSWD>) {
if (/^$user:/) {
(undef,undef,undef,undef,u ndef,$home dir,undef) = split(/:/, $_, 7);
return $homedir;
}
}
close(PASSWD);
}
sub makevaliddns {
my($domain) = @_;
$domain =~ s/[^\w\.\-]*[_]*//g;
if (length($domain) < 3) {
return(-1);
}
if ($domain =~ /^\./) {
return(-1);
}
return($domain);
}
sub getdomain {
my($user) = $_[0];
open(CPU,"/var/cpanel/user s/$user");
while(<CPU>) {
s/\n//g;
if (/^DNS=(\S+)/) {
close(CPU);
return $1;
}
}
close(CPU);
return "";
}
sub unsuspendshadowfile {
my($file) = @_;
my($shadowlock);
$shadowlock = SafeFile::safeopen(\*SHF," <",$file);
my @CT = <SHF>;
SafeFile::safeclose(\*SHF, $shadowloc k);
$shadowlock = SafeFile::safeopen(\*SHF," >",$file);
foreach (@CT) {
my @DC=split(/:/,$_);
chomp($DC[$#DC]);
while ($DC[1] =~ /^\*LOCKED\*/) {
$DC[1] =~ s/^\*LOCKED\*//g;
}
print SHF join(":",@DC) . "\n";
}
SafeFile::safeclose(\*SHF, $shadowloc k);
}
========================== ========== =======
thanks
1- suspendacct
#!/usr/bin/perl
# cpanel9 - scripts Copyright(c) 1997-2004 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited
BEGIN {
push(@INC,'/scripts');
}
use cPScript::SafetyBits;
use cPScript::iContact qw( );
use SafeFile;
use AcctLock;
use POSIX;
my $system = (POSIX::uname())[0];
$user = $ARGV[0];
$reason = $ARGV[1];
$disallowun = $ARGV[2];
if ($user eq "" || $user eq "root") {
print "Syntax Error: usage: suspendacct <user>\n";
exit;
}
my $homedir = gethomedir($user);
my $shell = getshell($user);
print "Changing Shell to /bin/false...";
system("chsh","-s","/bin/f
print "Done\n";
AcctLock::acctlock();
print "Locking Password...";
if (-e "/usr/sbin/pw") {
system("/usr/sbin/pw","loc
} else {
system("passwd","-l","$use
}
print "Done\n";
AcctLock::acctunlock();
$owner = getowner($user);
$owner =~ s/\n//g;
if ($owner eq "" || $owner eq "root" || $user eq $owner) {
chomp($host = `hostname`);
} else {
$host = getdomain($owner);
}
$domain = getdomain($user);
if (! -e "/var/cpanel/suspended") {
mkdir("/var/cpanel/suspend
}
open(USERS,">/var/cpanel/s
print USERS $reason;
close(USERS);
if ($disallowun eq "1") {
open(USERS,">/var/cpanel/s
close(USERS);
}
if ($system =~ /freebsd/i) {
system("killall","-9","-u"
} else {
system("skill","-9","$user
}
open(CPU,"/var/cpanel/user
while(<CPU>) {
if (/^DNS.?.?.?.?=(\S+)/) {
push(@DNS,$1);
}
}
close(CPU);
mkdir("/usr/local/cpanel/3
foreach my $dns (@DNS) {
$dns = makevaliddns($dns);
next if ($dns eq "-1");
system("mv /usr/local/cpanel/3rdparty
if (-f "${homedir}/etc/${dns}/sha
print "Suspending email account logins for ${dns} .... ";
suspendshadowfile("${homed
print "Done\n";
}
}
$msg = <<"EOM";
+=========================
| Account Info |
+=========================
| Domain: $domain
| UserName: $user
+=========================
Account suspended by $ENV{'REMOTE_USER'} ($ENV{'USER'})
EOM
cPScript::iContact::iconta
'level' => 3,
'subject' => qq{Account Suspended on $host ($domain)},
'message' => $msg,
'msgtype' => '');
if ($shell eq "/bin/false") {
print "Account Already Suspended\n";
exit;
}
if (! -e "/var/cpanel/suspendinfo")
mkdir("/var/cpanel/suspend
}
open(CPINFO,">","/var/cpan
print CPINFO "shell=${shell}\n";
close(CPINFO);
open(CPU,">>/var/cpanel/us
my $now = time();
print CPU "SUSPENDTIME=$now\n";
close(CPU);
if (! -e "/var/spool/cron.suspended
mkdir("/var/spool/cron.sus
}
if (-f "/var/spool/cron/${user}")
link("/var/spool/cron/${us
"/var/spool/cron.suspended
unlink("/var/spool/cron/${
}
cPScript::SafetyBits::safe
rename("$homedir/public_ht
unlink("$homedir/public_ht
open(HTACCESS,">>$homedir/
print HTACCESS "RedirectMatch .* http://${host}/suspended.page/\n";
print HTACCESS "Options -Includes -Indexes -ExecCGI\n";
close(HTACCESS);
system("sync");
my $ftpfile = "/etc/proftpd/$user";
if(-e $ftpfile && -e "/var/cpanel/suspended/$us
print "Suspending FTP accounts...\n";
rename($ftpfile, "$ftpfile.suspended")
or warn "Could not rename $ftpfile to $ftpfile.suspended";
}
system("/usr/local/cpanel/
system '/usr/local/cpanel/bin/upd
print ${user} . "'s account has been suspended\n";
sub gethomedir {
my($user) = @_;
my($homedir);
open(PASSWD,"/etc/passwd")
while(<PASSWD>) {
if (/^$user:/) {
(undef,undef,undef,undef,u
return $homedir;
}
}
close(PASSWD);
}
sub getshell {
my($user) = @_;
my($shell);
open(PASSWD,"/etc/passwd")
while(<PASSWD>) {
s/\n//g;
if (/^$user:/) {
(undef,undef,undef,undef,u
return $shell;
}
}
close(PASSWD);
}
sub getowner {
my($user) = @_;
my($owner);
open(CPUO,"/var/cpanel/use
while(<CPUO>) {
s/\n//g;
if (/^OWNER=(\S+)/) {
$owner = $1;
}
}
close(CPUO);
if ($owner eq "" || $owner eq "0") { $owner = 'root'; }
return($owner);
}
sub getdomain {
my($user) = $_[0];
open(CPU,"/var/cpanel/user
while(<CPU>) {
s/\n//g;
if (/^DNS=(\S+)/) {
close(CPU);
return $1;
}
}
close(CPU);
return "";
}
sub makevaliddns {
my($domain) = @_;
$domain =~ s/[^\w\.\-]*[_]*//g;
if (length($domain) < 3) {
return(-1);
}
if ($domain =~ /^\./) {
return(-1);
}
return($domain);
}
sub suspendshadowfile {
my($file) = @_;
my($shadowlock);
$shadowlock = SafeFile::safeopen(\*SHF,"
my @CT = <SHF>;
SafeFile::safeclose(\*SHF,
$shadowlock = SafeFile::safeopen(\*SHF,"
foreach (@CT) {
my @DC=split(/:/,$_);
chomp($DC[$#DC]);
if ($DC[1] !~ /^\*LOCKED\*/) {
$DC[1] = "*LOCKED*" . $DC[1];
}
print SHF join(":",@DC) . "\n";
}
SafeFile::safeclose(\*SHF,
}
==========================
==========================
2- unsuspendacct
#!/usr/bin/perl
# cpanel9 - scripts Copyright(c) 1997-2004 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cpanel license. Unauthorized copying is prohibited
BEGIN {
push(@INC,"/scripts");
}
use cPScript::SafetyBits;
use cPScript::iContact qw( );
use SafeFile;
use AcctLock;
open(CF,"/var/cpanel/cpane
while(<CF>) {
next if (/^\#/);
s/\n//g;
($var,$value) = split(/=/, $_);
$CPCONF{$var} = $value;
}
close(CF);
$user = $ARGV[0];
if ($user eq "" || $user eq "root") {
print "Syntax Error: usage: unsuspendacct <user>\n";
exit;
}
if (-e "/etc/wwwacct.conf") {
open(CONF,"/etc/wwwacct.co
while(<CONF>) {
$_ =~ s/\n//g;
if ($_ !~ /^;/) {
if ($_ =~ /DEFSHELL/) {
(undef,$shell) = split(/ /, $_);
last;
}
}
}
close(CONF);
}
if ($owner eq "" || $owner eq "root") {
chomp($host = `hostname`);
} else {
$host = getdomain($owner);
}
if ((! -e $shell) || (! $shell)) {
$shell = "/bin/bash";
}
my $homedir = gethomedir($user);
if ($CPCONF{'acls'} eq "1") {
if (my $pid = fork()) {
waitpid($pid,0);
} else {
setuids($user);
system("setfacl","-kb","-m
"-m","group:mail:x",
"-m","group:cpanel:x",
"-m","group:mailnull:x",
'-m','group:65535:x',
'-m','group:ftp:x',
"--","${homedir}");
chmod(0750,${homedir});
exit();
}
} else {
cPScript::SafetyBits::safe
}
if (-e "/var/cpanel/fileprotect")
my $httpgid = (getgrnam('nobody'))[2];
my $useruid = (getpwnam($user))[2];
cPScript::SafetyBits::safe
cPScript::SafetyBits::safe
} else {
cPScript::SafetyBits::safe
}
cPScript::SafetyBits::safe
my(%SUINFO);
open(SUINFO,"<","/var/cpan
while(<SUINFO>) {
chomp();
my($name,$value) = split(/=/, $_);
$SUINFO{$name} = $value;
}
close(SUINFO);
unlink("/var/cpanel/suspen
if ($SUINFO{'shell'} eq "") {
system("chsh","-s","/usr/l
} else {
system("chsh","-s",$SUINFO
}
AcctLock::acctlock();
if (-e "/usr/sbin/pw") {
system("/usr/sbin/pw","unl
} else {
system("passwd","-u","$use
}
AcctLock::acctunlock();
open(CPU,"/var/cpanel/user
while(<CPU>) {
if (/^DNS.?.?.?.?=(\S+)/) {
if (/^DNS.?.?.?.?=(\S+)/) {
push(@DNS,$1);
}
}
close(CPU);
mkdir("/usr/local/cpanel/3
foreach my $dns (@DNS) {
$dns = makevaliddns($dns);
next if ($dns eq "-1");
system("mv /usr/local/cpanel/3rdparty
if (-f "${homedir}/etc/${dns}/sha
print "Unsuspending email account logins for ${dns} .... ";
unsuspendshadowfile("${hom
print "Done\n";
}
}
unlink("$homedir/public_ht
rename("$homedir/public_ht
unlink("/var/cpanel/suspen
unlink("/var/cpanel/suspen
system("sync");
my $ftpfile = "/etc/proftpd/$user";
if(-e "$ftpfile.suspended" && !-e "/var/cpanel/suspended/$us
print "Unsuspending FTP accounts...\n";
rename("$ftpfile.suspended
or warn "Could not rename $ftpfile.suspended to $ftpfile";
}
system("/usr/local/cpanel/
system '/usr/local/cpanel/bin/upd
print "${user}'s account is now active\n";
$domain = getdomain($user);
if (-f "/var/spool/cron.suspended
unlink("/var/spool/cron/${
link("/var/spool/cron.susp
"/var/spool/cron/${user}")
unlink("/var/spool/cron.su
}
$msg = <<"EOM";
+=========================
| Account Info |
+=========================
| Domain: $domain
| UserName: $user
+=========================
Account Unsuspended by $ENV{'REMOTE_USER'} ($ENV{'USER'})
EOM
cPScript::iContact::iconta
'level' => 3,
'subject' => qq{Account Unsuspended on $host ($domain)},
'message' => $msg,
'msgtype' => '');
sub gethomedir {
my($user) = @_;
my($homedir);
open(PASSWD,"/etc/passwd")
while(<PASSWD>) {
if (/^$user:/) {
(undef,undef,undef,undef,u
return $homedir;
}
}
close(PASSWD);
}
sub makevaliddns {
my($domain) = @_;
$domain =~ s/[^\w\.\-]*[_]*//g;
if (length($domain) < 3) {
return(-1);
}
if ($domain =~ /^\./) {
return(-1);
}
return($domain);
}
sub getdomain {
my($user) = $_[0];
open(CPU,"/var/cpanel/user
while(<CPU>) {
s/\n//g;
if (/^DNS=(\S+)/) {
close(CPU);
return $1;
}
}
close(CPU);
return "";
}
sub unsuspendshadowfile {
my($file) = @_;
my($shadowlock);
$shadowlock = SafeFile::safeopen(\*SHF,"
my @CT = <SHF>;
SafeFile::safeclose(\*SHF,
$shadowlock = SafeFile::safeopen(\*SHF,"
foreach (@CT) {
my @DC=split(/:/,$_);
chomp($DC[$#DC]);
while ($DC[1] =~ /^\*LOCKED\*/) {
$DC[1] =~ s/^\*LOCKED\*//g;
}
print SHF join(":",@DC) . "\n";
}
SafeFile::safeclose(\*SHF,
}
==========================
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
There is not PHP function called suspend, so you must be looking at a specific application?