Пример #1
0
 public static function up($path)
 {
     if ($path == self::SEP || $path == "") {
         return null;
     }
     $ps = PathUtil::splitPath($path);
     array_pop($ps);
     return join(self::SEP, $ps) . self::SEP;
 }
Пример #2
0
 /**
  * Returns a context for computing this resource in case it is possible.
  *
  * Useful to avoid teleporting.
  *
  * @return null|string
  */
 public function getContextForProcessInSinglePlace()
 {
     if (!$this->isLocal()) {
         return null;
     }
     if (PathUtil::basename($this->original) === $this->target) {
         return dirname($this->original);
     }
 }
Пример #3
0
 /**
  * @depends testGetAllModelClassNames
  */
 public function testGetAllMungableModelClassNames()
 {
     $modelClassNames = PathUtil::getAllMungableModelClassNames();
     $compareData = array('Account', 'Campaign', 'Contact', 'Conversation', 'EmailMessage', 'EmailTemplate', 'ExportItem', 'GameReward', 'MarketingList', 'Meeting', 'Mission', 'Note', 'Opportunity', 'SavedReport', 'Product', 'SocialItem', 'Task', 'ContactWebForm', 'Project', 'SavedCalendar');
     $this->assertEquals($compareData, $modelClassNames);
     $modelClassNames2 = PathUtil::getAllMungableModelClassNames();
     $this->assertEquals($modelClassNames, $modelClassNames2);
     $modelClassNames3 = PathUtil::getAllMungableModelClassNames();
     $this->assertEquals($modelClassNames2, $modelClassNames3);
 }
Пример #4
0
function copyFiles($sd, $dd)
{
    global $fs;
    foreach ($fs->ls($sd) as $fn) {
        $sfp = PathUtil::rel($sd, $fn);
        $dfp = PathUtil::rel($dd, $fn);
        //print "copy $sfp $dfp<BR>\n";
        if ($fs->isDir($sfp)) {
            copyFiles($sfp, $dfp);
        } else {
            $fs->setContent($dfp, $fs->getContent($sfp));
        }
    }
}
Пример #5
0
 static function getFileName($e)
 {
     $fname = "";
     if (isset($e["nearest"])) {
         if (is_array($e["nearest"])) {
             foreach ($e["nearest"] as $s) {
                 $fname .= "{$s},";
             }
         } else {
             $fname = $e["nearest"];
         }
     } else {
         $fname = $e["filename"];
         $fname = PathUtil::name($fname);
     }
     return $fname;
 }
Пример #6
0
function getDirInfo2($path, $base)
{
    global $fs;
    $dst = array();
    if (!$fs->exists($path)) {
        return $dst;
    }
    $files = $fs->ls($path);
    foreach ($files as $e) {
        $fp = PathUtil::rel($path, $e);
        if ($fs->isDir($fp)) {
            $dst += getDirInfo2($fp, $base);
        } else {
            $dst[PathUtil::relPath($fp, $base)] = $fs->getMetaInfo($fp);
            //$dst+=array( PathUtil::relPath( $fp,$base ) => $fs->getMetaInfo($fp) );
        }
    }
    return $dst;
}
 /**
  * @param User $user
  * @param Role $role
  */
 public static function userBeingRemovedFromRole(User $user, Role $role)
 {
     foreach (PathUtil::getAllMungableModelClassNames() as $modelClassName) {
         $mungeTableName = self::getMungeTableName($modelClassName);
         $userId = $user->id;
         $sql = "select securableitem_id\n                        from   ownedsecurableitem\n                        where  owner__user_id = {$userId}";
         $securableItemIds = ZurmoRedBean::getCol($sql);
         self::bulkDecrementParentRolesCounts($mungeTableName, $securableItemIds, $role);
         $sql = "select {$mungeTableName}.securableitem_id\n                        from   {$mungeTableName}, _group__user\n                        where  {$mungeTableName}.munge_id = concat('G', _group__user._group_id) and\n                               _group__user._user_id = {$userId}";
         $securableItemIds = ZurmoRedBean::getCol($sql);
         self::bulkDecrementParentRolesCounts($mungeTableName, $securableItemIds, $role);
         /*
          * This additional step I don't think is needed because the sql query above actually traps
          * the upstream explicit securableItems because the lower level groups will already have a point for
          * each of them.
             What groups are the user part of and what groups are those groups children of recursively?
             For any models that have that group explicity for read, subtract 1 point for the user's
             upstream roles from the disconnected role.
         */
         self::garbageCollect($mungeTableName);
     }
 }
Пример #8
0
 private function upOrOfflineService($op_type)
 {
     // 1.argument receive and preprocess
     $res = "";
     $argus = self::commonArgusProcess($res);
     if ($argus === FALSE) {
         echo json_encode($res);
         return;
     }
     $user = $argus["user"];
     $path = $argus["path"];
     $idc = $argus["idc"];
     $main_buss_id = $argus["main_buss_id"];
     $sub_buss_id = $argus["sub_buss_id"];
     $service_name = $this->getRequest("service_name", "");
     if ($service_name === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "paramter: 'service_name({$service_name})'is required!");
         echo json_encode($res);
         return;
     }
     $service_list = preg_split("/[,]+/", trim($service_name, ","));
     //validate for ip_port
     if (ArgsUtil::ipPortsValidation($service_list) === FALSE) {
         //failed to add any new services
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "ilegal services : {$service_name} under {$path}!");
         echo json_encode($res);
         return;
     }
     // 2. check node exist and is node father type
     $check_res = ServiceController::checkServFatherNode($path, $main_buss_id);
     if ($check_res != InfoDescUtil::QCONF_OK) {
         $res = InfoDescUtil::getErrorMsg($check_res);
         echo json_encode($res);
         return;
     }
     // 3. do up or offline
     $op_type_msg = $op_type === InfoDescUtil::OP_TYPE_OFFLINE ? "offline" : "up";
     $idc_list = preg_split("/[,]+/", $idc);
     // split by ,
     foreach ($idc_list as $idc_each) {
         $idc_host = ZkConf::getZkHost($idc_each);
         $zk_web = new QconfZkWebBase(Log::INFO);
         $zk_web->connect($idc_host);
         $get_ret = ServiceController::getServicesAndStatusWithLink($zk_web, $path, $idc_each, $exist_services);
         if ($get_ret != InfoDescUtil::QCONF_OK) {
             $res = InfoDescUtil::getErrorMsg($get_ret);
             echo json_encode($res);
             return;
         }
         foreach ($service_list as $service) {
             $show_ser_path = PathUtil::unionPath($path, $service);
             // check service exist
             if (!array_key_exists($service, $exist_services)) {
                 $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SERVICE_NO_EXIST);
                 echo json_encode($res);
                 return;
             }
             if ($op_type === InfoDescUtil::OP_TYPE_OFFLINE) {
                 //check up service cout for offline operation
                 $is_last = TRUE;
                 foreach ($exist_services as $one_exist_service => $service_status) {
                     if ($service_status === InfoDescUtil::SERV_STATUS_UP && $one_exist_service != $service) {
                         $is_last = FALSE;
                         break;
                     }
                 }
                 if ($is_last) {
                     $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_OFFILE_SERVICE_ONLY);
                     QconfMgrLog::err(__FILE__, __LINE__, "{$service} is the last up service under {$path}");
                     echo json_encode($res);
                     return;
                 }
                 $ret = ServiceController::offlineServiceWithLink($zk_web, $path, $service, $idc_each);
                 $exist_services[$service] = InfoDescUtil::SERV_STATUS_DOWN;
             } else {
                 $ret = ServiceController::upServiceWithLink($zk_web, $path, $service, $idc_each);
             }
             if ($ret != InfoDescUtil::QCONF_OK) {
                 $res = InfoDescUtil::getErrorMsg($ret);
                 QconfMgrLog::err(__FILE__, __LINE__, "{$op_type_msg} service!");
                 OpServ::insert($op_type, $show_ser_path, $idc_each, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $user, "");
                 echo json_encode($res);
                 return;
             }
             OpServ::insert($op_type, $show_ser_path, $idc_each, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $user, $op_type === InfoDescUtil::OP_TYPE_OFFLINE ? InfoDescUtil::SERV_STATUS_OFFLINE : InfoDescUtil::SERV_STATUS_UP);
         }
     }
     $res = array("errno" => "0", "errmsg" => "", "data" => "{$op_type_msg} service success");
     $json = json_encode($res);
     echo $json;
     return;
 }
 protected function resolveElementsSidebarContent()
 {
     $uiAccessibleElements = PathUtil::getAllUIAccessibleBuilderElementClassNames();
     $uiAccessibleContent = $this->generateWidgetTagsForUIAccessibleElements($uiAccessibleElements);
     $this->wrapContentInDiv($uiAccessibleContent, $this->resolveElementsSidebarHtmlOptions());
     return $uiAccessibleContent;
 }
Пример #10
0
 public static function autoBuildDatabase(&$messageLogger, $autoBuildTestModels = false)
 {
     ZurmoDatabaseCompatibilityUtil::createStoredFunctionsAndProcedures();
     ZurmoDatabaseCompatibilityUtil::createActualPermissionsCacheTable();
     ZurmoDatabaseCompatibilityUtil::createNamedSecurableActualPermissionsCacheTable();
     ZurmoDatabaseCompatibilityUtil::createActualRightsCacheTable();
     $messageLogger->addInfoMessage(Zurmo::t('InstallModule', 'Searching for models'));
     $rootModels = PathUtil::getAllCanHaveBeanModelClassNames();
     $messageLogger->addInfoMessage(Zurmo::t('InstallModule', 'Models catalog built.'));
     RedBeanModelsToTablesAdapter::generateTablesFromModelClassNames($rootModels, $messageLogger);
     ReadPermissionsSubscriptionUtil::buildTables();
     if ($autoBuildTestModels) {
         TestSuite::buildDependentTestModels($messageLogger);
     }
 }
Пример #11
0
 public static function insert($parent_node_id, $node, $node_type_code, $node_whole, $main_buss_id, $sub_buss_id, $idc, $note)
 {
     ArgsUtil::setSQLEscape($node);
     ArgsUtil::setSQLEscape($node_whole);
     ArgsUtil::setSQLEscape($idc);
     ArgsUtil::setSQLEscape($note);
     ArgsUtil::setSQLEscape($node_type_code);
     ArgsUtil::setVal($parent_node_id);
     ArgsUtil::setVal($main_buss_id);
     $p_query = "select * from qconf_node where node_id = '{$parent_node_id}'";
     $p_res = self::executeQuery($p_query);
     if ($p_res === FALSE) {
         return FALSE;
     }
     $p_num = mysql_num_rows($p_res);
     if ($p_num === 0) {
         QconfMgrLog::err(__FILE__, __LINE__, "EXEC '{$p_query}' failed!");
         return FALSE;
     }
     $p_row = mysql_fetch_array($p_res, MYSQL_ASSOC);
     $p_level = $p_row["node_level"];
     $node_level = intval($p_level) + 1;
     $cal_node_level = PathUtil::calNodeLevel($node_whole);
     $query = "insert into qconf_node values(NULL, '{$parent_node_id}', '{$node}', '{$node_type_code}'," . " '{$node_whole}', '{$cal_node_level}', {$main_buss_id}, {$sub_buss_id}, '{$idc}', '{$note}')";
     $ret = self::executeQuery($query);
     if ($ret === FALSE) {
         QconfMgrLog::err(__FILE__, __LINE__, "EXEC '{$query}' failed!");
         return FALSE;
     }
     // update the parent node type
     if ($p_row["node_type_code"] == InfoDescUtil::NODE_TYPE_NORMAL) {
         $update = "update qconf_node set node_type_code = '" . InfoDescUtil::NODE_TYPE_NORMAL_FATHER . "' where node_id = '{$parent_node_id}'";
         $ret = self::executeQuery($update);
         if ($ret === FALSE) {
             QconfMgrLog::err(__FILE__, __LINE__, "EXEC '{$update}' failed!");
             return FALSE;
         }
     }
     return TRUE;
 }
 /**
  * Update read subscription table for all users and models
  * @param MessageLogger $messageLogger
  * @param null | array $modelClassNames
  * @param array $arrayOfModelIdsToUpdate
  * permission subscription table just for account ids that exist in account temp build table
  * @return bool
  */
 public static function updateAllReadSubscriptionTables(MessageLogger $messageLogger, $modelClassNames = null, $arrayOfModelIdsToUpdate = array())
 {
     $loggedUser = Yii::app()->user->userModel;
     $users = User::getAll();
     $updateStartTimestamp = time();
     static::setReadPermissionUpdateStatus(static::STATUS_STARTED);
     $messageLogger->addDebugMessage(Zurmo::t('ZurmoModule', 'Starting read permission building for all users.'));
     foreach ($users as $user) {
         if ($user->isSystemUser) {
             $messageLogger->addDebugMessage(Zurmo::t('ZurmoModule', 'Skipping system user with userID: {id}', array('{id}' => $user->id)));
             continue;
         }
         $messageLogger->addDebugMessage(Zurmo::t('ZurmoModule', 'Starting read permission building for userID: {id}', array('{id}' => $user->id)));
         $startTime = microtime(true);
         Yii::app()->user->userModel = $user;
         if (!is_array($modelClassNames) || empty($modelClassNames)) {
             $modelClassNames = PathUtil::getAllReadSubscriptionModelClassNames();
         }
         if (!empty($modelClassNames) && is_array($modelClassNames)) {
             foreach ($modelClassNames as $modelClassName) {
                 if ($modelClassName != 'Account') {
                     static::updateReadSubscriptionTableByModelClassNameAndUser($modelClassName, Yii::app()->user->userModel, $updateStartTimestamp, true, $messageLogger);
                 } else {
                     static::updateReadSubscriptionTableByModelClassNameAndUser($modelClassName, Yii::app()->user->userModel, $updateStartTimestamp, false, $messageLogger, $arrayOfModelIdsToUpdate);
                 }
             }
         }
         $endTime = microtime(true);
         $executionTimeMs = $endTime - $startTime;
         $messageLogger->addDebugMessage(Zurmo::t('ZurmoModule', 'Ending read permission building for userID: {id}', array('{id}' => $user->id)));
         $messageLogger->addDebugMessage(Zurmo::t('ZurmoModule', 'Build time for userID: {id} - {miliSeconds}', array('{id}' => $user->id, '{miliSeconds}' => $executionTimeMs)));
     }
     Yii::app()->user->userModel = $loggedUser;
     static::setTimeReadPermissionUpdateTimestamp($updateStartTimestamp);
     static::setReadPermissionUpdateStatus(static::STATUS_COMPLETED);
     return true;
 }
Пример #13
0
 public static function getAllClassNamesByPathFolder($folder)
 {
     assert('is_string($folder)');
     $classNames = array();
     $className = get_called_class();
     $alias = 'application.modules.' . $className::getDirectoryName() . '.' . $folder;
     $classNames = PathUtil::getAllClassNamesByPathAlias($alias);
     return $classNames;
 }
Пример #14
0
 public function endsWith($postfix)
 {
     return PathUtil::endsWith($this->name(), $postfix);
 }
Пример #15
0
 public function passNodeAction()
 {
     $this->setNoViewRender(true);
     //        $perm_id = isset($_POST['perm_id']) ? $_POST['perm_id'] : "";
     $perm_id = $this->getRequest("perm_id", "");
     $admin_user = $this->userInfo["userName"];
     // 2. parameter is not right
     if ($perm_id === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "'perm_id' is NULL!");
         echo json_encode($res);
         return;
     }
     // 3. get the perm_id value failed
     $res = PermServ::selectById($perm_id);
     if ($res === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         QconfMgrLog::err(__FILE__, __LINE__, "get the value of perm_id '{$perm_id}' failed!");
         echo json_encode($res);
         return;
     }
     $main_buss_id = $res["main_buss_id"];
     $qconf_path = PathUtil::getQconfPath($res["node"]);
     $node = $res["node"];
     $node_val = $res["node_val"];
     $idc = trim($res['idc'], ",");
     $idc_list = preg_split("/[,]+/", $idc);
     $succ_flgs = TRUE;
     $op_user = $res["apply_user"];
     $sub_buss_id = "NULL";
     $op_user_email = $res["apply_user_email"];
     $apply_status_code = $res["apply_status_code"];
     if (intval($apply_status_code) !== intval(InfoDescUtil::APPLY_STATUS_EXAMINE)) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "{$node} has already been deal with!");
         echo json_encode($res);
         return;
     }
     if ($idc != "") {
         foreach ($idc_list as $idc_tmp) {
             $idc_host = ZkConf::getZkHost($idc_tmp);
             // 3. idc zookeeper server not exist
             if ($idc_host === NULL) {
                 $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST);
                 QconfMgrLog::err(__FILE__, __LINE__, "{$idc_host} is not in ZOOKEEPER_SVR");
                 $succ_flgs = FALSE;
                 continue;
             }
             $zk_web = new QconfZkWebBase(Log::INFO);
             $zk_web->connect($idc_host);
             $ret = -1;
             $retry_time = 0;
             while ($ret === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) {
                 QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to add conf for {$qconf_path} on {$idc_host}");
                 $ret = $zk_web->add_conf($qconf_path, $node_val);
                 $retry_time++;
             }
             if ($ret === -1) {
                 // 4. zookeeper add failed
                 $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
                 OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc_tmp, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 QconfMgrLog::err(__FILE__, __LINE__, "add {$qconf_path} on {$idc_tmp} failed!");
                 $succ_flgs = FALSE;
                 continue;
             }
             $idc_on .= ",{$idc_tmp}";
         }
     }
     // 6. the zookeeper operation has failed
     if ($succ_flgs === FALSE) {
         $idc_on = trim($idc_on, ",");
         if ($idc_on != NULL) {
             $ret = NodeServ::addRoot($node, $main_buss_id, $idc_on);
             $ret = PermServ::modPerm($perm_id, InfoDescUtil::APPLY_STATUS_PASS);
             if ($ret === TRUE) {
                 NotifyUtil::notifyByQHEmail($op_user_email, "node: '{$node}' apply on '{$idc}' has been PASSED", " 在机房 {$idc_on} 申请的根节点 {$node} 已经被通过! ");
             }
         }
         echo json_encode($res);
         return;
     }
     $ret = NodeServ::addRoot($node, $main_buss_id, $idc);
     // 7. database operation failed
     if ($ret === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc, InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
         QconfMgrLog::err(__FILE__, __LINE__, "addRoot in qconf_node failed!");
         echo json_encode($res);
         return;
     }
     $ret = PermServ::modPerm($perm_id, InfoDescUtil::APPLY_STATUS_PASS);
     // 8. update the apply staus failed
     if ($ret === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc, InfoDescUtil::OP_STATUS_MYSQL_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
         QconfMgrLog::err(__FILE__, __LINE__, "update the apply stats in qconf_perm failed!");
         echo json_encode($res);
         return;
     }
     OpServ::insert(InfoDescUtil::OP_TYPE_AUDIT_PASS, $qconf_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, $node_val);
     // 9. return the data
     $res = array("errno" => "0", "errmsg" => "", "data" => "");
     NotifyUtil::notifyByQHEmail($op_user_email, "node: '{$node}' apply on '{$idc}' has been PASSED", " 在机房 {$idc} 申请的根节点 {$node} 已经通过! ", $admin_user);
     $json = json_encode($res);
     echo $json;
 }
 public function rollbackAction()
 {
     $path = trim($this->getRequest("path", ""), "/");
     $idc = $this->getRequest("idc", "");
     $main_buss_id = $this->getRequest("main_buss_id", "");
     $op_user = $this->userInfo["userName"];
     // 1. parameter null
     if ($path === "" || $main_buss_id === "" || $idc === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter 'main_buss_id', 'path' or 'idc' is null!");
         echo json_encode($res);
         return;
     }
     // 2. check node exist
     $path = "/" . $path;
     $node = NodeServ::getNodeByNodeWhole($path, $main_buss_id);
     if ($node === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "node({$path}) with main_buss_id({$main_buss_id}) not exist!");
         echo json_encode($res);
         return;
     }
     $node_whole = $node["node_whole"];
     //[USERPERM CHECK]
     $userperm_ret = UserPermServ::checkPerm($op_user, $node_whole);
     if ($userperm_ret === FALSE) {
         QconfMgrLog::err(__FILE__, __LINE__, "Insufficient permission of {$op_user} on node {$node_whole}");
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_USER_PERM_PERMISSION_DENIED);
         echo json_encode($res);
         return;
     }
     $main_buss_id = $node["main_buss_id"];
     $sub_buss_id = $node["sub_buss_id"];
     // 3. idc validation
     $cur_idcs = $node["idc"];
     $check_res = self::idcValidation($idc, $cur_idcs);
     if ($check_res["errno"] != "0") {
         echo json_encode($check_res);
         return;
     }
     // 4. get snapshot content
     $snapshot_content = SnapShotUtil::getSnapShotContent($main_buss_id, $node_whole);
     if ($snapshot_content === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_MODULE_FAILED);
         QconfMgrLog::err(__FILE__, __LINE__, "failed to get snapshot by node_whole({$node_whole}), main_buss_id({$main_buss_id})");
         echo json_encode($res);
         return;
     }
     // 5.rollback
     if (!array_key_exists($idc, $snapshot_content)) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_IDC_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "snapshot of node_whole({$node_whole}), main_buss_id({$main_buss_id}) do not exist on idc({$idc}) ");
         echo json_encode($res);
         return;
     }
     $result_idc = $snapshot_content[$idc];
     if (!array_key_exists("conf", $result_idc) || !array_key_exists("serv", $result_idc)) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_SNAPSHOT_FILE_ERROR);
         QconfMgrLog::err(__FILE__, __LINE__, "snapshot error of node_whole({$node_whole}), main_buss_id({$main_buss_id})");
         echo json_encode($res);
         return;
     }
     $idc_host = ZkConf::getZkHost($idc);
     $zk_web = new QconfZkWebBase(Log::INFO);
     $zk_web->connect($idc_host);
     $result_conf = $result_idc["conf"];
     foreach ($result_conf as $key => $value) {
         $set_ret = NodeController::setConfWithLink($zk_web, $key, $idc, $value);
         if ($set_ret != InfoDescUtil::QCONF_OK) {
             OpServ::insert(InfoDescUtil::OP_TYPE_MOD, $key, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
             $res = InfoDescUtil::getErrorMsg($set_ret);
             QconfMgrLog::err(__FILE__, __LINE__, "replace node value by snapshot failed, node_whole({$node_whole}),\n                    main_buss_id({$main_buss_id})");
             echo json_encode($res);
             return;
         }
         OpServ::insert(InfoDescUtil::OP_TYPE_MOD, $key, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, $value);
     }
     $result_serv = $result_idc["serv"];
     foreach ($result_serv as $key => $hosts) {
         $current_serv_no_statu = array();
         $snapshot_serv_no_statu = array_keys($hosts);
         $get_ret = ServiceController::getServicesWithLink($zk_web, $key, $idc, $current_serv_no_statu);
         if ($get_ret != InfoDescUtil::QCONF_OK) {
             $res = InfoDescUtil::getErrorMsg($get_ret);
             QconfMgrLog::err(__FILE__, __LINE__, "get service failed, key({$key})!");
             echo json_encode($res);
             return;
         }
         $serv_to_add = array_diff($snapshot_serv_no_statu, $current_serv_no_statu);
         $serv_to_delete = array_diff($current_serv_no_statu, $snapshot_serv_no_statu);
         $serv_to_modify = array_intersect($snapshot_serv_no_statu, $current_serv_no_statu);
         foreach ($serv_to_add as $ser) {
             $show_ser_path = PathUtil::unionPath($key, $ser);
             $add_ret = ServiceController::addServiceWithLink($zk_web, $key, $ser, $idc, $hosts[$ser]);
             if ($add_ret != InfoDescUtil::QCONF_OK) {
                 $res = InfoDescUtil::getErrorMsg($add_ret);
                 OpServ::insert(InfoDescUtil::OP_TYPE_ADD, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 echo json_encode($res);
                 return;
             }
             OpServ::insert(InfoDescUtil::OP_TYPE_ADD, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
         }
         foreach ($serv_to_modify as $ser) {
             $show_ser_path = PathUtil::unionPath($key, $ser);
             $snapshot_statu = $hosts[$ser];
             if ($snapshot_statu === InfoDescUtil::SERV_STATUS_UP || $snapshot_statu === InfoDescUtil::SERV_STATUS_DOWN) {
                 $modify_ret = ServiceController::upServiceWithLink($zk_web, $key, $ser, $idc);
                 $modify_type = InfoDescUtil::OP_TYPE_UP;
             } else {
                 if ($snapshot_statu === InfoDescUtil::SERV_STATUS_OFFLINE) {
                     $modify_ret = ServiceController::offlineServiceWithLink($zk_web, $key, $ser, $idc);
                     $modify_type = InfoDescUtil::OP_TYPE_OFFLINE;
                 } else {
                     QconfMgrLog::err(__FILE__, __LINE__, "service status is unknown, show_ser_path({$show_ser_path})!");
                 }
             }
             if ($modify_ret != InfoDescUtil::QCONF_OK) {
                 $res = InfoDescUtil::getErrorMsg($modify_ret);
                 OpServ::insert($modify_type, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 echo json_encode($res);
                 return;
             }
             OpServ::insert($modify_type, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
         }
         foreach ($serv_to_delete as $ser) {
             $show_ser_path = PathUtil::unionPath($key, $ser);
             $delete_ret = ServiceController::deleteServiceWithLink($zk_web, $key, $ser, $idc);
             if ($delete_ret != InfoDescUtil::QCONF_OK) {
                 $res = InfoDescUtil::getErrorMsg($delete_ret);
                 OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_ZOO_FAILED, $main_buss_id, $sub_buss_id, $op_user, "");
                 echo json_encode($res);
                 return;
             }
             OpServ::insert(InfoDescUtil::OP_TYPE_DEL, $show_ser_path, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
         }
     }
     OpServ::insert(InfoDescUtil::OP_TYPE_SNAPSHOT_ROLLBACK, $node_whole, $idc, InfoDescUtil::OP_STATUS_SUCCESS, $main_buss_id, $sub_buss_id, $op_user, "");
     $res = array("errno" => "0", "errmsg" => "", "data" => "rollback success");
     $json = json_encode($res);
     echo $json;
     return;
 }
Пример #17
0
 public function ls($path)
 {
     $this->check($path, Permission::LS);
     $res = array();
     if ($handle = opendir($this->resolve($path))) {
         while (false !== ($entry = readdir($handle))) {
             if ($entry != "." && $entry != "..") {
                 if ($this->isDir(PathUtil::rel($path, $entry))) {
                     $entry = $entry . PathUtil::SEP;
                 }
                 array_push($res, $entry);
             }
         }
         closedir($handle);
     } else {
         $this->notFound($path);
     }
     return $res;
 }
Пример #18
0
require_once "php/auth.php";
require_once "php/ErrorHandler.php";
$fs = Auth::getFS();
//new NativeFS("../fs");
$json = new Services_JSON();
header("Content-type: text/json");
if (!isset($_POST["base"])) {
    die("Specify base");
}
$base = $_POST["base"];
if (!isset($_POST["data"])) {
    die("Specify data");
}
$data = $json->decode($_POST["data"]);
foreach ($data as $path => $cont) {
    //print "cont $cont";
    $fp = PathUtil::rel($base, $path);
    if (isset($cont["trashed"])) {
        if ($fs->exists($fp)) {
            $fs->rm($fp);
        }
    } else {
        $fs->setContent($fp, $cont["text"]);
        $fs->setMetaInfo($fp, array("lastUpdate" => $cont["lastUpdate"]));
    }
}
//header("Content-type: text/plain");
//print "OK";
require_once "php/getDirInfoLib.php";
print $json->encode(getDirInfo($base, $base));
//print $_POST["data"];
Пример #19
0
 public function checkFeedbackAction()
 {
     $node_id = $this->getRequest("node_id", "");
     $idc = $this->getRequest("idc", "");
     $page = $this->getRequest("page", 1);
     $page_count = $this->getRequest("pageCount", 20);
     // 1. parameter is not right
     if ($node_id === "" || $idc === "") {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter node_id or idc is null!");
         echo json_encode($res);
         return;
     }
     ArgsUtil::setVal($page);
     ArgsUtil::setVal($page_count);
     if ($page <= 0) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter page error!");
         echo json_encode($res);
         return;
     }
     if ($page_count < 0) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_BAD_ARGS);
         QconfMgrLog::err(__FILE__, __LINE__, "parameter page_count error!");
         echo json_encode($res);
         return;
     }
     // 2. idc zookeeper server not exist
     $idc_host = ZkConf::getZkHost($idc);
     if ($idc_host === NULL) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "'{$idc}' is not int ZOOKEEPER_SVR!");
         echo json_encode($res);
         return;
     }
     // 3. get the node info from database
     $dbnode = NodeServ::getNode($node_id);
     if ($dbnode === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_NODE_NOT_EXIST);
         QconfMgrLog::err(__FILE__, __LINE__, "node : {$node_id} is not exist!");
         echo json_encode($res);
         return;
     }
     $node_whole = $dbnode["node_whole"];
     $node_type_code = $dbnode["node_type_code"];
     $data_type = $node_type_code == InfoDescUtil::NODE_TYPE_SERV_FATHER ? InfoDescUtil::FEEDBACK_DATA_TYPE_SERVICE : InfoDescUtil::FEEDBACK_DATA_TYPE_VALUE;
     $cur_node_idc = $dbnode["idc"];
     $cur_idcs_array = explode(',', $cur_node_idc);
     $exist_idc = in_array($idc, $cur_idcs_array);
     if ($exist_idc === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_IDC_NOT_IN_DATABASE);
         QconfMgrLog::err(__FILE__, __LINE__, "node : {$node_id} does not exist on idc : {$idc}!");
         echo json_encode($res);
         return;
     }
     // 4. get feedbacks on current node
     $start = ($page - 1) * $page_count;
     $qconf_path = PathUtil::getQconfPath($node_whole);
     $feedbacks = FeedbackServ::queryFeedbackByNode($qconf_path, $idc, $data_type, $start, $page_count);
     if ($feedbacks === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         QconfMgrLog::err(__FILE__, __LINE__, "failed to query feedbacks by node:{$node_whole},\n                idc({$idc}), data_type({$data_type}), page({$page}), page_count({$page_count})!");
         echo json_encode($res);
         return;
     }
     $total_count = FeedbackServ::feedbackAmountByNode($qconf_path, $idc, $data_type);
     if ($total_count === FALSE) {
         $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_MYSQL_FAIL);
         QconfMgrLog::err(__FILE__, __LINE__, "failed to get feedbacks amount by node:{$node_whole}, idc({$idc}), data_type({$data_type})");
         echo json_encode($res);
         return;
     }
     // 5. calcuate value_md5
     $zk_web = new QconfZkWebBase(Log::INFO);
     $zk_web->connect($idc_host);
     $retry_time = 0;
     if ($data_type == InfoDescUtil::FEEDBACK_DATA_TYPE_SERVICE) {
         // 5.1 calcuate value_md5 for service father node
         $services = -1;
         while ($services === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) {
             QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to get services {$node_whole} on {$idc_host}");
             $services = $zk_web->get_group_services_with_status($qconf_path);
             $retry_time++;
         }
         if ($services === -1) {
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
             QconfMgrLog::err(__FILE__, __LINE__, "The children of path: {$qconf_path} are null!");
             echo json_encode($res);
             return;
         }
         ksort($services);
         foreach ($services as $serv => $status) {
             $ser_combine .= "{$serv}#{$status},";
         }
         $ser_combine = trim($ser_combine, ',');
         //echo $ser_combine;
         $node_md5 = md5($ser_combine);
     } else {
         // 5.2 calcuate value_md5 for value
         $node_val = -1;
         while ($node_val === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) {
             QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to get value of {$node_whole} on {$idc}");
             $node_val = $zk_web->get_conf($qconf_path);
             $retry_time++;
         }
         if ($node_val === -1) {
             $res = InfoDescUtil::getErrorMsg(InfoDescUtil::ERR_ZOOKEEPER_FAIL);
             QconfMgrLog::err(__FILE__, __LINE__, "failed to get value of {$qconf_path}!");
             echo json_encode($res);
             return;
         }
         $node_md5 = md5($node_val);
     }
     // 6. encapsulate feedback result
     $fd_result = array();
     foreach ($feedbacks as $feedback) {
         $fd_one = array("feedback_id" => $feedback["feedback_id"], "hostname" => $feedback["hostname"], "ip" => $feedback["ip"], "status" => $feedback["value_md5"] == $node_md5 ? "0" : "1", "update_time" => $feedback["update_time"]);
         $fd_result[] = $fd_one;
     }
     $result = array("curPage" => "{$page}", "totalCount" => "{$total_count}", "listing" => $fd_result);
     $res = array("errno" => "0", "errmsg" => "", "data" => $result);
     $json = json_encode($res);
     echo $json;
 }
Пример #20
0
 public function setConfWithLink($zk_web, $node_whole, $idc, $value)
 {
     $ret = -1;
     $retry_time = 0;
     while ($ret === -1 && $retry_time <= InfoDescUtil::ZK_MAX_RETRY_TIME) {
         QconfMgrLog::err(__FILE__, __LINE__, "retry {$retry_time} of " . InfoDescUtil::ZK_MAX_RETRY_TIME . " to set value for {$node_whole} on {$idc}");
         $ret = $zk_web->set_conf(PathUtil::getQconfPath($node_whole), $value);
         $retry_time++;
     }
     if ($ret === -1) {
         QconfMgrLog::err(__FILE__, __LINE__, "Failed to set conf value by node_whole, {$node_whole}!");
         return InfoDescUtil::ERR_ZOOKEEPER_FAIL;
     }
     return InfoDescUtil::QCONF_OK;
 }