diff --git a/01.web/.vscode/launch.json b/01.web/.vscode/launch.json new file mode 100644 index 0000000..630b21c --- /dev/null +++ b/01.web/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // 使用 IntelliSense 了解相关属性。 + // 悬停以查看现有属性的描述。 + // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "pwa-chrome", + "request": "launch", + "name": "Launch Chrome against localhost", + "url": "http://127.0.0.1:8081/", + "webRoot": "${workspaceFolder}" + } + ] +} \ No newline at end of file diff --git a/01.web/src/views/layout/basicLayout/index.vue b/01.web/src/views/layout/basicLayout/index.vue index 064049b..94e0163 100644 --- a/01.web/src/views/layout/basicLayout/index.vue +++ b/01.web/src/views/layout/basicLayout/index.vue @@ -27,6 +27,7 @@ style="line-height: 64px; position: absolute; top: 12px; left: 1%" /> item.meta.user_role_id.indexOf(sessionStorage.user_role_id) != -1 + (item) => + item.meta.user_role_id.indexOf(sessionStorage.user_role_id) != -1 ); //转换为两层结构 diff --git a/01.web/src/views/login/index.vue b/01.web/src/views/login/index.vue index 1ef1a9b..52dd558 100644 --- a/01.web/src/views/login/index.vue +++ b/01.web/src/views/login/index.vue @@ -36,7 +36,7 @@ - diff --git a/01.web/src/views/personal/index.vue b/01.web/src/views/personal/index.vue index 16e3d07..38dcd85 100644 --- a/01.web/src/views/personal/index.vue +++ b/01.web/src/views/personal/index.vue @@ -10,7 +10,7 @@ >
- + - + @@ -67,7 +67,10 @@ > - diff --git a/01.web/src/views/repositoryGroup/index.vue b/01.web/src/views/repositoryGroup/index.vue index 65018f2..713fd3e 100644 --- a/01.web/src/views/repositoryGroup/index.vue +++ b/01.web/src/views/repositoryGroup/index.vue @@ -21,7 +21,7 @@ enter-button placeholder="通过SVN分组名、备注搜索..." style="width: 100%" - @on-enter="GetGroupList" + @on-search="SearchGetGroupList" /> @@ -386,7 +386,7 @@ -
globalPasswdContent, $this->globalUserName); + $result = $this->SVNAdminUser->GetPassByUser($this->globalPasswdContent, $this->globalUserName); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -101,7 +101,7 @@ class personal extends controller } //修改SVN指定用户的密码 - $result = \SVNAdmin\SVN\User::UpdSvnUserPass($this->globalPasswdContent, $this->globalUserName, $this->requestPayload['newPassword']); + $result = $this->SVNAdminUser->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 1c2847a..3e9e8b8 100644 --- a/02.php/app/controller/statistics.class.php +++ b/02.php/app/controller/statistics.class.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 18:23:46 + * @LastEditTime: 2022-04-28 01:53:50 * @Description: QQ:1801168257 */ @@ -228,17 +228,17 @@ class statistics extends controller $backupSize = FunFormatSize(FunGetDirSizeDu(SVN_BACHUP_PATH)); //SVN仓库数量 - $repCount = count(\SVNAdmin\SVN\Rep::GetSimpleRepList()); + $repCount = count($this->SVNAdminRep->GetSimpleRepList()); //SVN用户数量 - $userCount = \SVNAdmin\SVN\User::GetSvnUserList($this->globalPasswdContent); + $userCount = $this->SVNAdminUser->GetSvnUserList($this->globalPasswdContent); if ($userCount === '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } $userCount = count($userCount); //SVN分组数量 - $groupCount = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent); + $groupCount = $this->SVNAdminGroup->GetSvnGroupList($this->globalAuthzContent); if ($userCount === '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } diff --git a/02.php/app/controller/subversion.class.php b/02.php/app/controller/subversion.class.php index 44fddbf..9058a54 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 17:59:25 + * @LastEditTime: 2022-04-28 02:09:41 * @Description: QQ:1801168257 */ @@ -43,7 +43,7 @@ class subversion extends controller */ function GetCheckout() { - $result = \SVNAdmin\SVN\Info::GetSubversionListen(); + $result = $this->SVNAdminInfo->GetSubversionListen(SVNSERVE_ENV_FILE, LISTEN_FILE); $checkoutHost = $result[$result['enable']]; if ($result['bindPort'] != '3690') { $checkoutHost .= ':' . $result['bindPort']; @@ -60,7 +60,7 @@ class subversion extends controller function GetDetail() { //获取绑定主机、端口等信息 - $bindInfo = \SVNAdmin\SVN\Info::GetSubversionListen(); + $bindInfo = $this->SVNAdminInfo->GetSubversionListen(SVNSERVE_ENV_FILE, LISTEN_FILE); //检测运行信息 $runInfo = FunShellExec('ps auxf|grep -v "grep"|grep svnserve'); diff --git a/02.php/app/controller/svnadmin.class.php b/02.php/app/controller/svnadmin.class.php deleted file mode 100644 index 1042ac8..0000000 --- a/02.php/app/controller/svnadmin.class.php +++ /dev/null @@ -1,23 +0,0 @@ -globalAuthzContent); - - + $svnAndGroupList = $this->SVNAdminGroup->GetSvnGroupUserAndGroupList($this->globalAuthzContent); if ($svnAndGroupList == 0) { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); @@ -83,7 +81,7 @@ class svngroup extends controller */ function GetAllGroupList() { - $svnGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent); + $svnGroupList = $this->SVNAdminGroup->GetSvnGroupList($this->globalAuthzContent); if ($svnGroupList == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } else { @@ -171,7 +169,7 @@ class svngroup extends controller FunCheckRepGroup($this->requestPayload['svn_group_name']); //检查用户是否已存在 - $result = \SVNAdmin\SVN\Group::AddSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $result = $this->SVNAdminGroup->AddSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -199,7 +197,7 @@ class svngroup extends controller function DelGroup() { //从authz文件删除 - $result = \SVNAdmin\SVN\Group::DelSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $result = $this->SVNAdminGroup->DelSvnGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); @@ -226,7 +224,7 @@ class svngroup extends controller //新分组名称是否合法 FunCheckRepGroup($this->requestPayload['groupNameNew']); - $svnGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent); + $svnGroupList = $this->SVNAdminGroup->GetSvnGroupList($this->globalAuthzContent); //旧分组是否存在 if (!in_array($this->requestPayload['groupNameOld'], $svnGroupList)) { @@ -238,7 +236,7 @@ class svngroup extends controller FunMessageExit(200, 0, '要修改的分组名称已经存在'); } - $result = \SVNAdmin\SVN\Group::UpdSvnGroup($this->globalAuthzContent, $this->requestPayload['groupNameOld'], $this->requestPayload['groupNameNew']); + $result = $this->SVNAdminGroup->UpdSvnGroup($this->globalAuthzContent, $this->requestPayload['groupNameOld'], $this->requestPayload['groupNameNew']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -253,13 +251,13 @@ class svngroup extends controller */ function GetGroupMember() { - $memberUserList = \SVNAdmin\SVN\Group::GetSvnUserListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $memberUserList = $this->SVNAdminGroup->GetSvnUserListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); - $memberGroupList = \SVNAdmin\SVN\Group::GetSvnGroupListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); + $memberGroupList = $this->SVNAdminGroup->GetSvnGroupListByGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name']); - $allGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent); + $allGroupList = $this->SVNAdminGroup->GetSvnGroupList($this->globalAuthzContent); - $allUserList = \SVNAdmin\SVN\User::GetSvnUserList($this->globalPasswdContent); + $allUserList = $this->SVNAdminUser->GetSvnUserList($this->globalPasswdContent); if ($memberUserList == '0' || $memberGroupList == '0' || $allGroupList == '0' || $allUserList == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); @@ -317,7 +315,7 @@ class svngroup extends controller */ function GroupAddUser() { - $result = \SVNAdmin\SVN\Group::AddSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); + $result = $this->SVNAdminGroup->AddSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -338,7 +336,7 @@ class svngroup extends controller */ function GroupRemoveUser() { - $result = \SVNAdmin\SVN\Group::DelSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); + $result = $this->SVNAdminGroup->DelSvnGroupUser($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -359,7 +357,7 @@ class svngroup extends controller */ function GroupAddGroup() { - $result = \SVNAdmin\SVN\Group::AddSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_add']); + $result = $this->SVNAdminGroup->AddSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_add']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -391,7 +389,7 @@ class svngroup extends controller */ function GroupRemoveGroup() { - $result = \SVNAdmin\SVN\Group::DelSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_del']); + $result = $this->SVNAdminGroup->DelSvnGroupGroup($this->globalAuthzContent, $this->requestPayload['svn_group_name'], $this->requestPayload['svn_group_name_del']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); } @@ -424,10 +422,10 @@ class svngroup extends controller $authzContent = $this->globalAuthzContent; //所有的分组列表 - $allGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($authzContent); + $allGroupList = $this->SVNAdminGroup->GetSvnGroupList($authzContent); //用户所在的分组列表 - $userGroupList = \SVNAdmin\SVN\User::GetSvnUserGroupList($authzContent, $userName); + $userGroupList = $this->SVNAdminUser->GetSvnUserGroupList($authzContent, $userName); //剩余的分组列表 $leftGroupList = array_diff($allGroupList, $userGroupList); @@ -436,7 +434,7 @@ class svngroup extends controller loop: $userGroupListBack = $userGroupList; foreach ($userGroupList as $group1) { - $newList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $group1); + $newList = $this->SVNAdminGroup->GetSvnGroupGroupList($authzContent, $group1); foreach ($leftGroupList as $key2 => $group2) { if (in_array($group2, $newList)) { array_push($userGroupList, $group2); @@ -469,10 +467,10 @@ class svngroup extends controller $authzContent = $this->globalAuthzContent; //所有的分组列表 - $allGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($authzContent); + $allGroupList = $this->SVNAdminGroup->GetSvnGroupList($authzContent); //分组所在的分组列表 - $groupGroupList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $parentGroupName); + $groupGroupList = $this->SVNAdminGroup->GetSvnGroupGroupList($authzContent, $parentGroupName); //剩余的分组列表 $leftGroupList = array_diff($allGroupList, $groupGroupList); @@ -481,7 +479,7 @@ class svngroup extends controller loop: $userGroupListBack = $groupGroupList; foreach ($groupGroupList as $group1) { - $newList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $group1); + $newList = $this->SVNAdminGroup->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 156a729..e1380f0 100644 --- a/02.php/app/controller/svnrep.class.php +++ b/02.php/app/controller/svnrep.class.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 18:10:28 + * @LastEditTime: 2022-04-28 02:32:04 * @Description: QQ:1801168257 */ @@ -42,7 +42,7 @@ class svnrep extends controller FunCheckRepName($this->requestPayload['rep_name']); //检查仓库是否存在 - \SVNAdmin\SVN\Rep::CheckRepExist($this->requestPayload['rep_name']); + $this->SVNAdminRep->CheckRepExist($this->requestPayload['rep_name']); //创建空仓库 //解决创建中文仓库乱码问题 @@ -50,14 +50,14 @@ class svnrep extends controller if ($this->requestPayload['rep_type'] == '2') { //以指定的目录结构初始化仓库 - \SVNAdmin\SVN\Rep::InitRepStruct($this->requestPayload['rep_name']); + $this->SVNAdminRep->InitRepStruct($this->requestPayload['rep_name']); } //检查是否创建成功 - \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name']); + $this->SVNAdminRep->CheckRepCreate($this->requestPayload['rep_name']); //向authz写入仓库信息 - $status = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name'], '/'); + $status = $this->SVNAdminRep->SetRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name'], '/'); if ($status != '1') { FunShellExec('echo \'' . $status . '\' > ' . SVN_AUTHZ_FILE); } @@ -82,7 +82,7 @@ class svnrep extends controller */ function SyncRepAndDb() { - $svnRepList = \SVNAdmin\SVN\Rep::GetSimpleRepList(); + $svnRepList = $this->SVNAdminRep->GetSimpleRepList(); $dbRepList = $this->database->select('svn_reps', [ 'rep_name', @@ -97,7 +97,7 @@ class svnrep extends controller //更新 $this->database->update('svn_reps', [ 'rep_size' => FunGetDirSizeDu(SVN_REPOSITORY_PATH . $value['rep_name']), - 'rep_rev' => \SVNAdmin\SVN\Rep::GetRepRev($value['rep_name']) + 'rep_rev' => $this->SVNAdminRep->GetRepRev($value['rep_name']) ], [ 'rep_name' => $value['rep_name'] ]); @@ -110,7 +110,7 @@ class svnrep extends controller 'rep_name' => $value, 'rep_size' => FunGetDirSizeDu(SVN_REPOSITORY_PATH . $value), 'rep_note' => '', - 'rep_rev' => \SVNAdmin\SVN\Rep::GetRepRev($value), + 'rep_rev' => $this->SVNAdminRep->GetRepRev($value), 'rep_uuid' => '' ]); } @@ -125,15 +125,15 @@ class svnrep extends controller */ function SyncRepAndAuthz() { - $svnRepList = \SVNAdmin\SVN\Rep::GetSimpleRepList(); + $svnRepList = $this->SVNAdminRep->GetSimpleRepList(); - $svnRepAuthzList = \SVNAdmin\SVN\Rep::GetNoPathAndConRepAuthz($this->globalAuthzContent); + $svnRepAuthzList = $this->SVNAdminRep->GetNoPathAndConRepAuthz($this->globalAuthzContent); $authzContet = $this->globalAuthzContent; foreach ($svnRepList as $key => $value) { if (!in_array($value, $svnRepAuthzList)) { - $authzContet = \SVNAdmin\SVN\Rep::SetRepAuthz($authzContet, $value, '/'); + $authzContet = $this->SVNAdminRep->SetRepAuthz($authzContet, $value, '/'); if ($authzContet == '1') { FunMessageExit(200, 0, '同步到配置文件错误'); } @@ -142,7 +142,7 @@ class svnrep extends controller foreach ($svnRepAuthzList as $key => $value) { if (!in_array($value, $svnRepList)) { - $authzContet = \SVNAdmin\SVN\Rep::DelRepAuthz($authzContet, $value); + $authzContet = $this->SVNAdminRep->DelRepAuthz($authzContet, $value); if ($authzContet == '1') { FunMessageExit(200, 0, '同步到配置文件错误'); } @@ -164,14 +164,14 @@ class svnrep extends controller $userRepList = []; //获取用户有权限的仓库列表 - $userRepList = array_merge($userRepList, \SVNAdmin\SVN\User::GetUserPriRepListWithPriAndPath($this->globalAuthzContent, $this->globalUserName)); + $userRepList = array_merge($userRepList, $this->SVNAdminUser->GetUserPriRepListWithPriAndPath($this->globalAuthzContent, $this->globalUserName)); //获取用户所在的所有分组 $userGroupList = $this->Svngorup->GetSvnUserAllGroupList($this->globalUserName); //获取分组有权限的仓库路径列表 foreach ($userGroupList as $value) { - $userRepList = array_merge($userRepList, \SVNAdmin\SVN\Group::GetGroupPriRepListWithPriAndPath($this->globalAuthzContent, $value)); + $userRepList = array_merge($userRepList, $this->SVNAdminGroup->GetGroupPriRepListWithPriAndPath($this->globalAuthzContent, $value)); } //按照全路径去重 @@ -370,14 +370,14 @@ class svnrep extends controller * * 目的为使用当前SVN用户的身份来进行被授权过的路径的内容浏览 */ - $bindInfo = \SVNAdmin\SVN\Info::GetSubversionListen(); + $bindInfo = $this->SVNAdminInfo->GetSubversionListen(SVNSERVE_ENV_FILE, LISTEN_FILE); $checkoutHost = 'svn://' . $bindInfo['bindHost']; if ($bindInfo['bindPort'] != '3690') { $checkoutHost = 'svn://' . $bindInfo['bindHost'] . ':' . $bindInfo['bindPort']; } //获取SVN用户密码 - $svnUserPass = \SVNAdmin\SVN\User::GetPassByUser($this->globalPasswdContent, $this->globalUserName); + $svnUserPass = $this->SVNAdminUser->GetPassByUser($this->globalPasswdContent, $this->globalUserName); if ($svnUserPass == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } else if ($svnUserPass == '1') { @@ -396,8 +396,11 @@ class svnrep extends controller if (strstr($result, 'svn: E170001: Authorization failed')) { FunMessageExit(200, 0, '无访问权限'); } + if(strstr($result,'svn: E220003: Invalid authz configuration')){ + FunMessageExit(200, 0, '配置文件配置错误 请使用svnauthz-validate工具检查'); + } if (strstr($result, 'svn: E170013: Unable to connect to a repository at URL')) { - FunMessageExit(200, 0, '其它错误'); + FunMessageExit(200, 0, '其它错误' . $result); } $resultArray = explode("\n", trim($result)); @@ -413,16 +416,16 @@ class svnrep extends controller } //获取文件或者文件夹最年轻的版本号 - $lastRev = \SVNAdmin\SVN\Rep::GetRepFileRev($repName, $value); + $lastRev = $this->SVNAdminRep->GetRepFileRev($repName, $value); //获取文件或者文件夹最年轻的版本的作者 - $lastRevAuthor = \SVNAdmin\SVN\Rep::GetRepFileAuthor($repName, $lastRev); + $lastRevAuthor = $this->SVNAdminRep->GetRepFileAuthor($repName, $lastRev); //同上 日期 - $lastRevDate = \SVNAdmin\SVN\Rep::GetRepFileDate($repName, $lastRev); + $lastRevDate = $this->SVNAdminRep->GetRepFileDate($repName, $lastRev); //同上 日志 - $lastRevLog = \SVNAdmin\SVN\Rep::GetRepFileLog($repName, $lastRev); + $lastRevLog = $this->SVNAdminRep->GetRepFileLog($repName, $lastRev); $pathArray = explode('/', $value); $pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter')); @@ -442,7 +445,7 @@ class svnrep extends controller array_push($data, [ 'resourceType' => 1, 'resourceName' => $pathArray[$pathArrayCount - 1], - 'fileSize' => \SVNAdmin\SVN\Rep::GetRepRevFileSize($repName, $value), + 'fileSize' => $this->SVNAdminRep->GetRepRevFileSize($repName, $value), 'revAuthor' => $lastRevAuthor, 'revNum' => 'r' . $lastRev, 'revTime' => $lastRevDate, @@ -482,7 +485,8 @@ class svnrep extends controller 'data' => $data, 'bread' => [ 'path' => $breadPathArray, - 'name' => $breadNameArray + 'name' => $breadNameArray, + 'test' => $result ] ]); } @@ -510,16 +514,16 @@ class svnrep extends controller $data = []; foreach ($resultArray as $key => $value) { //获取文件或者文件夹最年轻的版本号 - $lastRev = \SVNAdmin\SVN\Rep::GetRepFileRev($this->requestPayload['rep_name'], $value); + $lastRev = $this->SVNAdminRep->GetRepFileRev($this->requestPayload['rep_name'], $value); //获取文件或者文件夹最年轻的版本的作者 - $lastRevAuthor = \SVNAdmin\SVN\Rep::GetRepFileAuthor($this->requestPayload['rep_name'], $lastRev); + $lastRevAuthor = $this->SVNAdminRep->GetRepFileAuthor($this->requestPayload['rep_name'], $lastRev); //同上 日期 - $lastRevDate = \SVNAdmin\SVN\Rep::GetRepFileDate($this->requestPayload['rep_name'], $lastRev); + $lastRevDate = $this->SVNAdminRep->GetRepFileDate($this->requestPayload['rep_name'], $lastRev); //同上 日志 - $lastRevLog = \SVNAdmin\SVN\Rep::GetRepFileLog($this->requestPayload['rep_name'], $lastRev); + $lastRevLog = $this->SVNAdminRep->GetRepFileLog($this->requestPayload['rep_name'], $lastRev); $pathArray = explode('/', $value); $pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter')); @@ -539,7 +543,7 @@ class svnrep extends controller array_push($data, [ 'resourceType' => 1, 'resourceName' => $pathArray[$pathArrayCount - 1], - 'fileSize' => \SVNAdmin\SVN\Rep::GetRepRevFileSize($this->requestPayload['rep_name'], $value), + 'fileSize' => $this->SVNAdminRep->GetRepRevFileSize($this->requestPayload['rep_name'], $value), 'revAuthor' => $lastRevAuthor, 'revNum' => 'r' . $lastRev, 'revTime' => $lastRevDate, @@ -647,7 +651,7 @@ class svnrep extends controller */ function GetRepPathUserPri() { - $result = \SVNAdmin\SVN\Rep::GetRepUserListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); + $result = $this->SVNAdminRep->GetRepUserListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); if ($result == '0') { //没有该路径的记录 if ($this->requestPayload['path'] == '/') { @@ -673,7 +677,7 @@ class svnrep extends controller */ function GetRepPathGroupPri() { - $result = \SVNAdmin\SVN\Rep::GetRepGroupListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); + $result = $this->SVNAdminRep->GetRepGroupListWithPri($this->globalAuthzContent, $this->requestPayload['rep_name'], $this->requestPayload['path']); if ($result == '0') { //没有该路径的记录 if ($this->requestPayload['path'] == '/') { @@ -720,20 +724,20 @@ class svnrep extends controller * 包括为已有权限的用户修改权限 * 包括为没有权限的用户增加权限 */ - $result = \SVNAdmin\SVN\Rep::SetRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); + $result = $this->SVNAdminRep->SetRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); //没有该仓库路径记录 if ($result == '0') { //没有该仓库路径记录 则进行插入 - $result = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $repName, $path); + $result = $this->SVNAdminRep->SetRepAuthz($this->globalAuthzContent, $repName, $path); if ($result == '1') { FunMessageExit(200, 1, '未知错误'); } //重新添加权限 - $result = \SVNAdmin\SVN\Rep::SetRepUserPri($result, $user, $pri, $repName, $path); + $result = $this->SVNAdminRep->SetRepUserPri($result, $user, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 1, '未知错误'); @@ -756,7 +760,7 @@ class svnrep extends controller $path = $this->requestPayload['path']; $user = $this->requestPayload['user']; - $result = \SVNAdmin\SVN\Rep::DelRepUserPri($this->globalAuthzContent, $user, $repName, $path); + $result = $this->SVNAdminRep->DelRepUserPri($this->globalAuthzContent, $user, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -786,7 +790,7 @@ class svnrep extends controller */ $pri = $pri == 'no' ? '' : $pri; - $result = \SVNAdmin\SVN\Rep::UpdRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); + $result = $this->SVNAdminRep->UpdRepUserPri($this->globalAuthzContent, $user, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -825,20 +829,20 @@ class svnrep extends controller * 包括为已有权限的分组修改权限 * 包括为没有权限的分组增加权限 */ - $result = \SVNAdmin\SVN\Rep::SetRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); + $result = $this->SVNAdminRep->SetRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); //没有该仓库路径记录 if ($result == '0') { //没有该仓库路径记录 则进行插入 - $result = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $repName, $path); + $result = $this->SVNAdminRep->SetRepAuthz($this->globalAuthzContent, $repName, $path); if ($result == '1') { FunMessageExit(200, 1, '未知错误'); } //重新添加权限 - $result = \SVNAdmin\SVN\Rep::SetRepGroupPri($result, $group, $pri, $repName, $path); + $result = $this->SVNAdminRep->SetRepGroupPri($result, $group, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 1, '未知错误'); @@ -861,7 +865,7 @@ class svnrep extends controller $path = $this->requestPayload['path']; $group = $this->requestPayload['group']; - $result = \SVNAdmin\SVN\Rep::DelRepGroupPri($this->globalAuthzContent, $group, $repName, $path); + $result = $this->SVNAdminRep->DelRepGroupPri($this->globalAuthzContent, $group, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -891,7 +895,7 @@ class svnrep extends controller */ $pri = $pri == 'no' ? '' : $pri; - $result = \SVNAdmin\SVN\Rep::UpdRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); + $result = $this->SVNAdminRep->UpdRepGroupPri($this->globalAuthzContent, $group, $pri, $repName, $path); if ($result == '0') { FunMessageExit(200, 0, '不存在该仓库路径的记录'); @@ -915,16 +919,16 @@ class svnrep extends controller FunCheckRepName($this->requestPayload['new_rep_name']); //检查原仓库是否不存在 - \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['old_rep_name'], '要修改的仓库不存在'); + $this->SVNAdminRep->CheckRepCreate($this->requestPayload['old_rep_name'], '要修改的仓库不存在'); //检查新仓库名是否存在 - \SVNAdmin\SVN\Rep::CheckRepExist($this->requestPayload['new_rep_name'], '已经存在同名仓库'); + $this->SVNAdminRep->CheckRepExist($this->requestPayload['new_rep_name'], '已经存在同名仓库'); //从仓库目录修改仓库名称 FunShellExec('mv ' . SVN_REPOSITORY_PATH . $this->requestPayload['old_rep_name'] . ' ' . SVN_REPOSITORY_PATH . $this->requestPayload['new_rep_name']); //检查修改过的仓库名称是否存在 - \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['new_rep_name'], '修改仓库名称失败'); + $this->SVNAdminRep->CheckRepCreate($this->requestPayload['new_rep_name'], '修改仓库名称失败'); //从数据库修改仓库名称 $this->database->update('svn_reps', [ @@ -934,7 +938,7 @@ class svnrep extends controller ]); //从配置文件修改仓库名称 - \SVNAdmin\SVN\Rep::UpdRepAuthz($this->globalAuthzContent, $this->requestPayload['old_rep_name'], $this->requestPayload['new_rep_name']); + $this->SVNAdminRep->UpdRepAuthz($this->globalAuthzContent, $this->requestPayload['old_rep_name'], $this->requestPayload['new_rep_name']); FunMessageExit(); } @@ -945,7 +949,7 @@ class svnrep extends controller function DelRep() { //从配置文件删除指定仓库的所有路径 - $result = \SVNAdmin\SVN\Rep::DelRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name']); + $result = $this->SVNAdminRep->DelRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name']); if ($result != '1') { FunShellExec('echo \'' . $result . '\' > ' . SVN_AUTHZ_FILE); } @@ -957,7 +961,7 @@ class svnrep extends controller //从仓库目录删除仓库文件夹 FunShellExec('cd ' . SVN_REPOSITORY_PATH . ' && rm -rf ./' . $this->requestPayload['rep_name']); - \SVNAdmin\SVN\Rep::CheckRepDelete($this->requestPayload['rep_name']); + $this->SVNAdminRep->CheckRepDelete($this->requestPayload['rep_name']); //返回 FunMessageExit(); @@ -968,7 +972,7 @@ class svnrep extends controller */ function GetRepDetail() { - $result = \SVNAdmin\SVN\Rep::GetRepDetail($this->requestPayload['rep_name']); + $result = $this->SVNAdminRep->GetRepDetail($this->requestPayload['rep_name']); $resultArray = explode("\n", $result); $newArray = []; @@ -1001,7 +1005,7 @@ class svnrep extends controller */ function RepDump() { - \SVNAdmin\SVN\Rep::RepDump($this->requestPayload['rep_name'], $this->requestPayload['rep_name'] . '_' . date('YmdHis') . '_' . FunGetRandStr() . '.dump'); + $this->SVNAdminRep->RepDump($this->requestPayload['rep_name'], $this->requestPayload['rep_name'] . '_' . date('YmdHis') . '_' . FunGetRandStr() . '.dump'); FunMessageExit(); } @@ -1011,7 +1015,7 @@ class svnrep extends controller */ function DelRepBackup() { - \SVNAdmin\SVN\Rep::DelRepBackup($this->requestPayload['fileName']); + $this->SVNAdminRep->DelRepBackup($this->requestPayload['fileName']); FunMessageExit(); } @@ -1147,10 +1151,10 @@ class svnrep extends controller } //检查操作的仓库是否存在 - \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); + $this->SVNAdminRep->CheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); //使用svndump - $result = \SVNAdmin\SVN\Rep::RepLoad($this->requestPayload['rep_name'], $this->requestPayload['fileName']); + $result = $this->SVNAdminRep->RepLoad($this->requestPayload['rep_name'], $this->requestPayload['fileName']); if ($result == ISNULL) { FunMessageExit(); @@ -1165,7 +1169,7 @@ class svnrep extends controller function GetRepHooks() { //检查仓库是否存在 - \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); + $this->SVNAdminRep->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 26b8dc3..b37cb62 100644 --- a/02.php/app/controller/svnuser.class.php +++ b/02.php/app/controller/svnuser.class.php @@ -30,7 +30,7 @@ class svnuser extends controller */ function SyncUserToDb() { - $svnUserPassList = \SVNAdmin\SVN\User::GetSvnUserPassList($this->globalPasswdContent); + $svnUserPassList = $this->SVNAdminUser->GetSvnUserPassList($this->globalPasswdContent); if ($svnUserPassList == 0) { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -79,7 +79,7 @@ class svnuser extends controller */ function GetAllUserList() { - $svnUserList = \SVNAdmin\SVN\User::GetSvnUserList($this->globalPasswdContent); + $svnUserList = $this->SVNAdminUser->GetSvnUserList($this->globalPasswdContent); if ($svnUserList == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } else { @@ -151,7 +151,7 @@ class svnuser extends controller */ function EnableUser() { - $result = \SVNAdmin\SVN\User::EnabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); + $result = $this->SVNAdminUser->EnabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -169,7 +169,7 @@ class svnuser extends controller */ function DisableUser() { - $result = \SVNAdmin\SVN\User::DisabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); + $result = $this->SVNAdminUser->DisabledUser($this->globalPasswdContent, $this->requestPayload['svn_user_name']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -205,7 +205,7 @@ class svnuser extends controller FunCheckRepUser($this->requestPayload['svn_user_name']); //检查用户是否已存在 - $result = \SVNAdmin\SVN\User::AddSvnUser($this->globalPasswdContent, $this->requestPayload['svn_user_name'], $this->requestPayload['svn_user_pass']); + $result = $this->SVNAdminUser->AddSvnUser($this->globalPasswdContent, $this->requestPayload['svn_user_name'], $this->requestPayload['svn_user_pass']); if ($result == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); } @@ -238,7 +238,7 @@ class svnuser extends controller function EditUserPass() { //检查用户是否已存在 - $result = \SVNAdmin\SVN\User::UpdSvnUserPass($this->globalPasswdContent, $this->requestPayload['svn_user_name'], $this->requestPayload['svn_user_pass'], !$this->requestPayload['svn_user_status']); + $result = $this->SVNAdminUser->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]标识)'); } @@ -270,7 +270,7 @@ class svnuser extends controller function DelUser() { //从passwd文件中全局删除 - $resultPasswd = \SVNAdmin\SVN\User::DelSvnUserPasswd($this->globalPasswdContent, $this->requestPayload['svn_user_name'], !$this->requestPayload['svn_user_status']); + $resultPasswd = $this->SVNAdminUser->DelSvnUserPasswd($this->globalPasswdContent, $this->requestPayload['svn_user_name'], !$this->requestPayload['svn_user_status']); if ($resultPasswd == '0') { FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); @@ -280,7 +280,7 @@ class svnuser extends controller } //从authz文件中删除 - $resultAuthz = \SVNAdmin\SVN\User::DelUserAuthz($this->globalAuthzContent, $this->requestPayload['svn_user_name']); + $resultAuthz = $this->SVNAdminUser->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 090d5e6..7eca346 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-27 18:03:08 + * @LastEditTime: 2022-04-28 02:03:15 * @Description: QQ:1801168257 */ @@ -24,7 +24,6 @@ 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'; @@ -56,6 +55,14 @@ require_once BASE_PATH . '/app/controller/update.class.php'; //require extension +//require svnadmin +require_once BASE_PATH . '/extension/SVNAdmin/src/core/Core.class.php'; +require_once BASE_PATH . '/extension/SVNAdmin/src/class/SVNGroup.class.php'; +require_once BASE_PATH . '/extension/SVNAdmin/src/class/SVNHooks.class.php'; +require_once BASE_PATH . '/extension/SVNAdmin/src/class/SVNInfo.class.php'; +require_once BASE_PATH . '/extension/SVNAdmin/src/class/SVNRep.class.php'; +require_once BASE_PATH . '/extension/SVNAdmin/src/class/SVNUser.class.php'; + class controller { @@ -70,10 +77,15 @@ class controller public $requestPayload; - public $files; - public $database; + //SVNAdmin对象 + public $SVNAdminGroup; + public $SVNAdminHooks; + public $SVNAdminInfo; + public $SVNAdminRep; + public $SVNAdminUser; + function __construct() { /** @@ -95,21 +107,24 @@ class controller $this->globalPasswdContent = file_exists(SVN_PASSWD_FILE) ? file_get_contents(SVN_PASSWD_FILE) : ''; /** - * 请求载体相关 + * 请求载体 */ global $requestPayload; $this->requestPayload = $requestPayload; /** - * 文件 + * 数据库连接 */ - global $files; - $this->files = $files; + $this->database = (new conn())->GetConn(); /** - * 数据库连接 + * svnadmin对象 */ - $this->database = (new conn())->GetConn(); + $this->SVNAdminGroup = new \SVNAdmin\SVN\Group($this->globalAuthzContent, $this->globalPasswdContent); + $this->SVNAdminHooks = new \SVNAdmin\SVN\Hooks($this->globalAuthzContent, $this->globalPasswdContent); + $this->SVNAdminInfo = new \SVNAdmin\SVN\Info($this->globalAuthzContent, $this->globalPasswdContent); + $this->SVNAdminRep = new \SVNAdmin\SVN\Rep($this->globalAuthzContent, $this->globalPasswdContent); + $this->SVNAdminUser = new \SVNAdmin\SVN\User($this->globalAuthzContent, $this->globalPasswdContent); } /** diff --git a/02.php/app/function/array.function.php b/02.php/app/function/array.function.php index 905c0e7..3d6e335 100644 --- a/02.php/app/function/array.function.php +++ b/02.php/app/function/array.function.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:05 * @LastEditors: witersen - * @LastEditTime: 2022-04-26 16:55:47 + * @LastEditTime: 2022-04-27 23:57:53 * @Description: QQ:1801168257 */ @@ -53,8 +53,10 @@ function FunArrayIsStrFolder($string) */ function FunArrayValueEnabled(&$value, $key) { - if (substr($value, 0, strlen(REG_SVN_USER_DISABLED)) == REG_SVN_USER_DISABLED) { - $value = substr($value, strlen(REG_SVN_USER_DISABLED)); + $REG_SVN_USER_DISABLED = '#disabled#'; + + if (substr($value, 0, strlen($REG_SVN_USER_DISABLED)) == $REG_SVN_USER_DISABLED) { + $value = substr($value, strlen($REG_SVN_USER_DISABLED)); } } diff --git a/02.php/app/model/util.model.php b/02.php/app/model/util.model.php deleted file mode 100644 index c34d754..0000000 --- a/02.php/app/model/util.model.php +++ /dev/null @@ -1,24 +0,0 @@ - $group - */ -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]+)$\n/m"); - -/** - * 匹配authz配置文件中所有用户有权限的仓库列表 - * - * *=r、*=rw - */ -define('REG_AUTHZ_ALL_HAVE_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*([rw]+)$\n/m"); - -/** - * 匹配authz配置文件中所有用户无权限的仓库列表 - * - * *= - */ -define('REG_AUTHZ_ALL_NO_PRI_REPS', "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*$\n/m"); - -/** - * 匹配通过魔力符号配置的相关信息 - * - * 包含 ~ $等前缀 - */ -//todo - -/** - * 匹配authz配置文件中指定仓库的指定路径 包含内容 - * - * 如 - * [rep1:/floder] - * u1=r - * @g1=rw - * - * %s => $repName - * %s => $repPath - */ -define('REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON', "/^\[%s:%s\]([\s\S][^\[]*)/m"); - -/** - * 匹配authz配置文件中指定仓库的指定路径 不包含内容 - * - * 如 - * [rep1:/] - * 或 - * [rep2:/floder] - * 等 - * - * %s => $repName - * %s => $repPaht str_replace('/', '\/', $repPath) - */ -define('REG_AUTHZ_REP_SPECIAL_PATH_WITHOUT_CON', "/^\[%s:%s\]/m"); - -/** - * 匹配authz配置文件中指定仓库的所有路径 不包含内容 - * - * %s => $repName - */ -define('REG_AUTHZ_REP_ALL_PATH_WITHOUT_CON', "/^\[%s:(.*?)\]/m"); - -/** - * 匹配authz配置文件中指定仓库的所有路径以及包含的内容 - * - * %s => $repName - */ -define('REG_AUTHZ_REP_ALL_PATH_WITH_CON', "/^\[%s:.*\][\s\S][^\[]*/m"); - -/** - * 匹配authz配置文件中的所有仓库名称 - * - * 不匹配这些仓库的内容和具体路径 - */ -define('REG_AUTHZ_ALL_REP_WITHOUT_PATH_AND_CON', "/^\[(.*?):.*?\]/m"); - -/** - * 将 svnadmin info $repPaht 的结果匹配为 key => value 形式 - */ -define('REG_REP_INFO', "/(.*):[\S]*(.*)/m"); - /** * 邮箱格式校验 */ diff --git a/02.php/config/version.config.php b/02.php/config/version.config.php index b9aa598..f7a3738 100644 --- a/02.php/config/version.config.php +++ b/02.php/config/version.config.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:06 * @LastEditors: witersen - * @LastEditTime: 2022-04-26 17:00:54 + * @LastEditTime: 2022-04-27 18:30:43 * @Description: QQ:1801168257 */ @@ -11,4 +11,4 @@ * 当前软件版本信息 * 用户请不要自行修改 以免影响后续升级检测 */ -define('VERSION', '2.2.2'); +define('VERSION', '2.3'); diff --git a/02.php/extension/SVNAdmin/README.md b/02.php/extension/SVNAdmin/README.md new file mode 100644 index 0000000..e69de29 diff --git a/02.php/app/util/SVNGroup.util.php b/02.php/extension/SVNAdmin/src/class/SVNGroup.class.php similarity index 85% rename from 02.php/app/util/SVNGroup.util.php rename to 02.php/extension/SVNAdmin/src/class/SVNGroup.class.php index 65ed511..2b42dde 100644 --- a/02.php/app/util/SVNGroup.util.php +++ b/02.php/extension/SVNAdmin/src/class/SVNGroup.class.php @@ -3,14 +3,20 @@ * @Author: witersen * @Date: 2022-04-27 15:55:52 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 16:55:12 + * @LastEditTime: 2022-04-28 01:20:13 * @Description: QQ:1801168257 + * @copyright: https://github.com/witersen/ */ namespace SVNAdmin\SVN; -class Group +class Group extends \SVNAdmin\SVN\Core { + function __construct($authzFileContent, $passwdFileContent) + { + parent::__construct($authzFileContent, $passwdFileContent); + } + /** * 添加分组 * @@ -18,17 +24,17 @@ class Group * 1 分组已存在 * string 正常 */ - public static function AddSvnGroup($authzContent, $groupName) + function AddSvnGroup($authzContent, $groupName) { $groupName = trim($groupName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); if (array_key_exists(0, $authzContentPreg[0])) { $temp1 = trim($authzContentPreg[1][0]); if (empty($temp1)) { $groupContent = "[groups]\n$groupName=\n"; return str_replace($authzContentPreg[0][0], str_replace("[groups]", $groupContent, $authzContentPreg[0][0]), $authzContent); } else { - preg_match_all(REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); + preg_match_all($this->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])) { @@ -59,16 +65,16 @@ class Group * 1 分组不存在 * string 正常 */ - public static function DelSvnGroup($authzContent, $groupName) + function DelSvnGroup($authzContent, $groupName) { $groupName = trim($groupName); $content1 = "[groups]\n"; $content2 = ""; - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -110,17 +116,17 @@ class Group * 0 文件格式错误(不存在[groups]标识) * string 正常 */ - public static function UpdSvnGroup($authzContent, $oldGroup, $newGroup) + 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); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); $groupContent = ""; @@ -166,15 +172,15 @@ class Group * [1] => group2 * ) */ - public static function GetSvnGroupList($authzContent) + function GetSvnGroupList($authzContent) { - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); return $resultPreg[1]; } @@ -202,16 +208,16 @@ class Group * [1] => group2 * ) */ - public static function GetSvnGroupGroupList($authzContent, $groupName) + function GetSvnGroupGroupList($authzContent, $groupName) { $groupName = trim($groupName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -252,16 +258,16 @@ class Group * [1] => user2 * ) */ - public static function GetSvnUserListByGroup($authzContent, $groupName) + function GetSvnUserListByGroup($authzContent, $groupName) { $groupName = trim($groupName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -303,16 +309,16 @@ class Group * [1] => group2 * ) */ - public static function GetSvnGroupListByGroup($authzContent, $groupName) + function GetSvnGroupListByGroup($authzContent, $groupName) { $groupName = trim($groupName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -380,15 +386,15 @@ class Group * ) * ) */ - public static function GetSvnGroupUserAndGroupList($authzContent) + function GetSvnGroupUserAndGroupList($authzContent) { - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_KEY_VALUE, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); $result = []; @@ -423,17 +429,17 @@ class Group * 2 要添加的用户已存在该分组 * string 正常 */ - public static function AddSvnGroupUser($authzContent, $groupName, $userName) + function AddSvnGroupUser($authzContent, $groupName, $userName) { $groupName = trim($groupName); $userName = trim($userName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -468,17 +474,17 @@ class Group * 2 要删除的用户不在该分组 * string 正常 */ - public static function DelSvnGroupUser($authzContent, $groupName, $userName) + function DelSvnGroupUser($authzContent, $groupName, $userName) { $groupName = trim($groupName); $userName = trim($userName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -515,20 +521,20 @@ class Group * 3 不能添加本身 * string 正常 */ - public static function AddSvnGroupGroup($authzContent, $groupName, $groupName2) + 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); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -563,17 +569,17 @@ class Group * 2 要删除的分组不在该分组 * string 正常 */ - public static function DelSvnGroupGroup($authzContent, $groupName, $groupName2) + function DelSvnGroupGroup($authzContent, $groupName, $groupName2) { $groupName = trim($groupName); $groupName2 = trim($groupName2); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->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])) { @@ -614,10 +620,10 @@ class Group * [1] => rep2 * ) */ - public static function GetGroupPriRepListWithoutPri($authzContent, $groupName) + function GetGroupPriRepListWithoutPri($authzContent, $groupName) { $groupName = trim($groupName); - preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); if (array_key_exists(0, $authzContentPreg[1])) { array_walk($authzContentPreg[1], 'FunArrayValueTrim'); return $authzContentPreg[1]; @@ -647,10 +653,10 @@ class Group * ) * ) */ - public static function GetGroupPriRepListWithPri($authzContent, $groupName) + function GetGroupPriRepListWithPri($authzContent, $groupName) { $groupName = trim($groupName); - preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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'); @@ -670,10 +676,10 @@ class Group /** * 获取某个分组有权限的仓库列表以及对应的权限 */ - public static function GetGroupPriRepListWithPriAndPath($authzContent, $groupName) + function GetGroupPriRepListWithPriAndPath($authzContent, $groupName) { $groupName = trim($groupName); - preg_match_all(sprintf(REG_AUTHZ_GROUP_PRI_REPS, $groupName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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'); diff --git a/02.php/extension/SVNAdmin/src/class/SVNHooks.class.php b/02.php/extension/SVNAdmin/src/class/SVNHooks.class.php new file mode 100644 index 0000000..150766c --- /dev/null +++ b/02.php/extension/SVNAdmin/src/class/SVNHooks.class.php @@ -0,0 +1,19 @@ + $bindHost == '' ? '0.0.0.0' : $bindHost, 'manageHost' => '127.0.0.1', 'enable' => $bindHost == '' ? 'manageHost' : 'bindHost' - ]) . '\' > ' . LISTEN_FILE); + ]) . '\' > ' . $LISTEN_FILE); } else { //更新内容 $listenArray = json_decode($listenContent, true); @@ -63,10 +69,10 @@ class Info 'bindHost' => $listenArray['bindHost'], 'manageHost' => $listenArray['manageHost'] == '' ? '127.0.0.1' : $listenArray['manageHost'], 'enable' => $listenArray['enable'] - ]) . '\' > ' . LISTEN_FILE); + ]) . '\' > ' . $LISTEN_FILE); } - $listenContent = FunShellExec('cat ' . LISTEN_FILE); + $listenContent = FunShellExec('cat ' . $LISTEN_FILE); $listenArray = json_decode($listenContent, true); return [ diff --git a/02.php/app/util/SVNRep.util.php b/02.php/extension/SVNAdmin/src/class/SVNRep.class.php similarity index 85% rename from 02.php/app/util/SVNRep.util.php rename to 02.php/extension/SVNAdmin/src/class/SVNRep.class.php index e904380..ed7e865 100644 --- a/02.php/app/util/SVNRep.util.php +++ b/02.php/extension/SVNAdmin/src/class/SVNRep.class.php @@ -3,14 +3,20 @@ * @Author: witersen * @Date: 2022-04-27 15:45:45 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 16:57:15 + * @LastEditTime: 2022-04-28 01:21:14 * @Description: QQ:1801168257 + * @copyright: https://github.com/witersen/ */ namespace SVNAdmin\SVN; -class Rep +class Rep extends Core { + function __construct($authzFileContent, $passwdFileContent) + { + parent::__construct($authzFileContent, $passwdFileContent); + } + /** * 获取某个仓库路径下有权限的用户列表 * @@ -26,7 +32,7 @@ class Rep * [1] => u2 * ) */ - public static function GetRepUserListWithoutPri($authzContent, $repName, $repPath) + function GetRepUserListWithoutPri($authzContent, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -35,13 +41,13 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); return $resultPreg[1]; } @@ -74,7 +80,7 @@ class Rep * ) * ) */ - public static function GetRepUserListWithPri($authzContent, $repName, $repPath) + function GetRepUserListWithPri($authzContent, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -83,13 +89,13 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); $result = []; @@ -123,7 +129,7 @@ class Rep * [1] => g2 * ) */ - public static function GetRepGroupListWithoutPri($authzContent, $repName, $repPath) + function GetRepGroupListWithoutPri($authzContent, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -132,13 +138,13 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); return $resultPreg[1]; } @@ -171,7 +177,7 @@ class Rep * ) * ) */ - public static function GetRepGroupListWithPri($authzContent, $repName, $repPath) + function GetRepGroupListWithPri($authzContent, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -180,13 +186,13 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); $result = []; @@ -212,7 +218,7 @@ class Rep * 0 不存在该仓库路径的记录 * string 正常 */ - public static function SetRepUserPri($authzContent, $user, $privilege, $repName, $repPath) + function SetRepUserPri($authzContent, $user, $privilege, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -221,7 +227,7 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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)) { @@ -229,12 +235,12 @@ class Rep 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); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); array_walk($resultPregGroup[1], 'FunArrayValueTrim'); array_walk($resultPregGroup[2], 'FunArrayValueTrim'); @@ -287,7 +293,7 @@ class Rep * 1 已删除 * string 正常 */ - public static function DelRepUserPri($authzContent, $user, $repName, $repPath) + function DelRepUserPri($authzContent, $user, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -296,19 +302,19 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); array_walk($resultPregGroup[1], 'FunArrayValueTrim'); array_walk($resultPregGroup[2], 'FunArrayValueTrim'); @@ -345,7 +351,7 @@ class Rep * 0 不存在该仓库路径的记录 * string 正常 */ - public static function UpdRepUserPri($authzContent, $user, $privilege, $repName, $repPath) + function UpdRepUserPri($authzContent, $user, $privilege, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -354,19 +360,19 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_GROUP_PRI, $authzContentPreg[1][0], $resultPregGroup); array_walk($resultPregGroup[1], 'FunArrayValueTrim'); array_walk($resultPregGroup[2], 'FunArrayValueTrim'); @@ -402,7 +408,7 @@ class Rep * 0 不存在该仓库路径的记录 * string 正常 */ - public static function SetRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) + function SetRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -411,19 +417,19 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); @@ -476,7 +482,7 @@ class Rep * 1 已删除 * string 正常 */ - public static function DelRepGroupPri($authzContent, $group, $repName, $repPath) + function DelRepGroupPri($authzContent, $group, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -485,19 +491,19 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); @@ -536,7 +542,7 @@ class Rep * 1 该仓库下不存在该分组 * string 正常 */ - public static function UpdRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) + function UpdRepGroupPri($authzContent, $group, $privilege, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -545,19 +551,19 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); @@ -595,7 +601,7 @@ class Rep * 1 已存在 * string 正常 */ - public static function SetRepAuthz($authzContent, $repName, $repPath) + function SetRepAuthz($authzContent, $repName, $repPath) { //处理路径结尾 if ($repPath != '/') { @@ -604,7 +610,7 @@ class Rep } } - preg_match_all(sprintf(REG_AUTHZ_REP_SPECIAL_PATH_WITHOUT_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->REG_AUTHZ_REP_SPECIAL_PATH_WITHOUT_CON, $repName, str_replace('/', '\/', $repPath)), $authzContent, $authzContentPreg); if (array_key_exists(0, $authzContentPreg[0])) { return '1'; } else { @@ -618,9 +624,9 @@ class Rep * 1 已删除 * string 正常 */ - public static function DelRepAuthz($authzContent, $repName) + function DelRepAuthz($authzContent, $repName) { - preg_match_all(sprintf(REG_AUTHZ_REP_ALL_PATH_WITH_CON, $repName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); @@ -642,9 +648,9 @@ class Rep * 正常数据 * */ - public static function GetNoPathAndConRepAuthz($authzContent) + function GetNoPathAndConRepAuthz($authzContent) { - preg_match_all(REG_AUTHZ_ALL_REP_WITHOUT_PATH_AND_CON, $authzContent, $authzContentPreg); + preg_match_all($this->REG_AUTHZ_ALL_REP_WITHOUT_PATH_AND_CON, $authzContent, $authzContentPreg); array_walk($authzContentPreg[1], 'FunArrayValueTrim'); return array_values(array_unique($authzContentPreg[1])); } @@ -658,9 +664,9 @@ class Rep * 1 仓库不存在 * string 正常 */ - public static function UpdRepAuthz($authzContent, $oldRepName, $newRepName) + function UpdRepAuthz($authzContent, $oldRepName, $newRepName) { - preg_match_all(sprintf(REG_AUTHZ_REP_ALL_PATH_WITHOUT_CON, $oldRepName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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); @@ -693,10 +699,10 @@ class Rep * ) * ) */ - public static function GetAllHavePriRepListWithPri($authzContent) + function GetAllHavePriRepListWithPri($authzContent) { $userName = '*'; - preg_match_all(sprintf(REG_AUTHZ_ALL_HAVE_PRI_REPS, $userName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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'); @@ -727,10 +733,10 @@ class Rep * [1] => rep2 * ) */ - public static function GetAllHavePriRepListWithoutPri($authzContent) + function GetAllHavePriRepListWithoutPri($authzContent) { $userName = '*'; - preg_match_all(sprintf(REG_AUTHZ_ALL_HAVE_PRI_REPS, $userName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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'); @@ -748,10 +754,10 @@ class Rep * 获取所有用户都无权限的仓库列表 * 用户匹配 *= */ - public static function GetAllNoPriRepListWithoutPri($authzContent) + function GetAllNoPriRepListWithoutPri($authzContent) { $userName = '*'; - preg_match_all(sprintf(REG_AUTHZ_ALL_NO_PRI_REPS, $userName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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'); @@ -770,7 +776,7 @@ class Rep /** * 获取SVN仓库列表 */ - public static function GetRepList() + function GetRepList() { $repArray = []; $file_arr = scandir(SVN_REPOSITORY_PATH); @@ -798,7 +804,7 @@ class Rep /** * 获取简单SVN仓库列表 */ - public static function GetSimpleRepList() + function GetSimpleRepList() { $repArray = []; $file_arr = scandir(SVN_REPOSITORY_PATH); @@ -821,7 +827,7 @@ class Rep /** * 初始化仓库结构为 trunk branches tags */ - public static function InitRepStruct($repName, $initUser = "SVNAdmin", $initPass = "SVNAdmin") + function InitRepStruct($repName, $initUser = "SVNAdmin", $initPass = "SVNAdmin") { $randPrefix = FunGetRandStr(); $tempPath = TEMP_PATH . $randPrefix; @@ -853,7 +859,7 @@ class Rep * FSFS Shards Packed * FSFS Logical Addressing */ - public static function GetRepInfo($repName) + function GetRepInfo($repName) { $repPath = SVN_REPOSITORY_PATH . $repName; @@ -861,7 +867,7 @@ class Rep $cmdResult = FunShellExec($svnadminInfoCmd); - preg_match_all(REG_REP_INFO, $cmdResult, $svnadminInfoPreg); + preg_match_all($this->REG_REP_INFO, $cmdResult, $svnadminInfoPreg); $svnadminInfoResult = array_combine($svnadminInfoPreg[1], $svnadminInfoPreg[2]); @@ -873,7 +879,7 @@ class Rep /** * 使用 svnlook tree $repPath 获取仓库的最新版本的目录树 */ - public static function GetRepTree($repName) + function GetRepTree($repName) { $repPath = SVN_REPOSITORY_PATH . $repName; $svnadminInfoCmd = sprintf("svnlook tree '%s'", $repPath); @@ -1016,7 +1022,7 @@ class Rep * ) * ) */ - public static function GetFolderStruct($complateArray, $fileIndex) + function GetFolderStruct($complateArray, $fileIndex) { //获取当前文件夹的目录内容 以子文件夹和子文件下标的形式返回 $dirContent = self::GetFolderDirAndFiles($complateArray, $fileIndex); @@ -1112,7 +1118,7 @@ class Rep * [3] => 8 * ) */ - public static function GetFolderDirAndFiles($complateArray, $fileIndex) + function GetFolderDirAndFiles($complateArray, $fileIndex) { $result = []; //末尾 @@ -1144,7 +1150,7 @@ class Rep /** * 检查仓库是否存在或者是否存在同名的文件夹 */ - public static function CheckRepExist($repName, $message = '仓库已经存在') + function CheckRepExist($repName, $message = '仓库已经存在') { clearstatcache(); if (is_dir(SVN_REPOSITORY_PATH . $repName)) { @@ -1155,7 +1161,7 @@ class Rep /** * 检查仓库是否创建成功 */ - public static function CheckRepCreate($repName, $message = '仓库创建失败') + function CheckRepCreate($repName, $message = '仓库创建失败') { clearstatcache(); if (!is_dir(SVN_REPOSITORY_PATH . $repName)) { @@ -1166,7 +1172,7 @@ class Rep /** * 检查仓库是否删除成功 */ - public static function CheckRepDelete($repName, $message = '仓库删除失败') + function CheckRepDelete($repName, $message = '仓库删除失败') { clearstatcache(); if (is_dir(SVN_REPOSITORY_PATH . $repName)) { @@ -1177,7 +1183,7 @@ class Rep /** * 获取仓库的修订版本数量 */ - public static function GetRepRev($repName) + function GetRepRev($repName) { $cmd = sprintf("svnadmin info '%s' | grep 'Revisions' | awk '{print $2}'", SVN_REPOSITORY_PATH . $repName); return (int)trim(FunShellExec($cmd)); @@ -1186,7 +1192,7 @@ class Rep /** * 获取仓库的属性内容(key-vlaue的形式) */ - public static function GetRepDetail($repName) + function GetRepDetail($repName) { $cmd = sprintf("svnadmin info '%s'", SVN_REPOSITORY_PATH . $repName); return trim(FunShellExec($cmd)); @@ -1199,7 +1205,7 @@ class Rep * * 根据体积大小自动调整单位 */ - public static function GetRepRevFileSize($repName, $filePath) + function GetRepRevFileSize($repName, $filePath) { $cmd = sprintf("svnlook filesize '%s' '%s'", SVN_REPOSITORY_PATH . $repName, $filePath); $size = (int)trim(FunShellExec($cmd)); @@ -1209,7 +1215,7 @@ class Rep /** * 获取仓库下指定文件或者文件夹的最高修订版本 */ - public static function GetRepFileRev($repName, $filePath) + function GetRepFileRev($repName, $filePath) { $cmd = sprintf("svnlook history --limit 1 '%s' '%s'", SVN_REPOSITORY_PATH . $repName, $filePath); $result = FunShellExec($cmd); @@ -1222,7 +1228,7 @@ class Rep /** * 获取仓库下指定文件或者文件夹的作者 */ - public static function GetRepFileAuthor($repName, $rev) + function GetRepFileAuthor($repName, $rev) { $cmd = sprintf("svnlook author -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); $result = FunShellExec($cmd); @@ -1232,7 +1238,7 @@ class Rep /** * 获取仓库下指定文件或者文件夹的提交日期 */ - public static function GetRepFileDate($repName, $rev) + function GetRepFileDate($repName, $rev) { $cmd = sprintf("svnlook date -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); $result = FunShellExec($cmd); @@ -1242,7 +1248,7 @@ class Rep /** * 获取仓库下指定文件或者文件夹的提交日志 */ - public static function GetRepFileLog($repName, $rev) + function GetRepFileLog($repName, $rev) { $cmd = sprintf("svnlook log -r %s '%s'", $rev, SVN_REPOSITORY_PATH . $repName); $result = FunShellExec($cmd); @@ -1254,7 +1260,7 @@ class Rep * * 默认为全版本 */ - public static function RepDump($repName, $backupName) + function RepDump($repName, $backupName) { $cmd = sprintf('svnadmin dump %s --quiet > %s', SVN_REPOSITORY_PATH . $repName, SVN_BACHUP_PATH . $backupName); FunShellExec($cmd); @@ -1263,7 +1269,7 @@ class Rep /** * 删除备份文件 */ - public static function DelRepBackup($fileName) + function DelRepBackup($fileName) { $cmd = sprintf("cd '%s' && rm -f './%s'", SVN_BACHUP_PATH, $fileName); FunShellExec($cmd); @@ -1272,7 +1278,7 @@ class Rep /** * 使用 svnadmin load 导入仓库 */ - public static function RepLoad($repName, $fileName) + function RepLoad($repName, $fileName) { $cmd = sprintf("svnadmin load --quiet '%s' < '%s'", SVN_REPOSITORY_PATH . $repName, SVN_BACHUP_PATH . $fileName); $result = FunShellExec($cmd); @@ -1282,7 +1288,7 @@ class Rep /** * 使用 svn list 为用户检查指令 */ - public static function CheckSvnUserPathAutzh($checkoutHost, $repName, $repPath, $svnUserName, $svnUserPass) + 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); diff --git a/02.php/app/util/SVNUser.util.php b/02.php/extension/SVNAdmin/src/class/SVNUser.class.php similarity index 77% rename from 02.php/app/util/SVNUser.util.php rename to 02.php/extension/SVNAdmin/src/class/SVNUser.class.php index 3ba93ef..b0f160e 100644 --- a/02.php/app/util/SVNUser.util.php +++ b/02.php/extension/SVNAdmin/src/class/SVNUser.class.php @@ -3,14 +3,20 @@ * @Author: witersen * @Date: 2022-04-27 15:57:48 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 16:58:51 + * @LastEditTime: 2022-04-28 01:21:18 * @Description: QQ:1801168257 + * @copyright: https://github.com/witersen/ */ namespace SVNAdmin\SVN; -class User +class User extends Core { + function __construct($authzFileContent, $passwdFileContent) + { + parent::__construct($authzFileContent, $passwdFileContent); + } + /** * 不提供修改SVN用户名称的方法 * 一个不变的用户对应SVN仓库所有的历史记录是非常有必要的 @@ -23,18 +29,18 @@ class User * 1 用户已存在 * string 正常 */ - public static function AddSvnUser($passwdContent, $userName, $userPass) + function AddSvnUser($passwdContent, $userName, $userPass) { $userName = trim($userName); $userPass = trim($userPass); - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + preg_match_all($this->REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); if (array_key_exists(0, $passwdContentPreg[1])) { $temp1 = trim($passwdContentPreg[1][0]); if (empty($temp1)) { $userStr = "\n$userName=$userPass\n"; return $passwdContent . $userStr; } else { - preg_match_all(sprintf(REG_PASSWD_USER_PASSWD, REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[3], 'FunArrayValueTrim'); @@ -59,7 +65,7 @@ class User /** * 修改SVN用户(passwd文件中) */ - public static function UpdSvnUserPasswd($passwdContent, $oldUserName, $newUserName) + function UpdSvnUserPasswd($passwdContent, $oldUserName, $newUserName) { //不提供此方法 } @@ -71,17 +77,17 @@ class User * 1 用户不存在 * string 正常 */ - public static function DelSvnUserPasswd($passwdContent, $userName, $isDisabledUser = false) + 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); + $userName = $isDisabledUser ? ($this->REG_SVN_USER_DISABLED . $userName) : $userName; + preg_match_all($this->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); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[3], 'FunArrayValueTrim'); if (in_array($userName, $resultPreg[1])) { @@ -127,21 +133,21 @@ class User * * ) */ - public static function GetSvnUserList($passwdContent) + function GetSvnUserList($passwdContent) { - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + preg_match_all($this->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); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->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)); + if (substr($value, 0, strlen($this->REG_SVN_USER_DISABLED)) == $this->REG_SVN_USER_DISABLED) { + $item['userName'] = substr($value, strlen($this->REG_SVN_USER_DISABLED)); $item['disabled'] = '1'; } else { $item['userName'] = $value; @@ -184,22 +190,22 @@ class User * * ) */ - public static function GetSvnUserPassList($passwdContent) + function GetSvnUserPassList($passwdContent) { - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + preg_match_all($this->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); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->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)); + if (substr($userName, 0, strlen($this->REG_SVN_USER_DISABLED)) == $this->REG_SVN_USER_DISABLED) { + $item['userName'] = substr($userName, strlen($this->REG_SVN_USER_DISABLED)); $item['userPass'] = $userPass; $item['disabled'] = '1'; } else { @@ -223,17 +229,17 @@ class User * 1 用户不存在 * string 正常 */ - public static function GetPassByUser($passwdContent, $userName, $isDisabledUser = false) + 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); + $userName = $isDisabledUser ? ($this->REG_SVN_USER_DISABLED . $userName) : $userName; + preg_match_all($this->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); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->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) { @@ -254,18 +260,18 @@ class User * 1 用户不存在 * string 正常 */ - public static function UpdSvnUserPass($passwdContent, $userName, $userPass, $isDisabledUser = false) + 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); + $userName = $isDisabledUser ? ($this->REG_SVN_USER_DISABLED . $userName) : $userName; + preg_match_all($this->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); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->REG_SVN_USER_DISABLED), $passwdContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[3], 'FunArrayValueTrim'); if (in_array($userName, $resultPreg[1])) { @@ -300,16 +306,16 @@ class User * [1] => group * ) */ - public static function GetSvnUserGroupList($authzContent, $userName) + function GetSvnUserGroupList($authzContent, $userName) { $userName = trim($userName); - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_USER_PRI, $authzContentPreg[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); $userArray = []; @@ -341,10 +347,10 @@ class User * [1] => rep2 * ) */ - public static function GetUserPriRepListWithoutPri($authzContent, $userName) + function GetUserPriRepListWithoutPri($authzContent, $userName) { $userName = trim($userName); - preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); if (array_key_exists(0, $authzContentPreg[1])) { array_walk($authzContentPreg[1], 'FunArrayValueTrim'); return $authzContentPreg[1]; @@ -374,10 +380,10 @@ class User * ) * ) */ - public static function GetUserPriRepListWithPri($authzContent, $userName) + function GetUserPriRepListWithPri($authzContent, $userName) { $userName = trim($userName); - preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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'); @@ -417,10 +423,10 @@ class User * ) * ) */ - public static function GetUserPriRepListWithPriAndPath($authzContent, $userName) + function GetUserPriRepListWithPriAndPath($authzContent, $userName) { $userName = trim($userName); - preg_match_all(sprintf(REG_AUTHZ_USER_PRI_REPS, $userName), $authzContent, $authzContentPreg); + preg_match_all(sprintf($this->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'); @@ -445,7 +451,7 @@ class User * * string 正常 */ - public static function UpdUserAuthz($authzContent, $oldUserName, $newUserName) + function UpdUserAuthz($authzContent, $oldUserName, $newUserName) { } @@ -457,16 +463,16 @@ class User * 0 文件格式错误(不存在[users]标识) * string 正常 */ - public static function DelUserAuthz($authzContent, $userName) + function DelUserAuthz($authzContent, $userName) { $userName = trim($userName); $content1 = "[groups]\n"; $content2 = ""; - preg_match_all(REG_AUTHZ_GROUP_WITH_CON, $authzContent, $authzContentPreg1); + preg_match_all($this->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); + preg_match_all($this->REG_AUTHZ_USER_PRI, $authzContentPreg1[1][0], $resultPreg); array_walk($resultPreg[1], 'FunArrayValueTrim'); array_walk($resultPreg[2], 'FunArrayValueTrim'); $groupContent = ""; @@ -494,23 +500,23 @@ class User * 1 要禁用的用户不存在 * string 正常 */ - public static function DisabledUser($passwdContent, $userName) + function DisabledUser($passwdContent, $userName) { $userName = trim($userName); - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + preg_match_all($this->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); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->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; + $key = $this->REG_SVN_USER_DISABLED . $key; } $resultStr .= "$key=$value\n"; } @@ -529,22 +535,22 @@ class User * 1 要启用的用户不存在 * string 正常 */ - public static function EnabledUser($passwdContent, $userName) + function EnabledUser($passwdContent, $userName) { $userName = trim($userName); - preg_match_all(REG_PASSWD_USER_WITH_CON, $passwdContent, $passwdContentPreg); + preg_match_all($this->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); + preg_match_all(sprintf($this->REG_PASSWD_USER_PASSWD, $this->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])) { + if (in_array($this->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) { + if ($key == $this->REG_SVN_USER_DISABLED . $userName) { $key = $userName; } $resultStr .= "$key=$value\n"; diff --git a/02.php/extension/SVNAdmin/src/core/Core.class.php b/02.php/extension/SVNAdmin/src/core/Core.class.php new file mode 100644 index 0000000..cdb3d7d --- /dev/null +++ b/02.php/extension/SVNAdmin/src/core/Core.class.php @@ -0,0 +1,212 @@ + $group + * + * @var string + */ + protected $REG_AUTHZ_GROUP_PRI_REPS = "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?@%s[\s]*=[\s]*([rw]+)$\n/m"; + + /** + * 匹配authz配置文件中某个用户有权限的仓库列表 + * + * %s => $user + * + * @var string + */ + protected $REG_AUTHZ_USER_PRI_REPS = "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?%s[\s]*=[\s]*([rw]+)$\n/m"; + + + /** + * 匹配authz配置文件中所有用户有权限的仓库列表 + * + * *=r、*=rw + * + * @var string + */ + protected $REG_AUTHZ_ALL_HAVE_PRI_REPS = "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*([rw]+)$\n/m"; + + + /** + * 匹配authz配置文件中所有用户无权限的仓库列表 + * + * *= + * + * @var string + */ + protected $REG_AUTHZ_ALL_NO_PRI_REPS = "/^\[(.*?):(.*?)\][A-za-z0-9_=@*\s]*?\*[\s]*=[\s]*$\n/m"; + + /** + * 匹配通过魔力符号配置的相关信息 + * + * 包含 ~ $等前缀 + */ + //todo + + /** + * 匹配authz配置文件中指定仓库的指定路径 包含内容 + * + * [rep1:/floder] + * u1=r + * @g1=rw + * + * %s => $repName + * %s => $repPath + * + * @var string + */ + protected $REG_AUTHZ_REP_SPECIAL_PATH_WITH_CON = "/^\[%s:%s\]([\s\S][^\[]*)/m"; + + /** + * 匹配authz配置文件中指定仓库的指定路径 不包含内容 + * + * 如 + * [rep1:/] + * 或 + * [rep2:/floder] + * 等 + * + * %s => $repName + * %s => $repPaht str_replace('/', '\/', $repPath) + * + * @var string + */ + protected $REG_AUTHZ_REP_SPECIAL_PATH_WITHOUT_CON = "/^\[%s:%s\]/m"; + + /** + * 匹配authz配置文件中指定仓库的所有路径 不包含内容 + * + * %s => $repName + * + * @var string + */ + protected $REG_AUTHZ_REP_ALL_PATH_WITHOUT_CON = "/^\[%s:(.*?)\]/m"; + + /** + * 匹配authz配置文件中指定仓库的所有路径以及包含的内容 + * + * %s => $repName + * + * @var string + */ + protected $REG_AUTHZ_REP_ALL_PATH_WITH_CON = "/^\[%s:.*\][\s\S][^\[]*/m"; + + /** + * 匹配authz配置文件中的所有仓库名称 + * + * 不匹配这些仓库的内容和具体路径 + * + * @var string + */ + protected $REG_AUTHZ_ALL_REP_WITHOUT_PATH_AND_CON = "/^\[(.*?):.*?\]/m"; + + /** + * 将 svnadmin info $repPaht 的结果匹配为 key => value 形式 + * + * @var string + */ + protected $REG_REP_INFO = "/(.*):[\S]*(.*)/m"; + + + function __construct($authzFileContent, $passwdFileContent) + { + $this->authzFileContent = $authzFileContent; + $this->passwdFileContent = $passwdFileContent; + } +} diff --git a/02.php/server/svnadmind.php b/02.php/server/svnadmind.php index 2dc3cdb..e153492 100644 --- a/02.php/server/svnadmind.php +++ b/02.php/server/svnadmind.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:06 * @LastEditors: witersen - * @LastEditTime: 2022-04-27 11:34:42 + * @LastEditTime: 2022-04-28 02:22:01 * @Description: QQ:1801168257 */ @@ -140,7 +140,7 @@ class Daemon $this->workMode == 'console' ? print_r(PHP_EOL . '---------result---------' . PHP_EOL . $result . PHP_EOL) : ''; //处理没有返回内容的情况 否则 socket_write 遇到空内容会报错 - $result = $result == '' ? ISNULL : $result; + $result = trim($result) == '' ? ISNULL : trim($result); //将结果返回给客户端 socket_write($client, $result, strlen($result)) or die('启动失败:socket_write 错误' . PHP_EOL);