该系统为使用PHP开发的基于web的Subversion(SVN)服务器端管理工具。支持功能:SVN仓库管理、SVN用户管理、SVN分组管理、目录授权、目录浏览、Hooks管理、在线dump备份、在线备份恢复、SVN用户禁用、服务器状态管理、日志管理、消息通知、更新检测...
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

145 lines
4.4 KiB

<?php
declare(strict_types=1);
/*
* 与防火墙操作相关
*/
class Firewall extends Controller {
function __construct() {
/*
* 避免子类的构造函数覆盖父类的构造函数
*/
parent::__construct();
/*
* 其它自定义操作
*/
}
//高级设置 使svnserve服务的端口通过防火墙
function SetFirewallStatus($requestPayload) {
$action = $requestPayload['action'];
if (empty($action)) {
$data['status'] = 0;
$data['message'] = '参数不完整';
return $data;
}
switch ($action) {
case 'startFirewall':
FunRequestReplyExec('systemctl start firewalld');
FunRequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
FunRequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
FunRequestReplyExec('firewall-cmd --reload');
break;
case 'restartFirewall':
FunRequestReplyExec('systemctl restart firewalld');
FunRequestReplyExec('firewall-cmd --zone=public --add-port=80/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
FunRequestReplyExec('firewall-cmd --zone=public --add-port=3690/tcp --permanent'); //启动的同时将80加入 使得web服务正常运行
FunRequestReplyExec('firewall-cmd --reload');
break;
case 'stopFirewall':
FunRequestReplyExec('systemctl stop firewalld');
break;
}
sleep(1);
$data['status'] = 1;
$data['message'] = '成功';
return $data;
}
//设置防火墙规则
function SetFirewallPolicy($requestPayload) {
$protocal = 'tcp';
$port = $requestPayload['port'];
$type = $requestPayload['type'] ? 'add' : 'remove';
if (empty($protocal) || empty($port) || empty($type)) {
$data['status'] = 0;
$data['message'] = '参数不完整';
return $data;
}
FunRequestReplyExec('firewall-cmd --zone=public --' . $type . '-port=' . $port . '/' . $protocal . ' --permanent');
FunRequestReplyExec('firewall-cmd --reload');
sleep(1);
$data['status'] = 1;
$data['message'] = '成功';
return $data;
}
//获取防火墙规则
function GetFirewallPolicy($requestPayload) {
//获取80 443 3690是否加入防火墙
$info = FunRequestReplyExec('ps auxf|grep -v "grep"|grep firewalld');
if ($info == ISNULL) {
$info = [];
$info['svn'] = false;
$info['http'] = false;
$info['https'] = false;
$data['status'] = 1;
$data['message'] = '成功';
$data['data'] = $info;
return $data;
}
$info = [];
$result = trim(FunRequestReplyExec('firewall-cmd --query-port=80/tcp'));
if ($result == 'yes') {
$info['http'] = true;
} else {
$info['http'] = false;
}
$result = trim(FunRequestReplyExec('firewall-cmd --query-port=443/tcp'));
if ($result == 'yes') {
$info['https'] = true;
} else {
$info['https'] = false;
}
$result = trim(FunRequestReplyExec('firewall-cmd --query-port=3690/tcp'));
if ($result == 'yes') {
$info['svn'] = true;
} else {
$info['svn'] = false;
}
$data['status'] = 1;
$data['message'] = '成功';
$data['data'] = $info;
return $data;
}
//获取防火墙状态
function GetFirewallStatus($requestPayload) {
$info = FunRequestReplyExec('ps auxf|grep -v "grep"|grep firewalld');
if ($info == ISNULL) {
$info = [];
$info['status'] = '已停止';
$info['type'] = 'warning';
$data['status'] = 1;
$data['message'] = '成功';
$data['data'] = $info;
return $data;
}
$info = [];
$info['status'] = '运行中';
$info['type'] = 'success';
$data['status'] = 1;
$data['message'] = '成功';
$data['data'] = $info;
return $data;
}
}