*/ exit(); // NO EXECUTION SECURITY function cp_r($src, $dest, $mv=false, $forbid=array(), $lvl=0) { if(in_array($src, $forbid)) return true; if(@is_file($src)) { $p = fileperms($src); $r = copy($src, $dest); chmod($dest, $p); if($mv) $r &= unlink($src); return $r; } if(!@is_dir($dest)) { $p = fileperms($src); mkdir($dest, $p); } $r = true; foreach(scandir($src) as $i) { if($i == '.' || $i == '..') continue; $r &= cp_r($src.'/'.$i, $dest.'/'.$i, $mv, $forbid, $lvl+1); } if($mv && $lvl) $r &= rmdir($src); return $r; } function installStep($s = null, $infarmer = true) { global $farmconf; $file = null; if(@file_exists($farmconf['farmer'].'lib/plugins/farm/installed')) $file = $farmconf['farmer'].'lib/plugins/farm/installed'; if(@file_exists('./lib/plugins/farm/installed')) $file = './lib/plugins/farm/installed'; if(!$file) return ''; if(!$s) return trim(@file_get_contents($file)); if($fp = fopen($file, 'w')) { fwrite($fp, $s); fclose($fp); }else die('Could not update install step'); } // Load config if(!@file_exists('config.php')) { if(!@file_exists('./lib/plugins/farm/config.php')) die('Cannot load config'); if(!copy('./lib/plugins/farm/config.php', 'config.php')) die('Cannot copy temp config'); } global $farmconf; $farmconf = array(); include 'config.php'; switch(installStep(null, false)) { case '' : die('Corrupted install index'); case '1' : // Create directories if(!@mkdir($farmconf['farmer'], 0755)) die('Cannot create farmer dir');; if(!@mkdir($farmconf['barn'], 0755)) die('Cannot create barn'); installStep('1.01', false); case '1.01' : // Move dokuwiki if(!cp_r( '.', $farmconf['farmer'], true, array('./'.basename(__FILE__), './config.php', './'.trim($farmconf['farmer'], '/'), './'.trim($farmconf['barn'], '/')) )) die('Cannot move structure'); installStep('1.02'); case '1.02' : // Create main htaccess if needed if($farmconf['userewrite']) { if($htaccess = @file_get_contents($farmconf['farmer'].'lib/plugins/farm/install/farm.htaccess')) { $farm = $farmconf['farmwebroot']; if(preg_match('`^([^:]+://)?([^/]+)?/?(.*)$`i', $farm, $m)) $farm = $m[3]; $htaccess = str_replace('{farm}', trim($farm, '/'), $htaccess); $htaccess = str_replace('{farmer}', trim($farmconf['farmer'], '/'), $htaccess); $htaccess = str_replace('{barn}', trim($farmconf['barn'], '/'), $htaccess); if($fp = fopen('.htaccess', 'w')) { fwrite($fp, $htaccess); fclose($fp); }else die('Could not create farm rewrite file'); }else die('Could not load farm rewrite template'); } installStep('1.03'); case '1.03' : // Create animals htaccess if($htaccess = @file_get_contents($farmconf['farmer'].'lib/plugins/farm/install/barn.htaccess')) { $farm = $farmconf['farmwebroot']; if(preg_match('`^([^:]+://)?([^/]+)?/?(.*)$`i', $farm, $m)) $farm = $m[3]; $htaccess = str_replace('{farm}', trim($farm, '/'), $htaccess); $htaccess = str_replace('{farmer}', trim($farmconf['farmer'], '/'), $htaccess); $htaccess = str_replace('{barn}', trim($farmconf['barn'], '/'), $htaccess); if($fp = fopen($farmconf['barn'].'.htaccess', 'w')) { fwrite($fp, $htaccess); fclose($fp); }else die('Could not create barn rewrite file'); }else die('Could not load barn rewrite template'); installStep('1.04'); case '1.04' : // Move animal default template if(!@mkdir($farmconf['barn'].$farmconf['animaltemplate'], 0755)) die('Cannot create animal default template directory'); if(!cp_r( $farmconf['farmer'].'lib/plugins/farm/install/animaltemplate', $farmconf['barn'].$farmconf['animaltemplate'] )) die('Cannot copy animal default template'); installStep('1.05'); case '1.05' : // Create animal default template meta if($fp = fopen($farmconf['barn'].'/'.$farmconf['animaltemplate'].'/animal.meta', 'w')) { fwrite($fp, 'creation_date : '.time()); fclose($fp); }else die('Could not create animal template metafile'); installStep('1.06'); case '1.06' : // Copy preload file if(!copy($farmconf['farmer'].'lib/plugins/farm/install/preload.php', $farmconf['farmer'].'inc/preload.php')) die('Could not copy preload file'); installStep('1.07'); case '1.07' : // Create farmer/wsdl.php $wsdl = @file_get_contents($farmconf['farmer'].'lib/plugins/farm/install/wsdl.base'); if(!$wsdl) die('Could not load wsdl base'); $file = $farmconf['farmwebroot'].'farm.wsdl'; $wsdl = str_replace('{wsdl}', $file, $wsdl); $wsdl = str_replace('{location}', $farmconf['farmwebroot'].$farmconf['farmer'].'lib/plugins/farm/soapserver.php', $wsdl); if($fp = fopen('farm.wsdl', 'w')) { fwrite($fp, $wsdl); fclose($fp); }else die('Could not save farm.wsdl'); installStep('1.08'); case '1.08' : // Copy trusted application config file if(!copy($farmconf['farmer'].'lib/plugins/farm/install/trusted_apps.php', $farmconf['farmer'].'lib/plugins/farm/trusted_apps.php')) die('Could not copy trusted applications config file'); installStep('1.09'); case '1.09' : // Updates DokuWiki htaccess if($htaccess = @file_get_contents($farmconf['farmfsroot'].$farmconf['farmer'].'.htaccess')) { $wr = $farmconf['farmwebroot'].$farmconf['farmer']; if(preg_match('`^([^:]+://)?([^/]+)?/?(.*)$`i', $wr, $m)) $wr = $m[3]; $htaccess = preg_replace('`RewriteBase\s+[a-zA-Z0-9/._-]+`', 'RewriteBase /'.trim($wr, '/'), $htaccess); if($fp = fopen($farmconf['farmfsroot'].$farmconf['farmer'].'.htaccess', 'w')) { fwrite($fp, $htaccess); fclose($fp); }else die('Could not update rewrite file'); }else die('Could not load rewrite file'); installStep('1.09'); case '1.09' : if(!@unlink(__FILE__)) die('Could not remove farm structure creator script file'); if(!@unlink('config.php')) die('Could not remove farm config temp file'); installStep('2'); // installation successfull ! } header('Location: '.$farmconf['farmwebroot'].$farmconf['farmer'].'?do=admin&page=farm'); ?>