changes & fixes in installer

This commit is contained in:
rahul shukla 2019-03-20 10:29:13 +05:30
parent 7a0d470c20
commit 03e18ca398
10 changed files with 227 additions and 426 deletions

View File

@ -1,18 +1,9 @@
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
</head>
<body>
<div class="container admin" id="admin">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src="Images/logo.svg">
<div class="initial-display">
<p>Admin Details</p>
<form action="AdminConfig.php" method= "POST" id="admin-form">
@ -49,10 +40,6 @@
</form>
</div>
<div class="footer">
<img class="left-patern" src="Images/left-side.svg">
<img class="right-patern" src="Images/right-side.svg">
</div>
</div>
</body>
@ -63,7 +50,6 @@
$.validate({});
</script>
<script>
$(document).ready(function() {
// process the form
@ -77,10 +63,12 @@
'admin_password' : $('input[name=admin_password]').val(),
'admin_re_password' : $('input[name=admin_re_password]').val(),
};
var adminTarget = window.location.href.concat('/AdminConfig.php');
// process the form
$.ajax({
type : 'POST', // define the type of HTTP verb we want to use (POST for our form)
url : 'AdminConfig.php', // the url where we want to POST
url : adminTarget, // the url where we want to POST
data : formData, // our data object
dataType : 'json', // what type of data do we expect back from the server
encode : true

View File

@ -1,112 +0,0 @@
<?php
class Permission {
/**
* @var array
*/
protected $results = [];
/**
* Set the result array permissions and errors.
*
* @return mixed
*/
public function __construct()
{
$this->results['permissions'] = [];
$this->results['errors'] = null;
}
/**
* Check for the folders permissions.
*
* @param array $folders
* @return array
*/
public function check()
{
$folders = [
// 'permissions' => [
'storage/framework/' => '775',
'storage/logs/' => '775',
'bootstrap/cache/' => '775'
// ]
];
foreach($folders as $folder => $permission)
{
if (!($this->getPermission($folder) >= $permission)) {
$this->addFileAndSetErrors($folder, $permission, false);
} else {
$this->addFile($folder, $permission, true);
}
}
return $this->results;
}
/**
* Get a folder permission.
*
* @param $folder
* @return string
*/
private function getPermission($folder)
{
$location = str_replace('\\', '/', getcwd());
$currentLocation = explode("/", $location);
array_pop($currentLocation);
array_pop($currentLocation);
$desiredLocation = implode("/", $currentLocation);
$fileLocation = $desiredLocation . '/' .$folder;
return substr(sprintf('%o', fileperms($fileLocation)), -4);
}
/**
* Add the file to the list of results.
*
* @param $folder
* @param $permission
* @param $isSet
*/
private function addFile($folder, $permission, $isSet)
{
array_push($this->results['permissions'], [
'folder' => $folder,
'permission' => $permission,
'isSet' => $isSet
]);
}
/**
* Add the file and set the errors.
*
* @param $folder
* @param $permission
* @param $isSet
*/
private function addFileAndSetErrors($folder, $permission, $isSet)
{
$this->addFile($folder, $permission, $isSet);
$this->results['errors'] = true;
}
/**
* Render view for class.
*
*/
public function render()
{
ob_start();
$permissions = $this->check();
include __DIR__ . '/../Views/permission.blade.php';
return ob_get_clean();
}
}

View File

@ -1,102 +1,88 @@
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
<link rel="stylesheet" type="text/css" href="CSS/style.css">
</head>
<body>
<div class="container environment" id="environment">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src="Images/logo.svg">
<div class="initial-display">
<p>Environment Configuration</p>
<form action="EnvConfig.php" method="POST" id="environment-form">
<div class="content">
<div class="databse-error" style="text-align: center; padding-top: 10px" id="database_error">
<form action="EnvConfig.php" method="POST" id="environment-form">
<div class="content">
<div class="databse-error" style="text-align: center; padding-top: 10px" id="database_error">
</div>
<div class="form-container" style="padding: 10%; padding-top: 35px">
<div class="control-group" id="app_name">
<label for="app_name" class="required">App Name</label>
<input type = "text" name = "app_name" class = "control"
value = "Bagisto_"
data-validation="required length" data-validation-length="max50"
>
</div>
<div class="form-container" style="padding: 10%; padding-top: 35px">
<div class="control-group" id="app_name">
<label for="app_name" class="required">App Name</label>
<input type = "text" name = "app_name" class = "control"
value = "Bagisto_"
data-validation="required length" data-validation-length="max50"
>
</div>
<div class="control-group" id="app_url">
<label for="app_url" class="required">App URL</label>
<input type="text" name="app_url" class="control"
placeholder="http://localhost"
data-validation="required length" data-validation-length="max50">
</div>
<div class="control-group" id="app_url">
<label for="app_url" class="required">App URL</label>
<input type="text" name="app_url" class="control"
placeholder="http://localhost"
data-validation="required length" data-validation-length="max50">
</div>
<div class="control-group">
<label for="database_connection" class="required">
Database Connection
</label>
<select name="database_connection" id="database_connection" class="control">
<option value="mysql" selected>Mysql</option>
<option value="sqlite">SQlite</option>
<option value="pgsql">pgSQL</option>
<option value="sqlsrv">SQLSRV</option>
</select>
</div>
<div class="control-group">
<label for="database_connection" class="required">
Database Connection
</label>
<select name="database_connection" id="database_connection" class="control">
<option value="mysql" selected>Mysql</option>
<option value="sqlite">SQlite</option>
<option value="pgsql">pgSQL</option>
<option value="sqlsrv">SQLSRV</option>
</select>
</div>
<div class="control-group" id="port_name">
<label for="port_name" class="required">Database Port</label>
<input type="text" name="port_name" class="control"
placeholder="3306"
data-validation="required alphanumeric number length" data-validation-length="max4">
</div>
<div class="control-group" id="port_name">
<label for="port_name" class="required">Database Port</label>
<input type="text" name="port_name" class="control"
placeholder="3306"
data-validation="required alphanumeric number length" data-validation-length="max4">
</div>
<div class="control-group" id="host_name">
<label for="host_name" class="required">Database Host</label>
<input type="text" name="host_name" class="control"
placeholder="127.0.0.1"
data-validation="required length" data-validation-length="max50">
</div>
<div class="control-group" id="host_name">
<label for="host_name" class="required">Database Host</label>
<input type="text" name="host_name" class="control"
placeholder="127.0.0.1"
data-validation="required length" data-validation-length="max50">
</div>
<div class="control-group" id="database_name">
<label for="database_name" class="required">Database Name</label>
<input type="text" name="database_name" class="control"
placeholder="database name"
data-validation="length required" data-validation-length="max50">
</div>
<div class="control-group" id="database_name">
<label for="database_name" class="required">Database Name</label>
<input type="text" name="database_name" class="control"
placeholder="database name"
data-validation="length required" data-validation-length="max50">
</div>
<div class="control-group" id="user_name">
<label for="user_name" class="required">User Name</label>
<input type="text" name="user_name" class="control"
value = "bagisto_"
data-validation="length required" data-validation-length="max50">
</div>
<div class="control-group" id="user_name">
<label for="user_name" class="required">User Name</label>
<input type="text" name="user_name" class="control"
value = "bagisto_"
data-validation="length required" data-validation-length="max50">
</div>
<div class="control-group" id="user_password">
<label for="user_password" class="required">User Password</label>
<input type="text" name="user_password" class="control"
placeholder="database password"
data-validation="length required" data-validation-length="max50">
</div>
<div class="control-group" id="user_password">
<label for="user_password" class="required">User Password</label>
<input type="text" name="user_password" class="control"
placeholder="database password"
data-validation="length required" data-validation-length="max50">
</div>
</div>
<div>
<button class="prepare-btn" id="environment-check">Save & Continue</button>
<div style="cursor: pointer; margin-top:10px">
<span id="envronment-back">back</span>
</div>
</div>
<div>
<button class="prepare-btn" id="environment-check">Save & Continue</button>
<div style="cursor: pointer; margin-top:10px">
<span id="envronment-back">back</span>
</div>
</form>
</div>
</form>
</div>
<div class="footer">
<img class="left-patern" src="Images/left-side.svg">
<img class="right-patern" src="Images/right-side.svg">
</div>
</div>
</body>
@ -128,10 +114,12 @@
};
var target = window.location.href.concat('/EnvConfig.php');
// process the form
$.ajax({
type : 'POST',
url : 'EnvConfig.php',
url : target,
data : formData,
dataType : 'json',
encode : true

View File

@ -1,16 +1,9 @@
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<link rel="stylesheet" type="text/css" href="CSS/style.css">
</head>
<body>
<div class="container finish" id="finish">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src="Images/logo.svg">
<div class="initial-display">
<p>Finish Installment</p>
<div class="content">
<div class="content-container" style="padding: 20px">
@ -23,10 +16,6 @@
<button class="prepare-btn" onclick="finish()">Finish</button>
</div>
<div class="footer">
<img class="left-patern" src="Images/left-side.svg">
<img class="right-patern" src="Images/right-side.svg">
</div>
</div>
</body>
@ -37,8 +26,8 @@
function finish() {
lastIndex = window.location.href.lastIndexOf("/");
secondlast = window.location.href.slice(0,lastIndex).lastIndexOf("/");
next = window.location.href.slice(0,secondlast);
secondlast = window.location.href.slice(0, lastIndex).lastIndexOf("/");
next = window.location.href.slice(0, secondlast);
next = next.concat('/admin/login');
window.location.href = next;
}

View File

@ -1,10 +1,4 @@
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<link rel="stylesheet" type="text/css" href="CSS/style.css">
</head>
<style>
.window {
@ -59,8 +53,7 @@
<body>
<div class="container migration" id="migration">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src="Images/logo.svg">
<div class="initial-display">
<p>Migration & Seed</p>
<div class="cp-spinner cp-round" id="loader">
@ -115,10 +108,6 @@
</form>
</div>
<div class="footer">
<img class="left-patern" src="Images/left-side.svg">
<img class="right-patern" src="Images/right-side.svg">
</div>
</div>
</body>
@ -144,10 +133,12 @@
$('#storage').hide();
$('#composer').hide();
var composerTarget = window.location.href.concat('/Composer.php');
// process form
$.ajax({
type : 'POST',
url : 'Composer.php',
url : composerTarget,
dataType : 'json',
encode : true
})
@ -163,10 +154,12 @@
if (data['install'] == 0) {
$('#composer-migrate').show();
var migrationTarget = window.location.href.concat('/MigrationRun.php');
// post the request again
$.ajax({
type : 'POST',
url : 'MigrationRun.php',
url : migrationTarget,
dataType : 'json',
encode : true
})
@ -178,9 +171,11 @@
if (data['results'] == 0) {
$('#composer-seed').show();
var seederTarget = window.location.href.concat('/Seeder.php');
$.ajax({
type : 'POST',
url : 'Seeder.php',
url : seederTarget,
dataType : 'json',
encode : true
})

View File

@ -6,7 +6,7 @@ $data = array();
// run command on terminal
$key = 'cd ../.. && php artisan key:generate 2>&1';
$seeder = 'cd ../.. && php artisan db:seed 2>&1';
$publish = 'cd ../.. && php artisan vendor:publish 2>&1';
$publish = 'cd ../.. && php artisan vendor:publish --all --force 2>&1';
$key_output = exec($key, $data['key'], $data['key_results']);
$seeder_output = exec($seeder, $data['seeder'], $data['seeder_results']);

View File

@ -1,61 +0,0 @@
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<link rel="stylesheet" type="text/css" href="CSS/style.css">
</head>
<body>
<div class="container permission" id="permission">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src="Images/logo.svg">
<p>Permission</p>
<div class="content">
<div class="title" style="text-align: center; margin-top: 10px">
Please wait while we are checking the permissions
</div>
<?php foreach($permissions['permissions'] as $permission): ?>
<div class="check" style="margin-left: 20%">
<?php if($permission['isSet'] ? $src = 'Images/green-check.svg' : $src = 'Images/red-check.svg' ): ?>
<img src="<?php echo $src ?>">
<?php endif; ?>
<span style="margin-left: 10px"><b><?php echo $permission['folder'] ?></b></span>
<span>(<?php echo $permission['permission'] ?> folder permission Required)</span>
</div>
<?php endforeach; ?>
</div>
<?php if(!isset($permissions['errors'])): ?>
<div>
<button class="prepare-btn" id="permission-check">Continue</button>
</div>
<div style="cursor: pointer; margin-top:10px">
<span id="permission-back">back</span>
</div>
<?php endif; ?>
</div>
<div class="footer">
<img class="left-patern" src="Images/left-side.svg">
<img class="right-patern" src="Images/right-side.svg">
</div>
</div>
</body>
</html>

View File

@ -1,16 +1,16 @@
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<link rel="stylesheet" type="text/css" href="CSS/style.css">
</head>
<?php
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$greenCheck = $actual_link .'/'. 'Images/green-check.svg';
$redCheck = $actual_link .'/'. 'Images/red-check.svg';
?>
<body>
<div class="container requirement" id="requirement">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src="Images/logo.svg">
<div class="initial-display">
<p>Requirement</p>
<div class="content">
@ -19,7 +19,7 @@
</div>
<div class="check" style="margin-left: 25%">
<?php if($phpVersion['supported'] ? $src = 'Images/green-check.svg' : $src = 'Images/red-check.svg' ): ?>
<?php if($phpVersion['supported'] ? $src = $greenCheck : $src = $redCheck): ?>
<img src="<?php echo $src ?>">
<?php endif; ?>
<span style="margin-left: 10px"><b>PHP</b></span>
@ -30,7 +30,7 @@
<?php foreach($requirements['requirements'][$type] as $extention => $enabled) : ?>
<div class="check" style="margin-left: 25%">
<?php if($enabled ? $src = 'Images/green-check.svg' : $src = 'Images/red-check.svg' ): ?>
<?php if($enabled ? $src = $greenCheck : $src = $redCheck ): ?>
<img src="<?php echo $src ?>">
<?php endif; ?>
<span style="margin-left: 10px"><b><?php echo $extention ?></b></span>
@ -49,11 +49,6 @@
<?php endif; ?>
</div>
<div class="footer">
<img class="left-patern" src="Images/left-side.svg">
<img class="right-patern" src="Images/right-side.svg">
</div>
</div>
</body>

View File

@ -1,14 +1,9 @@
<html>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<link rel="stylesheet" type="text/css" href="CSS/style.css">
<body>
<div class="container welcome" id="welcome">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src="Images/logo.svg">
<div class="initial-display">
<p>Welcome to Bagisto</p>
<div class="content">
@ -31,11 +26,6 @@
<button type="button" class="prepare-btn" id="welcome-check">Accept</button>
</div>
</div>
<div class="footer">
<img class="left-patern" src="Images/left-side.svg">
<img class="right-patern" src="Images/right-side.svg">
</div>
</div>
</body>

View File

@ -1,104 +1,133 @@
<?php
// getting env file
$location = str_replace('\\', '/', getcwd());
$currentLocation = explode("/", $location);
array_pop($currentLocation);
array_pop($currentLocation);
$desiredLocation = implode("/", $currentLocation);
$envFile = $desiredLocation . '/' . '.env';
<html>
$installed = false;
if (file_exists($envFile)) {
// reading env content
$str= file_get_contents($envFile);
// converting env content to key/value pair
$data = explode(PHP_EOL,$str);
$databaseArray = ['DB_HOST', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', 'DB_CONNECTION','DB_PORT'];
$key = $value = [];
if ($data) {
foreach ($data as $line) {
$rowValues = explode('=', $line);
if (count($rowValues) === 2) {
if (in_array($rowValues[0], $databaseArray)) {
$key[] = $rowValues[0];
$value[] = $rowValues[1];
}
}
}
}
$databaseData['DB_HOST'] = $databaseData['DB_USERNAME'] = $databaseData['DB_PASSWORD'] = $databaseData['DB_DATABASE'] = $databaseData['DB_CONNECTION'] = $databaseData['DB_PORT'] = '';
$databaseData = array_combine($key, $value);
// getting database info
$servername = $databaseData['DB_HOST'];
$username = $databaseData['DB_USERNAME'];
$password = $databaseData['DB_PASSWORD'];
$dbname = $databaseData['DB_DATABASE'];
$connection = $databaseData['DB_CONNECTION'];
$port = $databaseData['DB_PORT'];
if ($connection == 'mysql') {
@$conn = new mysqli($servername, $username, $password, $dbname, $port);
if (!$conn->connect_error) {
// retrieving admin entry
$sql = "SELECT id, name FROM admins";
$result = $conn->query($sql);
if ($result) {
$installed = true;
}
}
$conn->close();
} else {
$installed = true;
}
}
if (!$installed) {
// including classes
include __DIR__ . '/Classes/Permission.php';
include __DIR__ . '/Classes/Requirement.php';
include __DIR__ . '/Classes/Welcome.php';
// including php files
include __DIR__ . '/Environment.php';
include __DIR__ . '/Migration.php';
include __DIR__ . '/Admin.php';
include __DIR__ . '/Finish.php';
// including js
include __DIR__ . '/JS/script';
// object creation
$requirement = new Requirement();
$permission = new Permission();
$welcome = new Welcome();
// calling render function for template
echo $requirement->render();
echo $permission->render();
echo $welcome->render();
$storage_output = exec('cd ../.. && php artisan storage:link 2>&1');
} else {
// getting url
<?php
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = explode("/", $actual_link);
array_pop($url);
array_pop($url);
$url = implode("/", $url);
$url = $url . '/404';
$cssUrl = $actual_link .'/'. 'CSS/style.css';
$logo = $actual_link .'/'. 'Images/logo.svg';
$leftIcon = $actual_link .'/'. 'Images/left-side.svg';
$rightIcon = $actual_link .'/'. 'Images/right-side.svg';
?>
// redirecting to 404 error page
header("Location: $url");
}
?>
<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Montserrat:400,500">
<title>Bagisto Installer</title>
<link rel="icon" sizes="16x16" href="Images/favicon.ico">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
<link rel="stylesheet" type="text/css" href= "<?php echo $cssUrl; ?> ">
</head>
<body>
<div class="container requirement">
<div class="initial-display" style="padding-top: 100px;">
<img class="logo" src= "<?php echo $logo; ?>" >
</div>
<div class="footer">
<img class="left-patern" src= "<?php echo $leftIcon; ?>" >
<img class="right-patern" src= "<?php echo $rightIcon; ?>" >
</div>
</div>
<?php
// getting env file
$location = str_replace('\\', '/', getcwd());
$currentLocation = explode("/", $location);
array_pop($currentLocation);
array_pop($currentLocation);
$desiredLocation = implode("/", $currentLocation);
$envFile = $desiredLocation . '/' . '.env';
$installed = false;
if (file_exists($envFile)) {
// reading env content
$str= file_get_contents($envFile);
// converting env content to key/value pair
$data = explode(PHP_EOL,$str);
$databaseArray = ['DB_HOST', 'DB_DATABASE', 'DB_USERNAME', 'DB_PASSWORD', 'DB_CONNECTION','DB_PORT'];
$key = $value = [];
if ($data) {
foreach ($data as $line) {
$rowValues = explode('=', $line);
if (count($rowValues) === 2) {
if (in_array($rowValues[0], $databaseArray)) {
$key[] = $rowValues[0];
$value[] = $rowValues[1];
}
}
}
}
$databaseData['DB_HOST'] = $databaseData['DB_USERNAME'] = $databaseData['DB_PASSWORD'] = $databaseData['DB_DATABASE'] = $databaseData['DB_CONNECTION'] = $databaseData['DB_PORT'] = '';
$databaseData = array_combine($key, $value);
// getting database info
$servername = $databaseData['DB_HOST'];
$username = $databaseData['DB_USERNAME'];
$password = $databaseData['DB_PASSWORD'];
$dbname = $databaseData['DB_DATABASE'];
$connection = $databaseData['DB_CONNECTION'];
$port = $databaseData['DB_PORT'];
if ($connection == 'mysql') {
@$conn = new mysqli($servername, $username, $password, $dbname, $port);
if (!$conn->connect_error) {
// retrieving admin entry
$sql = "SELECT id, name FROM admins";
$result = $conn->query($sql);
if ($result) {
$installed = true;
}
}
$conn->close();
} else {
$installed = true;
}
}
if (!$installed) {
// including classes
include __DIR__ . '/Classes/Requirement.php';
// including php files
include __DIR__ . '/Environment.php';
include __DIR__ . '/Migration.php';
include __DIR__ . '/Admin.php';
include __DIR__ . '/Finish.php';
// including js
include __DIR__ . '/JS/script';
// object creation
$requirement = new Requirement();
echo $requirement->render();
$storage_output = exec('cd ../.. && php artisan storage:link 2>&1');
} else {
// getting url
$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$url = explode("/", $actual_link);
array_pop($url);
array_pop($url);
$url = implode("/", $url);
$url = $url . '/404';
// redirecting to 404 error page
header("Location: $url");
}
?>
</body>
</html>