|
From: <car...@us...> - 2025-02-23 08:56:35
|
Revision: 11162
http://sourceforge.net/p/phpwiki/code/11162
Author: carstenklapp
Date: 2025-02-23 08:56:33 +0000 (Sun, 23 Feb 2025)
Log Message:
-----------
New class _define_optional_suggestion for calculated paths that differ from the defaults. New spot for defining ADMIN_USER & pwd. Improved instructions. Better handling of default directories and calculate different paths for windows.
Modified Paths:
--------------
trunk/configurator.php
Modified: trunk/configurator.php
===================================================================
--- trunk/configurator.php 2025-02-23 03:28:58 UTC (rev 11161)
+++ trunk/configurator.php 2025-02-23 08:56:33 UTC (rev 11162)
@@ -1,7 +1,4 @@
<?php
-// defining these 2 here is a temporary fix
-if (!defined('ADMIN_USER')) define('ADMIN_USER', '');
-if (!defined('ADMIN_PASSWD')) define('ADMIN_PASSWD', '');
/**
* Copyright © 2002,2003,2005,2008-2010 $ThePhpWikiProgrammingTeam
* Copyright © 2002 Martin Geisler <gim...@gi...>
@@ -154,6 +151,8 @@
// If config.ini exists, we require ADMIN_USER access by faking HttpAuth.
// So nobody can see or reset the password(s).
if (file_exists($fs_config_file)) {
+ exit("Configuration config file \"$fs_config_file\" already exists.\n"
+ . "Cannot continue: You have to fix that manually.");
// Require admin user
if (!defined('ADMIN_USER') or !defined('ADMIN_PASSWD')) {
if (!function_exists("IniConfig")) {
@@ -361,14 +360,23 @@
<p>On any configuration problems, please edit the resulting config.ini
manually. If one is not created, copy config-dist.ini to config.ini and
edit that.</p>
- <p>This file currently has problems with:</p>
+ <p>This file currently has the following issues:</p>
<ul>
- <li>Handling Windows pathnames (use forward slashes /)</li>
- <li>Editing existing config.ini file is currently not possible. Rename it
- to generate a new one, or edit it manually.</li>
- <li>Php crypt() function fails sometimes and returns *0 or *1 as the
- password. In that case run passencrypt.php to generate a new password
- and manually paste it into config.ini.</li>
+<?php if(isWindows()) { ?>
+ <li>For Windows pathnames, use forward slashes / instead. Any \ will be
+ converted.</li>
+ <li>Default paths will be suggested based on the Windows TEMP dir instead
+ of /tmp.</li>
+<?php } ?>
+ <li>Using the suggested temporary dirs will get you up and running quickly
+ but you will lose your data sooner or later if you do not change them
+ to more permanent directories!</li>
+ <li>Editing an existing config.ini file using this configurator is
+ currently not possible. Rename or delete the file to generate a new
+ one, or edit it manually.</li>
+ <li>The Php crypt() function fails sometimes and returns *0 or *1 as the
+ password. In that case run passencrypt.php to generate a new
+ ADMIN_PASSWD and manually paste it into config.ini.</li>
</ul>
</div>
@@ -429,6 +437,20 @@
// for x in `perl -ne 'print $1,"\n" if /^;(\w+) =/' config/config-dist.ini`; do \
// grep \'$x\' configurator.php >/dev/null || echo $x ; done
+$defaulttempdir = "/tmp";
+$defaultenvtempdir = !empty($_ENV['TEMP']) ? $_ENV['TEMP'] : $defaulttempdir;
+
+if (defined('TEMP_DIR')) {
+ $guessedtempdir = TEMP_DIR;
+ $guessedtempdir = checkMassageWinPath($guessedtempdir);
+ if (isWindows() && (TEMP_DIR == $defaulttempdir)) { //try harder for windows
+ $guessedtempdir = $defaultenvtempdir;
+ }
+} else {
+ $guessedtempdir = $defaulttempdir;
+}
+$guessedtempdir = checkMassageWinPath($guessedtempdir);
+
$properties["Part Zero"] =
new part('_part0', $SEPARATOR . "\n", "
Part Zero: Latest Development and Tricky Options");
@@ -436,18 +458,12 @@
if (defined('INCLUDE_PATH')) {
$include_path = INCLUDE_PATH;
} else {
- if (substr(PHP_OS, 0, 3) == 'WIN') {
- $include_path = dirname(__FILE__) . ';' . ini_get('include_path');
- if (strchr(ini_get('include_path'), '/')) {
- $include_path = strtr($include_path, '\\', '/');
- }
- } else {
- $include_path = dirname(__FILE__) . ':' . ini_get('include_path');
- }
+ // PATH_SEPARATOR is ; on windows, : on others
+ $include_path = dirname(__FILE__) . PATH_SEPARATOR . ini_get('include_path');
}
-
+$include_path = checkMassageWinPath($include_path);
$properties["PHP include_path"] =
- new _define('INCLUDE_PATH', $include_path);
+ new _define_optional_suggestion('INCLUDE_PATH', $include_path);
// TODO: Convert this to a checkbox row as in tests/unit/test.php
$properties["DEBUG"] =
@@ -545,6 +561,9 @@
$properties["Wiki Name"] =
new _define_optional('WIKI_NAME', WIKI_NAME);
+if (!defined('ADMIN_USER')) {
+ define('ADMIN_USER', '');
+}
$properties["Admin Username"] =
new _define_notempty(
'ADMIN_USER',
@@ -554,6 +573,9 @@
"onchange=\"validate_ereg('Sorry, ADMIN_USER cannot be empty.', '^.+$', 'ADMIN_USER', this);\""
);
+if (!defined('ADMIN_PASSWD')) {
+ define('ADMIN_PASSWD', '');
+}
$properties["Admin Password"] =
new _define_password(
'ADMIN_PASSWD',
@@ -574,7 +596,7 @@
new boolean_define(
'ENCRYPTED_PASSWD',
array('true' => "true. use crypt for all passwords",
- 'false' => "false. use plaintest passwords (not recommended)")
+ 'false' => "false. use plaintext passwords (not recommended)")
);
$properties["MAX_PAGENAME_LENGTH"] =
@@ -706,8 +728,21 @@
$properties["COOKIE_DOMAIN"] =
new _define_commented_optional('COOKIE_DOMAIN', COOKIE_DOMAIN);
+//fixme
+$session_save_path = defined('SESSION_SAVE_PATH') ? SESSION_SAVE_PATH : ini_get('session.save_path');
+$session_save_path = checkMassageWinPath($session_save_path);
+if (defined('SESSION_SAVE_PATH')) {
+ $session_save_path = SESSION_SAVE_PATH;
+ $session_save_path = checkMassageWinPath($session_save_path);
+ if (isWindows() && (SESSION_SAVE_PATH == $defaulttempdir)) { //try harder for windows
+ $session_save_path = $defaultenvtempdir;
+ }
+} else {
+ $session_save_path = $defaulttempdir;
+}
+$session_save_path = checkMassageWinPath($session_save_path);
$properties["Path for PHP Session Support"] =
- new _define_optional('SESSION_SAVE_PATH', defined('SESSION_SAVE_PATH') ? SESSION_SAVE_PATH : ini_get('session.save_path'));
+ new _define_optional_suggestion('SESSION_SAVE_PATH', $session_save_path);
$properties["Force PHP Database Sessions"] =
new boolean_define_commented_optional(
@@ -848,10 +883,17 @@
A word of warning - any prefix defined above will be prepended to whatever is given here.
");
-//TODO: $TEMP
-$temp = !empty($_ENV['TEMP']) ? $_ENV['TEMP'] : "/tmp";
+if (defined('DATABASE_DIRECTORY')) {
+ $database_dir = DATABASE_DIRECTORY;
+ if (isWindows() && (DATABASE_DIRECTORY == $defaulttempdir)) { //try harder for windows
+ $database_dir = $defaultenvtempdir;
+ }
+} else {
+ $database_dir = $guessedtempdir;
+}
+$database_dir = checkMassageWinPath($database_dir);
$properties["dba directory"] =
- new _define("DATABASE_DIRECTORY", $temp);
+ new _define_optional_suggestion("DATABASE_DIRECTORY", $database_dir);
// TODO: list the available methods
$properties["dba handler"] =
@@ -1053,7 +1095,7 @@
A database DSN to connect to. Defaults to the DSN specified for the Wiki as a whole.");
$properties["User Exists Query"] =
- new _define('DBAUTH_AUTH_USER_EXISTS', "SELECT userid FROM user WHERE userid='\$userid'", "
+ new _define_optional('DBAUTH_AUTH_USER_EXISTS', "SELECT userid FROM user WHERE userid='\$userid'", "
USER/PASSWORD queries:
For USER_AUTH_POLICY=strict and the Db method is required");
@@ -1465,8 +1507,14 @@
$properties["Data Path"] =
new _define_commented_optional('DATA_PATH', dirname($scriptname));
+if (defined('PHPWIKI_DIR')) {
+ $phpwiki_dir = PHPWIKI_DIR;
+} else {
+ $phpwiki_dir = dirname(__FILE__);
+}
+$phpwiki_dir = checkMassageWinPath($phpwiki_dir);
$properties["PhpWiki Install Directory"] =
- new _define_commented_optional('PHPWIKI_DIR', dirname(__FILE__));
+ new _define_commented_optional('PHPWIKI_DIR', $phpwiki_dir);
$properties["Use PATH_INFO"] =
new _define_selection_optional_commented(
@@ -1516,14 +1564,13 @@
");
$upload_file_path = defined('UPLOAD_FILE_PATH') ? UPLOAD_FILE_PATH : getUploadFilePath();
-new _define_optional('UPLOAD_FILE_PATH', $temp);
+new _define_optional('UPLOAD_FILE_PATH', $upload_file_path);
$upload_data_path = defined('UPLOAD_DATA_PATH') ? UPLOAD_DATA_PATH : getUploadDataPath();
-new _define_optional('UPLOAD_DATA_PATH', $temp);
+new _define_optional('UPLOAD_DATA_PATH', $upload_data_path);
-$temp = !empty($_ENV['TEMP']) ? $_ENV['TEMP'] : "/tmp";
$properties["TEMP_DIR"] =
- new _define_optional('TEMP_DIR', $temp);
+ new _define_optional_suggestion('TEMP_DIR', $guessedtempdir);
$properties["Allowed Load"] =
new _define_commented_optional(
@@ -1552,11 +1599,14 @@
'true' => "quoted-printable")
);
+
+$guesseddumpdir = checkWinAlternatePath('DEFAULT_DUMP_DIR', "wikidump", $guessedtempdir, $defaulttempdir);
$properties["Default local Dump Directory"] =
- new _define_optional('DEFAULT_DUMP_DIR');
+ new _define_optional_suggestion('DEFAULT_DUMP_DIR', $guesseddumpdir);
+$guessedhtmldumpdir = checkWinAlternatePath('HTML_DUMP_DIR', "wikidumphtml", $guessedtempdir, $defaulttempdir);
$properties["Default local HTML Dump Directory"] =
- new _define_optional('HTML_DUMP_DIR');
+ new _define_optional_suggestion('HTML_DUMP_DIR', $guessedhtmldumpdir);
$properties["HTML Dump Filename Suffix"] =
new _define_optional('HTML_DUMP_SUFFIX');
@@ -1606,6 +1656,7 @@
$ttfont = 'luximr'; // This is the only what sourceforge offered.
//$ttfont = 'Helvetica';
}
+$ttfont = checkMassageWinPath($ttfont);
$properties["TTFONT"] =
new _define_commented_optional('TTFONT', $ttfont);
$properties["VISUALWIKIFONT"] =
@@ -1644,9 +1695,11 @@
db, trifile and imgfile might be supported, but you must hack that by yourself."
);
+$guessedcachedir = checkWinAlternatePath('PLUGIN_CACHED_CACHE_DIR', "cache", $guessedtempdir, $defaulttempdir);
$properties["pear Cache cache directory"] =
- new _define_commented_optional('PLUGIN_CACHED_CACHE_DIR', "/tmp/cache", "
+ new _define_optional_suggestion('PLUGIN_CACHED_CACHE_DIR', $guessedcachedir, "
Should be writable to the webserver.");
+
$properties["pear Cache Filename Prefix"] =
new _define_optional('PLUGIN_CACHED_FILENAME_PREFIX', "phpwiki", "");
$properties["pear Cache HIGHWATER"] =
@@ -1672,7 +1725,7 @@
new list_define('PLUGIN_CACHED_IMGTYPES', "png|gif|gd|gd2|jpeg|wbmp|xbm|xpm", "
Handle those image types via GD handles. Check your GD supported image types.");
-$end = "\n" . $SEPARATOR . "\n";
+$end = "\n" . $SEPARATOR . "\n;eof\n";
// performance hack
text_from_dist("_MAGIC_CLOSE_FILE");
@@ -1707,7 +1760,7 @@
$this->description = $description;
if (defined($config_item_name)
and !preg_match("/(selection|boolean)/", get_class($this))
- and !preg_match("/^(SCRIPT_NAME|VIRTUAL_PATH|TEMP_DIR)$/", $config_item_name)
+ and !preg_match("/^(SCRIPT_NAME|VIRTUAL_PATH|zTEMP_DIR)$/", $config_item_name)
) {
$this->default_value = constant($config_item_name);
} // ignore given default value
@@ -1959,12 +2012,16 @@
if ($this->description) {
$n = "\n";
}
+ $default_value = $this->default_value;
if ($posted_value == $this->default_value) {
+ //return "$n; DEBUG: equal dv=$default_value".gettype($default_value)." pv=" .gettype($posted_value). $this->_config_format($posted_value);
return "$n;" . $this->_config_format($posted_value);
}
if ($posted_value == '') {
- return "$n;" . $this->_config_format("");
+ //return "$n; DEBUG: posted is empty " . $this->_config_format('false');
+ return "$n;" . $this->_config_format($default_value);
} else {
+ //return "$n DEBUG else dv=$default_value".gettype($default_value)." pv=" .gettype($posted_value). $this->_config_format($posted_value);
return "$n" . $this->_config_format($posted_value);
}
}
@@ -1985,6 +2042,62 @@
}
}
+
+class _define_optional_suggestion extends _define_optional
+{
+ // This class expects config_item_name to be defined in config-default.ini
+ // but a calculated or suggested value will be passed in the default_value
+ // used for windows variables. the suggested value will be used in the
+ // html form instead of default_value
+ public $config_item_name;
+ public $default_value;
+ public $description;
+ public $prefix;
+ public $jscheck;
+ public $values;
+ public $suggested_value;
+
+ public function __construct($config_item_name, $default_value = '', $description = '', $jscheck = '')
+ {
+ $this->config_item_name = $config_item_name;
+ if (!$description) {
+ $description = text_from_dist($config_item_name);
+ }
+ $this->description = $description;
+ if (defined($config_item_name)
+ and !preg_match("/(selection|boolean)/", get_class($this))
+ and !preg_match("/^(SCRIPT_NAME|VIRTUAL_PATH|zTEMP_DIR)$/", $config_item_name)
+ ) {
+ $this->default_value = constant($config_item_name);
+ } // ignore given default value
+ elseif ($config_item_name == $default_value) {
+ $this->default_value = '';
+ } else {
+ $this->default_value = $default_value;
+ }
+ $this->suggested_value = $default_value;
+ $this->jscheck = $jscheck;
+ if (preg_match("/variable/i", get_class($this))) {
+ $this->prefix = "\$";
+ } elseif (preg_match("/ini_set/i", get_class($this))) {
+ $this->prefix = "ini_get: ";
+ } else {
+ $this->prefix = "";
+ }
+ }
+
+ public function get_html()
+ {
+ $size = strlen($this->suggested_value) > 45 ? 90 : 50;
+ return $this->get_config_item_header() .
+ "<input type=\"text\" size=\"$size\" name=\"" . $this->get_config_item_name()
+ . '" value="' . htmlspecialchars($this->suggested_value) . '" ' . $this->jscheck . " />"
+ . "<p id=\"" . $this->get_config_item_id() . "\" class=\"green\">Input accepted.</p>";
+ }
+}
+
+
+
class numeric_define extends _define
{
public function __construct($config_item_name, $default_value = '', $description = '', $jscheck = '')
@@ -2553,6 +2666,36 @@
return ($newpass);
}
+////
+// Function to replace windows slashes with forward slashes if necessary
+// https://stackoverflow.com/questions/5879043/php-script-detect-whether-running-under-linux-or-windows
+function checkMassageWinPath($path) {
+ if (DIRECTORY_SEPARATOR === '\\') {
+ return strtr($path, '\\', '/');
+ }
+ return $path;
+}
+
+// builds a directory name based off of /tmp checking if windows or other
+function checkWinAlternatePath($defined_name, $subdir, $guessedtempdir, $defaulttempdir) {
+
+ //echo ( "checkWinAlternatePath($defined_name, $subdir, $guessedtempdir, $defaulttempdir \n<br />" );
+ if (defined($defined_name)) {
+ $dirname = constant($defined_name);
+ //echo ("dirname=".$dirname."\n<br />");
+ if (isWindows() && ($dirname == $defaulttempdir . "/".$subdir)) { //try harder for windows
+ $dirname = $guessedtempdir. "/".$subdir;
+ //echo ("iswindows ".$dirname."\n<br />");
+ }
+ } else {
+ $dirname = $guessedtempdir. "/".$subdir;
+ }
+ $dirname = checkMassageWinPath($dirname);
+ //echo (" exiting ".$dirname."\n<br />\n<br />");
+ return $dirname;
+}
+
+
// end of class definitions
/////////////////////////////
// begin auto generation code
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|