witersen
3 years ago
20 changed files with 2790 additions and 2768 deletions
@ -1,35 +0,0 @@
@@ -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]; |
||||
} |
||||
} |
@ -1,74 +0,0 @@
@@ -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'], |
||||
]; |
||||
} |
@ -1,690 +0,0 @@
@@ -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 []; |
||||
} |
||||
} |
@ -1,10 +0,0 @@
@@ -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 |
||||
*/ |
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,555 +0,0 @@
@@ -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'; |
||||
} |
||||
} |
@ -0,0 +1,24 @@
@@ -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; |
@ -0,0 +1,695 @@
@@ -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 []; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,14 @@
@@ -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{ |
||||
|
||||
} |
@ -0,0 +1,79 @@
@@ -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'], |
||||
]; |
||||
} |
||||
} |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,560 @@
@@ -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'; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue