Browse Source

v2.3

docker-svn
witersen 3 years ago
parent
commit
891f71e9c5
  1. 17
      01.web/src/router.js
  2. 330
      01.web/src/views/index/index.vue
  3. 8
      01.web/src/views/login/index.vue
  4. 7
      02.php/api.php
  5. 70
      02.php/app/controller/Statistics.php
  6. 11
      02.php/app/controller/Svnrep.php
  7. 4
      02.php/app/controller/base/Base.php
  8. 4
      02.php/app/service/Personal.php
  9. 260
      02.php/app/service/Statistics.php
  10. 12
      02.php/app/service/Svn.php
  11. 16
      02.php/app/service/Svngroup.php
  12. 88
      02.php/app/service/Svnrep.php
  13. 14
      02.php/app/service/Svnuser.php
  14. 22
      02.php/app/service/base/Base.php
  15. 119
      02.php/server/svnadmind.php
  16. 11
      02.php/templete/svnadmind/svnadmind.service

17
01.web/src/router.js

@ -18,6 +18,21 @@ const routers = [ @@ -18,6 +18,21 @@ const routers = [
},
component: (resolve) => require(['./views/layout/basicLayout/index.vue'], resolve),
children: [
{
name: 'index',
path: '/index',
meta: {
title: '信息统计',
icon: "ios-stats",
requireAuth: true,
user_role_id: ['1'],
group: {
name: "仓库",
num: 1
}
},
component: (resolve) => require(['./views/index/index.vue'], resolve)
},
{
name: 'repositoryInfo',
path: '/repositoryInfo',
@ -27,7 +42,7 @@ const routers = [ @@ -27,7 +42,7 @@ const routers = [
requireAuth: true,
user_role_id: ['1', '2'],
group: {
name: "仓库",
name: "",
num: 1
}
},

330
01.web/src/views/index/index.vue

@ -0,0 +1,330 @@ @@ -0,0 +1,330 @@
<template>
<div>
<Card :bordered="false" :dis-hover="true" style="margin-bottom: 10px" v-if="display.part1">
<p slot="title">
<Icon type="md-bulb" />
{{ systemBrif.os }}
</p>
<div>
<Row>
<Col span="4">
<div class="statusTop">负载状态</div>
<Tooltip placement="bottom" max-width="200">
<Circle
:percent="statusInfo.load.percent"
dashboard
:size="100"
:stroke-color="statusInfo.load.color"
class="statusCircle"
>
<span class="demo-circle-inner" style="font-size: 24px"
>{{ statusInfo.load.percent }}%</span
>
</Circle>
<div slot="content">
<p>最近1分钟平均负载{{ statusInfo.load.cpuLoad1Min }}</p>
<p>最近5分钟平均负载{{ statusInfo.load.cpuLoad5Min }}</p>
<p>最近15分钟平均负载{{ statusInfo.load.cpuLoad15Min }}</p>
</div>
</Tooltip>
<div class="statusBottom">{{ statusInfo.load.title }}</div>
</Col>
<Col span="4">
<div class="statusTop">CPU使用率</div>
<Tooltip placement="bottom" max-width="200">
<Circle
:percent="statusInfo.cpu.percent"
dashboard
:size="100"
:stroke-color="statusInfo.cpu.color"
class="statusCircle"
>
<span class="demo-circle-inner" style="font-size: 24px"
>{{ statusInfo.cpu.percent }}%</span
>
</Circle>
<div slot="content">
<p v-for="item in statusInfo.cpu.cpu" :key="item">{{ item }}</p>
<p>物理CPU个数{{ statusInfo.cpu.cpuPhysical }}</p>
<p>物理CPU的总核心数{{ statusInfo.cpu.cpuCore }}</p>
<p>物理CPU的线程总数{{ statusInfo.cpu.cpuProcessor }}</p>
</div>
</Tooltip>
<div class="statusBottom">{{ statusInfo.cpu.cpuCore }}核心</div>
</Col>
<Col span="4">
<div class="statusTop">内存使用率</div>
<Circle
:percent="statusInfo.mem.percent"
dashboard
:size="100"
:stroke-color="statusInfo.mem.color"
class="statusCircle"
>
<span class="demo-circle-inner" style="font-size: 24px"
>{{ statusInfo.mem.percent }}%</span
>
</Circle>
<div class="statusBottom">
{{ statusInfo.mem.memUsed }} / {{ statusInfo.mem.memTotal }}(MB)
</div>
</Col>
<Col span="4" v-for="(item, index) in diskList" :key="index">
<div class="statusTop">{{ item.mountedOn }}</div>
<Tooltip placement="bottom" max-width="200">
<div slot="content">
<p>文件系统{{ item.fileSystem }}</p>
<p>容量{{ item.size }}</p>
<p>已使用{{ item.used }}</p>
<p>可使用{{ item.avail }}</p>
<p>使用率{{ item.percent }}%</p>
<p>挂载点{{ item.mountedOn }}</p>
</div>
<Circle
:percent="item.percent"
dashboard
:size="100"
:stroke-color="item.color"
class="statusCircle"
>
<span class="demo-circle-inner" style="font-size: 24px"
>{{ item.percent }}%</span
>
</Circle>
</Tooltip>
<div class="statusBottom">
{{ item.used }} /
{{ item.size }}
</div>
</Col>
</Row>
</div>
</Card>
<Card :bordered="false" :dis-hover="true" style="margin-bottom: 10px">
<p slot="title">
<Icon type="ios-options" />
统计
</p>
<div>
<Row :gutter="16">
<Col span="4">
<Card :dis-hover="true">
<div style="text-align: center">
<p>仓库占用</p>
<h2 style="color: #28bcfe">{{ systemBrif.repSize }}</h2>
</div>
</Card>
</Col>
<Col span="4">
<Card :dis-hover="true">
<div style="text-align: center">
<p>备份占用</p>
<h2 style="color: #28bcfe">{{ systemBrif.backupSize }}</h2>
</div>
</Card>
</Col>
<Col span="4">
<Card :dis-hover="true">
<div style="text-align: center">
<p>SVN仓库</p>
<h2 style="color: #28bcfe">{{ systemBrif.repCount }}</h2>
</div>
</Card>
</Col>
<Col span="4">
<Card :dis-hover="true">
<div style="text-align: center">
<p>SVN用户</p>
<h2 style="color: #28bcfe">{{ systemBrif.repUser }}</h2>
</div>
</Card>
</Col>
<Col span="4">
<Card :dis-hover="true">
<div style="text-align: center">
<p>SVN分组</p>
<h2 style="color: #28bcfe">{{ systemBrif.repGroup }}</h2>
</div>
</Card>
</Col>
<Col span="4">
<Card :dis-hover="true">
<div style="text-align: center">
<p>运行日志/</p>
<h2 style="color: #28bcfe">{{ systemBrif.logCount }}</h2>
</div>
</Card>
</Col>
</Row>
</div>
</Card>
</div>
</template>
<script>
export default {
data() {
return {
/**
* 两个板块的显示控制
*/
display: {
part1: true,
part2: true,
},
/**
* 硬盘信息
*/
diskList: [],
/**
* 状态信息
*/
statusInfo: {
load: {
cpuLoad15Min: 0.22,
cpuLoad5Min: 0.28,
cpuLoad1Min: 0.32,
percent: 16,
color: "#28bcfe",
},
cpu: {
percent: 28.2,
cpu: ["Intel(R) Xeon(R) Platinum 8255C CPU @ 2.50GHz"],
cpuPhysical: 1,
cpuPhysicalCore: 1,
cpuCore: 1,
cpuProcessor: 1,
color: "#28bcfe",
},
mem: {
memTotal: 1838,
memUsed: 975,
memFree: 863,
percent: 53,
color: "#28bcfe",
},
},
/**
* 统计信息
*/
systemBrif: {
os: "",
repSize: 0,
repCount: 0,
repUser: 0,
repGroup: 0,
logCount: 0,
backupSize: 0,
},
};
},
computed: {},
created() {},
mounted() {
var that = this;
if (that.display.part1) {
that.GetDisk();
that.GetSystemStatus();
//
that.timer = window.setInterval(() => {
setTimeout(that.GetSystemStatus(), 0);
}, 3000);
//
that.$once("hook:beforeDestroy", () => {
clearInterval(that.timer);
});
}
if (that.display.part2) {
that.GetSystemAnalysis();
}
},
methods: {
/**
* 获取磁盘
*/
GetDisk() {
var that = this;
var data = {};
that.$axios
.post("/api.php?c=Statistics&a=GetDisk&t=web", data)
.then(function (response) {
var result = response.data;
if (result.status == 1) {
// that.$Message.success(result.message);
that.diskList = result.data;
} else {
that.$Message.error(result.message);
}
})
.catch(function (error) {
console.log(error);
that.$Message.error("出错了 请联系管理员!");
});
},
/**
* 获取状态
*/
GetSystemStatus() {
var that = this;
var data = {};
that.$axios
.post("/api.php?c=Statistics&a=GetSystemStatus&t=web", data)
.then(function (response) {
var result = response.data;
if (result.status == 1) {
// that.$Message.success(result.message);
that.statusInfo = result.data;
} else {
that.$Message.error(result.message);
}
})
.catch(function (error) {
console.log(error);
that.$Message.error("出错了 请联系管理员!");
});
},
/**
* 获取统计
*/
GetSystemAnalysis() {
var that = this;
var data = {};
that.$axios
.post("/api.php?c=Statistics&a=GetSystemAnalysis&t=web", data)
.then(function (response) {
var result = response.data;
if (result.status == 1) {
// that.$Message.success(result.message);
that.systemBrif = result.data;
} else {
that.$Message.error(result.message);
}
})
.catch(function (error) {
console.log(error);
that.$Message.error("出错了 请联系管理员!");
});
},
},
};
</script>
<style>
.statusTop {
width: 140px;
text-align: center;
margin-bottom: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.statusCircle {
margin-left: 20px;
}
.statusBottom {
width: 140px;
text-align: center;
margin-bottom: 15px;
}
</style>

8
01.web/src/views/login/index.vue

@ -122,8 +122,8 @@ export default { @@ -122,8 +122,8 @@ export default {
that.$Message.success("已有登录信息 自动跳转中...");
setTimeout(function () {
if (sessionStorage.user_role_id == 1) {
//
that.$router.push({ name: "repositoryInfo" });
//
that.$router.push({ name: "index" });
} else if (sessionStorage.user_role_id == 2) {
//
that.$router.push({ name: "repositoryInfo" });
@ -197,8 +197,8 @@ export default { @@ -197,8 +197,8 @@ export default {
that.$Message.success(result.message);
if (result.data.user_role_id == 1) {
//
that.$router.push({ name: "repositoryInfo" });
//
that.$router.push({ name: "index" });
} else if (result.data.user_role_id == 2) {
//
that.$router.push({ name: "repositoryInfo" });

7
02.php/api.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:06
* @LastEditors: witersen
* @LastEditTime: 2022-05-21 12:51:28
* @LastEditTime: 2022-05-13 01:25:06
* @Description: QQ:1801168257
*/
@ -16,8 +16,8 @@ @@ -16,8 +16,8 @@
/**
* 开启错误信息 如需要调试 可取消注释
*/
ini_set('display_errors', '1');
error_reporting(E_ALL);
// ini_set('display_errors', '1');
// error_reporting(E_ALL);
define('BASE_PATH', __DIR__);
@ -98,7 +98,6 @@ foreach ($disable_functions as $disable) { @@ -98,7 +98,6 @@ foreach ($disable_functions as $disable) {
//检测守护进程状态
$state = FunDetectState();
// return;
if ($state == 0) {
json1(401, 0, '守护进程响应超时');
} else if ($state == 2) {

70
02.php/app/controller/Statistics.php

@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-07 14:00:06
* @Description: QQ:1801168257
*/
namespace app\controller;
use app\service\Statistics as ServiceStatistics;
class Statistics extends Base
{
/**
* 服务层对象
*
* @var object
*/
private $ServiceStatistics;
function __construct()
{
parent::__construct();
$this->ServiceStatistics = new ServiceStatistics();
}
/**
* 获取状态
*
* 负载状态
* CPU使用率
* 内存使用率
*/
public function GetSystemStatus()
{
$result = $this->ServiceStatistics->GetSystemStatus();
json2($result);
}
/**
* 获取硬盘
*
* 获取硬盘数量和每个硬盘的详细信息
*/
public function GetDisk()
{
$result = $this->ServiceStatistics->GetDisk();
json2($result);
}
/**
* 获取统计
*
* 操作系统类型
* 仓库占用体积
* SVN仓库数量
* SVN用户数量
* SVN分组数量
* 计划任务数量
* 运行日志数量
*/
public function GetSystemAnalysis()
{
$result = $this->ServiceStatistics->GetSystemAnalysis();
json2($result);
}
}

11
02.php/app/controller/Svnrep.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-21 13:55:49
* @LastEditTime: 2022-05-11 11:45:59
* @Description: QQ:1801168257
*/
@ -191,15 +191,6 @@ class Svnrep extends Base @@ -191,15 +191,6 @@ class Svnrep extends Base
json2($result);
}
/**
* 重设仓库的UUID
*/
public function SetUUID()
{
$result = $this->ServiceSvnrep->SetUUID();
json2($result);
}
/**
* 获取备份文件夹下的文件列表
*/

4
02.php/app/controller/base/Base.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-05-06 18:41:32
* @LastEditors: witersen
* @LastEditTime: 2022-05-20 15:04:52
* @LastEditTime: 2022-05-07 12:11:40
* @Description: QQ:1801168257
*/
@ -47,6 +47,7 @@ require_once BASE_PATH . '/app/controller/Logs.php'; @@ -47,6 +47,7 @@ require_once BASE_PATH . '/app/controller/Logs.php';
require_once BASE_PATH . '/app/controller/Mail.php';
require_once BASE_PATH . '/app/controller/Personal.php';
require_once BASE_PATH . '/app/controller/Safe.php';
require_once BASE_PATH . '/app/controller/Statistics.php';
require_once BASE_PATH . '/app/controller/Svn.php';
require_once BASE_PATH . '/app/controller/Svngroup.php';
require_once BASE_PATH . '/app/controller/Svnrep.php';
@ -60,6 +61,7 @@ require_once BASE_PATH . '/app/service/Logs.php'; @@ -60,6 +61,7 @@ require_once BASE_PATH . '/app/service/Logs.php';
require_once BASE_PATH . '/app/service/Mail.php';
require_once BASE_PATH . '/app/service/Personal.php';
require_once BASE_PATH . '/app/service/Safe.php';
require_once BASE_PATH . '/app/service/Statistics.php';
require_once BASE_PATH . '/app/service/Svn.php';
require_once BASE_PATH . '/app/service/Svngroup.php';
require_once BASE_PATH . '/app/service/Svnrep.php';

4
02.php/app/service/Personal.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-20 16:29:41
* @LastEditTime: 2022-05-11 02:15:09
* @Description: QQ:1801168257
*/
@ -119,6 +119,8 @@ class Personal extends Base @@ -119,6 +119,8 @@ class Personal extends Base
return message(200, 0, '用户不存在');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
$this->database->update('svn_users', [

260
02.php/app/service/Statistics.php

@ -0,0 +1,260 @@ @@ -0,0 +1,260 @@
<?php
/*
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-07 01:45:39
* @Description: QQ:1801168257
*/
namespace app\service;
class Statistics extends Base
{
function __construct()
{
parent::__construct();
}
/**
* 获取状态
*
* 负载状态
* CPU使用率
* 内存使用率
*/
public function GetSystemStatus()
{
/**
* ----------负载计算开始----------
*/
$laodavg = FunShellExec("cat /proc/loadavg | awk '{print $1,$2,$3}'");
$laodavg = $laodavg['result'];
$laodavgArray = explode(' ', $laodavg);
//获取CPU15分钟前到现在的负载平均值
$cpuLoad15Min = (float)trim($laodavgArray[2]);
//获取CPU5分钟前到现在的负载平均值
$cpuLoad5Min = (float)trim($laodavgArray[1]);
//获取CPU1分钟前到现在的负载平均值
$cpuLoad1Min = (float)trim($laodavgArray[0]);
//获取cpu总核数
$cpuCount = FunShellExec('grep -c "model name" /proc/cpuinfo');
$cpuCount = $cpuCount['result'];
$cpuCount = (int)trim($cpuCount);
//一分钟的平均负载 / (cpu总核数 * 2),超过100则为100 不超100为真实值取整
$percent = round($cpuLoad1Min / ($cpuCount * 2) * 100, 1);
if ($percent > 100) {
$percent = 100;
}
/**
* ----------负载计算结束----------
*/
$data['load'] = [
'cpuLoad15Min' => $cpuLoad15Min,
'cpuLoad5Min' => $cpuLoad5Min,
'cpuLoad1Min' => $cpuLoad1Min,
'percent' => $percent,
'color' => FunGetColor($percent)['color'],
'title' => FunGetColor($percent)['title']
];
/**
* ----------cpu计算开始----------
*/
/**
* cpu使用率
*
* %Cpu(s): 0.0 us, 3.2 sy, 0.0 ni, 96.8 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
*
* us user CPU time 用户空间占用CPU百分比
* sy system CPU time 内核空间占用CPU百分比
* ni nice CPU 用户进程空间内改变过优先级的进程占用CPU百分比
* id idle 空闲CPU百分比
* wa iowait 等待输入输出的CPU时间百分比
* hi hardware 硬件中断
* si software 软件中断
* st steal 实时
*/
$topResult = FunShellExec('top -b -n 1 | grep Cpu');
$topResult = $topResult['result'];
preg_match('/ni,(.*?)id/', $topResult, $matches);
$id = 100 - (float)trim($matches[1]);
//cpu型号
$cpuModelArray = [];
$cpuModelName = FunShellExec("cat /proc/cpuinfo | grep 'model name' | uniq");
$cpuModelName = $cpuModelName['result'];
$explodeArray = explode("\n", trim($cpuModelName));
foreach ($explodeArray as $value) {
if (trim($value) != '') {
$tempArray = explode(':', $value);
array_push($cpuModelArray, trim($tempArray[1]));
}
}
//物理cpu个数
$cpuPhysical = FunShellExec("cat /proc/cpuinfo | grep 'physical id' | sort -u | wc -l");
$cpuPhysical = $cpuPhysical['result'];
$cpuPhysical = (int)trim($cpuPhysical);
//每个物理cpu的物理核心数
$cpuPhysicalCore = FunShellExec("cat /proc/cpuinfo | grep 'cpu cores' | wc -l");
$cpuPhysicalCore = $cpuPhysicalCore['result'];
$cpuPhysicalCore = (int)trim($cpuPhysicalCore);
//总物理核心数 = 物理cpu个数 * 每个物理cpu的物理核心数(每个物理cpu的物理核心数都一样吗?)
$cpuCore = $cpuPhysical * $cpuPhysicalCore;
//逻辑核心总数(线程总数)
$cpuProcessor = FunShellExec("cat /proc/cpuinfo | grep 'processor' | wc -l");
$cpuProcessor = $cpuProcessor['result'];
$cpuProcessor = (int)trim($cpuProcessor);
/**
* ----------cpu计算结束----------
*/
$data['cpu'] = [
'percent' => round($id, 1),
'cpu' => $cpuModelArray,
'cpuPhysical' => $cpuPhysical,
'cpuPhysicalCore' => $cpuPhysicalCore,
'cpuCore' => $cpuCore,
'cpuProcessor' => $cpuProcessor,
'color' => FunGetColor($id)['color']
];
/**
* ----------内存计算开始----------
*/
/**
* MemTotal 总内存
* MemFree 空闲内存
* MemAvailable 可用内存(MemFree + 可回收的内存),系统中有些内存虽然已被使用但是可以回收,比如cache、buffer、slab都有一部分可以回收
*/
//物理内存总量
$memTotal = FunShellExec("cat /proc/meminfo | grep 'MemTotal' | awk '{print $2}'");
$memTotal = $memTotal['result'];
$memTotal = (int)trim($memTotal);
//操作系统可用内存总量(没有使用空闲内存)
$memFree = FunShellExec("cat /proc/meminfo | grep 'MemAvailable' | awk '{print $2}'");
$memFree = $memFree['result'];
$memFree = (int)trim($memFree);
//操作系统已使用内存总量
$memUsed = $memTotal - $memFree;
//内存使用率
$percent = round($memUsed / $memTotal * 100, 1);
/**
* ----------内存计算结束----------
*/
$data['mem'] = [
'memTotal' => round($memTotal / 1024),
'memUsed' => round($memUsed / 1024),
'memFree' => round($memFree / 1024),
'percent' => $percent,
'color' => FunGetColor($percent)['color']
];
return message(200, 1, '成功', $data);
}
/**
* 获取硬盘
*
* 获取硬盘数量和每个硬盘的详细信息
*/
public function GetDisk()
{
$rs = FunShellExec('df -lh | grep -E "^(/)"');
$rs = $rs['result'];
//将多个连续的空格换为一个
$result = preg_replace("/\s{2,}/", ' ', $rs);
//多个硬盘
$diskArray = explode("\n", $result);
$data = [];
//处理
foreach ($diskArray as $value) {
if (trim($value) != '') {
$diskInfo = explode(" ", $value);
array_push($data, [
'fileSystem' => $diskInfo[0],
'size' => $diskInfo[1],
'used' => $diskInfo[2],
'avail' => $diskInfo[3],
'percent' => (int)str_replace('%', '', $diskInfo[4]),
'mountedOn' => $diskInfo[5],
'color' => FunGetColor((int)str_replace('%', '', $diskInfo[4]))['color']
]);
}
}
return message(200, 1, '成功', $data);
}
/**
* 获取统计
*
* 操作系统类型
* 仓库占用体积
* SVN仓库数量
* SVN用户数量
* SVN分组数量
* 计划任务数量
* 运行日志数量
*/
public function GetSystemAnalysis()
{
//操作系统类型和版本
$os = FunShellExec("cat /etc/redhat-release");
$os = $os['result'];
//仓库占用体积
$repSize = FunFormatSize(FunGetDirSizeDu($this->config_svn['rep_base_path']));
//备份占用体积
$backupSize = FunFormatSize(FunGetDirSizeDu($this->config_svn['backup_base_path']));
//SVN仓库数量
$repCount = count($this->SVNAdminRep->GetSimpleRepList());
//SVN用户数量
$userCount = $this->SVNAdminUser->GetSvnUserList($this->passwdContent);
if ($userCount === '0') {
return message(200, 0, '文件格式错误(不存在[users]标识)');
}
$userCount = count($userCount);
//SVN分组数量
$groupCount = $this->SVNAdminGroup->GetSvnGroupList($this->authzContent);
if ($userCount === '0') {
return message(200, 0, '文件格式错误(不存在[groups]标识)');
}
$groupCount = count($groupCount);
//运行日志数量
$logCount = $this->database->count('logs', ['log_id[>]' => 0]);
return message(200, 1, '成功', [
'os' => trim($os),
'repSize' => $repSize,
'repCount' => $repCount,
'repUser' => $userCount,
'repGroup' => $groupCount,
'logCount' => $logCount,
'backupSize' => $backupSize
]);
}
}

12
02.php/app/service/Svn.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-20 16:29:48
* @LastEditTime: 2022-05-12 00:20:14
* @Description: QQ:1801168257
*/
@ -140,10 +140,8 @@ class Svn extends Base @@ -140,10 +140,8 @@ class Svn extends Base
$bindPort = '';
$bindHost = '';
if (!is_readable($this->config_svn['svnserve_env_file'])) {
json1(200, 0, '文件' . $this->config_svn['svnserve_env_file'] . '不可读');
}
$svnserveContent = file_get_contents($this->config_svn['svnserve_env_file']);
$svnserveContent = FunShellExec(sprintf("cat '%s'", $this->config_svn['svnserve_env_file']));
$svnserveContent = $svnserveContent['result'];
//匹配端口
if (preg_match('/--listen-port[\s]+([0-9]+)/', $svnserveContent, $portMatchs) != 0) {
@ -250,6 +248,8 @@ class Svn extends Base @@ -250,6 +248,8 @@ class Svn extends Base
$config = sprintf("OPTIONS=\"-r '%s' --config-file '%s' --log-file '%s' --listen-port %s --listen-host %s\"", $this->config_svn['rep_base_path'], $this->config_svn['svn_conf_file'], $this->config_svn['svnserve_log_file'], $this->payload['bindPort'], $result['bindHost']);
//写入配置文件
// FunShellExec('echo \'' . $config . '\' > ' . $this->config_svn['svnserve_env_file']);
FunFilePutContents($this->config_svn['svnserve_env_file'], $config);
//启动svnserve
@ -284,6 +284,8 @@ class Svn extends Base @@ -284,6 +284,8 @@ class Svn extends Base
$config = sprintf("OPTIONS=\"-r '%s' --config-file '%s' --log-file '%s' --listen-port %s --listen-host %s\"", $this->config_svn['rep_base_path'], $this->config_svn['svn_conf_file'], $this->config_svn['svnserve_log_file'], $result['bindPort'], $this->payload['bindHost']);
//写入配置文件
// FunShellExec('echo \'' . $config . '\' > ' . $this->config_svn['svnserve_env_file']);
FunFilePutContents($this->config_svn['svnserve_env_file'], $config);
//启动svnserve

16
02.php/app/service/Svngroup.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-20 16:29:58
* @LastEditTime: 2022-05-11 02:16:31
* @Description: QQ:1801168257
*/
@ -183,6 +183,8 @@ class Svngroup extends Base @@ -183,6 +183,8 @@ class Svngroup extends Base
}
//写入配置文件
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//写入数据库
@ -218,6 +220,8 @@ class Svngroup extends Base @@ -218,6 +220,8 @@ class Svngroup extends Base
return message(200, 0, '分组不存在');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//从数据库删除
@ -263,6 +267,8 @@ class Svngroup extends Base @@ -263,6 +267,8 @@ class Svngroup extends Base
return message(200, 0, '文件格式错误(不存在[groups]标识)');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
@ -348,6 +354,8 @@ class Svngroup extends Base @@ -348,6 +354,8 @@ class Svngroup extends Base
return message(200, 0, '要添加的用户已存在该分组');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
@ -369,6 +377,8 @@ class Svngroup extends Base @@ -369,6 +377,8 @@ class Svngroup extends Base
return message(200, 0, '要删除的用户不在该分组');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
@ -401,6 +411,8 @@ class Svngroup extends Base @@ -401,6 +411,8 @@ class Svngroup extends Base
return message(200, 0, '存在分组循环嵌套的情况');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
@ -422,6 +434,8 @@ class Svngroup extends Base @@ -422,6 +434,8 @@ class Svngroup extends Base
return message(200, 0, '要删除的分组不在该分组');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();

88
02.php/app/service/Svnrep.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-21 14:14:40
* @LastEditTime: 2022-05-12 17:27:57
* @Description: QQ:1801168257
*/
@ -79,6 +79,8 @@ class Svnrep extends Base @@ -79,6 +79,8 @@ class Svnrep extends Base
//向authz写入仓库信息
$status = $this->SVNAdminRep->SetRepAuthz($this->authzContent, $this->payload['rep_name'], '/');
if ($status != '1') {
// FunShellExec('echo \'' . $status . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $status);
}
@ -177,6 +179,8 @@ class Svnrep extends Base @@ -177,6 +179,8 @@ class Svnrep extends Base
}
if ($authzContet != $this->authzContent) {
// FunShellExec('echo \'' . $authzContet . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $authzContet);
}
}
@ -237,6 +241,8 @@ class Svnrep extends Base @@ -237,6 +241,8 @@ class Svnrep extends Base
//写入配置文件
if ($authzContent != $this->authzContent) {
// FunShellExec('echo \'' . $authzContent . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $authzContent);
}
}
@ -916,6 +922,8 @@ class Svnrep extends Base @@ -916,6 +922,8 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -939,6 +947,8 @@ class Svnrep extends Base @@ -939,6 +947,8 @@ class Svnrep extends Base
return message(200, 0, '已被删除');
} else {
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -968,6 +978,8 @@ class Svnrep extends Base @@ -968,6 +978,8 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -1021,6 +1033,8 @@ class Svnrep extends Base @@ -1021,6 +1033,8 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -1044,6 +1058,8 @@ class Svnrep extends Base @@ -1044,6 +1058,8 @@ class Svnrep extends Base
return message(200, 0, '已被删除');
} else {
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -1075,6 +1091,8 @@ class Svnrep extends Base @@ -1075,6 +1091,8 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -1146,6 +1164,8 @@ class Svnrep extends Base @@ -1146,6 +1164,8 @@ class Svnrep extends Base
//从配置文件删除指定仓库的所有路径
$result = $this->SVNAdminRep->DelRepAuthz($this->authzContent, $this->payload['rep_name']);
if ($result != '1') {
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
}
@ -1211,26 +1231,6 @@ class Svnrep extends Base @@ -1211,26 +1231,6 @@ class Svnrep extends Base
return message(200, 1, '成功', $newArray);
}
/**
* 重设仓库的UUID
*/
public function SetUUID()
{
if ($this->payload['uuid'] == '') {
$cmd = sprintf("'%s' setuuid '%s'", $this->config_bin['svnadmin'], $this->config_svn['rep_base_path'] . $this->payload['rep_name']);
} else {
$cmd = sprintf("'%s' setuuid '%s' '%s'", $this->config_bin['svnadmin'], $this->config_svn['rep_base_path'] . $this->payload['rep_name'], $this->payload['uuid']);
}
$result = FunShellExec($cmd);
if ($result['resultCode'] == 0) {
return message();
} else {
return message(200, 0, $result['error']);
}
}
/**
* 获取备份文件夹下的文件列表
*/
@ -1501,23 +1501,14 @@ class Svnrep extends Base @@ -1501,23 +1501,14 @@ class Svnrep extends Base
}
foreach ($repHooks as $key => $value) {
$hookFile = $hooksPath . $value['fileName'];
$hookTmpleFile = $hookFile . '.tmpl';
if (file_exists($hookFile)) {
if (file_exists($hooksPath . $value['fileName'])) {
$repHooks[$key]['hasFile'] = true;
if (!is_readable($hookFile)) {
return message(200, 0, '文件' . $hookFile . '不可读');
}
$repHooks[$key]['con'] = file_get_contents($hookFile);
$temp = FunShellExec(sprintf("cat '%s'", $hooksPath . $value['fileName']));
$repHooks[$key]['con'] = $temp['result'];
}
if (file_exists($hookTmpleFile)) {
if (!is_readable($hookTmpleFile)) {
return message(200, 0, '文件' . $hookTmpleFile . '不可读');
}
$repHooks[$key]['tmpl'] = file_get_contents($hookTmpleFile);
if (file_exists($hooksPath . $value['fileName'] . '.tmpl')) {
$temp = FunShellExec(sprintf("cat '%s'", $hooksPath . $value['fileName'] . '.tmpl'));
$repHooks[$key]['tmpl'] = $temp['result'];
}
}
@ -1575,9 +1566,6 @@ class Svnrep extends Base @@ -1575,9 +1566,6 @@ class Svnrep extends Base
return message(200, 0, '未创建自定义钩子目录');
}
if (!is_readable($recommend_hook_path)) {
return message(200, 0, '目录' . $recommend_hook_path . '不可读');
}
$dirs = scandir($recommend_hook_path);
foreach ($dirs as $dir) {
@ -1589,34 +1577,24 @@ class Svnrep extends Base @@ -1589,34 +1577,24 @@ class Svnrep extends Base
continue;
}
if (!is_readable($recommend_hook_path . $dir)) {
return message(200, 0, '目录' . $recommend_hook_path . $dir . '不可读');
}
$dirFiles = scandir($recommend_hook_path . $dir);
if (!in_array('hookDescription', $dirFiles) || !in_array('hookName', $dirFiles)) {
continue;
}
if (!is_readable($recommend_hook_path . $dir . '/hookName')) {
return message(200, 0, '文件' . $recommend_hook_path . $dir . '/hookName' . '不可读');
}
$hookName = file_get_contents($recommend_hook_path . $dir . '/hookName');
$hookName = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/hookName'));
$hookName = $hookName['result'];
if (!file_exists($recommend_hook_path . $dir . '/' . trim($hookName))) {
continue;
}
if (!is_readable($recommend_hook_path . $dir . '/' . $hookName)) {
return message(200, 0, '文件' . $recommend_hook_path . $dir . '/' . $hookName . '不可读');
}
$hookContent = file_get_contents($recommend_hook_path . $dir . '/' . $hookName);
$hookContent = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/' . $hookName));
$hookContent = $hookContent['result'];
if (!is_readable($recommend_hook_path . $dir . '/hookDescription')) {
return message(200, 0, '文件' . $recommend_hook_path . $dir . '/hookDescription' . '不可读');
}
$hookDescription = file_get_contents($recommend_hook_path . $dir . '/hookDescription');
$hookDescription = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/hookDescription'));
$hookDescription = $hookDescription['result'];
array_push($list, [
'hookName' => $hookName,

14
02.php/app/service/Svnuser.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
* @LastEditTime: 2022-05-20 16:31:46
* @LastEditTime: 2022-05-11 02:21:30
* @Description: QQ:1801168257
*/
@ -166,6 +166,8 @@ class Svnuser extends Base @@ -166,6 +166,8 @@ class Svnuser extends Base
return message(200, 0, '要启用的用户不存在');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
return message();
@ -184,6 +186,8 @@ class Svnuser extends Base @@ -184,6 +186,8 @@ class Svnuser extends Base
return message(200, 0, '要禁用的用户不存在');
}
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
return message();
@ -229,6 +233,8 @@ class Svnuser extends Base @@ -229,6 +233,8 @@ class Svnuser extends Base
}
//写入配置文件
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
//写入数据库
@ -269,6 +275,8 @@ class Svnuser extends Base @@ -269,6 +275,8 @@ class Svnuser extends Base
}
//写入配置文件
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
//写入数据库
@ -308,8 +316,12 @@ class Svnuser extends Base @@ -308,8 +316,12 @@ class Svnuser extends Base
'svn_user_name' => $this->payload['svn_user_name']
]);
// FunShellExec('echo \'' . $resultAuthz . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $resultAuthz);
// FunShellExec('echo \'' . $resultPasswd . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $resultPasswd);
//日志

22
02.php/app/service/base/Base.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-05-06 18:42:00
* @LastEditors: witersen
* @LastEditTime: 2022-05-20 16:39:27
* @LastEditTime: 2022-05-09 21:10:15
* @Description: QQ:1801168257
*/
@ -269,15 +269,7 @@ class Base @@ -269,15 +269,7 @@ class Base
*/
public function GetAuthz()
{
if (!file_exists($this->config_svn['svn_authz_file'])) {
json1(200, 0, '文件' . $this->config_svn['svn_authz_file'] . '不存在');
}
if (!is_readable($this->config_svn['svn_authz_file'])) {
json1(200, 0, '文件' . $this->config_svn['svn_authz_file'] . '不可读');
}
$this->authzContent = file_get_contents($this->config_svn['svn_authz_file']);
$this->authzContent = file_exists($this->config_svn['svn_authz_file']) ? file_get_contents($this->config_svn['svn_authz_file']) : '';
}
/**
@ -285,14 +277,6 @@ class Base @@ -285,14 +277,6 @@ class Base
*/
public function GetPasswd()
{
if (!file_exists($this->config_svn['svn_passwd_file'])) {
json1(200, 0, '文件' . $this->config_svn['svn_passwd_file'] . '不存在');
}
if (!is_readable($this->config_svn['svn_passwd_file'])) {
json1(200, 0, '文件' . $this->config_svn['svn_passwd_file'] . '不可读');
}
$this->passwdContent = file_get_contents($this->config_svn['svn_passwd_file']);
$this->passwdContent = file_exists($this->config_svn['svn_passwd_file']) ? file_get_contents($this->config_svn['svn_passwd_file']) : '';
}
}

119
02.php/server/svnadmind.php

@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:06
* @LastEditors: witersen
* @LastEditTime: 2022-05-20 16:06:09
* @LastEditTime: 2022-05-13 01:24:54
* @Description: QQ:1801168257
*/
@ -29,7 +29,8 @@ class Daemon @@ -29,7 +29,8 @@ class Daemon
private $scripts = [
'start',
'stop',
'debug'
'restart',
'console'
];
private $config_daemon;
private $config_svn;
@ -43,6 +44,42 @@ class Daemon @@ -43,6 +44,42 @@ class Daemon
$this->config_svn = Config::get('svn');
}
/**
* 将程序变为守护进程
*/
private function InitDeamon()
{
$pid = pcntl_fork();
if ($pid < 0) {
exit('pcntl_fork 错误' . PHP_EOL);
} elseif ($pid > 0) {
exit();
}
$sid = posix_setsid();
if (!$sid) {
exit('posix_setsid 错误' . PHP_EOL);
}
$pid = pcntl_fork();
if ($pid < 0) {
exit('pcntl_fork 错误' . PHP_EOL);
} elseif ($pid > 0) {
exit();
}
chdir('/');
umask(0);
if (defined('STDIN')) {
fclose(STDIN);
}
if (defined('STDOUT')) {
fclose(STDOUT);
}
if (defined('STDERR')) {
fclose(STDERR);
}
file_put_contents($this->pidFile, getmypid());
$this->InitSocket();
}
/**
* 创建TCP套接字并监听指定端口
*/
@ -100,8 +137,8 @@ class Daemon @@ -100,8 +137,8 @@ class Daemon
$type = $receive['type'];
$content = $receive['content'];
//debug模式
if ($this->workMode == 'debug') {
//console模式
if ($this->workMode == 'console') {
echo PHP_EOL . '---------receive---------' . PHP_EOL;
print_r($receive);
}
@ -154,8 +191,8 @@ class Daemon @@ -154,8 +191,8 @@ class Daemon
];
}
//debug模式
if ($this->workMode == 'debug') {
//console模式
if ($this->workMode == 'console') {
echo PHP_EOL . '---------result---------' . PHP_EOL;
echo 'resultCode: ' . $result['resultCode'] . PHP_EOL;
echo 'result: ' . $result['result'] . PHP_EOL;
@ -245,9 +282,29 @@ class Daemon @@ -245,9 +282,29 @@ class Daemon
}
/**
* 停止
* 以守护进程模式工作
*/
private function StartDaemon()
{
if (file_exists($this->pidFile)) {
$pid = file_get_contents($this->pidFile);
$result = trim(shell_exec("ps -ax | awk '{ print $1 }' | grep -e \"^$pid$\""));
if (strstr($result, $pid)) {
exit('程序正在运行中' . PHP_EOL);
}
}
$this->UpdateSign();
echo '启动成功' . PHP_EOL;
echo '可进行网站访问' . PHP_EOL;
echo '检出SVN仓库前请注意放行协议端口(默认3690)' . PHP_EOL;
echo '已自动更改系统加密密钥,在线用户会退出登录' . PHP_EOL;
$this->InitDeamon();
}
/**
* 关闭守护进程
*/
private function Stop()
private function StopDaemon()
{
if (file_exists($this->pidFile)) {
$pid = file_get_contents($this->pidFile);
@ -257,35 +314,18 @@ class Daemon @@ -257,35 +314,18 @@ class Daemon
}
/**
* 启动
* 重启守护进程
*/
private function Start()
private function RestartDeamon()
{
file_put_contents($this->pidFile, getmypid());
$this->UpdateSign();
echo '启动成功' . PHP_EOL;
echo '可进行网站访问' . PHP_EOL;
echo '检出SVN仓库前请注意放行协议端口(默认3690)' . PHP_EOL;
echo '已自动更改系统加密密钥,在线用户会退出登录' . PHP_EOL;
chdir('/');
umask(0);
if (defined('STDIN')) {
fclose(STDIN);
}
if (defined('STDOUT')) {
fclose(STDOUT);
}
if (defined('STDERR')) {
fclose(STDERR);
}
$this->InitSocket();
$this->StopDaemon();
$this->StartDaemon();
}
/**
* 调试
* 以控制台模式工作 用于调试
*/
private function Debug()
private function StartConsole()
{
if (file_exists($this->pidFile)) {
$pid = file_get_contents($this->pidFile);
@ -299,25 +339,28 @@ class Daemon @@ -299,25 +339,28 @@ class Daemon
public function Run($argv)
{
if (isset($argv[1])) {
$this->workMode = $argv[1];
if (!in_array($this->workMode, $this->scripts)) {
exit('用法:php svnadmin.php [' . implode(' | ', $this->scripts) . ']' . PHP_EOL);
exit('用法:php svnadmin.php [start | stop | restart | console]' . PHP_EOL);
}
if ($this->workMode == 'stop') {
$this->Stop();
$this->StopDaemon();
} else {
$this->CheckSysType();
$this->CheckPhpVersion();
$this->CheckDisabledFun();
if ($this->workMode == 'debug') {
$this->Debug();
} else if ($this->workMode == 'start') {
$this->Start();
if ($this->workMode == 'start') {
$this->StartDaemon();
} else if ($this->workMode == 'restart') {
$this->RestartDeamon();
} else if ($this->workMode == 'console') {
$this->StartConsole();
}
}
} else {
exit('用法:php svnadmin.php [' . implode(' | ', $this->scripts) . ']' . PHP_EOL);
exit('用法:php svnadmin.php [start | stop restart | console]' . PHP_EOL);
}
}
}

11
02.php/templete/svnadmind/svnadmind.service

@ -1,11 +0,0 @@ @@ -1,11 +0,0 @@
[Unit]
Description=Subversion protocol daemon
After=syslog.target network.target
[Service]
Type=simple
ExecStart=/usr/bin/php /var/www/html/server/svnadmind.php start
ExecStop=/usr/bin/php /var/www/html/server/svnadmind.php stop
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save