Browse Source

Starting installer script

1Day 3 years ago
parent
commit
b599f3d61f
3 changed files with 232 additions and 11 deletions
  1. 30 0
      public/install/forms.php
  2. 63 3
      public/install/functions.php
  3. 139 8
      public/install/index.php

+ 30 - 0
public/install/forms.php

@@ -0,0 +1,30 @@
+<?php 
+include("functions.php");
+
+if(isset($_POST['checkDB'])){
+
+        $values = [
+            //SETTINGS::VALUE => REQUEST-VALUE (coming from the html-form)
+            "DB_HOST" => "databasehost",
+            "DB_DATABASE" => "database",
+            "DB_USERNAME" => "databaseuser",
+            "DB_PASSWORD" => "databaseuserpass",
+            "DB_PORT" => "databaseport",
+            "DB_CONNECTION" => "databasedriver"
+        ];
+
+
+
+		$db = new mysqli($_POST["databasehost"], $_POST["databaseuser"], $_POST["databaseuserpass"], $_POST["database"], $_POST["databaseport"]);
+			if ($db->connect_error) {
+				header("LOCATION: index.php?step=2&message=Could not connect to the Database");	
+				die();
+			}
+			foreach ($values as $key => $value) {
+            	$param = $_POST[$value];
+            setEnvironmentValue($key, $param);
+        }
+			header("LOCATION: index.php?step=3");	
+		
+	}
+?>

+ 63 - 3
public/install/functions.php

@@ -1,30 +1,70 @@
 <?php 
 
 
-$required_extentions=array("cli_server","openssl","gd","mysql","PDO","mbstring","tokenizer","bcmath","xml","curl","zip","fpm");
+$required_extentions=array("openssl","gd","mysql","PDO","mbstring","tokenizer","bcmath","xml","curl","zip","fpm");
 
+$requirements = [
+	"php"=> "7.4",
+	"mysql"=>"5.7.22",
 
 
+];
+
 function checkPhpVersion(){
-	if (version_compare(phpversion(), '7.0', '>=')){
+	global $requirements;
+	if (version_compare(phpversion(), $requirements["php"], '>=')){
 		return "OK";
 	}
 	return "not OK";
 }
 
 function getMySQLVersion() { 
+	global $requirements;
 
   $output = shell_exec('mysql -V'); 
   preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); 
 
   $versionoutput = $version[0] ?? "0";
 
-  return ($versionoutput > 5 ? "OK":"not OK");; 
+  return ($versionoutput > $requirements["mysql"] ? "OK":"not OK");; 
+}
+
+function getZipVersion() { 
+	global $requirements;
+
+  $output = shell_exec('zip  -v'); 
+  preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); 
+
+  $versionoutput = $version[0] ?? 0;
+
+  return ($versionoutput!=0 ? "OK":"not OK");; 
+}
+
+function getGitVersion() { 
+	global $requirements;
+
+  $output = shell_exec('git  --version'); 
+  preg_match('@[0-9]+\.[0-9]+\.[0-9]+@', $output, $version); 
+
+  $versionoutput = $version[0] ?? 0;
+
+  return ($versionoutput!=0 ? "OK":"not OK");; 
 }
 
+function getTarVersion() { 
+	global $requirements;
+
+  $output = shell_exec('tar  --version'); 
+  preg_match('@[0-9]+\.[0-9]+@', $output, $version); 
+
+  $versionoutput = $version[0] ?? 0;
+
+  return ($versionoutput!=0 ? "OK":"not OK");; 
+}
 
 function checkExtensions(){
 	global $required_extentions;
+
 	$not_ok = [];
 	$extentions = get_loaded_extensions();
 
@@ -37,4 +77,24 @@ function checkExtensions(){
 
 }
 
+    function setEnvironmentValue($envKey, $envValue)
+    {
+
+        $envFile = dirname(__FILE__,3)."/.env";
+        $str = file_get_contents($envFile);
+
+        $str .= "\n"; // In case the searched variable is in the last line without \n
+        $keyPosition = strpos($str, "{$envKey}=");
+        $endOfLinePosition = strpos($str, PHP_EOL, $keyPosition);
+        $oldLine = substr($str, $keyPosition, $endOfLinePosition - $keyPosition);
+        $str = str_replace($oldLine, "{$envKey}={$envValue}", $str);
+        $str = substr($str, 0, -1);
+
+        $fp = fopen($envFile, 'w');
+        fwrite($fp, $str);
+        fclose($fp);
+    }
+
+
+
 ?>

+ 139 - 8
public/install/index.php

@@ -1,19 +1,150 @@
 <?php
 include ("functions.php");
+?>
 
+<html>
+  <head>
+    <title>Controlpanel.gg installer Script</title>
+	<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
+    <style>
+		body {background-color: powderblue;}
 
-echo "php version: ".checkPhpVersion();
+		.card {
+    position: absolute;
+    top: 50%;
+    left: 50%;
+    margin-right: -50%;
+    transform: translate(-50%, -50%);
+		}
+		.ok{
+			color: green;
+		}
+		.ok::before{
+			 content: "✔️";
+		}
+		.notok{
+			color: red;
+		}
+		.notok::before{
+			 content: "❌";
+		}
+	</style>
+  </head>
+  <body>
 
-echo "<br/>";
+<?php if(!isset($_GET['step'])){ ?>
+        <div class="card card-outline card-primary">
+            <div class="card-header text-center">
+                <b class="mr-1">Controlpanel.GG</b>
+            </div>
 
-echo "mysql version: ".getMySQLVersion();
+                <div class="card-body">
+                    <p class="login-box-msg">This installer will lead you through the most crucial Steps of Controlpanel.gg`s setup</p>
 
-echo "<br/>";
+                    <p class="<?php print(checkPhpVersion()==="OK"?"ok":"notok");?>">  php version: <?php echo phpversion();?> (required <?php echo $requirements["php"];?>)</p>
+                    <p class="<?php print(getMySQLVersion()==="OK"?"ok":"notok");?>">  mysql version: <?php echo getMySQLVersion();?> (required <?php echo $requirements["mysql"];?>)</p>
 
-echo "Missing extentions: "; foreach(checkExtensions() as $ext){ echo $ext.", ";};
+                    <p class="<?php print(sizeof(checkExtensions()) == 0?"ok":"notok");?>"> Missing extentions: <?php print(sizeof(checkExtensions()) == 0?"None":"");foreach(checkExtensions() as $ext){ echo $ext.", ";};?> (try to install anyway)</p>
 
-echo "<br/>";
+                    <p class="<?php print(getZipVersion()==="OK"?"ok":"notok");?>">  Zip version: <?php echo getZipVersion();?> </p>
 
-print_r(get_loaded_extensions());
+                    <p class="<?php print(getGitVersion()==="OK"?"ok":"notok");?>">  Git version: <?php echo getGitVersion();?> </p>
 
-?>
+                    <p class="<?php print(getTarVersion()==="OK"?"ok":"notok");?>">  Tar version: <?php echo getTarVersion();?> </p>
+
+
+                        <a href="?step=2"><button class="btn btn-primary">Lets go</button></a>
+                </div>
+            </div>
+
+<?php 
+}
+if (isset($_GET['step']) && $_GET['step']==2){
+
+	?>
+
+        <div class="card card-outline card-primary">
+            <div class="card-header text-center">
+                <b class="mr-1">Controlpanel.GG</b>
+            </div>
+
+                <div class="card-body">
+                    <p class="login-box-msg">Lets start with your Database</p>
+                  <?php if(isset($_GET['message'])){
+                    	echo "<p class='notok'>".$_GET['message']."</p>";
+                    }
+                    ?>
+
+               <form method="POST" enctype="multipart/form-data" class="mb-3"
+                          action="/install/forms.php" name="checkDB">
+
+                        <div class="row">
+                            <div class="col-md-12">
+                                <div class="form-group">
+                                    <div class="custom-control mb-3">
+                                        <label for="database">Database Driver</label>
+                                        <input x-model="databasedriver" id="databasedriver" name="databasedriver"
+                                               type="text" required
+                                               value="mysql" class="form-control">
+                                    </div>
+                                </div>
+                                <div class="form-group">
+                                    <div class="custom-control mb-3">
+                                        <label for="databasehost">Database Host</label>
+                                        <input x-model="databasehost" id="databasehost" name="databasehost" type="text"
+                                               required
+                                               value="127.0.0.1" class="form-control">
+                                    </div>
+                                </div>
+                                <div class="form-group">
+                                    <div class="custom-control mb-3">
+                                        <label for="databaseport">Database Port</label>
+                                        <input x-model="databaseport" id="databaseport" name="databaseport"
+                                               type="number" required
+                                               value="3306" class="form-control">
+                                    </div>
+                                </div>
+                                <div class="form-group">
+                                    <div class="custom-control mb-3">
+                                        <label for="databaseuser">Database User</label>
+                                        <input x-model="databaseuser" id="databaseuser" name="databaseuser" type="text"
+                                               required
+                                               value="dashboarduser" class="form-control">
+                                    </div>
+                                </div>
+                                <div class="form-group">
+                                    <div class="custom-control mb-3">
+                                        <label for="databaseuserpass">Database User Password</label>
+                                        <input x-model="databaseuserpass" id="databaseuserpass" name="databaseuserpass"
+                                               type="text" required
+                                               class="form-control ">
+                                    </div>
+                                </div>
+
+                                <div class="form-group">
+                                    <div class="custom-control mb-3">
+                                        <label for="database">Database</label>
+                                        <input x-model="database" id="database" name="database" type="text" required
+                                               value="dashboard" class="form-control">
+                                    </div>
+                                </div>
+
+                                </div>
+ 
+                                <button class="btn btn-primary" name="checkDB">Submit</button>
+                            </div>
+                        </div>
+
+
+                </div>
+            </div>
+	<?php
+}
+
+?>
+
+
+
+<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
+  </body>
+</html>