2018-07-13 18:39:55 +02:00
|
|
|
<?php
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
|
|
|
* as-is and without warranty under the MIT License. See
|
|
|
|
* [root]/license.txt for more. This information must remain intact.
|
|
|
|
*/
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
require_once('../../common.php');
|
|
|
|
require_once('./class.project.php');
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Verify Session or Key
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
checkSession();
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
$Project = new Project();
|
2018-12-12 16:30:14 +01:00
|
|
|
$Project->projects = $Project->get_projects();
|
2018-07-13 18:39:55 +02:00
|
|
|
|
Changed $path to __DIR__ for config location, Updated auto reload variables, Removed unload listener for auto reload, Changed project default to array so that if no projects exist the program does not crash, Updated autosave to use let instead of vars, Fixed capitalization for sideExpanded variable, Added try catch to pdo initialization on install, Added more error checks on install, Removed password function on install query, Changed default settings array, Added loading div to user delete, Updated queries that threw errors when a default value was zero, Added blank username and password check,
2019-02-09 22:14:27 +01:00
|
|
|
if( ! is_array( $Project->projects ) ) {
|
|
|
|
|
|
|
|
$Project->projects = array();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-11-19 19:30:49 +01:00
|
|
|
if( $_GET['action'] == 'add_user' ) {
|
|
|
|
|
|
|
|
$invalid_users = array(
|
|
|
|
"",
|
|
|
|
"null",
|
|
|
|
"undefined"
|
|
|
|
);
|
|
|
|
|
2019-07-01 15:24:34 +02:00
|
|
|
if( ! isset( $_GET['access'] ) || in_array( $_GET['access'], $invalid_users ) || ! in_array( $_GET['access'], array_keys( Permissions::LEVELS ) ) ) {
|
2018-11-19 19:30:49 +01:00
|
|
|
|
2019-07-02 22:46:32 +02:00
|
|
|
exit( formatJSEND( "error", "No access set." ) );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$Project->access = Permissions::LEVELS[$_GET['access']];
|
2019-07-01 15:24:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if( isset( $_GET['username'] ) && ! in_array( $_GET['username'], $invalid_users ) ) {
|
|
|
|
|
2018-11-19 19:30:49 +01:00
|
|
|
$Project->user = $_GET['username'];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo formatJSEND( "error", "No username set." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $_GET['project_path'] != '' ) {
|
|
|
|
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo formatJSEND( "error", "No project path set." );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $Project->check_owner( $_GET["project_path"], true ) ) {
|
|
|
|
|
|
|
|
$Project->add_user();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo formatJSEND( "error", "You can not manage this project." );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-11-10 06:41:28 +01:00
|
|
|
// Create Project
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
if( $_GET['action'] == 'create' ) {
|
|
|
|
|
|
|
|
$Project->name = $_GET['project_name'];
|
|
|
|
|
|
|
|
if( $_GET['public_project'] == 'true' ) {
|
|
|
|
|
|
|
|
$Project->public_project = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $_GET['project_path'] != '' ) {
|
|
|
|
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
$Project->path = $_GET['project_name'];
|
|
|
|
}
|
|
|
|
// Git Clone?
|
|
|
|
if( ! empty( $_GET['git_repo'] ) ) {
|
|
|
|
|
|
|
|
$Project->gitrepo = $_GET['git_repo'];
|
|
|
|
$Project->gitbranch = $_GET['git_branch'];
|
|
|
|
}
|
|
|
|
$Project->Create();
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Return Current
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-10-11 16:17:41 +02:00
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
if( $_GET['action'] == 'current' ) {
|
|
|
|
|
|
|
|
if( isset( $_SESSION['project'] ) ) {
|
|
|
|
|
|
|
|
echo formatJSEND( "success", $_SESSION['project'] );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
echo formatJSEND( "error", "No Project Returned" );
|
|
|
|
}
|
2018-10-11 16:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-11-10 06:41:28 +01:00
|
|
|
// Delete Project
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
if( $_GET['action'] == 'delete' ) {
|
|
|
|
|
2019-07-01 15:24:34 +02:00
|
|
|
if( isset( $_GET['project_path'] ) ) {
|
2018-11-10 06:41:28 +01:00
|
|
|
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
$Project->Delete();
|
|
|
|
}
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-11-10 06:41:28 +01:00
|
|
|
// Get Project Access
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
if( $_GET['action'] == 'get_access' ) {
|
|
|
|
|
2019-07-02 22:46:32 +02:00
|
|
|
$access = $Project->get_access( $_GET['project_id'] );
|
2018-11-10 06:41:28 +01:00
|
|
|
echo formatJSEND( "success", $access );
|
2018-10-11 16:17:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-11-10 06:41:28 +01:00
|
|
|
// Get Current Project
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
$no_return = false;
|
|
|
|
if( isset( $_GET['no_return'] ) ) {
|
|
|
|
|
|
|
|
$no_return = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( $_GET['action'] == 'get_current' ) {
|
|
|
|
|
|
|
|
if( ! isset( $_SESSION['project'] ) ) {
|
|
|
|
|
|
|
|
// Load default/first project
|
|
|
|
if( $no_return ) {
|
|
|
|
|
|
|
|
$Project->no_return = true;
|
|
|
|
}
|
|
|
|
$Project->GetFirst();
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Load current
|
|
|
|
$Project->path = $_SESSION['project'];
|
|
|
|
$project_name = $Project->GetName();
|
|
|
|
if( ! $no_return ) {
|
|
|
|
|
|
|
|
echo formatJSEND( "success", array( "name" => $project_name, "path" => $_SESSION['project'] ) );
|
|
|
|
}
|
|
|
|
}
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-11-10 06:41:28 +01:00
|
|
|
// Check Project Owner
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
if( $_GET['action'] == 'get_owner' ) {
|
|
|
|
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
$owner = $Project->get_owner();
|
|
|
|
try {
|
|
|
|
|
|
|
|
$return = json_decode( $owner );
|
|
|
|
exit( formatJSEND( "error", null ) );
|
|
|
|
} catch( exception $e ) {
|
|
|
|
|
|
|
|
exit( formatJSEND( "success", array( "owner" => $owner ) ) );
|
|
|
|
}
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
|
|
|
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-11-10 06:41:28 +01:00
|
|
|
// Open Project
|
2018-10-11 16:17:41 +02:00
|
|
|
//////////////////////////////////////////////////////////////////
|
2018-07-13 18:39:55 +02:00
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
if( $_GET['action'] == 'open' ) {
|
|
|
|
|
2019-07-02 22:46:32 +02:00
|
|
|
if( isset( $_GET['path'] ) && Permissions::has_read( $_GET['path'] ) ) {
|
2018-11-10 06:41:28 +01:00
|
|
|
|
|
|
|
die( formatJSEND( "error", "No Access to path " . $_GET['path'] ) );
|
|
|
|
}
|
|
|
|
$Project->path = $_GET['path'];
|
|
|
|
$Project->Open();
|
2018-10-11 16:17:41 +02:00
|
|
|
}
|
2018-11-10 06:41:28 +01:00
|
|
|
|
2018-11-19 19:30:49 +01:00
|
|
|
if( $_GET['action'] == 'remove_user' ) {
|
|
|
|
|
|
|
|
$invalid = array(
|
|
|
|
"",
|
|
|
|
"null",
|
|
|
|
"undefined"
|
|
|
|
);
|
|
|
|
|
|
|
|
if( ! in_array( $_GET['username'], $invalid ) ) {
|
|
|
|
|
|
|
|
$Project->user = $_GET['username'];
|
|
|
|
} else {
|
|
|
|
|
2019-07-02 22:46:32 +02:00
|
|
|
exit( formatJSEND( "error", "No username set." ) );
|
2018-11-19 19:30:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( ! in_array( $_GET['project_path'], $invalid ) ) {
|
|
|
|
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
} else {
|
|
|
|
|
2019-07-02 22:46:32 +02:00
|
|
|
exit( formatJSEND( "error", "No project path set." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ! in_array( $_GET['project_id'], $invalid ) ) {
|
|
|
|
|
|
|
|
$Project->project_id = $_GET['project_id'];
|
|
|
|
} else {
|
|
|
|
|
|
|
|
exit( formatJSEND( "error", "No project id set." ) );
|
2018-11-19 19:30:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if( $Project->check_owner( $_GET["project_path"], true ) ) {
|
|
|
|
|
|
|
|
$Project->remove_user();
|
|
|
|
} else {
|
|
|
|
|
2019-07-02 22:46:32 +02:00
|
|
|
exit( formatJSEND( "error", "You can not manage this project." ) );
|
2018-11-19 19:30:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-10 06:41:28 +01:00
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
// Rename Project
|
|
|
|
//////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
if( $_GET['action'] == 'rename' ) {
|
|
|
|
|
2019-07-01 15:24:34 +02:00
|
|
|
if( ! isset( $_GET['project_path'] ) || ! Permissions::has_owner( $_GET['project_path'] ) ) {
|
2018-11-10 06:41:28 +01:00
|
|
|
|
|
|
|
die( formatJSEND( "error", "No Access" ) );
|
|
|
|
}
|
|
|
|
$Project->path = $_GET['project_path'];
|
|
|
|
$Project->Rename();
|
2018-07-13 18:39:55 +02:00
|
|
|
}
|
2018-11-10 06:41:28 +01:00
|
|
|
|