示例#1
0
 private function init_special()
 {
     $lines = file($this->_path);
     if ($lines === FALSE) {
         return FALSE;
     }
     $this->_root = new CNode(CNode::K_ROOT, $this->_id, CNode::T_ROOT);
     $items = array();
     if ($this->_id == 'MIME') {
         foreach ($lines as $line) {
             if (($c = strpos($line, '=')) > 0) {
                 $suffix = trim(substr($line, 0, $c));
                 $type = trim(substr($line, $c + 1));
                 $m = new CNode('index', $suffix);
                 $m->AddChild(new CNode('suffix', $suffix));
                 $m->AddChild(new CNode('type', $type));
                 $items[$suffix] = $m;
             }
         }
     } elseif ($this->_id == 'ADMUSR' || $this->_id == 'V_UDB') {
         foreach ($lines as $line) {
             $parsed = explode(':', trim($line));
             $size = count($parsed);
             if ($size == 2 || $size == 3) {
                 $name = trim($parsed[0]);
                 $pass = trim($parsed[1]);
                 if ($name != '' && $pass != '') {
                     $u = new CNode('index', $name);
                     $u->AddChild(new CNode('name', $name));
                     $u->AddChild(new CNode('passwd', $pass));
                     if ($size == 3 && ($group = trim($parsed[2])) != '') {
                         $u->AddChild(new CNode('group', $group));
                     }
                     $items[$name] = $u;
                 }
             }
         }
     } elseif ($this->_id == 'V_GDB') {
         foreach ($lines as $line) {
             $parsed = explode(':', trim($line));
             if (count($parsed) == 2) {
                 $group = trim($parsed[0]);
                 $users = trim($parsed[1]);
                 if ($group != '') {
                     $g = new CNode('index', $group);
                     $g->AddChild(new CNode('name', $group));
                     $g->AddChild(new CNode('users', $users));
                     $items[$group] = $g;
                 }
             }
         }
     }
     ksort($items, SORT_STRING);
     reset($items);
     foreach ($items as $item) {
         $this->_root->AddChild($item);
     }
     return TRUE;
 }
示例#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;
 }