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. 416
      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 { @@ -102,8 +102,8 @@ class Config extends Controller {
//更改版本库父文件夹后触发的操作
private function UpdateRepositoryParentPath($old_path, $new_path) {
parent::RequestReplyExec(" mkdir $new_path");
$info = parent::RequestReplyExec(' ps auxf|grep -v "grep"|grep svnserve');
parent::RequestReplyExec("mkdir $new_path");
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
/*
* 没有安装过svn服务
@ -116,7 +116,7 @@ class Config extends Controller { @@ -116,7 +116,7 @@ class Config extends Controller {
$file_arr2 = scandir($old_path . '/' . $file_item);
foreach ($file_arr2 as $file_item2) {
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 { @@ -142,7 +142,7 @@ class Config extends Controller {
* 安装过svn服务
*/
//停止服务
parent::RequestReplyExec(' systemctl stop svnserve');
parent::RequestReplyExec('systemctl stop svnserve');
//移动仓库
$file_arr = scandir($old_path);
foreach ($file_arr as $file_item) {
@ -151,16 +151,16 @@ class Config extends Controller { @@ -151,16 +151,16 @@ class Config extends Controller {
$file_arr2 = scandir($old_path . '/' . $file_item);
foreach ($file_arr2 as $file_item2) {
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_content = array();

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

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

416
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'];
@ -79,7 +80,7 @@ class Svnserve extends Controller { @@ -79,7 +80,7 @@ class Svnserve extends Controller {
$data['message'] = '仓库不存在或文件损坏';
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) {
file_put_contents($this->svn_repository_path . '/' . $repository_name . '/' . 'hooks' . '/' . $value['value'], $value["shell"]);
}
@ -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,18 +236,12 @@ class Svnserve extends Controller { @@ -233,18 +236,12 @@ 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);
parent::RequestReplyExec('mkdir -p ' . $this->svn_repository_path);
if (!is_dir($this->svn_repository_path)) {
$data['status'] = 0;
$data['message'] = '安装失败 创建目录失败';
@ -252,133 +249,69 @@ class Svnserve extends Controller { @@ -252,133 +249,69 @@ class Svnserve extends Controller {
}
//通过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 ($platform == 'CentOS') {
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");
}
//yum安装
parent::RequestReplyExec("yum install -y subversion");
sleep(1);
//通常cp的别名为cp -i ,取消别名
parent::RequestReplyExec(" alias cp='cp'");
parent::RequestReplyExec(' cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak');
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');
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");
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') {
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");
$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');
parent::RequestReplyExec(' systemctl disable svnserve');
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");
}
parent::RequestReplyExec('systemctl stop svnserve');
sleep(2);
parent::RequestReplyExec('systemctl disable svnserve');
sleep(2);
parent::RequestReplyExec('yum remove -y subversion');
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'); //
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');
}
parent::RequestReplyExec('yum clean all');
//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;
@ -585,43 +522,7 @@ class Svnserve extends Controller { @@ -585,43 +522,7 @@ class Svnserve extends Controller {
$data['message'] = '添加仓库失败';
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");
}
}
parent::RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path);
//将新建仓库目录下的conf/svnserve.conf做以下修改,
/*
@ -629,17 +530,12 @@ class Svnserve extends Controller { @@ -629,17 +530,12 @@ class Svnserve extends Controller {
* 取消注释# password-db = passwd所在行
* 取消注释# 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/# 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/# 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/# 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');
parent::RequestReplyExec('setenforce 0');
if (!$this->InsertRepositoryTable($repository_name)) {
$data['status'] = 0;
@ -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;
@ -684,7 +581,7 @@ class Svnserve extends Controller { @@ -684,7 +581,7 @@ class Svnserve extends Controller {
$data['message'] = '失败,项目不存在';
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)) {
@ -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'];
@ -771,7 +669,7 @@ class Svnserve extends Controller { @@ -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['message'] = '账户授权成功';
@ -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']);
@ -808,9 +707,9 @@ class Svnserve extends Controller { @@ -808,9 +707,9 @@ class Svnserve extends Controller {
return $data;
}
//修改仓库文件夹的目录
parent::RequestReplyExec(' mv ' . $this->svn_repository_path . '/' . $old_repository_name . ' ' . $this->svn_repository_path . '/' . $new_repository_name);
// //修改authz文件中的仓库名称
// parent::RequestReplyExec('sed -i \'s/' . $old_repository_name . '/' . $new_repository_name . '/g\' ' . SVN_CONF_PATH . '/authz');
parent::RequestReplyExec('mv ' . $this->svn_repository_path . '/' . $old_repository_name . ' ' . $this->svn_repository_path . '/' . $new_repository_name);
// //修改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)) {
$data['status'] = 0;
@ -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)) {
@ -884,9 +752,9 @@ class Svnserve extends Controller { @@ -884,9 +752,9 @@ class Svnserve extends Controller {
$temp = explode('=', $file_content[$i]);
$account_info[$j]['id'] = $j;
$account_info[$j]['account'] = trim($temp[0]);
// if ($is_need_passwd == 1) {
// if ($is_need_passwd == 1) {
$account_info[$j]['password'] = trim($temp[1]);
// }
// }
$j++;
}
}
@ -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']);
@ -995,7 +865,7 @@ class Svnserve extends Controller { @@ -995,7 +865,7 @@ class Svnserve extends Controller {
//账户冲突校验
$account_list = array();
$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) {
array_push($account_list, $value['account']);
}
@ -1017,16 +887,7 @@ class Svnserve extends Controller { @@ -1017,16 +887,7 @@ class Svnserve extends Controller {
//写入文件
array_push($file_content, $account . ' = ' . $passwd . "\n");
$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");
}
parent::RequestReplyExec('echo \'' . $file_content . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
$data['status'] = 1;
$data['message'] = '添加账户成功';
@ -1034,7 +895,8 @@ class Svnserve extends Controller { @@ -1034,7 +895,8 @@ class Svnserve extends Controller {
}
//账号管理 删除账号
function DeleteAccount($requestPayload) {
function DeleteAccount($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']);
$account = trim($requestPayload['account']);
@ -1058,7 +920,7 @@ class Svnserve extends Controller { @@ -1058,7 +920,7 @@ class Svnserve extends Controller {
}
fclose($file);
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]), '=')) {
$temp = trim(substr($file_content[$i], 0, strrpos($file_content[$i], '=')));
if ($temp == $account) {
@ -1068,7 +930,7 @@ class Svnserve extends Controller { @@ -1068,7 +930,7 @@ class Svnserve extends Controller {
}
}
$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文件中的账号
$file = fopen($this->svn_repository_path . '/' . $repository_name . '/conf/authz', "r") or exit("无法打开文件!");
@ -1087,15 +949,7 @@ class Svnserve extends Controller { @@ -1087,15 +949,7 @@ 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");
}
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz');
$data['status'] = 1;
$data['message'] = '删除账户成功';
@ -1103,7 +957,8 @@ class Svnserve extends Controller { @@ -1103,7 +957,8 @@ class Svnserve extends Controller {
}
//账号管理 编辑账号 提交用户对账号信息的修改 账号作为唯一标识不能修改
function SetCountInfo($requestPayload) {
function SetCountInfo($requestPayload)
{
$repository_name = trim($requestPayload['repository_name']);
$account = trim($requestPayload['account']);
$passwd = trim($requestPayload['password']);
@ -1130,7 +985,7 @@ class Svnserve extends Controller { @@ -1130,7 +985,7 @@ class Svnserve extends Controller {
}
fclose($file);
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]), '=')) {
$temp = trim(substr($file_content[$i], 0, strrpos($file_content[$i], '=')));
if ($temp == $account) {
@ -1140,14 +995,7 @@ class Svnserve extends Controller { @@ -1140,14 +995,7 @@ 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");
}
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
$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')) {
@ -1182,7 +1031,7 @@ class Svnserve extends Controller { @@ -1182,7 +1031,7 @@ class Svnserve extends Controller {
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')) {
$info = array();
$info['status'] = '已停止'; //svn服务未启动
@ -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)) {
@ -1218,13 +1068,13 @@ class Svnserve extends Controller { @@ -1218,13 +1068,13 @@ class Svnserve extends Controller {
switch ($action) {
case 'startSvn':
parent::RequestReplyExec(' systemctl start svnserve');
parent::RequestReplyExec('systemctl start svnserve');
break;
case 'restartSvn':
parent::RequestReplyExec(' systemctl restart svnserve');
parent::RequestReplyExec('systemctl restart svnserve');
break;
case 'stopSvn':
parent::RequestReplyExec(' systemctl stop svnserve');
parent::RequestReplyExec('systemctl stop svnserve');
break;
}
@ -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,15 +1094,17 @@ class Svnserve extends Controller { @@ -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);
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')) {
$data['status'] = 0;
$data['code'] = '00';
@ -1266,7 +1119,7 @@ class Svnserve extends Controller { @@ -1266,7 +1119,7 @@ class Svnserve extends Controller {
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')) {
$data['status'] = 0;
$data['code'] = '01';
@ -1279,11 +1132,12 @@ class Svnserve extends Controller { @@ -1279,11 +1132,12 @@ class Svnserve extends Controller {
}
//获取文件夹体积
private function GetDirSize($dir) {
private function GetDirSize($dir)
{
clearstatcache();
$dh = opendir($dir) or exit('打开目录错误'); //打开目录,返回一个目录流
$size = 0; //初始大小为0
while (false !== ($file = @readdir($dh))) {//循环读取目录下的文件
while (false !== ($file = @readdir($dh))) { //循环读取目录下的文件
if ($file != '.' and $file != '..') {
$path = $dir . '/' . $file; //设置目录,用于含有子目录的情况
if (is_dir($path)) {
@ -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]
@ -1336,7 +1192,7 @@ class Svnserve extends Controller { @@ -1336,7 +1192,7 @@ class Svnserve extends Controller {
* root=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文件
/*
* [users]
@ -1344,17 +1200,12 @@ class Svnserve extends Controller { @@ -1344,17 +1200,12 @@ 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");
}
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
}
//向仓库表中写入仓库信息
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;");
}
}
}

46
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,15 +85,16 @@ class System extends Controller { @@ -81,15 +85,16 @@ class System extends Controller {
}
//获取服务器运行时间
function GetServerUpTime($requestPayload) {
function GetServerUpTime($requestPayload)
{
$temp = file_get_contents('/proc/uptime');
$info = explode(" ", $temp);
$info = trim($info[0]); //系统自启动开始的秒数
$min = $info / 60;
$hours = $min / 60;
$days = floor($hours / 24);
$hours = floor($hours - ( $days * 24));
$min = floor($min - ( $days * 60 * 24) - ( $hours * 60));
$hours = floor($hours - ($days * 24));
$min = floor($min - ($days * 60 * 24) - ($hours * 60));
$info = $days . "天" . $hours . "小时" . $min . "分钟";
$data['status'] = 1;
@ -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;
@ -247,7 +257,7 @@ class System extends Controller { @@ -247,7 +257,7 @@ class System extends Controller {
//计算
$result = array();
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]['TransmitSpeed'] = ($info2[$key]['Transmit']['bytes'] - $info1[$key]['Transmit']['bytes']) / $sleeptime / 1024; //1s内的网络速度 单位 kbps
$result[$value['name']][0]['time'] = $time;
@ -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 接口发送或接收的数据包总数
@ -303,9 +314,9 @@ class System extends Controller { @@ -303,9 +314,9 @@ class System extends Controller {
//去除网卡名称中的冒号
$value[0] = str_replace(':', '', $value[0]);
//删除本地回环口lo的数据
// if ($value[0] == 'lo') {
// continue;
// }
// if ($value[0] == 'lo') {
// continue;
// }
//只保留特定的网卡
if ($network_name != '') {
if ($value[0] != $network_name) {
@ -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