Browse Source

弃用只可在Linux平台使用的cat命令

docker-svn
witersen 3 years ago
parent
commit
29f43e4a22
  1. 3
      02.php/api.php
  2. 4
      02.php/app/service/Personal.php
  3. 12
      02.php/app/service/Svn.php
  4. 16
      02.php/app/service/Svngroup.php
  5. 68
      02.php/app/service/Svnrep.php
  6. 14
      02.php/app/service/Svnuser.php
  7. 22
      02.php/app/service/base/Base.php
  8. 119
      02.php/server/svnadmind.php

3
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-13 01:25:06
* @LastEditTime: 2022-05-20 16:31:42
* @Description: QQ:1801168257
*/
@ -98,7 +98,6 @@ foreach ($disable_functions as $disable) { @@ -98,7 +98,6 @@ foreach ($disable_functions as $disable) {
//检测守护进程状态
$state = FunDetectState();
// echo $state;
// return;
if ($state == 0) {
json1(401, 0, '守护进程响应超时');

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-11 02:15:09
* @LastEditTime: 2022-05-20 16:29:41
* @Description: QQ:1801168257
*/
@ -119,8 +119,6 @@ class Personal extends Base @@ -119,8 +119,6 @@ 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', [

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-12 00:20:14
* @LastEditTime: 2022-05-20 16:29:48
* @Description: QQ:1801168257
*/
@ -140,8 +140,10 @@ class Svn extends Base @@ -140,8 +140,10 @@ class Svn extends Base
$bindPort = '';
$bindHost = '';
$svnserveContent = FunShellExec(sprintf("cat '%s'", $this->config_svn['svnserve_env_file']));
$svnserveContent = $svnserveContent['result'];
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']);
//匹配端口
if (preg_match('/--listen-port[\s]+([0-9]+)/', $svnserveContent, $portMatchs) != 0) {
@ -248,8 +250,6 @@ class Svn extends Base @@ -248,8 +250,6 @@ 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,8 +284,6 @@ class Svn extends Base @@ -284,8 +284,6 @@ 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-11 02:16:31
* @LastEditTime: 2022-05-20 16:29:58
* @Description: QQ:1801168257
*/
@ -183,8 +183,6 @@ class Svngroup extends Base @@ -183,8 +183,6 @@ class Svngroup extends Base
}
//写入配置文件
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//写入数据库
@ -220,8 +218,6 @@ class Svngroup extends Base @@ -220,8 +218,6 @@ 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);
//从数据库删除
@ -267,8 +263,6 @@ class Svngroup extends Base @@ -267,8 +263,6 @@ 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();
@ -354,8 +348,6 @@ class Svngroup extends Base @@ -354,8 +348,6 @@ 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();
@ -377,8 +369,6 @@ class Svngroup extends Base @@ -377,8 +369,6 @@ 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();
@ -411,8 +401,6 @@ class Svngroup extends Base @@ -411,8 +401,6 @@ 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();
@ -434,8 +422,6 @@ class Svngroup extends Base @@ -434,8 +422,6 @@ 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();

68
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-12 17:27:57
* @LastEditTime: 2022-05-20 16:31:32
* @Description: QQ:1801168257
*/
@ -79,8 +79,6 @@ class Svnrep extends Base @@ -79,8 +79,6 @@ 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);
}
@ -179,8 +177,6 @@ class Svnrep extends Base @@ -179,8 +177,6 @@ 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);
}
}
@ -241,8 +237,6 @@ class Svnrep extends Base @@ -241,8 +237,6 @@ 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);
}
}
@ -922,8 +916,6 @@ class Svnrep extends Base @@ -922,8 +916,6 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -947,8 +939,6 @@ class Svnrep extends Base @@ -947,8 +939,6 @@ 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);
//返回
@ -978,8 +968,6 @@ class Svnrep extends Base @@ -978,8 +968,6 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -1033,8 +1021,6 @@ class Svnrep extends Base @@ -1033,8 +1021,6 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -1058,8 +1044,6 @@ class Svnrep extends Base @@ -1058,8 +1044,6 @@ 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);
//返回
@ -1091,8 +1075,6 @@ class Svnrep extends Base @@ -1091,8 +1075,6 @@ class Svnrep extends Base
}
//写入
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_authz_file']);
FunFilePutContents($this->config_svn['svn_authz_file'], $result);
//返回
@ -1164,8 +1146,6 @@ class Svnrep extends Base @@ -1164,8 +1146,6 @@ 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);
}
@ -1501,14 +1481,23 @@ class Svnrep extends Base @@ -1501,14 +1481,23 @@ class Svnrep extends Base
}
foreach ($repHooks as $key => $value) {
if (file_exists($hooksPath . $value['fileName'])) {
$hookFile = $hooksPath . $value['fileName'];
$hookTmpleFile = $hookFile . '.tmpl';
if (file_exists($hookFile)) {
$repHooks[$key]['hasFile'] = true;
$temp = FunShellExec(sprintf("cat '%s'", $hooksPath . $value['fileName']));
$repHooks[$key]['con'] = $temp['result'];
if (!is_readable($hookFile)) {
return message(200, 0, '文件' . $hookFile . '不可读');
}
$repHooks[$key]['con'] = file_get_contents($hookFile);
}
if (file_exists($hooksPath . $value['fileName'] . '.tmpl')) {
$temp = FunShellExec(sprintf("cat '%s'", $hooksPath . $value['fileName'] . '.tmpl'));
$repHooks[$key]['tmpl'] = $temp['result'];
if (file_exists($hookTmpleFile)) {
if (!is_readable($hookTmpleFile)) {
return message(200, 0, '文件' . $hookTmpleFile . '不可读');
}
$repHooks[$key]['tmpl'] = file_get_contents($hookTmpleFile);
}
}
@ -1566,6 +1555,9 @@ class Svnrep extends Base @@ -1566,6 +1555,9 @@ 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) {
@ -1577,24 +1569,34 @@ class Svnrep extends Base @@ -1577,24 +1569,34 @@ 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;
}
$hookName = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/hookName'));
$hookName = $hookName['result'];
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');
if (!file_exists($recommend_hook_path . $dir . '/' . trim($hookName))) {
continue;
}
$hookContent = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/' . $hookName));
$hookContent = $hookContent['result'];
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);
$hookDescription = FunShellExec(sprintf("cat '%s'", $recommend_hook_path . $dir . '/hookDescription'));
$hookDescription = $hookDescription['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');
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-11 02:21:30
* @LastEditTime: 2022-05-20 16:31:46
* @Description: QQ:1801168257
*/
@ -166,8 +166,6 @@ class Svnuser extends Base @@ -166,8 +166,6 @@ 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();
@ -186,8 +184,6 @@ class Svnuser extends Base @@ -186,8 +184,6 @@ 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();
@ -233,8 +229,6 @@ class Svnuser extends Base @@ -233,8 +229,6 @@ class Svnuser extends Base
}
//写入配置文件
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
//写入数据库
@ -275,8 +269,6 @@ class Svnuser extends Base @@ -275,8 +269,6 @@ class Svnuser extends Base
}
//写入配置文件
// FunShellExec('echo \'' . $result . '\' > ' . $this->config_svn['svn_passwd_file']);
FunFilePutContents($this->config_svn['svn_passwd_file'], $result);
//写入数据库
@ -316,12 +308,8 @@ class Svnuser extends Base @@ -316,12 +308,8 @@ 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-09 21:10:15
* @LastEditTime: 2022-05-20 16:39:27
* @Description: QQ:1801168257
*/
@ -269,7 +269,15 @@ class Base @@ -269,7 +269,15 @@ class Base
*/
public function GetAuthz()
{
$this->authzContent = file_exists($this->config_svn['svn_authz_file']) ? file_get_contents($this->config_svn['svn_authz_file']) : '';
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']);
}
/**
@ -277,6 +285,14 @@ class Base @@ -277,6 +285,14 @@ class Base
*/
public function GetPasswd()
{
$this->passwdContent = file_exists($this->config_svn['svn_passwd_file']) ? file_get_contents($this->config_svn['svn_passwd_file']) : '';
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']);
}
}

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-13 01:24:54
* @LastEditTime: 2022-05-20 16:06:09
* @Description: QQ:1801168257
*/
@ -29,8 +29,7 @@ class Daemon @@ -29,8 +29,7 @@ class Daemon
private $scripts = [
'start',
'stop',
'restart',
'console'
'debug'
];
private $config_daemon;
private $config_svn;
@ -44,42 +43,6 @@ class Daemon @@ -44,42 +43,6 @@ 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套接字并监听指定端口
*/
@ -137,8 +100,8 @@ class Daemon @@ -137,8 +100,8 @@ class Daemon
$type = $receive['type'];
$content = $receive['content'];
//console模式
if ($this->workMode == 'console') {
//debug模式
if ($this->workMode == 'debug') {
echo PHP_EOL . '---------receive---------' . PHP_EOL;
print_r($receive);
}
@ -191,8 +154,8 @@ class Daemon @@ -191,8 +154,8 @@ class Daemon
];
}
//console模式
if ($this->workMode == 'console') {
//debug模式
if ($this->workMode == 'debug') {
echo PHP_EOL . '---------result---------' . PHP_EOL;
echo 'resultCode: ' . $result['resultCode'] . PHP_EOL;
echo 'result: ' . $result['result'] . PHP_EOL;
@ -282,29 +245,9 @@ class Daemon @@ -282,29 +245,9 @@ 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 StopDaemon()
private function Stop()
{
if (file_exists($this->pidFile)) {
$pid = file_get_contents($this->pidFile);
@ -314,18 +257,35 @@ class Daemon @@ -314,18 +257,35 @@ class Daemon
}
/**
* 重启守护进程
* 启动
*/
private function RestartDeamon()
private function Start()
{
$this->StopDaemon();
$this->StartDaemon();
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();
}
/**
* 以控制台模式工作 用于调试
* 调试
*/
private function StartConsole()
private function Debug()
{
if (file_exists($this->pidFile)) {
$pid = file_get_contents($this->pidFile);
@ -339,28 +299,25 @@ class Daemon @@ -339,28 +299,25 @@ 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 [start | stop | restart | console]' . PHP_EOL);
exit('用法:php svnadmin.php [' . implode(' | ', $this->scripts) . ']' . PHP_EOL);
}
if ($this->workMode == 'stop') {
$this->StopDaemon();
$this->Stop();
} else {
$this->CheckSysType();
$this->CheckPhpVersion();
$this->CheckDisabledFun();
if ($this->workMode == 'start') {
$this->StartDaemon();
} else if ($this->workMode == 'restart') {
$this->RestartDeamon();
} else if ($this->workMode == 'console') {
$this->StartConsole();
if ($this->workMode == 'debug') {
$this->Debug();
} else if ($this->workMode == 'start') {
$this->Start();
}
}
} else {
exit('用法:php svnadmin.php [start | stop restart | console]' . PHP_EOL);
exit('用法:php svnadmin.php [' . implode(' | ', $this->scripts) . ']' . PHP_EOL);
}
}
}

Loading…
Cancel
Save