diff --git a/02.php/app/controller/personal.class.php b/02.php/app/controller/personal.class.php index bd28d59..01fcba6 100644 --- a/02.php/app/controller/personal.class.php +++ b/02.php/app/controller/personal.class.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-26 16:57:23 + * @LastEditTime: 2022-04-27 16:40:15 * @Description: QQ:1801168257 */ @@ -84,7 +84,7 @@ class personal extends controller } //获取SVN指定用户的密码 - $result = FunGetPassByUser($this->globalPasswdContent, $this->globalUserName); + $result = \SVNAdmin\SVN\User::GetPassByUser($this->globalPasswdContent, $this->globalUserName); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -101,7 +101,7 @@ class personal extends controller } //修改SVN指定用户的密码 - $result = FunUpdSvnUserPass($this->globalPasswdContent, $this->globalUserName, $this->requestPayload['newPassword']); + $result = \SVNAdmin\SVN\User::UpdSvnUserPass($this->globalPasswdContent, $this->globalUserName, $this->requestPayload['newPassword']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } diff --git a/02.php/app/controller/statistics.class.php b/02.php/app/controller/statistics.class.php index 991332a..8b2d9cc 100644 --- a/02.php/app/controller/statistics.class.php +++ b/02.php/app/controller/statistics.class.php @@ -3,10 +3,13 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 11:56:45 + * @LastEditTime: 2022-04-27 16:55:37 * @Description: QQ:1801168257 */ +use SVNAdmin\SVN\Rep; +use SVNAdmin\SVNRep\SVNRep; + /** * 信息统计类 */ @@ -225,13 +228,13 @@ class statistics extends controller $backupSize = FunFormatSize(FunGetDirSizeDu(SVN_BACHUP_PATH)); //SVN仓库数量 - $repCount = count(FunGetSimpleRepList()); + $repCount = count(\SVNAdmin\SVN\Rep::GetSimpleRepList()); //SVN用户数量 - $userCount = count(FunGetSvnUserList(SVN_PASSWD_FILE)); + $userCount = count(\SVNAdmin\SVN\User::GetSvnUserList(SVN_PASSWD_FILE)); //SVN分组数量 - $groupCount = count(FunGetSvnGroupList(SVN_AUTHZ_FILE)); + $groupCount = count(\SVNAdmin\SVN\Group::GetSvnGroupList(SVN_AUTHZ_FILE)); //运行日志数量 $logCount = $this->database->count('logs', ['log_id[>]' => 0]); diff --git a/02.php/app/controller/subversion.class.php b/02.php/app/controller/subversion.class.php index d4f868d..44fddbf 100644 --- a/02.php/app/controller/subversion.class.php +++ b/02.php/app/controller/subversion.class.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 15:20:52 + * @LastEditTime: 2022-04-27 17:59:25 * @Description: QQ:1801168257 */ @@ -43,7 +43,7 @@ class subversion extends controller */ function GetCheckout() { - $result = FunGetSubversionListen(); + $result = \SVNAdmin\SVN\Info::GetSubversionListen(); $checkoutHost = $result[$result['enable']]; if ($result['bindPort'] != '3690') { $checkoutHost .= ':' . $result['bindPort']; @@ -60,7 +60,7 @@ class subversion extends controller function GetDetail() { //获取绑定主机、端口等信息 - $bindInfo = FunGetSubversionListen(); + $bindInfo = \SVNAdmin\SVN\Info::GetSubversionListen(); //检测运行信息 $runInfo = FunShellExec('ps auxf|grep -v "grep"|grep svnserve'); diff --git a/02.php/app/controller/svngroup.class.php b/02.php/app/controller/svngroup.class.php index 65a5acd..2a3487a 100644 --- a/02.php/app/controller/svngroup.class.php +++ b/02.php/app/controller/svngroup.class.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-26 16:57:46 + * @LastEditTime: 2022-04-27 16:40:48 * @Description: QQ:1801168257 */ @@ -28,7 +28,7 @@ class svngroup extends controller */ function SyncGroupToDb() { - $svnAndGroupList = FunGetSvnGroupUserAndGroupList($this->globalAuthzContent); + $svnAndGroupList = \SVNAdmin\SVN\Group::GetSvnGroupUserAndGroupList($this->globalAuthzContent); @@ -83,7 +83,7 @@ class svngroup extends controller */ function GetAllGroupList() { - $svnGroupList = FunGetSvnGroupList($this->globalAuthzContent); + $svnGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent); if ($svnGroupList == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } else { @@ -171,7 +171,7 @@ class svngroup extends controller FunCheckRepGroup($this->requestPayload['svn_group_name']); //检查用户是否已存在 - $result = FunAddSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $result = \SVNAdmin\SVN\Group::AddSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -199,7 +199,7 @@ class svngroup extends controller function DelGroup() { //从authz文件删除 - $result = FunDelSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $result = \SVNAdmin\SVN\Group::DelSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); @@ -226,7 +226,7 @@ class svngroup extends controller //新分组名称是否合法 FunCheckRepGroup($this->requestPayload['groupNameNew']); - $svnGroupList = FunGetSvnGroupList($this->globalAuthzContent); + $svnGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent); //旧分组是否存在 if (!in_array($this->requestPayload['groupNameOld'], $svnGroupList)) { @@ -238,7 +238,7 @@ class svngroup extends controller FunMessageExit(200, 0, '要修改的分组名称已经存在'); } - $result = FunUpdSvnGroup($this->globalAuthzContent, $this->requestPayload['groupNameOld'], $this->requestPayload['groupNameNew']); + $result = \SVNAdmin\SVN\Group::UpdSvnGroup($this->globalAuthzContent, $this->requestPayload['groupNameOld'], $this->requestPayload['groupNameNew']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -253,13 +253,13 @@ class svngroup extends controller */ function GetGroupMember() { - $memberUserList = FunGetSvnUserListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $memberUserList = \SVNAdmin\SVN\Group::GetSvnUserListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); - $memberGroupList = FunGetSvnGroupListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $memberGroupList = \SVNAdmin\SVN\Group::GetSvnGroupListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); - $allGroupList = FunGetSvnGroupList($this->globalAuthzContent); + $allGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent); - $allUserList = FunGetSvnUserList($this->globalPasswdContent); + $allUserList = \SVNAdmin\SVN\User::GetSvnUserList($this->globalPasswdContent); if ($memberUserList == '0' || $memberGroupList == '0' || $allGroupList == '0' || $allUserList == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); @@ -317,7 +317,7 @@ class svngroup extends controller */ function GroupAddUser() { - $result = FunAddSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); + $result = \SVNAdmin\SVN\Group::AddSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -338,7 +338,7 @@ class svngroup extends controller */ function GroupRemoveUser() { - $result = FunDelSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); + $result = \SVNAdmin\SVN\Group::DelSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -359,7 +359,7 @@ class svngroup extends controller */ function GroupAddGroup() { - $result = FunAddSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_add']); + $result = \SVNAdmin\SVN\Group::AddSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_add']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -391,7 +391,7 @@ class svngroup extends controller */ function GroupRemoveGroup() { - $result = FunDelSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_del']); + $result = \SVNAdmin\SVN\Group::DelSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_del']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -424,10 +424,10 @@ class svngroup extends controller $authzContent = $this->globalAuthzContent; //所有的分组列表 - $allGroupList = FunGetSvnGroupList($authzContent); + $allGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($authzContent); //用户所在的分组列表 - $userGroupList = FunGetSvnUserGroupList($authzContent, $userName); + $userGroupList = \SVNAdmin\SVN\User::GetSvnUserGroupList($authzContent, $userName); //剩余的分组列表 $leftGroupList = array_diff($allGroupList, $userGroupList); @@ -436,7 +436,7 @@ class svngroup extends controller loop: $userGroupListBack = $userGroupList; foreach ($userGroupList as $group1) { - $newList = FunGetSvnGroupGroupList($authzContent, $group1); + $newList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $group1); foreach ($leftGroupList as $key2 => $group2) { if (in_array($group2, $newList)) { array_push($userGroupList, $group2); @@ -469,10 +469,10 @@ class svngroup extends controller $authzContent = $this->globalAuthzContent; //所有的分组列表 - $allGroupList = FunGetSvnGroupList($authzContent); + $allGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($authzContent); //分组所在的分组列表 - $groupGroupList = FunGetSvnGroupGroupList($authzContent, $parentGroupName); + $groupGroupList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $parentGroupName); //剩余的分组列表 $leftGroupList = array_diff($allGroupList, $groupGroupList); @@ -481,7 +481,7 @@ class svngroup extends controller loop: $userGroupListBack = $groupGroupList; foreach ($groupGroupList as $group1) { - $newList = FunGetSvnGroupGroupList($authzContent, $group1); + $newList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $group1); foreach ($leftGroupList as $key2 => $group2) { if (in_array($group2, $newList)) { array_push($groupGroupList, $group2); diff --git a/02.php/app/controller/svnrep.class.php b/02.php/app/controller/svnrep.class.php index 38704bb..4f5e6fc 100644 --- a/02.php/app/controller/svnrep.class.php +++ b/02.php/app/controller/svnrep.class.php @@ -3,10 +3,12 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 02:06:19 + * @LastEditTime: 2022-04-27 18:03:13 * @Description: QQ:1801168257 */ +use SVNAdmin\SVNRep\SVNRep as SVNRepSVNRep; + class svnrep extends controller { private $Svngorup; @@ -40,7 +42,7 @@ class svnrep extends controller FunCheckRepName($this->requestPayload['rep_name']); //检查仓库是否存在 - FunCheckRepExist($this->requestPayload['rep_name']); + \SVNAdmin\SVN\Rep::CheckRepExist($this->requestPayload['rep_name']); //创建空仓库 //解决创建中文仓库乱码问题 @@ -48,14 +50,14 @@ class svnrep extends controller if ($this->requestPayload['rep_type'] == '2') { //以指定的目录结构初始化仓库 - FunInitRepStruct($this->requestPayload['rep_name']); + \SVNAdmin\SVN\Rep::InitRepStruct($this->requestPayload['rep_name']); } //检查是否创建成功 - FunCheckRepCreate($this->requestPayload['rep_name']); + \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name']); //向authz写入仓库信息 - $status = FunSetRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name'], '/'); + $status = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name'], '/'); if ($status != '1') { FunShellExec('echo \'' . $status . '\' > ' . SVN_AUTHZ_FILE); } @@ -80,7 +82,7 @@ class svnrep extends controller */ function SyncRepAndDb() { - $svnRepList = FunGetSimpleRepList(); + $svnRepList = \SVNAdmin\SVN\Rep::GetSimpleRepList(); $dbRepList = $this->database->select('svn_reps', [ 'rep_name', @@ -95,7 +97,7 @@ class svnrep extends controller //更新 $this->database->update('svn_reps', [ 'rep_size' => FunGetDirSizeDu(SVN_REPOSITORY_PATH . $value['rep_name']), - 'rep_rev' => FunGetRepRev($value['rep_name']) + 'rep_rev' => \SVNAdmin\SVN\Rep::GetRepRev($value['rep_name']) ], [ 'rep_name' => $value['rep_name'] ]); @@ -108,7 +110,7 @@ class svnrep extends controller 'rep_name' => $value, 'rep_size' => FunGetDirSizeDu(SVN_REPOSITORY_PATH . $value), 'rep_note' => '', - 'rep_rev' => FunGetRepRev($value), + 'rep_rev' => \SVNAdmin\SVN\Rep::GetRepRev($value), 'rep_uuid' => '' ]); } @@ -123,15 +125,15 @@ class svnrep extends controller */ function SyncRepAndAuthz() { - $svnRepList = FunGetSimpleRepList(); + $svnRepList = \SVNAdmin\SVN\Rep::GetSimpleRepList(); - $svnRepAuthzList = FunGetNoPathAndConRepAuthz($this->globalAuthzContent); + $svnRepAuthzList = \SVNAdmin\SVN\Rep::GetNoPathAndConRepAuthz($this->globalAuthzContent); $authzContet = $this->globalAuthzContent; foreach ($svnRepList as $key => $value) { if (!in_array($value, $svnRepAuthzList)) { - $authzContet = FunSetRepAuthz($authzContet, $value, '/'); + $authzContet = \SVNAdmin\SVN\Rep::SetRepAuthz($authzContet, $value, '/'); if ($authzContet == '1') { FunMessageExit(200, 0, '同步到配置文件错误'); } @@ -140,7 +142,7 @@ class svnrep extends controller foreach ($svnRepAuthzList as $key => $value) { if (!in_array($value, $svnRepList)) { - $authzContet = FunDelRepAuthz($authzContet, $value); + $authzContet = \SVNAdmin\SVN\Rep::DelRepAuthz($authzContet, $value); if ($authzContet == '1') { FunMessageExit(200, 0, '同步到配置文件错误'); } @@ -162,14 +164,14 @@ class svnrep extends controller $userRepList = []; //获取用户有权限的仓库列表 - $userRepList = array_merge($userRepList, FunGetUserPriRepListWithPriAndPath($this->globalAuthzContent, $this->globalUserName)); + $userRepList = array_merge($userRepList, \SVNAdmin\SVN\User::GetUserPriRepListWithPriAndPath($this->globalAuthzContent, $this->globalUserName)); //获取用户所在的所有分组 $userGroupList = $this->Svngorup->GetSvnUserAllGroupList($this->globalUserName); //获取分组有权限的仓库路径列表 foreach ($userGroupList as $value) { - $userRepList = array_merge($userRepList, FunGetGroupPriRepListWithPriAndPath($this->globalAuthzContent, $value)); + $userRepList = array_merge($userRepList, \SVNAdmin\SVN\Group::GetGroupPriRepListWithPriAndPath($this->globalAuthzContent, $value)); } //按照全路径去重 @@ -368,14 +370,14 @@ class svnrep extends controller * * 目的为使用当前SVN用户的身份来进行被授权过的路径的内容浏览 */ - $bindInfo = FunGetSubversionListen(); + $bindInfo = \SVNAdmin\SVN\Info::GetSubversionListen(); $checkoutHost = 'svn://' . $bindInfo['bindHost']; if ($bindInfo['bindPort'] != '3690') { $checkoutHost = 'svn://' . $bindInfo['bindHost'] . ':' . $bindInfo['bindPort']; } //获取SVN用户密码 - $svnUserPass = FunGetPassByUser($this->globalPasswdContent, $this->globalUserName); + $svnUserPass = \SVNAdmin\SVN\User::GetPassByUser($this->globalPasswdContent, $this->globalUserName); if ($svnUserPass == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } else if ($svnUserPass == '1') { @@ -392,7 +394,7 @@ class svnrep extends controller FunMessageExit(200, 0, '密码错误'); } if (strstr($result, 'svn: E170001: Authorization failed')) { - FunMessageExit(200, 0, '没有权限'); + FunMessageExit(200, 0, '无访问权限'); } if (strstr($result, 'svn: E170013: Unable to connect to a repository at URL')) { FunMessageExit(200, 0, '其它错误'); @@ -411,16 +413,16 @@ class svnrep extends controller } //获取文件或者文件夹最年轻的版本号 - $lastRev = FunGetRepFileRev($repName, $value); + $lastRev = \SVNAdmin\SVN\Rep::GetRepFileRev($repName, $value); //获取文件或者文件夹最年轻的版本的作者 - $lastRevAuthor = FunGetRepFileAuthor($repName, $lastRev); + $lastRevAuthor = \SVNAdmin\SVN\Rep::GetRepFileAuthor($repName, $lastRev); //同上 日期 - $lastRevDate = FunGetRepFileDate($repName, $lastRev); + $lastRevDate = \SVNAdmin\SVN\Rep::GetRepFileDate($repName, $lastRev); //同上 日志 - $lastRevLog = FunGetRepFileLog($repName, $lastRev); + $lastRevLog = \SVNAdmin\SVN\Rep::GetRepFileLog($repName, $lastRev); $pathArray = explode('/', $value); $pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter')); @@ -440,7 +442,7 @@ class svnrep extends controller array_push($data, [ 'resourceType' => 1, 'resourceName' => $pathArray[$pathArrayCount - 1], - 'fileSize' => FunGetRepRevFileSize($repName, $value), + 'fileSize' => \SVNAdmin\SVN\Rep::GetRepRevFileSize($repName, $value), 'revAuthor' => $lastRevAuthor, 'revNum' => 'r' . $lastRev, 'revTime' => $lastRevDate, @@ -508,16 +510,16 @@ class svnrep extends controller $data = []; foreach ($resultArray as $key => $value) { //获取文件或者文件夹最年轻的版本号 - $lastRev = FunGetRepFileRev($this->requestPayload['rep_name'], $value); + $lastRev = \SVNAdmin\SVN\Rep::GetRepFileRev($this->requestPayload['rep_name'], $value); //获取文件或者文件夹最年轻的版本的作者 - $lastRevAuthor = FunGetRepFileAuthor($this->requestPayload['rep_name'], $lastRev); + $lastRevAuthor = \SVNAdmin\SVN\Rep::GetRepFileAuthor($this->requestPayload['rep_name'], $lastRev); //同上 日期 - $lastRevDate = FunGetRepFileDate($this->requestPayload['rep_name'], $lastRev); + $lastRevDate = \SVNAdmin\SVN\Rep::GetRepFileDate($this->requestPayload['rep_name'], $lastRev); //同上 日志 - $lastRevLog = FunGetRepFileLog($this->requestPayload['rep_name'], $lastRev); + $lastRevLog = \SVNAdmin\SVN\Rep::GetRepFileLog($this->requestPayload['rep_name'], $lastRev); $pathArray = explode('/', $value); $pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter')); @@ -537,7 +539,7 @@ class svnrep extends controller array_push($data, [ 'resourceType' => 1, 'resourceName' => $pathArray[$pathArrayCount - 1], - 'fileSize' => FunGetRepRevFileSize($this->requestPayload['rep_name'], $value), + 'fileSize' => \SVNAdmin\SVN\Rep::GetRepRevFileSize($this->requestPayload['rep_name'], $value), 'revAuthor' => $lastRevAuthor, 'revNum' => 'r' . $lastRev, 'revTime' => $lastRevDate, @@ -645,7 +647,7 @@ class svnrep extends controller */ function GetRepPathUserPri() { - $result = FunGetRepUserListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); + $result = \SVNAdmin\SVN\Rep::GetRepUserListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); if ($result == '0') { //没有该路径的记录 if ($this->requestPayload['path'] == '/') { @@ -671,7 +673,7 @@ class svnrep extends controller */ function GetRepPathGroupPri() { - $result = FunGetRepGroupListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); + $result = \SVNAdmin\SVN\Rep::GetRepGroupListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); if ($result == '0') { //没有该路径的记录 if ($this->requestPayload['path'] == '/') { @@ -718,20 +720,20 @@ class svnrep extends controller * 包括为已有权限的用户修改权限 * 包括为没有权限的用户增加权限 */ - $result = FunSetRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); + $result = \SVNAdmin\SVN\Rep::SetRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); //没有该仓库路径记录 if ($result == '0') { //没有该仓库路径记录 则进行插入 - $result = FunSetRepAuthz($this->globalAuthzContent, $repName, $path); + $result = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $repName, $path); if ($result == '1') { FunMessageExit(200, 1, '未知错误'); } //重新添加权限 - $result = FunSetRepUserPri($result, $user, $pri, $repName, $path); + $result = \SVNAdmin\SVN\Rep::SetRepUserPri($result, $user, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 1, '未知错误'); @@ -754,7 +756,7 @@ class svnrep extends controller $path = $this->requestPayload['path']; $user = $this->requestPayload['user']; - $result = FunDelRepUserPri($this->globalAuthzContent, $user, $repName, $path); + $result = \SVNAdmin\SVN\Rep::DelRepUserPri($this->globalAuthzContent, $user, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -784,7 +786,7 @@ class svnrep extends controller */ $pri = $pri == 'no' ? '' : $pri; - $result = FunUpdRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); + $result = \SVNAdmin\SVN\Rep::UpdRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -823,20 +825,20 @@ class svnrep extends controller * 包括为已有权限的分组修改权限 * 包括为没有权限的分组增加权限 */ - $result = FunSetRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); + $result = \SVNAdmin\SVN\Rep::SetRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); //没有该仓库路径记录 if ($result == '0') { //没有该仓库路径记录 则进行插入 - $result = FunSetRepAuthz($this->globalAuthzContent, $repName, $path); + $result = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $repName, $path); if ($result == '1') { FunMessageExit(200, 1, '未知错误'); } //重新添加权限 - $result = FunSetRepGroupPri($result, $group, $pri, $repName, $path); + $result = \SVNAdmin\SVN\Rep::SetRepGroupPri($result, $group, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 1, '未知错误'); @@ -859,7 +861,7 @@ class svnrep extends controller $path = $this->requestPayload['path']; $group = $this->requestPayload['group']; - $result = FunDelRepGroupPri($this->globalAuthzContent, $group, $repName, $path); + $result = \SVNAdmin\SVN\Rep::DelRepGroupPri($this->globalAuthzContent, $group, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -889,7 +891,7 @@ class svnrep extends controller */ $pri = $pri == 'no' ? '' : $pri; - $result = FunUpdRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); + $result = \SVNAdmin\SVN\Rep::UpdRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -913,16 +915,16 @@ class svnrep extends controller FunCheckRepName($this->requestPayload['new_rep_name']); //检查原仓库是否不存在 - FunCheckRepCreate($this->requestPayload['old_rep_name'], '要修改的仓库不存在'); + \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['old_rep_name'], '要修改的仓库不存在'); //检查新仓库名是否存在 - FunCheckRepExist($this->requestPayload['new_rep_name'], '已经存在同名仓库'); + \SVNAdmin\SVN\Rep::CheckRepExist($this->requestPayload['new_rep_name'], '已经存在同名仓库'); //从仓库目录修改仓库名称 FunShellExec('mv ' . SVN_REPOSITORY_PATH . $this->requestPayload['old_rep_name'] . ' ' . SVN_REPOSITORY_PATH . $this->requestPayload['new_rep_name']); //检查修改过的仓库名称是否存在 - FunCheckRepCreate($this->requestPayload['new_rep_name'], '修改仓库名称失败'); + \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['new_rep_name'], '修改仓库名称失败'); //从数据库修改仓库名称 $this->database->update('svn_reps', [ @@ -932,7 +934,7 @@ class svnrep extends controller ]); //从配置文件修改仓库名称 - FunUpdRepAuthz($this->globalAuthzContent, $this->requestPayload['old_rep_name'], $this->requestPayload['new_rep_name']); + \SVNAdmin\SVN\Rep::UpdRepAuthz($this->globalAuthzContent, $this->requestPayload['old_rep_name'], $this->requestPayload['new_rep_name']); FunMessageExit(); } @@ -943,7 +945,7 @@ class svnrep extends controller function DelRep() { //从配置文件删除指定仓库的所有路径 - $result = FunDelRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name']); + $result = \SVNAdmin\SVN\Rep::DelRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name']); if ($result != '1') { FunShellExec('echo \'' . $result . '\' > ' . SVN_AUTHZ_FILE); } @@ -955,7 +957,7 @@ class svnrep extends controller //从仓库目录删除仓库文件夹 FunShellExec('cd ' . SVN_REPOSITORY_PATH . ' && rm -rf ./' . $this->requestPayload['rep_name']); - FunCheckRepDelete($this->requestPayload['rep_name']); + \SVNAdmin\SVN\Rep::CheckRepDelete($this->requestPayload['rep_name']); //返回 FunMessageExit(); @@ -966,7 +968,7 @@ class svnrep extends controller */ function GetRepDetail() { - $result = FunGetRepDetail($this->requestPayload['rep_name']); + $result = \SVNAdmin\SVN\Rep::GetRepDetail($this->requestPayload['rep_name']); $resultArray = explode("\n", $result); $newArray = []; @@ -999,7 +1001,7 @@ class svnrep extends controller */ function RepDump() { - FunRepDump($this->requestPayload['rep_name'], $this->requestPayload['rep_name'] . '_' . date('YmdHis') . '_' . FunGetRandStr() . '.dump'); + \SVNAdmin\SVN\Rep::RepDump($this->requestPayload['rep_name'], $this->requestPayload['rep_name'] . '_' . date('YmdHis') . '_' . FunGetRandStr() . '.dump'); FunMessageExit(); } @@ -1009,7 +1011,7 @@ class svnrep extends controller */ function DelRepBackup() { - FunDelRepBackup($this->requestPayload['fileName']); + \SVNAdmin\SVN\Rep::DelRepBackup($this->requestPayload['fileName']); FunMessageExit(); } @@ -1098,6 +1100,8 @@ class svnrep extends controller set_time_limit(0); + require_once BASE_PATH . '/extension/Download/download.class.php'; + $transfer = new Transfer($filePath, $mimeType, $range); $transfer->send(); @@ -1143,10 +1147,10 @@ class svnrep extends controller } //检查操作的仓库是否存在 - FunCheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); + \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); //使用svndump - $result = FunRepLoad($this->requestPayload['rep_name'], $this->requestPayload['fileName']); + $result = \SVNAdmin\SVN\Rep::RepLoad($this->requestPayload['rep_name'], $this->requestPayload['fileName']); if ($result == ISNULL) { FunMessageExit(); @@ -1161,7 +1165,7 @@ class svnrep extends controller function GetRepHooks() { //检查仓库是否存在 - FunCheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); + \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); clearstatcache(); if (!is_dir(SVN_REPOSITORY_PATH . $this->requestPayload['rep_name'] . '/' . 'hooks')) { diff --git a/02.php/app/controller/svnuser.class.php b/02.php/app/controller/svnuser.class.php index 19e5bbe..8e71903 100644 --- a/02.php/app/controller/svnuser.class.php +++ b/02.php/app/controller/svnuser.class.php @@ -3,10 +3,12 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-26 16:57:57 + * @LastEditTime: 2022-04-27 16:41:35 * @Description: QQ:1801168257 */ +use SVNAdmin\svnUser\svnUser as SvnUserSvnUser; + class svnuser extends controller { function __construct() @@ -28,7 +30,7 @@ class svnuser extends controller */ function SyncUserToDb() { - $svnUserPassList = FunGetSvnUserPassList($this->globalPasswdContent); + $svnUserPassList = \SVNAdmin\SVN\User::GetSvnUserPassList($this->globalPasswdContent); if ($svnUserPassList == 0) { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -77,7 +79,7 @@ class svnuser extends controller */ function GetAllUserList() { - $svnUserList = FunGetSvnUserList($this->globalPasswdContent); + $svnUserList = \SVNAdmin\SVN\User::GetSvnUserList($this->globalPasswdContent); if ($svnUserList == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } else { @@ -149,7 +151,7 @@ class svnuser extends controller */ function EnableUser() { - $result = FunEnabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); + $result = \SVNAdmin\SVN\User::EnabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -167,7 +169,7 @@ class svnuser extends controller */ function DisableUser() { - $result = FunDisabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); + $result = \SVNAdmin\SVN\User::DisabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -203,7 +205,7 @@ class svnuser extends controller FunCheckRepUser($this->requestPayload['svn_user_name']); //检查用户是否已存在 - $result = FunAddSvnUser($this->globalPasswdContent, $this->requestPayload['svn_user_name'], $this->requestPayload['svn_user_pass']); + $result = \SVNAdmin\SVN\User::AddSvnUser($this->globalPasswdContent, $this->requestPayload['svn_user_name'], $this->requestPayload['svn_user_pass']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -236,7 +238,7 @@ class svnuser extends controller function EditUserPass() { //检查用户是否已存在 - $result = FunUpdSvnUserPass($this->globalPasswdContent, $this->requestPayload['svn_user_name'], $this->requestPayload['svn_user_pass'], !$this->requestPayload['svn_user_status']); + $result = \SVNAdmin\SVN\User::UpdSvnUserPass($this->globalPasswdContent, $this->requestPayload['svn_user_name'], $this->requestPayload['svn_user_pass'], !$this->requestPayload['svn_user_status']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -268,7 +270,7 @@ class svnuser extends controller function DelUser() { //从passwd文件中全局删除 - $resultPasswd = FunDelSvnUserPasswd($this->globalPasswdContent, $this->requestPayload['svn_user_name'], !$this->requestPayload['svn_user_status']); + $resultPasswd = \SVNAdmin\SVN\User::DelSvnUserPasswd($this->globalPasswdContent, $this->requestPayload['svn_user_name'], !$this->requestPayload['svn_user_status']); if ($resultPasswd == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); @@ -278,7 +280,7 @@ class svnuser extends controller } //从authz文件中删除 - $resultAuthz = FunDelUserAuthz($this->globalAuthzContent, $this->requestPayload['svn_user_name']); + $resultAuthz = \SVNAdmin\SVN\User::DelUserAuthz($this->globalAuthzContent, $this->requestPayload['svn_user_name']); if ($resultAuthz == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); diff --git a/02.php/app/core/controller.class.php b/02.php/app/core/controller.class.php index c267570..090d5e6 100644 --- a/02.php/app/core/controller.class.php +++ b/02.php/app/core/controller.class.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-26 16:58:08 + * @LastEditTime: 2022-04-27 18:03:08 * @Description: QQ:1801168257 */ @@ -24,11 +24,11 @@ require_once BASE_PATH . '/config/version.config.php'; //require model require_once BASE_PATH . '/app/model/conn.model.php'; +require_once BASE_PATH . '/app/model/util.model.php'; //require function require_once BASE_PATH . '/app/function/array.function.php'; require_once BASE_PATH . '/app/function/color.function.php'; -require_once BASE_PATH . '/app/function/config.function.php'; require_once BASE_PATH . '/app/function/curl.function.php'; require_once BASE_PATH . '/app/function/file.function.php'; require_once BASE_PATH . '/app/function/json.function.php'; @@ -36,11 +36,6 @@ require_once BASE_PATH . '/app/function/regular.function.php'; require_once BASE_PATH . '/app/function/return.function.php'; require_once BASE_PATH . '/app/function/socket.function.php'; require_once BASE_PATH . '/app/function/string.function.php'; -require_once BASE_PATH . '/app/function/subversion.function.php'; -require_once BASE_PATH . '/app/function/svnGroup.function.php'; -require_once BASE_PATH . '/app/function/svnHooks.function.php'; -require_once BASE_PATH . '/app/function/svnRep.function.php'; -require_once BASE_PATH . '/app/function/svnUser.function.php'; require_once BASE_PATH . '/app/function/token.function.php'; require_once BASE_PATH . '/app/function/update.function.php'; @@ -60,7 +55,7 @@ require_once BASE_PATH . '/app/controller/svnuser.class.php'; require_once BASE_PATH . '/app/controller/update.class.php'; //require extension -require_once BASE_PATH . '/extension/Download/download.class.php'; + class controller { diff --git a/02.php/app/function/config.function.php b/02.php/app/function/config.function.php deleted file mode 100644 index da0473f..0000000 --- a/02.php/app/function/config.function.php +++ /dev/null @@ -1,35 +0,0 @@ - $bindPort == '' ? '3690' : $bindPort, - 'bindHost' => $bindHost == '' ? '0.0.0.0' : $bindHost, - 'manageHost' => '127.0.0.1', - 'enable' => $bindHost == '' ? 'manageHost' : 'bindHost' - ]) . '\' > ' . LISTEN_FILE); - } else { - //更新内容 - $listenArray = json_decode($listenContent, true); - if ($listenArray['bindPort'] != $bindPort) { - $listenArray['bindPort'] = $bindPort == '' ? '3690' : $bindHost; - } - if ($listenArray['bindHost'] != $bindHost) { - $listenArray['bindHost'] = $bindHost == '' ? '0.0.0.0' : $bindHost; - } - FunShellExec('echo \'' . json_encode([ - 'bindPort' => $listenArray['bindPort'], - 'bindHost' => $listenArray['bindHost'], - 'manageHost' => $listenArray['manageHost'] == '' ? '127.0.0.1' : $listenArray['manageHost'], - 'enable' => $listenArray['enable'] - ]) . '\' > ' . LISTEN_FILE); - } - - $listenContent = FunShellExec('cat ' . LISTEN_FILE); - $listenArray = json_decode($listenContent, true); - - return [ - 'bindPort' => $listenArray['bindPort'], - 'bindHost' => $listenArray['bindHost'], - 'manageHost' => $listenArray['manageHost'], - 'enable' => $listenArray['enable'], - ]; -} diff --git a/02.php/app/function/svnGroup.function.php b/02.php/app/function/svnGroup.function.php deleted file mode 100644 index 586c661..0000000 --- a/02.php/app/function/svnGroup.function.php +++ /dev/null @@ -1,690 +0,0 @@ - $userGroupStr) { - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - $groupContent .= "$groupName=\n"; - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } - } - } else { - return '0'; - } -} - -/** - * 删除分组(从所有仓库路径和分组下删除分组名称) - * - * 操作后会将[aliases]的位置放于[groups]之后 - * - * 0 文件格式错误(不存在[groups]标识) - * 1 分组不存在 - * string 正常 - */ -function FunDelSvnGroup($authzContent, $groupName) -{ - $groupName = trim($groupName); - $content1 = "[groups]\n"; - $content2 = ""; - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (!empty($temp1)) { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $groupContent = ""; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - //处理左值 - if ($groupStr == $groupName) { - continue; - } - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - //处理右值 - foreach ($userGroupArray as $key => $value) { - if ($value == "@$groupName") { - unset($userGroupArray[$key]); - break; - } - } - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - $content1 .= $groupContent; - } else { - return '1'; - } - } - } else { - return '0'; - } - $content2 = preg_replace("/(^@" . $groupName . "[\s]*=.*?)\n/m", "", str_replace($authzContentPreg[0][0], '', $authzContent)); - return $content1 . $content2; -} - -/** - * 修改分组(从所有仓库路径和分组下修改分组名称) - * - * 操作后会将[aliases]的位置放于[groups]之后 - * - * 0 文件格式错误(不存在[groups]标识) - * string 正常 - */ -function FunUpdSvnGroup($authzContent, $oldGroup, $newGroup) -{ - $oldGroup = trim($oldGroup); - $newGroup = trim($newGroup); - $content1 = "[groups]\n"; - $content2 = ""; - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (!empty($temp1)) { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - $groupContent = ""; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - //处理左值 - if ($groupStr == $oldGroup) { - $groupStr = $newGroup; - } - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - //处理右值 - foreach ($userGroupArray as $key => $value) { - if ($value == "@$oldGroup") { - $userGroupArray[$key] = "@$newGroup"; - break; - } - } - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - $content1 .= $groupContent; - } - } else { - return '0'; - } - $content2 = preg_replace("/(^@" . $oldGroup . "[\s]*)=/m", "@$newGroup=", str_replace($authzContentPreg[0][0], '', $authzContent)); - return $content1 . $content2; -} - -/** - * 获取分组列表 - * - * 文件格式错误(不存在[groups]标识) - * 0 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => group1 - * [1] => group2 - * ) - */ -function FunGetSvnGroupList($authzContent) -{ - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - return $resultPreg[1]; - } - } else { - return '0'; - } -} - -/** - * 获取某个分组所在的分组列表 - * - * 文件格式错误(不存在[groups]标识) - * 0 - * - * 分组不存在 - * 1 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => group1 - * [1] => group2 - * ) - */ -function FunGetSvnGroupGroupList($authzContent, $groupName) -{ - $groupName = trim($groupName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $groupArray = []; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - if (in_array("@$groupName", $userGroupArray)) { - array_push($groupArray, $groupStr); - } - } - return $groupArray; - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 获取某个分组下的所有用户列表 - * - * 文件格式错误(不存在[groups]标识) - * 0 - * - * 分组不存在 - * 1 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => user1 - * [1] => user2 - * ) - */ -function FunGetSvnUserListByGroup($authzContent, $groupName) -{ - $groupName = trim($groupName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $userGroupStr = array_combine($resultPreg[1], $resultPreg[2])[$groupName]; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - $userArray = []; - foreach ($userGroupArray as $key => $value) { - if (substr($value, 0, 1) != '@') { - array_push($userArray, $value); - } - } - return $userArray; - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 获取某个分组下的所有分组列表 - * - * 文件格式错误(不存在[groups]标识) - * 0 - * - * 分组不存在 - * 1 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => group1 - * [1] => group2 - * ) - */ -function FunGetSvnGroupListByGroup($authzContent, $groupName) -{ - $groupName = trim($groupName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $userGroupStr = array_combine($resultPreg[1], $resultPreg[2])[$groupName]; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - $groupArray = []; - foreach ($userGroupArray as $key => $value) { - if (substr($value, 0, 1) == '@') { - array_push($groupArray, substr($value, 1)); - } - } - return $groupArray; - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 获取分组列表以及每个分组包含的用户列表和分组列表 - * - * 文件格式错误(不存在[groups]标识) - * 0 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [groupName] => commonAdmin - * [include] => Array - * ( - * [users] => Array - * ( - * [0] => Hachi - * [1] => taosir - * ) - * [groups] => Array - * ( - * ) - * ) - * ) - * [1] => Array - * ( - * [groupName] => g1 - * [include] => Array - * ( - * [users] => Array - * ( - * [0] => Hachi - * ) - * [groups] => Array - * ( - * [0] => superAdmin - * [1] => commonAdmin - * ) - * ) - * ) - * ) - */ -function FunGetSvnGroupUserAndGroupList($authzContent) -{ - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $userArray = []; - $groupArray = []; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); //解决 key=value 中 value 为空的匹配的bug - array_walk($userGroupArray, 'FunArrayValueTrim'); - foreach ($userGroupArray as $key => $value) { - substr($value, 0, 1) == '@' ? array_push($groupArray, substr($value, 1, strlen($value) - 1)) : array_push($userArray, $value); - } - array_push($result, [ - 'groupName' => $groupStr, - 'include' => [ - 'users' => $userArray, - 'groups' => $groupArray - ] - ]); - } - return $result; - } - } else { - return '0'; - } -} - -/** - * 为分组添加用户 - * - * 0 文件格式错误(不存在[groups]标识) - * 1 分组不存在 - * 2 要添加的用户已存在该分组 - * string 正常 - */ -function FunAddSvnGroupUser($authzContent, $groupName, $userName) -{ - $groupName = trim($groupName); - $userName = trim($userName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $groupContent = "[groups]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - if ($groupStr == $groupName) { - if (in_array($userName, $userGroupArray)) { - return '2'; - } - array_push($userGroupArray, $userName); - } - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 从分组删除用户 - * - * 0 文件格式错误(不存在[groups]标识) - * 1 分组不存在 - * 2 要删除的用户不在该分组 - * string 正常 - */ -function FunDelSvnGroupUser($authzContent, $groupName, $userName) -{ - $groupName = trim($groupName); - $userName = trim($userName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $groupContent = "[groups]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - if ($groupStr == $groupName) { - if (in_array($userName, $userGroupArray)) { - unset($userGroupArray[array_search($userName, $userGroupArray)]); - } else { - return '2'; - } - } - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 为分组添加分组 - * - * 0 文件格式错误(不存在[groups]标识) - * 1 分组不存在 - * 2 要添加的分组已存在该分组 - * 3 不能添加本身 - * string 正常 - */ -function FunAddSvnGroupGroup($authzContent, $groupName, $groupName2) -{ - $groupName = trim($groupName); - $groupName2 = trim($groupName2); - if ($groupName == $groupName2) { - return '3'; - } - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $groupContent = "[groups]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - if ($groupStr == $groupName) { - if (in_array("@$groupName2", $userGroupArray)) { - return '2'; - } - array_push($userGroupArray, "@$groupName2"); - } - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 从分组删除分组 - * - * 0 文件格式错误(不存在[groups]标识) - * 1 分组不存在 - * 2 要删除的分组不在该分组 - * string 正常 - */ -function FunDelSvnGroupGroup($authzContent, $groupName, $groupName2) -{ - $groupName = trim($groupName); - $groupName2 = trim($groupName2); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - if (in_array($groupName, $resultPreg[1])) { - $groupContent = "[groups]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - if ($groupStr == $groupName) { - if (in_array("@$groupName2", $userGroupArray)) { - unset($userGroupArray[array_search("@$groupName2", $userGroupArray)]); - } else { - return '2'; - } - } - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 获取某个分组有权限的仓库列表 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => rep1 - * [1] => rep2 - * ) - */ -function FunGetGroupPriRepListWithoutPri($authzContent, $groupName) -{ - $groupName = trim($groupName); - preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - return $authzContentPreg[1]; - } else { - return []; - } -} - -/** - * 获取某个分组有权限的仓库列表以及对应的权限 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [repName] => rep1 - * [repPri] => rw - * ) - * [1] => Array - * ( - * [repName] => rep2 - * [repPri] => rw - * ) - * ) - */ -function FunGetGroupPriRepListWithPri($authzContent, $groupName) -{ - $groupName = trim($groupName); - preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - array_walk($authzContentPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { - $item = []; - $item['repName'] = $key; - $item['repPri'] = $value; - array_push($result, $item); - } - return $result; - } else { - return []; - } -} - -/** - * 获取某个分组有权限的仓库列表以及对应的权限 - */ -function FunGetGroupPriRepListWithPriAndPath($authzContent, $groupName) -{ - $groupName = trim($groupName); - preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - array_walk($authzContentPreg[2], 'FunArrayValueTrim'); - array_walk($authzContentPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach ($authzContentPreg[1] as $key => $value) { - array_push($result, [ - 'repName' => $value, - 'priPath' => $authzContentPreg[2][$key], - 'repPri' => $authzContentPreg[3][$key], - 'unique' => $value . ':' . $authzContentPreg[2][$key] . $authzContentPreg[3][$key] - ]); - } - return $result; - } else { - return []; - } -} diff --git a/02.php/app/function/svnHooks.function.php b/02.php/app/function/svnHooks.function.php deleted file mode 100644 index 7802de4..0000000 --- a/02.php/app/function/svnHooks.function.php +++ /dev/null @@ -1,10 +0,0 @@ - u1 - * [1] => u2 - * ) - */ -function FunGetRepUserListWithoutPri($authzContent, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - return $resultPreg[1]; - } - } else { - return '0'; - } -} - -/** - * 获取某个仓库路径下有权限的用户列表以及对应的权限 - * - * 不存在该仓库路径的记录 - * 0 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [userName] => rep1 - * [userPri] => r - * ) - * [1] => Array - * ( - * [userName] => rep2 - * [userPri] => - * ) - * ) - */ -function FunGetRepUserListWithPri($authzContent, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - $result = []; - //注意$value的值 不限于合法的 r 、rw、空 以及不合法的其它字符 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $key => $value) { - $item = []; - $item['userName'] = $key; - $item['userPri'] = $value; - array_push($result, $item); - } - return $result; - } - } else { - return '0'; - } -} - -/** - * 获取某个仓库路径下有权限的分组列表 - * - * 不存在该仓库路径的记录 - * 0 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => g1 - * [1] => g2 - * ) - */ -function FunGetRepGroupListWithoutPri($authzContent, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - return $resultPreg[1]; - } - } else { - return '0'; - } -} - -/** - * 获取某个仓库路径下有权限的分组列表以及对应的权限 - * - * 不存在该仓库路径的记录 - * 0 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [groupName] => rep1 - * [groupPri] => rw - * ) - * [1] => Array - * ( - * [groupName] => rep2 - * [groupPri] => rw - * ) - * ) - */ -function FunGetRepGroupListWithPri($authzContent, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $key => $value) { - $item = []; - $item['groupName'] = $key; - $item['groupPri'] = $value; - array_push($result, $item); - } - return $result; - } - } else { - return '0'; - } -} - -/** - * 为某个仓库路径设置用户权限 - * 包括为已有权限的用户修改权限 - * 包括为没有权限的用户增加权限 - * 如果该目录的该用户的父目录有权限 那么所有子目录继承权限 - * - * 0 不存在该仓库路径的记录 - * string 正常 - */ -function FunSetRepUserPri($authzContent, $user, $privilege, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - //添加用户 - return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n$user=$privilege\n", $authzContent); - } else { - //进一步判断有没有用户数据 - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - - //处理分组 - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); - array_walk($resultPregGroup[1], 'FunArrayValueTrim'); - array_walk($resultPregGroup[2], 'FunArrayValueTrim'); - - if (in_array($user, $resultPreg[1])) { - //编辑 - $userContent = "[$repName:$repPath]\n"; - - //处理分组 - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - $userContent .= "@$groupStr=$groupPri\n"; - } - - //处理用户 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - if ($userStr == $user) { - $userContent .= "$userStr=$privilege\n"; - } else { - $userContent .= "$userStr=$userPri\n"; - } - } - - return str_replace($authzContentPreg[0][0], $userContent, $authzContent); - } else { - //新增 - $userContent = "[$repName:$repPath]\n"; - - //处理分组 - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - $userContent .= "@$groupStr=$groupPri\n"; - } - - //处理用户 - $userContent .= "$user=$privilege\n"; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - $userContent .= "$userStr=$userPri\n"; - } - return str_replace($authzContentPreg[0][0], $userContent, $authzContent); - } - } - } else { - return '0'; - } -} - -/** - * 删除某个仓库路径的用户权限 - * 父目录有权限 无法取消子目录的权限 - * - * 0 不存在该仓库路径的记录 - * 1 已删除 - * string 正常 - */ -function FunDelRepUserPri($authzContent, $user, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - //进一步判断有没有用户数据 - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - - //处理分组 - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); - array_walk($resultPregGroup[1], 'FunArrayValueTrim'); - array_walk($resultPregGroup[2], 'FunArrayValueTrim'); - - if (in_array($user, $resultPreg[1])) { - //删除 - $userContent = "[$repName:$repPath]\n"; - - //处理分组 - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - $userContent .= "@$groupStr=$groupPri\n"; - } - - //处理用户 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - if ($userStr == $user) { - continue; - } - $userContent .= "$userStr=$userPri\n"; - } - - return str_replace($authzContentPreg[0][0], $userContent, $authzContent); - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 修改某个仓库路径的用户权限 - * - * 0 不存在该仓库路径的记录 - * string 正常 - */ -function FunUpdRepUserPri($authzContent, $user, $privilege, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n$user=$privilege\n", $authzContent); - } else { - //进一步判断有没有用户数据 - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - - //处理分组 - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); - array_walk($resultPregGroup[1], 'FunArrayValueTrim'); - array_walk($resultPregGroup[2], 'FunArrayValueTrim'); - - //编辑 - $userContent = "[$repName:$repPath]\n"; - - //处理分组 - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - $userContent .= "@$groupStr=$groupPri\n"; - } - - //处理用户 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - if ($userStr == $user) { - $userContent .= "$userStr=$privilege\n"; - } else { - $userContent .= "$userStr=$userPri\n"; - } - } - return str_replace($authzContentPreg[0][0], $userContent, $authzContent); - } - } else { - return '0'; - } -} - -/** - * 为某个仓库路径设置分组权限 - * 包括为已有权限的分组修改权限 - * 包括为没有权限的分组增加权限 - * 其中如果分组和用户都设置了权限 但是权限一个为可读 一个为可写 应该遵循什么规则呢 开发者无需考虑 - * - * 0 不存在该仓库路径的记录 - * string 正常 - */ -function FunSetRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n@$group=$privilege\n", $authzContent); - } else { - //进一步判断有没有分组数据 - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); - array_walk($resultPregGroup[1], 'FunArrayValueTrim'); - array_walk($resultPregGroup[2], 'FunArrayValueTrim'); - - //处理用户 - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - - if (in_array($group, $resultPregGroup[1])) { - //编辑 - $groupContent = "[$repName:$repPath]\n"; - - //处理分组 - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - if ($groupStr == $group) { - $groupContent .= "@$group=$privilege\n"; - } else { - $groupContent .= "@$groupStr=$groupPri\n"; - } - } - - //处理用户 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - $groupContent .= "$userStr=$userPri\n"; - } - - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } else { - //新增 - $groupContent = "[$repName:$repPath]\n"; - - //处理分组 - $groupContent .= "@$group=$privilege\n"; - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - $groupContent .= "@$groupStr=$groupPri\n"; - } - - //处理用户 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - $groupContent .= "$userStr=$userPri\n"; - } - - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } - } - } else { - return '0'; - } -} - -/** - * 删除某个仓库的分组权限 - * - * 0 不存在该仓库路径的记录 - * 1 已删除 - * string 正常 - */ -function FunDelRepGroupPri($authzContent, $group, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - //进一步判断有没有分组数据 - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); - array_walk($resultPregGroup[1], 'FunArrayValueTrim'); - array_walk($resultPregGroup[2], 'FunArrayValueTrim'); - - //处理用户 - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - - if (in_array($group, $resultPregGroup[1])) { - //编辑 - $groupContent = "[$repName:$repPath]\n"; - - //处理分组 - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - if ($groupStr == $group) { - continue; - } else { - $groupContent .= "@$groupStr=$groupPri\n"; - } - } - - //处理用户 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - $groupContent .= "$userStr=$userPri\n"; - } - - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 修改某个仓库路径的分组权限 - * - * 0 不存在该仓库路径的记录 - * 1 该仓库下不存在该分组 - * string 正常 - */ -function FunUpdRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n@$group=$privilege\n", $authzContent); - } else { - //进一步判断有没有分组数据 - preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); - array_walk($resultPregGroup[1], 'FunArrayValueTrim'); - array_walk($resultPregGroup[2], 'FunArrayValueTrim'); - - //处理用户 - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - - if (in_array($group, $resultPregGroup[1])) { - //编辑 - $groupContent = "[$repName:$repPath]\n"; - - //处理分组 - foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { - if ($groupStr == $group) { - $groupContent .= "@$group=$privilege\n"; - } else { - $groupContent .= "@$groupStr=$groupPri\n"; - } - } - - //处理用户 - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { - $groupContent .= "$userStr=$userPri\n"; - } - - return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 向配置文件写入仓库路径 - * - * 1 已存在 - * string 正常 - */ -function FunSetRepAuthz($authzContent, $repName, $repPath) -{ - //处理路径结尾 - if ($repPath != '/') { - if (substr($repPath, strlen($repPath) - 1, 1) == '/') { - $repPath = substr($repPath, 0, strlen($repPath) - 1); - } - } - - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITHOUT_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - return '1'; - } else { - return $authzContent . "\n[$repName:$repPath]\n"; - } -} - -/** - * 从配置文件删除指定仓库的所有路径 - * - * 1 已删除 - * string 正常 - */ -function FunDelRepAuthz($authzContent, $repName) -{ - preg_match_all(sprintf(REG_AUTHZ_REP_ALL_PATH_WITH_CON, $repName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - foreach ($authzContentPreg[0] as $key => $value) { - $authzContent = str_replace($value, "", $authzContent); - } - return $authzContent; - } else { - return '1'; - } -} - -/** - * 从配置文件获取所有的仓库名称 - * - * 不匹配这些仓库的内容和具体路径 - * - * 空列表 - * [] - * - * 正常数据 - * - */ -function FunGetNoPathAndConRepAuthz($authzContent) -{ - preg_match_all(REG_AUTHZ_ALL_REP_WITHOUT_PATH_AND_CON, $authzContent, $authzContentPreg); - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - return array_values(array_unique($authzContentPreg[1])); -} - -/** - * 从配置文件修改仓库名称 - * 修改该仓库所有路径的仓库名称 - * - * 没有校验要修改的仓库是否已经存在 需要上层函数进行校验 - * - * 1 仓库不存在 - * string 正常 - */ -function FunUpdRepAuthz($authzContent, $oldRepName, $newRepName) -{ - preg_match_all(sprintf(REG_AUTHZ_REP_ALL_PATH_WITHOUT_CON, $oldRepName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - foreach ($authzContentPreg[0] as $key => $value) { - $authzContent = str_replace($value, '[' . $newRepName . ':' . $authzContentPreg[1][$key] . ']', $authzContent); - } - return $authzContent; - } else { - return '1'; - } -} - -/** - * 获取所有用户都有权限的仓库列表带有权限(包括只读、读写) - * 用户匹配 *=r *=rw - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [repName] => rep1 - * [repPri] => rw - * ) - * [1] => Array - * ( - * [repName] => rep2 - * [repPri] => r - * ) - * ) - */ -function FunGetAllHavePriRepListWithPri($authzContent) -{ - $userName = '*'; - preg_match_all(sprintf(REG_AUTHZ_ALL_HAVE_PRI_REPS, $userName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - array_walk($authzContentPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { - $item = []; - $item['repName'] = $key; - $item['repPri'] = $value; - array_push($result, $item); - } - return $result; - } else { - return []; - } -} - -/** - * 获取所有用户都有权限的仓库列表(包括只读、读写) - * 用户匹配 *=r *=rw - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => rep1 - * [1] => rep2 - * ) - */ -function FunGetAllHavePriRepListWithoutPri($authzContent) -{ - $userName = '*'; - preg_match_all(sprintf(REG_AUTHZ_ALL_HAVE_PRI_REPS, $userName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - array_walk($authzContentPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { - array_push($result, $key); - } - return $result; - } else { - return []; - } -} - -/** - * 获取所有用户都无权限的仓库列表 - * 用户匹配 *= - */ -function FunGetAllNoPriRepListWithoutPri($authzContent) -{ - $userName = '*'; - preg_match_all(sprintf(REG_AUTHZ_ALL_NO_PRI_REPS, $userName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - array_walk($authzContentPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { - if ($value == '') { - array_push($result, $key); - } - } - return $result; - } else { - return []; - } -} - -/** - * 获取SVN仓库列表 - */ -function FunGetRepList() -{ - $repArray = []; - $file_arr = scandir(SVN_REPOSITORY_PATH); - foreach ($file_arr as $file_item) { - if ($file_item != '.' && $file_item != '..') { - if (is_dir(SVN_REPOSITORY_PATH . $file_item)) { - $file_arr2 = scandir(SVN_REPOSITORY_PATH . $file_item); - foreach ($file_arr2 as $file_item2) { - if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { - array_push($repArray, array( - 'repName' => $file_item, - 'repUrl' => SVN_REPOSITORY_PATH . $file_item, - 'repSize' => round(FunGetDirSize(SVN_REPOSITORY_PATH . $file_item) / (1024 * 1024), 2), - 'repCheckoutUrl' => 'svn://' . 'SERVER_DOMAIN' . '/' . $file_item, - )); - break; - } - } - } - } - } - return $repArray; -} - -/** - * 获取简单SVN仓库列表 - */ -function FunGetSimpleRepList() -{ - $repArray = []; - $file_arr = scandir(SVN_REPOSITORY_PATH); - foreach ($file_arr as $file_item) { - if ($file_item != '.' && $file_item != '..') { - if (is_dir(SVN_REPOSITORY_PATH . $file_item)) { - $file_arr2 = scandir(SVN_REPOSITORY_PATH . $file_item); - foreach ($file_arr2 as $file_item2) { - if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { - array_push($repArray, $file_item); - break; - } - } - } - } - } - return $repArray; -} - -/** - * 初始化仓库结构为 trunk branches tags - */ -function FunInitRepStruct($repName, $initUser = "SVNAdmin", $initPass = "SVNAdmin") -{ - $randPrefix = FunGetRandStr(); - $tempPath = TEMP_PATH . $randPrefix; - $repPath = SVN_REPOSITORY_PATH . $repName; - - $tempMkdirCmd = sprintf("mkdir -p %s", $tempPath); - $svnCheckoutCmd = sprintf("svn checkout file:///%s --quiet --username %s --password %s %s", $repPath, $initUser, $initPass, $tempPath); - $repMkdirCmd = sprintf("mkdir -p %s/{trank/,branches/,tags/}", $tempPath); - $svnAddCmd = sprintf("svn add --quiet --username %s --password %s %s/*", $initUser, $initPass, $tempPath); - $svnCommitCmd = sprintf("svn commit --quiet --username %s --password %s --message 'Initial structure' %s/*", $initUser, $initPass, $tempPath); - $delDirCmd = sprintf("rm -rf %s", $tempPath); - - $cmd = implode(';', [$tempMkdirCmd, $svnCheckoutCmd, $repMkdirCmd, $svnAddCmd, $svnCommitCmd, $delDirCmd]); - - FunShellExec($cmd); -} - -/** - * 使用 svnadmin info $repPath 获取部分仓库信息 - * UUID - * Revisions - * Repository Format - * Compatible With Version - * Repository Capability - * Filesystem Type - * Filesystem Format - * FSFS Sharded - * FSFS Shard Size - * FSFS Shards Packed - * FSFS Logical Addressing - */ -function FunGetRepInfo($repName) -{ - $repPath = SVN_REPOSITORY_PATH . $repName; - - $svnadminInfoCmd = sprintf("svnadmin info '%s'", $repPath); - - $cmdResult = FunShellExec($svnadminInfoCmd); - - preg_match_all(REG_REP_INFO, $cmdResult, $svnadminInfoPreg); - - $svnadminInfoResult = array_combine($svnadminInfoPreg[1], $svnadminInfoPreg[2]); - - unset($svnadminInfoResult['Path'], $svnadminInfoResult['Configuration File']); - - return $svnadminInfoResult; -} - -/** - * 使用 svnlook tree $repPath 获取仓库的最新版本的目录树 - */ -function FunGetRepTree($repName) -{ - $repPath = SVN_REPOSITORY_PATH . $repName; - $svnadminInfoCmd = sprintf("svnlook tree '%s'", $repPath); - $cmdResult = FunShellExec($svnadminInfoCmd); - // $cmdResult = shell_exec($svnadminInfoCmd); - $treeArray = explode("\n", $cmdResult); - //去除数组中的空字符串键值 通常为最后一项 - $treeArray = array_filter($treeArray, 'FunArrayValueFilter'); - //获取对应空格数开头的数组 - $spaceCountArray = array_map('FunArrayGetStrSpaceCount', $treeArray); - //获取是否为目录或者文件的数组 - $isFolderArray = array_map('FunArrayIsStrFolder', $treeArray); - //合并数组 - $complateArray = []; - foreach ($treeArray as $key => $value) { - array_push($complateArray, array( - 'content' => trim($value), - 'spaceCount' => $spaceCountArray[$key], - 'isFolder' => $isFolderArray[$key] - )); - } - //拼接根目录 - return [ - [ - 'title' => '/', - 'expand' => true, - 'children' => FunGetFolderStruct($complateArray, 0) - ] - ]; -} - -/** - * 按照指定的数据结构以递归方式拼接目录结构 - * - * 示例输入以下数组和0 - * Array - * ( - * [0] => Array - * ( - * [content] => / - * [spaceCount] => 0 - * [isFolder] => 1 - * ) - * [1] => Array - * ( - * [content] => 00.folder/ - * [spaceCount] => 1 - * [isFolder] => 1 - * ) - * [2] => Array - * ( - * [content] => 001.jpg - * [spaceCount] => 2 - * [isFolder] => 0 - * ) - * [3] => Array - * ( - * [content] => 01.folder/ - * [spaceCount] => 1 - * [isFolder] => 1 - * ) - * [4] => Array - * ( - * [content] => 011.folder/ - * [spaceCount] => 2 - * [isFolder] => 1 - * ) - * [5] => Array - * ( - * [content] => 02.folder/ - * [spaceCount] => 1 - * [isFolder] => 1 - * ) - * [6] => Array - * ( - * [content] => 021.folder/ - * [spaceCount] => 2 - * [isFolder] => 1 - * ) - * [7] => Array - * ( - * [content] => 0211.file.docx - * [spaceCount] => 3 - * [isFolder] => 0 - * ) - * [8] => Array - * ( - * [content] => 03.jpg - * [spaceCount] => 1 - * [isFolder] => 0 - * ) - * ) - * - * 示例输出 - * Array - * ( - * [0] => Array - * ( - * [title] => 00.folder/ - * [children] => Array - * ( - * [0] => Array - * ( - * [title] => 001.jpg - * ) - * ) - * ) - * [1] => Array - * ( - * [title] => 01.folder/ - * [children] => Array - * ( - * [0] => Array - * ( - * [title] => 011.folder/ - * ) - * ) - * ) - * [2] => Array - * ( - * [title] => 02.folder/ - * [children] => Array - * ( - * [0] => Array - * ( - * [title] => 021.folder/ - * [children] => Array - * ( - * [0] => Array - * ( - * [title] => 0211.file.docx - * ) - * ) - * ) - * ) - * ) - * [3] => Array - * ( - * [title] => 03.jpg - * ) - * ) - */ -function FunGetFolderStruct($complateArray, $fileIndex) -{ - //获取当前文件夹的目录内容 以子文件夹和子文件下标的形式返回 - $dirContent = FunGetFolderDirAndFiles($complateArray, $fileIndex); - - //按照特定结构拼接 - $result = []; - foreach ($dirContent as $key => $value) { - $children = FunGetFolderStruct($complateArray, $value); - if ($children == []) { - array_push($result, array( - 'title' => $complateArray[$value]['content'], - 'expand' => true, - )); - } else { - array_push($result, array( - 'title' => $complateArray[$value]['content'], - 'expand' => true, - 'children' => $children - )); - } - } - return $result; -} - -/** - * 模拟正常的文件系统 获取指定目录或者文件的子文件夹和子文件(文件会返回空) - * - * 示例输入(只用到spaceCount键值)以下数组和0 - * Array - * ( - * [0] => Array - * ( - * [content] => / - * [spaceCount] => 0 - * [isFolder] => 1 - * ) - * [1] => Array - * ( - * [content] => 00.folder/ - * [spaceCount] => 1 - * [isFolder] => 1 - * ) - * [2] => Array - * ( - * [content] => 001.jpg - * [spaceCount] => 2 - * [isFolder] => 0 - * ) - * [3] => Array - * ( - * [content] => 01.folder/ - * [spaceCount] => 1 - * [isFolder] => 1 - * ) - * [4] => Array - * ( - * [content] => 011.folder/ - * [spaceCount] => 2 - * [isFolder] => 1 - * ) - * [5] => Array - * ( - * [content] => 02.folder/ - * [spaceCount] => 1 - * [isFolder] => 1 - * ) - * [6] => Array - * ( - * [content] => 021.folder/ - * [spaceCount] => 2 - * [isFolder] => 1 - * ) - * [7] => Array - * ( - * [content] => 0211.file.docx - * [spaceCount] => 3 - * [isFolder] => 0 - * ) - * [8] => Array - * ( - * [content] => 03.jpg - * [spaceCount] => 1 - * [isFolder] => 0 - * ) - * ) - * - * 示例输出 - * Array - * ( - * [0] => 1 - * [1] => 3 - * [2] => 5 - * [3] => 8 - * ) - */ -function FunGetFolderDirAndFiles($complateArray, $fileIndex) -{ - $result = []; - //末尾 - if (!array_key_exists($fileIndex + 1, $complateArray)) { - return []; - } - //无子节点 - if ($complateArray[$fileIndex]['spaceCount'] == $complateArray[$fileIndex + 1]['spaceCount']) { - return []; - } - //有子节点 - foreach ($complateArray as $key => $value) { - if ($key > $fileIndex) { - //遇到同级目录退出 - //遇到上级目录退出 - if ($complateArray[$key]['spaceCount'] <= $complateArray[$fileIndex]['spaceCount']) { - break; - } - //遇到下级目录push - if ($complateArray[$key]['spaceCount'] == $complateArray[$fileIndex]['spaceCount'] + 1) { - array_push($result, $key); - } - } - } - return $result; -} - - -/** - * 检查仓库是否存在或者是否存在同名的文件夹 - */ -function FunCheckRepExist($repName, $message = '仓库已经存在') -{ - clearstatcache(); - if (is_dir(SVN_REPOSITORY_PATH . $repName)) { - FunMessageExit(200, 0, $message); - } -} - -/** - * 检查仓库是否创建成功 - */ -function FunCheckRepCreate($repName, $message = '仓库创建失败') -{ - clearstatcache(); - if (!is_dir(SVN_REPOSITORY_PATH . $repName)) { - FunMessageExit(200, 0, $message); - } -} - -/** - * 检查仓库是否删除成功 - */ -function FunCheckRepDelete($repName, $message = '仓库删除失败') -{ - clearstatcache(); - if (is_dir(SVN_REPOSITORY_PATH . $repName)) { - FunMessageExit(200, 0, $message); - } -} - -/** - * 获取仓库的修订版本数量 - */ -function FunGetRepRev($repName) -{ - $cmd = sprintf("svnadmin info '%s' | grep 'Revisions' | awk '{print $2}'", SVN_REPOSITORY_PATH . $repName); - return (int)trim(FunShellExec($cmd)); -} - -/** - * 获取仓库的属性内容(key-vlaue的形式) - */ -function FunGetRepDetail($repName) -{ - $cmd = sprintf("svnadmin info '%s'", SVN_REPOSITORY_PATH . $repName); - return trim(FunShellExec($cmd)); -} - -/** - * 获取仓库下某个文件的体积 - * - * 目前为默认最新版本 - * - * 根据体积大小自动调整单位 - */ -function FunGetRepRevFileSize($repName, $filePath) -{ - $cmd = sprintf("svnlook filesize '%s' '%s'", SVN_REPOSITORY_PATH . $repName, $filePath); - $size = (int)trim(FunShellExec($cmd)); - return FunFormatSize($size); -} - -/** - * 获取仓库下指定文件或者文件夹的最高修订版本 - */ -function FunGetRepFileRev($repName, $filePath) -{ - $cmd = sprintf("svnlook history --limit 1 '%s' '%s'", SVN_REPOSITORY_PATH . $repName, $filePath); - $result = FunShellExec($cmd); - $resultArray = explode("\n", trim($result)); - $content = preg_replace("/\s{2,}/", ' ', $resultArray[2]); - $contentArray = explode(' ', $content); - return trim($contentArray[1]); -} - -/** - * 获取仓库下指定文件或者文件夹的作者 - */ -function FunGetRepFileAuthor($repName, $rev) -{ - $cmd = sprintf("svnlook author -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); - $result = FunShellExec($cmd); - return trim($result); -} - -/** - * 获取仓库下指定文件或者文件夹的提交日期 - */ -function FunGetRepFileDate($repName, $rev) -{ - $cmd = sprintf("svnlook date -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); - $result = FunShellExec($cmd); - return trim($result); -} - -/** - * 获取仓库下指定文件或者文件夹的提交日志 - */ -function FunGetRepFileLog($repName, $rev) -{ - $cmd = sprintf("svnlook log -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); - $result = FunShellExec($cmd); - return trim($result); -} - -/** - * 使用 svnadmin dump 备份仓库 - * - * 默认为全版本 - */ -function FunRepDump($repName, $backupName) -{ - $cmd = sprintf('svnadmin dump %s --quiet > %s', SVN_REPOSITORY_PATH . $repName, SVN_BACHUP_PATH . $backupName); - FunShellExec($cmd); -} - -/** - * 删除备份文件 - */ -function FunDelRepBackup($fileName) -{ - $cmd = sprintf("cd '%s' && rm -f './%s'", SVN_BACHUP_PATH, $fileName); - FunShellExec($cmd); -} - -/** - * 使用 svnadmin load 导入仓库 - */ -function FunRepLoad($repName, $fileName) -{ - $cmd = sprintf("svnadmin load --quiet '%s' < '%s'", SVN_REPOSITORY_PATH . $repName, SVN_BACHUP_PATH . $fileName); - $result = FunShellExec($cmd); - return trim($result); -} - -/** - * 使用 svn list 为用户检查指令 - */ -function CheckSvnUserPathAutzh($checkoutHost, $repName, $repPath, $svnUserName, $svnUserPass) -{ - $cmd = sprintf("svn list '%s' --username '%s' --password '%s' --no-auth-cache --non-interactive --trust-server-cert", $checkoutHost . '/' . $repName . $repPath, $svnUserName, $svnUserPass); - $result = FunShellExec($cmd); - if (strstr($result, 'svn: E170001: Authentication error from server: Password incorrect')) { - //密码错误 - return false; - } - if (strstr($result, 'svn: E170001: Authorization failed')) { - //没有权限 - return false; - } - if (strstr($result, 'svn: E170013: Unable to connect to a repository at URL')) { - //其它错误 - return false; - } - return true; -} diff --git a/02.php/app/function/svnUser.function.php b/02.php/app/function/svnUser.function.php deleted file mode 100644 index bf25f52..0000000 --- a/02.php/app/function/svnUser.function.php +++ /dev/null @@ -1,555 +0,0 @@ - $value) { - $resultStr .= "$key=$value\n"; - } - $resultStr .= "$userName=$userPass\n"; - return $resultStr; - } - } else { - return '0'; - } -} - -/** - * 修改SVN用户(passwd文件中) - */ -function FunUpdSvnUserPasswd($passwdContent, $oldUserName, $newUserName) -{ - //不提供此方法 -} - -/** - * 删除SVN用户 - * - * 0 文件格式错误(不存在[users]标识) - * 1 用户不存在 - * string 正常 - */ -function FunDelSvnUserPasswd($passwdContent, $userName, $isDisabledUser = false) -{ - $userName = trim($userName); - $userName = $isDisabledUser ? (REG_SVN_USER_DISABLED . $userName) : $userName; - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); - if (array_key_exists(0, $passwdContentPreg[1])) { - $temp1 = trim($passwdContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[3], 'FunArrayValueTrim'); - if (in_array($userName, $resultPreg[1])) { - $resultStr = "[users]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { - if ($key == $userName) { - continue; - } - $resultStr .= "$key=$value\n"; - } - return $resultStr; - } - return '1'; - } - } else { - return '0'; - } -} - -/** - * 获取SVN用户列表 - * - * 文件格式错误(不存在[users]标识) - * 0 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [userName] => u1 - * [disabled] => 1 - * ) - * - * [1] => Array - * ( - * [userName] => u2 - * [disabled] => 0 - * ) - * - * ) - */ -function FunGetSvnUserList($passwdContent) -{ - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); - if (array_key_exists(0, $passwdContentPreg[1])) { - $temp1 = trim($passwdContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - $result = []; - foreach ($resultPreg[1] as $value) { - $item = []; - if (substr($value, 0, strlen(REG_SVN_USER_DISABLED)) == REG_SVN_USER_DISABLED) { - $item['userName'] = substr($value, strlen(REG_SVN_USER_DISABLED)); - $item['disabled'] = '1'; - } else { - $item['userName'] = $value; - $item['disabled'] = '0'; - } - array_push($result, $item); - } - return $result; - } - } else { - return '0'; - } -} - -/** - * 获取SVN用户以及密码列表 - * - * 文件格式错误(不存在[users]标识) - * 0 - * - * 空数据 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [userName] => u1 - * [userPass] => p1 - * [disabled] => 1 - * ) - * - * [1] => Array - * ( - * [userName] => u2 - * [userPass] => p2 - * [disabled] => 0 - * ) - * - * ) - */ -function FunGetSvnUserPassList($passwdContent) -{ - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); - if (array_key_exists(0, $passwdContentPreg[1])) { - $tem1 = trim($passwdContentPreg[1][0]); - if (empty($tem1)) { - return []; - } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($resultPreg[1], $resultPreg[3]) as $userName => $userPass) { - $item = []; - if (substr($userName, 0, strlen(REG_SVN_USER_DISABLED)) == REG_SVN_USER_DISABLED) { - $item['userName'] = substr($userName, strlen(REG_SVN_USER_DISABLED)); - $item['userPass'] = $userPass; - $item['disabled'] = '1'; - } else { - $item['userName'] = $userName; - $item['userPass'] = $userPass; - $item['disabled'] = '0'; - } - array_push($result, $item); - } - return $result; - } - } else { - return '0'; - } -} - -/** - * 获取SVN指定用户的密码 - * - * 0 文件格式错误(不存在[users]标识) - * 1 用户不存在 - * string 正常 - */ -function FunGetPassByUser($passwdContent, $userName, $isDisabledUser = false) -{ - $userName = trim($userName); - $userName = $isDisabledUser ? (REG_SVN_USER_DISABLED . $userName) : $userName; - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); - if (array_key_exists(0, $passwdContentPreg[1])) { - $temp1 = trim($passwdContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[3], 'FunArrayValueTrim'); - if (array_search($userName, $resultPreg[1]) !== false) { - return $resultPreg[3][array_search($userName, $resultPreg[1])]; - } else { - return '1'; - } - } - } else { - return '0'; - } -} - -/** - * 修改SVN指定用户的密码 - * - * 0 文件格式错误(不存在[users]标识) - * 1 用户不存在 - * string 正常 - */ -function FunUpdSvnUserPass($passwdContent, $userName, $userPass, $isDisabledUser = false) -{ - $userName = trim($userName); - $userPass = trim($userPass); - $userName = $isDisabledUser ? (REG_SVN_USER_DISABLED . $userName) : $userName; - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); - if (array_key_exists(0, $passwdContentPreg[1])) { - $temp1 = trim($passwdContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[3], 'FunArrayValueTrim'); - if (in_array($userName, $resultPreg[1])) { - $resultStr = "[users]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { - if ($key == $userName) { - $value = $userPass; - } - $resultStr .= "$key=$value\n"; - } - return $resultStr; - } - return '1'; - } - } else { - return '0'; - } -} - -/** - * 获取某个用户所在的分组列表 - * $recursively = false 只获取用户与分组处于直接包含关系的分组列表 - * $recursively = true 获取用户与分组处于直接包含关系的分组列表、获取处于分组嵌套分组导致用户与分组处于间接包含关系的分组列表 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => goup1 - * [1] => group - * ) - */ -function FunGetSvnUserGroupList($authzContent, $userName) -{ - $userName = trim($userName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[0])) { - $temp1 = trim($authzContentPreg[1][0]); - if (empty($temp1)) { - return []; - } else { - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - $userArray = []; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - if (in_array($userName, $userGroupArray)) { - array_push($userArray, $groupStr); - } - } - return $userArray; - } - } else { - return '0'; - } -} - -/** - * 获取某个用户有权限的所有仓库列表 - * - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => rep1 - * [1] => rep2 - * ) - */ -function FunGetUserPriRepListWithoutPri($authzContent, $userName) -{ - $userName = trim($userName); - preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - return $authzContentPreg[1]; - } else { - return []; - } -} - -/** - * 获取某个用户有权限的所有仓库列表以及对应的权限 - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [repName] => rep1 - * [repPri] => rw - * ) - * [1] => Array - * ( - * [repName] => rep2 - * [repPri] => rw - * ) - * ) - */ -function FunGetUserPriRepListWithPri($authzContent, $userName) -{ - $userName = trim($userName); - preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - array_walk($authzContentPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { - $item = []; - $item['repName'] = $key; - $item['repPri'] = $value; - array_push($result, $item); - } - return $result; - } else { - return []; - } -} - -/** - * 获取某个用户有权限的所有仓库列表(带有路径和权限) - * - * 空列表 - * [] - * - * 正常数据 - * Array - * ( - * [0] => Array - * ( - * [repName] => rep1 - * [priPath] => / - * [repPri] => rw - * ) - * [1] => Array - * ( - * [repName] => rep2 - * [priPath] => /branches/taoweitao/计划.md - * [repPri] => rw - * ) - * ) - */ -function FunGetUserPriRepListWithPriAndPath($authzContent, $userName) -{ - $userName = trim($userName); - preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); - if (array_key_exists(0, $authzContentPreg[1])) { - array_walk($authzContentPreg[1], 'FunArrayValueTrim'); - array_walk($authzContentPreg[2], 'FunArrayValueTrim'); - array_walk($authzContentPreg[3], 'FunArrayValueTrim'); - $result = []; - foreach ($authzContentPreg[1] as $key => $value) { - array_push($result, [ - 'repName' => $value, - 'priPath' => $authzContentPreg[2][$key], - 'repPri' => $authzContentPreg[3][$key], - 'unique' => $value . ':' . $authzContentPreg[2][$key] . $authzContentPreg[3][$key] - ]); - } - return $result; - } else { - return []; - } -} - -/** - * 从所有仓库路径和分组下修改用户名 - * - * string 正常 - */ -function FunUpdUserAuthz($authzContent, $oldUserName, $newUserName) -{ -} - -/** - * 从所有仓库路径和分组下删除SVN用户 - * 从所有分组中删除用户 - * 从所有仓库下删除用户 - * - * 0 文件格式错误(不存在[users]标识) - * string 正常 - */ -function FunDelUserAuthz($authzContent, $userName) -{ - $userName = trim($userName); - $content1 = "[groups]\n"; - $content2 = ""; - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg1); - if (array_key_exists(0, $authzContentPreg1[0])) { - $temp1 = trim($authzContentPreg1[1][0]); - if (!empty($temp1)) { - preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg1[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[2], 'FunArrayValueTrim'); - $groupContent = ""; - foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { - $groupContent .= "$groupStr="; - $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); - array_walk($userGroupArray, 'FunArrayValueTrim'); - if (in_array($userName, $userGroupArray)) { - unset($userGroupArray[array_search($userName, $userGroupArray)]); - } - $groupContent .= implode(',', $userGroupArray) . "\n"; - } - $content1 .= $groupContent; - } - } else { - return '0'; - } - $content2 = preg_replace("/([^@]^$userName" . "[\s]*=.*?)\n/m", "\n", str_replace($authzContentPreg1[0][0], '', $authzContent)); - return $content1 . $content2; -} - -/** - * 禁用某个SVN用户 - * 0 文件格式错误(不存在[users]标识) - * 1 要禁用的用户不存在 - * string 正常 - */ -function FunDisabledUser($passwdContent, $userName) -{ - $userName = trim($userName); - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); - if (array_key_exists(0, $passwdContentPreg[1])) { - $temp1 = trim($passwdContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[3], 'FunArrayValueTrim'); - if (in_array($userName, $resultPreg[1])) { - $resultStr = "[users]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { - if ($key == $userName) { - $key = REG_SVN_USER_DISABLED . $key; - } - $resultStr .= "$key=$value\n"; - } - return $resultStr; - } - return '1'; - } - } else { - return '0'; - } -} - -/** - * 启用某个SVN用户 - * 0 文件格式错误(不存在[users]标识) - * 1 要启用的用户不存在 - * string 正常 - */ -function FunEnabledUser($passwdContent, $userName) -{ - $userName = trim($userName); - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); - if (array_key_exists(0, $passwdContentPreg[1])) { - $temp1 = trim($passwdContentPreg[1][0]); - if (empty($temp1)) { - return '1'; - } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); - array_walk($resultPreg[1], 'FunArrayValueTrim'); - array_walk($resultPreg[3], 'FunArrayValueTrim'); - if (in_array(REG_SVN_USER_DISABLED . $userName, $resultPreg[1])) { - $resultStr = "[users]\n"; - foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { - if ($key == REG_SVN_USER_DISABLED . $userName) { - $key = $userName; - } - $resultStr .= "$key=$value\n"; - } - return $resultStr; - } - return '1'; - } - } else { - return '0'; - } -} diff --git a/02.php/app/model/util.model.php b/02.php/app/model/util.model.php new file mode 100644 index 0000000..c34d754 --- /dev/null +++ b/02.php/app/model/util.model.php @@ -0,0 +1,24 @@ + $userGroupStr) { + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + $groupContent .= "$groupName=\n"; + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } + } + } else { + return '0'; + } + } + + /** + * 删除分组(从所有仓库路径和分组下删除分组名称) + * + * 操作后会将[aliases]的位置放于[groups]之后 + * + * 0 文件格式错误(不存在[groups]标识) + * 1 分组不存在 + * string 正常 + */ + public static function DelSvnGroup($authzContent, $groupName) + { + $groupName = trim($groupName); + $content1 = "[groups]\n"; + $content2 = ""; + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (!empty($temp1)) { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $groupContent = ""; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + //处理左值 + if ($groupStr == $groupName) { + continue; + } + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + //处理右值 + foreach ($userGroupArray as $key => $value) { + if ($value == "@$groupName") { + unset($userGroupArray[$key]); + break; + } + } + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + $content1 .= $groupContent; + } else { + return '1'; + } + } + } else { + return '0'; + } + $content2 = preg_replace("/(^@" . $groupName . "[\s]*=.*?)\n/m", "", str_replace($authzContentPreg[0][0], '', $authzContent)); + return $content1 . $content2; + } + + /** + * 修改分组(从所有仓库路径和分组下修改分组名称) + * + * 操作后会将[aliases]的位置放于[groups]之后 + * + * 0 文件格式错误(不存在[groups]标识) + * string 正常 + */ + public static function UpdSvnGroup($authzContent, $oldGroup, $newGroup) + { + $oldGroup = trim($oldGroup); + $newGroup = trim($newGroup); + $content1 = "[groups]\n"; + $content2 = ""; + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (!empty($temp1)) { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + $groupContent = ""; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + //处理左值 + if ($groupStr == $oldGroup) { + $groupStr = $newGroup; + } + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + //处理右值 + foreach ($userGroupArray as $key => $value) { + if ($value == "@$oldGroup") { + $userGroupArray[$key] = "@$newGroup"; + break; + } + } + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + $content1 .= $groupContent; + } + } else { + return '0'; + } + $content2 = preg_replace("/(^@" . $oldGroup . "[\s]*)=/m", "@$newGroup=", str_replace($authzContentPreg[0][0], '', $authzContent)); + return $content1 . $content2; + } + + /** + * 获取分组列表 + * + * 文件格式错误(不存在[groups]标识) + * 0 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => group1 + * [1] => group2 + * ) + */ + public static function GetSvnGroupList($authzContent) + { + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + return $resultPreg[1]; + } + } else { + return '0'; + } + } + + /** + * 获取某个分组所在的分组列表 + * + * 文件格式错误(不存在[groups]标识) + * 0 + * + * 分组不存在 + * 1 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => group1 + * [1] => group2 + * ) + */ + public static function GetSvnGroupGroupList($authzContent, $groupName) + { + $groupName = trim($groupName); + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $groupArray = []; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + if (in_array("@$groupName", $userGroupArray)) { + array_push($groupArray, $groupStr); + } + } + return $groupArray; + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 获取某个分组下的所有用户列表 + * + * 文件格式错误(不存在[groups]标识) + * 0 + * + * 分组不存在 + * 1 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => user1 + * [1] => user2 + * ) + */ + public static function GetSvnUserListByGroup($authzContent, $groupName) + { + $groupName = trim($groupName); + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $userGroupStr = array_combine($resultPreg[1], $resultPreg[2])[$groupName]; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + $userArray = []; + foreach ($userGroupArray as $key => $value) { + if (substr($value, 0, 1) != '@') { + array_push($userArray, $value); + } + } + return $userArray; + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 获取某个分组下的所有分组列表 + * + * 文件格式错误(不存在[groups]标识) + * 0 + * + * 分组不存在 + * 1 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => group1 + * [1] => group2 + * ) + */ + public static function GetSvnGroupListByGroup($authzContent, $groupName) + { + $groupName = trim($groupName); + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $userGroupStr = array_combine($resultPreg[1], $resultPreg[2])[$groupName]; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + $groupArray = []; + foreach ($userGroupArray as $key => $value) { + if (substr($value, 0, 1) == '@') { + array_push($groupArray, substr($value, 1)); + } + } + return $groupArray; + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 获取分组列表以及每个分组包含的用户列表和分组列表 + * + * 文件格式错误(不存在[groups]标识) + * 0 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [groupName] => commonAdmin + * [include] => Array + * ( + * [users] => Array + * ( + * [0] => Hachi + * [1] => taosir + * ) + * [groups] => Array + * ( + * ) + * ) + * ) + * [1] => Array + * ( + * [groupName] => g1 + * [include] => Array + * ( + * [users] => Array + * ( + * [0] => Hachi + * ) + * [groups] => Array + * ( + * [0] => superAdmin + * [1] => commonAdmin + * ) + * ) + * ) + * ) + */ + public static function GetSvnGroupUserAndGroupList($authzContent) + { + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $userArray = []; + $groupArray = []; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); //解决 key=value 中 value 为空的匹配的bug + array_walk($userGroupArray, 'FunArrayValueTrim'); + foreach ($userGroupArray as $key => $value) { + substr($value, 0, 1) == '@' ? array_push($groupArray, substr($value, 1, strlen($value) - 1)) : array_push($userArray, $value); + } + array_push($result, [ + 'groupName' => $groupStr, + 'include' => [ + 'users' => $userArray, + 'groups' => $groupArray + ] + ]); + } + return $result; + } + } else { + return '0'; + } + } + + /** + * 为分组添加用户 + * + * 0 文件格式错误(不存在[groups]标识) + * 1 分组不存在 + * 2 要添加的用户已存在该分组 + * string 正常 + */ + public static function AddSvnGroupUser($authzContent, $groupName, $userName) + { + $groupName = trim($groupName); + $userName = trim($userName); + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $groupContent = "[groups]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + if ($groupStr == $groupName) { + if (in_array($userName, $userGroupArray)) { + return '2'; + } + array_push($userGroupArray, $userName); + } + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 从分组删除用户 + * + * 0 文件格式错误(不存在[groups]标识) + * 1 分组不存在 + * 2 要删除的用户不在该分组 + * string 正常 + */ + public static function DelSvnGroupUser($authzContent, $groupName, $userName) + { + $groupName = trim($groupName); + $userName = trim($userName); + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $groupContent = "[groups]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + if ($groupStr == $groupName) { + if (in_array($userName, $userGroupArray)) { + unset($userGroupArray[array_search($userName, $userGroupArray)]); + } else { + return '2'; + } + } + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 为分组添加分组 + * + * 0 文件格式错误(不存在[groups]标识) + * 1 分组不存在 + * 2 要添加的分组已存在该分组 + * 3 不能添加本身 + * string 正常 + */ + public static function AddSvnGroupGroup($authzContent, $groupName, $groupName2) + { + $groupName = trim($groupName); + $groupName2 = trim($groupName2); + if ($groupName == $groupName2) { + return '3'; + } + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $groupContent = "[groups]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + if ($groupStr == $groupName) { + if (in_array("@$groupName2", $userGroupArray)) { + return '2'; + } + array_push($userGroupArray, "@$groupName2"); + } + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 从分组删除分组 + * + * 0 文件格式错误(不存在[groups]标识) + * 1 分组不存在 + * 2 要删除的分组不在该分组 + * string 正常 + */ + public static function DelSvnGroupGroup($authzContent, $groupName, $groupName2) + { + $groupName = trim($groupName); + $groupName2 = trim($groupName2); + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + if (in_array($groupName, $resultPreg[1])) { + $groupContent = "[groups]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + if ($groupStr == $groupName) { + if (in_array("@$groupName2", $userGroupArray)) { + unset($userGroupArray[array_search("@$groupName2", $userGroupArray)]); + } else { + return '2'; + } + } + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 获取某个分组有权限的仓库列表 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => rep1 + * [1] => rep2 + * ) + */ + public static function GetGroupPriRepListWithoutPri($authzContent, $groupName) + { + $groupName = trim($groupName); + preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + return $authzContentPreg[1]; + } else { + return []; + } + } + + /** + * 获取某个分组有权限的仓库列表以及对应的权限 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [repName] => rep1 + * [repPri] => rw + * ) + * [1] => Array + * ( + * [repName] => rep2 + * [repPri] => rw + * ) + * ) + */ + public static function GetGroupPriRepListWithPri($authzContent, $groupName) + { + $groupName = trim($groupName); + preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + array_walk($authzContentPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { + $item = []; + $item['repName'] = $key; + $item['repPri'] = $value; + array_push($result, $item); + } + return $result; + } else { + return []; + } + } + + /** + * 获取某个分组有权限的仓库列表以及对应的权限 + */ + public static function GetGroupPriRepListWithPriAndPath($authzContent, $groupName) + { + $groupName = trim($groupName); + preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + array_walk($authzContentPreg[2], 'FunArrayValueTrim'); + array_walk($authzContentPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach ($authzContentPreg[1] as $key => $value) { + array_push($result, [ + 'repName' => $value, + 'priPath' => $authzContentPreg[2][$key], + 'repPri' => $authzContentPreg[3][$key], + 'unique' => $value . ':' . $authzContentPreg[2][$key] . $authzContentPreg[3][$key] + ]); + } + return $result; + } else { + return []; + } + } +} diff --git a/02.php/app/util/SVNHooks.util.php b/02.php/app/util/SVNHooks.util.php new file mode 100644 index 0000000..e9a41d5 --- /dev/null +++ b/02.php/app/util/SVNHooks.util.php @@ -0,0 +1,14 @@ + $bindPort == '' ? '3690' : $bindPort, + 'bindHost' => $bindHost == '' ? '0.0.0.0' : $bindHost, + 'manageHost' => '127.0.0.1', + 'enable' => $bindHost == '' ? 'manageHost' : 'bindHost' + ]) . '\' > ' . LISTEN_FILE); + } else { + //更新内容 + $listenArray = json_decode($listenContent, true); + if ($listenArray['bindPort'] != $bindPort) { + $listenArray['bindPort'] = $bindPort == '' ? '3690' : $bindHost; + } + if ($listenArray['bindHost'] != $bindHost) { + $listenArray['bindHost'] = $bindHost == '' ? '0.0.0.0' : $bindHost; + } + FunShellExec('echo \'' . json_encode([ + 'bindPort' => $listenArray['bindPort'], + 'bindHost' => $listenArray['bindHost'], + 'manageHost' => $listenArray['manageHost'] == '' ? '127.0.0.1' : $listenArray['manageHost'], + 'enable' => $listenArray['enable'] + ]) . '\' > ' . LISTEN_FILE); + } + + $listenContent = FunShellExec('cat ' . LISTEN_FILE); + $listenArray = json_decode($listenContent, true); + + return [ + 'bindPort' => $listenArray['bindPort'], + 'bindHost' => $listenArray['bindHost'], + 'manageHost' => $listenArray['manageHost'], + 'enable' => $listenArray['enable'], + ]; + } +} diff --git a/02.php/app/util/SVNRep.util.php b/02.php/app/util/SVNRep.util.php new file mode 100644 index 0000000..e904380 --- /dev/null +++ b/02.php/app/util/SVNRep.util.php @@ -0,0 +1,1303 @@ + u1 + * [1] => u2 + * ) + */ + public static function GetRepUserListWithoutPri($authzContent, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + return $resultPreg[1]; + } + } else { + return '0'; + } + } + + /** + * 获取某个仓库路径下有权限的用户列表以及对应的权限 + * + * 不存在该仓库路径的记录 + * 0 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [userName] => rep1 + * [userPri] => r + * ) + * [1] => Array + * ( + * [userName] => rep2 + * [userPri] => + * ) + * ) + */ + public static function GetRepUserListWithPri($authzContent, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + $result = []; + //注意$value的值 不限于合法的 r 、rw、空 以及不合法的其它字符 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $key => $value) { + $item = []; + $item['userName'] = $key; + $item['userPri'] = $value; + array_push($result, $item); + } + return $result; + } + } else { + return '0'; + } + } + + /** + * 获取某个仓库路径下有权限的分组列表 + * + * 不存在该仓库路径的记录 + * 0 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => g1 + * [1] => g2 + * ) + */ + public static function GetRepGroupListWithoutPri($authzContent, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + return $resultPreg[1]; + } + } else { + return '0'; + } + } + + /** + * 获取某个仓库路径下有权限的分组列表以及对应的权限 + * + * 不存在该仓库路径的记录 + * 0 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [groupName] => rep1 + * [groupPri] => rw + * ) + * [1] => Array + * ( + * [groupName] => rep2 + * [groupPri] => rw + * ) + * ) + */ + public static function GetRepGroupListWithPri($authzContent, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $key => $value) { + $item = []; + $item['groupName'] = $key; + $item['groupPri'] = $value; + array_push($result, $item); + } + return $result; + } + } else { + return '0'; + } + } + + /** + * 为某个仓库路径设置用户权限 + * 包括为已有权限的用户修改权限 + * 包括为没有权限的用户增加权限 + * 如果该目录的该用户的父目录有权限 那么所有子目录继承权限 + * + * 0 不存在该仓库路径的记录 + * string 正常 + */ + public static function SetRepUserPri($authzContent, $user, $privilege, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + //添加用户 + return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n$user=$privilege\n", $authzContent); + } else { + //进一步判断有没有用户数据 + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + + //处理分组 + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); + array_walk($resultPregGroup[1], 'FunArrayValueTrim'); + array_walk($resultPregGroup[2], 'FunArrayValueTrim'); + + if (in_array($user, $resultPreg[1])) { + //编辑 + $userContent = "[$repName:$repPath]\n"; + + //处理分组 + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + $userContent .= "@$groupStr=$groupPri\n"; + } + + //处理用户 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + if ($userStr == $user) { + $userContent .= "$userStr=$privilege\n"; + } else { + $userContent .= "$userStr=$userPri\n"; + } + } + + return str_replace($authzContentPreg[0][0], $userContent, $authzContent); + } else { + //新增 + $userContent = "[$repName:$repPath]\n"; + + //处理分组 + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + $userContent .= "@$groupStr=$groupPri\n"; + } + + //处理用户 + $userContent .= "$user=$privilege\n"; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + $userContent .= "$userStr=$userPri\n"; + } + return str_replace($authzContentPreg[0][0], $userContent, $authzContent); + } + } + } else { + return '0'; + } + } + + /** + * 删除某个仓库路径的用户权限 + * 父目录有权限 无法取消子目录的权限 + * + * 0 不存在该仓库路径的记录 + * 1 已删除 + * string 正常 + */ + public static function DelRepUserPri($authzContent, $user, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + //进一步判断有没有用户数据 + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + + //处理分组 + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); + array_walk($resultPregGroup[1], 'FunArrayValueTrim'); + array_walk($resultPregGroup[2], 'FunArrayValueTrim'); + + if (in_array($user, $resultPreg[1])) { + //删除 + $userContent = "[$repName:$repPath]\n"; + + //处理分组 + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + $userContent .= "@$groupStr=$groupPri\n"; + } + + //处理用户 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + if ($userStr == $user) { + continue; + } + $userContent .= "$userStr=$userPri\n"; + } + + return str_replace($authzContentPreg[0][0], $userContent, $authzContent); + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 修改某个仓库路径的用户权限 + * + * 0 不存在该仓库路径的记录 + * string 正常 + */ + public static function UpdRepUserPri($authzContent, $user, $privilege, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n$user=$privilege\n", $authzContent); + } else { + //进一步判断有没有用户数据 + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + + //处理分组 + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); + array_walk($resultPregGroup[1], 'FunArrayValueTrim'); + array_walk($resultPregGroup[2], 'FunArrayValueTrim'); + + //编辑 + $userContent = "[$repName:$repPath]\n"; + + //处理分组 + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + $userContent .= "@$groupStr=$groupPri\n"; + } + + //处理用户 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + if ($userStr == $user) { + $userContent .= "$userStr=$privilege\n"; + } else { + $userContent .= "$userStr=$userPri\n"; + } + } + return str_replace($authzContentPreg[0][0], $userContent, $authzContent); + } + } else { + return '0'; + } + } + + /** + * 为某个仓库路径设置分组权限 + * 包括为已有权限的分组修改权限 + * 包括为没有权限的分组增加权限 + * 其中如果分组和用户都设置了权限 但是权限一个为可读 一个为可写 应该遵循什么规则呢 开发者无需考虑 + * + * 0 不存在该仓库路径的记录 + * string 正常 + */ + public static function SetRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n@$group=$privilege\n", $authzContent); + } else { + //进一步判断有没有分组数据 + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); + array_walk($resultPregGroup[1], 'FunArrayValueTrim'); + array_walk($resultPregGroup[2], 'FunArrayValueTrim'); + + //处理用户 + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + + if (in_array($group, $resultPregGroup[1])) { + //编辑 + $groupContent = "[$repName:$repPath]\n"; + + //处理分组 + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + if ($groupStr == $group) { + $groupContent .= "@$group=$privilege\n"; + } else { + $groupContent .= "@$groupStr=$groupPri\n"; + } + } + + //处理用户 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + $groupContent .= "$userStr=$userPri\n"; + } + + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } else { + //新增 + $groupContent = "[$repName:$repPath]\n"; + + //处理分组 + $groupContent .= "@$group=$privilege\n"; + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + $groupContent .= "@$groupStr=$groupPri\n"; + } + + //处理用户 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + $groupContent .= "$userStr=$userPri\n"; + } + + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } + } + } else { + return '0'; + } + } + + /** + * 删除某个仓库的分组权限 + * + * 0 不存在该仓库路径的记录 + * 1 已删除 + * string 正常 + */ + public static function DelRepGroupPri($authzContent, $group, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + //进一步判断有没有分组数据 + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); + array_walk($resultPregGroup[1], 'FunArrayValueTrim'); + array_walk($resultPregGroup[2], 'FunArrayValueTrim'); + + //处理用户 + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + + if (in_array($group, $resultPregGroup[1])) { + //编辑 + $groupContent = "[$repName:$repPath]\n"; + + //处理分组 + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + if ($groupStr == $group) { + continue; + } else { + $groupContent .= "@$groupStr=$groupPri\n"; + } + } + + //处理用户 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + $groupContent .= "$userStr=$userPri\n"; + } + + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 修改某个仓库路径的分组权限 + * + * 0 不存在该仓库路径的记录 + * 1 该仓库下不存在该分组 + * string 正常 + */ + public static function UpdRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return str_replace($authzContentPreg[0][0], "[$repName:$repPath]\n@$group=$privilege\n", $authzContent); + } else { + //进一步判断有没有分组数据 + preg_match_all(REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); + array_walk($resultPregGroup[1], 'FunArrayValueTrim'); + array_walk($resultPregGroup[2], 'FunArrayValueTrim'); + + //处理用户 + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + + if (in_array($group, $resultPregGroup[1])) { + //编辑 + $groupContent = "[$repName:$repPath]\n"; + + //处理分组 + foreach (array_combine($resultPregGroup[1], $resultPregGroup[2]) as $groupStr => $groupPri) { + if ($groupStr == $group) { + $groupContent .= "@$group=$privilege\n"; + } else { + $groupContent .= "@$groupStr=$groupPri\n"; + } + } + + //处理用户 + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $userStr => $userPri) { + $groupContent .= "$userStr=$userPri\n"; + } + + return str_replace($authzContentPreg[0][0], $groupContent, $authzContent); + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 向配置文件写入仓库路径 + * + * 1 已存在 + * string 正常 + */ + public static function SetRepAuthz($authzContent, $repName, $repPath) + { + //处理路径结尾 + if ($repPath != '/') { + if (substr($repPath, strlen($repPath) - 1, 1) == '/') { + $repPath = substr($repPath, 0, strlen($repPath) - 1); + } + } + + preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITHOUT_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + return '1'; + } else { + return $authzContent . "\n[$repName:$repPath]\n"; + } + } + + /** + * 从配置文件删除指定仓库的所有路径 + * + * 1 已删除 + * string 正常 + */ + public static function DelRepAuthz($authzContent, $repName) + { + preg_match_all(sprintf(REG_AUTHZ_REP_ALL_PATH_WITH_CON, $repName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + foreach ($authzContentPreg[0] as $key => $value) { + $authzContent = str_replace($value, "", $authzContent); + } + return $authzContent; + } else { + return '1'; + } + } + + /** + * 从配置文件获取所有的仓库名称 + * + * 不匹配这些仓库的内容和具体路径 + * + * 空列表 + * [] + * + * 正常数据 + * + */ + public static function GetNoPathAndConRepAuthz($authzContent) + { + preg_match_all(REG_AUTHZ_ALL_REP_WITHOUT_PATH_AND_CON, $authzContent, $authzContentPreg); + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + return array_values(array_unique($authzContentPreg[1])); + } + + /** + * 从配置文件修改仓库名称 + * 修改该仓库所有路径的仓库名称 + * + * 没有校验要修改的仓库是否已经存在 需要上层函数进行校验 + * + * 1 仓库不存在 + * string 正常 + */ + public static function UpdRepAuthz($authzContent, $oldRepName, $newRepName) + { + preg_match_all(sprintf(REG_AUTHZ_REP_ALL_PATH_WITHOUT_CON, $oldRepName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + foreach ($authzContentPreg[0] as $key => $value) { + $authzContent = str_replace($value, '[' . $newRepName . ':' . $authzContentPreg[1][$key] . ']', $authzContent); + } + return $authzContent; + } else { + return '1'; + } + } + + /** + * 获取所有用户都有权限的仓库列表带有权限(包括只读、读写) + * 用户匹配 *=r *=rw + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [repName] => rep1 + * [repPri] => rw + * ) + * [1] => Array + * ( + * [repName] => rep2 + * [repPri] => r + * ) + * ) + */ + public static function GetAllHavePriRepListWithPri($authzContent) + { + $userName = '*'; + preg_match_all(sprintf(REG_AUTHZ_ALL_HAVE_PRI_REPS, $userName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + array_walk($authzContentPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { + $item = []; + $item['repName'] = $key; + $item['repPri'] = $value; + array_push($result, $item); + } + return $result; + } else { + return []; + } + } + + /** + * 获取所有用户都有权限的仓库列表(包括只读、读写) + * 用户匹配 *=r *=rw + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => rep1 + * [1] => rep2 + * ) + */ + public static function GetAllHavePriRepListWithoutPri($authzContent) + { + $userName = '*'; + preg_match_all(sprintf(REG_AUTHZ_ALL_HAVE_PRI_REPS, $userName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + array_walk($authzContentPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { + array_push($result, $key); + } + return $result; + } else { + return []; + } + } + + /** + * 获取所有用户都无权限的仓库列表 + * 用户匹配 *= + */ + public static function GetAllNoPriRepListWithoutPri($authzContent) + { + $userName = '*'; + preg_match_all(sprintf(REG_AUTHZ_ALL_NO_PRI_REPS, $userName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + array_walk($authzContentPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { + if ($value == '') { + array_push($result, $key); + } + } + return $result; + } else { + return []; + } + } + + /** + * 获取SVN仓库列表 + */ + public static function GetRepList() + { + $repArray = []; + $file_arr = scandir(SVN_REPOSITORY_PATH); + foreach ($file_arr as $file_item) { + if ($file_item != '.' && $file_item != '..') { + if (is_dir(SVN_REPOSITORY_PATH . $file_item)) { + $file_arr2 = scandir(SVN_REPOSITORY_PATH . $file_item); + foreach ($file_arr2 as $file_item2) { + if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { + array_push($repArray, array( + 'repName' => $file_item, + 'repUrl' => SVN_REPOSITORY_PATH . $file_item, + 'repSize' => round(FunGetDirSize(SVN_REPOSITORY_PATH . $file_item) / (1024 * 1024), 2), + 'repCheckoutUrl' => 'svn://' . 'SERVER_DOMAIN' . '/' . $file_item, + )); + break; + } + } + } + } + } + return $repArray; + } + + /** + * 获取简单SVN仓库列表 + */ + public static function GetSimpleRepList() + { + $repArray = []; + $file_arr = scandir(SVN_REPOSITORY_PATH); + foreach ($file_arr as $file_item) { + if ($file_item != '.' && $file_item != '..') { + if (is_dir(SVN_REPOSITORY_PATH . $file_item)) { + $file_arr2 = scandir(SVN_REPOSITORY_PATH . $file_item); + foreach ($file_arr2 as $file_item2) { + if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { + array_push($repArray, $file_item); + break; + } + } + } + } + } + return $repArray; + } + + /** + * 初始化仓库结构为 trunk branches tags + */ + public static function InitRepStruct($repName, $initUser = "SVNAdmin", $initPass = "SVNAdmin") + { + $randPrefix = FunGetRandStr(); + $tempPath = TEMP_PATH . $randPrefix; + $repPath = SVN_REPOSITORY_PATH . $repName; + + $tempMkdirCmd = sprintf("mkdir -p %s", $tempPath); + $svnCheckoutCmd = sprintf("svn checkout file:///%s --quiet --username %s --password %s %s", $repPath, $initUser, $initPass, $tempPath); + $repMkdirCmd = sprintf("mkdir -p %s/{trank/,branches/,tags/}", $tempPath); + $svnAddCmd = sprintf("svn add --quiet --username %s --password %s %s/*", $initUser, $initPass, $tempPath); + $svnCommitCmd = sprintf("svn commit --quiet --username %s --password %s --message 'Initial structure' %s/*", $initUser, $initPass, $tempPath); + $delDirCmd = sprintf("rm -rf %s", $tempPath); + + $cmd = implode(';', [$tempMkdirCmd, $svnCheckoutCmd, $repMkdirCmd, $svnAddCmd, $svnCommitCmd, $delDirCmd]); + + FunShellExec($cmd); + } + + /** + * 使用 svnadmin info $repPath 获取部分仓库信息 + * UUID + * Revisions + * Repository Format + * Compatible With Version + * Repository Capability + * Filesystem Type + * Filesystem Format + * FSFS Sharded + * FSFS Shard Size + * FSFS Shards Packed + * FSFS Logical Addressing + */ + public static function GetRepInfo($repName) + { + $repPath = SVN_REPOSITORY_PATH . $repName; + + $svnadminInfoCmd = sprintf("svnadmin info '%s'", $repPath); + + $cmdResult = FunShellExec($svnadminInfoCmd); + + preg_match_all(REG_REP_INFO, $cmdResult, $svnadminInfoPreg); + + $svnadminInfoResult = array_combine($svnadminInfoPreg[1], $svnadminInfoPreg[2]); + + unset($svnadminInfoResult['Path'], $svnadminInfoResult['Configuration File']); + + return $svnadminInfoResult; + } + + /** + * 使用 svnlook tree $repPath 获取仓库的最新版本的目录树 + */ + public static function GetRepTree($repName) + { + $repPath = SVN_REPOSITORY_PATH . $repName; + $svnadminInfoCmd = sprintf("svnlook tree '%s'", $repPath); + $cmdResult = FunShellExec($svnadminInfoCmd); + // $cmdResult = shell_exec($svnadminInfoCmd); + $treeArray = explode("\n", $cmdResult); + //去除数组中的空字符串键值 通常为最后一项 + $treeArray = array_filter($treeArray, 'FunArrayValueFilter'); + //获取对应空格数开头的数组 + $spaceCountArray = array_map('FunArrayGetStrSpaceCount', $treeArray); + //获取是否为目录或者文件的数组 + $isFolderArray = array_map('FunArrayIsStrFolder', $treeArray); + //合并数组 + $complateArray = []; + foreach ($treeArray as $key => $value) { + array_push($complateArray, array( + 'content' => trim($value), + 'spaceCount' => $spaceCountArray[$key], + 'isFolder' => $isFolderArray[$key] + )); + } + //拼接根目录 + return [ + [ + 'title' => '/', + 'expand' => true, + 'children' => self::GetFolderStruct($complateArray, 0) + ] + ]; + } + + /** + * 按照指定的数据结构以递归方式拼接目录结构 + * + * 示例输入以下数组和0 + * Array + * ( + * [0] => Array + * ( + * [content] => / + * [spaceCount] => 0 + * [isFolder] => 1 + * ) + * [1] => Array + * ( + * [content] => 00.folder/ + * [spaceCount] => 1 + * [isFolder] => 1 + * ) + * [2] => Array + * ( + * [content] => 001.jpg + * [spaceCount] => 2 + * [isFolder] => 0 + * ) + * [3] => Array + * ( + * [content] => 01.folder/ + * [spaceCount] => 1 + * [isFolder] => 1 + * ) + * [4] => Array + * ( + * [content] => 011.folder/ + * [spaceCount] => 2 + * [isFolder] => 1 + * ) + * [5] => Array + * ( + * [content] => 02.folder/ + * [spaceCount] => 1 + * [isFolder] => 1 + * ) + * [6] => Array + * ( + * [content] => 021.folder/ + * [spaceCount] => 2 + * [isFolder] => 1 + * ) + * [7] => Array + * ( + * [content] => 0211.file.docx + * [spaceCount] => 3 + * [isFolder] => 0 + * ) + * [8] => Array + * ( + * [content] => 03.jpg + * [spaceCount] => 1 + * [isFolder] => 0 + * ) + * ) + * + * 示例输出 + * Array + * ( + * [0] => Array + * ( + * [title] => 00.folder/ + * [children] => Array + * ( + * [0] => Array + * ( + * [title] => 001.jpg + * ) + * ) + * ) + * [1] => Array + * ( + * [title] => 01.folder/ + * [children] => Array + * ( + * [0] => Array + * ( + * [title] => 011.folder/ + * ) + * ) + * ) + * [2] => Array + * ( + * [title] => 02.folder/ + * [children] => Array + * ( + * [0] => Array + * ( + * [title] => 021.folder/ + * [children] => Array + * ( + * [0] => Array + * ( + * [title] => 0211.file.docx + * ) + * ) + * ) + * ) + * ) + * [3] => Array + * ( + * [title] => 03.jpg + * ) + * ) + */ + public static function GetFolderStruct($complateArray, $fileIndex) + { + //获取当前文件夹的目录内容 以子文件夹和子文件下标的形式返回 + $dirContent = self::GetFolderDirAndFiles($complateArray, $fileIndex); + + //按照特定结构拼接 + $result = []; + foreach ($dirContent as $key => $value) { + $children = self::GetFolderStruct($complateArray, $value); + if ($children == []) { + array_push($result, array( + 'title' => $complateArray[$value]['content'], + 'expand' => true, + )); + } else { + array_push($result, array( + 'title' => $complateArray[$value]['content'], + 'expand' => true, + 'children' => $children + )); + } + } + return $result; + } + + /** + * 模拟正常的文件系统 获取指定目录或者文件的子文件夹和子文件(文件会返回空) + * + * 示例输入(只用到spaceCount键值)以下数组和0 + * Array + * ( + * [0] => Array + * ( + * [content] => / + * [spaceCount] => 0 + * [isFolder] => 1 + * ) + * [1] => Array + * ( + * [content] => 00.folder/ + * [spaceCount] => 1 + * [isFolder] => 1 + * ) + * [2] => Array + * ( + * [content] => 001.jpg + * [spaceCount] => 2 + * [isFolder] => 0 + * ) + * [3] => Array + * ( + * [content] => 01.folder/ + * [spaceCount] => 1 + * [isFolder] => 1 + * ) + * [4] => Array + * ( + * [content] => 011.folder/ + * [spaceCount] => 2 + * [isFolder] => 1 + * ) + * [5] => Array + * ( + * [content] => 02.folder/ + * [spaceCount] => 1 + * [isFolder] => 1 + * ) + * [6] => Array + * ( + * [content] => 021.folder/ + * [spaceCount] => 2 + * [isFolder] => 1 + * ) + * [7] => Array + * ( + * [content] => 0211.file.docx + * [spaceCount] => 3 + * [isFolder] => 0 + * ) + * [8] => Array + * ( + * [content] => 03.jpg + * [spaceCount] => 1 + * [isFolder] => 0 + * ) + * ) + * + * 示例输出 + * Array + * ( + * [0] => 1 + * [1] => 3 + * [2] => 5 + * [3] => 8 + * ) + */ + public static function GetFolderDirAndFiles($complateArray, $fileIndex) + { + $result = []; + //末尾 + if (!array_key_exists($fileIndex + 1, $complateArray)) { + return []; + } + //无子节点 + if ($complateArray[$fileIndex]['spaceCount'] == $complateArray[$fileIndex + 1]['spaceCount']) { + return []; + } + //有子节点 + foreach ($complateArray as $key => $value) { + if ($key > $fileIndex) { + //遇到同级目录退出 + //遇到上级目录退出 + if ($complateArray[$key]['spaceCount'] <= $complateArray[$fileIndex]['spaceCount']) { + break; + } + //遇到下级目录push + if ($complateArray[$key]['spaceCount'] == $complateArray[$fileIndex]['spaceCount'] + 1) { + array_push($result, $key); + } + } + } + return $result; + } + + + /** + * 检查仓库是否存在或者是否存在同名的文件夹 + */ + public static function CheckRepExist($repName, $message = '仓库已经存在') + { + clearstatcache(); + if (is_dir(SVN_REPOSITORY_PATH . $repName)) { + FunMessageExit(200, 0, $message); + } + } + + /** + * 检查仓库是否创建成功 + */ + public static function CheckRepCreate($repName, $message = '仓库创建失败') + { + clearstatcache(); + if (!is_dir(SVN_REPOSITORY_PATH . $repName)) { + FunMessageExit(200, 0, $message); + } + } + + /** + * 检查仓库是否删除成功 + */ + public static function CheckRepDelete($repName, $message = '仓库删除失败') + { + clearstatcache(); + if (is_dir(SVN_REPOSITORY_PATH . $repName)) { + FunMessageExit(200, 0, $message); + } + } + + /** + * 获取仓库的修订版本数量 + */ + public static function GetRepRev($repName) + { + $cmd = sprintf("svnadmin info '%s' | grep 'Revisions' | awk '{print $2}'", SVN_REPOSITORY_PATH . $repName); + return (int)trim(FunShellExec($cmd)); + } + + /** + * 获取仓库的属性内容(key-vlaue的形式) + */ + public static function GetRepDetail($repName) + { + $cmd = sprintf("svnadmin info '%s'", SVN_REPOSITORY_PATH . $repName); + return trim(FunShellExec($cmd)); + } + + /** + * 获取仓库下某个文件的体积 + * + * 目前为默认最新版本 + * + * 根据体积大小自动调整单位 + */ + public static function GetRepRevFileSize($repName, $filePath) + { + $cmd = sprintf("svnlook filesize '%s' '%s'", SVN_REPOSITORY_PATH . $repName, $filePath); + $size = (int)trim(FunShellExec($cmd)); + return FunFormatSize($size); + } + + /** + * 获取仓库下指定文件或者文件夹的最高修订版本 + */ + public static function GetRepFileRev($repName, $filePath) + { + $cmd = sprintf("svnlook history --limit 1 '%s' '%s'", SVN_REPOSITORY_PATH . $repName, $filePath); + $result = FunShellExec($cmd); + $resultArray = explode("\n", trim($result)); + $content = preg_replace("/\s{2,}/", ' ', $resultArray[2]); + $contentArray = explode(' ', $content); + return trim($contentArray[1]); + } + + /** + * 获取仓库下指定文件或者文件夹的作者 + */ + public static function GetRepFileAuthor($repName, $rev) + { + $cmd = sprintf("svnlook author -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); + $result = FunShellExec($cmd); + return trim($result); + } + + /** + * 获取仓库下指定文件或者文件夹的提交日期 + */ + public static function GetRepFileDate($repName, $rev) + { + $cmd = sprintf("svnlook date -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); + $result = FunShellExec($cmd); + return trim($result); + } + + /** + * 获取仓库下指定文件或者文件夹的提交日志 + */ + public static function GetRepFileLog($repName, $rev) + { + $cmd = sprintf("svnlook log -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); + $result = FunShellExec($cmd); + return trim($result); + } + + /** + * 使用 svnadmin dump 备份仓库 + * + * 默认为全版本 + */ + public static function RepDump($repName, $backupName) + { + $cmd = sprintf('svnadmin dump %s --quiet > %s', SVN_REPOSITORY_PATH . $repName, SVN_BACHUP_PATH . $backupName); + FunShellExec($cmd); + } + + /** + * 删除备份文件 + */ + public static function DelRepBackup($fileName) + { + $cmd = sprintf("cd '%s' && rm -f './%s'", SVN_BACHUP_PATH, $fileName); + FunShellExec($cmd); + } + + /** + * 使用 svnadmin load 导入仓库 + */ + public static function RepLoad($repName, $fileName) + { + $cmd = sprintf("svnadmin load --quiet '%s' < '%s'", SVN_REPOSITORY_PATH . $repName, SVN_BACHUP_PATH . $fileName); + $result = FunShellExec($cmd); + return trim($result); + } + + /** + * 使用 svn list 为用户检查指令 + */ + public static function CheckSvnUserPathAutzh($checkoutHost, $repName, $repPath, $svnUserName, $svnUserPass) + { + $cmd = sprintf("svn list '%s' --username '%s' --password '%s' --no-auth-cache --non-interactive --trust-server-cert", $checkoutHost . '/' . $repName . $repPath, $svnUserName, $svnUserPass); + $result = FunShellExec($cmd); + if (strstr($result, 'svn: E170001: Authentication error from server: Password incorrect')) { + //密码错误 + return false; + } + if (strstr($result, 'svn: E170001: Authorization failed')) { + //没有权限 + return false; + } + if (strstr($result, 'svn: E170013: Unable to connect to a repository at URL')) { + //其它错误 + return false; + } + return true; + } +} diff --git a/02.php/app/util/SVNUser.util.php b/02.php/app/util/SVNUser.util.php new file mode 100644 index 0000000..3ba93ef --- /dev/null +++ b/02.php/app/util/SVNUser.util.php @@ -0,0 +1,560 @@ + $value) { + $resultStr .= "$key=$value\n"; + } + $resultStr .= "$userName=$userPass\n"; + return $resultStr; + } + } else { + return '0'; + } + } + + /** + * 修改SVN用户(passwd文件中) + */ + public static function UpdSvnUserPasswd($passwdContent, $oldUserName, $newUserName) + { + //不提供此方法 + } + + /** + * 删除SVN用户 + * + * 0 文件格式错误(不存在[users]标识) + * 1 用户不存在 + * string 正常 + */ + public static function DelSvnUserPasswd($passwdContent, $userName, $isDisabledUser = false) + { + $userName = trim($userName); + $userName = $isDisabledUser ? (REG_SVN_USER_DISABLED . $userName) : $userName; + preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + if (array_key_exists(0, $passwdContentPreg[1])) { + $temp1 = trim($passwdContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[3], 'FunArrayValueTrim'); + if (in_array($userName, $resultPreg[1])) { + $resultStr = "[users]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { + if ($key == $userName) { + continue; + } + $resultStr .= "$key=$value\n"; + } + return $resultStr; + } + return '1'; + } + } else { + return '0'; + } + } + + /** + * 获取SVN用户列表 + * + * 文件格式错误(不存在[users]标识) + * 0 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [userName] => u1 + * [disabled] => 1 + * ) + * + * [1] => Array + * ( + * [userName] => u2 + * [disabled] => 0 + * ) + * + * ) + */ + public static function GetSvnUserList($passwdContent) + { + preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + if (array_key_exists(0, $passwdContentPreg[1])) { + $temp1 = trim($passwdContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + $result = []; + foreach ($resultPreg[1] as $value) { + $item = []; + if (substr($value, 0, strlen(REG_SVN_USER_DISABLED)) == REG_SVN_USER_DISABLED) { + $item['userName'] = substr($value, strlen(REG_SVN_USER_DISABLED)); + $item['disabled'] = '1'; + } else { + $item['userName'] = $value; + $item['disabled'] = '0'; + } + array_push($result, $item); + } + return $result; + } + } else { + return '0'; + } + } + + /** + * 获取SVN用户以及密码列表 + * + * 文件格式错误(不存在[users]标识) + * 0 + * + * 空数据 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [userName] => u1 + * [userPass] => p1 + * [disabled] => 1 + * ) + * + * [1] => Array + * ( + * [userName] => u2 + * [userPass] => p2 + * [disabled] => 0 + * ) + * + * ) + */ + public static function GetSvnUserPassList($passwdContent) + { + preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + if (array_key_exists(0, $passwdContentPreg[1])) { + $tem1 = trim($passwdContentPreg[1][0]); + if (empty($tem1)) { + return []; + } else { + preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($resultPreg[1], $resultPreg[3]) as $userName => $userPass) { + $item = []; + if (substr($userName, 0, strlen(REG_SVN_USER_DISABLED)) == REG_SVN_USER_DISABLED) { + $item['userName'] = substr($userName, strlen(REG_SVN_USER_DISABLED)); + $item['userPass'] = $userPass; + $item['disabled'] = '1'; + } else { + $item['userName'] = $userName; + $item['userPass'] = $userPass; + $item['disabled'] = '0'; + } + array_push($result, $item); + } + return $result; + } + } else { + return '0'; + } + } + + /** + * 获取SVN指定用户的密码 + * + * 0 文件格式错误(不存在[users]标识) + * 1 用户不存在 + * string 正常 + */ + public static function GetPassByUser($passwdContent, $userName, $isDisabledUser = false) + { + $userName = trim($userName); + $userName = $isDisabledUser ? (REG_SVN_USER_DISABLED . $userName) : $userName; + preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + if (array_key_exists(0, $passwdContentPreg[1])) { + $temp1 = trim($passwdContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[3], 'FunArrayValueTrim'); + if (array_search($userName, $resultPreg[1]) !== false) { + return $resultPreg[3][array_search($userName, $resultPreg[1])]; + } else { + return '1'; + } + } + } else { + return '0'; + } + } + + /** + * 修改SVN指定用户的密码 + * + * 0 文件格式错误(不存在[users]标识) + * 1 用户不存在 + * string 正常 + */ + public static function UpdSvnUserPass($passwdContent, $userName, $userPass, $isDisabledUser = false) + { + $userName = trim($userName); + $userPass = trim($userPass); + $userName = $isDisabledUser ? (REG_SVN_USER_DISABLED . $userName) : $userName; + preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + if (array_key_exists(0, $passwdContentPreg[1])) { + $temp1 = trim($passwdContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[3], 'FunArrayValueTrim'); + if (in_array($userName, $resultPreg[1])) { + $resultStr = "[users]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { + if ($key == $userName) { + $value = $userPass; + } + $resultStr .= "$key=$value\n"; + } + return $resultStr; + } + return '1'; + } + } else { + return '0'; + } + } + + /** + * 获取某个用户所在的分组列表 + * $recursively = false 只获取用户与分组处于直接包含关系的分组列表 + * $recursively = true 获取用户与分组处于直接包含关系的分组列表、获取处于分组嵌套分组导致用户与分组处于间接包含关系的分组列表 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => goup1 + * [1] => group + * ) + */ + public static function GetSvnUserGroupList($authzContent, $userName) + { + $userName = trim($userName); + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[0])) { + $temp1 = trim($authzContentPreg[1][0]); + if (empty($temp1)) { + return []; + } else { + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + $userArray = []; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + if (in_array($userName, $userGroupArray)) { + array_push($userArray, $groupStr); + } + } + return $userArray; + } + } else { + return '0'; + } + } + + /** + * 获取某个用户有权限的所有仓库列表 + * + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => rep1 + * [1] => rep2 + * ) + */ + public static function GetUserPriRepListWithoutPri($authzContent, $userName) + { + $userName = trim($userName); + preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + return $authzContentPreg[1]; + } else { + return []; + } + } + + /** + * 获取某个用户有权限的所有仓库列表以及对应的权限 + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [repName] => rep1 + * [repPri] => rw + * ) + * [1] => Array + * ( + * [repName] => rep2 + * [repPri] => rw + * ) + * ) + */ + public static function GetUserPriRepListWithPri($authzContent, $userName) + { + $userName = trim($userName); + preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + array_walk($authzContentPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach (array_combine($authzContentPreg[1], $authzContentPreg[3]) as $key => $value) { + $item = []; + $item['repName'] = $key; + $item['repPri'] = $value; + array_push($result, $item); + } + return $result; + } else { + return []; + } + } + + /** + * 获取某个用户有权限的所有仓库列表(带有路径和权限) + * + * 空列表 + * [] + * + * 正常数据 + * Array + * ( + * [0] => Array + * ( + * [repName] => rep1 + * [priPath] => / + * [repPri] => rw + * ) + * [1] => Array + * ( + * [repName] => rep2 + * [priPath] => /branches/taoweitao/计划.md + * [repPri] => rw + * ) + * ) + */ + public static function GetUserPriRepListWithPriAndPath($authzContent, $userName) + { + $userName = trim($userName); + preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); + if (array_key_exists(0, $authzContentPreg[1])) { + array_walk($authzContentPreg[1], 'FunArrayValueTrim'); + array_walk($authzContentPreg[2], 'FunArrayValueTrim'); + array_walk($authzContentPreg[3], 'FunArrayValueTrim'); + $result = []; + foreach ($authzContentPreg[1] as $key => $value) { + array_push($result, [ + 'repName' => $value, + 'priPath' => $authzContentPreg[2][$key], + 'repPri' => $authzContentPreg[3][$key], + 'unique' => $value . ':' . $authzContentPreg[2][$key] . $authzContentPreg[3][$key] + ]); + } + return $result; + } else { + return []; + } + } + + /** + * 从所有仓库路径和分组下修改用户名 + * + * string 正常 + */ + public static function UpdUserAuthz($authzContent, $oldUserName, $newUserName) + { + } + + /** + * 从所有仓库路径和分组下删除SVN用户 + * 从所有分组中删除用户 + * 从所有仓库下删除用户 + * + * 0 文件格式错误(不存在[users]标识) + * string 正常 + */ + public static function DelUserAuthz($authzContent, $userName) + { + $userName = trim($userName); + $content1 = "[groups]\n"; + $content2 = ""; + preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg1); + if (array_key_exists(0, $authzContentPreg1[0])) { + $temp1 = trim($authzContentPreg1[1][0]); + if (!empty($temp1)) { + preg_match_all(REG_AUTHZ_USER_PRI, $authzContentPreg1[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[2], 'FunArrayValueTrim'); + $groupContent = ""; + foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $userGroupStr) { + $groupContent .= "$groupStr="; + $userGroupArray = $userGroupStr == '' ? [] : explode(',', $userGroupStr); + array_walk($userGroupArray, 'FunArrayValueTrim'); + if (in_array($userName, $userGroupArray)) { + unset($userGroupArray[array_search($userName, $userGroupArray)]); + } + $groupContent .= implode(',', $userGroupArray) . "\n"; + } + $content1 .= $groupContent; + } + } else { + return '0'; + } + $content2 = preg_replace("/([^@]^$userName" . "[\s]*=.*?)\n/m", "\n", str_replace($authzContentPreg1[0][0], '', $authzContent)); + return $content1 . $content2; + } + + /** + * 禁用某个SVN用户 + * 0 文件格式错误(不存在[users]标识) + * 1 要禁用的用户不存在 + * string 正常 + */ + public static function DisabledUser($passwdContent, $userName) + { + $userName = trim($userName); + preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + if (array_key_exists(0, $passwdContentPreg[1])) { + $temp1 = trim($passwdContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[3], 'FunArrayValueTrim'); + if (in_array($userName, $resultPreg[1])) { + $resultStr = "[users]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { + if ($key == $userName) { + $key = REG_SVN_USER_DISABLED . $key; + } + $resultStr .= "$key=$value\n"; + } + return $resultStr; + } + return '1'; + } + } else { + return '0'; + } + } + + /** + * 启用某个SVN用户 + * 0 文件格式错误(不存在[users]标识) + * 1 要启用的用户不存在 + * string 正常 + */ + public static function EnabledUser($passwdContent, $userName) + { + $userName = trim($userName); + preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + if (array_key_exists(0, $passwdContentPreg[1])) { + $temp1 = trim($passwdContentPreg[1][0]); + if (empty($temp1)) { + return '1'; + } else { + preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + array_walk($resultPreg[1], 'FunArrayValueTrim'); + array_walk($resultPreg[3], 'FunArrayValueTrim'); + if (in_array(REG_SVN_USER_DISABLED . $userName, $resultPreg[1])) { + $resultStr = "[users]\n"; + foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $value) { + if ($key == REG_SVN_USER_DISABLED . $userName) { + $key = $userName; + } + $resultStr .= "$key=$value\n"; + } + return $resultStr; + } + return '1'; + } + } else { + return '0'; + } + } +} diff --git a/02.php/config/reg.config.php b/02.php/config/reg.config.php index 9cdac23..392c983 100644 --- a/02.php/config/reg.config.php +++ b/02.php/config/reg.config.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:06 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 11:48:17 + * @LastEditTime: 2022-04-27 17:45:47 * @Description: QQ:1801168257 */ @@ -97,30 +97,35 @@ define('REG_PASSWD_USER_PASSWD', "/^((%s)*[A-Za-z0-9-_.]+)\s*=(.*)/m"); * * %s => $group */ -define('REG_AUTHZ_GROUP_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?@%s[\s]*=[\s]*([rw]+)/m"); +define('REG_AUTHZ_GROUP_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?@%s[\s]*=[\s]*([rw]+)$\n/m"); /** * 匹配authz配置文件中某个用户有权限的仓库列表 * * %s => $user */ -define('REG_AUTHZ_USER_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?%s[\s]*=[\s]*([rw]+)/m"); +define('REG_AUTHZ_USER_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?%s[\s]*=[\s]*([rw]+)$\n/m"); /** * 匹配authz配置文件中所有用户有权限的仓库列表 * * *=r、*=rw */ -define('REG_AUTHZ_ALL_HAVE_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*([rw]+)/m"); +define('REG_AUTHZ_ALL_HAVE_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*([rw]+)$\n/m"); /** - * 匹配authz配置文件中所有用户有权限的仓库列表(配置*=不代表所有人无权限 只代表未设置的用户无权限) + * 匹配authz配置文件中所有用户无权限的仓库列表 * * *= + */ +define('REG_AUTHZ_ALL_NO_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*$\n/m"); + +/** + * 匹配通过魔力符号配置的相关信息 * - * 存疑 + * 包含 ~ $等前缀 */ -define('REG_AUTHZ_ALL_NO_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*([rw]+)/m"); +//todo /** * 匹配authz配置文件中指定仓库的指定路径 包含内容