/** * Delete an Nginx virtual host configuration file using ajax * @return void * @throws App\Error\Exception\RestException */ public function ajaxDelete() { if (!$this->request->is('post')) { throw new NotFoundException(); } if (empty($this->request->data['id'])) { throw new RestException('Parameter id is required', null, 401); } $id = $this->request->data['id']; $execute = new CakeboxExecute(); if ($execute->removeSite($id) == false) { throw new RestException("Error deleting website {$id}. See cakebox.log for details.", null, 401); } $this->set(['message' => "Website {$id} deleted successfully.", '_serialize' => ['message']]); }
/** * Show most recent execute log message to user before exiting PHP script * with exit code 1 to inform bash about errors. * * @param string $message Message to be logged. * @return void */ public function exitBashError($message = null) { if (empty($message)) { $message = 'Error'; } if (count($this->Execute->debug()) != 0) { foreach ($this->Execute->debug() as $entry) { $this->out($entry, 1, Shell::QUIET); } } $this->logError($message); exit(1); }
/** * Run readiness test to see if a directory can be used for composer/git * installations. * * @param string $directory Full path to directory to check. * @return bool */ public function dirAvailable($directory) { Log::debug("Checking installation directory readiness"); # Directory does not exist Log::debug("* Checking if installation directory exists"); if (!file_exists($directory)) { Log::debug("* Pass: directory does not exist"); return true; } # Directory exists but is not empty Log::debug("* Checking if existing directory is empty"); $files = scandir($directory); if (count($files) > 2) { Log::warning("* Fail: directory exists but is NOT empty"); return false; } # Check if the directory is writable by vagrant user $Execute = new CakeboxExecute(); if (!$Execute->isVagrantWritable($directory)) { return false; } Log::debug("* Pass: directory is writable"); return true; }