Browse Source

适配ubuntu

docker-svn
witersen 3 years ago
parent
commit
e43c25ff10
  1. 4
      02.php/api.php
  2. 3
      02.php/app/service/Svnrep.php
  3. 7
      02.php/config/svn.php
  4. 56
      02.php/server/install.php
  5. 33
      02.php/server/svnadmind.php

4
02.php/api.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-11 23:48:29 * @LastEditTime: 2022-05-12 17:19:13
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -84,7 +84,7 @@ if (PHP_VERSION < '5.5') {
//检测open_basedir //检测open_basedir
if (ini_get('open_basedir') != '') { if (ini_get('open_basedir') != '') {
json1(200, 0, '需要关闭open_basedir'); json1(200, 0, '需要关闭open_basedir!如果已经关闭未生效,请重启php!');
} }
//检测禁用函数 //检测禁用函数

3
02.php/app/service/Svnrep.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:05 * @Date: 2022-04-24 23:37:05
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-12 13:30:42 * @LastEditTime: 2022-05-12 17:27:57
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -1199,6 +1199,7 @@ class Svnrep extends Base
{ {
$result = $this->SVNAdminRep->GetRepDetail110($this->payload['rep_name']); $result = $this->SVNAdminRep->GetRepDetail110($this->payload['rep_name']);
if ($result['resultCode'] == 0) { if ($result['resultCode'] == 0) {
$result = $result['result'];
//Subversion 1.10 及以上版本 //Subversion 1.10 及以上版本
$resultArray = explode("\n", $result); $resultArray = explode("\n", $result);
$newArray = []; $newArray = [];

7
02.php/config/svn.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-12 00:52:40 * @LastEditTime: 2022-05-12 16:59:04
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -64,7 +64,10 @@ return [
/** /**
* svnserve 自启动文件 * 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'
],
/** /**
* 推荐钩子目录 * 推荐钩子目录

56
02.php/server/install.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-05-08 13:31:07 * @Date: 2022-05-08 13:31:07
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-12 00:11:29 * @LastEditTime: 2022-05-12 17:01:52
* @Description: QQ:1801168257 * @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的管理 * 修改已经安装的Subversion配置以适合SVNAdmin的管理
*/ */
@ -411,9 +445,17 @@ CON;
echo '注册新的svnserve服务' . PHP_EOL; echo '注册新的svnserve服务' . PHP_EOL;
$os = $this->GetOS();
$con_svnserve_service_file = file_get_contents($templete_path . 'svnserve/svnserve.service'); $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']); $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; 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(); (new Install())->Run();

33
02.php/server/svnadmind.php

@ -3,7 +3,7 @@
* @Author: witersen * @Author: witersen
* @Date: 2022-04-24 23:37:06 * @Date: 2022-04-24 23:37:06
* @LastEditors: witersen * @LastEditors: witersen
* @LastEditTime: 2022-05-12 00:17:45 * @LastEditTime: 2022-05-12 17:07:33
* @Description: QQ:1801168257 * @Description: QQ:1801168257
*/ */
@ -11,7 +11,7 @@
* 将工作模式限制在cli模式 * 将工作模式限制在cli模式
*/ */
if (!preg_match('/cli/i', php_sapi_name())) { 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'); ini_set('display_errors', '1');
@ -50,17 +50,17 @@ class Daemon
{ {
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid < 0) { if ($pid < 0) {
exit('pcntl_fork 错误'); exit('pcntl_fork 错误' . PHP_EOL);
} elseif ($pid > 0) { } elseif ($pid > 0) {
exit(); exit();
} }
$sid = posix_setsid(); $sid = posix_setsid();
if (!$sid) { if (!$sid) {
exit('posix_setsid 错误'); exit('posix_setsid 错误' . PHP_EOL);
} }
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid < 0) { if ($pid < 0) {
exit('pcntl_fork 错误'); exit('pcntl_fork 错误' . PHP_EOL);
} elseif ($pid > 0) { } elseif ($pid > 0) {
exit(); exit();
} }
@ -217,13 +217,24 @@ class Daemon
exit('启动失败:当前操作系统不为Linux' . PHP_EOL); exit('启动失败:当前操作系统不为Linux' . PHP_EOL);
} }
if (file_exists('/etc/redhat-release')) { if (file_exists('/etc/redhat-release')) {
$info = file_get_contents('/etc/redhat-release'); $readhat_release = file_get_contents('/etc/redhat-release');
if (!strstr($info, 'CentOS') && (strstr($info, '8.') || strstr($info, '7.'))) { $readhat_release = strtolower($readhat_release);
exit('启动失败:当前仅支持 CentOS 7和 CentOS8 操作系统' . PHP_EOL); 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')); $disable_functions = explode(',', ini_get('disable_functions'));
foreach ($disable_functions as $disable) { foreach ($disable_functions as $disable) {
if (in_array(trim($disable), $require_functions)) { if (in_array(trim($disable), $require_functions)) {
exit("启动失败:需要的 $disable 函数被禁用"); exit("启动失败:需要的 $disable 函数被禁用" . PHP_EOL);
} }
} }
} }

Loading…
Cancel
Save