* @desc Process and render first steps of farm installation */ // must be run within Dokuwiki if(!defined('DOKU_INC')) die(); if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC.'lib/plugins/'); if(!defined('DOKU_FARM_PLUGIN')) define('DOKU_FARM_PLUGIN', DOKU_PLUGIN.'farm/'); if(!defined('DOKU_FARMPLUGINLOADED')) define('DOKU_FARMPLUGINLOADED', true); class dokuwiki_farm_install { var $manager = null; var $webroot = null; var $fsroot = null; var $farmer = null; var $barn = null; /** * @param $manager object that must handle error(), success(), nicesize(), getLang() ... calls */ function __construct($manager) { $this->manager = & $manager; } /** * Process requests */ function process() { if(isset($this->manager->opt['next'])) { // Parameters checks if( !isset($_POST['install_field_farmwebroot']) || !isset($_POST['install_field_farmfsroot']) || !isset($_POST['install_field_farmer']) || !isset($_POST['install_field_barn']) ) { $this->manager->error('install_errors', 'postparametermissing_failure'); return; } $ok = true; $this->webroot = $_POST['install_field_farmwebroot']; $this->fsroot = $_POST['install_field_farmfsroot']; $this->farmer = $_POST['install_field_farmer']; $this->barn = $_POST['install_field_barn']; if(empty($this->webroot)) { $this->manager->error('install_errors', array('code' => 'emptyfield_failure', 'data' => array($this->manager->getLang('install_field_name_farmwebroot')))); $ok = false; } if(empty($this->fsroot)) { $this->manager->error('install_errors', array('code' => 'emptyfield_failure', 'data' => array($this->manager->getLang('install_field_name_farmfsroot')))); $ok = false; } if(empty($this->farmer)) { $this->manager->error('install_errors', array('code' => 'emptyfield_failure', 'data' => array($this->manager->getLang('install_field_name_farmer')))); $ok = false; } /* Barn can be empty since the current folder can be the abrn (barnatroot mode) if(empty($this->barn)) { $this->manager->error('install_errors', array('code' => 'emptyfield_failure', 'data' => array($this->manager->getLang('install_field_name_barn')))); $ok = false; } */ if(!$ok) return; if(substr($this->webroot, -1) != '/') { $this->manager->error('install_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('install_field_name_farmwebroot')))); $ok = false; } if((substr($this->fsroot, -1) != '/') || !@is_dir($this->fsroot)) { $this->manager->error('install_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('install_field_name_farmfsroot')))); $ok = false; } if(substr($this->farmer, -1) != '/') { $this->manager->error('install_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('install_field_name_farmer')))); $ok = false; } if($this ->barn && substr($this->barn, -1) != '/') { $this->manager->error('install_errors', array('code' => 'invalidfield_failure', 'data' => array($this->manager->getLang('install_field_name_barn')))); $ok = false; } if(!$ok) return; $conf = explode("\n", @file_get_contents(DOKU_FARM_PLUGIN.'install/config.php')); if(count($conf)) { $r = 0; for($i=0; $iwebroot.'\';'.$m[3]; break; case 'farmfsroot' : $r++; $conf[$i] = '$farmconf[\'farmfsroot\'] = \''.$this->fsroot.'\';'.$m[3]; break; case 'farmer' : $r++; $conf[$i] = '$farmconf[\'farmer\'] = \''.$this->farmer.'\';'.$m[3]; break; case 'barn' : $r++; $conf[$i] = '$farmconf[\'barn\'] = \''.$this->barn.'\';'.$m[3]; break; } } } if($r != 4) return $this->manager->error('install_errors', 'install_configcopy_failure'); if($fp = fopen(DOKU_FARM_PLUGIN.'config.php', 'w')) { fwrite($fp, implode("\n", $conf)); fclose($fp); if(!@touch(DOKU_FARM_PLUGIN.'installed', 'w')) return $this->manager->error('install_errors', 'install_stepupdate_failure'); $sc = @file_get_contents(DOKU_FARM_PLUGIN.'install/farmstructurecreator.php'); if($sc != '') { global $conf; $l = isset($conf['lang']) ? $conf['lang'] : 'en'; $l = @file_exists(DOKU_FARM_PLUGIN.'lang/'.$l.'/lang.php') ? DOKU_FARM_PLUGIN.'lang/'.$l.'/lang.php' : DOKU_FARM_PLUGIN.'lang/en/lang.php'; $c = DOKU_FARM_PLUGIN.'config.php'; $sc = str_replace('exit(); // NO EXECUTION SECURITY', 'include \''.$c.'\';'."\n".'include \''.$l.'\';'."\n", $sc); if($fp = fopen($this->fsroot.'farmstructurecreator.php', 'w')) { fwrite($fp, $sc); fclose($fp); header('Location: '.$this->webroot.'farmstructurecreator.php'); exit(); }else $this->manager->error('install_errors', 'install_cannotsavecreator_failure'); }else $this->manager->error('install_errors', 'install_nocreatorfile_failure'); }else $this->manager->error('install_errors', 'install_configcopy_failure'); }else $this->manager->error('install_errors', 'install_configcopy_failure'); } } /** * Renders */ function html() { ptln('
'.$this->manager->getLang('install_title').'
'); ptln('
'.$this->manager->getLang('install_info').'
'); // Weird css inclusion bug fix echo ''; $this->manager->formHead(array('farm_cmd' => 'farminstall')); if(is_null($this->webroot)) $this->webroot = preg_replace('`doku\.php$`', '', wl('', array(), true)); if(is_null($this->fsroot)) $this->fsroot = substr(__FILE__, 0, -1 * strlen('lib/plugins/farm/install.class.php')); if(is_null($this->farmer)) $this->farmer = 'farmer/'; if(is_null($this->barn)) $this->barn = 'barn/'; ptln('
'); ptln(' '.$this->manager->getLang('install_field_name_farmwebroot').' :
'); ptln(''.$this->manager->getLang('install_field_desc_farmwebroot').''); ptln('
'); ptln('
'); ptln(' '.$this->manager->getLang('install_field_name_farmfsroot').' :
'); ptln(''.$this->manager->getLang('install_field_desc_farmfsroot').''); ptln('
'); ptln('
'); ptln(' '.$this->manager->getLang('install_field_name_farmer').' :
'); ptln(''.$this->manager->getLang('install_field_desc_farmer').''); ptln('
'); ptln('
'); ptln(' '.$this->manager->getLang('install_field_name_barn').' :
'); ptln(''.$this->manager->getLang('install_field_desc_barn').''); ptln('
'); ptln('
'); ptln(' '); ptln('
'); ptln(''); } } ?>