You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
302 lines
9.5 KiB
302 lines
9.5 KiB
3 years ago
|
<?php
|
||
|
/*
|
||
|
* @Author: witersen
|
||
|
* @Date: 2022-04-24 23:37:05
|
||
|
* @LastEditors: witersen
|
||
3 years ago
|
* @LastEditTime: 2022-05-07 14:23:38
|
||
3 years ago
|
* @Description: QQ:1801168257
|
||
|
*/
|
||
|
|
||
3 years ago
|
namespace app\service;
|
||
3 years ago
|
|
||
3 years ago
|
class Svnuser extends Base
|
||
3 years ago
|
{
|
||
3 years ago
|
function __construct()
|
||
|
{
|
||
|
parent::__construct();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 将SVN用户数据同步到数据库
|
||
|
*
|
||
|
* 目的为维护用户启用状态和自定义备注信息
|
||
|
*/
|
||
|
public function SyncUserToDb()
|
||
|
{
|
||
|
$svnUserPassList = $this->SVNAdminUser->GetSvnUserPassList($this->passwdContent);
|
||
|
if ($svnUserPassList == 0) {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
}
|
||
|
$dbUserPassList = $this->database->select('svn_users', [
|
||
|
'svn_user_id',
|
||
|
'svn_user_name',
|
||
|
'svn_user_pass',
|
||
|
'svn_user_status',
|
||
|
'svn_user_note'
|
||
|
]);
|
||
|
|
||
|
$combinArray1 = array_combine(FunArrayColumn($svnUserPassList, 'userName'), FunArrayColumn($svnUserPassList, 'disabled'));
|
||
|
$combinArray2 = array_combine(FunArrayColumn($svnUserPassList, 'userName'), FunArrayColumn($svnUserPassList, 'userPass'));
|
||
|
foreach ($dbUserPassList as $value) {
|
||
|
if (!in_array($value['svn_user_name'], FunArrayColumn($svnUserPassList, 'userName'))) {
|
||
|
$this->database->delete('svn_users', [
|
||
|
'svn_user_name' => $value['svn_user_name']
|
||
|
]);
|
||
|
} else {
|
||
|
//更新启用状态和密码
|
||
|
$this->database->update('svn_users', [
|
||
|
'svn_user_pass' => $combinArray2[$value['svn_user_name']],
|
||
|
'svn_user_status' => !$combinArray1[$value['svn_user_name']]
|
||
|
], [
|
||
|
'svn_user_name' => $value['svn_user_name']
|
||
|
]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
foreach ($svnUserPassList as $value) {
|
||
|
if (!in_array($value['userName'], FunArrayColumn($dbUserPassList, 'svn_user_name'))) {
|
||
|
$this->database->insert('svn_users', [
|
||
|
'svn_user_name' => $value['userName'],
|
||
|
'svn_user_pass' => $value['userPass'],
|
||
|
'svn_user_status' => !$value['disabled'],
|
||
|
'svn_user_note' => ''
|
||
|
]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return message();
|
||
|
}
|
||
|
|
||
3 years ago
|
/**
|
||
|
* 获取全部的SVN用户
|
||
|
*
|
||
|
* 只包含用户名和启用状态
|
||
|
*/
|
||
|
public function GetAllUserList()
|
||
|
{
|
||
|
$svnUserList = $this->SVNAdminUser->GetSvnUserList($this->passwdContent);
|
||
|
if ($svnUserList == '0') {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
} else {
|
||
|
return message(200, 1, '成功', $svnUserList);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取带有分页的SVN用户
|
||
|
*
|
||
|
* 只包含用户名和启用状态
|
||
|
*/
|
||
|
public function GetUserList()
|
||
|
{
|
||
|
//将SVN用户数据同步到数据库
|
||
3 years ago
|
$syncResult = $this->SyncUserToDb();
|
||
3 years ago
|
if ($syncResult['status'] != 1) {
|
||
|
return message($syncResult['code'], $syncResult['status'], $syncResult['message'], $syncResult['data']);
|
||
|
}
|
||
|
|
||
|
$pageSize = $this->payload['pageSize'];
|
||
|
$currentPage = $this->payload['currentPage'];
|
||
|
$searchKeyword = trim($this->payload['searchKeyword']);
|
||
|
|
||
|
//分页
|
||
|
$begin = $pageSize * ($currentPage - 1);
|
||
|
|
||
|
$list = $this->database->select('svn_users', [
|
||
|
'svn_user_id',
|
||
|
'svn_user_name',
|
||
|
'svn_user_pass',
|
||
|
'svn_user_status',
|
||
|
'svn_user_note'
|
||
|
], [
|
||
|
'AND' => [
|
||
|
'OR' => [
|
||
|
'svn_user_name[~]' => $searchKeyword,
|
||
|
// 'svn_user_pass[~]' => $searchKeyword,
|
||
|
'svn_user_note[~]' => $searchKeyword,
|
||
|
],
|
||
|
],
|
||
|
'LIMIT' => [$begin, $pageSize],
|
||
|
'ORDER' => [
|
||
|
$this->payload['sortName'] => strtoupper($this->payload['sortType'])
|
||
|
]
|
||
|
]);
|
||
|
|
||
|
$total = $this->database->count('svn_users', [
|
||
|
'svn_user_id'
|
||
|
], [
|
||
|
'AND' => [
|
||
|
'OR' => [
|
||
|
'svn_user_name[~]' => $searchKeyword,
|
||
|
// 'svn_user_pass[~]' => $searchKeyword,
|
||
|
'svn_user_note[~]' => $searchKeyword,
|
||
|
],
|
||
|
],
|
||
|
]);
|
||
|
|
||
|
foreach ($list as $key => $value) {
|
||
|
$list[$key]['svn_user_status'] = $value['svn_user_status'] == '1' ? true : false;
|
||
|
}
|
||
|
|
||
|
return message(200, 1, '成功', [
|
||
|
'data' => $list,
|
||
|
'total' => $total
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 启用SVN用户
|
||
|
*/
|
||
|
public function EnableUser()
|
||
|
{
|
||
|
$result = $this->SVNAdminUser->EnabledUser($this->passwdContent, $this->payload['svn_user_name']);
|
||
|
if ($result == '0') {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
}
|
||
|
if ($result == '1') {
|
||
|
return message(200, 0, '要启用的用户不存在');
|
||
|
}
|
||
|
|
||
3 years ago
|
FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
|
||
3 years ago
|
|
||
|
return message();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 禁用SVN用户
|
||
|
*/
|
||
|
public function DisableUser()
|
||
|
{
|
||
|
$result = $this->SVNAdminUser->DisabledUser($this->passwdContent, $this->payload['svn_user_name']);
|
||
|
if ($result == '0') {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
}
|
||
|
if ($result == '1') {
|
||
|
return message(200, 0, '要禁用的用户不存在');
|
||
|
}
|
||
|
|
||
3 years ago
|
FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
|
||
3 years ago
|
|
||
|
return message();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改SVN用户的备注信息
|
||
|
*/
|
||
|
public function EditUserNote()
|
||
|
{
|
||
|
$this->database->update('svn_users', [
|
||
|
'svn_user_note' => $this->payload['svn_user_note']
|
||
|
], [
|
||
|
'svn_user_name' => $this->payload['svn_user_name']
|
||
|
]);
|
||
|
|
||
3 years ago
|
return message(200, 1, '已保存');
|
||
3 years ago
|
}
|
||
|
|
||
|
/**
|
||
|
* 新建SVN用户
|
||
|
*/
|
||
|
public function CreateUser()
|
||
|
{
|
||
|
//检查用户名是否合法
|
||
|
$checkResult = $this->checkService->CheckRepUser($this->payload['svn_user_name']);
|
||
|
if ($checkResult['status'] != 1) {
|
||
|
return message($checkResult['code'], $checkResult['status'], $checkResult['message'], $checkResult['data']);
|
||
|
}
|
||
|
|
||
|
//检查用户是否已存在
|
||
|
$result = $this->SVNAdminUser->AddSvnUser($this->passwdContent, $this->payload['svn_user_name'], $this->payload['svn_user_pass']);
|
||
|
if ($result == '0') {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
}
|
||
|
if ($result == '1') {
|
||
|
return message(200, 0, '用户已存在');
|
||
|
}
|
||
|
|
||
|
//检查密码是否不为空
|
||
|
if (trim($this->payload['svn_user_pass']) == '') {
|
||
|
return message(200, 0, '密码不能为空');
|
||
|
}
|
||
|
|
||
|
//写入配置文件
|
||
3 years ago
|
FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
|
||
3 years ago
|
|
||
|
//写入数据库
|
||
|
$this->database->insert('svn_users', [
|
||
|
'svn_user_name' => $this->payload['svn_user_name'],
|
||
|
'svn_user_pass' => $this->payload['svn_user_pass'],
|
||
|
'svn_user_status' => 1,
|
||
|
'svn_user_note' => ''
|
||
|
]);
|
||
|
|
||
|
return message();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 修改SVN用户的密码
|
||
|
*/
|
||
|
public function EditUserPass()
|
||
|
{
|
||
|
//检查用户是否已存在
|
||
|
$result = $this->SVNAdminUser->UpdSvnUserPass($this->passwdContent, $this->payload['svn_user_name'], $this->payload['svn_user_pass'], !$this->payload['svn_user_status']);
|
||
|
if ($result == '0') {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
}
|
||
|
if ($result == '1') {
|
||
|
return message(200, 0, '用户不存在 请刷新重试');
|
||
|
}
|
||
|
|
||
|
//检查密码是否不为空
|
||
|
if (trim($this->payload['svn_user_pass']) == '') {
|
||
|
return message(200, 0, '密码不能为空');
|
||
|
}
|
||
|
|
||
|
//写入配置文件
|
||
3 years ago
|
FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
|
||
3 years ago
|
|
||
|
//写入数据库
|
||
|
$this->database->update('svn_users', [
|
||
|
'svn_user_pass' => $this->payload['svn_user_pass'],
|
||
|
], [
|
||
|
'svn_user_name' => $this->payload['svn_user_name']
|
||
|
]);
|
||
|
|
||
|
return message();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除SVN用户
|
||
|
*/
|
||
|
public function DelUser()
|
||
|
{
|
||
|
//从passwd文件中全局删除
|
||
|
$resultPasswd = $this->SVNAdminUser->DelSvnUserPasswd($this->passwdContent, $this->payload['svn_user_name'], !$this->payload['svn_user_status']);
|
||
|
|
||
|
if ($resultPasswd == '0') {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
}
|
||
|
if ($resultPasswd == '1') {
|
||
|
return message(200, 0, '用户不存在');
|
||
|
}
|
||
|
|
||
|
//从authz文件中删除
|
||
|
$resultAuthz = $this->SVNAdminUser->DelUserAuthz($this->authzContent, $this->payload['svn_user_name']);
|
||
|
|
||
|
if ($resultAuthz == '0') {
|
||
|
return message(200, 0, '文件格式错误(不存在[users]标识)');
|
||
|
}
|
||
|
|
||
|
//从数据删除
|
||
|
$this->database->delete('svn_users', [
|
||
|
'svn_user_name' => $this->payload['svn_user_name']
|
||
|
]);
|
||
|
|
||
3 years ago
|
FunShellExec('echo \'' . $resultAuthz . '\' > ' . $this->config_svn['svn_authz_file']);
|
||
3 years ago
|
|
||
3 years ago
|
FunShellExec('echo \'' . $resultPasswd . '\' > ' . $this->config_svn['svn_passwd_file']);
|
||
3 years ago
|
|
||
|
return message();
|
||
|
}
|
||
|
}
|