2011-12-20 15:38:43 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class Core {
|
|
|
|
|
|
|
|
// Function to validate the post data
|
|
|
|
function validate_post($data)
|
|
|
|
{
|
|
|
|
// Counter variable
|
|
|
|
$counter = 0;
|
|
|
|
|
|
|
|
// Validate the hostname
|
2021-07-20 18:22:39 +00:00
|
|
|
if(isset($data['hostname']) AND !empty($data['hostname'])) {
|
2011-12-20 15:38:43 +00:00
|
|
|
$counter++;
|
|
|
|
}
|
|
|
|
// Validate the username
|
|
|
|
if(isset($data['username']) AND !empty($data['username'])) {
|
|
|
|
$counter++;
|
|
|
|
}
|
|
|
|
// Validate the password
|
|
|
|
if(isset($data['password']) AND !empty($data['password'])) {
|
|
|
|
// pass
|
|
|
|
}
|
|
|
|
// Validate the database
|
|
|
|
if(isset($data['database']) AND !empty($data['database'])) {
|
|
|
|
$counter++;
|
|
|
|
}
|
|
|
|
|
2021-07-20 19:31:48 +00:00
|
|
|
if($data['directory'] != "") {
|
2021-10-09 13:25:10 +00:00
|
|
|
if (file_exists($_SERVER['DOCUMENT_ROOT'].$data['directory'])) {
|
2021-07-20 19:31:48 +00:00
|
|
|
//pass folders real
|
|
|
|
$counter++;
|
|
|
|
} else {
|
|
|
|
echo "Directory ".$data['directory']." cannot be found";
|
|
|
|
exit;
|
|
|
|
}
|
2021-07-25 21:42:26 +00:00
|
|
|
} else {
|
|
|
|
$counter++;
|
2021-07-20 19:31:48 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 15:38:43 +00:00
|
|
|
// Check if all the required fields have been entered
|
2021-07-20 19:31:48 +00:00
|
|
|
if($counter == '4') {
|
2011-12-20 15:38:43 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to show an error
|
|
|
|
function show_message($type,$message) {
|
|
|
|
return $message;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to write the config file
|
|
|
|
function write_config($data) {
|
|
|
|
|
|
|
|
// Config path
|
|
|
|
$template_path = 'config/database.php';
|
2021-10-09 13:25:10 +00:00
|
|
|
$output_path = $_SERVER['DOCUMENT_ROOT'].$data['directory'].'/application/config/database.php';
|
2011-12-20 15:38:43 +00:00
|
|
|
|
|
|
|
// Open the file
|
|
|
|
$database_file = file_get_contents($template_path);
|
|
|
|
|
|
|
|
$new = str_replace("%HOSTNAME%",$data['hostname'],$database_file);
|
|
|
|
$new = str_replace("%USERNAME%",$data['username'],$new);
|
|
|
|
$new = str_replace("%PASSWORD%",$data['password'],$new);
|
|
|
|
$new = str_replace("%DATABASE%",$data['database'],$new);
|
|
|
|
|
|
|
|
// Write the new database.php file
|
|
|
|
$handle = fopen($output_path,'w+');
|
|
|
|
|
|
|
|
// Chmod the file, in case the user forgot
|
|
|
|
@chmod($output_path,0777);
|
|
|
|
|
|
|
|
// Verify file permissions
|
|
|
|
if(is_writable($output_path)) {
|
|
|
|
|
|
|
|
// Write the file
|
|
|
|
if(fwrite($handle,$new)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Function to write the config file
|
|
|
|
function write_configfile($data) {
|
|
|
|
|
|
|
|
// Config path
|
|
|
|
$template_path = 'config/config.php';
|
2021-10-09 13:25:10 +00:00
|
|
|
$output_path = $_SERVER['DOCUMENT_ROOT'].$data['directory'].'/application/config/config.php';
|
2011-12-20 15:38:43 +00:00
|
|
|
|
|
|
|
// Open the file
|
|
|
|
$database_file = file_get_contents($template_path);
|
|
|
|
|
|
|
|
$new = str_replace("%baselocator%",$data['locator'],$database_file);
|
|
|
|
$new = str_replace("%websiteurl%",$data['websiteurl'],$new);
|
|
|
|
$new = str_replace("%directory%",$data['directory'],$new);
|
|
|
|
|
|
|
|
// Write the new config.php file
|
|
|
|
$handle = fopen($output_path,'w+');
|
|
|
|
|
|
|
|
// Chmod the file, in case the user forgot
|
|
|
|
@chmod($output_path,0777);
|
|
|
|
|
|
|
|
// Verify file permissions
|
|
|
|
if(is_writable($output_path)) {
|
|
|
|
|
|
|
|
// Write the file
|
|
|
|
if(fwrite($handle,$new)) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2023-08-15 19:59:56 +00:00
|
|
|
?>
|