From e43c25ff100b0af117b6efccb59bff73c0ffc474 Mon Sep 17 00:00:00 2001 From: witersen <1801168257@qq.com> Date: Thu, 12 May 2022 17:34:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8Dubuntu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02.php/api.php | 4 +-- 02.php/app/service/Svnrep.php | 3 +- 02.php/config/svn.php | 7 +++-- 02.php/server/install.php | 56 +++++++++++++++++++++++++++++++++-- 02.php/server/svnadmind.php | 33 ++++++++++++++------- 5 files changed, 85 insertions(+), 18 deletions(-) diff --git a/02.php/api.php b/02.php/api.php index a34f4a2..74a7747 100644 --- a/02.php/api.php +++ b/02.php/api.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:06 * @LastEditors: witersen - * @LastEditTime: 2022-05-11 23:48:29 + * @LastEditTime: 2022-05-12 17:19:13 * @Description: QQ:1801168257 */ @@ -84,7 +84,7 @@ if (PHP_VERSION < '5.5') { //检测open_basedir if (ini_get('open_basedir') != '') { - json1(200, 0, '需要关闭open_basedir'); + json1(200, 0, '需要关闭open_basedir!如果已经关闭未生效,请重启php!'); } //检测禁用函数 diff --git a/02.php/app/service/Svnrep.php b/02.php/app/service/Svnrep.php index 7d97ed3..d6df810 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-12 13:30:42 + * @LastEditTime: 2022-05-12 17:27:57 * @Description: QQ:1801168257 */ @@ -1199,6 +1199,7 @@ class Svnrep extends Base { $result = $this->SVNAdminRep->GetRepDetail110($this->payload['rep_name']); if ($result['resultCode'] == 0) { + $result = $result['result']; //Subversion 1.10 及以上版本 $resultArray = explode("\n", $result); $newArray = []; diff --git a/02.php/config/svn.php b/02.php/config/svn.php index c5f36f6..67a9611 100644 --- a/02.php/config/svn.php +++ b/02.php/config/svn.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-04-24 23:37:06 * @LastEditors: witersen - * @LastEditTime: 2022-05-12 00:52:40 + * @LastEditTime: 2022-05-12 16:59:04 * @Description: QQ:1801168257 */ @@ -64,7 +64,10 @@ return [ /** * svnserve 自启动文件 */ - 'svnserve_service_file' => '/usr/lib/systemd/system/svnserve.service', + 'svnserve_service_file' => [ + 'centos' => '/usr/lib/systemd/system/svnserve.service', + 'ubuntu' => '/lib/systemd/system/svnserve.service' + ], /** * 推荐钩子目录 diff --git a/02.php/server/install.php b/02.php/server/install.php index 11979a6..f24256d 100644 --- a/02.php/server/install.php +++ b/02.php/server/install.php @@ -3,7 +3,7 @@ * @Author: witersen * @Date: 2022-05-08 13:31:07 * @LastEditors: witersen - * @LastEditTime: 2022-05-12 00:11:29 + * @LastEditTime: 2022-05-12 17:01:52 * @Description: QQ:1801168257 */ @@ -206,6 +206,40 @@ class Install { } + /** + * 获取Linux操作系统类型 + * + * /etc/redhat-release redhat 或 centos + * /etc/debian_version debian 或 ubuntu + * /etc/slackware_version Slackware + * /etc/lsb-release ubuntu + */ + private function GetOS() + { + if (PHP_OS != 'Linux') { + return false; + } + if (file_exists('/etc/redhat-release')) { + $readhat_release = file_get_contents('/etc/redhat-release'); + $readhat_release = strtolower($readhat_release); + if (strstr($readhat_release, 'centos')) { + if (strstr($readhat_release, '8.')) { + return 'centos 8'; + } else if (strstr($readhat_release, '7.')) { + return 'centos 7'; + } else { + return false; + } + } else { + return false; + } + } else if (file_exists('/etc/lsb-release')) { + return 'ubuntu'; + } else { + return false; + } + } + /** * 修改已经安装的Subversion配置以适合SVNAdmin的管理 */ @@ -411,9 +445,17 @@ CON; echo '注册新的svnserve服务' . PHP_EOL; + $os = $this->GetOS(); $con_svnserve_service_file = file_get_contents($templete_path . 'svnserve/svnserve.service'); $con_svnserve_service_file = sprintf($con_svnserve_service_file, $this->config_svn['svnserve_env_file'], $needBin['svnserve'], $this->config_svn['svnserve_pid_file']); - file_put_contents($this->config_svn['svnserve_service_file'], $con_svnserve_service_file); + if ($os == 'centos 7' || $os == 'centos 8') { + file_put_contents($this->config_svn['svnserve_service_file']['centos'], $con_svnserve_service_file); + } else if ($os == 'ubuntu') { + file_put_contents($this->config_svn['svnserve_service_file']['ubuntu'], $con_svnserve_service_file); + } else { + echo '暂时不支持该系统' . PHP_EOL; + exit(); + } echo '===============================================' . PHP_EOL; @@ -529,4 +571,14 @@ CON; } } +//检测禁用函数 +$require_functions = ['shell_exec', 'passthru']; +$disable_functions = explode(',', ini_get('disable_functions')); +foreach ($disable_functions as $disable) { + if (in_array(trim($disable), $require_functions)) { + echo "需要的 $disable 函数被禁用" . PHP_EOL; + exit(); + } +} + (new Install())->Run(); diff --git a/02.php/server/svnadmind.php b/02.php/server/svnadmind.php index 6fe996c..5c067d8 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-12 00:17:45 + * @LastEditTime: 2022-05-12 17:07:33 * @Description: QQ:1801168257 */ @@ -11,7 +11,7 @@ * 将工作模式限制在cli模式 */ if (!preg_match('/cli/i', php_sapi_name())) { - exit('require php-cli mode'); + exit('require php-cli mode' . PHP_EOL); } ini_set('display_errors', '1'); @@ -50,17 +50,17 @@ class Daemon { $pid = pcntl_fork(); if ($pid < 0) { - exit('pcntl_fork 错误'); + exit('pcntl_fork 错误' . PHP_EOL); } elseif ($pid > 0) { exit(); } $sid = posix_setsid(); if (!$sid) { - exit('posix_setsid 错误'); + exit('posix_setsid 错误' . PHP_EOL); } $pid = pcntl_fork(); if ($pid < 0) { - exit('pcntl_fork 错误'); + exit('pcntl_fork 错误' . PHP_EOL); } elseif ($pid > 0) { exit(); } @@ -217,13 +217,24 @@ class Daemon exit('启动失败:当前操作系统不为Linux' . PHP_EOL); } if (file_exists('/etc/redhat-release')) { - $info = file_get_contents('/etc/redhat-release'); - if (!strstr($info, 'CentOS') && (strstr($info, '8.') || strstr($info, '7.'))) { - exit('启动失败:当前仅支持 CentOS 7和 CentOS8 操作系统' . PHP_EOL); + $readhat_release = file_get_contents('/etc/redhat-release'); + $readhat_release = strtolower($readhat_release); + if (strstr($readhat_release, 'centos')) { + if (strstr($readhat_release, '8.')) { + return 'centos 8'; + } else if (strstr($readhat_release, '7.')) { + return 'centos 7'; + } else { + exit('启动失败:不支持当前操作系统类型或版本' . PHP_EOL); + } + } else { + exit('启动失败:不支持当前操作系统类型或版本' . PHP_EOL); } - return; + } else if (file_exists('/etc/lsb-release')) { + return 'ubuntu'; + } else { + exit('启动失败:不支持当前操作系统类型或版本' . PHP_EOL); } - exit('启动失败:当前仅支持 CentOS 7和 CentOS8 操作系统' . PHP_EOL); } /** @@ -247,7 +258,7 @@ class Daemon $disable_functions = explode(',', ini_get('disable_functions')); foreach ($disable_functions as $disable) { if (in_array(trim($disable), $require_functions)) { - exit("启动失败:需要的 $disable 函数被禁用"); + exit("启动失败:需要的 $disable 函数被禁用" . PHP_EOL); } } }