summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandi <andi@splitbrain.org>2005-03-03 23:29:03 +0100
committerandi <andi@splitbrain.org>2005-03-03 23:29:03 +0100
commit3dc3a5f166aa2c4e345b27f6811db5889261c3d4 (patch)
treecc2295a03f04aad6df1aa6b03c9538087df0fcca
parent08505e404feaf25dae0741eb381980f26b2f6d98 (diff)
downloadrpg-3dc3a5f166aa2c4e345b27f6811db5889261c3d4.tar.gz
rpg-3dc3a5f166aa2c4e345b27f6811db5889261c3d4.tar.bz2
safemode hack #179
darcs-hash:20050303222903-9977f-038e77fc63d17af9bda168d214cecd1cf84b5aa9.gz
-rw-r--r--conf/dokuwiki.php8
-rw-r--r--inc/html.php1
-rw-r--r--inc/init.php8
-rw-r--r--inc/io.php55
-rw-r--r--media.php4
5 files changed, 68 insertions, 8 deletions
diff --git a/conf/dokuwiki.php b/conf/dokuwiki.php
index 87dacf2a5..ea29f19e1 100644
--- a/conf/dokuwiki.php
+++ b/conf/dokuwiki.php
@@ -72,6 +72,14 @@ $conf['target']['extern'] = '_blank';
$conf['target']['media'] = '';
$conf['target']['windows'] = '';
+/* Safemode Hack */
+$conf['safemodehack'] = 0; //read http://wiki.splitbrain.org/wiki:safemodehack !
+$conf['ftp']['host'] = 'localhost';
+$conf['ftp']['port'] = '21';
+$conf['ftp']['user'] = 'user';
+$conf['ftp']['pass'] = 'password';
+$conf['ftp']['root'] = '/home/user/htdocs';
+
//this includes a local config file if exist which make upgrading more easy - just don't touch this
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../').'/');
@include(DOKU_INC.'conf/local.php');
diff --git a/inc/html.php b/inc/html.php
index 4761ade99..36bd25e2f 100644
--- a/inc/html.php
+++ b/inc/html.php
@@ -1124,6 +1124,7 @@ function html_debug(){
$cnf = $conf;
$cnf['auth']='***';
$cnf['notify']='***';
+ $cnf['ftp']='***';
print '<html><body>';
diff --git a/inc/init.php b/inc/init.php
index 9314008e1..334d77b00 100644
--- a/inc/init.php
+++ b/inc/init.php
@@ -49,7 +49,13 @@
$conf['mediaweb'] = getBaseURL().$conf['mediaweb'];
}
-
+ // make real paths and check them
+ $conf['datadir'] = realpath($conf['datadir']);
+ if(!$conf['datadir']) msg('Wrong datadir!',-1);
+ $conf['olddir'] = realpath($conf['olddir']);
+ if(!$conf['olddir']) msg('Wrong olddir!',-1);
+ $conf['mediadir'] = realpath($conf['mediadir']);
+ if(!$conf['mediadir']) msg('Wrong mediadir!',-1);
/**
* remove magic quotes recursivly
diff --git a/inc/io.php b/inc/io.php
index 6586a554e..d59efbc78 100644
--- a/inc/io.php
+++ b/inc/io.php
@@ -113,7 +113,10 @@ function io_saveFile($file,$content){
function io_makeFileDir($file){
global $conf;
- $dir = dirname($file);
+ $dir = dirname($file);
+ if($conf['safemodehack']){
+ preg_replace('/^'.preg_quote(realpath($conf['ftp']['root']),'/').'/','',$dir);
+ }
umask($conf['dmask']);
if(!is_dir($dir)){
io_mkdir_p($dir) || msg("Creating directory $dir failed",-1);
@@ -125,21 +128,65 @@ function io_makeFileDir($file){
* Creates a directory hierachy.
*
* @link http://www.php.net/manual/en/function.mkdir.php
- * @author <saint@corenova.com>
+ * @author <saint@corenova.com>
+ * @author Andreas Gohr <andi@splitbrain.org>
*/
function io_mkdir_p($target){
+ global $conf;
if (is_dir($target)||empty($target)) return 1; // best case check first
if (@file_exists($target) && !is_dir($target)) return 0;
- if (io_mkdir_p(substr($target,0,strrpos($target,'/'))))
- return @mkdir($target,0777); // crawl back up & create dir tree
+ //recursion
+ if (io_mkdir_p(substr($target,0,strrpos($target,'/')))){
+ if($conf['safemodehack']){
+ return io_mkdir_ftp($target);
+ }else{
+ return @mkdir($target,0777); // crawl back up & create dir tree
+ }
+ }
return 0;
}
/**
+ * Creates a directory using FTP
+ *
+ * This is used when the safemode workaround is enabled
+ *
+ * @author <andi@splitbrain.org>
+ */
+function io_mkdir_ftp($dir){
+ global $conf;
+
+ if(!function_exists('ftp_connect')){
+ msg("FTP support not found - safemode workaround not usable",-1);
+ return false;
+ }
+
+ $conn = @ftp_connect($conf['ftp']['host'],$conf['ftp']['port'],10);
+ if(!$conn){
+ msg("FTP connection failed",-1);
+ return false;
+ }
+
+ if(!@ftp_login($conn, $conf['ftp']['user'], $conf['ftp']['pass'])){
+ msg("FTP login failed",-1);
+ return false;
+ }
+
+ //create directory
+ $ok = @ftp_mkdir($conn, $dir);
+ //set permissions (using the directory umask)
+ @ftp_site($conn,sprintf("CHMOD %04o %s",$perm & (0777 - $conf['dmask']),$dir));
+
+ ftp_close($conn);
+ return $ok;
+}
+
+/**
* Runs an external command and returns it's output as string
*
* @author Harry Brueckner <harry_b@eml.cc>
* @author Andreas Gohr <andi@splitbrain.org>
+ * @deprecated
*/
function io_runcmd($cmd){
$fh = popen($cmd, "r");
diff --git a/media.php b/media.php
index f5527fb8e..7413a2b7a 100644
--- a/media.php
+++ b/media.php
@@ -18,9 +18,7 @@
$uploadok = true;
//create the given namespace (just for beautification)
$mdir = $conf['mediadir'].'/'.utf8_encodeFN(str_replace(':','/',$NS));
- umask($conf['dmask']);
- io_mkdir_p($mdir);
- umask($conf['umask']);
+ io_makeFileDir("$mdir/xxx");
}else{
$uploadok = false;
}