$error = true; $topass['message']['type'] = MESSAGE_ERROR; $topass['message']['text'] = $p->error_text; } } $install_index = 0; $ui_request = false; $show_finish = true; // used to figure out if we should show the finish button in case of an error or not. if (!$error) { // read the manifest if (substr($file, -4) == '.zip') { $p = new etano_package(); if (!isset($_GET['finish']) && !isset($_GET['skip_input']) && !isset($_GET['ui_error'])) { // first time here $dirname = $fileop->extract_zip(_BASEPATH_ . '/tmp/packages/' . $file); } else { $dirname = substr($file, 0, -4); } if (is_file(_BASEPATH_ . '/tmp/packages/' . $dirname . '/manifest.xml')) { $p->set_file(_BASEPATH_ . '/tmp/packages/' . $dirname . '/manifest.xml'); } elseif (!empty($dirname)) { if (is_dir(_BASEPATH_ . '/tmp/packages/' . $dirname)) { $fileop->delete(_BASEPATH_ . '/tmp/packages/' . $dirname); } $error = true; $topass['message']['type'] = MESSAGE_ERROR; $topass['message']['text'] = 'Invalid package'; } if (!$p->error) { $install_index_start = 0;
function install($install_index, $skip_input = -1) { $this->ui = ''; if (isset($this->install[$install_index]['input']) && $skip_input != $install_index) { $this->ui = (require_once $this->package_path . '/' . $this->install[$install_index]['input']); $this->error = false; } else { $modfile = $this->package_path . '/' . $this->install[$install_index]['file']; $mod_content = file_get_contents($modfile); $fileop = new fileop(); $mydoc = new XML_dsb(); $mydoc->parseXML($mod_content); $mod_command = $mydoc->firstChild->firstChild; while ($mod_command) { if ($mod_command->nodeName == 'php') { // artificially create a block // inside the included file we're still in this class!! // this php file can generate errors of type critical which halt the execution of installer $mod_command->firstChild->nodeValue = str_replace(array('{package_path}', '{basepath}'), array($this->package_path, _BASEPATH_), $mod_command->firstChild->nodeValue); require_once $mod_command->firstChild->nodeValue; // end block } elseif ($mod_command->nodeName == 'diff') { if (isset($mod_command->attributes['force_revision'])) { $force_revision = true; } else { $force_revision = false; } if (!$this->_do_diff($this->package_path . '/' . $mod_command->firstChild->nodeValue, $force_revision)) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'diff'; $this->manual_actions[$masize]['from'] = $this->package_path . '/' . $mod_command->firstChild->nodeValue; $this->manual_actions[$masize]['to'] = ''; $this->manual_actions[$masize]['error'] = $this->error_text; } } elseif ($mod_command->nodeName == 'copy') { $attrs = $mod_command->attributes; $attrs['from'] = str_replace(array('{package_path}', '{basepath}'), array($this->package_path, _BASEPATH_), $attrs['from']); $attrs['to'] = str_replace(array('{package_path}', '{basepath}'), array($this->package_path, _BASEPATH_), $attrs['to']); if (isset($attrs['type']) && $attrs['type'] == 'skin') { foreach ($GLOBALS['skins'] as $mc => $mdir) { $temp = str_replace('{skin}', $mdir, $attrs['from']); $temp1 = str_replace('{skin}', $mdir, $attrs['to']); if (!$fileop->copy($temp, $temp1)) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'copy'; $this->manual_actions[$masize]['from'] = $temp; $this->manual_actions[$masize]['to'] = $temp1; $this->manual_actions[$masize]['error'] = sprintf('Unable to copy file %1$s to %2$s', $temp, $temp1); } } } else { if (!$fileop->copy($attrs['from'], $attrs['to'])) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'copy'; $this->manual_actions[$masize]['from'] = $attrs['from']; $this->manual_actions[$masize]['to'] = $attrs['to']; $this->manual_actions[$masize]['error'] = sprintf('Unable to copy file %1$s to %2$s', $attrs['from'], $attrs['to']); } } } elseif ($mod_command->nodeName == 'delete') { $attrs = $mod_command->attributes; $attrs['file'] = str_replace(array('{package_path}', '{basepath}'), array($this->package_path, _BASEPATH_), $attrs['file']); if (isset($attrs['type']) && $attrs['type'] == 'skin') { foreach ($GLOBALS['skins'] as $mc => $mdir) { $temp = str_replace('{skin}', $mdir, $attrs['file']); if (!$fileop->delete($temp)) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'delete'; $this->manual_actions[$masize]['from'] = $temp; $this->manual_actions[$masize]['to'] = ''; $this->manual_actions[$masize]['error'] = 'Unable to automatically delete file.'; } } } else { if (!$fileop->delete($attrs['file'])) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'delete'; $this->manual_actions[$masize]['from'] = $attrs['file']; $this->manual_actions[$masize]['to'] = ''; $this->manual_actions[$masize]['error'] = "Unable to automatically delete file."; } } } elseif ($mod_command->nodeName == 'extract') { $attrs = $mod_command->attributes; $attrs['archive'] = str_replace(array('{package_path}', '{basepath}'), array($this->package_path, _BASEPATH_), $attrs['archive']); $attrs['to'] = str_replace(array('{package_path}', '{basepath}'), array($this->package_path, _BASEPATH_), $attrs['to']); if (isset($attrs['type']) && $attrs['type'] == 'zip') { if (!$fileop->extract_zip($attrs['archive'], $attrs['to'])) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'extract'; $this->manual_actions[$masize]['from'] = $attrs['archive']; $this->manual_actions[$masize]['to'] = $attrs['to']; $this->manual_actions[$masize]['error'] = "Unable to extract archive."; } } } elseif ($mod_command->nodeName == 'mkdir') { $attrs = $mod_command->attributes; $attrs['path'] = str_replace(array('{package_path}', '{basepath}'), array($this->package_path, _BASEPATH_), $attrs['path']); if (isset($attrs['type']) && $attrs['type'] == 'skin') { for ($i = 0; isset($GLOBALS['skins'][$i]); ++$i) { $temp1 = str_replace('{skin}', $GLOBALS['skins'][$i], $attrs['path']); $path = ''; $temp = explode('/', $temp1); for ($i = 0; isset($temp[$i]); ++$i) { if (!empty($temp[$i])) { $path .= '/' . $temp[$i]; if (strpos($path, _BASEPATH_) === false) { continue; } if (!is_dir($path) && !$fileop->mkdir($path)) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'mkdir'; $this->manual_actions[$masize]['from'] = $temp1; $this->manual_actions[$masize]['to'] = ''; $this->manual_actions[$masize]['error'] = 'Unable to automatically create directory.'; break; } } } } } else { $path = ''; $temp = explode('/', $attrs['path']); for ($i = 0; isset($temp[$i]); ++$i) { if (!empty($temp[$i])) { $path .= '/' . $temp[$i]; if (strpos($path, _BASEPATH_) === false) { continue; } if (!is_dir($path) && !$fileop->mkdir($path)) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'mkdir'; $this->manual_actions[$masize]['from'] = $attrs['path']; $this->manual_actions[$masize]['to'] = ''; $this->manual_actions[$masize]['error'] = 'Unable to automatically create directory.'; break; } } } } } elseif ($mod_command->nodeName == 'sql') { $attrs = $mod_command->attributes; if (!isset($attrs['type'])) { $attrs['type'] = 'inline'; } if ($attrs['type'] == 'inline') { $query = $mod_command->firstChild->nodeValue; $query = trim($query, " \n\t;\r"); if (!@mysql_query($query)) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'sql'; $this->manual_actions[$masize]['from'] = $mod_command->firstChild->nodeValue; $this->manual_actions[$masize]['to'] = ''; $this->manual_actions[$masize]['error'] = mysql_error(); } } else { if (!$this->db_insert_file($this->package_path . '/' . $mod_command->firstChild->nodeValue)) { $this->error = true; $masize = count($this->manual_actions); $this->manual_actions[$masize]['type'] = 'sqlfile'; $this->manual_actions[$masize]['from'] = $this->package_path . '/' . $mod_command->firstChild->nodeValue; $this->manual_actions[$masize]['to'] = ''; $this->manual_actions[$masize]['error'] = mysql_error(); } } } $mod_command = $mod_command->nextSibling; } if (!$this->error) { $this->post_install($install_index); } } return !$this->error; }