Browse Source

增加禁用函数检查和操作系统类型检查

docker-svn v2.2
witersen 3 years ago
parent
commit
d50428545a
  1. 14
      02.php/app/controller/config.class.php
  2. 18
      02.php/app/controller/crontab.class.php
  3. 32
      02.php/app/controller/firewall.class.php
  4. 90
      02.php/app/controller/svnserve.class.php
  5. 13
      02.php/app/core/controller.class.php
  6. 37
      02.php/app/function/socket.function.php
  7. 15
      02.php/config/config.php
  8. 55
      02.php/server/svnadmind.php

14
02.php/app/controller/config.class.php

@ -102,8 +102,8 @@ class Config extends Controller {
//更改版本库父文件夹后触发的操作 //更改版本库父文件夹后触发的操作
private function UpdateRepositoryParentPath($old_path, $new_path) { private function UpdateRepositoryParentPath($old_path, $new_path) {
parent::RequestReplyExec("mkdir $new_path"); RequestReplyExec("mkdir $new_path");
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
/* /*
* 没有安装过svn服务 * 没有安装过svn服务
@ -116,7 +116,7 @@ class Config extends Controller {
$file_arr2 = scandir($old_path . '/' . $file_item); $file_arr2 = scandir($old_path . '/' . $file_item);
foreach ($file_arr2 as $file_item2) { foreach ($file_arr2 as $file_item2) {
if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) {
parent::RequestReplyExec('mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path); RequestReplyExec('mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path);
} }
} }
} }
@ -142,7 +142,7 @@ class Config extends Controller {
* 安装过svn服务 * 安装过svn服务
*/ */
//停止服务 //停止服务
parent::RequestReplyExec('systemctl stop svnserve'); RequestReplyExec('systemctl stop svnserve');
//移动仓库 //移动仓库
$file_arr = scandir($old_path); $file_arr = scandir($old_path);
foreach ($file_arr as $file_item) { foreach ($file_arr as $file_item) {
@ -151,16 +151,16 @@ class Config extends Controller {
$file_arr2 = scandir($old_path . '/' . $file_item); $file_arr2 = scandir($old_path . '/' . $file_item);
foreach ($file_arr2 as $file_item2) { foreach ($file_arr2 as $file_item2) {
if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) { if (($file_item2 == 'conf' || $file_item2 == 'db' || $file_item2 == 'hooks' || $file_item2 == 'locks')) {
parent::RequestReplyExec('mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path); RequestReplyExec('mv -b -f ' . $old_path . '/' . $file_item . ' ' . $new_path);
} }
} }
} }
} }
} }
//修改配置文件 //修改配置文件
parent::RequestReplyExec('sed -i \'s/' . str_replace('/', '\/', $old_path) . '/' . str_replace('/', '\/', $new_path) . '/g\'' . ' /etc/sysconfig/svnserve'); //bug RequestReplyExec('sed -i \'s/' . str_replace('/', '\/', $old_path) . '/' . str_replace('/', '\/', $new_path) . '/g\'' . ' /etc/sysconfig/svnserve'); //bug
//启动服务 //启动服务
parent::RequestReplyExec('systemctl start svnserve'); RequestReplyExec('systemctl start svnserve');
//检查配置文件是否被正确修改 //检查配置文件是否被正确修改
$file = fopen("/etc/sysconfig/svnserve", "r") or exit("无法打开文件!"); $file = fopen("/etc/sysconfig/svnserve", "r") or exit("无法打开文件!");
$file_content = array(); $file_content = array();

18
02.php/app/controller/crontab.class.php

@ -57,7 +57,7 @@ class Crontab extends Controller {
$cron_path = "/var/spool/cron/root"; $cron_path = "/var/spool/cron/root";
//检查计划任务文件是否存在 //检查计划任务文件是否存在
if (!file_exists($cron_path)) { if (!file_exists($cron_path)) {
parent::RequestReplyExec("touch $cron_path"); RequestReplyExec("touch $cron_path");
} }
//构造脚本文件标识字符串 //构造脚本文件标识字符串
@ -65,8 +65,8 @@ class Crontab extends Controller {
//构造脚本文件路径 //构造脚本文件路径
$shell_path = BASE_PATH . '/data/crond/' . $sign; $shell_path = BASE_PATH . '/data/crond/' . $sign;
parent::RequestReplyExec("touch $shell_path"); RequestReplyExec("touch $shell_path");
parent::RequestReplyExec("chmod 755 $shell_path"); RequestReplyExec("chmod 755 $shell_path");
//获取执行周期 //获取执行周期
$cycle = $this->EnCrontabFormat($cycle_type, $week, $hour, $minute); $cycle = $this->EnCrontabFormat($cycle_type, $week, $hour, $minute);
@ -93,20 +93,20 @@ shell;
shell; shell;
} else { } else {
parent::RequestReplyExec("rm -f $shell_path"); RequestReplyExec("rm -f $shell_path");
$data['status'] = 0; $data['status'] = 0;
$data['message'] = '失败 备份类型错误'; $data['message'] = '失败 备份类型错误';
return $data; return $data;
} }
//向脚本文件并写入内容 //向脚本文件并写入内容
parent::RequestReplyExec("echo '$shell_content' > $shell_path"); RequestReplyExec("echo '$shell_content' > $shell_path");
//将周期+脚本文件路径以追加方式写入计划任务文件 /var/spool/cron/root //将周期+脚本文件路径以追加方式写入计划任务文件 /var/spool/cron/root
//$content = $cycle . ' bash ' . $shell_path; //$content = $cycle . ' bash ' . $shell_path;
$content = $cycle . ' bash ' . $shell_path; $content = $cycle . ' bash ' . $shell_path;
parent::RequestReplyExec("echo '$content' >> $cron_path"); RequestReplyExec("echo '$content' >> $cron_path");
parent::RequestReplyExec("systemctl restart crond"); RequestReplyExec("systemctl restart crond");
//将信息写入数据库表 //将信息写入数据库表
$this->database_medoo->insert("crontab", [ $this->database_medoo->insert("crontab", [
@ -129,9 +129,9 @@ shell;
function DeleteCrontab($requestPayload) { function DeleteCrontab($requestPayload) {
$sign = $requestPayload["sign"]; $sign = $requestPayload["sign"];
//从计划任务文件删除 //从计划任务文件删除
parent::RequestReplyExec("sed -i '/$sign/d' /var/spool/cron/root"); RequestReplyExec("sed -i '/$sign/d' /var/spool/cron/root");
//从web路径删除 //从web路径删除
parent::RequestReplyExec("rm -f " . BASE_PATH . '/data/crond/' . $sign); RequestReplyExec("rm -f " . BASE_PATH . '/data/crond/' . $sign);
//从数据库删除 //从数据库删除
$this->database_medoo->delete("crontab", [ $this->database_medoo->delete("crontab", [
"AND" => [ "AND" => [

32
02.php/app/controller/firewall.class.php

@ -40,19 +40,19 @@ class Firewall extends Controller {
switch ($action) { switch ($action) {
case 'startFirewall': case 'startFirewall':
parent::RequestReplyExec('systemctl start firewalld'); RequestReplyExec('systemctl start firewalld');
parent::RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec('firewall-cmd --reload'); RequestReplyExec('firewall-cmd --reload');
break; break;
case 'restartFirewall': case 'restartFirewall':
parent::RequestReplyExec('systemctl restart firewalld'); RequestReplyExec('systemctl restart firewalld');
parent::RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
parent::RequestReplyExec('firewall-cmd --reload'); RequestReplyExec('firewall-cmd --reload');
break; break;
case 'stopFirewall': case 'stopFirewall':
parent::RequestReplyExec('systemctl stop firewalld'); RequestReplyExec('systemctl stop firewalld');
break; break;
} }
@ -74,8 +74,8 @@ class Firewall extends Controller {
$data['message'] = '参数不完整'; $data['message'] = '参数不完整';
return $data; return $data;
} }
parent::RequestReplyExec('firewall-cmd --zone=public --' . $type . '-port=' . $port . '/' . $protocal . ' --permanent'); RequestReplyExec('firewall-cmd --zone=public --' . $type . '-port=' . $port . '/' . $protocal . ' --permanent');
parent::RequestReplyExec('firewall-cmd --reload'); RequestReplyExec('firewall-cmd --reload');
sleep(1); sleep(1);
@ -87,7 +87,7 @@ class Firewall extends Controller {
//获取防火墙规则 //获取防火墙规则
function GetFirewallPolicy($requestPayload) { function GetFirewallPolicy($requestPayload) {
//获取80 443 3690是否加入防火墙 //获取80 443 3690是否加入防火墙
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep firewalld'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep firewalld');
if ($info == ISNULL) { if ($info == ISNULL) {
$info = array(); $info = array();
$info['svn'] = false; $info['svn'] = false;
@ -101,21 +101,21 @@ class Firewall extends Controller {
} }
$info = array(); $info = array();
$result = trim(parent::RequestReplyExec('firewall-cmd --query-port=80/tcp')); $result = trim(RequestReplyExec('firewall-cmd --query-port=80/tcp'));
if ($result == 'yes') { if ($result == 'yes') {
$info['http'] = true; $info['http'] = true;
} else { } else {
$info['http'] = false; $info['http'] = false;
} }
$result = trim(parent::RequestReplyExec('firewall-cmd --query-port=443/tcp')); $result = trim(RequestReplyExec('firewall-cmd --query-port=443/tcp'));
if ($result == 'yes') { if ($result == 'yes') {
$info['https'] = true; $info['https'] = true;
} else { } else {
$info['https'] = false; $info['https'] = false;
} }
$result = trim(parent::RequestReplyExec('firewall-cmd --query-port=3690/tcp')); $result = trim(RequestReplyExec('firewall-cmd --query-port=3690/tcp'));
if ($result == 'yes') { if ($result == 'yes') {
$info['svn'] = true; $info['svn'] = true;
} else { } else {
@ -130,7 +130,7 @@ class Firewall extends Controller {
//获取防火墙状态 //获取防火墙状态
function GetFirewallStatus($requestPayload) { function GetFirewallStatus($requestPayload) {
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep firewalld'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep firewalld');
if ($info == ISNULL) { if ($info == ISNULL) {
$info = array(); $info = array();
$info['status'] = '已停止'; $info['status'] = '已停止';

90
02.php/app/controller/svnserve.class.php

@ -80,7 +80,7 @@ class Svnserve extends Controller
$data['message'] = '仓库不存在或文件损坏'; $data['message'] = '仓库不存在或文件损坏';
return $data; return $data;
} }
parent::RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path); RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path);
foreach ($hooks_type_list as $key => $value) { foreach ($hooks_type_list as $key => $value) {
file_put_contents($this->svn_repository_path . '/' . $repository_name . '/' . 'hooks' . '/' . $value['value'], $value["shell"]); file_put_contents($this->svn_repository_path . '/' . $repository_name . '/' . 'hooks' . '/' . $value['value'], $value["shell"]);
} }
@ -241,7 +241,7 @@ class Svnserve extends Controller
$data = array(); $data = array();
//创建svn仓库父目录 //创建svn仓库父目录
parent::RequestReplyExec('mkdir -p ' . $this->svn_repository_path); RequestReplyExec('mkdir -p ' . $this->svn_repository_path);
if (!is_dir($this->svn_repository_path)) { if (!is_dir($this->svn_repository_path)) {
$data['status'] = 0; $data['status'] = 0;
$data['message'] = '安装失败 创建目录失败'; $data['message'] = '安装失败 创建目录失败';
@ -249,19 +249,19 @@ class Svnserve extends Controller
} }
//通过ps auxf|grep -v "grep"|grep svnserve和判断文件/usr/bin/svnserve是否存在这两方面来同时判断 如果没有安装过则进行安装 //通过ps auxf|grep -v "grep"|grep svnserve和判断文件/usr/bin/svnserve是否存在这两方面来同时判断 如果没有安装过则进行安装
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
//yum安装 //yum安装
parent::RequestReplyExec("yum install -y subversion"); RequestReplyExec("yum install -y subversion");
sleep(1); sleep(1);
//通常cp的别名为cp -i ,取消别名 //通常cp的别名为cp -i ,取消别名
parent::RequestReplyExec("alias cp='cp'"); RequestReplyExec("alias cp='cp'");
parent::RequestReplyExec('cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak'); RequestReplyExec('cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak');
//更改存储库位置 将配置文件/etc/sysconfig/svnserve中的/var/svn/更换为svn仓库目录 //更改存储库位置 将配置文件/etc/sysconfig/svnserve中的/var/svn/更换为svn仓库目录
parent::RequestReplyExec('sed -i \'s/\/var\/svn/' . str_replace('/', '\/', $this->svn_repository_path) . '/g\'' . ' /etc/sysconfig/svnserve'); RequestReplyExec('sed -i \'s/\/var\/svn/' . str_replace('/', '\/', $this->svn_repository_path) . '/g\'' . ' /etc/sysconfig/svnserve');
//设置存储密码选项 将以下内容写入文件/etc/subversion/servers servers文件不存在则创建 //设置存储密码选项 将以下内容写入文件/etc/subversion/servers servers文件不存在则创建
/** /**
@ -269,16 +269,16 @@ class Svnserve extends Controller
* [global] * [global]
* store-plaintext-passwords = yes * store-plaintext-passwords = yes
*/ */
parent::RequestReplyExec("touch /etc/subversion/servers"); RequestReplyExec("touch /etc/subversion/servers");
$con = "[groups]\n[global]\nstore-plaintext-passwords = yes\n"; $con = "[groups]\n[global]\nstore-plaintext-passwords = yes\n";
parent::RequestReplyExec('echo \'' . $con . '\' > /etc/subversion/servers'); RequestReplyExec('echo \'' . $con . '\' > /etc/subversion/servers');
parent::RequestReplyExec("systemctl enable svnserve.service"); RequestReplyExec("systemctl enable svnserve.service");
parent::RequestReplyExec("systemctl start svnserve.service"); RequestReplyExec("systemctl start svnserve.service");
$this->Firewall->SetFirewallPolicy(["port" => $this->svn_port, "type" => "add"]); $this->Firewall->SetFirewallPolicy(["port" => $this->svn_port, "type" => "add"]);
$this->Firewall->SetFirewallPolicy(["port" => $this->http_port, "type" => "add"]); $this->Firewall->SetFirewallPolicy(["port" => $this->http_port, "type" => "add"]);
parent::RequestReplyExec('setenforce 0'); RequestReplyExec('setenforce 0');
parent::RequestReplyExec("sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"); RequestReplyExec("sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config");
$data['status'] = 1; $data['status'] = 1;
$data['message'] = '安装服务成功'; $data['message'] = '安装服务成功';
@ -296,22 +296,22 @@ class Svnserve extends Controller
//清空表数据 //清空表数据
$this->TruncateTable(); $this->TruncateTable();
parent::RequestReplyExec('systemctl stop svnserve'); RequestReplyExec('systemctl stop svnserve');
sleep(2); sleep(2);
parent::RequestReplyExec('systemctl disable svnserve'); RequestReplyExec('systemctl disable svnserve');
sleep(2); sleep(2);
parent::RequestReplyExec('yum remove -y subversion'); RequestReplyExec('yum remove -y subversion');
sleep(2); sleep(2);
parent::RequestReplyExec('yum remove -y subversion'); RequestReplyExec('yum remove -y subversion');
sleep(2); sleep(2);
parent::RequestReplyExec('yum remove -y subversion'); RequestReplyExec('yum remove -y subversion');
sleep(2); sleep(2);
parent::RequestReplyExec('rm -f /etc/subversion/servers'); RequestReplyExec('rm -f /etc/subversion/servers');
parent::RequestReplyExec('rm -rf /etc/subversion'); RequestReplyExec('rm -rf /etc/subversion');
parent::RequestReplyExec('rm -rf /usr/bin/svnserve'); // RequestReplyExec('rm -rf /usr/bin/svnserve'); //
//清除yum缓存 //清除yum缓存
parent::RequestReplyExec('yum clean all'); RequestReplyExec('yum clean all');
//is_dir的结果会被缓存,所以需要清除缓存 //is_dir的结果会被缓存,所以需要清除缓存
clearstatcache(); clearstatcache();
@ -515,14 +515,14 @@ class Svnserve extends Controller
} }
//创建仓库 //创建仓库
//解决创建中文仓库乱码问题 //解决创建中文仓库乱码问题
parent::RequestReplyExec('export LC_CTYPE=en_US.UTF-8 && svnadmin create ' . $this->svn_repository_path . '/' . $repository_name); RequestReplyExec('export LC_CTYPE=en_US.UTF-8 && svnadmin create ' . $this->svn_repository_path . '/' . $repository_name);
//判断是否创建成功 //判断是否创建成功
if (!is_dir($this->svn_repository_path . '/' . $repository_name)) { if (!is_dir($this->svn_repository_path . '/' . $repository_name)) {
$data['status'] = 0; $data['status'] = 0;
$data['message'] = '添加仓库失败'; $data['message'] = '添加仓库失败';
return $data; return $data;
} }
parent::RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path); RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path);
//将新建仓库目录下的conf/svnserve.conf做以下修改, //将新建仓库目录下的conf/svnserve.conf做以下修改,
/* /*
@ -530,12 +530,12 @@ class Svnserve extends Controller
* 取消注释# password-db = passwd所在行 * 取消注释# password-db = passwd所在行
* 取消注释# authz-db = authz所在行 * 取消注释# authz-db = authz所在行
*/ */
parent::RequestReplyExec("sed -i 's/# anon-access = read/anon-access = none/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf"); RequestReplyExec("sed -i 's/# anon-access = read/anon-access = none/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf");
parent::RequestReplyExec("sed -i 's/# password-db = passwd/password-db = passwd/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf"); RequestReplyExec("sed -i 's/# password-db = passwd/password-db = passwd/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf");
parent::RequestReplyExec("sed -i 's/# authz-db = authz/authz-db = authz/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf"); RequestReplyExec("sed -i 's/# authz-db = authz/authz-db = authz/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf");
$this->InitRepositoryConfFile($repository_name); $this->InitRepositoryConfFile($repository_name);
parent::RequestReplyExec('setenforce 0'); RequestReplyExec('setenforce 0');
if (!$this->InsertRepositoryTable($repository_name)) { if (!$this->InsertRepositoryTable($repository_name)) {
$data['status'] = 0; $data['status'] = 0;
@ -581,7 +581,7 @@ class Svnserve extends Controller
$data['message'] = '失败,项目不存在'; $data['message'] = '失败,项目不存在';
return $data; return $data;
} }
parent::RequestReplyExec('rm -rf ' . $this->svn_repository_path . '/' . $repository_name); RequestReplyExec('rm -rf ' . $this->svn_repository_path . '/' . $repository_name);
//检查是否删除成功 //检查是否删除成功
if (!is_dir($this->svn_repository_path . '/' . $repository_name)) { if (!is_dir($this->svn_repository_path . '/' . $repository_name)) {
@ -669,7 +669,7 @@ class Svnserve extends Controller
} }
} }
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz'); RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz');
$data['status'] = 1; $data['status'] = 1;
$data['message'] = '账户授权成功'; $data['message'] = '账户授权成功';
@ -707,9 +707,9 @@ class Svnserve extends Controller
return $data; return $data;
} }
//修改仓库文件夹的目录 //修改仓库文件夹的目录
parent::RequestReplyExec('mv ' . $this->svn_repository_path . '/' . $old_repository_name . ' ' . $this->svn_repository_path . '/' . $new_repository_name); RequestReplyExec('mv ' . $this->svn_repository_path . '/' . $old_repository_name . ' ' . $this->svn_repository_path . '/' . $new_repository_name);
// //修改authz文件中的仓库名称 // //修改authz文件中的仓库名称
// parent::RequestReplyExec('sed -i \'s/' . $old_repository_name . '/' . $new_repository_name . '/g\' ' . SVN_CONF_PATH . '/authz'); // RequestReplyExec('sed -i \'s/' . $old_repository_name . '/' . $new_repository_name . '/g\' ' . SVN_CONF_PATH . '/authz');
if (!$this->UpdateRepositoryName($old_repository_name, $new_repository_name)) { if (!$this->UpdateRepositoryName($old_repository_name, $new_repository_name)) {
$data['status'] = 0; $data['status'] = 0;
@ -887,7 +887,7 @@ class Svnserve extends Controller
//写入文件 //写入文件
array_push($file_content, $account . ' = ' . $passwd . "\n"); array_push($file_content, $account . ' = ' . $passwd . "\n");
$file_content = implode($file_content); $file_content = implode($file_content);
parent::RequestReplyExec('echo \'' . $file_content . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); RequestReplyExec('echo \'' . $file_content . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
$data['status'] = 1; $data['status'] = 1;
$data['message'] = '添加账户成功'; $data['message'] = '添加账户成功';
@ -930,7 +930,7 @@ class Svnserve extends Controller
} }
} }
$con = implode($file_content); $con = implode($file_content);
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
//删除authz文件中的账号 //删除authz文件中的账号
$file = fopen($this->svn_repository_path . '/' . $repository_name . '/conf/authz', "r") or exit("无法打开文件!"); $file = fopen($this->svn_repository_path . '/' . $repository_name . '/conf/authz', "r") or exit("无法打开文件!");
@ -949,7 +949,7 @@ class Svnserve extends Controller
} }
} }
$con = implode($file_content); $con = implode($file_content);
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz'); RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz');
$data['status'] = 1; $data['status'] = 1;
$data['message'] = '删除账户成功'; $data['message'] = '删除账户成功';
@ -995,7 +995,7 @@ class Svnserve extends Controller
} }
} }
$con = implode($file_content); $con = implode($file_content);
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
$data['status'] = 1; $data['status'] = 1;
$data['message'] = '修改成功'; $data['message'] = '修改成功';
@ -1006,7 +1006,7 @@ class Svnserve extends Controller
function GetSvnserveStatus($requestPayload) function GetSvnserveStatus($requestPayload)
{ {
//是否安装服务 //是否安装服务
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
$info = array(); $info = array();
$info['status'] = '未安装'; //未安装 $info['status'] = '未安装'; //未安装
@ -1031,7 +1031,7 @@ class Svnserve extends Controller
return $data; return $data;
} }
//是否启动 //是否启动
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && file_exists('/usr/bin/svnserve')) {
$info = array(); $info = array();
$info['status'] = '已停止'; //svn服务未启动 $info['status'] = '已停止'; //svn服务未启动
@ -1068,13 +1068,13 @@ class Svnserve extends Controller
switch ($action) { switch ($action) {
case 'startSvn': case 'startSvn':
parent::RequestReplyExec('systemctl start svnserve'); RequestReplyExec('systemctl start svnserve');
break; break;
case 'restartSvn': case 'restartSvn':
parent::RequestReplyExec('systemctl restart svnserve'); RequestReplyExec('systemctl restart svnserve');
break; break;
case 'stopSvn': case 'stopSvn':
parent::RequestReplyExec('systemctl stop svnserve'); RequestReplyExec('systemctl stop svnserve');
break; break;
} }
@ -1104,7 +1104,7 @@ class Svnserve extends Controller
private function CheckSvnserveStatus() private function CheckSvnserveStatus()
{ {
//是否安装服务 //是否安装服务
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) {
$data['status'] = 0; $data['status'] = 0;
$data['code'] = '00'; $data['code'] = '00';
@ -1119,7 +1119,7 @@ class Svnserve extends Controller
return $data; return $data;
} }
//是否启动 //是否启动
$info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); $info = RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve');
if ($info == ISNULL && file_exists('/usr/bin/svnserve')) { if ($info == ISNULL && file_exists('/usr/bin/svnserve')) {
$data['status'] = 0; $data['status'] = 0;
$data['code'] = '01'; $data['code'] = '01';
@ -1192,7 +1192,7 @@ class Svnserve extends Controller
* root=rw * root=rw
*/ */
$con = "[aliases]\n\n[groups]\n\n[/]\nroot = rw"; $con = "[aliases]\n\n[groups]\n\n[/]\nroot = rw";
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz'); RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/authz');
//将以下内容写入passwd文件 //将以下内容写入passwd文件
/* /*
* [users] * [users]
@ -1200,7 +1200,7 @@ class Svnserve extends Controller
*/ */
$pass = trim($this->GetInitPasswd(16)); $pass = trim($this->GetInitPasswd(16));
$con = "[users]\nroot = " . $pass . "\n"; $con = "[users]\nroot = " . $pass . "\n";
parent::RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd'); RequestReplyExec('echo \'' . $con . '\' > ' . $this->svn_repository_path . '/' . $repository_name . '/conf/passwd');
} }
//向仓库表中写入仓库信息 //向仓库表中写入仓库信息

13
02.php/app/core/controller.class.php

@ -18,8 +18,8 @@ require_once BASE_PATH . '/app/controller/system.class.php';
require_once BASE_PATH . '/app/controller/user.class.php'; require_once BASE_PATH . '/app/controller/user.class.php';
//require function //require function
require_once BASE_PATH . '/app/function/detect.function.php';
require_once BASE_PATH . '/app/function/token.function.php'; require_once BASE_PATH . '/app/function/token.function.php';
require_once BASE_PATH . '/app/function/socket.function.php';
class Controller class Controller
{ {
@ -46,15 +46,4 @@ class Controller
); );
return $data; return $data;
} }
//与守护进程通信
final function RequestReplyExec($shell)
{
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("error:" . socket_strerror(socket_last_error()));
$server = socket_connect($socket, IPC_ADDRESS, IPC_PORT);
socket_write($socket, $shell);
$reply = socket_read($socket, SOCKET_READ_LENGTH);
socket_close($socket);
return $reply;
}
} }

37
02.php/app/function/socket.function.php

@ -0,0 +1,37 @@
<?php
//与守护进程通信
function RequestReplyExec($shell)
{
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("error:" . socket_strerror(socket_last_error()));
$server = socket_connect($socket, IPC_ADDRESS, IPC_PORT);
socket_write($socket, $shell);
$reply = socket_read($socket, SOCKET_READ_LENGTH);
socket_close($socket);
return $reply;
}
/**
* 守护进程状态探测
* 0 超时
* 1 打开
* 2 关闭
*/
function DetectState()
{
$sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
socket_set_nonblock($sock);
socket_connect($sock, IPC_ADDRESS, IPC_PORT);
socket_set_block($sock);
$v = array($sock);
$state = @socket_select($r = $v, $w = $v, $f = $v, 5);
socket_close($sock);
return $state;
}

15
02.php/config/config.php

@ -50,6 +50,21 @@ define("SOCKET_LISTEN_BACKLOG", 2000);
*/ */
define('VERSION', '2.1.2'); define('VERSION', '2.1.2');
/**
* 当前程序支持的最低PHP版本
*/
define('Required_PHP_VERSION', '7.3.0');
/**
* 需要解除禁止的函数
*/
define('NEEDED_FUNCTION', array(
'pcntl_fork',
'pcntl_signal',
'pcntl_wait',
'shell_exec'
));
/** /**
* 升级服务器地址 * 升级服务器地址
* 用户请不要自行修改 以免影响后续升级检测 * 用户请不要自行修改 以免影响后续升级检测

55
02.php/server/svnadmind.php

@ -28,17 +28,17 @@ class Daemon
{ {
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid < 0) { if ($pid < 0) {
exit("pcntl_fork 错误"); exit('pcntl_fork 错误');
} elseif ($pid > 0) { } elseif ($pid > 0) {
exit(); exit();
} }
$sid = posix_setsid(); $sid = posix_setsid();
if (!$sid) { if (!$sid) {
exit("posix_setsid 错误"); exit('posix_setsid 错误');
} }
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid < 0) { if ($pid < 0) {
exit("pcntl_fork 错误"); exit('pcntl_fork 错误');
} elseif ($pid > 0) { } elseif ($pid > 0) {
exit(); exit();
} }
@ -60,10 +60,10 @@ class Daemon
private function init_socket() private function init_socket()
{ {
//创建套接字 //创建套接字
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or die("socket_create 错误"); $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP) or exit('socket_create 错误');
//绑定地址和端口 //绑定地址和端口
socket_bind($socket, IPC_ADDRESS, IPC_PORT) or die("socket_bind 错误"); socket_bind($socket, IPC_ADDRESS, IPC_PORT) or exit('socket_bind 错误');
//设置可重复使用端口号 //设置可重复使用端口号
socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1); socket_set_option($socket, SOL_SOCKET, SO_REUSEADDR, 1);
@ -75,14 +75,14 @@ class Daemon
//非阻塞式回收僵尸进程 //非阻塞式回收僵尸进程
pcntl_wait($status, WNOHANG); pcntl_wait($status, WNOHANG);
$clien = socket_accept($socket) or die("socket_accept 错误"); $clien = socket_accept($socket) or exit('socket_accept 错误');
//非阻塞式回收僵尸进程 //非阻塞式回收僵尸进程
pcntl_wait($status, WNOHANG); pcntl_wait($status, WNOHANG);
$pid = pcntl_fork(); $pid = pcntl_fork();
if ($pid == -1) { if ($pid == -1) {
die('pcntl_fork 错误'); exit('pcntl_fork 错误');
} else if ($pid == 0) { } else if ($pid == 0) {
$this->handle_request($clien); $this->handle_request($clien);
} else { } else {
@ -90,6 +90,44 @@ class Daemon
} }
} }
private function check_sys_type()
{
if (PHP_OS != 'Linux') {
exit("启动失败 \n当前操作系统不为Linux\n");
}
if (file_exists('/etc/redhat-release')) {
$info = file_get_contents('/etc/redhat-release');
if (!strstr($info, 'CentOS') && (strstr($info, '8.') || strstr($info, '7.'))) {
exit("启动失败 \n仅支持CentOS 7 和 CentOS8 系统\n");
}
return;
}
exit("启动失败 \n不支持当前操作系统\n");
}
private function check_php_version()
{
if (PHP_VERSION < Required_PHP_VERSION) {
echo "启动失败 \n当前的PHP版本为 " . PHP_VERSION . " 最低的PHP版本要求为 " . Required_PHP_VERSION . "\n";
exit();
}
}
private function check_disabled_function()
{
$disabled_function = explode(',', ini_get('disable_functions'));
$needed_function = NEEDED_FUNCTION;
foreach ($needed_function as $key => $value) {
if (!in_array($value, $disabled_function)) {
unset($needed_function[$key]);
}
}
if (!empty($needed_function)) {
echo "启动失败 \n需要的以下PHP函数被禁用:\n" . implode("\n", $needed_function) . "\n";
exit();
}
}
private function handle_request($clien) private function handle_request($clien)
{ {
//接收客户端发送的数据 //接收客户端发送的数据
@ -157,6 +195,9 @@ class Daemon
public function run($argv) public function run($argv)
{ {
$this->check_sys_type();
$this->check_php_version();
$this->check_disabled_function();
if (isset($argv[1])) { if (isset($argv[1])) {
$this->state = $argv[1]; $this->state = $argv[1];
if (!in_array($this->state, $this->cmdlist)) { if (!in_array($this->state, $this->cmdlist)) {

Loading…
Cancel
Save