Ejemplo n.º 1
0
 public function call(WhmCall $call, $tmo = 0)
 {
     $this->result = array();
     //echo "whm call=".$call->getCallName().",tmo=".$tmo."<br>";
     $opts = array('http' => array('method' => WHM_CALL_METHOD));
     if (WHM_CALL_METHOD == 'POST') {
         $opts['http']['content'] = $call->buildPostData();
     }
     if ($tmo > 0) {
         $opts['http']['timeout'] = $tmo;
     }
     $url = $this->whm_url . $call->buildUrl($this->skey);
     if (WHM_CALL_METHOD != 'POST') {
         $url .= '&' . $call->buildPostData();
     }
     $msg = @file_get_contents($url, false, stream_context_create($opts));
     if ($msg === FALSE) {
         $this->err_msg = "cann't connect to host";
         return false;
     }
     try {
         $xml = new SimpleXMLElement($msg);
         //print_r($xml);
         $result = new WhmResult();
         foreach ($xml->children() as $child) {
             if ($child->getName() == 'result') {
                 $result->status = $child['status'];
                 foreach ($child->children() as $node) {
                     $result->add($node->getName(), $node[0]);
                 }
                 break;
             }
         }
         return $result;
     } catch (Exception $e) {
         echo "msg=" . $msg . "<br>***********\n";
         return null;
     }
 }
Ejemplo n.º 2
0
 public function getPhyDir($vhost, $domain, $dir)
 {
     $node = apicall('vhost', 'getNode', array($vhost));
     if (!$node) {
         return false;
     }
     $whm = apicall('nodes', 'makeWhm', array($node));
     $whmCall = new WhmCall('core.whm', 'info_vh');
     $whmCall->addParam('name', $vhost);
     $result = $whm->call($whmCall, 10);
     if (!$result) {
         return false;
     }
     //$doc_root = $result->get("doc_root");
     $add_dir = $result->get("add_dir");
     $hosts = $result->get("host");
     $host = explode("\n", $hosts);
     $finded = false;
     foreach ($host as $h) {
         $hi = explode('|', $h);
         if (trim($hi[0]) == $domain) {
             $finded = true;
             $subdir = $hi[1];
             break;
         }
     }
     if (!$finded) {
         return false;
     }
     $phy_dir = $subdir . $add_dir;
     if ($dir[0] != '/') {
         $phy_dir .= '/';
     }
     $phy_dir .= $dir;
     return $phy_dir;
 }
Ejemplo n.º 3
0
 /**
  * 
  * 初始化一个节点
  * @param $node 节点名称
  * @param $level 初始化级别
  * 0   全部(首次初始化开始)
  * 1  除首次初始化全部
  * @deprecated vhms上不应该调用这个方法
  */
 public function init($node, $config_flag, $init_flag, $reboot_flag)
 {
     trigger_error('init方法废弃');
     $node_cfg = $GLOBALS['node_cfg'][$node];
     $whm = $this->makeWhm($node);
     $result = true;
     if ($config_flag == 1) {
         /*
          * 生成数据库连接文件etc/vh_db.xml
          * 这个文件为什么要放到etc呢?而不放到ext下面?
          * 问得好!权限问题,数据库连接文件包含重要的密码信息,要确保除超级用户外无人可访问。
          * 而ext目录下面是扩展目录,普通用户需要读和运行的权限。
          * 我们可以在ext/templete.xml放入一条<!--#include etc/vh_db.xml -->,把数据库连接文件包含进来.
          * 这样就可以加载etc/vh_db.xml文件了。
          */
         $driver = "bin/vhs_sqlite";
         $win = $node_cfg['win'];
         if ($win) {
             $driver .= ".dll";
         } else {
             $driver .= ".so";
         }
         //$phpmyadmin_password = getRandPasswd(12);
         $tpl = tpl::singleton();
         //$tpl->assign('phpmyadmin_password',$phpmyadmin_password);
         $tpl->assign('win', $win);
         $tpl->assign('skey', $GLOBALS['skey']);
         $tpl->assign('node', $node);
         $tpl->assign('driver', $driver);
         $tpl->assign('node_db', $GLOBALS['node_db']);
         if ($GLOBALS['node_db'] != 'sqlite') {
             $tpl->assign('col_map', daocall('vhost', 'getColMap', array($node)));
             $tpl->assign('load_sql', daocall('vhost', 'getLoadSql', array($node)));
             $tpl->assign('flush_sql', daocall('vhost', 'getFlushSql', array(null)));
             $tpl->assign('load_info_sql', daocall('vhostinfo', 'getLoadInfoSql', array(null)));
             $tpl->assign('table', daocall('vhost', 'getTable'));
             $tpl->assign('col', daocall('vhost', 'getCols'));
             global $db_cfg;
             if ($db_cfg['ftp']) {
                 $db = $db_cfg['ftp'];
             } else {
                 $db = $db_cfg['default'];
             }
             $db_local = $this->isLocalHost($db['host']);
             $node_local = $this->isLocalHost($node_cfg['host']);
             if ($db_local && !$node_local) {
                 $host = $_SERVER['SERVER_ADDR'];
                 if ($host == "") {
                     $host = $_SERVER['SERVER_NAME'];
                 }
                 if ($host == "" || $this->isLocalHost($host)) {
                     trigger_error("Cann't init node,I Cann't translate the db host.");
                     return false;
                 }
                 //如果db host是local,而节点不是local,则要替换db的host为公网IP
                 $db['host'] = $host;
             }
             $tpl->assign('db', $db);
         }
         $tpl->assign('dev', $node_cfg['dev']);
         $whmCall = new WhmCall('core.whm', 'write_file');
         $whmCall->addParam('file', 'etc/vh_db.xml');
         $content = $tpl->fetch('config/vh_db.xml');
         $whmCall->addParam('content', base64_encode($content));
         $result = $whm->call($whmCall);
         /*
          * 写入模板文件,etc/templete.xml
          */
         $content = $tpl->fetch('config/templete.xml');
         $whmCall = new WhmCall('core.whm', 'write_file');
         $whmCall->addParam('file', 'ext/templete.xml');
         $whmCall->addParam('content', base64_encode($content));
         $result = $whm->call($whmCall);
         /*
          * 写入ftp配置文件
          */
         $whmCall = new WhmCall('core.whm', 'write_file');
         if ($win) {
             $content = $tpl->fetch('config/linxftp.conf');
             $whmCall->addParam('file', 'etc/linxftp.conf');
         } else {
             $content = $tpl->fetch('config/proftpd.conf');
             $whmCall->addParam('file', '/vhs/proftpd/etc/proftpd.conf');
         }
         $whmCall->addParam('content', base64_encode($content));
         $result = $whm->call($whmCall);
         /*
          * 写do_config.php
          */
         $content = $tpl->fetch('config/db_config.conf');
         $whmCall = new WhmCall('core.whm', 'write_file');
         $whmCall->addParam('file', 'etc/db_config.php');
         $whmCall->addParam('content', base64_encode($content));
         $result = $whm->call($whmCall);
         $whmCall = new WhmCall('vhost.whm', 'reboot_ftp');
         $result = $whm->call($whmCall);
     }
     if ($init_flag == 1) {
         /*
          * 调用init_node,初始化节点,如开启磁盘quota等等操作
          */
         $whmCall = new WhmCall('vhost.whm', 'init_node');
         $whmCall->addParam('dev', $node_cfg['dev']);
         $whmCall->addParam('prefix', apicall('vhost', 'getPrefix'));
         //$whmCall->addParam('phpmyadmin_password',$phpmyadmin_password);
         $result = $whm->call($whmCall);
     }
     if ($reboot_flag == 1) {
         /*
          * 调用重启,使设置生效
          */
         $whmCall = new WhmCall('core.whm', 'reboot');
         $whm->call($whmCall);
     }
     if (!$result) {
         trigger_error($whmCall->getCallName() . " " . $whm->err_msg);
         return false;
     }
     return true;
 }
Ejemplo n.º 4
0
 private function getDbUsed($nodename, $name)
 {
     $whm = apicall('nodes', 'makeWhm', array($nodename));
     $whmCall = new WhmCall('getDbUsed');
     $whmCall->addParam('name', $name);
     return $whm->call($whmCall, 10);
 }
Ejemplo n.º 5
0
 public function del($node, $name)
 {
     $whm = apicall('nodes', 'makeWhm', array($node));
     if (!$whm) {
         return false;
     }
     $whmCall = new WhmCall('del_vh');
     $whmCall->addParam('destroy', 1);
     $whmCall->addParam('name', $name);
     if ($whm->call($whmCall)) {
         //	daocall('vhostinfo','delAllInfo',array($name));
         return daocall('vhost', 'delVhost', array($name, null));
     }
     return false;
 }
Ejemplo n.º 6
0
 /**
  * 同步产品到磁盘或者远程
  * @param  $user
  * @param  $param
  */
 public function sync($user, $params, $product_info)
 {
     $param = $params['name'];
     $whm = apicall('nodes', 'makeWhm', array($params['node']));
     if (!is_object($whm)) {
         echo "该空间所在节点不存在";
         return false;
     }
     if ($GLOBALS['node_db'] == 'sqlite') {
         //			if($params['resync'] == '1'){
         //				$whmCall = new WhmCall('del_vh');
         //				$whmCall->addParam('name',$param);
         //				$whm->call($whmCall,10);
         //			}
         $whmCall = new WhmCall('add_vh');
         $whmCall->addParam('doc_root', $params['doc_root']);
         if ($GLOBALS['node_cfg'][$params['node']]['win'] == 1) {
             $whmCall->addParam('user', 'a' . $params['uid']);
         } else {
             $whmCall->addParam('user', $params['uid']);
         }
         if ($product_info['db_quota'] > 0) {
             $whmCall->addParam('db_quota', $product_info['db_quota']);
         }
         //$whmCall->addParam('group', $params['gid']);
         $whmCall->addParam('templete', $product_info['templete']);
         //$whmCall->addParam('product_id', $params['product_id']);
         $whmCall->addParam('uid', $params['uid']);
         if ($params['create_time']) {
             $whmCall->addParam('create_time', $params['create_time']);
         }
         if ($params['expire_time']) {
             $whmCall->addParam('expire_time', $params['expire_time']);
         }
         if ($params['month']) {
             $whmCall->addParam('expire_time', $params['month'] * 2592000 + time());
         }
         $whmCall->addParam('subtemplete', $product_info['subtemplete']);
         $whmCall->addParam('domain', $product_info['domain']);
         $whmCall->addParam('subdir', $product_info['subdir']);
         $whmCall->addParam('subdir_flag', $product_info['subdir_flag']);
         $whmCall->addParam('htaccess', $product_info['htaccess']);
         $whmCall->addParam('ftp', $product_info['ftp']);
         $whmCall->addParam('log_file', $product_info['log_file']);
         $whmCall->addParam('access', $product_info['access']);
         $whmCall->addParam('max_connect', $product_info['max_connect']);
         $whmCall->addParam('speed_limit', $product_info['speed_limit']);
         $whmCall->addParam('cs', $product_info['cs']);
         $whmCall->addParam('envs', $product_info['envs']);
         $whmCall->addParam('cdn', $product_info['cdn']);
         $whmCall->addParam('db_type', $product_info['db_type']);
         $whmCall->addParam('max_subdir', $product_info['max_subdir']);
         $whmCall->addParam('max_worker', $product_info['max_worker']);
         $whmCall->addParam('max_queue', $product_info['max_queue']);
         $whmCall->addParam('log_handle', $product_info['log_handle']);
         $whmCall->addParam('flow', $product_info['flow']);
         if ($params['passwd']) {
             $whmCall->addParam('passwd', $params['passwd']);
         }
         if ($params['status']) {
             $whmCall->addParam('status', $params['status']);
         }
     } else {
         $whmCall = new WhmCall('add_vh');
     }
     $whmCall->addParam('name', $param);
     $whmCall->addParam('init', $params['init']);
     $whmCall->addParam('web_quota', $product_info['web_quota']);
     return $whm->call($whmCall, 10);
 }