WIP: add xshop installer steps [packacges, env, database, reweite]

main
A1Gard 5 months ago
parent 44e5bd3f6e
commit 099b150992

1402
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -0,0 +1,405 @@
<?php @require_once __DIR__ . '/sections/header.php'; ?>
<?php
function curlGet($url) {
$curl = curl_init();
// Set the cURL options
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 5); //timeout in seconds
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt ($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
// Execute the cURL request
$result = curl_exec($curl);
// Close cURL session
curl_close($curl);
if(curl_error($curl)) {
echo 'Curl error: ' . curl_error($curl);
}
return $result;
}
function parseEnv($file){
// parse env file
$envData = file_get_contents($file);
$envData = explode(PHP_EOL, $envData);
$envVars = [];
foreach ($envData as $line) {
$l = explode('=', $line);
if (count($l) > 1 && $line[0] != '#') {
$envVars[trim($l[0])] = trim($l[1], '" ');
}
}
return $envVars;
}
function makeEnv($file,$data)
{
$env = '';
$lkey = 'A';
foreach ($data as $k => $item){
if ($k[0] !== $lkey){
$env.= PHP_EOL.PHP_EOL;
$lkey = $k[0];
}
$env .= $k .'="'.$item.'"'.PHP_EOL;
}
return file_put_contents($file,$env);
}
$hasPackage = is_dir(__DIR__ . '/../vendor') && is_dir(__DIR__ . '/../vendor/xmen/starter-kit/');
if (isset($_GET['download']) && !$hasPackage) {
/**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
'https://github.com/A1Gard/xshop-installer-assets/raw/master/vendor.zip');
/**
* Create a new file
*/
$fp = fopen(__DIR__ . '/../file.zip', 'w');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec($ch);
/**
* Close cURL session and file
*/
curl_close($ch);
fclose($fp);
$zip = new ZipArchive;
$res = $zip->open(__DIR__ . '/../file.zip');
if ($res === TRUE) {
$zip->extractTo(__DIR__ . '/..');
$zip->close();
$hasPackage = true;
} else {
die('unzip error!');
}
unlink(__DIR__ . '/../file.zip');
}
if (isset($_POST['dbname'])){
$env = parseEnv(__DIR__ . '/../.env.example');
$env['DB_HOST'] = $_POST['host'];
$env['DB_DATABASE'] = $_POST['dbname'];
$env['DB_USERNAME'] = $_POST['user'];
$env['DB_PASSWORD'] = $_POST['passwd'];
makeEnv(__DIR__ . '/../.env',$env);
}
?>
<h2>
Requrirment check
</h2>
<?php if (PHP_MAJOR_VERSION >= 8 && PHP_MINOR_VERSION > 0): ?>
<div class="msg success">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11.0026 16L6.75999 11.7574L8.17421 10.3431L11.0026 13.1716L16.6595 7.51472L18.0737 8.92893L11.0026 16Z"></path>
</svg>
<span>
PHP Version check <b>8.1 or Above</b>
</span>
</div>
<?php else: ?>
<div class="msg error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z"></path>
</svg>
<span>
PHP version check <b>8.1 or Above</b>
<br>
Your php version is <b><?php echo PHP_VERSION; ?></b>
</span>
</div>
<?php endif; ?>
<?php
$exts = get_loaded_extensions();
$ourRequriedExts = ['pdo_mysql', 'sqlite3', 'soap', 'zip', 'gd', 'mbstring', 'xml', 'curl', 'json', 'fileinfo', 'bcmath'];
// print_r($exts);
$have = [];
$haveNot = [];
foreach ($ourRequriedExts as $ext) {
if (in_array($ext, $exts)) {
$have[] = $ext;
} else {
$haveNot[] = $ext;
}
}
?>
<?php if (count($have) > 0): ?>
<div class="msg success">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11.0026 16L6.75999 11.7574L8.17421 10.3431L11.0026 13.1716L16.6595 7.51472L18.0737 8.92893L11.0026 16Z"></path>
</svg>
<span>
PHP extentions not installed:
<b>
<?php foreach ($have as $item) {
echo $item . ', ';
} ?>
</b>
</span>
</div>
<?php endif; ?>
<?php if (count($haveNot) > 0): ?>
<div class="msg error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z"></path>
</svg>
<span>
PHP extentions not installed:
<b>
<?php foreach ($haveNot as $item) {
echo $item . ', ';
} ?>
</b>
</span>
</div>
<?php endif; ?>
<?php
const TMPDIR = __DIR__ . '/../tempCheck';
echo is_dir(TMPDIR) ? rmdir(TMPDIR) : '';
$writeAcess = mkdir(TMPDIR);
rmdir(TMPDIR);
if ($writeAcess):
?>
<div class="msg success">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11.0026 16L6.75999 11.7574L8.17421 10.3431L11.0026 13.1716L16.6595 7.51472L18.0737 8.92893L11.0026 16Z"></path>
</svg>
<span>
Write permission!
</span>
</div>
<?php else: ?>
<div class="msg error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z"></path>
</svg>
<span>
Write permission problem:
<b>
<?php echo substr(__DIR__, 0, -10); ?>
</b>
</span>
</div>
<?php endif; ?>
<?php if ($hasPackage): ?>
<div class="msg success">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11.0026 16L6.75999 11.7574L8.17421 10.3431L11.0026 13.1716L16.6595 7.51472L18.0737 8.92893L11.0026 16Z"></path>
</svg>
<span>
Packages already installed
</span>
</div>
<script>
window.addEventListener('load', function () {
let p = 25;
document.querySelector('#percent').innerText = p;
document.querySelector('#bar').style.width = p + '%';
});
</script>
<?php else: ?>
<a class="btn btn-next" href="?download">
install packages
</a>
<?php endif; ?>
<?php
$envInvalid = false;
if (file_exists(__DIR__ . '/../.env')) {
$envVars = parseEnv(__DIR__ . '/../.env');
try {
//...
$dbh = new PDO('mysql:host=' . $envVars['DB_HOST'] . ';dbname=' . $envVars['DB_DATABASE'], $envVars['DB_USERNAME'],
$envVars['DB_PASSWORD']);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// var_dump($dbh);
} catch (PDOException $e) {
// Display a message and log the exception.
// exit();
$envInvalid = true;
}
}else{
$envVars = parseEnv(__DIR__ . '/../.env.example');
$envInvalid = true;
}
if($envInvalid):
?>
<div class="msg error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z"></path>
</svg>
<span>
You need modify database connection
</span>
</div>
<form action="" method="post">
<label>
Host:
<br>
<input type="text" name="host" value="<?php echo $envVars['DB_HOST']; ?>" >
</label>
<label>
Database name:
<br>
<input type="text" name="dbname" value="<?php echo $envVars['DB_DATABASE']; ?>" >
</label>
<label>
Database user:
<br>
<input type="text" name="user" value="<?php echo $envVars['DB_USERNAME']; ?>" >
</label>
<label>
Database password:
<br>
<input type="password" name="passwd" value="<?php echo $envVars['DB_PASSWORD']; ?>" >
</label>
<button class="btn">
Save
</button>
</form>
<?php else: ?>
<div class="msg success">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM11.0026 16L6.75999 11.7574L8.17421 10.3431L11.0026 13.1716L16.6595 7.51472L18.0737 8.92893L11.0026 16Z"></path>
</svg>
<span>
Database connection is OK!
</span>
</div>
<script>
window.addEventListener('load', function () {
let p = 37;
document.querySelector('#percent').innerText = p;
document.querySelector('#bar').style.width = p + '%';
});
</script>
<!--<pre>-->
<?php
if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') {
$url = "https://";
} else {
$url = "http://";
}
$url .= $_SERVER['HTTP_HOST']. substr($_SERVER['REQUEST_URI'],0,-13).'work';
// echo $url;
// $response = curlGet( $url );
// print_r($_SERVER);
// echo $response;
?>
<input type="hidden" id="url" value="<?php echo $url;?>">
<div id="config">
<div class="msg error">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
<path
d="M12 22C6.47715 22 2 17.5228 2 12C2 6.47715 6.47715 2 12 2C17.5228 2 22 6.47715 22 12C22 17.5228 17.5228 22 12 22ZM12 20C16.4183 20 20 16.4183 20 12C20 7.58172 16.4183 4 12 4C7.58172 4 4 7.58172 4 12C4 16.4183 7.58172 20 12 20ZM12 10.5858L14.8284 7.75736L16.2426 9.17157L13.4142 12L16.2426 14.8284L14.8284 16.2426L12 13.4142L9.17157 16.2426L7.75736 14.8284L10.5858 12L7.75736 9.17157L9.17157 7.75736L12 10.5858Z"></path>
</svg>
<span>
Rewrite error:
</span>
</div>
Your server is : <?php echo $_SERVER['SERVER_SOFTWARE']; ?>
<ul>
<li>
If you use `PHP`, restart laravel
</li>
<li>
If you use `Apache`, your public_html has problem
</li>
<li>
If you use `NGINX`, active this rewrite on domain config, then restart server:
<code>
rewrite ^/(.*)$ /index.php/$1 last;
</code>
</li>
</ul>
<a href="?" class="btn" >
Re-check
</a>
</div>
<a href="<?php echo substr($url,0,-7);?>" class="btn" id="continue">
Continue
</a>
<script>
url = document.querySelector('#url').value;
async function getURL(url) {
try {
const response = await fetch(url);
if(!response.ok) {
throw new Error(response.statusText);
}
return response.text();
} catch(error) {
throw error;
}
}
// Usage:
getURL(url)
.then(response => {
// Do something with response
if (response.trim() === 'work!'){
document.querySelector('#config').remove();
window.addEventListener('load', function () {
let p = 50;
document.querySelector('#percent').innerText = p;
document.querySelector('#bar').style.width = p + '%';
});
}else{
document.querySelector('#continue').remove();
}
})
.catch(error => {
console.error(error);
document.querySelector('#continue').remove();
});
</script>
<?php endif; ?>
<!--</pre>-->
<?php @require_once __DIR__ . '/sections/footer.php'; ?>

File diff suppressed because one or more lines are too long

@ -0,0 +1,175 @@
<?php
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
?><!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>xShop installer</title>
<link href="https://cdn.jsdelivr.net/gh/rastikerdar/vazirmatn@v33.003/Vazirmatn-font-face.css" rel="stylesheet"
type="text/css"/>
<style>
* {
font-family: Vazirmatn, sans-serif;
margin: 0;
padding: 0;
}
body {
background: #282c34;
color: white;
}
h1, h2, h3, h4 {
font-weight: 200;
}
svg {
width: 75%;
height: auto;
}
h2 {
color: red;
padding: .5rem;
border-bottom: 1px solid darkred;
margin-bottom: 1rem;
}
b {
color: yellow;
}
form{
padding: .5rem 1.5rem;
}
ul{
padding: 2rem;
}
li{
margin-bottom: 1rem;
}
code{
background: #111;
padding: 1rem;
display: block;
margin-top: 1rem;
}
input{
border: 0;
border-bottom: 1px solid white;
background: #ffffff77;
display: block;
padding: 2px;
width: 100%;
margin-bottom: 7px;
}
#installer {
display: grid;
grid-template-columns: repeat(2, 1fr);
min-height: 100vh;
}
#installer > div {
padding: 1rem;
}
#installer > div:first-child {
background: #1b2739;
}
#installer > div:last-child {
text-align: center;
}
#progress {
width: 95%;
border: 1px solid darkred;
border-radius: 5px;
padding: 2px;
box-shadow: 0 0 7px darkred;
}
#bar {
width: 10%;
font-size: 17px;
margin: 0;
background: red;
border-radius: 5px;
text-align: center;
}
#percent {
display: inline-flex;
align-items: center;
justify-self: center;
padding-top: 3px;
color: white;
}
#percent:after {
content: "%";
/*mix-blend-mode: difference;*/
color: white;
}
#config{
background: #00000022;
padding: 1rem;
}
.success {
background: rgba(0, 255, 0, 0.3);
}
.error {
background: rgba(255, 0, 0, 0.3);
}
.msg {
padding: .5rem 1rem;
border-radius: 5px;
display: flex;
align-items: center;
justify-self: start;
margin-bottom: 5px;
}
.msg svg {
fill: white;
width: 25px;
height: 25px;
margin-right: 2rem;
}
.btn{
padding: 7px;
display: block;
background: transparent;
margin: 1rem auto;
width: 50%;
text-align: center;
border: 1px solid white;
border-radius: 5px;
cursor: pointer;
color: #FFFFFF;
text-decoration: none;
}
.btn:hover{
background: #ffffff33;
}
</style>
</head>
<body>
<div id="installer">
<div id="content">

@ -0,0 +1,3 @@
<?php
require_once './../../installer/installer.php';

@ -19,6 +19,10 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('/test/laravel', function () {
return 'work!';
});
Route::get('/clear', function () {
Artisan::call('cache:clear');
@ -33,6 +37,5 @@ Route::get('/clear', function () {
Route::prefix('v1')->name('v1.')->group(
function () {
Route::get('index', [\App\Http\Controllers\Api\ApiV1Controller::class,'index'])->name('index');
});

Loading…
Cancel
Save