From d50428545a2f4102c7c899fd94a2ae6cf5e9566a Mon Sep 17 00:00:00 2001 From: witersen <1801168257@qq.com> Date: Fri, 10 Dec 2021 16:50:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=A6=81=E7=94=A8=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=A3=80=E6=9F=A5=E5=92=8C=E6=93=8D=E4=BD=9C=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=B1=BB=E5=9E=8B=E6=A3=80=E6=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 02.php/app/controller/config.class.php | 14 ++-- 02.php/app/controller/crontab.class.php | 18 ++--- 02.php/app/controller/firewall.class.php | 32 ++++----- 02.php/app/controller/svnserve.class.php | 90 ++++++++++++------------ 02.php/app/core/controller.class.php | 13 +--- 02.php/app/function/socket.function.php | 37 ++++++++++ 02.php/config/config.php | 15 ++++ 02.php/server/svnadmind.php | 55 +++++++++++++-- 8 files changed, 178 insertions(+), 96 deletions(-) create mode 100644 02.php/app/function/socket.function.php diff --git a/02.php/app/controller/config.class.php b/02.php/app/controller/config.class.php index 2861550..2268395 100644 --- a/02.php/app/controller/config.class.php +++ b/02.php/app/controller/config.class.php @@ -102,8 +102,8 @@ class Config extends Controller { //更改版本库父文件夹后触发的操作 private function UpdateRepositoryParentPath($old_path, $new_path) { - parent::RequestReplyExec("mkdir $new_path"); - $info = parent::RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); + RequestReplyExec("mkdir $new_path"); + $info = RequestReplyExec('ps auxf|grep -v "grep"|grep svnserve'); if ($info == ISNULL && !file_exists('/usr/bin/svnserve')) { /* * 没有安装过svn服务 @@ -116,7 +116,7 @@ class Config extends Controller { $file_arr2 = scandir($old_path . '/' . $file_item); foreach ($file_arr2 as $file_item2) { 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服务 */ //停止服务 - parent::RequestReplyExec('systemctl stop svnserve'); + RequestReplyExec('systemctl stop svnserve'); //移动仓库 $file_arr = scandir($old_path); foreach ($file_arr as $file_item) { @@ -151,16 +151,16 @@ class Config extends Controller { $file_arr2 = scandir($old_path . '/' . $file_item); foreach ($file_arr2 as $file_item2) { 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_content = array(); diff --git a/02.php/app/controller/crontab.class.php b/02.php/app/controller/crontab.class.php index d5d7274..dba0efd 100644 --- a/02.php/app/controller/crontab.class.php +++ b/02.php/app/controller/crontab.class.php @@ -57,7 +57,7 @@ class Crontab extends Controller { $cron_path = "/var/spool/cron/root"; //检查计划任务文件是否存在 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; - parent::RequestReplyExec("touch $shell_path"); - parent::RequestReplyExec("chmod 755 $shell_path"); + RequestReplyExec("touch $shell_path"); + RequestReplyExec("chmod 755 $shell_path"); //获取执行周期 $cycle = $this->EnCrontabFormat($cycle_type, $week, $hour, $minute); @@ -93,20 +93,20 @@ shell; shell; } else { - parent::RequestReplyExec("rm -f $shell_path"); + RequestReplyExec("rm -f $shell_path"); $data['status'] = 0; $data['message'] = '失败 备份类型错误'; return $data; } //向脚本文件并写入内容 - parent::RequestReplyExec("echo '$shell_content' > $shell_path"); + RequestReplyExec("echo '$shell_content' > $shell_path"); //将周期+脚本文件路径以追加方式写入计划任务文件 /var/spool/cron/root //$content = $cycle . ' bash ' . $shell_path; $content = $cycle . ' bash ' . $shell_path; - parent::RequestReplyExec("echo '$content' >> $cron_path"); - parent::RequestReplyExec("systemctl restart crond"); + RequestReplyExec("echo '$content' >> $cron_path"); + RequestReplyExec("systemctl restart crond"); //将信息写入数据库表 $this->database_medoo->insert("crontab", [ @@ -129,9 +129,9 @@ shell; function DeleteCrontab($requestPayload) { $sign = $requestPayload["sign"]; //从计划任务文件删除 - parent::RequestReplyExec("sed -i '/$sign/d' /var/spool/cron/root"); + RequestReplyExec("sed -i '/$sign/d' /var/spool/cron/root"); //从web路径删除 - parent::RequestReplyExec("rm -f " . BASE_PATH . '/data/crond/' . $sign); + RequestReplyExec("rm -f " . BASE_PATH . '/data/crond/' . $sign); //从数据库删除 $this->database_medoo->delete("crontab", [ "AND" => [ diff --git a/02.php/app/controller/firewall.class.php b/02.php/app/controller/firewall.class.php index bf56a3e..3c0ed96 100644 --- a/02.php/app/controller/firewall.class.php +++ b/02.php/app/controller/firewall.class.php @@ -40,19 +40,19 @@ class Firewall extends Controller { switch ($action) { case 'startFirewall': - parent::RequestReplyExec('systemctl start firewalld'); - parent::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服务正常运行 - parent::RequestReplyExec('firewall-cmd --reload'); + RequestReplyExec('systemctl start firewalld'); + RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 + RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 + RequestReplyExec('firewall-cmd --reload'); break; case 'restartFirewall': - parent::RequestReplyExec('systemctl restart firewalld'); - parent::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服务正常运行 - parent::RequestReplyExec('firewall-cmd --reload'); + RequestReplyExec('systemctl restart firewalld'); + RequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 + RequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行 + RequestReplyExec('firewall-cmd --reload'); break; case 'stopFirewall': - parent::RequestReplyExec('systemctl stop firewalld'); + RequestReplyExec('systemctl stop firewalld'); break; } @@ -74,8 +74,8 @@ class Firewall extends Controller { $data['message'] = '参数不完整'; return $data; } - parent::RequestReplyExec('firewall-cmd --zone=public --' . $type . '-port=' . $port . '/' . $protocal . ' --permanent'); - parent::RequestReplyExec('firewall-cmd --reload'); + RequestReplyExec('firewall-cmd --zone=public --' . $type . '-port=' . $port . '/' . $protocal . ' --permanent'); + RequestReplyExec('firewall-cmd --reload'); sleep(1); @@ -87,7 +87,7 @@ class Firewall extends Controller { //获取防火墙规则 function GetFirewallPolicy($requestPayload) { //获取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) { $info = array(); $info['svn'] = false; @@ -101,21 +101,21 @@ class Firewall extends Controller { } $info = array(); - $result = trim(parent::RequestReplyExec('firewall-cmd --query-port=80/tcp')); + $result = trim(RequestReplyExec('firewall-cmd --query-port=80/tcp')); if ($result == 'yes') { $info['http'] = true; } else { $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') { $info['https'] = true; } else { $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') { $info['svn'] = true; } else { @@ -130,7 +130,7 @@ class Firewall extends Controller { //获取防火墙状态 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) { $info = array(); $info['status'] = '已停止'; diff --git a/02.php/app/controller/svnserve.class.php b/02.php/app/controller/svnserve.class.php index ec9f6c0..9bc9548 100644 --- a/02.php/app/controller/svnserve.class.php +++ b/02.php/app/controller/svnserve.class.php @@ -80,7 +80,7 @@ class Svnserve extends Controller $data['message'] = '仓库不存在或文件损坏'; 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) { file_put_contents($this->svn_repository_path . '/' . $repository_name . '/' . 'hooks' . '/' . $value['value'], $value["shell"]); } @@ -241,7 +241,7 @@ class Svnserve extends Controller $data = array(); //创建svn仓库父目录 - parent::RequestReplyExec('mkdir -p ' . $this->svn_repository_path); + RequestReplyExec('mkdir -p ' . $this->svn_repository_path); if (!is_dir($this->svn_repository_path)) { $data['status'] = 0; $data['message'] = '安装失败 创建目录失败'; @@ -249,19 +249,19 @@ class Svnserve extends Controller } //通过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')) { //yum安装 - parent::RequestReplyExec("yum install -y subversion"); + RequestReplyExec("yum install -y subversion"); sleep(1); //通常cp的别名为cp -i ,取消别名 - parent::RequestReplyExec("alias cp='cp'"); - parent::RequestReplyExec('cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak'); + RequestReplyExec("alias cp='cp'"); + RequestReplyExec('cp -f /etc/sysconfig/svnserve /etc/sysconfig/svnserve.bak'); //更改存储库位置 将配置文件/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文件不存在则创建 /** @@ -269,16 +269,16 @@ class Svnserve extends Controller * [global] * store-plaintext-passwords = yes */ - parent::RequestReplyExec("touch /etc/subversion/servers"); + RequestReplyExec("touch /etc/subversion/servers"); $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"); - parent::RequestReplyExec("systemctl start svnserve.service"); + RequestReplyExec("systemctl enable svnserve.service"); + RequestReplyExec("systemctl start svnserve.service"); $this->Firewall->SetFirewallPolicy(["port" => $this->svn_port, "type" => "add"]); $this->Firewall->SetFirewallPolicy(["port" => $this->http_port, "type" => "add"]); - parent::RequestReplyExec('setenforce 0'); - parent::RequestReplyExec("sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"); + RequestReplyExec('setenforce 0'); + RequestReplyExec("sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config"); $data['status'] = 1; $data['message'] = '安装服务成功'; @@ -296,22 +296,22 @@ class Svnserve extends Controller //清空表数据 $this->TruncateTable(); - parent::RequestReplyExec('systemctl stop svnserve'); + RequestReplyExec('systemctl stop svnserve'); sleep(2); - parent::RequestReplyExec('systemctl disable svnserve'); + RequestReplyExec('systemctl disable svnserve'); sleep(2); - parent::RequestReplyExec('yum remove -y subversion'); + RequestReplyExec('yum remove -y subversion'); sleep(2); - parent::RequestReplyExec('yum remove -y subversion'); + RequestReplyExec('yum remove -y subversion'); sleep(2); - parent::RequestReplyExec('yum remove -y subversion'); + RequestReplyExec('yum remove -y subversion'); sleep(2); - parent::RequestReplyExec('rm -f /etc/subversion/servers'); - parent::RequestReplyExec('rm -rf /etc/subversion'); - parent::RequestReplyExec('rm -rf /usr/bin/svnserve'); // + RequestReplyExec('rm -f /etc/subversion/servers'); + RequestReplyExec('rm -rf /etc/subversion'); + RequestReplyExec('rm -rf /usr/bin/svnserve'); // //清除yum缓存 - parent::RequestReplyExec('yum clean all'); + RequestReplyExec('yum clean all'); //is_dir的结果会被缓存,所以需要清除缓存 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)) { $data['status'] = 0; $data['message'] = '添加仓库失败'; return $data; } - parent::RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path); + RequestReplyExec('chmod 777 -R ' . $this->svn_repository_path); //将新建仓库目录下的conf/svnserve.conf做以下修改, /* @@ -530,12 +530,12 @@ class Svnserve extends Controller * 取消注释# password-db = passwd所在行 * 取消注释# authz-db = authz所在行 */ - parent::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"); - 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/# anon-access = read/anon-access = none/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"); + RequestReplyExec("sed -i 's/# authz-db = authz/authz-db = authz/g' " . $this->svn_repository_path . "/" . $repository_name . "/conf/svnserve.conf"); $this->InitRepositoryConfFile($repository_name); - parent::RequestReplyExec('setenforce 0'); + RequestReplyExec('setenforce 0'); if (!$this->InsertRepositoryTable($repository_name)) { $data['status'] = 0; @@ -581,7 +581,7 @@ class Svnserve extends Controller $data['message'] = '失败,项目不存在'; 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)) { @@ -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['message'] = '账户授权成功'; @@ -707,9 +707,9 @@ class Svnserve extends Controller 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文件中的仓库名称 - // 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)) { $data['status'] = 0; @@ -887,7 +887,7 @@ class Svnserve extends Controller //写入文件 array_push($file_content, $account . ' = ' . $passwd . "\n"); $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['message'] = '添加账户成功'; @@ -930,7 +930,7 @@ class Svnserve extends Controller } } $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文件中的账号 $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); - 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['message'] = '删除账户成功'; @@ -995,7 +995,7 @@ class Svnserve extends Controller } } $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['message'] = '修改成功'; @@ -1006,7 +1006,7 @@ class Svnserve extends Controller 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')) { $info = array(); $info['status'] = '未安装'; //未安装 @@ -1031,7 +1031,7 @@ class Svnserve extends Controller 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')) { $info = array(); $info['status'] = '已停止'; //svn服务未启动 @@ -1068,13 +1068,13 @@ class Svnserve extends Controller switch ($action) { case 'startSvn': - parent::RequestReplyExec('systemctl start svnserve'); + RequestReplyExec('systemctl start svnserve'); break; case 'restartSvn': - parent::RequestReplyExec('systemctl restart svnserve'); + RequestReplyExec('systemctl restart svnserve'); break; case 'stopSvn': - parent::RequestReplyExec('systemctl stop svnserve'); + RequestReplyExec('systemctl stop svnserve'); break; } @@ -1104,7 +1104,7 @@ class Svnserve extends Controller 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')) { $data['status'] = 0; $data['code'] = '00'; @@ -1119,7 +1119,7 @@ class Svnserve extends Controller 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')) { $data['status'] = 0; $data['code'] = '01'; @@ -1192,7 +1192,7 @@ class Svnserve extends Controller * root=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文件 /* * [users] @@ -1200,7 +1200,7 @@ class Svnserve extends Controller */ $pass = trim($this->GetInitPasswd(16)); $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'); } //向仓库表中写入仓库信息 diff --git a/02.php/app/core/controller.class.php b/02.php/app/core/controller.class.php index 6ccea66..dad1aec 100644 --- a/02.php/app/core/controller.class.php +++ b/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 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/socket.function.php'; class Controller { @@ -46,15 +46,4 @@ class Controller ); 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; - } } diff --git a/02.php/app/function/socket.function.php b/02.php/app/function/socket.function.php new file mode 100644 index 0000000..5503f4f --- /dev/null +++ b/02.php/app/function/socket.function.php @@ -0,0 +1,37 @@ + 0) { exit(); } $sid = posix_setsid(); if (!$sid) { - exit("posix_setsid 错误"); + exit('posix_setsid 错误'); } $pid = pcntl_fork(); if ($pid < 0) { - exit("pcntl_fork 错误"); + exit('pcntl_fork 错误'); } elseif ($pid > 0) { exit(); } @@ -60,10 +60,10 @@ class Daemon 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); @@ -75,14 +75,14 @@ class Daemon //非阻塞式回收僵尸进程 pcntl_wait($status, WNOHANG); - $clien = socket_accept($socket) or die("socket_accept 错误"); + $clien = socket_accept($socket) or exit('socket_accept 错误'); //非阻塞式回收僵尸进程 pcntl_wait($status, WNOHANG); $pid = pcntl_fork(); if ($pid == -1) { - die('pcntl_fork 错误'); + exit('pcntl_fork 错误'); } else if ($pid == 0) { $this->handle_request($clien); } 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) { //接收客户端发送的数据 @@ -157,6 +195,9 @@ class Daemon public function run($argv) { + $this->check_sys_type(); + $this->check_php_version(); + $this->check_disabled_function(); if (isset($argv[1])) { $this->state = $argv[1]; if (!in_array($this->state, $this->cmdlist)) {