errors[] = $message; } protected $warnings = array(); public function warning($message) { $this->warnings[] = $message; } public function run() { $string = ""; if (!empty($this->errors)) { foreach ($this->errors as $error) { $string .= '
' . $error . "
"; } } if (!empty($this->warnings)) { foreach ($this->warnings as $warning) { $string .= '' . $warning . "
"; } } return $string; } } class Settings { protected $user = ""; protected $userPassword = ""; protected $siteUrl = ""; protected $overwriteEmptyForm = array( "social.twitter" => "", "social.facebook" => "", ); protected function extractUser() { $this->user = (string)$_REQUEST["user_name"]; unset($_REQUEST["user_name"]); $this->userPassword = (string)$_REQUEST["user_password"]; unset($_REQUEST["user_password"]); } protected function convertRequestToConfig() { $array = array(); foreach ($_REQUEST as $name => $value) { if (!is_string($value) || empty($value)) continue; $name = str_replace("_", ".", $name); $array[$name] = $value; } foreach ($this->overwriteEmptyForm as $name => $value) { if (!isset($array[$name])) { $array[$name] = $value; } } return $array; } protected function generateSiteUrl() { $dir = trim(dirname(substr($_SERVER["SCRIPT_FILENAME"], strlen($_SERVER["DOCUMENT_ROOT"]))), '/'); if ($dir == '.' || $dir == '..') { $dir = ''; } $port = ''; if ($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443") { $port = ':' . $_SERVER["SERVER_PORT"]; } $scheme = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off' ? 'https' : 'http'; if ($dir === '') { $this->siteUrl = $scheme . '://' . trim($_SERVER['SERVER_NAME'], "/") . $port . "/"; return; } $this->siteUrl = $scheme . '://' . trim($_SERVER['SERVER_NAME'], "/") . $port . "/" . $dir . '/'; } protected function overwriteINI($data, $string) { foreach ($data as $word => $value) { $string = preg_replace("/^" . $word . " = .+$/m", $word . ' = "' . $value . '"', $string); } return $string; } protected function saveConfigs() { $this->extractUser(); //save config.ini $config = array( "site.url" => $this->siteUrl, "timezone" => $this->getTimeZone(), ); $config += $this->convertRequestToConfig(); $configFile = file_get_contents("config/config.ini.example"); $configFile = $this->overwriteINI($config, $configFile); file_put_contents("config/config.ini", $configFile, LOCK_EX); //save users/[Username].ini $userFile = file_get_contents("config/users/username.ini.example"); $parsed = parse_ini_string($userFile); if (isset($parsed['encryption'])) { $userFile = $this->overwriteINI(array( 'encryption' => 'sha512', 'password' => hash('sha512', $this->userPassword), 'role' => 'admin', 'mfa_secret' => 'disabled', ), $userFile); } else { $userFile = $this->overwriteINI(array( "password" => $this->userPassword, 'role' => 'admin', 'mfa_secret' => 'disabled', ), $userFile); } file_put_contents("config/users/" . $this->user . ".ini", $userFile, LOCK_EX); } protected function testTheEnvironment() { $message = new Message; if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50300) { $message->error('HTMLy requires at least PHP 5.3 to run.'); } if (!in_array('https', stream_get_wrappers())) { $message->error('Installer needs the https wrapper, please install openssl.'); } if (function_exists('apache_get_modules') && !in_array('mod_rewrite', apache_get_modules())) { $message->warning('mod_rewrite must be enabled if you use Apache.'); } if (!is__writable("./")) { $message->error('no permission to write in the Directory.'); } return $message->run(); } public function __construct() { $message = $this->testTheEnvironment(); $this->generateSiteUrl(); if (!empty($message)) { echo $message; } elseif ($this->runForm()) { unlink(__FILE__); header("Location:" . $this->siteUrl . "add/content?type=post"); exit(); } } protected function getTimeZone() { static $ip; if (empty($ip)) { $ip = @file_get_contents("http://ipecho.net/plain"); if (!is_string($ip)) { $ip = $_SERVER['REMOTE_ADDR']; } } $json = @json_decode(@file_get_contents("http://ip-api.com/json/" . $ip), true); if (isset($json['timezone'])) return $json['timezone']; return 'Europe/Berlin'; } protected function runForm() { if (from($_REQUEST, 'user_name') && from($_REQUEST, 'user_password')) { $this->saveConfigs(); $_SESSION[$this->siteUrl]["user"] = $this->user; return true; } else { unset($_SESSION[$this->siteUrl]["user"]); return false; } } } if(from($_SERVER,'QUERY_STRING') == "rewriteRule.html") { echo "YES!"; die(); } $samesite = 'strict'; if(PHP_VERSION_ID < 70300) { session_set_cookie_params('samesite='.$samesite); } else { session_set_cookie_params(['samesite' => $samesite]); } session_start(); new Settings; ?>the HTMLy Installer Tool