Styling install.php

This commit is contained in:
jpedryc 2022-02-15 22:48:45 +01:00
parent 25c68ad837
commit db5812548d
1 changed files with 168 additions and 155 deletions

View File

@ -1,4 +1,5 @@
<?php
/*><div style="width:60%; margin: auto; background-color: #fcc;
border: 1px solid #faa; padding: 0.5em 1em;">
<h1 style="font-size: 120%">No PHP Support</h1>
@ -14,25 +15,28 @@
* @author Chris Smith <chris@jalakai.co.uk>
*/
if(!defined('DOKU_INC')) define('DOKU_INC',dirname(__FILE__).'/');
if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
if(!defined('DOKU_LOCAL')) define('DOKU_LOCAL',DOKU_INC.'conf/');
if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__) . '/');
if (!defined('DOKU_CONF')) define('DOKU_CONF', DOKU_INC . 'conf/');
if (!defined('DOKU_LOCAL')) define('DOKU_LOCAL', DOKU_INC . 'conf/');
// load and initialize the core system
require_once(DOKU_INC.'inc/init.php');
require_once(DOKU_INC . 'inc/init.php');
// check for error reporting override or set error reporting to sane values
if (!defined('DOKU_E_LEVEL')) { error_reporting(E_ALL ^ E_NOTICE); }
else { error_reporting(DOKU_E_LEVEL); }
if (!defined('DOKU_E_LEVEL')) {
error_reporting(E_ALL ^ E_NOTICE);
} else {
error_reporting(DOKU_E_LEVEL);
}
// language strings
require_once(DOKU_INC.'inc/lang/en/lang.php');
if(isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
$LC = preg_replace('/[^a-z\-]+/','',$_REQUEST['l']);
require_once(DOKU_INC . 'inc/lang/en/lang.php');
if (isset($_REQUEST['l']) && !is_array($_REQUEST['l'])) {
$LC = preg_replace('/[^a-z\-]+/', '', $_REQUEST['l']);
}
if(empty($LC)) $LC = 'en';
if($LC && $LC != 'en' ) {
require_once(DOKU_INC.'inc/lang/'.$LC.'/lang.php');
if (empty($LC)) $LC = 'en';
if ($LC && $LC != 'en') {
require_once(DOKU_INC . 'inc/lang/' . $LC . '/lang.php');
}
// initialise variables ...
@ -87,13 +91,13 @@ header('Content-Type: text/html; charset=utf-8');
<div style="float: right; width: 34%;">
<?php
if(file_exists(DOKU_INC.'inc/lang/'.$LC.'/install.html')){
include(DOKU_INC.'inc/lang/'.$LC.'/install.html');
}else{
print "<div lang=\"en\" dir=\"ltr\">\n";
include(DOKU_INC.'inc/lang/en/install.html');
print "</div>\n";
}
if (file_exists(DOKU_INC . 'inc/lang/' . $LC . '/install.html')) {
include(DOKU_INC . 'inc/lang/' . $LC . '/install.html');
} else {
print "<div lang=\"en\" dir=\"ltr\">\n";
include(DOKU_INC . 'inc/lang/en/install.html');
print "</div>\n";
}
?>
<a style="
background: transparent
@ -106,29 +110,29 @@ header('Content-Type: text/html; charset=utf-8');
<div style="float: left; width: 58%;">
<?php
try {
if(! (check_functions() && check_permissions()) ){
echo '<p>'.$lang['i_problems'].'</p>';
try {
if (! (check_functions() && check_permissions())) {
echo '<p>' . $lang['i_problems'] . '</p>';
print_errors();
print_retry();
} elseif (!check_configs()) {
echo '<p>' . $lang['i_modified'] . '</p>';
print_errors();
} elseif (check_data($_REQUEST['d'])) {
// check_data has sanitized all input parameters
if (!store_data($_REQUEST['d'])) {
echo '<p>' . $lang['i_failure'] . '</p>';
print_errors();
print_retry();
}elseif(!check_configs()){
echo '<p>'.$lang['i_modified'].'</p>';
print_errors();
}elseif(check_data($_REQUEST['d'])){
// check_data has sanitized all input parameters
if(!store_data($_REQUEST['d'])){
echo '<p>'.$lang['i_failure'].'</p>';
print_errors();
}else{
echo '<p>'.$lang['i_success'].'</p>';
}
}else{
print_errors();
print_form($_REQUEST['d']);
} else {
echo '<p>' . $lang['i_success'] . '</p>';
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
} else {
print_errors();
print_form($_REQUEST['d']);
}
} catch (Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
?>
</div>
@ -146,17 +150,18 @@ header('Content-Type: text/html; charset=utf-8');
*
* @param array $d submitted entry 'd' of request data
*/
function print_form($d){
function print_form($d)
{
global $lang;
global $LC;
include(DOKU_CONF.'license.php');
include(DOKU_CONF . 'license.php');
if(!is_array($d)) $d = array();
$d = array_map('hsc',$d);
if (!is_array($d)) $d = array();
$d = array_map('hsc', $d);
if(!isset($d['acl'])) $d['acl']=1;
if(!isset($d['pop'])) $d['pop']=1;
if (!isset($d['acl'])) $d['acl'] = 1;
if (!isset($d['pop'])) $d['pop'] = 1;
?>
<form action="" method="post">
@ -191,11 +196,11 @@ function print_form($d){
<label for="policy"><?php echo $lang['i_policy']?></label>
<select class="text" name="d[policy]" id="policy">
<option value="0" <?php echo ($d['policy'] == 0)?'selected="selected"':'' ?>><?php
<option value="0" <?php echo ($d['policy'] == 0) ? 'selected="selected"' : '' ?>><?php
echo $lang['i_pol0']?></option>
<option value="1" <?php echo ($d['policy'] == 1)?'selected="selected"':'' ?>><?php
<option value="1" <?php echo ($d['policy'] == 1) ? 'selected="selected"' : '' ?>><?php
echo $lang['i_pol1']?></option>
<option value="2" <?php echo ($d['policy'] == 2)?'selected="selected"':'' ?>><?php
<option value="2" <?php echo ($d['policy'] == 2) ? 'selected="selected"' : '' ?>><?php
echo $lang['i_pol2']?></option>
</select>
@ -210,14 +215,14 @@ function print_form($d){
<fieldset>
<p><?php echo $lang['i_license']?></p>
<?php
array_push($license,array('name' => $lang['i_license_none'], 'url'=>''));
if(empty($d['license'])) $d['license'] = 'cc-by-sa';
foreach($license as $key => $lic){
echo '<label for="lic_'.$key.'">';
echo '<input type="radio" name="d[license]" value="'.hsc($key).'" id="lic_'.$key.'"'.
(($d['license'] === $key)?' checked="checked"':'').'>';
array_push($license, array('name' => $lang['i_license_none'], 'url' => ''));
if (empty($d['license'])) $d['license'] = 'cc-by-sa';
foreach ($license as $key => $lic) {
echo '<label for="lic_' . $key . '">';
echo '<input type="radio" name="d[license]" value="' . hsc($key) . '" id="lic_' . $key . '"' .
(($d['license'] === $key) ? ' checked="checked"' : '') . '>';
echo hsc($lic['name']);
if($lic['url']) echo ' <a href="'.$lic['url'].'" target="_blank"><sup>[?]</sup></a>';
if ($lic['url']) echo ' <a href="' . $lic['url'] . '" target="_blank"><sup>[?]</sup></a>';
echo '</label>';
}
?>
@ -241,7 +246,8 @@ function print_form($d){
<?php
}
function print_retry() {
function print_retry()
{
global $lang;
global $LC;
?>
@ -262,7 +268,8 @@ function print_retry() {
* @param array $d
* @return bool ok?
*/
function check_data(&$d){
function check_data(&$d)
{
static $form_default = array(
'title' => '',
'acl' => '1',
@ -278,12 +285,11 @@ function check_data(&$d){
global $lang;
global $error;
if(!is_array($d)) $d = array();
foreach($d as $k => $v) {
if(is_array($v))
if (!is_array($d)) $d = array();
foreach ($d as $k => $v) {
if (is_array($v))
unset($d[$k]);
else
$d[$k] = (string)$v;
else $d[$k] = (string)$v;
}
//autolowercase the username
@ -291,36 +297,35 @@ function check_data(&$d){
$ok = false;
if(isset($_REQUEST['submit'])) {
if (isset($_REQUEST['submit'])) {
$ok = true;
// check input
if(empty($d['title'])){
$error[] = sprintf($lang['i_badval'],$lang['i_wikiname']);
if (empty($d['title'])) {
$error[] = sprintf($lang['i_badval'], $lang['i_wikiname']);
$ok = false;
}
if(isset($d['acl'])){
if(!preg_match('/^[a-z0-9_]+$/',$d['superuser'])){
$error[] = sprintf($lang['i_badval'],$lang['i_superuser']);
if (isset($d['acl'])) {
if (!preg_match('/^[a-z0-9_]+$/', $d['superuser'])) {
$error[] = sprintf($lang['i_badval'], $lang['i_superuser']);
$ok = false;
}
if(empty($d['password'])){
$error[] = sprintf($lang['i_badval'],$lang['pass']);
if (empty($d['password'])) {
$error[] = sprintf($lang['i_badval'], $lang['pass']);
$ok = false;
} elseif (!isset($d['confirm']) || $d['confirm'] != $d['password']) {
$error[] = sprintf($lang['i_badval'], $lang['passchk']);
$ok = false;
}
elseif(!isset($d['confirm']) || $d['confirm'] != $d['password']){
$error[] = sprintf($lang['i_badval'],$lang['passchk']);
if (empty($d['fullname']) || strstr($d['fullname'], ':')) {
$error[] = sprintf($lang['i_badval'], $lang['fullname']);
$ok = false;
}
if(empty($d['fullname']) || strstr($d['fullname'],':')){
$error[] = sprintf($lang['i_badval'],$lang['fullname']);
if (empty($d['email']) || strstr($d['email'], ':') || !strstr($d['email'], '@')) {
$error[] = sprintf($lang['i_badval'], $lang['email']);
$ok = false;
}
if(empty($d['email']) || strstr($d['email'],':') || !strstr($d['email'],'@')){
$error[] = sprintf($lang['i_badval'],$lang['email']);
$ok = false;
}
}else{
} else {
// Since default = 1, browser won't send acl=0 when user untick acl
$d['acl'] = '0';
}
@ -337,7 +342,8 @@ function check_data(&$d){
* @param array $d
* @return bool
*/
function store_data($d){
function store_data($d)
{
global $LC;
$ok = true;
$d['policy'] = (int) $d['policy'];
@ -354,8 +360,8 @@ function store_data($d){
EOT;
// add any config options set by a previous installer
$preset = __DIR__.'/install.conf';
if(file_exists($preset)){
$preset = __DIR__ . '/install.conf';
if (file_exists($preset)) {
$output .= "# preset config options\n";
$output .= file_get_contents($preset);
$output .= "\n\n";
@ -363,17 +369,17 @@ EOT;
@unlink($preset);
}
$output .= '$conf[\'title\'] = \''.addslashes($d['title'])."';\n";
$output .= '$conf[\'lang\'] = \''.addslashes($LC)."';\n";
$output .= '$conf[\'license\'] = \''.addslashes($d['license'])."';\n";
if($d['acl']){
$output .= '$conf[\'useacl\'] = 1'.";\n";
$output .= '$conf[\'title\'] = \'' . addslashes($d['title']) . "';\n";
$output .= '$conf[\'lang\'] = \'' . addslashes($LC) . "';\n";
$output .= '$conf[\'license\'] = \'' . addslashes($d['license']) . "';\n";
if ($d['acl']) {
$output .= '$conf[\'useacl\'] = 1' . ";\n";
$output .= "\$conf['superuser'] = '@admin';\n";
}
if(!$d['allowreg']){
$output .= '$conf[\'disableactions\'] = \'register\''.";\n";
if (!$d['allowreg']) {
$output .= '$conf[\'disableactions\'] = \'register\'' . ";\n";
}
$ok = $ok && fileWrite(DOKU_LOCAL.'local.php',$output);
$ok = $ok && fileWrite(DOKU_LOCAL . 'local.php', $output);
if ($d['acl']) {
// hash the password
@ -396,8 +402,8 @@ EOT;
EOT;
// --- user:bcryptpasswordhash:Real Name:email:groups,comma,seperated
$output = $output."\n".join(":",array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user'))."\n";
$ok = $ok && fileWrite(DOKU_LOCAL.'users.auth.php', $output);
$output = $output . "\n" . join(":", array($d['superuser'], $pass, $d['fullname'], $d['email'], 'admin,user')) . "\n";
$ok = $ok && fileWrite(DOKU_LOCAL . 'users.auth.php', $output);
// create acl.auth.php
$output = <<<EOT
@ -411,21 +417,21 @@ EOT;
# Date: $now
EOT;
if($d['policy'] == 2){
if ($d['policy'] == 2) {
$output .= "* @ALL 0\n";
$output .= "* @user 8\n";
}elseif($d['policy'] == 1){
} elseif ($d['policy'] == 1) {
$output .= "* @ALL 1\n";
$output .= "* @user 8\n";
}else{
} else {
$output .= "* @ALL 8\n";
}
$ok = $ok && fileWrite(DOKU_LOCAL.'acl.auth.php', $output);
$ok = $ok && fileWrite(DOKU_LOCAL . 'acl.auth.php', $output);
}
// enable popularity submission
if(isset($d['pop']) && $d['pop']){
@touch(DOKU_INC.'data/cache/autosubmit.txt');
if (isset($d['pop']) && $d['pop']) {
@touch(DOKU_INC . 'data/cache/autosubmit.txt');
}
// disable auth plugins til needed
@ -444,7 +450,7 @@ EOT;
\$plugins['authpgsql'] = 0;
EOT;
$ok = $ok && fileWrite(DOKU_LOCAL.'plugins.local.php', $output);
$ok = $ok && fileWrite(DOKU_LOCAL . 'plugins.local.php', $output);
return $ok;
}
@ -458,17 +464,20 @@ EOT;
* @param string $data
* @return bool
*/
function fileWrite($filename, $data) {
function fileWrite($filename, $data)
{
global $error;
global $lang;
if (($fp = @fopen($filename, 'wb')) === false) {
$filename = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $filename);
$error[] = sprintf($lang['i_writeerr'],$filename);
$filename = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $filename);
$error[] = sprintf($lang['i_writeerr'], $filename);
return false;
}
if (!empty($data)) { fwrite($fp, $data); }
if (!empty($data)) {
fwrite($fp, $data);
}
fclose($fp);
return true;
}
@ -482,23 +491,24 @@ function fileWrite($filename, $data) {
*
* @return bool
*/
function check_configs(){
function check_configs()
{
global $error;
global $lang;
$ok = true;
$config_files = array(
'local' => DOKU_LOCAL.'local.php',
'users' => DOKU_LOCAL.'users.auth.php',
'auth' => DOKU_LOCAL.'acl.auth.php'
'local' => DOKU_LOCAL . 'local.php',
'users' => DOKU_LOCAL . 'users.auth.php',
'auth' => DOKU_LOCAL . 'acl.auth.php'
);
// configs shouldn't exist
foreach ($config_files as $file) {
if (file_exists($file) && filesize($file)) {
$file = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}/', $file);
$error[] = sprintf($lang['i_confexists'],$file);
$file = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}/', $file);
$error[] = sprintf($lang['i_confexists'], $file);
$ok = false;
}
}
@ -513,30 +523,31 @@ function check_configs(){
*
* @return bool
*/
function check_permissions(){
function check_permissions()
{
global $error;
global $lang;
$dirs = array(
'conf' => DOKU_LOCAL,
'data' => DOKU_INC.'data',
'pages' => DOKU_INC.'data/pages',
'attic' => DOKU_INC.'data/attic',
'media' => DOKU_INC.'data/media',
'media_attic' => DOKU_INC.'data/media_attic',
'media_meta' => DOKU_INC.'data/media_meta',
'meta' => DOKU_INC.'data/meta',
'cache' => DOKU_INC.'data/cache',
'locks' => DOKU_INC.'data/locks',
'index' => DOKU_INC.'data/index',
'tmp' => DOKU_INC.'data/tmp'
'data' => DOKU_INC . 'data',
'pages' => DOKU_INC . 'data/pages',
'attic' => DOKU_INC . 'data/attic',
'media' => DOKU_INC . 'data/media',
'media_attic' => DOKU_INC . 'data/media_attic',
'media_meta' => DOKU_INC . 'data/media_meta',
'meta' => DOKU_INC . 'data/meta',
'cache' => DOKU_INC . 'data/cache',
'locks' => DOKU_INC . 'data/locks',
'index' => DOKU_INC . 'data/index',
'tmp' => DOKU_INC . 'data/tmp'
);
$ok = true;
foreach($dirs as $dir){
if(!file_exists("$dir/.") || !is_writable($dir)){
$dir = str_replace($_SERVER['DOCUMENT_ROOT'],'{DOCUMENT_ROOT}', $dir);
$error[] = sprintf($lang['i_permfail'],$dir);
foreach ($dirs as $dir) {
if (!file_exists("$dir/.") || !is_writable($dir)) {
$dir = str_replace($_SERVER['DOCUMENT_ROOT'], '{DOCUMENT_ROOT}', $dir);
$error[] = sprintf($lang['i_permfail'], $dir);
$ok = false;
}
}
@ -550,17 +561,18 @@ function check_permissions(){
*
* @return bool
*/
function check_functions(){
function check_functions()
{
global $error;
global $lang;
$ok = true;
if(version_compare(phpversion(),'5.6.0','<')){
$error[] = sprintf($lang['i_phpver'],phpversion(),'5.6.0');
if (version_compare(phpversion(), '5.6.0', '<')) {
$error[] = sprintf($lang['i_phpver'], phpversion(), '5.6.0');
$ok = false;
}
if(ini_get('mbstring.func_overload') != 0){
if (ini_get('mbstring.func_overload') != 0) {
$error[] = $lang['i_mbfuncoverload'];
$ok = false;
}
@ -573,17 +585,17 @@ function check_functions(){
$ok = false;
}
if(ini_get('mbstring.func_overload') != 0){
if (ini_get('mbstring.func_overload') != 0) {
$error[] = $lang['i_mbfuncoverload'];
$ok = false;
}
$funcs = explode(' ','addslashes call_user_func chmod copy fgets '.
'file file_exists fseek flush filesize ftell fopen '.
'glob header ignore_user_abort ini_get mkdir '.
'ob_start opendir parse_ini_file readfile realpath '.
'rename rmdir serialize session_start unlink usleep '.
'preg_replace file_get_contents htmlspecialchars_decode '.
$funcs = explode(' ', 'addslashes call_user_func chmod copy fgets ' .
'file file_exists fseek flush filesize ftell fopen ' .
'glob header ignore_user_abort ini_get mkdir ' .
'ob_start opendir parse_ini_file readfile realpath ' .
'rename rmdir serialize session_start unlink usleep ' .
'preg_replace file_get_contents htmlspecialchars_decode ' .
'spl_autoload_register stream_select fsockopen pack xml_parser_create');
if (!function_exists('mb_substr')) {
@ -591,19 +603,18 @@ function check_functions(){
$funcs[] = 'utf8_decode';
}
if(!function_exists('mail')){
if(strpos(ini_get('disable_functions'),'mail') !== false) {
if (!function_exists('mail')) {
if (strpos(ini_get('disable_functions'), 'mail') !== false) {
$disabled = $lang['i_disabled'];
}
else {
} else {
$disabled = "";
}
$error[] = sprintf($lang['i_funcnmail'],$disabled);
$error[] = sprintf($lang['i_funcnmail'], $disabled);
}
foreach($funcs as $func){
if(!function_exists($func)){
$error[] = sprintf($lang['i_funcna'],$func);
foreach ($funcs as $func) {
if (!function_exists($func)) {
$error[] = sprintf($lang['i_funcna'], $func);
$ok = false;
}
}
@ -615,18 +626,19 @@ function check_functions(){
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function langsel(){
function langsel()
{
global $lang;
global $LC;
$dir = DOKU_INC.'inc/lang';
$dir = DOKU_INC . 'inc/lang';
$dh = opendir($dir);
if(!$dh) return;
if (!$dh) return;
$langs = array();
while (($file = readdir($dh)) !== false) {
if(preg_match('/^[\._]/',$file)) continue;
if(is_dir($dir.'/'.$file) && file_exists($dir.'/'.$file.'/lang.php')){
if (preg_match('/^[\._]/', $file)) continue;
if (is_dir($dir . '/' . $file) && file_exists($dir . '/' . $file . '/lang.php')) {
$langs[] = $file;
}
}
@ -636,12 +648,12 @@ function langsel(){
echo '<form action="">';
echo $lang['i_chooselang'];
echo ': <select name="l" onchange="submit()">';
foreach($langs as $l){
foreach ($langs as $l) {
$sel = ($l == $LC) ? 'selected="selected"' : '';
echo '<option value="'.$l.'" '.$sel.'>'.$l.'</option>';
echo '<option value="' . $l . '" ' . $sel . '>' . $l . '</option>';
}
echo '</select> ';
echo '<button type="submit">'.$lang['btn_update'].'</button>';
echo '<button type="submit">' . $lang['btn_update'] . '</button>';
echo '</form>';
}
@ -650,11 +662,12 @@ function langsel(){
*
* @author Andreas Gohr <andi@splitbrain.org>
*/
function print_errors(){
function print_errors()
{
global $error;
if(!empty($error)) {
if (!empty($error)) {
echo '<ul>';
foreach ($error as $err){
foreach ($error as $err) {
echo "<li>$err</li>";
}
echo '</ul>';