|
|
@@ -7,8 +7,6 @@ class DeployDevController {
|
|
|
$domain = $data['domain'];
|
|
|
$adminName = $data['admin_name'] ?? '';
|
|
|
$adminPassword = $data['admin_password'];
|
|
|
- $databaseName = $username . "_dev_";
|
|
|
- $databaseName = $databaseName . str_replace(['-', '.'], ["_", "_"], $domain);
|
|
|
$webDir = "/home/$username/dev.$domain";
|
|
|
$configTemplate = '/etc/apache2/site-config.in';
|
|
|
$configFile = "/etc/apache2/sites-enabled/dev.$domain.conf";
|
|
|
@@ -30,23 +28,6 @@ class DeployDevController {
|
|
|
|
|
|
error_log(" Starting function deploy for " . $username . " and " . $domain . " DebugMode: " . $GLOBALS['debug']);
|
|
|
|
|
|
- $userExisted = false;
|
|
|
- if( strpos(file_get_contents("/etc/passwd"),$username) !== false) {
|
|
|
- $userExisted = true;
|
|
|
- }
|
|
|
-
|
|
|
- if ($userExisted != true) {
|
|
|
- // Create user without login access
|
|
|
- if ($GLOBALS['debug'] == true) {error_log("Adding User: " . $username); }
|
|
|
- exec("sudo /usr/sbin/useradd -m -k -M -s /usr/sbin/nologin $username 2>&1", $userOutput, $userReturnCode);
|
|
|
- if ($userReturnCode !== 0) {
|
|
|
- error_log("deploy: ERROR: Useradd for $username failed, details => " . implode("\n", $userOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to create user', 'details' => implode("\n", $userOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
if ($GLOBALS['debug'] == true) { error_log("Creating Webdir ($webDir) for : " . $username); }
|
|
|
exec("sudo /usr/bin/mkdir -p $webDir 2>&1", $mkdirOutput, $mkdirReturnCode);
|
|
|
if ($mkdirReturnCode !== 0) {
|
|
|
@@ -82,7 +63,7 @@ class DeployDevController {
|
|
|
if ($chownReturnCode !== 0) {
|
|
|
error_log("deploy: ERROR: chown on /home/$username failed, details => " . implode("\n", $chownOutput));
|
|
|
http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to chown backups dir', 'details' => implode("\n", $chownOutput)]);
|
|
|
+ echo json_encode(['error' => 'Failed to chown homedir', 'details' => implode("\n", $chownOutput)]);
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -118,111 +99,9 @@ class DeployDevController {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // Create PHP-FPM User
|
|
|
- // /etc/php/8.2/fpm/user.in
|
|
|
- if ($userExisted != true) {
|
|
|
- if ($GLOBALS['debug'] == true) {error_log("Writing PHP-FPM Config for : " . $username); }
|
|
|
- $phpContent = file_get_contents("/etc/php/8.2/fpm/user.in");
|
|
|
- $phpContent = str_replace("USERNAME", $username, $phpContent);
|
|
|
- file_put_contents("/etc/php/8.2/fpm/pool.d/" . $username . ".conf", $phpContent);
|
|
|
-
|
|
|
- if ($GLOBALS['debug'] == true) {error_log("Restarting PHP-FPM : " . $username);}
|
|
|
- exec('sudo /usr/bin/systemctl reload php8.2-fpm', $phpOutput, $phpReturnCode);
|
|
|
- if ($phpReturnCode !== 0) {
|
|
|
- error_log("deploy: ERROR: PHP-FPM reload error, details => " . implode("\n", $phpOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to reload PHP-FPM', 'details' => implode("\n", $phpOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-/*
|
|
|
- //Create MySQL Database
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("creating database: " . $databaseName); }
|
|
|
- $sqlCommand = "sudo mysql -e \"create database $databaseName;\" 2>&1";
|
|
|
- exec($sqlCommand,$mysqlOutput,$mysqlReturnCode);
|
|
|
- if ($mysqlReturnCode !== 0) {
|
|
|
- error_log("deploy: MySQL create database error, details => " . implode("\n", $mysqlOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to create database $databaseName', 'details' => implode("\n", $mysqlOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
- //Create MySQL User
|
|
|
-
|
|
|
- $sqlCommand = "sudo mysql -e \"create user '" . $username . "'@'localhost' identified by '" . $username . "'\" 2>&1";
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("creating database user: " . $sqlCommand); }
|
|
|
- exec($sqlCommand,$mysqlOutput,$mysqlReturnCode);
|
|
|
- if ($mysqlReturnCode !== 0) {
|
|
|
- error_log("deploy: MySQL create user $username error, details => " . implode("\n", $mysqlOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to create databaseuser $username', 'details' => implode("\n", $mysqlOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- //Grant permission
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("granting permission on $databaseName to: " . $username); }
|
|
|
- $sqlCommand = "sudo mysql -e \"grant all on " . $databaseName . ".* to '" . $username . "'@'localhost';\" 2>&1";
|
|
|
- exec($sqlCommand,$mysqlOutput,$mysqlReturnCode);
|
|
|
- if ($mysqlReturnCode !== 0) {
|
|
|
- error_log("deploy: MySQL grant permission to user $username error, details => " . implode("\n", $mysqlOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to grant permission on $databaseName ot $username', 'details' => implode("\n", $mysqlOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- // Deployment of the Concrete CMS Application
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("Copy master directory to $webDir"); }
|
|
|
- exec("sudo /usr/bin/cp -r /var/www/master/* $webDir 2>&1",$cpOutput,$cpReturnCode);
|
|
|
- if ($cpReturnCode !== 0) {
|
|
|
- error_log("deploy: Error while copying master installation to $webDir, details => " . implode("\n", $cpOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to copy master installation into web dir', 'details' => implode("\n", $cpOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("Chown WebDir $webDir"); }
|
|
|
- exec("sudo /usr/bin/chown $username:$username $webDir -R 2>&1", $chownOutput, $chownReturnCode);
|
|
|
- if ($chownReturnCode !== 0) {
|
|
|
- error_log("deploy: chown error on $webDir, details => " . implode("\n", $chownOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to chown web dir', 'details' => implode("\n", $chownOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("Writing install script to: /home/" . $username . "/" . $databaseName ."-inst.sh"); }
|
|
|
- $installCommand = "#!/bin/bash\n";
|
|
|
- $installCommand .= "$webDir/concrete/bin/concrete5 c5:install --starting-point=restaurantly --db-server='localhost' --db-username='" . $username . "' --db-password='" . $username ."' --db-database='" . $databaseName . "' --timezone='Europe/Zurich' --admin-email='" . $adminName . "' --admin-password='" . $adminPassword . "' --site-locale=ch_DE --language=ch_DE --site='" . $domain . "' -n 2>&1 \n";
|
|
|
- $installCommand .= "$webDir/concrete/bin/concrete5 c5:package-install studio_templates 2>&1 \n";
|
|
|
- $installCommand .= "$webDir/concrete/bin/concrete5 studio:setup 2>&1 \n";
|
|
|
- file_put_contents("/var/www/scripts/" . $databaseName ."-inst.sh",$installCommand);
|
|
|
-
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("Chmod install script: /home/" . $username . "/" . $databaseName ." -inst.sh"); }
|
|
|
- exec("sudo /usr/bin/chmod a+x /var/www/scripts/" . $databaseName ."-inst.sh 2>&1", $chmodOutput, $chmodReturnCode);
|
|
|
- if ($chmodReturnCode !== 0) {
|
|
|
- error_log("deploy: ERROR: chmod on /var/www/scripts/" . $databaseName ."-inst.sh failed, details => " . implode("\n", $chmodOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to chmod on /var/www/scripts/' . $databaseName .'-inst.sh', 'details' => implode("\n", $chmodOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if ($GLOBALS['debug'] == true) { error_log("Executing Concrete 5 installation: " . $installCommand); }
|
|
|
- exec("sudo -u $username /var/www/sudo-concrete5.sh /var/www/scripts/" . $databaseName ."-inst.sh",$createOutput, $createReturnCode);
|
|
|
- if ($createReturnCode !== 0) {
|
|
|
- error_log("deploy: cms installation error, details => " . implode("\n", $createOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to install cms system', 'details' => implode("\n", $createOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-*/
|
|
|
echo json_encode(['success' => 'Development site deployed successfully','details' => '']);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-//exec("php /path/to/scripts/post_install_setup.php", $output, $code);
|
|
|
-
|
|
|
-
|
|
|
public static function revert($data): void {
|
|
|
$username = $data['username'] ?? '';
|
|
|
$domain = $data['domain'] ?? '';
|
|
|
@@ -256,65 +135,10 @@ class DeployDevController {
|
|
|
echo json_encode(['error' => 'Failed to chown web dir', 'details' => implode("\n", $chownOutput)]);
|
|
|
return;
|
|
|
}
|
|
|
-/*
|
|
|
- $sqlCommand = "sudo mysql \"drop database $databaseName;\" 2>&1";
|
|
|
- exec($sqlCommand,$mysqlOutput,$mysqlReturnCode);
|
|
|
- if ($mysqlReturnCode !== 0) {
|
|
|
- error_log("revert: MySQL drop database error, details => " . implode("\n", $mysqlOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to drop database $usernmae', 'details' => implode("\n", $mysqlOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- $sqlCommand = "sudo mysql \"create database $databaseName;\" 2>&1";
|
|
|
- exec($sqlCommand,$mysqlOutput,$mysqlReturnCode);
|
|
|
- if ($mysqlReturnCode !== 0) {
|
|
|
- error_log("revert: MySQL create database error, details => " . implode("\n", $mysqlOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to create database $usernmae', 'details' => implode("\n", $mysqlOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- // Deployment of the Concrete CMS Application
|
|
|
- exec("sudo /usr/bin/cp -r /var/www/master/* $webDir 2>&1",$cpOutput,$cpReturnCode);
|
|
|
- if ($cpReturnCode !== 0) {
|
|
|
- error_log("revert: Error while copying master installation to $webDir, details => " . implode("\n", $cpOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to copy master installation into web dir', 'details' => implode("\n", $cpOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- exec("sudo /usr/bin/chown $username:$username $webDir -R 2>&1", $chownOutput, $chownReturnCode);
|
|
|
- if ($chownReturnCode !== 0) {
|
|
|
- error_log("revert: chown error on $webDir, details => " . implode("\n", $chownOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to chown web dir', 'details' => implode("\n", $chownOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- exec("sudo -u $username /var/www/sudo-concrete5.sh $webDir/concrete/bin/concrete5 c5:install --db-server=localhost --db-username=$username --db-password=$username --db-database=$databaseName --timezone=\"Europe/Zurich\" --admin-email=$adminName --admin-password=$adminPassword --site-locale=ch_DE --language=ch_DE --site=$domain --starting-point=atomik_blank -n -vv 2>&1",$createOutput, $createReturnCode);
|
|
|
- if ($createReturnCode !== 0) {
|
|
|
- error_log("revert: cms installation error, details => " . implode("\n", $createOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to install cms system', 'details' => implode("\n", $createOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- exec("sudo /usr/bin/chown $username:$username $webDir 2>&1", $chownOutput, $chownReturnCode);
|
|
|
- if ($chownReturnCode !== 0) {
|
|
|
- error_log("revert: chown error on $webDir, details => " . implode("\n", $chownOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to chown web dir', 'details' => implode("\n", $chownOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
-*/
|
|
|
echo json_encode(['success' => 'Development site deployed successfully']);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public static function terminate($data): void {
|
|
|
+ public static function undeploy($data): void {
|
|
|
$username = $data['username'] ?? '';
|
|
|
$domain = $data['domain'] ?? '';
|
|
|
if (empty($username)) {
|
|
|
@@ -331,18 +155,6 @@ class DeployDevController {
|
|
|
echo json_encode(['error' => 'Unknown user']);
|
|
|
return;
|
|
|
}
|
|
|
- // remove PHP-FPM User
|
|
|
- if ($GLOBALS['debug'] == true) {error_log("Removing PHP-FPM Config for : " . $username); }
|
|
|
- $configName = "/etc/php/8.2/fpm/pool.d/" . $username . ".conf";
|
|
|
- exec("sudo /usr/bin/rm -f $configName 2>&1", $userOutput, $userReturnCode);
|
|
|
- if ($GLOBALS['debug'] == true) {error_log("Restarting PHP-FPM : " . $username);}
|
|
|
- exec('sudo /usr/bin/systemctl reload php8.2-fpm', $phpOutput, $phpReturnCode);
|
|
|
- if ($phpReturnCode !== 0) {
|
|
|
- error_log("deploy: ERROR: PHP-FPM reload error, details => " . implode("\n", $phpOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to reload PHP-FPM', 'details' => implode("\n", $phpOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
if(!empty($domain)) {
|
|
|
$configFile = "/etc/apache2/sites-enabled/dev.$domain.conf";
|
|
|
if ($GLOBALS['debug'] == true) { error_log("Remove config of user : " . $username); }
|
|
|
@@ -363,16 +175,7 @@ class DeployDevController {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
- // Remove user and files
|
|
|
- if ($GLOBALS['debug'] == true) {error_log("Remove User: " . $username); }
|
|
|
- exec("sudo /usr/sbin/userdel -r -f $username 2>&1", $userOutput, $userReturnCode);
|
|
|
- if ($userReturnCode !== 0) {
|
|
|
- error_log("deploy: ERROR: Userdel for $username failed, details => " . implode("\n", $userOutput));
|
|
|
- http_response_code(500);
|
|
|
- echo json_encode(['error' => 'Failed to remove user', 'details' => implode("\n", $userOutput)]);
|
|
|
- return;
|
|
|
- }
|
|
|
- echo json_encode(['success' => 'Removing user ' . $username . ' successfully']);
|
|
|
+ echo json_encode(['success' => 'Undeploy site dev.' . $domain . ' successfully']);
|
|
|
}
|
|
|
|
|
|
}
|