1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| <?php
//affichage des erreurs php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
require('config.php');
$username="supraSupra";
$password="test";
$path = "/var/www/".$username;
if (!is_dir($path)) {
mkdir($path, 0777, true);
}
$vhost = $username.".conf";
$query_mysql_user = "CREATE USER $username@'%' IDENTIFIED BY '$password'";
$res_mysql_user = mysqli_query($conn, $query_mysql_user);
$query_mysql_grant = "GRANT USAGE ON * . * TO $username@'%' IDENTIFIED BY '$password'";
$res_mysql_grant = mysqli_query($conn, $query_mysql_grant);
$query_mysql_create_db = "CREATE DATABASE IF NOT EXISTS $username DEFAULT CHARACTER SET = utf8 DEFAULT COLLATE = utf8_general_ci";
$res_mysql_create_db = mysqli_query($conn, $query_mysql_create_db);
$query_mysql_all_privilege = "GRANT ALL PRIVILEGES ON $username . * TO $username@'%'";
$res_mysql_all_privilege = mysqli_query($conn, $query_mysql_all_privilege);
$query_ftp = "INSERT INTO `ftpd` (`User`, `status`, `Password`, `Uid`, `Gid`, `Dir`, `ULBandwidth`, `DLBandwidth`, `comment`, `ipaccess`, `QuotaSize`, `QuotaFiles`) VALUES ('$username', '1', '".hash('MD5', $password)."', '2001', '2001', '$path', '0', '0', '', '*', '0', '0')";
$res_ftp = mysqli_query($conn, $query_ftp);
file_put_contents("/etc/apache2/sites-available/".$vhost, "<VirtualHost *:80>\r\n ServerName $username.test.be\r\n\r\n\r\nServerAdmin admin@test.be\r\n DocumentRoot $path\r\n\r\n\r\n ErrorLog /var/logs/apache2/error.log\r\n CustomLog /var/logs/apache2/access.log combined\r\n\r\n\r\n</VirtualHost>");
$output = exec("./heb.sh $vhost");
?> |
Partager