public function Create()
{
if ($this->name != '' && $this->path != '') {
$this->path = $this->cleanPath();
$this->name = htmlspecialchars($this->name);
if (!$this->isAbsPath($this->path)) {
$this->path = $this->SanitizePath();
}
if ($this->path != '') {
$pass = $this->checkDuplicate();
if ($pass) {
if (!$this->isAbsPath($this->path)) {
mkdir(WORKSPACE . '/' . $this->path);
} else {
if (defined('WHITEPATHS')) {
$allowed = false;
foreach (explode(",", WHITEPATHS) as $whitepath) {
if (strpos($this->path, $whitepath) === 0) {
$allowed = true;
}
}
if (!$allowed) {
die(formatJSEND("error", "Absolute Path Only Allowed for " . WHITEPATHS));
}
}
if (!file_exists($this->path)) {
if (!mkdir($this->path . '/', 0755, true)) {
die(formatJSEND("error", "Unable to create Absolute Path"));
}
} else {
if (!is_writable($this->path) || !is_readable($this->path)) {
die(formatJSEND("error", "No Read/Write Permission"));
}
}
}
$this->projects[] = array("name" => $this->name, "path" => $this->path);
saveJSON('projects.php', $this->projects);
// Pull from Git Repo?
if ($this->gitrepo && filter_var($this->gitrepo, FILTER_VALIDATE_URL) !== false) {
$this->git_branch = $this->SanitizeGitBranch();
if (!$this->isAbsPath($this->path)) {
$this->command_exec = "cd " . escapeshellarg(WORKSPACE . '/' . $this->path) . " && git init && git remote add origin " . escapeshellarg($this->gitrepo) . " && git pull origin " . escapeshellarg($this->gitbranch);
} else {
$this->command_exec = "cd " . escapeshellarg($this->path) . " && git init && git remote add origin " . escapeshellarg($this->gitrepo) . " && git pull origin " . escapeshellarg($this->gitbranch);
}
$this->ExecuteCMD();
}
echo formatJSEND("success", array("name" => $this->name, "path" => $this->path));
} else {
echo formatJSEND("error", "A Project With the Same Name or Path Exists");
}
} else {
echo formatJSEND("error", "Project Name/Folder not allowed");
}
} else {
echo formatJSEND("error", "Project Name/Folder is empty");
}
}