From 4f2b5c3c45739df612a1e981b4462303907243ec Mon Sep 17 00:00:00 2001 From: Akkariin Meiko Date: Thu, 3 Dec 2020 04:20:22 +0800 Subject: [PATCH] Add isUserHasPermission & isNodeAvailable function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加判断用户是否有权限使用此节点以及节点是否可用的函数 --- core/NodeManager.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/core/NodeManager.php b/core/NodeManager.php index 6b27d83..3c7a24a 100755 --- a/core/NodeManager.php +++ b/core/NodeManager.php @@ -59,6 +59,28 @@ class NodeManager { return count($rs); } + public function isUserHasPermission($user, $node) + { + $um = new SakuraPanel\UserManager(); + $ns = $this->getNodeInfo($node); + $us = $um->getInfoByUser($user); + if(is_array($us) && is_array($ns)) { + if(stristr($ns['group'], "{$us['group']};")) { + return true; + } else { + return false; + } + } else { + return false; + } + } + + public function isNodeAvailable($node) + { + $ns = $this->getNodeInfo($node); + return Intval($ns['status']) == 200; + } + public function addNode($data) { return Database::insert("nodes", $data); @@ -80,4 +102,4 @@ class NodeManager { return false; } } -} \ No newline at end of file +}