# # # add_file "www/errpage.php" # content [740f3e01085555e06e11f59de7f2ef809646a576] # # patch "www/common-ctrl.php" # from [5ea62c8285f5c48fad5e55441be84f6a8f484bec] # to [faa67a0b50337520ed254b6056b9a2bb36796580] # # patch "www/common.php" # from [8f3bd6047bd0e87b006cb882abe899342a200533] # to [f55edc355d24a53645e2f984ef40b5a179a041fd] # # patch "www/proj-ctrl.php" # from [e0275c0d892427b2e0cb5ab6cc42b179e751559b] # to [375b6a00d7d0d0fa602aaa46455886daf20e9fe1] # # patch "www/sidebar.js" # from [591674ba9a1f37b50fe779982c88caaca5aa0145] # to [db04812a9ddc52a1351c9c9d3ab39e0405182c76] # # patch "www/sidebar.php" # from [9622ee994313814de8df8f44aa099e1ea4886e29] # to [661addb051744696769d491796b90c83fd7ab830] # ============================================================ --- www/errpage.php 740f3e01085555e06e11f59de7f2ef809646a576 +++ www/errpage.php 740f3e01085555e06e11f59de7f2ef809646a576 @@ -0,0 +1,38 @@ + + + + + +Oops + + + + + + + + + + + + +
+
+ + + +

Something didn't work!

+ + +
+
+ + ============================================================ --- www/common-ctrl.php 5ea62c8285f5c48fad5e55441be84f6a8f484bec +++ www/common-ctrl.php faa67a0b50337520ed254b6056b9a2bb36796580 @@ -1,9 +1,10 @@ $project = $args->project; if($_REQUEST[ decode($GLOBALS['HTTP_RAW_POST_DATA']); $action = $args->action; if($_REQUEST['action']) $action = $_REQUEST['action']; $project = $args->project; if($_REQUEST['project']) $project = $_REQUEST['project']; +$render_type = $args->render_type; if($_REQUEST['render_type']) $render_type = $_REQUEST['render_type']; $projdir = $project_dir . "/" . basename($project); $projwww = $www_dir . "/projects/" . basename($project); @@ -22,7 +23,8 @@ if (!$project) { } if (!$project) { - $project = basename(dirname($_SERVER['PHP_SELF'])); + if (basename(dirname(dirname($_SERVER['PHP_SELF']))) == "projects") + $project = basename(dirname($_SERVER['PHP_SELF'])); } function allowed($what) { global $json, $permissions, $validuser, $username; ============================================================ --- www/common.php 8f3bd6047bd0e87b006cb882abe899342a200533 +++ www/common.php f55edc355d24a53645e2f984ef40b5a179a041fd @@ -1,5 +1,5 @@ '; ============================================================ --- www/proj-ctrl.php e0275c0d892427b2e0cb5ab6cc42b179e751559b +++ www/proj-ctrl.php 375b6a00d7d0d0fa602aaa46455886daf20e9fe1 @@ -96,53 +96,51 @@ function maintlist() { return $out; } -header('Content-type: text/x-json'); +function newproj_chkerr() { + global $project, $db; + if ($project == "") + return array("error" => "A project cannot have the empty name."); + + $result = $db->Execute("SELECT * FROM projects WHERE name=?", array($project)); + + if(!preg_match('/^[a-zA-Z0-9-]*$/D', $project)) + return array("error" => "Only letters, numbers, and dash are allowed in a project name."); + + if(!$result) + return array("error" => "Internal server error."); + + if ($result->RecordCount()) + return array("error" => "That project name is already taken."); + + + return array(); +} + + if ($action == "new_project") { if ($validuser) { $db->BeginTrans(); # pg_exec($db, "LOCK TABLE projects, permissions"); $err = false; + $errmsg = newproj_chkerr(); - $result = $db->Execute("SELECT * FROM projects WHERE name=?", - array($project)); do { - if ($project == "") { - print $json->encode(array("error" => "A project cannot have the empty name.")); - $err = true; + if (count($errmsg) > 0) { break; } - if(!preg_match('/^[a-zA-Z0-9-]*$/D', $project)) { - print $json->encode(array("error" => "Only letters, numbers, and dash are allowed in a project name.")); - $err = true; - break; - } - if(!$result) { - $err = true; - print $json->encode(array("error" => "Internal server error.")); - break; - } - if ($result->RecordCount()) { - print $json->encode(array("error" => "That project name is already taken.")); - $err = true; - break; - } $projdir = $project_dir . '/'. $project; $projwww = $www_dir . '/projects/'. $project; -# $query = "INSERT INTO projects (name, directory) VALUES ('%s', '%s')"; -# $result = pg_exec($db, sprintf($query, $safeproj, '/foobar')); $result = $db->Execute("INSERT INTO projects (name) VALUES (?)", array($project)); if(!$result) { - $err = true; - print $json->encode(array("error" => "Internal server error.")); + $errmsg = array("error" => "Internal server error."); break; } $fields = "username, project, give, upload, homepage, access, server, description"; $query = sprintf("INSERT INTO permissions (%s) VALUES (?,?,1,1,1,1,1,1)", $fields); $result = $db->Execute($query, array($username, $project)); if(!$result) { - $err = true; - print $json->encode(array("error" => "Internal server error.")); + $errmsg = array("error" => "Internal server error."); break; } $out = array(); @@ -160,20 +158,41 @@ if ($action == "new_project") { exec("cp $projdir/database $projdir/database.transfer"); exec("chmod ug+rwX '$projdir' '$projdir'/database* 2>&1", $out, $res3); if ($res1 || $res2 || $res3) { - print $json->encode(array("error" => "Internal server error", "verboseError" => $out)); - $err = true; + $errmsg = array("error" => "Internal server error", "verboseError" => $out); } usherctrl("RELOAD"); } while (false); - if ($err) - $db->RollbackTrans(); - else - print $json->encode(array("name" => $project)); + if (count($errmsg) > 0) { + $db->RollbackTrans(); + if ($render_type == "json") { + header('Content-type: text/x-json'); + print $json->encode($errmsg); + } else { + include('errpage.php'); + } + } else { + if ($render_type == "json") { + header('Content-type: text/x-json'); + print $json->encode(array("name" => $project)); + } else { + header('Content-type: text/html'); + header(sprintf("Location: %s/projects/%s/admin.php", $base_url, $project)); + } + } + $db->CommitTrans(); - } else - print $json->encode(array("error" => "username or password incorrect.")); -} else if ($action == "delete_project") { + } else { + $errmsg = array("error" => "username or password incorrect."); + if ($render_type == "json") { + header('Content-type: text/x-json'); + print $json->encode($errmsg); + } else { + include('errpage.php'); + } + } + } else if ($action == "delete_project") { + header('Content-type: text/x-json'); $super_maintainer = $permissions['give'] && $permissions['upload'] && $permissions['homepage'] && $permissions['access'] && $permissions['server'] && @@ -191,7 +210,9 @@ if ($action == "new_project") { exec("rm -rf '$projdir' '$projwww'"); print $json->encode(array("ok" => sprintf("'%s' deleted.", $project))); } -} else - print $json->encode(array("error" => sprintf("'%s' not implemented.", $action))); + } else { + header('Content-type: text/x-json'); + print $json->encode(array("error" => sprintf("'%s' not implemented.", $action))); + } $db->Close(); ?> ============================================================ --- www/sidebar.js 591674ba9a1f37b50fe779982c88caaca5aa0145 +++ www/sidebar.js db04812a9ddc52a1351c9c9d3ab39e0405182c76 @@ -25,7 +25,9 @@ do_newproj = function() { status("Creating project..."); var args = {'project':getElement('newproject').value}; args.action = "new_project"; + args.render_type = "json"; call_server('proj-ctrl.php', args, "newproj", function(data) { window.location = "projects/" + data.name + "/admin.php"; }); + return false; } ============================================================ --- www/sidebar.php 9622ee994313814de8df8f44aa099e1ea4886e29 +++ www/sidebar.php 661addb051744696769d491796b90c83fd7ab830 @@ -40,8 +40,12 @@ if ($validuser && $level == 'main') { if ($validuser && $level == 'main') { ?>
- - +
+ + + + +