mirror of
https://github.com/xevidos/codiad.git
synced 2024-12-22 13:52:16 +01:00
Refactored install process.
This commit is contained in:
parent
b175a7037e
commit
db5acdd4df
2 changed files with 138 additions and 112 deletions
|
@ -1,8 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Codiad & Kent Safranski (codiad.com), distributed
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), Isaac Brown (telaaedifex.com),
|
||||||
* as-is and without warranty under the MIT License. See
|
* distributed as-is and without warranty under the MIT License. See
|
||||||
* [root]/license.txt for more. This information must remain intact.
|
* [root]/license.txt for more. This information must remain intact.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -10,143 +10,152 @@
|
||||||
// Paths
|
// Paths
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
$path = $_POST['path'];
|
$path = $_POST['path'];
|
||||||
|
|
||||||
$rel = str_replace('/components/install/process.php', '', $_SERVER['REQUEST_URI']);
|
$rel = str_replace( '/components/install/process.php', '', $_SERVER['REQUEST_URI'] );
|
||||||
|
|
||||||
$workspace = $path . "/workspace";
|
$workspace = $path . "/workspace";
|
||||||
$users = $path . "/data/users.php";
|
$users = $path . "/data/users.php";
|
||||||
$projects = $path . "/data/projects.php";
|
$projects = $path . "/data/projects.php";
|
||||||
$active = $path . "/data/active.php";
|
$active = $path . "/data/active.php";
|
||||||
$sessions = $path . "/data/sessions";
|
$sessions = $path . "/data/sessions";
|
||||||
$config = $path . "/config.php";
|
$config = $path . "/config.php";
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Functions
|
// Functions
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
function saveFile($file, $data)
|
function saveFile( $file, $data ) {
|
||||||
{
|
|
||||||
$write = fopen($file, 'w') or die("can't open file");
|
$write = fopen( $file, 'w' ) or die( "can't open file" );
|
||||||
fwrite($write, $data);
|
fwrite( $write, $data );
|
||||||
fclose($write);
|
fclose( $write );
|
||||||
}
|
}
|
||||||
|
|
||||||
function saveJSON($file, $data)
|
function saveJSON( $file, $data ) {
|
||||||
{
|
|
||||||
$data = "<?php/*|\r\n" . json_encode($data) . "\r\n|*/?>";
|
$data = "<?php/*|\r\n" . json_encode( $data ) . "\r\n|*/?>";
|
||||||
saveFile($file, $data);
|
saveFile( $file, $data );
|
||||||
}
|
}
|
||||||
|
|
||||||
function encryptPassword($p)
|
function encryptPassword( $p ) {
|
||||||
{
|
|
||||||
return sha1(md5($p));
|
return sha1( md5( $p ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanUsername($username)
|
function cleanUsername( $username ) {
|
||||||
{
|
|
||||||
return preg_replace('#[^A-Za-z0-9'.preg_quote('-_@. ').']#', '', $username);
|
return preg_replace( '#[^A-Za-z0-9' . preg_quote( '-_@. ' ). ']#', '', $username );
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAbsPath($path)
|
function isAbsPath( $path ) {
|
||||||
{
|
|
||||||
return $path[0] === '/';
|
return $path[0] === '/';
|
||||||
}
|
}
|
||||||
|
|
||||||
function cleanPath($path)
|
function cleanPath( $path ) {
|
||||||
{
|
|
||||||
|
|
||||||
// prevent Poison Null Byte injections
|
// prevent Poison Null Byte injections
|
||||||
$path = str_replace(chr(0), '', $path);
|
$path = str_replace( chr( 0 ), '', $path );
|
||||||
|
|
||||||
// prevent go out of the workspace
|
// prevent go out of the workspace
|
||||||
while (strpos($path, '../') !== false) {
|
while ( strpos( $path, '../' ) !== false ) {
|
||||||
$path = str_replace('../', '', $path);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $path;
|
$path = str_replace( '../', '', $path );
|
||||||
|
}
|
||||||
|
return $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
// Verify no overwrites
|
// Verify no overwrites
|
||||||
//////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
if (!file_exists($users) && !file_exists($projects) && !file_exists($active)) {
|
if ( ( file_exists( $user_settings_file ) || file_exists( $projects_file ) || file_exists( $users_file ) ) || ! ( defined( "DBHOST" ) && defined( "DBNAME" ) && defined( "DBUSER" ) && defined( "DBPASS" ) && defined( "DBTYPE" ) ) ) {
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
// Get POST responses
|
|
||||||
//////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
$username = cleanUsername($_POST['username']);
|
//////////////////////////////////////////////////////////////////
|
||||||
$password = encryptPassword($_POST['password']);
|
// Get POST responses
|
||||||
$project_name = $_POST['project_name'];
|
//////////////////////////////////////////////////////////////////
|
||||||
if (isset($_POST['project_path'])) {
|
|
||||||
$project_path = $_POST['project_path'];
|
|
||||||
} else {
|
|
||||||
$project_path = $project_name;
|
|
||||||
}
|
|
||||||
$timezone = $_POST['timezone'];
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
$username = cleanUsername( $_POST['username'] );
|
||||||
// Create Projects files
|
$password = encryptPassword( $_POST['password'] );
|
||||||
//////////////////////////////////////////////////////////////////
|
$project_name = $_POST['project_name'];
|
||||||
|
if ( isset( $_POST['project_path'] ) ) {
|
||||||
|
|
||||||
$project_path = cleanPath($project_path);
|
$project_path = $_POST['project_path'];
|
||||||
|
} else {
|
||||||
|
|
||||||
if (!isAbsPath($project_path)) {
|
$project_path = $project_name;
|
||||||
$project_path = str_replace(" ", "_", preg_replace('/[^\w-\.]/', '', $project_path));
|
}
|
||||||
mkdir($workspace . "/" . $project_path);
|
$timezone = $_POST['timezone'];
|
||||||
} else {
|
|
||||||
$project_path = cleanPath($project_path);
|
|
||||||
if (substr($project_path, -1) == '/') {
|
|
||||||
$project_path = substr($project_path, 0, strlen($project_path)-1);
|
|
||||||
}
|
|
||||||
if (!file_exists($project_path)) {
|
|
||||||
if (!mkdir($project_path.'/', 0755, true)) {
|
|
||||||
die("Unable to create Absolute Path");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!is_writable($project_path) || !is_readable($project_path)) {
|
|
||||||
die("No Read/Write Permission");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$project_data = array("name"=>$project_name,"path"=>$project_path);
|
|
||||||
|
|
||||||
saveJSON($projects, array($project_data));
|
//////////////////////////////////////////////////////////////////
|
||||||
|
// Create Projects files
|
||||||
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
$project_path = cleanPath( $project_path );
|
||||||
|
|
||||||
|
if ( ! isAbsPath( $project_path ) ) {
|
||||||
|
|
||||||
|
$project_path = str_replace( " ", "_", preg_replace( '/[^\w-\.]/', '', $project_path ) );
|
||||||
|
mkdir( $workspace . "/" . $project_path );
|
||||||
|
} else {
|
||||||
|
|
||||||
|
$project_path = cleanPath( $project_path );
|
||||||
|
if ( substr( $project_path, -1 ) == '/' ) {
|
||||||
|
|
||||||
|
$project_path = substr( $project_path, 0, strlen( $project_path ) - 1 );
|
||||||
|
}
|
||||||
|
if ( ! file_exists( $project_path ) ) {
|
||||||
|
|
||||||
|
if ( ! mkdir( $project_path . '/', 0755, true ) ) {
|
||||||
|
|
||||||
|
die( "Unable to create Absolute Path" );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if ( ! is_writable( $project_path ) || ! is_readable( $project_path ) ) {
|
||||||
|
|
||||||
|
die( "No Read/Write Permission" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$project_data = array("name"=>$project_name,"path"=>$project_path);
|
||||||
|
|
||||||
|
saveJSON($projects, array($project_data));
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create sessions path.
|
* Create sessions path.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ( ! is_dir( $sessions ) ) {
|
if ( ! is_dir( $sessions ) ) {
|
||||||
|
|
||||||
mkdir( $sessions, 00755 );
|
mkdir( $sessions, 00755 );
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Create Users file
|
// Create Users file
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
$user_data = array("username"=>$username,"password"=>$password,"project"=>$project_path);
|
$user_data = array("username"=>$username,"password"=>$password,"project"=>$project_path);
|
||||||
|
|
||||||
saveJSON($users, array($user_data));
|
saveJSON($users, array($user_data));
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Create Active file
|
// Create Active file
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
saveJSON($active, array(''));
|
saveJSON($active, array(''));
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// Create Config
|
// Create Config
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
$config_data = '<?php
|
$config_data = '<?php
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) Codiad & Kent Safranski (codiad.com), Isaac Brown (telaaedifex.com), distributed
|
* Copyright (c) Codiad & Kent Safranski (codiad.com), Isaac Brown (telaaedifex.com),
|
||||||
* as-is and without warranty under the MIT License. See
|
* distributed as-is and without warranty under the MIT License. See
|
||||||
* [root]/license.txt for more. This information must remain intact.
|
* [root]/license.txt for more. This information must remain intact.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -178,6 +187,13 @@ date_default_timezone_set("' . $_POST['timezone'] . '");
|
||||||
// Site Name
|
// Site Name
|
||||||
define("SITE_NAME", "' . $_POST['sitename'] . '");
|
define("SITE_NAME", "' . $_POST['sitename'] . '");
|
||||||
|
|
||||||
|
// Database Information
|
||||||
|
define( "DBHOST", "' . $_POST['dbhost'] . '" );
|
||||||
|
define( "DBNAME", "' . $_POST['dbname'] . '" );
|
||||||
|
define( "DBUSER", "' . $_POST['dbuser'] . '" );
|
||||||
|
define( "DBPASS", "' . $_POST['dbpass'] . '" );
|
||||||
|
define( "DBTYPE", "mysql" );
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
// ** DO NOT EDIT CONFIG BELOW **
|
// ** DO NOT EDIT CONFIG BELOW **
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
@ -196,7 +212,6 @@ define("WSURL", BASE_URL . "/workspace");
|
||||||
//define("MARKETURL", "http://market.codiad.com/json");
|
//define("MARKETURL", "http://market.codiad.com/json");
|
||||||
';
|
';
|
||||||
|
|
||||||
saveFile($config, $config_data);
|
saveFile( $config, $config_data );
|
||||||
|
echo( "success" );
|
||||||
echo("success");
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,6 +156,15 @@ if ($newrelic) {
|
||||||
<input type="text" name="project_name" value="<?php echo($autocomplete['project_name']); ?>">
|
<input type="text" name="project_name" value="<?php echo($autocomplete['project_name']); ?>">
|
||||||
<label><?php i18n("Folder Name or Absolute Path"); ?></label>
|
<label><?php i18n("Folder Name or Absolute Path"); ?></label>
|
||||||
<input type="text" name="project_path" value="<?php echo($autocomplete['project_path']); ?>">
|
<input type="text" name="project_path" value="<?php echo($autocomplete['project_path']); ?>">
|
||||||
|
|
||||||
|
<label><?php i18n("Database Host"); ?></label>
|
||||||
|
<input type="text" name="dbhost" value="<?php echo($autocomplete['dbhost']); ?>">
|
||||||
|
<label><?php i18n("Database Name"); ?></label>
|
||||||
|
<input type="text" name="dbname" value="<?php echo($autocomplete['dbname']); ?>">
|
||||||
|
<label><?php i18n("Database User"); ?></label>
|
||||||
|
<input type="text" name="dbuser" value="<?php echo($autocomplete['dbuser']); ?>">
|
||||||
|
<label><?php i18n("Database Pass"); ?></label>
|
||||||
|
<input type="text" name="dbpass" value="<?php echo($autocomplete['dbpass']); ?>">
|
||||||
<hr>
|
<hr>
|
||||||
<?php
|
<?php
|
||||||
$location = array(
|
$location = array(
|
||||||
|
@ -266,6 +275,8 @@ if ($newrelic) {
|
||||||
?>
|
?>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<button><?php i18n("Install"); ?></button>
|
<button><?php i18n("Install"); ?></button>
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
|
|
Loading…
Reference in a new issue