Browse Source

1、修改用户权限匹配正则失误的bug2、封装关于仓库操作的静态类

docker-svn
witersen 3 years ago
parent
commit
49b31cd77a
  1. 6
      02.php/app/controller/personal.class.php
  2. 11
      02.php/app/controller/statistics.class.php
  3. 6
      02.php/app/controller/subversion.class.php
  4. 42
      02.php/app/controller/svngroup.class.php
  5. 106
      02.php/app/controller/svnrep.class.php
  6. 20
      02.php/app/controller/svnuser.class.php
  7. 11
      02.php/app/core/controller.class.php
  8. 35
      02.php/app/function/config.function.php
  9. 74
      02.php/app/function/subversion.function.php
  10. 690
      02.php/app/function/svnGroup.function.php
  11. 10
      02.php/app/function/svnHooks.function.php
  12. 1298
      02.php/app/function/svnRep.function.php
  13. 555
      02.php/app/function/svnUser.function.php
  14. 24
      02.php/app/model/util.model.php
  15. 695
      02.php/app/util/SVNGroup.util.php
  16. 14
      02.php/app/util/SVNHooks.util.php
  17. 79
      02.php/app/util/SVNInfo.util.php
  18. 1303
      02.php/app/util/SVNRep.util.php
  19. 560
      02.php/app/util/SVNUser.util.php
  20. 19
      02.php/config/reg.config.php

6
02.php/app/controller/personal.class.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-26 16:57:23 * @LastEditTime: 2022-04-27 16:40:15
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -84,7 +84,7 @@ class personal extends controller
} }
//获取SVN指定用户的密码 //获取SVN指定用户的密码
$result = FunGetPassByUser($this->globalPasswdContent, $this->globalUserName); $result = \SVNAdmin\SVN\User::GetPassByUser($this->globalPasswdContent, $this->globalUserName);
if ($result == '0') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} }
@ -101,7 +101,7 @@ class personal extends controller
} }
//修改SVN指定用户的密码 //修改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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} }

11
02.php/app/controller/statistics.class.php

@ -3,10 +3,13 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-27 11:56:45 * @LastEditTime: 2022-04-27 16:55:37
* @Description: QQ:1801168257 * @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)); $backupSize = FunFormatSize(FunGetDirSizeDu(SVN_BACHUP_PATH));
//SVN仓库数量 //SVN仓库数量
$repCount = count(FunGetSimpleRepList()); $repCount = count(\SVNAdmin\SVN\Rep::GetSimpleRepList());
//SVN用户数量 //SVN用户数量
$userCount = count(FunGetSvnUserList(SVN_PASSWD_FILE)); $userCount = count(\SVNAdmin\SVN\User::GetSvnUserList(SVN_PASSWD_FILE));
//SVN分组数量 //SVN分组数量
$groupCount = count(FunGetSvnGroupList(SVN_AUTHZ_FILE)); $groupCount = count(\SVNAdmin\SVN\Group::GetSvnGroupList(SVN_AUTHZ_FILE));
//运行日志数量 //运行日志数量
$logCount = $this->database->count('logs', ['log_id[>]' => 0]); $logCount = $this->database->count('logs', ['log_id[>]' => 0]);

6
02.php/app/controller/subversion.class.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-27 15:20:52 * @LastEditTime: 2022-04-27 17:59:25
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -43,7 +43,7 @@ class subversion extends controller
*/ */
function GetCheckout() function GetCheckout()
{ {
$result = FunGetSubversionListen(); $result = \SVNAdmin\SVN\Info::GetSubversionListen();
$checkoutHost = $result[$result['enable']]; $checkoutHost = $result[$result['enable']];
if ($result['bindPort'] != '3690') { if ($result['bindPort'] != '3690') {
$checkoutHost .= ':' . $result['bindPort']; $checkoutHost .= ':' . $result['bindPort'];
@ -60,7 +60,7 @@ class subversion extends controller
function GetDetail() function GetDetail()
{ {
//获取绑定主机、端口等信息 //获取绑定主机、端口等信息
$bindInfo = FunGetSubversionListen(); $bindInfo = \SVNAdmin\SVN\Info::GetSubversionListen();
//检测运行信息 //检测运行信息
$runInfo = FunShellExec('ps auxf|grep -v "grep"|grep svnserve'); $runInfo = FunShellExec('ps auxf|grep -v "grep"|grep svnserve');

42
02.php/app/controller/svngroup.class.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-26 16:57:46 * @LastEditTime: 2022-04-27 16:40:48
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -28,7 +28,7 @@ class svngroup extends controller
*/ */
function SyncGroupToDb() function SyncGroupToDb()
{ {
$svnAndGroupList = FunGetSvnGroupUserAndGroupList($this->globalAuthzContent); $svnAndGroupList = \SVNAdmin\SVN\Group::GetSvnGroupUserAndGroupList($this->globalAuthzContent);
@ -83,7 +83,7 @@ class svngroup extends controller
*/ */
function GetAllGroupList() function GetAllGroupList()
{ {
$svnGroupList = FunGetSvnGroupList($this->globalAuthzContent); $svnGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent);
if ($svnGroupList == '0') { if ($svnGroupList == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
} else { } else {
@ -171,7 +171,7 @@ class svngroup extends controller
FunCheckRepGroup($this->requestPayload['svn_group_name']); 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
} }
@ -199,7 +199,7 @@ class svngroup extends controller
function DelGroup() function DelGroup()
{ {
//从authz文件删除 //从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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
@ -226,7 +226,7 @@ class svngroup extends controller
//新分组名称是否合法 //新分组名称是否合法
FunCheckRepGroup($this->requestPayload['groupNameNew']); FunCheckRepGroup($this->requestPayload['groupNameNew']);
$svnGroupList = FunGetSvnGroupList($this->globalAuthzContent); $svnGroupList = \SVNAdmin\SVN\Group::GetSvnGroupList($this->globalAuthzContent);
//旧分组是否存在 //旧分组是否存在
if (!in_array($this->requestPayload['groupNameOld'], $svnGroupList)) { if (!in_array($this->requestPayload['groupNameOld'], $svnGroupList)) {
@ -238,7 +238,7 @@ class svngroup extends controller
FunMessageExit(200, 0, '要修改的分组名称已经存在'); 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
} }
@ -253,13 +253,13 @@ class svngroup extends controller
*/ */
function GetGroupMember() 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') { if ($memberUserList == '0' || $memberGroupList == '0' || $allGroupList == '0' || $allUserList == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
@ -317,7 +317,7 @@ class svngroup extends controller
*/ */
function GroupAddUser() 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
} }
@ -338,7 +338,7 @@ class svngroup extends controller
*/ */
function GroupRemoveUser() 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
} }
@ -359,7 +359,7 @@ class svngroup extends controller
*/ */
function GroupAddGroup() 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
} }
@ -391,7 +391,7 @@ class svngroup extends controller
*/ */
function GroupRemoveGroup() 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[groups]标识)');
} }
@ -424,10 +424,10 @@ class svngroup extends controller
$authzContent = $this->globalAuthzContent; $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); $leftGroupList = array_diff($allGroupList, $userGroupList);
@ -436,7 +436,7 @@ class svngroup extends controller
loop: loop:
$userGroupListBack = $userGroupList; $userGroupListBack = $userGroupList;
foreach ($userGroupList as $group1) { foreach ($userGroupList as $group1) {
$newList = FunGetSvnGroupGroupList($authzContent, $group1); $newList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $group1);
foreach ($leftGroupList as $key2 => $group2) { foreach ($leftGroupList as $key2 => $group2) {
if (in_array($group2, $newList)) { if (in_array($group2, $newList)) {
array_push($userGroupList, $group2); array_push($userGroupList, $group2);
@ -469,10 +469,10 @@ class svngroup extends controller
$authzContent = $this->globalAuthzContent; $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); $leftGroupList = array_diff($allGroupList, $groupGroupList);
@ -481,7 +481,7 @@ class svngroup extends controller
loop: loop:
$userGroupListBack = $groupGroupList; $userGroupListBack = $groupGroupList;
foreach ($groupGroupList as $group1) { foreach ($groupGroupList as $group1) {
$newList = FunGetSvnGroupGroupList($authzContent, $group1); $newList = \SVNAdmin\SVN\Group::GetSvnGroupGroupList($authzContent, $group1);
foreach ($leftGroupList as $key2 => $group2) { foreach ($leftGroupList as $key2 => $group2) {
if (in_array($group2, $newList)) { if (in_array($group2, $newList)) {
array_push($groupGroupList, $group2); array_push($groupGroupList, $group2);

106
02.php/app/controller/svnrep.class.php

@ -3,10 +3,12 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-27 02:06:19 * @LastEditTime: 2022-04-27 18:03:13
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
use SVNAdmin\SVNRep\SVNRep as SVNRepSVNRep;
class svnrep extends controller class svnrep extends controller
{ {
private $Svngorup; private $Svngorup;
@ -40,7 +42,7 @@ class svnrep extends controller
FunCheckRepName($this->requestPayload['rep_name']); 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') { 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写入仓库信息 //向authz写入仓库信息
$status = FunSetRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name'], '/'); $status = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name'], '/');
if ($status != '1') { if ($status != '1') {
FunShellExec('echo \'' . $status . '\' > ' . SVN_AUTHZ_FILE); FunShellExec('echo \'' . $status . '\' > ' . SVN_AUTHZ_FILE);
} }
@ -80,7 +82,7 @@ class svnrep extends controller
*/ */
function SyncRepAndDb() function SyncRepAndDb()
{ {
$svnRepList = FunGetSimpleRepList(); $svnRepList = \SVNAdmin\SVN\Rep::GetSimpleRepList();
$dbRepList = $this->database->select('svn_reps', [ $dbRepList = $this->database->select('svn_reps', [
'rep_name', 'rep_name',
@ -95,7 +97,7 @@ class svnrep extends controller
//更新 //更新
$this->database->update('svn_reps', [ $this->database->update('svn_reps', [
'rep_size' => FunGetDirSizeDu(SVN_REPOSITORY_PATH . $value['rep_name']), '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'] 'rep_name' => $value['rep_name']
]); ]);
@ -108,7 +110,7 @@ class svnrep extends controller
'rep_name' => $value, 'rep_name' => $value,
'rep_size' => FunGetDirSizeDu(SVN_REPOSITORY_PATH . $value), 'rep_size' => FunGetDirSizeDu(SVN_REPOSITORY_PATH . $value),
'rep_note' => '', 'rep_note' => '',
'rep_rev' => FunGetRepRev($value), 'rep_rev' => \SVNAdmin\SVN\Rep::GetRepRev($value),
'rep_uuid' => '' 'rep_uuid' => ''
]); ]);
} }
@ -123,15 +125,15 @@ class svnrep extends controller
*/ */
function SyncRepAndAuthz() function SyncRepAndAuthz()
{ {
$svnRepList = FunGetSimpleRepList(); $svnRepList = \SVNAdmin\SVN\Rep::GetSimpleRepList();
$svnRepAuthzList = FunGetNoPathAndConRepAuthz($this->globalAuthzContent); $svnRepAuthzList = \SVNAdmin\SVN\Rep::GetNoPathAndConRepAuthz($this->globalAuthzContent);
$authzContet = $this->globalAuthzContent; $authzContet = $this->globalAuthzContent;
foreach ($svnRepList as $key => $value) { foreach ($svnRepList as $key => $value) {
if (!in_array($value, $svnRepAuthzList)) { if (!in_array($value, $svnRepAuthzList)) {
$authzContet = FunSetRepAuthz($authzContet, $value, '/'); $authzContet = \SVNAdmin\SVN\Rep::SetRepAuthz($authzContet, $value, '/');
if ($authzContet == '1') { if ($authzContet == '1') {
FunMessageExit(200, 0, '同步到配置文件错误'); FunMessageExit(200, 0, '同步到配置文件错误');
} }
@ -140,7 +142,7 @@ class svnrep extends controller
foreach ($svnRepAuthzList as $key => $value) { foreach ($svnRepAuthzList as $key => $value) {
if (!in_array($value, $svnRepList)) { if (!in_array($value, $svnRepList)) {
$authzContet = FunDelRepAuthz($authzContet, $value); $authzContet = \SVNAdmin\SVN\Rep::DelRepAuthz($authzContet, $value);
if ($authzContet == '1') { if ($authzContet == '1') {
FunMessageExit(200, 0, '同步到配置文件错误'); FunMessageExit(200, 0, '同步到配置文件错误');
} }
@ -162,14 +164,14 @@ class svnrep extends controller
$userRepList = []; $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); $userGroupList = $this->Svngorup->GetSvnUserAllGroupList($this->globalUserName);
//获取分组有权限的仓库路径列表 //获取分组有权限的仓库路径列表
foreach ($userGroupList as $value) { 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用户的身份来进行被授权过的路径的内容浏览 * 目的为使用当前SVN用户的身份来进行被授权过的路径的内容浏览
*/ */
$bindInfo = FunGetSubversionListen(); $bindInfo = \SVNAdmin\SVN\Info::GetSubversionListen();
$checkoutHost = 'svn://' . $bindInfo['bindHost']; $checkoutHost = 'svn://' . $bindInfo['bindHost'];
if ($bindInfo['bindPort'] != '3690') { if ($bindInfo['bindPort'] != '3690') {
$checkoutHost = 'svn://' . $bindInfo['bindHost'] . ':' . $bindInfo['bindPort']; $checkoutHost = 'svn://' . $bindInfo['bindHost'] . ':' . $bindInfo['bindPort'];
} }
//获取SVN用户密码 //获取SVN用户密码
$svnUserPass = FunGetPassByUser($this->globalPasswdContent, $this->globalUserName); $svnUserPass = \SVNAdmin\SVN\User::GetPassByUser($this->globalPasswdContent, $this->globalUserName);
if ($svnUserPass == '0') { if ($svnUserPass == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} else if ($svnUserPass == '1') { } else if ($svnUserPass == '1') {
@ -392,7 +394,7 @@ class svnrep extends controller
FunMessageExit(200, 0, '密码错误'); FunMessageExit(200, 0, '密码错误');
} }
if (strstr($result, 'svn: E170001: Authorization failed')) { 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')) { if (strstr($result, 'svn: E170013: Unable to connect to a repository at URL')) {
FunMessageExit(200, 0, '其它错误'); 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 = explode('/', $value);
$pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter')); $pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter'));
@ -440,7 +442,7 @@ class svnrep extends controller
array_push($data, [ array_push($data, [
'resourceType' => 1, 'resourceType' => 1,
'resourceName' => $pathArray[$pathArrayCount - 1], 'resourceName' => $pathArray[$pathArrayCount - 1],
'fileSize' => FunGetRepRevFileSize($repName, $value), 'fileSize' => \SVNAdmin\SVN\Rep::GetRepRevFileSize($repName, $value),
'revAuthor' => $lastRevAuthor, 'revAuthor' => $lastRevAuthor,
'revNum' => 'r' . $lastRev, 'revNum' => 'r' . $lastRev,
'revTime' => $lastRevDate, 'revTime' => $lastRevDate,
@ -508,16 +510,16 @@ class svnrep extends controller
$data = []; $data = [];
foreach ($resultArray as $key => $value) { 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 = explode('/', $value);
$pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter')); $pathArray = array_values(array_filter($pathArray, 'FunArrayValueFilter'));
@ -537,7 +539,7 @@ class svnrep extends controller
array_push($data, [ array_push($data, [
'resourceType' => 1, 'resourceType' => 1,
'resourceName' => $pathArray[$pathArrayCount - 1], 'resourceName' => $pathArray[$pathArrayCount - 1],
'fileSize' => FunGetRepRevFileSize($this->requestPayload['rep_name'], $value), 'fileSize' => \SVNAdmin\SVN\Rep::GetRepRevFileSize($this->requestPayload['rep_name'], $value),
'revAuthor' => $lastRevAuthor, 'revAuthor' => $lastRevAuthor,
'revNum' => 'r' . $lastRev, 'revNum' => 'r' . $lastRev,
'revTime' => $lastRevDate, 'revTime' => $lastRevDate,
@ -645,7 +647,7 @@ class svnrep extends controller
*/ */
function GetRepPathUserPri() 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 ($result == '0') {
//没有该路径的记录 //没有该路径的记录
if ($this->requestPayload['path'] == '/') { if ($this->requestPayload['path'] == '/') {
@ -671,7 +673,7 @@ class svnrep extends controller
*/ */
function GetRepPathGroupPri() 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 ($result == '0') {
//没有该路径的记录 //没有该路径的记录
if ($this->requestPayload['path'] == '/') { 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') { if ($result == '0') {
//没有该仓库路径记录 则进行插入 //没有该仓库路径记录 则进行插入
$result = FunSetRepAuthz($this->globalAuthzContent, $repName, $path); $result = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $repName, $path);
if ($result == '1') { if ($result == '1') {
FunMessageExit(200, 1, '未知错误'); FunMessageExit(200, 1, '未知错误');
} }
//重新添加权限 //重新添加权限
$result = FunSetRepUserPri($result, $user, $pri, $repName, $path); $result = \SVNAdmin\SVN\Rep::SetRepUserPri($result, $user, $pri, $repName, $path);
if ($result == '0') { if ($result == '0') {
FunMessageExit(200, 1, '未知错误'); FunMessageExit(200, 1, '未知错误');
@ -754,7 +756,7 @@ class svnrep extends controller
$path = $this->requestPayload['path']; $path = $this->requestPayload['path'];
$user = $this->requestPayload['user']; $user = $this->requestPayload['user'];
$result = FunDelRepUserPri($this->globalAuthzContent, $user, $repName, $path); $result = \SVNAdmin\SVN\Rep::DelRepUserPri($this->globalAuthzContent, $user, $repName, $path);
if ($result == '0') { if ($result == '0') {
FunMessageExit(200, 0, '不存在该仓库路径的记录'); FunMessageExit(200, 0, '不存在该仓库路径的记录');
@ -784,7 +786,7 @@ class svnrep extends controller
*/ */
$pri = $pri == 'no' ? '' : $pri; $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') { if ($result == '0') {
FunMessageExit(200, 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') { if ($result == '0') {
//没有该仓库路径记录 则进行插入 //没有该仓库路径记录 则进行插入
$result = FunSetRepAuthz($this->globalAuthzContent, $repName, $path); $result = \SVNAdmin\SVN\Rep::SetRepAuthz($this->globalAuthzContent, $repName, $path);
if ($result == '1') { if ($result == '1') {
FunMessageExit(200, 1, '未知错误'); FunMessageExit(200, 1, '未知错误');
} }
//重新添加权限 //重新添加权限
$result = FunSetRepGroupPri($result, $group, $pri, $repName, $path); $result = \SVNAdmin\SVN\Rep::SetRepGroupPri($result, $group, $pri, $repName, $path);
if ($result == '0') { if ($result == '0') {
FunMessageExit(200, 1, '未知错误'); FunMessageExit(200, 1, '未知错误');
@ -859,7 +861,7 @@ class svnrep extends controller
$path = $this->requestPayload['path']; $path = $this->requestPayload['path'];
$group = $this->requestPayload['group']; $group = $this->requestPayload['group'];
$result = FunDelRepGroupPri($this->globalAuthzContent, $group, $repName, $path); $result = \SVNAdmin\SVN\Rep::DelRepGroupPri($this->globalAuthzContent, $group, $repName, $path);
if ($result == '0') { if ($result == '0') {
FunMessageExit(200, 0, '不存在该仓库路径的记录'); FunMessageExit(200, 0, '不存在该仓库路径的记录');
@ -889,7 +891,7 @@ class svnrep extends controller
*/ */
$pri = $pri == 'no' ? '' : $pri; $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') { if ($result == '0') {
FunMessageExit(200, 0, '不存在该仓库路径的记录'); FunMessageExit(200, 0, '不存在该仓库路径的记录');
@ -913,16 +915,16 @@ class svnrep extends controller
FunCheckRepName($this->requestPayload['new_rep_name']); 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']); 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', [ $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(); FunMessageExit();
} }
@ -943,7 +945,7 @@ class svnrep extends controller
function DelRep() function DelRep()
{ {
//从配置文件删除指定仓库的所有路径 //从配置文件删除指定仓库的所有路径
$result = FunDelRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name']); $result = \SVNAdmin\SVN\Rep::DelRepAuthz($this->globalAuthzContent, $this->requestPayload['rep_name']);
if ($result != '1') { if ($result != '1') {
FunShellExec('echo \'' . $result . '\' > ' . SVN_AUTHZ_FILE); 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']); 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(); FunMessageExit();
@ -966,7 +968,7 @@ class svnrep extends controller
*/ */
function GetRepDetail() function GetRepDetail()
{ {
$result = FunGetRepDetail($this->requestPayload['rep_name']); $result = \SVNAdmin\SVN\Rep::GetRepDetail($this->requestPayload['rep_name']);
$resultArray = explode("\n", $result); $resultArray = explode("\n", $result);
$newArray = []; $newArray = [];
@ -999,7 +1001,7 @@ class svnrep extends controller
*/ */
function RepDump() 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(); FunMessageExit();
} }
@ -1009,7 +1011,7 @@ class svnrep extends controller
*/ */
function DelRepBackup() function DelRepBackup()
{ {
FunDelRepBackup($this->requestPayload['fileName']); \SVNAdmin\SVN\Rep::DelRepBackup($this->requestPayload['fileName']);
FunMessageExit(); FunMessageExit();
} }
@ -1098,6 +1100,8 @@ class svnrep extends controller
set_time_limit(0); set_time_limit(0);
require_once BASE_PATH . '/extension/Download/download.class.php';
$transfer = new Transfer($filePath, $mimeType, $range); $transfer = new Transfer($filePath, $mimeType, $range);
$transfer->send(); $transfer->send();
@ -1143,10 +1147,10 @@ class svnrep extends controller
} }
//检查操作的仓库是否存在 //检查操作的仓库是否存在
FunCheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name'], '仓库不存在');
//使用svndump //使用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) { if ($result == ISNULL) {
FunMessageExit(); FunMessageExit();
@ -1161,7 +1165,7 @@ class svnrep extends controller
function GetRepHooks() function GetRepHooks()
{ {
//检查仓库是否存在 //检查仓库是否存在
FunCheckRepCreate($this->requestPayload['rep_name'], '仓库不存在'); \SVNAdmin\SVN\Rep::CheckRepCreate($this->requestPayload['rep_name'], '仓库不存在');
clearstatcache(); clearstatcache();
if (!is_dir(SVN_REPOSITORY_PATH . $this->requestPayload['rep_name'] . '/' . 'hooks')) { if (!is_dir(SVN_REPOSITORY_PATH . $this->requestPayload['rep_name'] . '/' . 'hooks')) {

20
02.php/app/controller/svnuser.class.php

@ -3,10 +3,12 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-26 16:57:57 * @LastEditTime: 2022-04-27 16:41:35
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
use SVNAdmin\svnUser\svnUser as SvnUserSvnUser;
class svnuser extends controller class svnuser extends controller
{ {
function __construct() function __construct()
@ -28,7 +30,7 @@ class svnuser extends controller
*/ */
function SyncUserToDb() function SyncUserToDb()
{ {
$svnUserPassList = FunGetSvnUserPassList($this->globalPasswdContent); $svnUserPassList = \SVNAdmin\SVN\User::GetSvnUserPassList($this->globalPasswdContent);
if ($svnUserPassList == 0) { if ($svnUserPassList == 0) {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} }
@ -77,7 +79,7 @@ class svnuser extends controller
*/ */
function GetAllUserList() function GetAllUserList()
{ {
$svnUserList = FunGetSvnUserList($this->globalPasswdContent); $svnUserList = \SVNAdmin\SVN\User::GetSvnUserList($this->globalPasswdContent);
if ($svnUserList == '0') { if ($svnUserList == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} else { } else {
@ -149,7 +151,7 @@ class svnuser extends controller
*/ */
function EnableUser() 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} }
@ -167,7 +169,7 @@ class svnuser extends controller
*/ */
function DisableUser() 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} }
@ -203,7 +205,7 @@ class svnuser extends controller
FunCheckRepUser($this->requestPayload['svn_user_name']); 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} }
@ -236,7 +238,7 @@ class svnuser extends controller
function EditUserPass() 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') { if ($result == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
} }
@ -268,7 +270,7 @@ class svnuser extends controller
function DelUser() function DelUser()
{ {
//从passwd文件中全局删除 //从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') { if ($resultPasswd == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');
@ -278,7 +280,7 @@ class svnuser extends controller
} }
//从authz文件中删除 //从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') { if ($resultAuthz == '0') {
FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)'); FunMessageExit(200, 0, '文件格式错误(不存在[users]标识)');

11
02.php/app/core/controller.class.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-26 16:58:08 * @LastEditTime: 2022-04-27 18:03:08
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -24,11 +24,11 @@ require_once BASE_PATH . '/config/version.config.php';
//require model //require model
require_once BASE_PATH . '/app/model/conn.model.php'; require_once BASE_PATH . '/app/model/conn.model.php';
require_once BASE_PATH . '/app/model/util.model.php';
//require function //require function
require_once BASE_PATH . '/app/function/array.function.php'; require_once BASE_PATH . '/app/function/array.function.php';
require_once BASE_PATH . '/app/function/color.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/curl.function.php';
require_once BASE_PATH . '/app/function/file.function.php'; require_once BASE_PATH . '/app/function/file.function.php';
require_once BASE_PATH . '/app/function/json.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/return.function.php';
require_once BASE_PATH . '/app/function/socket.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/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/token.function.php';
require_once BASE_PATH . '/app/function/update.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_once BASE_PATH . '/app/controller/update.class.php';
//require extension //require extension
require_once BASE_PATH . '/extension/Download/download.class.php';
class controller class controller
{ {

35
02.php/app/function/config.function.php

@ -1,35 +0,0 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-04-26 16:58:25
* @Description: QQ:1801168257
*/
/**
* 更新配置文件的value项
*/
function FunUpdateConfigValue($strContent, $key, $value)
{
$status = preg_match(sprintf(REG_CONFIG, $key), $strContent, $result);
if ($status == 0) {
return false;
} else {
return str_replace($result[0], "define('$key', '$value')", $strContent);
}
}
/**
* 获取配置文件的value项
*/
function FunGetConfigValue($strContent, $key)
{
$status = preg_match(sprintf(REG_CONFIG, $key), $strContent, $result);
if ($status == 0) {
return false;
} else {
return $result[1];
}
}

74
02.php/app/function/subversion.function.php

@ -1,74 +0,0 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-24 23:37:06
* @LastEditors: witersen
* @LastEditTime: 2022-04-26 16:59:14
* @Description: QQ:1801168257
*/
/**
* 获取Subversion端口和主机情况
*
* 先从Subversion配置文件获取绑定端口和主机
* 然后与listen.json配置文件中的端口和主机进行对比和同步
*
* 绑定端口
* 绑定地址
* 管理地址
* 检出地址的启用地址
*/
function FunGetSubversionListen()
{
$bindPort = '';
$bindHost = '';
$svnserveContent = FunShellExec('cat ' . SVNSERVE_ENV_FILE);
//匹配端口
if (preg_match('/--listen-port[\s]+([0-9]+)/', $svnserveContent, $portMatchs) != 0) {
$bindPort = trim($portMatchs[1]);
}
//匹配地址
if (preg_match('/--listen-host[\s]+([\S]+)\b/', $svnserveContent, $hostMatchs) != 0) {
$bindHost = trim($hostMatchs[1]);
}
$listenContent = FunShellExec('cat ' . LISTEN_FILE);
if (!FunCheckJson($listenContent)) {
//文件格式错误则初始化
FunShellExec('echo \'' . json_encode([
'bindPort' => $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'],
];
}

690
02.php/app/function/svnGroup.function.php

@ -1,690 +0,0 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-24 23:37:06
* @LastEditors: witersen
* @LastEditTime: 2022-04-26 21:28:48
* @Description: QQ:1801168257
*/
/**
* 添加分组
*
* 0 文件格式错误(不存在[groups]标识)
* 1 分组已存在
* string 正常
*/
function FunAddSvnGroup($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)) {
$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);
array_walk($resultPreg[1], 'FunArrayValueTrim');
array_walk($resultPreg[2], 'FunArrayValueTrim');
if (in_array($groupName, $resultPreg[1])) {
return '1';
} else {
$groupContent = "[groups]\n";
foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $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 [];
}
}

10
02.php/app/function/svnHooks.function.php

@ -1,10 +0,0 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-24 23:37:06
* @LastEditors: witersen
* @LastEditTime: 2022-04-26 16:59:34
* @Description: QQ:1801168257
*/

1298
02.php/app/function/svnRep.function.php

File diff suppressed because it is too large Load Diff

555
02.php/app/function/svnUser.function.php

@ -1,555 +0,0 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-24 23:37:06
* @LastEditors: witersen
* @LastEditTime: 2022-04-26 21:28:06
* @Description: QQ:1801168257
*/
/**
* 不提供修改SVN用户名称的方法
* 一个不变的用户对应SVN仓库所有的历史记录是非常有必要的
*/
/**
* 添加SVN用户
*
* 0 文件格式错误(不存在[users]标识)
* 1 用户已存在
* string 正常
*/
function FunAddSvnUser($passwdContent, $userName, $userPass)
{
$userName = trim($userName);
$userPass = trim($userPass);
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)) {
$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);
array_walk($resultPreg[1], 'FunArrayValueTrim');
array_walk($resultPreg[3], 'FunArrayValueTrim');
$enabledAllUser = $resultPreg[1];
array_walk($enabledAllUser, 'FunArrayValueEnabled');
if (in_array($userName, $resultPreg[1]) || in_array($userName, $enabledAllUser)) {
return '1';
}
$resultStr = "[users]\n";
foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $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';
}
}

24
02.php/app/model/util.model.php

@ -0,0 +1,24 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-27 15:53:12
* @LastEditors: witersen
* @LastEditTime: 2022-04-27 18:00:17
* @Description: QQ:1801168257
*/
require_once BASE_PATH . '/app/util/SVNRep.util.php';
require_once BASE_PATH . '/app/util/SVNGroup.util.php';
require_once BASE_PATH . '/app/util/SVNUser.util.php';
require_once BASE_PATH . '/app/util/SVNHooks.util.php';
require_once BASE_PATH . '/app/util/SVNInfo.util.php';
use SVNAdmin\SVN\Rep;
use SVNAdmin\SVN\Group;
use SVNAdmin\SVN\User;
use SVNAdmin\SVN\Hooks;
use SVNAdmin\SVN\Info;

695
02.php/app/util/SVNGroup.util.php

@ -0,0 +1,695 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-27 15:55:52
* @LastEditors: witersen
* @LastEditTime: 2022-04-27 16:55:12
* @Description: QQ:1801168257
*/
namespace SVNAdmin\SVN;
class Group
{
/**
* 添加分组
*
* 0 文件格式错误(不存在[groups]标识)
* 1 分组已存在
* string 正常
*/
public static function AddSvnGroup($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)) {
$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);
array_walk($resultPreg[1], 'FunArrayValueTrim');
array_walk($resultPreg[2], 'FunArrayValueTrim');
if (in_array($groupName, $resultPreg[1])) {
return '1';
} else {
$groupContent = "[groups]\n";
foreach (array_combine($resultPreg[1], $resultPreg[2]) as $groupStr => $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 [];
}
}
}

14
02.php/app/util/SVNHooks.util.php

@ -0,0 +1,14 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-27 17:53:46
* @LastEditors: witersen
* @LastEditTime: 2022-04-27 17:55:06
* @Description: QQ:1801168257
*/
namespace SVNAdmin\SVN;
class Hooks{
}

79
02.php/app/util/SVNInfo.util.php

@ -0,0 +1,79 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-27 17:58:13
* @LastEditors: witersen
* @LastEditTime: 2022-04-27 17:58:14
* @Description: QQ:1801168257
*/
namespace SVNAdmin\SVN;
class Info
{
/**
* 获取Subversion端口和主机情况
*
* 先从Subversion配置文件获取绑定端口和主机
* 然后与listen.json配置文件中的端口和主机进行对比和同步
*
* 绑定端口
* 绑定地址
* 管理地址
* 检出地址的启用地址
*/
public static function GetSubversionListen()
{
$bindPort = '';
$bindHost = '';
$svnserveContent = FunShellExec('cat ' . SVNSERVE_ENV_FILE);
//匹配端口
if (preg_match('/--listen-port[\s]+([0-9]+)/', $svnserveContent, $portMatchs) != 0) {
$bindPort = trim($portMatchs[1]);
}
//匹配地址
if (preg_match('/--listen-host[\s]+([\S]+)\b/', $svnserveContent, $hostMatchs) != 0) {
$bindHost = trim($hostMatchs[1]);
}
$listenContent = FunShellExec('cat ' . LISTEN_FILE);
if (!FunCheckJson($listenContent)) {
//文件格式错误则初始化
FunShellExec('echo \'' . json_encode([
'bindPort' => $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'],
];
}
}

1303
02.php/app/util/SVNRep.util.php

File diff suppressed because it is too large Load Diff

560
02.php/app/util/SVNUser.util.php

@ -0,0 +1,560 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-27 15:57:48
* @LastEditors: witersen
* @LastEditTime: 2022-04-27 16:58:51
* @Description: QQ:1801168257
*/
namespace SVNAdmin\SVN;
class User
{
/**
* 不提供修改SVN用户名称的方法
* 一个不变的用户对应SVN仓库所有的历史记录是非常有必要的
*/
/**
* 添加SVN用户
*
* 0 文件格式错误(不存在[users]标识)
* 1 用户已存在
* string 正常
*/
public static function AddSvnUser($passwdContent, $userName, $userPass)
{
$userName = trim($userName);
$userPass = trim($userPass);
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)) {
$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);
array_walk($resultPreg[1], 'FunArrayValueTrim');
array_walk($resultPreg[3], 'FunArrayValueTrim');
$enabledAllUser = $resultPreg[1];
array_walk($enabledAllUser, 'FunArrayValueEnabled');
if (in_array($userName, $resultPreg[1]) || in_array($userName, $enabledAllUser)) {
return '1';
}
$resultStr = "[users]\n";
foreach (array_combine($resultPreg[1], $resultPreg[3]) as $key => $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';
}
}
}

19
02.php/config/reg.config.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-04-27 11:48:17 * @LastEditTime: 2022-04-27 17:45:47
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -97,30 +97,35 @@ define('REG_PASSWD_USER_PASSWD', "/^((%s)*[A-Za-z0-9-_.]+)\s*=(.*)/m");
* *
* %s => $group * %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配置文件中某个用户有权限的仓库列表 * 匹配authz配置文件中某个用户有权限的仓库列表
* *
* %s => $user * %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配置文件中所有用户有权限的仓库列表 * 匹配authz配置文件中所有用户有权限的仓库列表
* *
* *=r、*=rw * *=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配置文件中指定仓库的指定路径 包含内容 * 匹配authz配置文件中指定仓库的指定路径 包含内容

Loading…
Cancel
Save