From ac5bb41488426a24df143adeb4db86cb91e1303e Mon Sep 17 00:00:00 2001
From: witersen <1801168257@qq.com>
Date: Wed, 11 May 2022 11:00:47 +0800
Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3echo=E5=87=BA=E7=8E=B0?=
=?UTF-8?q?=E7=9A=84=E5=AD=97=E7=AC=A6=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
01.web/src/views/repositoryGroup/index.vue | 6 +-
01.web/src/views/repositoryInfo/index.vue | 390 +++++++++++++++------
01.web/src/views/repositoryUser/index.vue | 4 +-
02.php/app/controller/Svnrep.php | 11 +-
02.php/app/function/ipc.php | 44 ++-
02.php/app/service/Personal.php | 6 +-
02.php/app/service/Svn.php | 10 +-
02.php/app/service/Svngroup.php | 30 +-
02.php/app/service/Svnrep.php | 197 +++++++----
02.php/app/service/Svnuser.php | 26 +-
02.php/server/svnadmind.php | 67 ++--
11 files changed, 551 insertions(+), 240 deletions(-)
diff --git a/01.web/src/views/repositoryGroup/index.vue b/01.web/src/views/repositoryGroup/index.vue
index 5aae3b5..8ddafb5 100644
--- a/01.web/src/views/repositoryGroup/index.vue
+++ b/01.web/src/views/repositoryGroup/index.vue
@@ -463,7 +463,7 @@ export default {
//自动显示输入信息
this.formEditGroupName.groupNameNew = svn_group_name;
//标题
- this.titleEditGroupName = "编辑SVN分组名-" + svn_group_name;
+ this.titleEditGroupName = "编辑SVN分组名 - " + svn_group_name;
//对话框
this.modalEditGroupName = true;
},
@@ -499,7 +499,7 @@ export default {
DelGroup(svn_group_name) {
var that = this;
that.$Modal.confirm({
- title: "删除SVN分组-" + svn_group_name,
+ title: "删除SVN分组 - " + svn_group_name,
content: "确定要删除该用户吗?
该操作不可逆!",
onOk: () => {
var data = {
@@ -532,7 +532,7 @@ export default {
//显示对话框
this.modalGetGroupMember = true;
//标题
- this.titleGetGroupMember = "编辑分组成员信息-" + grouName;
+ this.titleGetGroupMember = "编辑分组成员信息 - " + grouName;
//请求数据
this.GetGroupMember();
},
diff --git a/01.web/src/views/repositoryInfo/index.vue b/01.web/src/views/repositoryInfo/index.vue
index ce8d087..3fa0b32 100644
--- a/01.web/src/views/repositoryInfo/index.vue
+++ b/01.web/src/views/repositoryInfo/index.vue
@@ -390,32 +390,6 @@
:title="titleModalRepHooks"
class-name="hooks"
>
-
@@ -423,80 +397,156 @@
Commit
-
+
+
- 编辑
+ 介绍
+
+
+ 编辑
- 移除
+ 移除
-
+
+
- 编辑
+ 介绍
+
+
+ 编辑
- 移除
+ 移除
-
+
+
- 编辑
+ 介绍
+
+
+ 编辑
- 移除
+ 移除
Locks
-
+
+
- 编辑
+ 介绍
- 移除
+ 编辑
+
+
+ 移除
-
+
+
- 编辑
+ 介绍
+
+
+ 编辑
- 移除
+ 移除
-
+
+
- 编辑
+ 介绍
- 移除
+ 编辑
+
+
+ 移除
-
+
+
- 编辑
+ 介绍
- 移除
+ 编辑
+
+
+ 移除
@@ -504,30 +554,69 @@
>Revision property change
-
+
+
- 编辑
+ 介绍
- 移除
+ 编辑
+
+
+ 移除
-
+
+
- 编辑
+ 介绍
+
+
+ 编辑
- 移除
+ 移除
+
@@ -564,6 +653,38 @@
>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -781,6 +902,10 @@ export default {
modalRepAllUser: false,
//SVN仓库所有分组
modalRepAllGroup: false,
+ //编辑仓库钩子内容
+ modalEditRepHook: false,
+ //查看钩子模板内容
+ modalStudyRepHook: false,
/**
* 排序数据
@@ -851,6 +976,10 @@ export default {
loadingImportBackup: false,
//修改仓库名称
loadingEditRepName: false,
+ //获取仓库钩子信息
+ loadingGetRepHooks: true,
+ //编辑仓库内容
+ loadingEditRepHook: false,
/**
* 临时变量
@@ -877,6 +1006,12 @@ export default {
currentRepPriAddUser: "",
//仓库路径的权限新增分组列表 当前选中的分组
currentRepPriAddGroup: "",
+ //仓库钩子名称
+ tempSelectRepHook: "",
+ //仓库钩子内容
+ tempSelectRepHookCon: "",
+ //钩子模板内容
+ tempSelectRepHookTmpl: "",
/**
* 对话框标题
@@ -893,6 +1028,10 @@ export default {
titleModalEditRepName: "",
//高级
titleModalRepAdvance: "",
+ //钩子文件编辑
+ titleModalEditRepHook: "",
+ //钩子文件模板
+ titleModalStudyRepHook: "",
/**
* 表单
@@ -918,53 +1057,19 @@ export default {
formRepImport: {},
//钩子结构
formRepHooks: {
- select: "start-commit",
- type: {
- "start-commit": {
- value: "start-commit",
- label: "start-commit---事务创建前",
- shell: "",
- },
- "pre-commit": {
- value: "pre-commit",
- label: "pre-commit---事务提交前",
- shell: "",
- },
- "post-commit": {
- value: "post-commit",
- label: "post-commit---事务提交后",
- shell: "",
- },
- "pre-lock": {
- value: "pre-lock",
- label: "pre-lock---锁定文件前",
- shell: "",
- },
- "post-lock": {
- value: "post-lock",
- label: "post-lock---锁定文件后",
- shell: "",
- },
- "pre-unlock": {
- value: "pre-unlock",
- label: "pre-unlock---解锁文件前",
- shell: "",
- },
- "post-unlock": {
- value: "post-unlock",
- label: "post-unlock---解锁文件后",
- shell: "",
- },
- "pre-revprop-change": {
- value: "pre-revprop-change",
- label: "pre-revprop-change---修改修订版属性前",
- shell: "",
- },
- "post-revprop-change": {
- value: "post-revprop-change",
- label: "post-revprop-change---修改修订版属性后",
- shell: "",
- },
+ start_commit: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ pre_commit: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ post_commit: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ pre_lock: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ post_lock: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ pre_unlock: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ post_unlock: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ pre_revprop_change: { fileName: "", hasFile: false, con: "", tmpl: "" },
+ post_revprop_change: {
+ fileName: "",
+ hasFile: false,
+ con: "",
+ tmpl: "",
},
},
//页头提示信息
@@ -1476,7 +1581,7 @@ export default {
that.currentRepTreePath = "/";
that.currentRepName = rep_name;
//设置标题
- that.titleModalViewRep = "仓库内容-" + rep_name;
+ that.titleModalViewRep = "仓库内容 - " + rep_name;
//显示对话框
that.modalViewRep = true;
//请求检出地址信息
@@ -1496,7 +1601,7 @@ export default {
that.currentRepTreePath = pri_path;
that.currentRepName = rep_name;
//设置标题
- that.titleModalViewRep = "仓库内容-" + rep_name;
+ that.titleModalViewRep = "仓库内容 - " + rep_name;
//显示对话框
that.modalViewRep = true;
//请求检出地址信息
@@ -1667,7 +1772,7 @@ export default {
*/
ModalRepDump(rep_name) {
//设置标题
- this.titleModalRepBackup = "仓库备份-" + rep_name;
+ this.titleModalRepBackup = "仓库备份 - " + rep_name;
//显示对话框
this.modalRepDump = true;
//设置当前选中的仓库名
@@ -1813,7 +1918,7 @@ export default {
that.currentRepTreePriPath = "/";
that.currentRepName = rep_name;
//设置标题
- that.titleModalRepPri = "仓库权限-" + rep_name;
+ that.titleModalRepPri = "仓库权限 - " + rep_name;
//显示对话框
that.modalRepPri = true;
//显示加载动画
@@ -2321,7 +2426,7 @@ export default {
*/
ModalRepHooks(rep_name) {
//设置标题
- this.titleModalRepHooks = "仓库钩子-" + rep_name;
+ this.titleModalRepHooks = "仓库钩子 - " + rep_name;
//显示对话框
this.modalRepHooks = true;
//设置当前选中仓库
@@ -2334,39 +2439,98 @@ export default {
*/
GetRepHooks() {
var that = this;
+ that.loadingGetRepHooks = true;
var data = {
rep_name: that.currentRepName,
};
that.$axios
.post("/api.php?c=Svnrep&a=GetRepHooks&t=web", data)
+ .then(function (response) {
+ that.loadingGetRepHooks = false;
+ var result = response.data;
+ if (result.status == 1) {
+ that.formRepHooks = result.data;
+ } else {
+ that.$Message.error(result.message);
+ }
+ })
+ .catch(function (error) {
+ that.loadingGetRepHooks = false;
+ console.log(error);
+ that.$Message.error("出错了 请联系管理员!");
+ });
+ },
+ /**
+ * 移除仓库钩子
+ */
+ DelRepHook(fileName) {
+ var that = this;
+ that.loadingGetRepHooks = true;
+ var data = {
+ rep_name: that.currentRepName,
+ fileName: fileName,
+ };
+ that.$axios
+ .post("/api.php?c=Svnrep&a=DelRepHook&t=web", data)
.then(function (response) {
var result = response.data;
if (result.status == 1) {
- that.formRepHooks.type = result.data;
+ that.$Message.success(result.message);
+ that.GetRepHooks();
} else {
+ that.loadingGetRepHooks = false;
that.$Message.error(result.message);
}
})
.catch(function (error) {
+ that.loadingGetRepHooks = false;
console.log(error);
that.$Message.error("出错了 请联系管理员!");
});
},
/**
- * 修改仓库的钩子内容(针对单个钩子)
+ * 查看钩子模板内容
*/
+ ModalStudyRepHook(key) {
+ //设置当前选中的钩子文件名称
+ this.tempSelectRepHook = this.formRepHooks[key].fileName;
+ //设置当前选中的钩子文件模板内容到输入框
+ this.tempSelectRepHookTmpl = this.formRepHooks[key].tmpl;
+ //设置标题
+ this.titleModalStudyRepHook =
+ "钩子信息介绍 - " + this.formRepHooks[key].fileName;
+ // 展示输入框
+ this.modalStudyRepHook = true;
+ },
+ /**
+ * 修改仓库的钩子内容
+ */
+ ModalEditRepHook(key) {
+ //设置当前选中的钩子文件名称
+ this.tempSelectRepHook = this.formRepHooks[key].fileName;
+ //设置当前选中的钩子文件内容到输入框
+ this.tempSelectRepHookCon = this.formRepHooks[key].con;
+ //设置标题
+ this.titleModalEditRepHook =
+ "钩子文件编辑 - " + this.formRepHooks[key].fileName;
+ // 展示输入框
+ this.modalEditRepHook = true;
+ },
EditRepHook() {
var that = this;
+ that.loadingEditRepHook = true;
var data = {
rep_name: that.currentRepName,
- type: that.formRepHooks.select,
- content: that.formRepHooks.type[that.formRepHooks.select].shell,
+ fileName: that.tempSelectRepHook,
+ content: that.tempSelectRepHookCon,
};
that.$axios
.post("/api.php?c=Svnrep&a=EditRepHook&t=web", data)
.then(function (response) {
+ that.loadingEditRepHook = false;
var result = response.data;
if (result.status == 1) {
+ that.modalEditRepHook = false;
that.$Message.success(result.message);
that.GetRepHooks();
} else {
@@ -2374,11 +2538,11 @@ export default {
}
})
.catch(function (error) {
+ that.loadingEditRepHook = false;
console.log(error);
that.$Message.error("出错了 请联系管理员!");
});
},
-
/**
* 高级
*/
@@ -2386,7 +2550,7 @@ export default {
//设置当前仓库名称
this.currentRepName = rep_name;
//设置标题
- this.titleModalRepAdvance = "高级-" + rep_name;
+ this.titleModalRepAdvance = "高级 - " + rep_name;
//重置
this.formUploadBackup.selectType = "1";
this.formUploadBackup.fileName = "";
@@ -2535,7 +2699,7 @@ export default {
//设置新名称
this.formRepEdit.new_rep_name = JSON.parse(JSON.stringify(rep_name));
//配置标题
- this.titleModalEditRepName = "修改仓库名称-" + rep_name;
+ this.titleModalEditRepName = "修改仓库名称 - " + rep_name;
//显示对话框
this.modalEditRepName = true;
},
@@ -2572,7 +2736,7 @@ export default {
DelRep(rep_name) {
var that = this;
that.$Modal.confirm({
- title: "删除仓库-" + rep_name,
+ title: "删除仓库 - " + rep_name,
content:
"确定要删除该仓库吗?
该操作不可逆!
如果该仓库有正在进行的网络传输,可能会删除失败,请注意提示信息!",
onOk: () => {
diff --git a/01.web/src/views/repositoryUser/index.vue b/01.web/src/views/repositoryUser/index.vue
index 59994eb..a031494 100644
--- a/01.web/src/views/repositoryUser/index.vue
+++ b/01.web/src/views/repositoryUser/index.vue
@@ -438,7 +438,7 @@ export default {
*/
ModalEditUserPass(index, svn_user_name) {
//设置标题
- this.titleEditUser = "修改密码-" + svn_user_name;
+ this.titleEditUser = "修改密码 - " + svn_user_name;
//设置选中用户
this.formEditUser.svn_user_name = svn_user_name;
//设置密码同步到输入框
@@ -482,7 +482,7 @@ export default {
DelUser(index, svn_user_name) {
var that = this;
that.$Modal.confirm({
- title: "删除SVN用户-" + svn_user_name,
+ title: "删除SVN用户 - " + svn_user_name,
content:
"确定要删除该用户吗?
将会从所有仓库和分组下将该用户移除
该操作不可逆!",
onOk: () => {
diff --git a/02.php/app/controller/Svnrep.php b/02.php/app/controller/Svnrep.php
index 01b6aff..b2a4575 100644
--- a/02.php/app/controller/Svnrep.php
+++ b/02.php/app/controller/Svnrep.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
- * @LastEditTime: 2022-05-09 18:54:31
+ * @LastEditTime: 2022-05-10 21:53:20
* @Description: QQ:1801168257
*/
@@ -262,6 +262,15 @@ class Svnrep extends Base
json2($result);
}
+ /**
+ * 移除仓库钩子
+ */
+ public function DelRepHook()
+ {
+ $result = $this->ServiceSvnrep->DelRepHook();
+ json2($result);
+ }
+
/**
* 修改仓库的钩子内容(针对单个钩子)
*/
diff --git a/02.php/app/function/ipc.php b/02.php/app/function/ipc.php
index 47c3ea2..d3358ee 100644
--- a/02.php/app/function/ipc.php
+++ b/02.php/app/function/ipc.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-05-07 01:00:10
* @LastEditors: witersen
- * @LastEditTime: 2022-05-07 14:19:50
+ * @LastEditTime: 2022-05-11 02:01:26
* @Description: QQ:1801168257
*/
@@ -14,13 +14,51 @@ function FunShellExec($shell)
{
$config_daemon = Config::get('daemon');
+ $request = [
+ 'type' => 'passthru',
+ 'content' => $shell
+ ];
+ $request = serialize($request);
+
+ //检测信息长度
+ if (strlen($request) >= $config_daemon['SOCKET_READ_LENGTH']) {
+ json1(200, 0, '数据长度超过' . $config_daemon['SOCKET_READ_LENGTH'] . ' 请向上调整参数:SOCKET_READ_LENGTH');
+ }
+ $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("error:" . socket_strerror(socket_last_error()));
+ $server = socket_connect($socket, $config_daemon['IPC_ADDRESS'], (int)$config_daemon['IPC_PORT']);
+ socket_write($socket, $request);
+ $reply = socket_read($socket, (int)$config_daemon['SOCKET_READ_LENGTH']);
+ socket_close($socket);
+ return unserialize($reply);
+}
+
+/**
+ * file_put_contents
+ */
+function FunFilePutContents($filename, $data, $flags = 0, $context = '')
+{
+ $config_daemon = Config::get('daemon');
+
+ $content = [
+ 'filename' => $filename,
+ 'data' => $data,
+ 'flags' => $flags,
+ 'context' => $context
+ ];
+
+ $request = [
+ 'type' => 'file_put_contents',
+ 'content' => $content
+ ];
+ $request = serialize($request);
+
//检测信息长度
- if (strlen($shell) >= $config_daemon['SOCKET_READ_LENGTH']) {
+ if (strlen($request) >= $config_daemon['SOCKET_READ_LENGTH']) {
json1(200, 0, '数据长度超过' . $config_daemon['SOCKET_READ_LENGTH'] . ' 请向上调整参数:SOCKET_READ_LENGTH');
}
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("error:" . socket_strerror(socket_last_error()));
$server = socket_connect($socket, $config_daemon['IPC_ADDRESS'], (int)$config_daemon['IPC_PORT']);
- socket_write($socket, $shell);
+ socket_write($socket, $request);
$reply = socket_read($socket, (int)$config_daemon['SOCKET_READ_LENGTH']);
socket_close($socket);
return unserialize($reply);
diff --git a/02.php/app/service/Personal.php b/02.php/app/service/Personal.php
index 8148990..d1d95fb 100644
--- a/02.php/app/service/Personal.php
+++ b/02.php/app/service/Personal.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
- * @LastEditTime: 2022-05-10 14:22:43
+ * @LastEditTime: 2022-05-11 02:15:09
* @Description: QQ:1801168257
*/
@@ -119,7 +119,9 @@ class Personal extends Base
return message(200, 0, '用户不存在');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+
+ FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
$this->database->update('svn_users', [
'svn_user_pass' => $this->payload['newPassword']
diff --git a/02.php/app/service/Svn.php b/02.php/app/service/Svn.php
index bee890a..1578b99 100644
--- a/02.php/app/service/Svn.php
+++ b/02.php/app/service/Svn.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
- * @LastEditTime: 2022-05-09 20:52:21
+ * @LastEditTime: 2022-05-11 02:15:44
* @Description: QQ:1801168257
*/
@@ -248,7 +248,9 @@ 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']);
+ // FunShellExec('echo \'' . $config . '\' > ' . $this->config_svn['svnserve_env_file']);
+
+ FunFilePutContents($this->config_svn['svnserve_env_file'], $config);
//启动svnserve
$result = FunShellExec('systemctl start svnserve');
@@ -282,7 +284,9 @@ 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']);
+ // FunShellExec('echo \'' . $config . '\' > ' . $this->config_svn['svnserve_env_file']);
+
+ FunFilePutContents($this->config_svn['svnserve_env_file'], $config);
//启动svnserve
$result = FunShellExec('systemctl start svnserve');
diff --git a/02.php/app/service/Svngroup.php b/02.php/app/service/Svngroup.php
index 2f0d32a..40d8873 100644
--- a/02.php/app/service/Svngroup.php
+++ b/02.php/app/service/Svngroup.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
- * @LastEditTime: 2022-05-10 14:49:53
+ * @LastEditTime: 2022-05-11 02:16:31
* @Description: QQ:1801168257
*/
@@ -183,7 +183,9 @@ class Svngroup extends Base
}
//写入配置文件
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//写入数据库
$this->database->insert('svn_groups', [
@@ -218,7 +220,9 @@ class Svngroup extends Base
return message(200, 0, '分组不存在');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//从数据库删除
$this->database->delete('svn_groups', [
@@ -263,7 +267,9 @@ class Svngroup extends Base
return message(200, 0, '文件格式错误(不存在[groups]标识)');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
}
@@ -348,7 +354,9 @@ class Svngroup extends Base
return message(200, 0, '要添加的用户已存在该分组');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
}
@@ -369,7 +377,9 @@ class Svngroup extends Base
return message(200, 0, '要删除的用户不在该分组');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
}
@@ -401,7 +411,9 @@ class Svngroup extends Base
return message(200, 0, '存在分组循环嵌套的情况');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
}
@@ -422,7 +434,9 @@ class Svngroup extends Base
return message(200, 0, '要删除的分组不在该分组');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
return message();
}
diff --git a/02.php/app/service/Svnrep.php b/02.php/app/service/Svnrep.php
index a707492..edddede 100644
--- a/02.php/app/service/Svnrep.php
+++ b/02.php/app/service/Svnrep.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
- * @LastEditTime: 2022-05-10 14:50:26
+ * @LastEditTime: 2022-05-11 02:19:00
* @Description: QQ:1801168257
*/
@@ -76,7 +76,9 @@ 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']);
+ // FunShellExec('echo \'' . $status . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $status);
}
//写入数据库
@@ -174,7 +176,9 @@ class Svnrep extends Base
}
if ($authzContet != $this->authzContent) {
- FunShellExec('echo \'' . $authzContet . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $authzContet . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $authzContet);
}
}
@@ -234,7 +238,9 @@ class Svnrep extends Base
//写入配置文件
if ($authzContent != $this->authzContent) {
- FunShellExec('echo \'' . $authzContent . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $authzContent . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $authzContent);
}
}
@@ -913,7 +919,9 @@ class Svnrep extends Base
}
//写入
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
return message();
@@ -936,7 +944,9 @@ class Svnrep extends Base
return message(200, 0, '已被删除');
} else {
//写入
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
return message();
@@ -965,7 +975,9 @@ class Svnrep extends Base
}
//写入
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
return message();
@@ -1018,7 +1030,9 @@ class Svnrep extends Base
}
//写入
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
return message();
@@ -1041,7 +1055,9 @@ class Svnrep extends Base
return message(200, 0, '已被删除');
} else {
//写入
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
return message();
@@ -1072,7 +1088,9 @@ class Svnrep extends Base
}
//写入
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
return message();
@@ -1138,7 +1156,9 @@ 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']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
+
+ FunFilePutContents($this->config_svn['svn_authz_file'], $result);
}
//从数据库中删除
@@ -1393,94 +1413,119 @@ class Svnrep extends Base
return message($checkResult['code'], $checkResult['status'], $checkResult['message'], $checkResult['data']);
}
- clearstatcache();
- if (!is_dir($this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/' . 'hooks')) {
- return message(200, 0, '仓库不存在或文件损坏');
- }
-
- $hooks_type_list = [
- "start-commit" => [
- "value" => "start-commit",
- "label" => "start-commit---事务创建前",
- "shell" => ""
+ $repHooks = [
+ 'start_commit' => [
+ 'fileName' => 'start-commit',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "pre-commit" => [
- "value" => "pre-commit",
- "label" => "pre-commit---事务提交前",
- "shell" => ""
+ 'pre_commit' => [
+ 'fileName' => 'pre-commit',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "post-commit" => [
- "value" => "post-commit",
- "label" => "post-commit---事务提交后",
- "shell" => ""
+ 'post_commit' => [
+ 'fileName' => 'post-commit',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "pre-lock" => [
- "value" => "pre-lock",
- "label" => "pre-lock---锁定文件前",
- "shell" => ""
+ 'pre_lock' => [
+ 'fileName' => 'pre-lock',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "post-lock" => [
- "value" => "post-lock",
- "label" => "post-lock---锁定文件后",
- "shell" => ""
+ 'post_lock' => [
+ 'fileName' => 'post-lock',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "pre-unlock" => [
- "value" => "pre-unlock",
- "label" => "pre-unlock---解锁文件前",
- "shell" => ""
+ 'pre_unlock' => [
+ 'fileName' => 'pre-unlock',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "post-unlock" => [
- "value" => "post-unlock",
- "label" => "post-unlock---解锁文件后",
- "shell" => ""
+ 'post_unlock' => [
+ 'fileName' => 'post-unlock',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "pre-revprop-change" => [
- "value" => "pre-revprop-change",
- "label" => "pre-revprop-change---修改修订版属性前",
- "shell" => ""
+ 'pre_revprop_change' => [
+ 'fileName' => 'pre-revprop-change',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
- "post-revprop-change" => [
- "value" => "post-revprop-change",
- "label" => "post-revprop-change---修改修订版属性后",
- "shell" => ""
+ 'post_revprop_change' => [
+ 'fileName' => 'post-revprop-change',
+ 'hasFile' => false,
+ 'con' => '',
+ 'tmpl' => ''
],
];
- $hooks_file_list = [
- 'start-commit',
- 'pre-commit',
- 'post-commit',
- 'pre-lock',
- 'post-lock',
- 'pre-unlock',
- 'post-unlock',
- 'pre-revprop-change',
- 'post-revprop-change'
- ];
+ $hooksPath = $this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/hooks/';
- $file_arr = scandir($this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/' . 'hooks');
+ if (!is_dir($hooksPath)) {
+ return message(200, 0, '该仓库不存在hooks文件夹');
+ }
- foreach ($file_arr as $file_item) {
- if ($file_item != '.' && $file_item != '..') {
- if (in_array($file_item, $hooks_file_list)) {
- $temp = FunShellExec(sprintf("cat '%s'", $this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/' . 'hooks' . '/' . $file_item));
- $hooks_type_list[$file_item]['shell'] = $temp['result'];
- $hooks_type_list[$file_item]['shell'] = trim($hooks_type_list[$file_item]['shell']);
- }
+ foreach ($repHooks as $key => $value) {
+ if (file_exists($hooksPath . $value['fileName'])) {
+ $repHooks[$key]['hasFile'] = true;
+ $temp = FunShellExec(sprintf("cat '%s'", $hooksPath . $value['fileName']));
+ $repHooks[$key]['con'] = $temp['result'];
+ }
+ if (file_exists($hooksPath . $value['fileName'] . '.tmpl')) {
+ $temp = FunShellExec(sprintf("cat '%s'", $hooksPath . $value['fileName'] . '.tmpl'));
+ $repHooks[$key]['tmpl'] = $temp['result'];
}
}
- return message(200, 1, '成功', $hooks_type_list);
+ return message(200, 1, '成功', $repHooks);
}
/**
- * 修改仓库的钩子内容(针对单个钩子)
+ * 移除仓库钩子
+ */
+ public function DelRepHook()
+ {
+ //检查仓库是否存在
+ $checkResult = $this->SVNAdminRep->CheckRepCreate($this->payload['rep_name'], '仓库不存在');
+ if ($checkResult['status'] != 1) {
+ return message($checkResult['code'], $checkResult['status'], $checkResult['message'], $checkResult['data']);
+ }
+
+ $hooksPath = $this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/hooks/';
+
+ if (!is_dir($hooksPath)) {
+ return message(200, 0, '该仓库不存在hooks文件夹');
+ }
+
+ if (!file_exists($hooksPath . $this->payload['fileName'])) {
+ return message(200, 0, '已经移除该仓库钩子');
+ }
+
+ FunShellExec(sprintf("cd '%s' && rm -f ./'%s'", $hooksPath, $this->payload['fileName']));
+
+ return message(200, 1, '移除成功');
+ }
+
+ /**
+ * 修改仓库的某个钩子内容
*/
public function EditRepHook()
{
- $cmd = sprintf("echo '%s' > '%s'", trim($this->payload['content']), $this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/hooks/' . $this->payload['type']);
+ $hooksPath = $this->config_svn['rep_base_path'] . $this->payload['rep_name'] . '/hooks/';
- FunShellExec($cmd);
+ //使用echo写入文件 当出现不规则的不成对的 ' " 等会出问题 当然也会包括其他问题
+ FunFilePutContents($hooksPath . $this->payload['fileName'],$this->payload['content']);
return message();
}
diff --git a/02.php/app/service/Svnuser.php b/02.php/app/service/Svnuser.php
index cb85e36..de453af 100644
--- a/02.php/app/service/Svnuser.php
+++ b/02.php/app/service/Svnuser.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:05
* @LastEditors: witersen
- * @LastEditTime: 2022-05-10 14:50:05
+ * @LastEditTime: 2022-05-11 02:21:30
* @Description: QQ:1801168257
*/
@@ -166,7 +166,9 @@ class Svnuser extends Base
return message(200, 0, '要启用的用户不存在');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+
+ FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
return message();
}
@@ -184,7 +186,9 @@ class Svnuser extends Base
return message(200, 0, '要禁用的用户不存在');
}
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+
+ FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
return message();
}
@@ -229,7 +233,9 @@ class Svnuser extends Base
}
//写入配置文件
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+
+ FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
//写入数据库
$this->database->insert('svn_users', [
@@ -269,7 +275,9 @@ class Svnuser extends Base
}
//写入配置文件
- FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+ // FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
+
+ FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
//写入数据库
$this->database->update('svn_users', [
@@ -308,9 +316,13 @@ class Svnuser extends Base
'svn_user_name' => $this->payload['svn_user_name']
]);
- FunShellExec('echo \'' . $resultAuthz . '\' > ' . $this->config_svn['svn_authz_file']);
+ // 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']);
- FunShellExec('echo \'' . $resultPasswd . '\' > ' . $this->config_svn['svn_passwd_file']);
+ FunFilePutContents($this->config_svn['svn_passwd_file'], $resultPasswd);
//日志
$this->Logs->InsertLog(
diff --git a/02.php/server/svnadmind.php b/02.php/server/svnadmind.php
index b5a47e9..d74046e 100644
--- a/02.php/server/svnadmind.php
+++ b/02.php/server/svnadmind.php
@@ -3,7 +3,7 @@
* @Author: witersen
* @Date: 2022-04-24 23:37:06
* @LastEditors: witersen
- * @LastEditTime: 2022-05-09 22:30:20
+ * @LastEditTime: 2022-05-11 01:54:56
* @Description: QQ:1801168257
*/
@@ -129,36 +129,59 @@ class Daemon
private function HandleRequest($client)
{
//接收客户端发送的数据
- $cmmand = socket_read($client, $this->config_daemon['SOCKET_READ_LENGTH']);
+ $receive = socket_read($client, $this->config_daemon['SOCKET_READ_LENGTH']);
+ $receive = unserialize($receive);
+
+ $type = $receive['type'];
+ $content = $receive['content'];
//console模式
if ($this->workMode == 'console') {
echo PHP_EOL . '---------receive---------' . PHP_EOL;
- echo $cmmand . PHP_EOL;
+ print_r($receive);
}
- if (trim($cmmand) != '') {
- //定义错误输出文件路径
- $stderrFile = $this->config_svn['temp_base_path'] . uniqid();
-
- //将标准错误重定向到文件
- //使用状态码来标识错误信息
- ob_start();
- passthru($cmmand . " 2>$stderrFile", $resultCode);
- $buffer = ob_get_contents();
- ob_end_clean();
-
- //将错误信息和正确信息分类收集
+ if ($type == 'passthru') {
+ if (trim($content) != '') {
+ //定义错误输出文件路径
+ $stderrFile = $this->config_svn['temp_base_path'] . uniqid();
+
+ //将标准错误重定向到文件
+ //使用状态码来标识错误信息
+ ob_start();
+ passthru($content . " 2>$stderrFile", $resultCode);
+ $buffer = ob_get_contents();
+ ob_end_clean();
+
+ //将错误信息和正确信息分类收集
+ $result = [
+ 'resultCode' => $resultCode,
+ 'result' => trim($buffer),
+ 'error' => file_get_contents($stderrFile)
+ ];
+
+ //销毁文件
+ unlink($stderrFile);
+ } else {
+ //探测程序会发送空信息
+ $result = [
+ 'resultCode' => 0,
+ 'result' => '',
+ 'error' => ''
+ ];
+ }
+ } else if ($type == 'file_put_contents') {
+ if ($content['flags'] == 0) {
+ file_put_contents($content['filename'], $content['data']);
+ } else {
+ file_put_contents($content['filename'], $content['data'], $content['flags'], $content['context']);
+ }
$result = [
- 'resultCode' => $resultCode,
- 'result' => trim($buffer),
- 'error' => file_get_contents($stderrFile)
+ 'resultCode' => 0,
+ 'result' => '',
+ 'error' => ''
];
-
- //销毁文件
- unlink($stderrFile);
} else {
- //探测程序会发送空信息
$result = [
'resultCode' => 0,
'result' => '',