|
|
@@ -316,6 +316,7 @@ class DeployDevController {
|
|
|
|
|
|
public static function terminate($data): void {
|
|
|
$username = $data['username'] ?? '';
|
|
|
+ $domain = $data['domain'] ?? '';
|
|
|
if (empty($username)) {
|
|
|
error_log("terminate: ERROR: No username provided");
|
|
|
http_response_code(400);
|
|
|
@@ -336,9 +337,41 @@ class DeployDevController {
|
|
|
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 create user', 'details' => implode("\n", $userOutput)]);
|
|
|
+ echo json_encode(['error' => 'Failed to remove user', 'details' => implode("\n", $userOutput)]);
|
|
|
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); }
|
|
|
+ exec("sudo /usr/bin/rm -f $configFile 2>&1", $userOutput, $userReturnCode);
|
|
|
+ exec("sudo /usr/bin/certbot delete --cert-name dev.$domain 2>&1", $output, $returnCode);
|
|
|
+ if ($returnCode !== 0) {
|
|
|
+ error_log("deploy: ERROR: certbot failed to delete certificate on dev.$domain, details => " . implode("\n", $output));
|
|
|
+ http_response_code(500);
|
|
|
+ echo json_encode(['error' => 'Certbot failed', 'details' => implode("\n", $output)]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ exec('sudo /usr/bin/systemctl reload apache2 2>&1', $apacheOutput, $apacheReturnCode);
|
|
|
+ if ($GLOBALS['debug'] == true) { error_log("Restarting Apache"); }
|
|
|
+ if ($apacheReturnCode !== 0) {
|
|
|
+ error_log("deploy: ERROR: Apache Reload error, details => " . implode("\n", $apacheOutput));
|
|
|
+ http_response_code(500);
|
|
|
+ echo json_encode(['error' => 'Failed to reload Apache', 'details' => implode("\n", $apacheOutput)]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
echo json_encode(['success' => 'Removing useri ' . $username . ' successfully']);
|
|
|
}
|
|
|
|