|
|
@ -1,11 +1,26 @@ |
|
|
|
<?php |
|
|
|
include_once('init.php'); |
|
|
|
|
|
|
|
/* choice */ |
|
|
|
$choice = ""; |
|
|
|
|
|
|
|
/** |
|
|
|
* prompt user to eneter domain name |
|
|
|
*/ |
|
|
|
echo "Enter a domain name which needs to be removed...\n"; |
|
|
|
$usr_domain = (trim(fgets(STDIN))); |
|
|
|
|
|
|
|
$domain_arr = explode(" ", $usr_domain); |
|
|
|
|
|
|
|
foreach($domain_arr as $domain){ |
|
|
|
echo "****************************************************************************"; |
|
|
|
echo "\n\nMoving :: $domain \n\n"; |
|
|
|
remove_domain(trim($domain)); |
|
|
|
} |
|
|
|
|
|
|
|
function remove_domain($usr_domain){ |
|
|
|
global $local_env, $choice; |
|
|
|
|
|
|
|
echo "You have entered :: $usr_domain \n"; |
|
|
|
|
|
|
|
if(strlen($usr_domain) == 0 ){ |
|
|
@ -20,6 +35,7 @@ if(strpos($usr_domain,"\\") !== false ){ |
|
|
|
die("domain cannot contain \\ !"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
* Set domain environment values |
|
|
|
*/ |
|
|
@ -38,35 +54,31 @@ echo "\n Domain Name - " . $domain['name'] . |
|
|
|
"\n Webroot Dir - " . realpath($domain['rootdir']) . |
|
|
|
"\n Database Name - " . $domain['name'] ; |
|
|
|
|
|
|
|
echo "\nDo you want to remove this domain, related files and databases for sure? [Y/N] (default=N): "; |
|
|
|
if($choice != "a"){ |
|
|
|
//ask for confirmation |
|
|
|
echo "\nDo you want to remove this domain, related files and databases for sure? [Y(es)/N(o)/A(lways)] (default=N): "; |
|
|
|
|
|
|
|
if ( strtolower(trim(fgets(STDIN))) != "y" ) { |
|
|
|
switch(strtolower(trim(fgets(STDIN)))){ |
|
|
|
case 'y' : |
|
|
|
die("\nYou choose to terminate this script! The domain is NOT removed! \n"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* At this point - user has confirmed domain removal |
|
|
|
//Drop Database |
|
|
|
/** |
|
|
|
* MySQL Database Deletion |
|
|
|
*/ |
|
|
|
|
|
|
|
$command = "mysql -h " . $local_env['mysql_host'] . " -u " . $local_env['mysql_user'] . " -p" . $local_env['mysql_pass'] . " -e 'drop database `'" . $domain['name'] . "'` '"; |
|
|
|
$result = system($command); |
|
|
|
|
|
|
|
case 'a' : $choice = "a"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//remove htdocs |
|
|
|
if(file_exists(realpath($domain['rootdir']))){ |
|
|
|
if(dirname(realpath($domain['rootdir']))=="/var/www") |
|
|
|
system("rm -rf ". realpath($domain['rootdir'])); |
|
|
|
if(dirname(realpath($domain['rootdir']))=="/var/www"){ |
|
|
|
echo "/nremoving webroot \n"; |
|
|
|
system("rm -rf ". $domain['rootdir']); |
|
|
|
} |
|
|
|
else |
|
|
|
die("Try something else!"); |
|
|
|
}else{ |
|
|
|
echo "\n Directory " . $domain['rootdir'] . " doesn't exists\n"; |
|
|
|
} |
|
|
|
//delete database |
|
|
|
$command = "mysql -h " . $local_env['mysql_host'] . " -u " . $local_env['mysql_user'] . " -p" . $local_env['mysql_pass'] . " -e 'create database `'" . $domain['name'] . "'` '"; |
|
|
|
$command = "mysql -h " . $local_env['mysql_host'] . " -u " . $local_env['mysql_user'] . " -p" . $local_env['mysql_pass'] . " -e 'drop database `'" . $domain['name'] . "'` '"; |
|
|
|
$result = system($command); |
|
|
|
|
|
|
|
|
|
|
@ -77,13 +89,19 @@ if(file_exists($local_env['nginx_dir_sites_enabled']."/".$domain['name']) OR fil |
|
|
|
unlink($local_env['nginx_dir_sites_enabled']."/".$domain['name']); |
|
|
|
unlink($local_env['nginx_dir_sites_avilable']."/".$domain['name']); |
|
|
|
|
|
|
|
}else{ |
|
|
|
echo "\nNginx config files for $usr_domain domain do not exist\n"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}//end func |
|
|
|
|
|
|
|
/** |
|
|
|
* ALL SEENS WELL - Restart nginx |
|
|
|
*/ |
|
|
|
echo "\n Issuing nginx reboot command...\n\n"; |
|
|
|
system('service nginx restart'); |
|
|
|
}else{ |
|
|
|
echo "\nNginx config files for this domain do not exist\n"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
?> |