diff --git a/setup.php b/setup.php
index 235b4f1..3c44ac1 100644
--- a/setup.php
+++ b/setup.php
@@ -5,302 +5,265 @@
* @package WikiDocs
* @repository https://github.com/Zavy86/wikidocs
*/
-
-// initialize session
session_start();
// errors configuration
error_reporting(E_ALL & ~E_NOTICE);
ini_set("display_errors",true);
-function getSetting($key, $default = '') {
- return (string) $_SESSION['wikidocs']['setup'][$key] ?? (string)$default;
-}
-function sanitizeInput($input) {
- return htmlspecialchars(trim($input), ENT_COMPAT, 'UTF-8');
+function getSetting($key,$default=''){return (string)($_SESSION['wikidocs']['setup'][$key]??$default);}
+function sanitizeInput($input){return htmlspecialchars(trim($input),ENT_COMPAT,'UTF-8');}
+function checkWebServer(){
+ if((isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'Apache') !== false)){return "apache";}
+ elseif(isset($_SERVER['SERVER_SOFTWARE']) && strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false){return "nginx";}
+ else{return null;}
}
// definitions
$errors=false;
$configured=false;
$checks_array=[];
-$g_act = $_GET['act'] ?? 'preliminary_check';
-
+$g_act=$_GET['act']??'preliminary_check';
// include configuration sample
include("sample.config.inc.php");
-
// defines constants
define('PATH_URI',explode("setup.php",$_SERVER['REQUEST_URI'])[0]);
-
// Check if already configured
-if (file_exists("datasets/config.inc.php")) {
- die("Wiki|Docs is already configured.");
-}
-
+if(file_exists("datasets/config.inc.php")){header("location:index.php");}
// make root dir from given path
$original_dir=str_replace("\\","/",realpath(dirname(__FILE__))."/");
$root_dir=substr($original_dir,0,strrpos($original_dir,($_POST['path'] ?? ''))).($_POST['path'] ?? '');
-
-
-if($g_act=="preliminary_check") {
- $softwares = [];
- $installed['nginx'] = isNginx();
-
- $installed['apache'] = isApache();
- //if apache_get_modules() is not available, we can't check for the required modules
- if (function_exists('apache_get_modules')) {
- $required_modules = ['mod_rewrite','mod_mime'];
- foreach ($required_modules as $module) {
- $installed[$module] = in_array($module, apache_get_modules());
- }
- }
-
- $versions = [];
- foreach (['Core','dom','json','mbstring','session','xml'] as $extension) {
- $versions[$extension] =phpversion($extension);
- }
+// preliminary checks
+if($g_act=="preliminary_check"){
+ $server_modules=[];
+ if(function_exists('apache_get_modules')){
+ $available_modules=apache_get_modules();
+ foreach(['mod_rewrite','mod_mime'] as $module){
+ $server_modules[$module]=in_array($module,$available_modules);
+ }
+ }
+ $php_modules=[];
+ foreach(['Core','dom','json','mbstring','session','xml'] as $module) {
+ $label=($module=='Core'?'php_version':'php_'.$module);
+ $php_modules[$label]=phpversion($module);
+ }
}
// check action
if($g_act=="check"){
-
- $required_fields = ['path', 'title', 'subtitle', 'owner', 'notice', 'editcode'];
- $_SESSION['wikidocs']['setup'] = [];
-
-
- foreach ($required_fields as $field) {
- $value = $_POST[$field] ?? '';
-
- $_SESSION['wikidocs']['setup'][$field] = $value;
-
- $checks_array[$field] = !empty($value);
- $errors = $errors || !$checks_array[$field];
- }
-
- $checks_array['path'] = file_exists($root_dir . "setup.php");
- $errors = $errors || !$checks_array['path'];
-
- if ($_POST['editcode'] !== $_POST['editcode_repeat']) {
- $checks_array['editcode'] = false;
- $errors = true;
- }
+ $required_fields=['path','title','subtitle','owner','notice','editcode'];
+ $_SESSION['wikidocs']['setup']=[];
+ foreach($required_fields as $field){
+ $value=$_POST[$field]??'';
+ $_SESSION['wikidocs']['setup'][$field]=$value;
+ $checks_array[$field]=!empty($value);
+ $errors=$errors||!$checks_array[$field];
+ }
+ $checks_array['path']=file_exists($root_dir."setup.php");
+ $errors=$errors||!$checks_array['path'];
+ if($_POST['editcode']!==$_POST['editcode_repeat']){
+ $checks_array['editcode']=false;
+ $errors=true;
+ }
}
// conclude action
if($g_act=="conclude"){
- $config = " 'false',
- 'PATH' => getSetting('path'),
- 'TITLE' => getSetting('title'),
- 'SUBTITLE' => getSetting('subtitle'),
- 'OWNER' => getSetting('owner'),
- 'NOTICE' => getSetting('notice'),
- 'PRIVACY' => 'null',
- 'EDITCODE' => getSetting('editcode') ? password_hash(getSetting('editcode'), PASSWORD_DEFAULT) : 'null',
- 'VIEWCODE' => 'null',
- 'COLOR' => '#4CAF50',
- 'DARK' => 'false',
- 'GTAG' => 'null'
- ];
-
- foreach ($config_items as $key => $value) {
- if ($value === null || $value === 'null') {
- $config .= "define('" . $key . "', null);\n";
- } elseif (is_bool($value) || $value === 'true' || $value === 'false') {
- $config .= "define('" . $key . "', " . ($value === 'true' ? 'true' : 'false') . ");\n";
- } elseif (is_numeric($value)) {
- $config .= "define('" . $key . "', " . $value . ");\n";
- } else {
- $config .= "define('" . $key . "', '" . addslashes($value) . "');\n";
- }
+ $config="'false',
+ 'PATH'=>getSetting('path'),
+ 'TITLE'=>getSetting('title'),
+ 'SUBTITLE'=>getSetting('subtitle'),
+ 'OWNER'=>getSetting('owner'),
+ 'NOTICE'=>getSetting('notice'),
+ 'PRIVACY'=>'null',
+ 'EDITCODE'=>getSetting('editcode')?password_hash(getSetting('editcode'),PASSWORD_DEFAULT):'null',
+ 'VIEWCODE'=>'null',
+ 'COLOR'=>'#4CAF50',
+ 'DARK'=>'false',
+ 'GTAG'=>'null'
+ ];
+ foreach($config_items as $key=>$value){
+ if($value===null||$value==='null'){
+ $config.="define('".$key."', null);\n";
+ }elseif(is_bool($value)||$value==='true'||$value==='false'){
+ $config.="define('".$key. "', ".($value==='true'?'true':'false').");\n";
+ }elseif(is_numeric($value)){
+ $config.="define('".$key."', ".$value.");\n";
+ }else{
+ $config.="define('" .$key."', '".addslashes($value)."');\n";
}
-
- // Write configuration file
- $configPath = $root_dir . "datasets/config.inc.php";
- file_put_contents($configPath, $config);
-
- // Generate .htaccess
- $htaccess = "
Just a databaseless markdown flat-file wiki engine..
-Webserver
-Php modules and versions
-Setup your wiki engine..
- -Your configuration has been verified..
-Your configuration has been saved..
-Continue to your wiki!
- check_circle - -An error occurred while saving the configuration!
- cancel - - -Just a databaseless markdown flat-file wiki engine..
+Setup your wiki engine..
+ +Your configuration has been verified..
+Your configuration has been saved..
+Continue to your wiki!
+ check_circle + +An error occurred while saving the configuration!
+ cancel + + +