Browse Source

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

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

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

@ -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;");
}
}
}

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

@ -4,7 +4,8 @@ @@ -4,7 +4,8 @@
* 与操作系统相关的方法的封装
*/
class System extends Controller {
class System extends Controller
{
/*
* 注意事项:
* 1、所有的控制器都要继承基类控制器:Controller
@ -19,7 +20,8 @@ class System extends Controller { @@ -19,7 +20,8 @@ class System extends Controller {
private $Config;
function __construct() {
function __construct()
{
/*
* 避免子类的构造函数覆盖父类的构造函数
*/
@ -32,7 +34,8 @@ class System extends Controller { @@ -32,7 +34,8 @@ class System extends Controller {
}
//判断操作系统类型
function GetPlatform() {
function GetPlatform()
{
if (!PHP_OS == 'Linux') {
$data['status'] = 0;
$data['message'] = '当前操作系统不为Linux';
@ -68,7 +71,8 @@ class System extends Controller { @@ -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['DiskFree'] = round(disk_free_space(".") / 1024 / 1024 / 1024, 1);
$info['DiskUsed'] = round($info['DiskTotal'] - $info['DiskFree'], 1);
@ -81,7 +85,8 @@ class System extends Controller { @@ -81,7 +85,8 @@ class System extends Controller {
}
//获取服务器运行时间
function GetServerUpTime($requestPayload) {
function GetServerUpTime($requestPayload)
{
$temp = file_get_contents('/proc/uptime');
$info = explode(" ", $temp);
$info = trim($info[0]); //系统自启动开始的秒数
@ -112,7 +117,8 @@ class System extends Controller { @@ -112,7 +117,8 @@ class System extends Controller {
* softirq 0 从系统启动开始累计到当前时刻,软中断时间
*/
//GetCPURate GetCPUInfo
function GetCPURate($requestPayload) {
function GetCPURate($requestPayload)
{
//第一次取值
$array = file('/proc/stat');
if (!$array)
@ -141,7 +147,8 @@ class System extends Controller { @@ -141,7 +147,8 @@ class System extends Controller {
}
//获取内存信息
function GetMemInfo($requestPayload) {
function GetMemInfo($requestPayload)
{
$array = file('/proc/meminfo');
if (!$array)
return false;
@ -178,7 +185,8 @@ class System extends Controller { @@ -178,7 +185,8 @@ class System extends Controller {
}
//获取系统平均负载,有问题未修复
function GetLoadAvg($requestPayload) {
function GetLoadAvg($requestPayload)
{
//获取系统总核心数
$array = file('/proc/cpuinfo');
if (!$array)
@ -210,7 +218,8 @@ class System extends Controller { @@ -210,7 +218,8 @@ class System extends Controller {
}
//根据网卡名称获取实时网速 动态更新使用
function GetNetworkByName($requestPayload) {
function GetNetworkByName($requestPayload)
{
$network_name = $requestPayload['network_name'];
//获取时间 作为x坐标轴数据
@ -236,7 +245,8 @@ class System extends Controller { @@ -236,7 +245,8 @@ class System extends Controller {
}
//获取网卡实时网速 第一次加载时使用
function GetNetwork($requestPayload) {
function GetNetwork($requestPayload)
{
//获取时间 作为x坐标轴数据
$time = date("H:i:s");
$sleeptime = 1;
@ -260,7 +270,8 @@ class System extends Controller { @@ -260,7 +270,8 @@ class System extends Controller {
}
//获取单次网卡的流量
private function GetSingleNetwork($network_name) {
private function GetSingleNetwork($network_name)
{
/*
* bytes 接口发送或接收的数据的总字节数
* packets 接口发送或接收的数据包总数
@ -324,5 +335,4 @@ class System extends Controller { @@ -324,5 +335,4 @@ class System extends Controller {
return $networklist;
}
}

2
02.php/config/config.php

@ -48,7 +48,7 @@ define("SOCKET_LISTEN_BACKLOG", 2000); @@ -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 @@ -12,9 +12,11 @@ class Daemon
{
private $pidfile;
private $state;
private $cmdlist = array(
"start",
"stop"
"stop",
"console"
);
function __construct()
@ -28,7 +30,7 @@ class Daemon @@ -28,7 +30,7 @@ class Daemon
if ($pid < 0) {
exit("pcntl_fork 错误");
} elseif ($pid > 0) {
exit(0);
exit();
}
$sid = posix_setsid();
if (!$sid) {
@ -38,7 +40,7 @@ class Daemon @@ -38,7 +40,7 @@ class Daemon
if ($pid < 0) {
exit("pcntl_fork 错误");
} elseif ($pid > 0) {
exit(0);
exit();
}
chdir("/");
umask(0);
@ -68,12 +70,15 @@ class Daemon @@ -68,12 +70,15 @@ class Daemon
//监听 设置并发队列的最大长度
socket_listen($socket, SOCKET_LISTEN_BACKLOG);
while (true) {
//非阻塞式回收僵尸进程
pcntl_wait($status, WNOHANG);
$clien = socket_accept($socket) or die("socket_accept 错误");
//如果父进程不关心子进程什么时候结束 子进程结束后 内核会回收
//避免了正常情况下僵尸进程的产生
pcntl_signal(SIGCHLD, SIG_IGN);
//非阻塞式回收僵尸进程
pcntl_wait($status, WNOHANG);
$pid = pcntl_fork();
if ($pid == -1) {
@ -90,14 +95,20 @@ class Daemon @@ -90,14 +95,20 @@ class Daemon
//接收客户端发送的数据
$data = socket_read($clien, SOCKET_READ_LENGTH);
//console
$this->state == "console" ? print_r($data . "\n") : "";
//执行
$result = shell_exec($data);
//console
$this->state == "console" ? print_r($result . "\n") : "";
//处理没有返回内容的情况 否则 socket_write 遇到空内容会报错
$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);
@ -113,7 +124,7 @@ class Daemon @@ -113,7 +124,7 @@ class Daemon
$result = trim(shell_exec("ps -ax | awk '{ print $1 }' | grep -e \"^$pid$\""));
if (strstr($result, $pid)) {
echo "进程正在运行中 无需启动\n";
exit(0);
exit();
}
}
return $this->init_daemon();
@ -142,17 +153,20 @@ class Daemon @@ -142,17 +153,20 @@ class Daemon
public function run($argv)
{
if (isset($argv[1])) {
if (!in_array($argv[1], $this->cmdlist)) {
echo "用法: php svnadmind.php [start] [stop]\n";
return;
$this->state = $argv[1];
if (!in_array($this->state, $this->cmdlist)) {
echo "用法: php svnadmind.php [start] [stop] [console]\n";
exit();
}
if ($argv[1] == 'start') {
if ($this->state == 'start') {
$this->start();
} else if ($argv[1] == 'stop') {
} else if ($this->state == 'stop') {
$this->stop();
} else if ($this->state == 'console') {
$this->init_socket();
}
} 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相关函数 @@ -28,11 +28,16 @@ yum install -y php-json #json相关函数
yum install -y httpd #安装Apache
systemctl start 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
mv svnadmin.db /usr/local/svnadmin
chmod -R 777 /usr/local/svnadmin
@ -43,6 +48,7 @@ chmod -R 777 /usr/local/svnadmin @@ -43,6 +48,7 @@ chmod -R 777 /usr/local/svnadmin
- 进入程序代码的server目录,在命令行下以root用户身份执行以下命令
```
cd server
php svnadmind.php start
```

Loading…
Cancel
Save