Ejemplo n.º 1
0
 private function migrate_allconf2xml()
 {
     if (($vhosts = $this->_root->GetChildren('virtualhost')) != NULL) {
         if (!is_array($vhosts)) {
             $vhosts = array($vhosts);
         }
         $filemap = DPageDef::GetInstance()->GetFileMap(DInfo::CT_VH);
         foreach ($vhosts as $vh) {
             $vhname = $vh->Get(CNode::FLD_VAL);
             $vhroot = $vh->GetChildVal('vhRoot');
             $vhconf = $vh->GetChildVal('configFile');
             $conffile = PathTool::GetAbsFile($vhconf, 'VR', $vhname, $vhroot);
             $vhdata = new CData(DInfo::CT_VH, $conffile);
             $this->save_xml_file($vhdata->_root, $filemap, $vhdata->_xmlpath);
             $this->copy_permission($vhdata->_path, $vhdata->_xmlpath);
             error_log("  converted {$vhdata->_path} to {$vhdata->_xmlpath}\n");
         }
     }
     if (($tps = $this->_root->GetChildren('vhTemplate')) != NULL) {
         if (!is_array($tps)) {
             $tps = array($tps);
         }
         $filemap = DPageDef::GetInstance()->GetFileMap(DInfo::CT_TP);
         foreach ($tps as $tp) {
             $tpconf = $tp->GetChildVal('templateFile');
             $conffile = PathTool::GetAbsFile($tpconf, 'SR');
             $tpdata = new CData(DInfo::CT_TP, $conffile);
             $this->save_xml_file($tpdata->_root, $filemap, $tpdata->_xmlpath);
             $this->copy_permission($tpdata->_path, $tpdata->_xmlpath);
             error_log("  converted {$tpdata->_path} to {$tpdata->_xmlpath}\n");
         }
     }
     $filemap = DPageDef::GetInstance()->GetFileMap(DInfo::CT_SERV);
     $this->save_xml_file($this->_root, $filemap, $this->_xmlpath);
     $this->copy_permission($this->_path, $this->_xmlpath);
     error_log("  converted {$this->_path} to {$this->_xmlpath}\n");
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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;
 }
Ejemplo n.º 5
0
 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;
 }