protected function instantiateTemplate() { $tpname = $this->_disp->Get(DInfo::FLD_ViewName); $vhname = $this->_disp->GetLast(DInfo::FLD_REF); $s_tpnode = $this->_serv->GetChildNodeById('vhTemplate', $tpname); if ($s_tpnode == NULL) { return false; } $s_vhnode = $s_tpnode->GetChildNodeById('member', $vhname); if ($s_vhnode == NULL) { return false; } $confpath = $this->getConfFilePath(DInfo::CT_TP, $tpname); $tp = new CData(DInfo::CT_TP, $confpath); if (($conferr = $tp->GetConfErr()) != NULL) { $this->_disp->Set(DInfo::FLD_TopMsg, $conferr); return false; } $tproot = $tp->GetRootNode(); $configfile = $tproot->GetChildVal('configFile'); if ($configfile == NULL) { return false; } $vhRoot_path = ''; if (strncasecmp('$VH_ROOT', $configfile, 8) == 0) { $vhRoot_path = $s_vhnode->GetChildVal('vhRoot'); // customized if ($vhRoot_path == NULL) { //default $vhRoot_path = $tproot->GetChildVal('vhRoot'); if ($vhRoot_path == NULL) { return false; } } } $configfile = PathTool::GetAbsFile($configfile, 'VR', $vhname, $vhRoot_path); $vh = new CData(DInfo::CT_VH, $configfile, "`{$vhname}"); if (($conferr = $vh->GetConfErr()) != NULL) { $this->_disp->Set(DInfo::FLD_TopMsg, $conferr); return false; } $vhroot = $tproot->GetChildren('virtualHostConfig'); if ($vhroot == false) { return false; } $vh->SetRootNode($vhroot); $vh->SaveFile(); // save serv file $basemap = new DTblMap(array('', '*virtualhost$name'), 'V_TOPD'); $tproot->AddChild(new CNode('name', $vhname)); $tproot->AddChild(new CNode('note', "Instantiated from template {$tpname}")); $basemap->Convert(0, $tproot, 1, $this->_serv->GetRootNode()); $s_vhnode->RemoveFromParent(); $domains = $s_vhnode->GetChildVal('vhDomain'); if ($domains == NULL) { $domains = $vhname; } // default if (($domainalias = $s_vhnode->GetChildVal('vhAliases')) != NULL) { $domains .= ", {$domainalias}"; } $listeners = $s_tpnode->GetChildVal('listeners'); $lns = preg_split("/, /", $listeners, -1, PREG_SPLIT_NO_EMPTY); foreach ($lns as $ln) { $listener = $this->_serv->GetChildNodeById('listener', $ln); if ($listener != NULL) { $vhmap = new CNode('vhmap', $vhname); $vhmap->AddChild(new CNode('domain', $domains)); $listener->AddChild($vhmap); } else { error_log("cannot find listener {$ln} \n"); } } $this->_serv->SaveFile(); return true; }
private function write_file($filepath, $buf) { if (!file_exists($filepath)) { // new file, check path exists if (!PathTool::createFile("{$filepath}.new", $err)) { error_log("failed to create file {$filepath} : {$err} \n"); return FALSE; } } $fd = fopen("{$filepath}.new", 'w'); if (!$fd) { error_log("failed to open in write mode for {$filepath}.new"); return FALSE; } if (fwrite($fd, $buf) === FALSE) { error_log("failed to write temp config for {$filepath}.new"); return FALSE; } fclose($fd); @unlink("{$filepath}.bak"); if (file_exists($filepath) && !rename($filepath, "{$filepath}.bak")) { error_log("failed to rename {$filepath} to {$filepath}.bak"); return FALSE; } if (!rename("{$filepath}.new", $filepath)) { error_log("failed to rename {$filepath}.new to {$filepath}"); return FALSE; } return TRUE; }
public function GetVHRoot() { // type = 'SR', 'VR' if ($this->_view == self::CT_VH) { $vn = $this->_viewName; if (($vh = $this->_servData->GetChildNodeById('virtualhost', $vn)) != NULL) { $vhroot = PathTool::GetAbsFile($vh->GetChildVal('vhRoot'), 'SR', $vn); return $vhroot; } } return NULL; }
private function validate_install_path($path) { $path = PathTool::clean($path); if ($path == '') { $this->pass_val['err']['installPath'] = DMsg::Err('err_valcannotempty'); return FALSE; } if ($path[0] != '/') { $this->pass_val['err']['installPath'] = DMsg::Err('err_requireabspath'); return FALSE; } if (preg_match('/([;&"|#$?`])/', $path)) { $this->pass_val['err']['installPath'] = DMsg::Err('err_illegalcharfound'); return FALSE; } //parent exists. if (!is_dir($path)) { if (is_file($path)) { $this->pass_val['err']['installPath'] = DMsg::Err('err_invalidpath'); return FALSE; } $testpath = dirname($path); if (!is_dir($testpath)) { $this->pass_val['err']['installPath'] = DMsg::Err('err_parentdirnotexist'); return FALSE; } } else { $testpath = $path; } if ($testpath == '.' || $testpath == '/' || PathTool::isDenied($testpath)) { $this->pass_val['err']['installPath'] = 'Illegal location'; return FALSE; } return TRUE; }
public function chkAttr_file_val($attr, $val, &$err) { //this is public clearstatcache(); $err = NULL; if ($attr->_type == 'filep') { $path = substr($val, 0, strrpos($val, '/')); } else { $path = $val; if ($attr->_type == 'file1') { $pos = strpos($val, ' '); if ($pos > 0) { $path = substr($val, 0, $pos); } } } $res = $this->chk_file1($attr, $path, $err); if ($attr->_type == 'filetp') { $pathtp = SERVER_ROOT . 'conf/templates/'; if (strstr($path, $pathtp) === FALSE) { $err = ' Template file must locate within $SERVER_ROOT/conf/templates/'; $res = -1; } else { if (substr($path, -5) != '.conf') { $err = ' Template file name needs to be ".conf"'; $res = -1; } } } elseif ($attr->_type == 'filevh') { $pathvh = SERVER_ROOT . 'conf/vhosts/'; if (strstr($path, $pathvh) === FALSE) { $err = ' VHost config file must locate within $SERVER_ROOT/conf/vhosts/, suggested value is $SERVER_ROOT/conf/vhosts/$VH_NAME/vhconf.conf'; $res = -1; } else { if (substr($path, -5) != '.conf') { $err = ' VHost config file name needs to be ".conf"'; $res = -1; } } } if ($res == -1 && $_POST['file_create'] == $attr->GetKey() && $this->allow_create($attr, $path)) { if (PathTool::createFile($path, $err, $attr->GetKey())) { $err = "{$path} has been created successfully."; } $res = 0; // make it always point to curr page } return $res; }
public function LoadLog($field) { $this->_serverLog = PathTool::GetAbsFile($this->_servData->GetChildVal('errorlog'), 'SR'); if ($field == SInfo::DATA_DASH_LOG) { $logdata = LogViewer::GetDashErrLog($this->_serverLog); } else { $logdata = LogViewer::GetErrLog($this->_serverLog); } return $logdata; }
public static function GetAbsFile($filename, $type, $vhname = '', $vhroot = '') { // type = 'SR', 'VR' if (strpos($filename, '$VH_NAME') !== false) { $filename = str_replace('$VH_NAME', $vhname, $filename); } if ($filename[0] == '$') { if (strncasecmp('$SERVER_ROOT', $filename, 12) == 0) { $filename = SERVER_ROOT . substr($filename, 13); } elseif ($type == 'VR' && strncasecmp('$VH_ROOT', $filename, 8) == 0) { $vhrootf = PathTool::GetAbsFile($vhroot, 'SR', $vhname); if (substr($vhrootf, -1, 1) !== '/') { $vhrootf .= '/'; } $filename = $vhrootf . substr($filename, 9); } } elseif ($filename[0] == '/') { if (isset($_SERVER['LS_CHROOT'])) { $root = $_SERVER['LS_CHROOT']; $len = strlen($root); if (strncmp($filename, $root, $len) == 0) { $filename = substr($filename, $len); } } } return $filename; }