Browse Source

完善子进程回收机制 新增守护进程console调试状态启动 修复v2.1.0版本因为信号问题导致的svn卸载失败问题

docker-svn v2.0.0
witersen 3 years ago
parent
commit
8cff1fe783
  1. 14
      02.php/app/controller/config.class.php
  2. 32
      02.php/app/controller/firewall.class.php
  3. 482
      02.php/app/controller/svnserve.class.php
  4. 46
      02.php/app/controller/system.class.php
  5. 2
      02.php/config/config.php
  6. 42
      02.php/server/svnadmind.php
  7. 6
      README.md

14
02.php/app/controller/config.class.php

@ -102,8 +102,8 @@ class Config extends Controller {
//更改版本库父文件夹后触发的操作 //更改版本库父文件夹后触发的操作
private function UpdateRepositoryParentPath($old_path, $new_path) { private function UpdateRepositoryParentPath($old_path, $new_path) {
parent::RequestReplyExec(" mkdir $new_path"); parent::RequestReplyExec("mkdir $new_path");
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep svnserve'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
/* /*
* 没有安装过svn服务 * 没有安装过svn服务
@ -116,7 +116,7 @@ class Config extends Controller {
$file_arr2 = scandir($old_path . '/' . $file_item); $file_arr2 = scandir($old_path . '/' . $file_item);
foreach ($file_arr2 as $file_item2) { foreach ($file_arr2 as $file_item2) {
if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) {
parent::RequestReplyExec(' mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path); parent::RequestReplyExec('mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path);
} }
} }
} }
@ -142,7 +142,7 @@ class Config extends Controller {
* 安装过svn服务 * 安装过svn服务
*/ */
//停止服务 //停止服务
parent::RequestReplyExec(' systemctl stop svnserve'); parent::RequestReplyExec('systemctl stop svnserve');
//移动仓库 //移动仓库
$file_arr = scandir($old_path); $file_arr = scandir($old_path);
foreach ($file_arr as $file_item) { foreach ($file_arr as $file_item) {
@ -151,16 +151,16 @@ class Config extends Controller {
$file_arr2 = scandir($old_path . '/' . $file_item); $file_arr2 = scandir($old_path . '/' . $file_item);
foreach ($file_arr2 as $file_item2) { foreach ($file_arr2 as $file_item2) {
if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) {
parent::RequestReplyExec(' mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path); parent::RequestReplyExec('mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path);
} }
} }
} }
} }
} }
//修改配置文件 //修改配置文件
parent::RequestReplyExec(' sed -i \'s/' . str_replace('/', '\/', $old_path) . '/' . str_replace('/', '\/', $new_path) . '/g\'' . ' /etc/sysconfig/svnserve'); //bug parent::RequestReplyExec('sed -i \'s/' . str_replace('/', '\/', $old_path) . '/' . str_replace('/', '\/', $new_path) . '/g\'' . ' /etc/sysconfig/svnserve'); //bug
//启动服务 //启动服务
parent::RequestReplyExec(' systemctl start svnserve'); parent::RequestReplyExec('systemctl start svnserve');
//检查配置文件是否被正确修改 //检查配置文件是否被正确修改
$file = fopen("/etc/sysconfig/svnserve", "r") or exit("无法打开文件!"); $file = fopen("/etc/sysconfig/svnserve", "r") or exit("无法打开文件!");
$file_content = array(); $file_content = array();

32
02.php/app/controller/firewall.class.php

@ -40,19 +40,19 @@ class Firewall extends Controller {
switch ($action) { switch ($action) {
case 'startFirewall': case 'startFirewall':
parent::RequestReplyExec(' systemctl start firewalld'); parent::RequestReplyExec('systemctl start firewalld');
parent::RequestReplyExec(' firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 parent::RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec(' firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 parent::RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec(' firewall-cmd --reload'); parent::RequestReplyExec('firewall-cmd --reload');
break; break;
case 'restartFirewall': case 'restartFirewall':
parent::RequestReplyExec(' systemctl restart firewalld'); parent::RequestReplyExec('systemctl restart firewalld');
parent::RequestReplyExec(' firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 parent::RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec(' firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 parent::RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec(' firewall-cmd --reload'); parent::RequestReplyExec('firewall-cmd --reload');
break; break;
case 'stopFirewall': case 'stopFirewall':
parent::RequestReplyExec(' systemctl stop firewalld'); parent::RequestReplyExec('systemctl stop firewalld');
break; break;
} }
@ -74,8 +74,8 @@ class Firewall extends Controller {
$data['message'] = '参数不完整'; $data['message'] = '参数不完整';
return $data; return $data;
} }
parent::RequestReplyExec(' firewall-cmd --zone=public --' . $type . '-port=' . $port . '/' . $protocal . ' --permanent'); parent::RequestReplyExec('firewall-cmd --zone=public --' . $type . '-port=' . $port . '/' . $protocal . ' --permanent');
parent::RequestReplyExec(' firewall-cmd --reload'); parent::RequestReplyExec('firewall-cmd --reload');
sleep(1); sleep(1);
@ -87,7 +87,7 @@ class Firewall extends Controller {
//获取防火墙规则 //获取防火墙规则
function GetFirewallPolicy($requestPayload) { function GetFirewallPolicy($requestPayload) {
//获取80 443 3690是否加入防火墙 //获取80 443 3690是否加入防火墙
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep firewalld'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep firewalld');
if ($info == ISNULL) { if ($info == ISNULL) {
$info = array(); $info = array();
$info['svn'] = false; $info['svn'] = false;
@ -101,21 +101,21 @@ class Firewall extends Controller {
} }
$info = array(); $info = array();
$result = trim(parent::RequestReplyExec(' firewall-cmd --query-port=80/tcp')); $result = trim(parent::RequestReplyExec('firewall-cmd --query-port=80/tcp'));
if ($result == 'yes') { if ($result == 'yes') {
$info['http'] = true; $info['http'] = true;
} else { } else {
$info['http'] = false; $info['http'] = false;
} }
$result = trim(parent::RequestReplyExec(' firewall-cmd --query-port=443/tcp')); $result = trim(parent::RequestReplyExec('firewall-cmd --query-port=443/tcp'));
if ($result == 'yes') { if ($result == 'yes') {
$info['https'] = true; $info['https'] = true;
} else { } else {
$info['https'] = false; $info['https'] = false;
} }
$result = trim(parent::RequestReplyExec(' firewall-cmd --query-port=3690/tcp')); $result = trim(parent::RequestReplyExec('firewall-cmd --query-port=3690/tcp'));
if ($result == 'yes') { if ($result == 'yes') {
$info['svn'] = true; $info['svn'] = true;
} else { } else {
@ -130,7 +130,7 @@ class Firewall extends Controller {
//获取防火墙状态 //获取防火墙状态
function GetFirewallStatus($requestPayload) { function GetFirewallStatus($requestPayload) {
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep firewalld'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep firewalld');
if ($info == ISNULL) { if ($info == ISNULL) {
$info = array(); $info = array();
$info['status'] = '已停止'; $info['status'] = '已停止';

482
02.php/app/controller/svnserve.class.php

@ -13,7 +13,8 @@
* 7、如果在本地检出时,http://domain/仓库名称/format 无法访问 权限不够 需要关闭Linux系统的selinux * 7、如果在本地检出时,http://domain/仓库名称/format 无法访问 权限不够 需要关闭Linux系统的selinux
*/ */
class Svnserve extends Controller { class Svnserve extends Controller
{
/* /*
* 注意事项: * 注意事项:
* 1、所有的控制器都要继承基类控制器:Controller * 1、所有的控制器都要继承基类控制器:Controller
@ -37,10 +38,10 @@ class Svnserve extends Controller {
private $Firewall; private $Firewall;
private $System; private $System;
private $Mail; private $Mail;
private $Mod_dav_svn_status;
private $Clientinfo; private $Clientinfo;
function __construct() { function __construct()
{
/* /*
* 避免子类的构造函数覆盖父类的构造函数 * 避免子类的构造函数覆盖父类的构造函数
*/ */
@ -66,11 +67,11 @@ class Svnserve extends Controller {
$this->svn_web_path = $this->Config->Get("SVN_WEB_PATH"); $this->svn_web_path = $this->Config->Get("SVN_WEB_PATH");
$this->svn_port = $this->Config->Get("SVN_PORT"); $this->svn_port = $this->Config->Get("SVN_PORT");
$this->http_port = $this->Config->Get("HTTP_PORT"); $this->http_port = $this->Config->Get("HTTP_PORT");
$this->Mod_dav_svn_status = $this->Config->Get("Mod_dav_svn_status");
} }
//设置仓库的hooks //设置仓库的hooks
function SetRepositoryHooks($requestPayload) { function SetRepositoryHooks($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']); $repository_name = trim($requestPayload['repository_name']);
$hooks_type_list = $requestPayload['hooks_type_list']; $hooks_type_list = $requestPayload['hooks_type_list'];
@ -79,7 +80,7 @@ class Svnserve extends Controller {
$data['message'] = '仓库不存在或文件损坏'; $data['message'] = '仓库不存在或文件损坏';
return $data; return $data;
} }
parent::RequestReplyExec(' chmod 777 -R ' . $this->svn_repository_path); parent::RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path);
foreach ($hooks_type_list as $key => $value) { foreach ($hooks_type_list as $key => $value) {
file_put_contents($this->svn_repository_path . '/' . $repository_name . '/' . 'hooks' . '/' . $value['value'], $value["shell"]); file_put_contents($this->svn_repository_path . '/' . $repository_name . '/' . 'hooks' . '/' . $value['value'], $value["shell"]);
} }
@ -89,7 +90,8 @@ class Svnserve extends Controller {
} }
//获取仓库的hooks //获取仓库的hooks
function GetRepositoryHooks($requestPayload) { function GetRepositoryHooks($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']); $repository_name = trim($requestPayload['repository_name']);
if (empty($repository_name)) { if (empty($repository_name)) {
@ -175,7 +177,8 @@ class Svnserve extends Controller {
} }
//系统首页 获取概览情况 //系统首页 获取概览情况
function GetGailan($requestPayload) { function GetGailan($requestPayload)
{
$userid = $this->this_userid; $userid = $this->this_userid;
$resultlist = array( $resultlist = array(
@ -233,18 +236,12 @@ class Svnserve extends Controller {
} }
//安装svnserve服务 //安装svnserve服务
function Install($requestPayload) { function Install($requestPayload)
$platform = $this->System->GetPlatform(); {
$data = array(); $data = array();
if (!$platform['status'] == 1) {
return $platform;
}
$platform = $platform['platform'];
//创建svn仓库父目录 //创建svn仓库父目录
parent::RequestReplyExec(' mkdir -p ' . $this->svn_repository_path); parent::RequestReplyExec('mkdir -p ' . $this->svn_repository_path);
if (!is_dir($this->svn_repository_path)) { if (!is_dir($this->svn_repository_path)) {
$data['status'] = 0; $data['status'] = 0;
$data['message'] = '安装失败 创建目录失败'; $data['message'] = '安装失败 创建目录失败';
@ -252,133 +249,69 @@ class Svnserve extends Controller {
} }
//通过ps auxf|grep -v "grep"|grep svnserve和判断文件/usr/bin/svnserve是否存在这两方面来同时判断 如果没有安装过则进行安装 //通过ps auxf|grep -v "grep"|grep svnserve和判断文件/usr/bin/svnserve是否存在这两方面来同时判断 如果没有安装过则进行安装
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep svnserve'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
if ($platform == 'CentOS') { //yum安装
parent::RequestReplyExec(" yum install -y subversion"); parent::RequestReplyExec("yum install -y subversion");
/*
* 安装目录浏览的依赖模块 sleep(1);
* 在/etc/httpd/conf.d/下创建空文件AuthUserFile.conf
*/ //通常cp的别名为cp -i ,取消别名
if ($this->Mod_dav_svn_status) { parent::RequestReplyExec("alias cp='cp'");
parent::RequestReplyExec(" yum install -y mod_dav_svn"); parent::RequestReplyExec('cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak');
parent::RequestReplyExec(" touch /etc/httpd/conf.d/AuthUserFile.conf");
parent::RequestReplyExec(" chmod 777 /etc/httpd/conf.d/AuthUserFile.conf"); //更改存储库位置 将配置文件/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
*/
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 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"]);
parent::RequestReplyExec('setenforce 0');
parent::RequestReplyExec("sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config");
//通常cp的别名为cp -i ,取消别名 $data['status'] = 1;
parent::RequestReplyExec(" alias cp='cp'"); $data['message'] = '安装服务成功';
parent::RequestReplyExec(' cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak'); return $data;
//更改存储库位置 将配置文件/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
*/
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 { } else {
if ($platform == 'CentOS') { $data['status'] = 1;
$this->UnInstall(array()); $data['message'] = 'Subversion已存在';
$this->Install(array()); return $data;
} else if ($platform == 'Ubuntu') {
}
} }
$data['status'] = 1;
$data['message'] = '安装服务成功';
return $data;
} }
//卸载svnserve服务 //卸载svnserve服务
function UnInstall($requestPayload) { function UnInstall($requestPayload)
{
//清空表数据 //清空表数据
$this->TruncateTable(); $this->TruncateTable();
$platform = $this->System->GetPlatform(); parent::RequestReplyExec('systemctl stop svnserve');
sleep(2);
parent::RequestReplyExec(" rm -rf " . $this->svn_repository_path); parent::RequestReplyExec('systemctl disable svnserve');
if (is_dir($this->svn_repository_path)) { sleep(2);
$data['status'] = 0; parent::RequestReplyExec('yum remove -y subversion');
$data['message'] = '卸载失败 删除目录失败'; sleep(2);
return $data; parent::RequestReplyExec('yum remove -y subversion');
} sleep(2);
//判断平台 parent::RequestReplyExec('yum remove -y subversion');
if (!$platform['status'] == 1) { sleep(2);
return $platform; parent::RequestReplyExec('rm -f /etc/subversion/servers');
} parent::RequestReplyExec('rm -rf /etc/subversion');
$platform = $platform['platform']; parent::RequestReplyExec('rm -rf /usr/bin/svnserve'); //
parent::RequestReplyExec(' systemctl stop svnserve'); //清除yum缓存
parent::RequestReplyExec(' systemctl disable svnserve'); parent::RequestReplyExec('yum clean all');
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') {
parent::RequestReplyExec(' rm -f /etc/subversion/servers');
parent::RequestReplyExec(' rm -rf /etc/subversion');
//清除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的结果会被缓存,所以需要清除缓存 //is_dir的结果会被缓存,所以需要清除缓存
clearstatcache(); clearstatcache();
@ -389,7 +322,8 @@ class Svnserve extends Controller {
} }
//修复svn服务 包括重新扫描仓库列表重新写入仓库表 //修复svn服务 包括重新扫描仓库列表重新写入仓库表
function Repaire($requestPayload) { function Repaire($requestPayload)
{
//清空仓库表和用户-仓库表 //清空仓库表和用户-仓库表
$this->TruncateTable(); $this->TruncateTable();
//扫描仓库并写入仓库表 //扫描仓库并写入仓库表
@ -403,7 +337,8 @@ class Svnserve extends Controller {
} }
//获取所有仓库信息 计划任务列表下拉菜单使用 //获取所有仓库信息 计划任务列表下拉菜单使用
function GetAllRepositoryList($requestPayload) { function GetAllRepositoryList($requestPayload)
{
$userid = $this->this_userid; $userid = $this->this_userid;
//更新仓库表 //更新仓库表
@ -421,7 +356,7 @@ class Svnserve extends Controller {
//获取列表 //获取列表
$list = $this->database_medoo->select("repository", [ $list = $this->database_medoo->select("repository", [
"repository_name(value)", "repository_name(value)",
], [ ], [
"ORDER" => ["repository_edittime" => "DESC"], "ORDER" => ["repository_edittime" => "DESC"],
]); ]);
} else { } else {
@ -430,9 +365,9 @@ class Svnserve extends Controller {
"[>]repository" => [ "[>]repository" => [
"repositoryid" => "id" "repositoryid" => "id"
], ],
], [ ], [
"repository.repository_name(value)", "repository.repository_name(value)",
], [ ], [
"userid" => $userid, "userid" => $userid,
"ORDER" => ["repository.repository_edittime" => "DESC"], "ORDER" => ["repository.repository_edittime" => "DESC"],
]); ]);
@ -448,7 +383,8 @@ class Svnserve extends Controller {
} }
//项目管理 获取仓库信息 //项目管理 获取仓库信息
function GetRepositoryList($requestPayload) { function GetRepositoryList($requestPayload)
{
$userid = $this->this_userid; $userid = $this->this_userid;
$pageSize = trim($requestPayload['pageSize']); $pageSize = trim($requestPayload['pageSize']);
$currentPage = trim($requestPayload['currentPage']); $currentPage = trim($requestPayload['currentPage']);
@ -492,7 +428,7 @@ class Svnserve extends Controller {
"repository_web_url", "repository_web_url",
"repository_size", "repository_size",
"repository_edittime" "repository_edittime"
], [ ], [
"ORDER" => ["repository_edittime" => "DESC"], "ORDER" => ["repository_edittime" => "DESC"],
"LIMIT" => [$begin, $pageSize] "LIMIT" => [$begin, $pageSize]
]); ]);
@ -521,7 +457,7 @@ class Svnserve extends Controller {
"[>]repository" => [ "[>]repository" => [
"repositoryid" => "id" "repositoryid" => "id"
], ],
], [ ], [
"repository.id", "repository.id",
"repository.repository_name", "repository.repository_name",
"repository.repository_url", "repository.repository_url",
@ -529,7 +465,7 @@ class Svnserve extends Controller {
"repository.repository_web_url", "repository.repository_web_url",
"repository.repository_size", "repository.repository_size",
"repository.repository_edittime" "repository.repository_edittime"
], [ ], [
"userid" => $userid, "userid" => $userid,
"ORDER" => ["repository.repository_edittime" => "DESC"], "ORDER" => ["repository.repository_edittime" => "DESC"],
"LIMIT" => [$begin, $pageSize] "LIMIT" => [$begin, $pageSize]
@ -553,7 +489,8 @@ class Svnserve extends Controller {
} }
//项目管理 按钮 添加svn仓库 包括项目标题 //项目管理 按钮 添加svn仓库 包括项目标题
function AddRepository($requestPayload) { function AddRepository($requestPayload)
{
$repository_name = $requestPayload['repository_name']; $repository_name = $requestPayload['repository_name'];
$this_userid = $this->this_userid; $this_userid = $this->this_userid;
$this_username = $this->this_userid; $this_username = $this->this_userid;
@ -585,43 +522,7 @@ class Svnserve extends Controller {
$data['message'] = '添加仓库失败'; $data['message'] = '添加仓库失败';
return $data; return $data;
} }
parent::RequestReplyExec(' chmod 777 -R ' . $this->svn_repository_path); 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做以下修改, //将新建仓库目录下的conf/svnserve.conf做以下修改,
/* /*
@ -629,17 +530,12 @@ class Svnserve extends Controller {
* 取消注释# password-db = passwd所在行 * 取消注释# password-db = passwd所在行
* 取消注释# authz-db = authz所在行 * 取消注释# authz-db = authz所在行
*/ */
parent::RequestReplyExec(" sed -i 's/# anon-access = read/anon-access = none/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf"); parent::RequestReplyExec("sed -i 's/# anon-access = read/anon-access = none/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf");
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/# 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"); 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); $this->InitRepositoryConfFile($repository_name);
/*
* 配置目录浏览后重载服务· parent::RequestReplyExec('setenforce 0');
*/
if ($this->Mod_dav_svn_status) {
parent::RequestReplyExec(" systemctl reload httpd");
}
parent::RequestReplyExec(' setenforce 0');
if (!$this->InsertRepositoryTable($repository_name)) { if (!$this->InsertRepositoryTable($repository_name)) {
$data['status'] = 0; $data['status'] = 0;
@ -650,12 +546,12 @@ class Svnserve extends Controller {
//发送邮件 //发送邮件
$time = date("Y-m-d-H-i-s"); $time = date("Y-m-d-H-i-s");
$ip = $send_content = "" $ip = $send_content = ""
. "被创建的仓库名称:$repository_name \n" . "被创建的仓库名称:$repository_name \n"
. "操作用户:$this_username \n" . "操作用户:$this_username \n"
. "操作用户uid:$this_userid \n" . "操作用户uid:$this_userid \n"
. "服务器已设置域名:$this->server_domain \n" . "服务器已设置域名:$this->server_domain \n"
. "服务器已设置IP地址:$this->server_ip \n" . "服务器已设置IP地址:$this->server_ip \n"
. "当前时间:$time"; . "当前时间:$time";
$send_title = "SVN仓库创建通知"; $send_title = "SVN仓库创建通知";
$receive_roleid = 2; $receive_roleid = 2;
$receive_userid = 1; $receive_userid = 1;
@ -667,7 +563,8 @@ class Svnserve extends Controller {
} }
//项目管理 按钮 删除svn仓库 //项目管理 按钮 删除svn仓库
function DeleteRepository($requestPayload) { function DeleteRepository($requestPayload)
{
$repository_name = $requestPayload['repository_name']; $repository_name = $requestPayload['repository_name'];
$this_userid = $this->this_userid; $this_userid = $this->this_userid;
$this_username = $this->this_userid; $this_username = $this->this_userid;
@ -684,7 +581,7 @@ class Svnserve extends Controller {
$data['message'] = '失败,项目不存在'; $data['message'] = '失败,项目不存在';
return $data; return $data;
} }
parent::RequestReplyExec(' rm -rf ' . $this->svn_repository_path . '/' . $repository_name); parent::RequestReplyExec('rm -rf ' . $this->svn_repository_path . '/' . $repository_name);
//检查是否删除成功 //检查是否删除成功
if (!is_dir($this->svn_repository_path . '/' . $repository_name)) { if (!is_dir($this->svn_repository_path . '/' . $repository_name)) {
@ -702,12 +599,12 @@ class Svnserve extends Controller {
//发送邮件 //发送邮件
$time = date("Y-m-d-H-i-s"); $time = date("Y-m-d-H-i-s");
$send_content = "" $send_content = ""
. "被删除的仓库名称:$repository_name \n" . "被删除的仓库名称:$repository_name \n"
. "操作用户:$this_username \n" . "操作用户:$this_username \n"
. "操作用户uid:$this_userid \n" . "操作用户uid:$this_userid \n"
. "服务器已设置域名:$this->server_domain \n" . "服务器已设置域名:$this->server_domain \n"
. "服务器已设置IP地址:$this->server_ip \n" . "服务器已设置IP地址:$this->server_ip \n"
. "当前时间:$time"; . "当前时间:$time";
$send_title = "SVN仓库删除通知"; $send_title = "SVN仓库删除通知";
$receive_roleid = 2; $receive_roleid = 2;
$receive_userid = 1; $receive_userid = 1;
@ -719,7 +616,8 @@ class Svnserve extends Controller {
} }
//项目管理 按钮 为svn项目授权 -> 在账号列表收集并提交账户相对于svn项目的权限变化 //项目管理 按钮 为svn项目授权 -> 在账号列表收集并提交账户相对于svn项目的权限变化
function SetRepositoryPrivilege($requestPayload) { function SetRepositoryPrivilege($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']); $repository_name = trim($requestPayload['repository_name']);
$this_account_list = $requestPayload['this_account_list']; $this_account_list = $requestPayload['this_account_list'];
@ -771,7 +669,7 @@ class Svnserve extends Controller {
} }
} }
parent::RequestReplyExec(' echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz'); parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz');
$data['status'] = 1; $data['status'] = 1;
$data['message'] = '账户授权成功'; $data['message'] = '账户授权成功';
@ -779,7 +677,8 @@ class Svnserve extends Controller {
} }
//项目管理 按钮 编辑svn项目 提交用户对svn项目的标题的修改 //项目管理 按钮 编辑svn项目 提交用户对svn项目的标题的修改
function SetRepositoryInfo($requestPayload) { function SetRepositoryInfo($requestPayload)
{
$old_repository_name = trim($requestPayload['old_repository_name']); $old_repository_name = trim($requestPayload['old_repository_name']);
$new_repository_name = trim($requestPayload['new_repository_name']); $new_repository_name = trim($requestPayload['new_repository_name']);
@ -808,9 +707,9 @@ class Svnserve extends Controller {
return $data; return $data;
} }
//修改仓库文件夹的目录 //修改仓库文件夹的目录
parent::RequestReplyExec(' mv ' . $this->svn_repository_path . '/' . $old_repository_name . ' ' . $this->svn_repository_path . '/' . $new_repository_name); parent::RequestReplyExec('mv ' . $this->svn_repository_path . '/' . $old_repository_name . ' ' . $this->svn_repository_path . '/' . $new_repository_name);
// //修改authz文件中的仓库名称 // //修改authz文件中的仓库名称
// parent::RequestReplyExec('sed -i \'s/' . $old_repository_name . '/' . $new_repository_name . '/g\' ' . SVN_CONF_PATH . '/authz'); // parent::RequestReplyExec('sed -i \'s/' . $old_repository_name . '/' . $new_repository_name . '/g\' ' . SVN_CONF_PATH . '/authz');
if (!$this->UpdateRepositoryName($old_repository_name, $new_repository_name)) { if (!$this->UpdateRepositoryName($old_repository_name, $new_repository_name)) {
$data['status'] = 0; $data['status'] = 0;
@ -818,45 +717,14 @@ class Svnserve extends Controller {
return $data; 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['status'] = 1;
$data['message'] = '修改仓库信息成功'; $data['message'] = '修改仓库信息成功';
return $data; return $data;
} }
//获取仓库对应的用户和密码列表 //获取仓库对应的用户和密码列表
function GetRepositoryUserList($requestPayload) { function GetRepositoryUserList($requestPayload)
{
$repository_name = $requestPayload['repository_name']; $repository_name = $requestPayload['repository_name'];
if (empty($repository_name)) { if (empty($repository_name)) {
@ -884,9 +752,9 @@ class Svnserve extends Controller {
$temp = explode('=', $file_content[$i]); $temp = explode('=', $file_content[$i]);
$account_info[$j]['id'] = $j; $account_info[$j]['id'] = $j;
$account_info[$j]['account'] = trim($temp[0]); $account_info[$j]['account'] = trim($temp[0]);
// if ($is_need_passwd == 1) { // if ($is_need_passwd == 1) {
$account_info[$j]['password'] = trim($temp[1]); $account_info[$j]['password'] = trim($temp[1]);
// } // }
$j++; $j++;
} }
} }
@ -898,7 +766,8 @@ class Svnserve extends Controller {
} }
//获取仓库对应的账户的权限 //获取仓库对应的账户的权限
function GetRepositoryUserPrivilegeList($requestPayload) { function GetRepositoryUserPrivilegeList($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']); $repository_name = trim($requestPayload['repository_name']);
if (empty($repository_name)) { if (empty($repository_name)) {
@ -958,7 +827,8 @@ class Svnserve extends Controller {
} }
//账号管理 添加账号 //账号管理 添加账号
function AddAccount($requestPayload) { function AddAccount($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']); $repository_name = trim($requestPayload['repository_name']);
$account = trim($requestPayload['account']); $account = trim($requestPayload['account']);
$passwd = trim($requestPayload['password']); $passwd = trim($requestPayload['password']);
@ -995,7 +865,7 @@ class Svnserve extends Controller {
//账户冲突校验 //账户冲突校验
$account_list = array(); $account_list = array();
$temp = $this->GetRepositoryUserList(array("repository_name" => $repository_name))['data']; $temp = $this->GetRepositoryUserList(array("repository_name" => $repository_name))['data'];
// $temp = $this->GetAccountList(0, 99, 99)['data']; // $temp = $this->GetAccountList(0, 99, 99)['data'];
foreach ($temp as $key => $value) { foreach ($temp as $key => $value) {
array_push($account_list, $value['account']); array_push($account_list, $value['account']);
} }
@ -1017,16 +887,7 @@ class Svnserve extends Controller {
//写入文件 //写入文件
array_push($file_content, $account . ' = ' . $passwd . "\n"); array_push($file_content, $account . ' = ' . $passwd . "\n");
$file_content = implode($file_content); $file_content = implode($file_content);
parent::RequestReplyExec(' echo \'' . $file_content . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); 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['status'] = 1;
$data['message'] = '添加账户成功'; $data['message'] = '添加账户成功';
@ -1034,7 +895,8 @@ class Svnserve extends Controller {
} }
//账号管理 删除账号 //账号管理 删除账号
function DeleteAccount($requestPayload) { function DeleteAccount($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']); $repository_name = trim($requestPayload['repository_name']);
$account = trim($requestPayload['account']); $account = trim($requestPayload['account']);
@ -1058,7 +920,7 @@ class Svnserve extends Controller {
} }
fclose($file); fclose($file);
for ($i = 0; $i < sizeof($file_content); $i++) { for ($i = 0; $i < sizeof($file_content); $i++) {
// if (!strstr(trim($file_content[$i]), '[users]')) { // if (!strstr(trim($file_content[$i]), '[users]')) {
if (strstr(trim($file_content[$i]), '=')) { if (strstr(trim($file_content[$i]), '=')) {
$temp = trim(substr($file_content[$i], 0, strrpos($file_content[$i], '='))); $temp = trim(substr($file_content[$i], 0, strrpos($file_content[$i], '=')));
if ($temp == $account) { if ($temp == $account) {
@ -1068,7 +930,7 @@ class Svnserve extends Controller {
} }
} }
$con = implode($file_content); $con = implode($file_content);
parent::RequestReplyExec(' echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
//删除authz文件中的账号 //删除authz文件中的账号
$file = fopen($this->svn_repository_path . '/' . $repository_name . '/conf/authz', "r") or exit("无法打开文件!"); $file = fopen($this->svn_repository_path . '/' . $repository_name . '/conf/authz', "r") or exit("无法打开文件!");
@ -1087,15 +949,7 @@ class Svnserve extends Controller {
} }
} }
$con = implode($file_content); $con = implode($file_content);
parent::RequestReplyExec(' echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz'); 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['status'] = 1;
$data['message'] = '删除账户成功'; $data['message'] = '删除账户成功';
@ -1103,7 +957,8 @@ class Svnserve extends Controller {
} }
//账号管理 编辑账号 提交用户对账号信息的修改 账号作为唯一标识不能修改 //账号管理 编辑账号 提交用户对账号信息的修改 账号作为唯一标识不能修改
function SetCountInfo($requestPayload) { function SetCountInfo($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']); $repository_name = trim($requestPayload['repository_name']);
$account = trim($requestPayload['account']); $account = trim($requestPayload['account']);
$passwd = trim($requestPayload['password']); $passwd = trim($requestPayload['password']);
@ -1130,7 +985,7 @@ class Svnserve extends Controller {
} }
fclose($file); fclose($file);
for ($i = 0; $i < sizeof($file_content); $i++) { for ($i = 0; $i < sizeof($file_content); $i++) {
// if (!strstr(trim($file_content[$i]), '[users]')) { // if (!strstr(trim($file_content[$i]), '[users]')) {
if (strstr(trim($file_content[$i]), '=')) { if (strstr(trim($file_content[$i]), '=')) {
$temp = trim(substr($file_content[$i], 0, strrpos($file_content[$i], '='))); $temp = trim(substr($file_content[$i], 0, strrpos($file_content[$i], '=')));
if ($temp == $account) { if ($temp == $account) {
@ -1140,14 +995,7 @@ class Svnserve extends Controller {
} }
} }
$con = implode($file_content); $con = implode($file_content);
parent::RequestReplyExec(' echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); 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['status'] = 1;
$data['message'] = '修改成功'; $data['message'] = '修改成功';
@ -1155,7 +1003,8 @@ class Svnserve extends Controller {
} }
//高级设置 初始化加载 列出svnserve服务的状态 //高级设置 初始化加载 列出svnserve服务的状态
function GetSvnserveStatus($requestPayload) { function GetSvnserveStatus($requestPayload)
{
//是否安装服务 //是否安装服务
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
@ -1182,7 +1031,7 @@ class Svnserve extends Controller {
return $data; return $data;
} }
//是否启动 //是否启动
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep svnserve'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && file_exists('/usr/bin/svnserve')) {
$info = array(); $info = array();
$info['status'] = '已停止'; //svn服务未启动 $info['status'] = '已停止'; //svn服务未启动
@ -1207,7 +1056,8 @@ class Svnserve extends Controller {
} }
//高级设置 管理svnserve服务的状态 //高级设置 管理svnserve服务的状态
function SetSvnserveStatus($requestPayload) { function SetSvnserveStatus($requestPayload)
{
$action = $requestPayload['action']; $action = $requestPayload['action'];
if (empty($action)) { if (empty($action)) {
@ -1218,13 +1068,13 @@ class Svnserve extends Controller {
switch ($action) { switch ($action) {
case 'startSvn': case 'startSvn':
parent::RequestReplyExec(' systemctl start svnserve'); parent::RequestReplyExec('systemctl start svnserve');
break; break;
case 'restartSvn': case 'restartSvn':
parent::RequestReplyExec(' systemctl restart svnserve'); parent::RequestReplyExec('systemctl restart svnserve');
break; break;
case 'stopSvn': case 'stopSvn':
parent::RequestReplyExec(' systemctl stop svnserve'); parent::RequestReplyExec('systemctl stop svnserve');
break; break;
} }
@ -1234,7 +1084,8 @@ class Svnserve extends Controller {
} }
//获取随机的root密码 //获取随机的root密码
private function GetInitPasswd($length) { private function GetInitPasswd($length)
{
!empty($length) or die('参数不完整'); !empty($length) or die('参数不完整');
$str = md5(time()); $str = md5(time());
@ -1243,15 +1094,17 @@ 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); $res = preg_match('/^[\x{4e00}-\x{9fa5}A-Za-z0-9_]+$/u', $str);
return $res ? true : false; return $res ? true : false;
} }
//获取服务状态 检查相关的目录文件是否存在 //获取服务状态 检查相关的目录文件是否存在
private function CheckSvnserveStatus() { private function CheckSvnserveStatus()
{
//是否安装服务 //是否安装服务
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep svnserve'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
$data['status'] = 0; $data['status'] = 0;
$data['code'] = '00'; $data['code'] = '00';
@ -1266,7 +1119,7 @@ class Svnserve extends Controller {
return $data; return $data;
} }
//是否启动 //是否启动
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep svnserve'); $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && file_exists('/usr/bin/svnserve')) {
$data['status'] = 0; $data['status'] = 0;
$data['code'] = '01'; $data['code'] = '01';
@ -1279,11 +1132,12 @@ class Svnserve extends Controller {
} }
//获取文件夹体积 //获取文件夹体积
private function GetDirSize($dir) { private function GetDirSize($dir)
{
clearstatcache(); clearstatcache();
$dh = opendir($dir) or exit('打开目录错误'); //打开目录,返回一个目录流 $dh = opendir($dir) or exit('打开目录错误'); //打开目录,返回一个目录流
$size = 0; //初始大小为0 $size = 0; //初始大小为0
while (false !== ($file = @readdir($dh))) {//循环读取目录下的文件 while (false !== ($file = @readdir($dh))) { //循环读取目录下的文件
if ($file != '.' and $file != '..') { if ($file != '.' and $file != '..') {
$path = $dir . '/' . $file; //设置目录,用于含有子目录的情况 $path = $dir . '/' . $file; //设置目录,用于含有子目录的情况
if (is_dir($path)) { if (is_dir($path)) {
@ -1298,7 +1152,8 @@ class Svnserve extends Controller {
} }
//从仓库表中删除仓库信息 //从仓库表中删除仓库信息
private function DeleteRepositoryTable($repository_name) { private function DeleteRepositoryTable($repository_name)
{
$repository_name = trim($repository_name); $repository_name = trim($repository_name);
if ($repository_name == "" || $repository_name == null) { if ($repository_name == "" || $repository_name == null) {
return false; return false;
@ -1327,7 +1182,8 @@ class Svnserve extends Controller {
} }
//写入账户和密码的初始内容到仓库中的passowrd和authz配置文件,进行仓库初始化 //写入账户和密码的初始内容到仓库中的passowrd和authz配置文件,进行仓库初始化
private function InitRepositoryConfFile($repository_name) { private function InitRepositoryConfFile($repository_name)
{
//将以下内容写入authz文件 //将以下内容写入authz文件
/* /*
* [aliases] * [aliases]
@ -1336,7 +1192,7 @@ class Svnserve extends Controller {
* root=rw * root=rw
*/ */
$con = "[aliases]\n\n[groups]\n\n[/]\nroot = rw"; $con = "[aliases]\n\n[groups]\n\n[/]\nroot = rw";
parent::RequestReplyExec(' echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz'); parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz');
//将以下内容写入passwd文件 //将以下内容写入passwd文件
/* /*
* [users] * [users]
@ -1344,17 +1200,12 @@ class Svnserve extends Controller {
*/ */
$pass = trim($this->GetInitPasswd(16)); $pass = trim($this->GetInitPasswd(16));
$con = "[users]\nroot = " . $pass . "\n"; $con = "[users]\nroot = " . $pass . "\n";
parent::RequestReplyExec(' echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); 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); $repository_name = trim($repository_name);
if ($repository_name == "" || $repository_name == null) { if ($repository_name == "" || $repository_name == null) {
return false; return false;
@ -1365,7 +1216,8 @@ class Svnserve extends Controller {
} }
//扫描仓库信息并更新仓库信息表 //扫描仓库信息并更新仓库信息表
private function UpdateRepositoryInfo() { private function UpdateRepositoryInfo()
{
//查仓库表 //查仓库表
$list = $this->database_medoo->select("repository", [ $list = $this->database_medoo->select("repository", [
"id", "id",
@ -1378,24 +1230,21 @@ class Svnserve extends Controller {
$repository_url = $this->svn_repository_path . '/' . $repository_name; $repository_url = $this->svn_repository_path . '/' . $repository_name;
$repository_size = round($this->GetDirSize($this->svn_repository_path . '/' . $repository_name) / (1024 * 1024), 2); $repository_size = round($this->GetDirSize($this->svn_repository_path . '/' . $repository_name) / (1024 * 1024), 2);
$repository_checkout_url = 'svn://' . $this->server_domain . '/' . $repository_name; $repository_checkout_url = 'svn://' . $this->server_domain . '/' . $repository_name;
if ($this->Mod_dav_svn_status) { $repository_web_url = "-";
$repository_web_url = $this->protocol . "://" . $this->server_domain . $this->svn_web_path . '/' . $repository_name;
} else {
$repository_web_url = "-";
}
$result = $this->database_medoo->update("repository", [ $result = $this->database_medoo->update("repository", [
"repository_url" => $repository_url, "repository_url" => $repository_url,
"repository_size" => $repository_size, "repository_size" => $repository_size,
"repository_checkout_url" => $repository_checkout_url, "repository_checkout_url" => $repository_checkout_url,
"repository_web_url" => $repository_web_url "repository_web_url" => $repository_web_url
], [ ], [
"id" => $id "id" => $id
]); ]);
} }
} }
//扫描仓库并写入仓库表 //扫描仓库并写入仓库表
private function ScanRepository() { private function ScanRepository()
{
$file_arr = scandir($this->svn_repository_path); $file_arr = scandir($this->svn_repository_path);
foreach ($file_arr as $file_item) { foreach ($file_arr as $file_item) {
if ($file_item != '.' && $file_item != '..') { if ($file_item != '.' && $file_item != '..') {
@ -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); $old_repository_name = trim($old_repository_name);
$new_repository_name = trim($new_repository_name); $new_repository_name = trim($new_repository_name);
if ($old_repository_name == "" || $old_repository_name == null || $new_repository_name == "" || $new_repository_name == null) { if ($old_repository_name == "" || $old_repository_name == null || $new_repository_name == "" || $new_repository_name == null) {
@ -1436,7 +1286,8 @@ class Svnserve extends Controller {
} }
//卸载程序时要清空仓库表和用户-仓库表 //卸载程序时要清空仓库表和用户-仓库表
private function TruncateTable() { private function TruncateTable()
{
$arr = array( $arr = array(
"repository", "repository",
"user_repository" "user_repository"
@ -1445,5 +1296,4 @@ class Svnserve extends Controller {
$this->database_medoo->query("truncate table $value;"); $this->database_medoo->query("truncate table $value;");
} }
} }
} }

46
02.php/app/controller/system.class.php

@ -4,7 +4,8 @@
* 与操作系统相关的方法的封装 * 与操作系统相关的方法的封装
*/ */
class System extends Controller { class System extends Controller
{
/* /*
* 注意事项: * 注意事项:
* 1、所有的控制器都要继承基类控制器:Controller * 1、所有的控制器都要继承基类控制器:Controller
@ -19,7 +20,8 @@ class System extends Controller {
private $Config; private $Config;
function __construct() { function __construct()
{
/* /*
* 避免子类的构造函数覆盖父类的构造函数 * 避免子类的构造函数覆盖父类的构造函数
*/ */
@ -32,7 +34,8 @@ class System extends Controller {
} }
//判断操作系统类型 //判断操作系统类型
function GetPlatform() { function GetPlatform()
{
if (!PHP_OS == 'Linux') { if (!PHP_OS == 'Linux') {
$data['status'] = 0; $data['status'] = 0;
$data['message'] = '当前操作系统不为Linux'; $data['message'] = '当前操作系统不为Linux';
@ -68,7 +71,8 @@ class System extends Controller {
} }
//获取磁盘信息,如果有多块磁盘如何处理,可以只显示某个目录如根目录对应的磁盘容量 //获取磁盘信息,如果有多块磁盘如何处理,可以只显示某个目录如根目录对应的磁盘容量
function GetDiskInfo($requestPayload) { function GetDiskInfo($requestPayload)
{
$info['DiskTotal'] = round(disk_total_space(".") / 1024 / 1024 / 1024, 1); $info['DiskTotal'] = round(disk_total_space(".") / 1024 / 1024 / 1024, 1);
$info['DiskFree'] = round(disk_free_space(".") / 1024 / 1024 / 1024, 1); $info['DiskFree'] = round(disk_free_space(".") / 1024 / 1024 / 1024, 1);
$info['DiskUsed'] = round($info['DiskTotal'] - $info['DiskFree'], 1); $info['DiskUsed'] = round($info['DiskTotal'] - $info['DiskFree'], 1);
@ -81,15 +85,16 @@ class System extends Controller {
} }
//获取服务器运行时间 //获取服务器运行时间
function GetServerUpTime($requestPayload) { function GetServerUpTime($requestPayload)
{
$temp = file_get_contents('/proc/uptime'); $temp = file_get_contents('/proc/uptime');
$info = explode(" ", $temp); $info = explode(" ", $temp);
$info = trim($info[0]); //系统自启动开始的秒数 $info = trim($info[0]); //系统自启动开始的秒数
$min = $info / 60; $min = $info / 60;
$hours = $min / 60; $hours = $min / 60;
$days = floor($hours / 24); $days = floor($hours / 24);
$hours = floor($hours - ( $days * 24)); $hours = floor($hours - ($days * 24));
$min = floor($min - ( $days * 60 * 24) - ( $hours * 60)); $min = floor($min - ($days * 60 * 24) - ($hours * 60));
$info = $days . "天" . $hours . "小时" . $min . "分钟"; $info = $days . "天" . $hours . "小时" . $min . "分钟";
$data['status'] = 1; $data['status'] = 1;
@ -112,7 +117,8 @@ class System extends Controller {
* softirq 0 从系统启动开始累计到当前时刻,软中断时间 * softirq 0 从系统启动开始累计到当前时刻,软中断时间
*/ */
//GetCPURate GetCPUInfo //GetCPURate GetCPUInfo
function GetCPURate($requestPayload) { function GetCPURate($requestPayload)
{
//第一次取值 //第一次取值
$array = file('/proc/stat'); $array = file('/proc/stat');
if (!$array) if (!$array)
@ -141,7 +147,8 @@ class System extends Controller {
} }
//获取内存信息 //获取内存信息
function GetMemInfo($requestPayload) { function GetMemInfo($requestPayload)
{
$array = file('/proc/meminfo'); $array = file('/proc/meminfo');
if (!$array) if (!$array)
return false; return false;
@ -178,7 +185,8 @@ class System extends Controller {
} }
//获取系统平均负载,有问题未修复 //获取系统平均负载,有问题未修复
function GetLoadAvg($requestPayload) { function GetLoadAvg($requestPayload)
{
//获取系统总核心数 //获取系统总核心数
$array = file('/proc/cpuinfo'); $array = file('/proc/cpuinfo');
if (!$array) if (!$array)
@ -210,7 +218,8 @@ class System extends Controller {
} }
//根据网卡名称获取实时网速 动态更新使用 //根据网卡名称获取实时网速 动态更新使用
function GetNetworkByName($requestPayload) { function GetNetworkByName($requestPayload)
{
$network_name = $requestPayload['network_name']; $network_name = $requestPayload['network_name'];
//获取时间 作为x坐标轴数据 //获取时间 作为x坐标轴数据
@ -236,7 +245,8 @@ class System extends Controller {
} }
//获取网卡实时网速 第一次加载时使用 //获取网卡实时网速 第一次加载时使用
function GetNetwork($requestPayload) { function GetNetwork($requestPayload)
{
//获取时间 作为x坐标轴数据 //获取时间 作为x坐标轴数据
$time = date("H:i:s"); $time = date("H:i:s");
$sleeptime = 1; $sleeptime = 1;
@ -247,7 +257,7 @@ class System extends Controller {
//计算 //计算
$result = array(); $result = array();
foreach ($info1 as $key => $value) { foreach ($info1 as $key => $value) {
// $result[$key]['name'] = $value['name']; // $result[$key]['name'] = $value['name'];
$result[$value['name']][0]['ReceiveSpeed'] = ($info2[$key]['Receive']['bytes'] - $info1[$key]['Receive']['bytes']) / $sleeptime / 1024; //1s内的网络速度 单位 kbps $result[$value['name']][0]['ReceiveSpeed'] = ($info2[$key]['Receive']['bytes'] - $info1[$key]['Receive']['bytes']) / $sleeptime / 1024; //1s内的网络速度 单位 kbps
$result[$value['name']][0]['TransmitSpeed'] = ($info2[$key]['Transmit']['bytes'] - $info1[$key]['Transmit']['bytes']) / $sleeptime / 1024; //1s内的网络速度 单位 kbps $result[$value['name']][0]['TransmitSpeed'] = ($info2[$key]['Transmit']['bytes'] - $info1[$key]['Transmit']['bytes']) / $sleeptime / 1024; //1s内的网络速度 单位 kbps
$result[$value['name']][0]['time'] = $time; $result[$value['name']][0]['time'] = $time;
@ -260,7 +270,8 @@ class System extends Controller {
} }
//获取单次网卡的流量 //获取单次网卡的流量
private function GetSingleNetwork($network_name) { private function GetSingleNetwork($network_name)
{
/* /*
* bytes 接口发送或接收的数据的总字节数 * bytes 接口发送或接收的数据的总字节数
* packets 接口发送或接收的数据包总数 * packets 接口发送或接收的数据包总数
@ -303,9 +314,9 @@ class System extends Controller {
//去除网卡名称中的冒号 //去除网卡名称中的冒号
$value[0] = str_replace(':', '', $value[0]); $value[0] = str_replace(':', '', $value[0]);
//删除本地回环口lo的数据 //删除本地回环口lo的数据
// if ($value[0] == 'lo') { // if ($value[0] == 'lo') {
// continue; // continue;
// } // }
//只保留特定的网卡 //只保留特定的网卡
if ($network_name != '') { if ($network_name != '') {
if ($value[0] != $network_name) { if ($value[0] != $network_name) {
@ -324,5 +335,4 @@ class System extends Controller {
return $networklist; return $networklist;
} }
} }

2
02.php/config/config.php

@ -48,7 +48,7 @@ define("SOCKET_LISTEN_BACKLOG", 2000);
* 当前软件版本信息 * 当前软件版本信息
* 用户请不要自行修改 以免影响后续升级检测 * 用户请不要自行修改 以免影响后续升级检测
*/ */
define('VERSION', '2.1.0'); define('VERSION', '2.1.1');
/** /**
* 升级服务器地址 * 升级服务器地址

42
02.php/server/svnadmind.php

@ -12,9 +12,11 @@ class Daemon
{ {
private $pidfile; private $pidfile;
private $state;
private $cmdlist = array( private $cmdlist = array(
"start", "start",
"stop" "stop",
"console"
); );
function __construct() function __construct()
@ -28,7 +30,7 @@ class Daemon
if ($pid < 0) { if ($pid < 0) {
exit("pcntl_fork 错误"); exit("pcntl_fork 错误");
} elseif ($pid > 0) { } elseif ($pid > 0) {
exit(0); exit();
} }
$sid = posix_setsid(); $sid = posix_setsid();
if (!$sid) { if (!$sid) {
@ -38,7 +40,7 @@ class Daemon
if ($pid < 0) { if ($pid < 0) {
exit("pcntl_fork 错误"); exit("pcntl_fork 错误");
} elseif ($pid > 0) { } elseif ($pid > 0) {
exit(0); exit();
} }
chdir("/"); chdir("/");
umask(0); umask(0);
@ -68,12 +70,15 @@ class Daemon
//监听 设置并发队列的最大长度 //监听 设置并发队列的最大长度
socket_listen($socket, SOCKET_LISTEN_BACKLOG); socket_listen($socket, SOCKET_LISTEN_BACKLOG);
while (true) { while (true) {
//非阻塞式回收僵尸进程
pcntl_wait($status, WNOHANG);
$clien = socket_accept($socket) or die("socket_accept 错误"); $clien = socket_accept($socket) or die("socket_accept 错误");
//如果父进程不关心子进程什么时候结束 子进程结束后 内核会回收 //非阻塞式回收僵尸进程
//避免了正常情况下僵尸进程的产生 pcntl_wait($status, WNOHANG);
pcntl_signal(SIGCHLD, SIG_IGN);
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid == -1) { if ($pid == -1) {
@ -90,14 +95,20 @@ class Daemon
//接收客户端发送的数据 //接收客户端发送的数据
$data = socket_read($clien, SOCKET_READ_LENGTH); $data = socket_read($clien, SOCKET_READ_LENGTH);
//console
$this->state == "console" ? print_r($data . "\n") : "";
//执行 //执行
$result = shell_exec($data); $result = shell_exec($data);
//console
$this->state == "console" ? print_r($result . "\n") : "";
//处理没有返回内容的情况 否则 socket_write 遇到空内容会报错 //处理没有返回内容的情况 否则 socket_write 遇到空内容会报错
$result = $result == "" ? ISNULL : $result; $result = $result == "" ? ISNULL : $result;
//将结果返回给客户端 //将结果返回给客户端
socket_write($clien, $result, strlen($result)) or die("socket_write error"); socket_write($clien, $result, strlen($result)) or die("socket_write 错误");
//关闭会话 //关闭会话
socket_close($clien); socket_close($clien);
@ -113,7 +124,7 @@ class Daemon
$result = trim(shell_exec("ps -ax | awk '{ print $1 }' | grep -e \"^$pid$\"")); $result = trim(shell_exec("ps -ax | awk '{ print $1 }' | grep -e \"^$pid$\""));
if (strstr($result, $pid)) { if (strstr($result, $pid)) {
echo "进程正在运行中 无需启动\n"; echo "进程正在运行中 无需启动\n";
exit(0); exit();
} }
} }
return $this->init_daemon(); return $this->init_daemon();
@ -142,17 +153,20 @@ class Daemon
public function run($argv) public function run($argv)
{ {
if (isset($argv[1])) { if (isset($argv[1])) {
if (!in_array($argv[1], $this->cmdlist)) { $this->state = $argv[1];
echo "用法: php svnadmind.php [start] [stop]\n"; if (!in_array($this->state, $this->cmdlist)) {
return; echo "用法: php svnadmind.php [start] [stop] [console]\n";
exit();
} }
if ($argv[1] == 'start') { if ($this->state == 'start') {
$this->start(); $this->start();
} else if ($argv[1] == 'stop') { } else if ($this->state == 'stop') {
$this->stop(); $this->stop();
} else if ($this->state == 'console') {
$this->init_socket();
} }
} else { } else {
echo "用法: php svnadmind.php [start] [stop]\n"; echo "用法: php svnadmind.php [start] [stop] [console]\n";
} }
} }
} }

6
README.md

@ -28,11 +28,16 @@ yum install -y php-json #json相关函数
yum install -y httpd #安装Apache yum install -y httpd #安装Apache
systemctl start httpd #开启Apache systemctl start httpd #开启Apache
systemctl enable httpd #将Apache加入开机自启动 systemctl enable httpd #将Apache加入开机自启动
systemctl restart php-fpm
``` ```
### (三)下载并解压部署程序 ### (三)下载并解压部署程序
- 在控制台 执行以下命令 将数据库文件移动到指定位置 - 在控制台 执行以下命令 将数据库文件移动到指定位置
``` ```
cd /var/www/html/
wget https://gitee.com/witersen/SvnAdminV2.0/releases/v2.1
unzip v2.1.0.zip
mv v2.1.0.zip/* ./*
mkdir -p /usr/local/svnadmin mkdir -p /usr/local/svnadmin
mv svnadmin.db /usr/local/svnadmin mv svnadmin.db /usr/local/svnadmin
chmod -R 777 /usr/local/svnadmin chmod -R 777 /usr/local/svnadmin
@ -43,6 +48,7 @@ chmod -R 777 /usr/local/svnadmin
- 进入程序代码的server目录,在命令行下以root用户身份执行以下命令 - 进入程序代码的server目录,在命令行下以root用户身份执行以下命令
``` ```
cd server
php svnadmind.php start php svnadmind.php start
``` ```

Loading…
Cancel
Save