diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/html.php | 1 | ||||
-rw-r--r-- | inc/init.php | 8 | ||||
-rw-r--r-- | inc/io.php | 55 |
3 files changed, 59 insertions, 5 deletions
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"); |