[dokuwiki] Re: patch to configure location of acl.auth.php
- From: "TNHarris" <telliamed@xxxxxxxxxxx>
- To: dokuwiki@xxxxxxxxxxxxx
- Date: Thu, 19 Jul 2007 19:56:23 -0400
On Thu, 05 Jul 2007 19:10:34 +0200, "Simon Heimlicher"
<heimlicher@xxxxxxxxxxxxxx> said:
> I have a setup where I only use one dokuwiki directory and many data
> directories ("wiki farm"), and for this setup I had to replace all
> occurrences of DOKU_CONF.'acl.auth.php' with $conf['aclfile'].
I'm doing something similar. The solution I came up with uses a hosts
configuration file to set the DOKU_CONF and DOKU_URL constants. This
required modifying inc/init.php to read the hosts.conf early. I also had
to define DOKU_DIR as an alternative to DOKU_INC because the sitemaps
were being written to the wrong place.
Diff patch is attached. The configuration looks like this:
# hosts.conf.php
# <?php exit()?>
# DokuWiki hosts configuration file
# Defines URIs for wikis and the directories they live in
# URI pattern <sp> Canonical URI <sp> Base directory
# Pattern can contain subpatterns that will be replaced in the URI and
base dir.
^(www.)?whoopdedo.org/doku/ http://whoopdedo.org/doku/
/path/to/doku/
^(www.)?whoopdedo.org/moe/ http://whoopdedo.org/moe/
/path/to/moe/
-- tom
telliamed@xxxxxxxxxxx
--
http://www.fastmail.fm - The professional email service
--- _darcs/pristine/inc/init.php 2007-07-05 17:36:20.000000000 -0400
+++ inc/init.php 2007-07-19 19:38:29.000000000 -0400
@@ -13,6 +13,11 @@
// define the include path
if(!defined('DOKU_INC'))
define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
+ if (@file_exists(DOKU_INC.'conf/hosts.conf.php')) {
+ getHostsConfig(file(DOKU_INC.'conf/hosts.conf.php'));
+ }
+ if(!defined('DOKU_DIR')) define('DOKU_DIR',DOKU_INC);
+
// define config path (packagers may want to change this to /etc/dokuwiki/)
if(!defined('DOKU_CONF')) define('DOKU_CONF',DOKU_INC.'conf/');
@@ -198,11 +203,16 @@
*/
function init_path($path){
// check existance
- $p = realpath($path);
- if(!@file_exists($p)){
- $p = realpath(DOKU_INC.$path);
+ if (substr($path,0,1)=='/') {
+ $p = realpath($path);
+ if(!@file_exists($p)) return '';
+ }else{
+ $p = realpath(DOKU_DIR.$path);
if(!@file_exists($p)){
- return '';
+ $p = realpath(DOKU_INC.$path);
+ if(!@file_exists($p)){
+ return '';
+ }
}
}
@@ -387,5 +397,65 @@
exit;
}
+function getHostsConfig($lines) {
+ //split hostheader into host and port
+ list($host,$port) = explode(':',$_SERVER['HTTP_HOST']);
+ if(!$port) $port = $_SERVER['SERVER_PORT'];
+ if(!$port) $port = 80;
+ // see if HTTPS is enabled - apache leaves this empty when not available,
+ // IIS sets it to 'off', 'false' and 'disabled' are just guessing
+ if (!isset($_SERVER['HTTPS']) ||
preg_match('/^(|off|false|disabled)$/i',$_SERVER['HTTPS'])){
+ if ($port == '80') $port='';
+ }else{
+ if ($port == '443') $port='';
+ }
+ if($port) $port = ':'.$port;
+ if(!empty($_SERVER['REQUEST_URI'])){
+ $dir = $_SERVER['REQUEST_URI'];
+ }elseif(!empty($_SERVER['SCRIPT_URL'])){
+ $dir = $_SERVER['SCRIPT_URL'];
+ }elseif(!empty($_SERVER['SCRIPT_NAME'])){
+ $dir = $_SERVER['SCRIPT_NAME'];
+ }elseif(!empty($_SERVER['PHP_SELF'])){
+ $dir = $_SERVER['PHP_SELF'];
+ }elseif($_SERVER['DOCUMENT_ROOT'] && $_SERVER['SCRIPT_FILENAME']){
+ $dir = preg_replace ('/^'.preg_quote($_SERVER['DOCUMENT_ROOT'],'/').'/','',
+ $_SERVER['SCRIPT_FILENAME']);
+ }else{
+ $dir = '/'; //probably wrong
+ }
+ $dir = str_replace('\\','/',$dir); #bugfix for weird WIN behaviour
+ $dir = preg_replace('#//+#','/',$dir);
+ $request = $host.$port.$dir;
+ $uri = '';
+ $dir = '';
+ foreach ($lines as $line) {
+ $line = preg_replace('/#.*$/','',$line); //ignore comments
+ $line = trim($line);
+ if(empty($line)) continue;
+ $host = preg_split('/\s+/', $line);
+ if (count($host) >= 3) {
+ if (preg_match('!'.$host[0].'!', $request, $matches)) {
+ $uri = $host[1];
+ $dir = $host[2];
+ $n = 0;
+ foreach ($matches as $match) {
+ $uri = preg_replace('/\$'.$n.'/',$match,$uri);
+ $dir = preg_replace('/\$'.$n.'/',$match,$dir);
+ $n++;
+ }
+ if (substr($uri,-1,1) != '/') $uri = $uri.'/';
+ if (substr($dir,-1,1) != '/') $dir = $dir.'/';
+ if(!defined('DOKU_DIR')) define('DOKU_DIR',$dir);
+ if(!defined('DOKU_CONF')) define('DOKU_CONF',$dir.'conf/');
+ if(!defined('DOKU_URL')) define('DOKU_URL',$uri);
+ if(!defined('DOKU_REL')) {
+ define('DOKU_REL',preg_replace('#^https?://[^/]+#','',$uri));
+ }
+ return;
+ }
+ }
+ }
+}
//Setup VIM: ex: et ts=2 enc=utf-8 :
- Follow-Ups:
- [dokuwiki] Re: patch to configure location of acl.auth.php
- From: Luke Howson
- References:
- [dokuwiki] Re: patch to configure location of acl.auth.php
- From: Simon Heimlicher
Other related posts:
- » [dokuwiki] patch to configure location of acl.auth.php
- » [dokuwiki] Re: patch to configure location of acl.auth.php
- » [dokuwiki] Re: patch to configure location of acl.auth.php
- » [dokuwiki] Re: patch to configure location of acl.auth.php
- » [dokuwiki] Re: patch to configure location of acl.auth.php
- » [dokuwiki] Re: patch to configure location of acl.auth.php
- » [dokuwiki] Re: patch to configure location of acl.auth.php
- [dokuwiki] Re: patch to configure location of acl.auth.php
- From: Luke Howson
- [dokuwiki] Re: patch to configure location of acl.auth.php
- From: Simon Heimlicher