|
|
|
@ -13,7 +13,8 @@
@@ -13,7 +13,8 @@
|
|
|
|
|
* 7、如果在本地检出时,http://domain/仓库名称/format 无法访问 权限不够 需要关闭Linux系统的selinux |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
class Svnserve extends Controller { |
|
|
|
|
class Svnserve extends Controller |
|
|
|
|
{ |
|
|
|
|
/* |
|
|
|
|
* 注意事项: |
|
|
|
|
* 1、所有的控制器都要继承基类控制器:Controller |
|
|
|
@ -37,10 +38,10 @@ class Svnserve extends Controller {
@@ -37,10 +38,10 @@ class Svnserve extends Controller {
|
|
|
|
|
private $Firewall; |
|
|
|
|
private $System; |
|
|
|
|
private $Mail; |
|
|
|
|
private $Mod_dav_svn_status; |
|
|
|
|
private $Clientinfo; |
|
|
|
|
|
|
|
|
|
function __construct() { |
|
|
|
|
function __construct() |
|
|
|
|
{ |
|
|
|
|
/* |
|
|
|
|
* 避免子类的构造函数覆盖父类的构造函数 |
|
|
|
|
*/ |
|
|
|
@ -66,11 +67,11 @@ class Svnserve extends Controller {
@@ -66,11 +67,11 @@ class Svnserve extends Controller {
|
|
|
|
|
$this->svn_web_path = $this->Config->Get("SVN_WEB_PATH"); |
|
|
|
|
$this->svn_port = $this->Config->Get("SVN_PORT"); |
|
|
|
|
$this->http_port = $this->Config->Get("HTTP_PORT"); |
|
|
|
|
$this->Mod_dav_svn_status = $this->Config->Get("Mod_dav_svn_status"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//设置仓库的hooks |
|
|
|
|
function SetRepositoryHooks($requestPayload) { |
|
|
|
|
function SetRepositoryHooks($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($requestPayload['repository_name']); |
|
|
|
|
$hooks_type_list = $requestPayload['hooks_type_list']; |
|
|
|
|
|
|
|
|
@ -89,7 +90,8 @@ class Svnserve extends Controller {
@@ -89,7 +90,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取仓库的hooks |
|
|
|
|
function GetRepositoryHooks($requestPayload) { |
|
|
|
|
function GetRepositoryHooks($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($requestPayload['repository_name']); |
|
|
|
|
|
|
|
|
|
if (empty($repository_name)) { |
|
|
|
@ -175,7 +177,8 @@ class Svnserve extends Controller {
@@ -175,7 +177,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//系统首页 获取概览情况 |
|
|
|
|
function GetGailan($requestPayload) { |
|
|
|
|
function GetGailan($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$userid = $this->this_userid; |
|
|
|
|
|
|
|
|
|
$resultlist = array( |
|
|
|
@ -233,16 +236,10 @@ class Svnserve extends Controller {
@@ -233,16 +236,10 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//安装svnserve服务 |
|
|
|
|
function Install($requestPayload) { |
|
|
|
|
$platform = $this->System->GetPlatform(); |
|
|
|
|
|
|
|
|
|
function Install($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$data = array(); |
|
|
|
|
|
|
|
|
|
if (!$platform['status'] == 1) { |
|
|
|
|
return $platform; |
|
|
|
|
} |
|
|
|
|
$platform = $platform['platform']; |
|
|
|
|
|
|
|
|
|
//创建svn仓库父目录 |
|
|
|
|
parent::RequestReplyExec('mkdir -p ' . $this->svn_repository_path); |
|
|
|
|
if (!is_dir($this->svn_repository_path)) { |
|
|
|
@ -254,25 +251,20 @@ class Svnserve extends Controller {
@@ -254,25 +251,20 @@ class Svnserve extends Controller {
|
|
|
|
|
//通过ps auxf|grep -v "grep"|grep svnserve和判断文件/usr/bin/svnserve是否存在这两方面来同时判断 如果没有安装过则进行安装 |
|
|
|
|
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); |
|
|
|
|
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { |
|
|
|
|
if ($platform == 'CentOS') { |
|
|
|
|
//yum安装 |
|
|
|
|
parent::RequestReplyExec("yum install -y subversion"); |
|
|
|
|
/* |
|
|
|
|
* 安装目录浏览的依赖模块 |
|
|
|
|
* 在/etc/httpd/conf.d/下创建空文件AuthUserFile.conf |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(" yum install -y mod_dav_svn"); |
|
|
|
|
parent::RequestReplyExec(" touch /etc/httpd/conf.d/AuthUserFile.conf"); |
|
|
|
|
parent::RequestReplyExec(" chmod 777 /etc/httpd/conf.d/AuthUserFile.conf"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sleep(1); |
|
|
|
|
|
|
|
|
|
//通常cp的别名为cp -i ,取消别名 |
|
|
|
|
parent::RequestReplyExec("alias cp='cp'"); |
|
|
|
|
parent::RequestReplyExec('cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak'); |
|
|
|
|
|
|
|
|
|
//更改存储库位置 将配置文件/etc/sysconfig/svnserve中的/var/svn/更换为svn仓库目录 |
|
|
|
|
parent::RequestReplyExec('sed -i \'s/\/var\/svn/' . str_replace('/', '\/', $this->svn_repository_path) . '/g\'' . ' /etc/sysconfig/svnserve'); |
|
|
|
|
|
|
|
|
|
//设置存储密码选项 将以下内容写入文件/etc/subversion/servers servers文件不存在则创建 |
|
|
|
|
/* |
|
|
|
|
/** |
|
|
|
|
* [groups] |
|
|
|
|
* [global] |
|
|
|
|
* store-plaintext-passwords = yes |
|
|
|
@ -280,105 +272,46 @@ class Svnserve extends Controller {
@@ -280,105 +272,46 @@ class Svnserve extends Controller {
|
|
|
|
|
parent::RequestReplyExec("touch /etc/subversion/servers"); |
|
|
|
|
$con = "[groups]\n[global]\nstore-plaintext-passwords = yes\n"; |
|
|
|
|
parent::RequestReplyExec('echo \'' . $con . '\' > /etc/subversion/servers'); |
|
|
|
|
parent::RequestReplyExec(" systemctl reload httpd"); |
|
|
|
|
} else if ($platform == 'Ubuntu') { |
|
|
|
|
parent::RequestReplyExec(' apt install subversion -y'); |
|
|
|
|
parent::RequestReplyExec(' cp /etc/subversion/servers /etc/subversion/servers.bak'); |
|
|
|
|
//设置存储密码选项 将文件/etc/subversion/servers中store-plaintext-passwords对应的值由no改为yes |
|
|
|
|
parent::RequestReplyExec(" sed -i 's/# store-plaintext-passwords = no/store-plaintext-passwords = yes/g' /etc/subversion/servers"); |
|
|
|
|
//将以下内容写入文件/lib/systemd/system/svnserve.service |
|
|
|
|
/* |
|
|
|
|
* [Unit] |
|
|
|
|
* Description=Subversion protocol daemon |
|
|
|
|
* After=syslog.target network.target |
|
|
|
|
* |
|
|
|
|
* [Service] |
|
|
|
|
* Type=forking |
|
|
|
|
* ExecStart=/usr/bin/svnserve --daemon --pid-file=/run/svnserve.pid -r /www/svn/repository |
|
|
|
|
* |
|
|
|
|
* [Install] |
|
|
|
|
* WantedBy=multi-user.target |
|
|
|
|
*/ |
|
|
|
|
if (!file_exists('/lib/systemd/system/svnserve.service')) { |
|
|
|
|
$data['status'] = 0; |
|
|
|
|
$data['message'] = '文件/lib/systemd/system/svnserve.service不存在'; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
parent::RequestReplyExec(' cp /lib/systemd/system/svnserve.service /lib/systemd/system/svnserve.service.bak'); |
|
|
|
|
$con = "\n[Unit]\nDescription=Subversion protocol daemon\nAfter=syslog.target network.target\n\n[Service]\nType=forking\nExecStart=/usr/bin/svnserve --daemon --pid-file=/run/svnserve.pid -r " . $this->svn_repository_path . "\n\n[Install]\nWantedBy=multi-user.target\n"; |
|
|
|
|
parent::RequestReplyExec(" echo '$con' >> /lib/systemd/system/svnserve.service"); |
|
|
|
|
//执行命令systemctl daemon-reload使配置生效 |
|
|
|
|
parent::RequestReplyExec(' systemctl daemon-reload'); |
|
|
|
|
} else { |
|
|
|
|
$data['status'] = 0; |
|
|
|
|
$data['message'] = '当前操作系统不受支持'; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
parent::RequestReplyExec("systemctl enable svnserve.service"); |
|
|
|
|
parent::RequestReplyExec("systemctl start svnserve.service"); |
|
|
|
|
$this->Firewall->SetFirewallPolicy(["port" => $this->svn_port, "type" => "add"]); |
|
|
|
|
$this->Firewall->SetFirewallPolicy(["port" => $this->http_port, "type" => "add"]); |
|
|
|
|
// $this->Firewall->SetFirewallPolicy('tcp', $this->svn_port, 'add'); |
|
|
|
|
// $this->Firewall->SetFirewallPolicy('tcp', $this->http_port, 'add'); |
|
|
|
|
parent::RequestReplyExec('setenforce 0'); |
|
|
|
|
parent::RequestReplyExec("sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"); |
|
|
|
|
} else { |
|
|
|
|
if ($platform == 'CentOS') { |
|
|
|
|
$this->UnInstall(array()); |
|
|
|
|
$this->Install(array()); |
|
|
|
|
} else if ($platform == 'Ubuntu') { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['status'] = 1; |
|
|
|
|
$data['message'] = '安装服务成功'; |
|
|
|
|
return $data; |
|
|
|
|
} else { |
|
|
|
|
$data['status'] = 1; |
|
|
|
|
$data['message'] = 'Subversion已存在'; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//卸载svnserve服务 |
|
|
|
|
function UnInstall($requestPayload) { |
|
|
|
|
function UnInstall($requestPayload) |
|
|
|
|
{ |
|
|
|
|
//清空表数据 |
|
|
|
|
$this->TruncateTable(); |
|
|
|
|
|
|
|
|
|
$platform = $this->System->GetPlatform(); |
|
|
|
|
|
|
|
|
|
parent::RequestReplyExec(" rm -rf " . $this->svn_repository_path); |
|
|
|
|
if (is_dir($this->svn_repository_path)) { |
|
|
|
|
$data['status'] = 0; |
|
|
|
|
$data['message'] = '卸载失败 删除目录失败'; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
//判断平台 |
|
|
|
|
if (!$platform['status'] == 1) { |
|
|
|
|
return $platform; |
|
|
|
|
} |
|
|
|
|
$platform = $platform['platform']; |
|
|
|
|
|
|
|
|
|
parent::RequestReplyExec('systemctl stop svnserve'); |
|
|
|
|
sleep(2); |
|
|
|
|
parent::RequestReplyExec('systemctl disable svnserve'); |
|
|
|
|
sleep(2); |
|
|
|
|
parent::RequestReplyExec('yum remove -y subversion'); |
|
|
|
|
/* |
|
|
|
|
* 目录浏览 |
|
|
|
|
* 卸载开启目录浏览的支持模块 |
|
|
|
|
* 删除配置文件 |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(' yum remove -y mod_dav_svn'); |
|
|
|
|
parent::RequestReplyExec(" rm -f /etc/httpd/conf.d/AuthUserFile.conf"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ($platform == 'CentOS') { |
|
|
|
|
sleep(2); |
|
|
|
|
parent::RequestReplyExec('yum remove -y subversion'); |
|
|
|
|
sleep(2); |
|
|
|
|
parent::RequestReplyExec('yum remove -y subversion'); |
|
|
|
|
sleep(2); |
|
|
|
|
parent::RequestReplyExec('rm -f /etc/subversion/servers'); |
|
|
|
|
parent::RequestReplyExec('rm -rf /etc/subversion'); |
|
|
|
|
parent::RequestReplyExec('rm -rf /usr/bin/svnserve'); // |
|
|
|
|
|
|
|
|
|
//清除yum缓存 |
|
|
|
|
parent::RequestReplyExec('yum clean all'); |
|
|
|
|
} else if ($platform == 'Ubuntu') { |
|
|
|
|
parent::RequestReplyExec(' mv -f /etc/subversion/servers.bak /etc/subversion/servers'); |
|
|
|
|
parent::RequestReplyExec(' mv -f /lib/systemd/system/svnserve.service.bak /lib/systemd/system/svnserve.service'); |
|
|
|
|
parent::RequestReplyExec(' systemctl daemon-reload'); |
|
|
|
|
parent::RequestReplyExec(' apt-get clean'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//is_dir的结果会被缓存,所以需要清除缓存 |
|
|
|
|
clearstatcache(); |
|
|
|
@ -389,7 +322,8 @@ class Svnserve extends Controller {
@@ -389,7 +322,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//修复svn服务 包括重新扫描仓库列表重新写入仓库表 |
|
|
|
|
function Repaire($requestPayload) { |
|
|
|
|
function Repaire($requestPayload) |
|
|
|
|
{ |
|
|
|
|
//清空仓库表和用户-仓库表 |
|
|
|
|
$this->TruncateTable(); |
|
|
|
|
//扫描仓库并写入仓库表 |
|
|
|
@ -403,7 +337,8 @@ class Svnserve extends Controller {
@@ -403,7 +337,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取所有仓库信息 计划任务列表下拉菜单使用 |
|
|
|
|
function GetAllRepositoryList($requestPayload) { |
|
|
|
|
function GetAllRepositoryList($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$userid = $this->this_userid; |
|
|
|
|
|
|
|
|
|
//更新仓库表 |
|
|
|
@ -448,7 +383,8 @@ class Svnserve extends Controller {
@@ -448,7 +383,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//项目管理 获取仓库信息 |
|
|
|
|
function GetRepositoryList($requestPayload) { |
|
|
|
|
function GetRepositoryList($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$userid = $this->this_userid; |
|
|
|
|
$pageSize = trim($requestPayload['pageSize']); |
|
|
|
|
$currentPage = trim($requestPayload['currentPage']); |
|
|
|
@ -553,7 +489,8 @@ class Svnserve extends Controller {
@@ -553,7 +489,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//项目管理 按钮 添加svn仓库 包括项目标题 |
|
|
|
|
function AddRepository($requestPayload) { |
|
|
|
|
function AddRepository($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = $requestPayload['repository_name']; |
|
|
|
|
$this_userid = $this->this_userid; |
|
|
|
|
$this_username = $this->this_userid; |
|
|
|
@ -586,42 +523,6 @@ class Svnserve extends Controller {
@@ -586,42 +523,6 @@ class Svnserve extends Controller {
|
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
parent::RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path); |
|
|
|
|
/* |
|
|
|
|
* 配置目录浏览部分 |
|
|
|
|
* 1、在conf目录下创建用户目录浏览的用户文件http_passwd |
|
|
|
|
* 2、在/etc/httpd/conf.d/AuthUserFile.conf文件中检测是否包含本仓库记录 如果包含 则不进行写入 |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(" touch " . $this->svn_repository_path . "/" . $repository_name . "/conf/http_passwd"); |
|
|
|
|
parent::RequestReplyExec(' chmod 777 -R ' . $this->svn_repository_path); |
|
|
|
|
//读取文本到数组 |
|
|
|
|
$file = fopen("/etc/httpd/conf.d/AuthUserFile.conf", "r") or exit("无法打开文件!"); |
|
|
|
|
$file_content = array(); |
|
|
|
|
while (!feof($file)) { |
|
|
|
|
array_push($file_content, fgets($file)); |
|
|
|
|
} |
|
|
|
|
fclose($file); |
|
|
|
|
//判断不存在记录则写入 |
|
|
|
|
$flag = true; |
|
|
|
|
foreach ($file_content as $key => $value) { |
|
|
|
|
if (strstr($value, "<Location " . $this->svn_web_path . "/" . $repository_name . ">")) { |
|
|
|
|
$flag = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if ($flag) { |
|
|
|
|
$con = "<Location " . $this->svn_web_path . "/" . $repository_name . ">\n" |
|
|
|
|
. "DAV svn\n" |
|
|
|
|
. "SVNPath " . $this->svn_repository_path . "/" . $repository_name . "\n" |
|
|
|
|
. "AuthType Basic\n" |
|
|
|
|
. "AuthName \"Authorization SVN\"\n" |
|
|
|
|
. "AuthzSVNAccessFile " . $this->svn_repository_path . "/" . $repository_name . "/conf/authz\n" |
|
|
|
|
. "AuthUserFile " . $this->svn_repository_path . "/" . $repository_name . "/conf/http_passwd\n" |
|
|
|
|
. "Require valid-user\n" |
|
|
|
|
. "</Location>\n"; |
|
|
|
|
parent::RequestReplyExec(" echo '$con' >> /etc/httpd/conf.d/AuthUserFile.conf"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//将新建仓库目录下的conf/svnserve.conf做以下修改, |
|
|
|
|
/* |
|
|
|
@ -633,12 +534,7 @@ class Svnserve extends Controller {
@@ -633,12 +534,7 @@ class Svnserve extends Controller {
|
|
|
|
|
parent::RequestReplyExec("sed -i 's/# password-db = passwd/password-db = passwd/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf"); |
|
|
|
|
parent::RequestReplyExec("sed -i 's/# authz-db = authz/authz-db = authz/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf"); |
|
|
|
|
$this->InitRepositoryConfFile($repository_name); |
|
|
|
|
/* |
|
|
|
|
* 配置目录浏览后重载服务· |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(" systemctl reload httpd"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
parent::RequestReplyExec('setenforce 0'); |
|
|
|
|
|
|
|
|
|
if (!$this->InsertRepositoryTable($repository_name)) { |
|
|
|
@ -667,7 +563,8 @@ class Svnserve extends Controller {
@@ -667,7 +563,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//项目管理 按钮 删除svn仓库 |
|
|
|
|
function DeleteRepository($requestPayload) { |
|
|
|
|
function DeleteRepository($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = $requestPayload['repository_name']; |
|
|
|
|
$this_userid = $this->this_userid; |
|
|
|
|
$this_username = $this->this_userid; |
|
|
|
@ -719,7 +616,8 @@ class Svnserve extends Controller {
@@ -719,7 +616,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//项目管理 按钮 为svn项目授权 -> 在账号列表收集并提交账户相对于svn项目的权限变化 |
|
|
|
|
function SetRepositoryPrivilege($requestPayload) { |
|
|
|
|
function SetRepositoryPrivilege($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($requestPayload['repository_name']); |
|
|
|
|
$this_account_list = $requestPayload['this_account_list']; |
|
|
|
|
|
|
|
|
@ -779,7 +677,8 @@ class Svnserve extends Controller {
@@ -779,7 +677,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//项目管理 按钮 编辑svn项目 提交用户对svn项目的标题的修改 |
|
|
|
|
function SetRepositoryInfo($requestPayload) { |
|
|
|
|
function SetRepositoryInfo($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$old_repository_name = trim($requestPayload['old_repository_name']); |
|
|
|
|
$new_repository_name = trim($requestPayload['new_repository_name']); |
|
|
|
|
|
|
|
|
@ -818,45 +717,14 @@ class Svnserve extends Controller {
@@ -818,45 +717,14 @@ class Svnserve extends Controller {
|
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* 目录浏览 |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
//读取文本到数组 |
|
|
|
|
$file = fopen("/etc/httpd/conf.d/AuthUserFile.conf", "r") or exit("无法打开文件!"); |
|
|
|
|
$file_content = array(); |
|
|
|
|
while (!feof($file)) { |
|
|
|
|
array_push($file_content, fgets($file)); |
|
|
|
|
} |
|
|
|
|
fclose($file); |
|
|
|
|
//如果存在记录则修改 |
|
|
|
|
foreach ($file_content as $key => $value) { |
|
|
|
|
if (strstr($value, "<Location " . $this->svn_web_path . "/" . $old_repository_name . ">")) { |
|
|
|
|
$file_content[$key] = "<Location " . $this->svn_web_path . "/" . $new_repository_name . ">\n"; |
|
|
|
|
$file_content[$key + 1] = "DAV svn\n"; |
|
|
|
|
$file_content[$key + 2] = "SVNPath " . $this->svn_repository_path . "/" . $old_repository_name . "\n"; |
|
|
|
|
$file_content[$key + 3] = "AuthType Basic\n"; |
|
|
|
|
$file_content[$key + 4] = "AuthName \"Authorization SVN\"\n"; |
|
|
|
|
$file_content[$key + 5] = "AuthzSVNAccessFile " . $this->svn_repository_path . "/" . $old_repository_name . "/conf/authz\n"; |
|
|
|
|
$file_content[$key + 6] = "AuthUserFile " . $this->svn_repository_path . "/" . $old_repository_name . "/conf/http_passwd\n"; |
|
|
|
|
$file_content[$key + 7] = "Require valid-user\n"; |
|
|
|
|
$file_content[$key + 8] = "</Location>\n"; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
//写入 |
|
|
|
|
$file_content = implode($file_content); |
|
|
|
|
parent::RequestReplyExec(" echo '$file_content' > /etc/httpd/conf.d/AuthUserFile.conf"); |
|
|
|
|
parent::RequestReplyExec(" systemctl reload httpd"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['status'] = 1; |
|
|
|
|
$data['message'] = '修改仓库信息成功'; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取仓库对应的用户和密码列表 |
|
|
|
|
function GetRepositoryUserList($requestPayload) { |
|
|
|
|
function GetRepositoryUserList($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = $requestPayload['repository_name']; |
|
|
|
|
|
|
|
|
|
if (empty($repository_name)) { |
|
|
|
@ -898,7 +766,8 @@ class Svnserve extends Controller {
@@ -898,7 +766,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取仓库对应的账户的权限 |
|
|
|
|
function GetRepositoryUserPrivilegeList($requestPayload) { |
|
|
|
|
function GetRepositoryUserPrivilegeList($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($requestPayload['repository_name']); |
|
|
|
|
|
|
|
|
|
if (empty($repository_name)) { |
|
|
|
@ -958,7 +827,8 @@ class Svnserve extends Controller {
@@ -958,7 +827,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//账号管理 添加账号 |
|
|
|
|
function AddAccount($requestPayload) { |
|
|
|
|
function AddAccount($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($requestPayload['repository_name']); |
|
|
|
|
$account = trim($requestPayload['account']); |
|
|
|
|
$passwd = trim($requestPayload['password']); |
|
|
|
@ -1019,22 +889,14 @@ class Svnserve extends Controller {
@@ -1019,22 +889,14 @@ class Svnserve extends Controller {
|
|
|
|
|
$file_content = implode($file_content); |
|
|
|
|
parent::RequestReplyExec('echo \'' . $file_content . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* 目录浏览 |
|
|
|
|
* 向仓库的conf文件下的用户文件中添加用户和密码 |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(" htpasswd -m -b " . $this->svn_repository_path . "/" . $repository_name . "/conf/http_passwd $account $passwd"); |
|
|
|
|
parent::RequestReplyExec(" sytemctl reload httpd"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['status'] = 1; |
|
|
|
|
$data['message'] = '添加账户成功'; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//账号管理 删除账号 |
|
|
|
|
function DeleteAccount($requestPayload) { |
|
|
|
|
function DeleteAccount($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($requestPayload['repository_name']); |
|
|
|
|
$account = trim($requestPayload['account']); |
|
|
|
|
|
|
|
|
@ -1089,21 +951,14 @@ class Svnserve extends Controller {
@@ -1089,21 +951,14 @@ class Svnserve extends Controller {
|
|
|
|
|
$con = implode($file_content); |
|
|
|
|
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz'); |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
* 目录浏览 |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(" htpasswd -D " . $this->svn_repository_path . "/" . $repository_name . "/conf/http_passwd $account"); |
|
|
|
|
parent::RequestReplyExec(" sytemctl reload httpd"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['status'] = 1; |
|
|
|
|
$data['message'] = '删除账户成功'; |
|
|
|
|
return $data; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//账号管理 编辑账号 提交用户对账号信息的修改 账号作为唯一标识不能修改 |
|
|
|
|
function SetCountInfo($requestPayload) { |
|
|
|
|
function SetCountInfo($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($requestPayload['repository_name']); |
|
|
|
|
$account = trim($requestPayload['account']); |
|
|
|
|
$passwd = trim($requestPayload['password']); |
|
|
|
@ -1141,13 +996,6 @@ class Svnserve extends Controller {
@@ -1141,13 +996,6 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
$con = implode($file_content); |
|
|
|
|
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); |
|
|
|
|
/* |
|
|
|
|
* 目录浏览 |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(" htpasswd -m -b " . $this->svn_repository_path . "/" . $repository_name . "/conf/http_passwd $account $passwd"); |
|
|
|
|
parent::RequestReplyExec(" sytemctl reload httpd"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
$data['status'] = 1; |
|
|
|
|
$data['message'] = '修改成功'; |
|
|
|
@ -1155,7 +1003,8 @@ class Svnserve extends Controller {
@@ -1155,7 +1003,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//高级设置 初始化加载 列出svnserve服务的状态 |
|
|
|
|
function GetSvnserveStatus($requestPayload) { |
|
|
|
|
function GetSvnserveStatus($requestPayload) |
|
|
|
|
{ |
|
|
|
|
//是否安装服务 |
|
|
|
|
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); |
|
|
|
|
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { |
|
|
|
@ -1207,7 +1056,8 @@ class Svnserve extends Controller {
@@ -1207,7 +1056,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//高级设置 管理svnserve服务的状态 |
|
|
|
|
function SetSvnserveStatus($requestPayload) { |
|
|
|
|
function SetSvnserveStatus($requestPayload) |
|
|
|
|
{ |
|
|
|
|
$action = $requestPayload['action']; |
|
|
|
|
|
|
|
|
|
if (empty($action)) { |
|
|
|
@ -1234,7 +1084,8 @@ class Svnserve extends Controller {
@@ -1234,7 +1084,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取随机的root密码 |
|
|
|
|
private function GetInitPasswd($length) { |
|
|
|
|
private function GetInitPasswd($length) |
|
|
|
|
{ |
|
|
|
|
!empty($length) or die('参数不完整'); |
|
|
|
|
|
|
|
|
|
$str = md5(time()); |
|
|
|
@ -1243,13 +1094,15 @@ class Svnserve extends Controller {
@@ -1243,13 +1094,15 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//只允许中文 数字 字母 |
|
|
|
|
private function CheckStr($str) { |
|
|
|
|
private function CheckStr($str) |
|
|
|
|
{ |
|
|
|
|
$res = preg_match('/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u', $str); |
|
|
|
|
return $res ? true : false; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取服务状态 检查相关的目录文件是否存在 |
|
|
|
|
private function CheckSvnserveStatus() { |
|
|
|
|
private function CheckSvnserveStatus() |
|
|
|
|
{ |
|
|
|
|
//是否安装服务 |
|
|
|
|
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); |
|
|
|
|
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { |
|
|
|
@ -1279,7 +1132,8 @@ class Svnserve extends Controller {
@@ -1279,7 +1132,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//获取文件夹体积 |
|
|
|
|
private function GetDirSize($dir) { |
|
|
|
|
private function GetDirSize($dir) |
|
|
|
|
{ |
|
|
|
|
clearstatcache(); |
|
|
|
|
$dh = opendir($dir) or exit('打开目录错误'); //打开目录,返回一个目录流 |
|
|
|
|
$size = 0; //初始大小为0 |
|
|
|
@ -1298,7 +1152,8 @@ class Svnserve extends Controller {
@@ -1298,7 +1152,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//从仓库表中删除仓库信息 |
|
|
|
|
private function DeleteRepositoryTable($repository_name) { |
|
|
|
|
private function DeleteRepositoryTable($repository_name) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($repository_name); |
|
|
|
|
if ($repository_name == "" || $repository_name == null) { |
|
|
|
|
return false; |
|
|
|
@ -1327,7 +1182,8 @@ class Svnserve extends Controller {
@@ -1327,7 +1182,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//写入账户和密码的初始内容到仓库中的passowrd和authz配置文件,进行仓库初始化 |
|
|
|
|
private function InitRepositoryConfFile($repository_name) { |
|
|
|
|
private function InitRepositoryConfFile($repository_name) |
|
|
|
|
{ |
|
|
|
|
//将以下内容写入authz文件 |
|
|
|
|
/* |
|
|
|
|
* [aliases] |
|
|
|
@ -1345,16 +1201,11 @@ class Svnserve extends Controller {
@@ -1345,16 +1201,11 @@ class Svnserve extends Controller {
|
|
|
|
|
$pass = trim($this->GetInitPasswd(16)); |
|
|
|
|
$con = "[users]\nroot = " . $pass . "\n"; |
|
|
|
|
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); |
|
|
|
|
/* |
|
|
|
|
* 目录浏览 |
|
|
|
|
*/ |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
parent::RequestReplyExec(" htpasswd -m -b " . $this->svn_repository_path . "/" . $repository_name . "/conf/http_passwd root $pass"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//向仓库表中写入仓库信息 |
|
|
|
|
private function InsertRepositoryTable($repository_name) { |
|
|
|
|
private function InsertRepositoryTable($repository_name) |
|
|
|
|
{ |
|
|
|
|
$repository_name = trim($repository_name); |
|
|
|
|
if ($repository_name == "" || $repository_name == null) { |
|
|
|
|
return false; |
|
|
|
@ -1365,7 +1216,8 @@ class Svnserve extends Controller {
@@ -1365,7 +1216,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//扫描仓库信息并更新仓库信息表 |
|
|
|
|
private function UpdateRepositoryInfo() { |
|
|
|
|
private function UpdateRepositoryInfo() |
|
|
|
|
{ |
|
|
|
|
//查仓库表 |
|
|
|
|
$list = $this->database_medoo->select("repository", [ |
|
|
|
|
"id", |
|
|
|
@ -1378,11 +1230,7 @@ class Svnserve extends Controller {
@@ -1378,11 +1230,7 @@ class Svnserve extends Controller {
|
|
|
|
|
$repository_url = $this->svn_repository_path . '/' . $repository_name; |
|
|
|
|
$repository_size = round($this->GetDirSize($this->svn_repository_path . '/' . $repository_name) / (1024 * 1024), 2); |
|
|
|
|
$repository_checkout_url = 'svn://' . $this->server_domain . '/' . $repository_name; |
|
|
|
|
if ($this->Mod_dav_svn_status) { |
|
|
|
|
$repository_web_url = $this->protocol . "://" . $this->server_domain . $this->svn_web_path . '/' . $repository_name; |
|
|
|
|
} else { |
|
|
|
|
$repository_web_url = "-"; |
|
|
|
|
} |
|
|
|
|
$result = $this->database_medoo->update("repository", [ |
|
|
|
|
"repository_url" => $repository_url, |
|
|
|
|
"repository_size" => $repository_size, |
|
|
|
@ -1395,7 +1243,8 @@ class Svnserve extends Controller {
@@ -1395,7 +1243,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//扫描仓库并写入仓库表 |
|
|
|
|
private function ScanRepository() { |
|
|
|
|
private function ScanRepository() |
|
|
|
|
{ |
|
|
|
|
$file_arr = scandir($this->svn_repository_path); |
|
|
|
|
foreach ($file_arr as $file_item) { |
|
|
|
|
if ($file_item != '.' && $file_item != '..') { |
|
|
|
@ -1416,7 +1265,8 @@ class Svnserve extends Controller {
@@ -1416,7 +1265,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//向仓库表中更新仓库信息 |
|
|
|
|
private function UpdateRepositoryName($old_repository_name, $new_repository_name) { |
|
|
|
|
private function UpdateRepositoryName($old_repository_name, $new_repository_name) |
|
|
|
|
{ |
|
|
|
|
$old_repository_name = trim($old_repository_name); |
|
|
|
|
$new_repository_name = trim($new_repository_name); |
|
|
|
|
if ($old_repository_name == "" || $old_repository_name == null || $new_repository_name == "" || $new_repository_name == null) { |
|
|
|
@ -1436,7 +1286,8 @@ class Svnserve extends Controller {
@@ -1436,7 +1286,8 @@ class Svnserve extends Controller {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//卸载程序时要清空仓库表和用户-仓库表 |
|
|
|
|
private function TruncateTable() { |
|
|
|
|
private function TruncateTable() |
|
|
|
|
{ |
|
|
|
|
$arr = array( |
|
|
|
|
"repository", |
|
|
|
|
"user_repository" |
|
|
|
@ -1445,5 +1296,4 @@ class Svnserve extends Controller {
@@ -1445,5 +1296,4 @@ class Svnserve extends Controller {
|
|
|
|
|
$this->database_medoo->query("truncate table $value;"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|