Sophos XGAPI
1.0.0
Sophos XGAPI是一个用于请求 Sophos XG 防火墙的 PHP 库。该库可以:
您可以在 Sophos 网站上找到所有支持的实体的名称。
composer require benclerc/sophos-xgapi
安装库。require 'vendor/autoload.php';
。$configFirewall = new SophosConfig('123.123.123.123', 'admin', 'password');
。$firewall = new SophosXGAPI($configFirewall);
。$hosts = $firewall->get(['IPHost']);
。 您可以在此处找到完整的文档。
该Config类用于准备实例化和使用XGAPI类所需的强制配置信息。在构造函数中,您必须传递:
可选参数:
setTimeout()
来改变。setSSLVerifyPeer()
进行更改。setSSLVerifyHost()
进行更改。例子 :
// Basic configuration
$ configFirewall = new Sophos Config ( ' 123.123.123.123 ' , ' admin ' , ' password ' );
// Configuration for very slow firewalls/long requests
$ configFirewall = new Sophos Config ( ' 123.123.123.123 ' , ' admin ' , ' password ' );
$ configFirewall -> setTimeout ( 20000 );
// Unsecure configuration
$ configFirewall = new Sophos Config ( ' 123.123.123.123 ' , ' admin ' , ' password ' );
$ configFirewall -> setSSLVerifyPeer ( FALSE )-> setSSLVerifyHost ( FALSE );
$ firewall = new Sophos XGAPI ( $ configFirewall );
此方法用于从防火墙检索数据。您必须设置要检索的一个或多个实体,并且可以为每个实体设置一个过滤器。请注意,如果您为同一实体设置多个过滤器,它们加起来就像“OR”而不是“AND”。请注意,并非所有属性都是可过滤的,请参阅 Sophos 文档。可用的过滤标准:
例子:
// All IPHost
$ entities = [ ' IPHost ' ];
// IPHost named 'IP_TEST'
$ entities = [
' IPHost ' =>[
[ ' Name ' , ' = ' , ' IP_TEST ' ]
]
];
// All IPHost with 'IP_' in the name OR of type 'Network'
$ entities = [
' IPHost ' =>[
[ ' Name ' , ' like ' , ' IP_ ' ],
[ ' HostType ' , ' = ' , ' Network ' ]
]
];
// All IPHost and network interface named LAN
$ entities = [
' IPHost ' ,
' Interface ' =>[
[ ' Name ' , ' = ' , ' LAN ' ]
]
];
try {
$ result = $ firewall -> get ( $ entites );
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}
该方法用于在防火墙上设置数据。您必须为要添加的每个实体设置所有强制属性。
例子:
// Add 1 IPv4 hosts
$ entities = [
' IPHost ' => [
[
' Name ' => ' IP_TEST ' ,
' IPFamily ' => ' IPv4 ' ,
' HostType ' => ' IP ' ,
' HostGroupList ' =>[
' HostGroup ' => ' IP-GRP_TEST '
],
' IPAddress ' => ' 10.11.12.13 ' ,
' Subnet ' => ' 255.255.255.0 '
]
]
];
// Add 2 IPv4 hosts
$ entities = [
' IPHost ' => [
[
' Name ' => ' IP_TEST ' ,
' IPFamily ' => ' IPv4 ' ,
' HostType ' => ' IP ' ,
' HostGroupList ' =>[
' HostGroup ' => ' IP-GRP_TEST '
],
' IPAddress ' => ' 10.11.12.13 ' ,
' Subnet ' => ' 255.255.255.0 '
],
[
' Name ' => ' IP_TEST2 ' ,
' IPFamily ' => ' IPv4 ' ,
' HostType ' => ' IP ' ,
' HostGroupList ' =>[
' HostGroup ' => ' IP-GRP_TEST '
],
' IPAddress ' => ' 10.11.12.14 ' ,
' Subnet ' => ' 255.255.255.0 '
]
]
];
// Add 2 IPv4 hosts and 1 QOS policy
$ entities = [
' IPHost ' => [
[
' Name ' => ' IP_TEST ' ,
' IPFamily ' => ' IPv4 ' ,
' HostType ' => ' IP ' ,
' HostGroupList ' =>[
' HostGroup ' => ' IP-GRP_TEST '
],
' IPAddress ' => ' 10.11.12.13 ' ,
' Subnet ' => ' 255.255.255.0 '
],
[
' Name ' => ' IP_TEST2 ' ,
' IPFamily ' => ' IPv4 ' ,
' HostType ' => ' IP ' ,
' HostGroupList ' =>[
' HostGroup ' => ' IP-GRP_TEST '
],
' IPAddress ' => ' 10.11.12.14 ' ,
' Subnet ' => ' 255.255.255.0 '
]
],
' QoSPolicy ' =>[
[
' Name ' => ' QOS_TEST ' ,
' PolicyBasedOn ' => ' FirewallRule ' ,
' BandwidthUsageType ' => ' Shared ' ,
' ImplementationOn ' => ' Total ' ,
' PolicyType ' => ' Strict ' ,
' Priority ' => ' Normal4 ' ,
' TotalBandwidth ' => ' 6875 '
]
]
];
try {
$ result = $ firewall -> set ( $ entites );
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}
此方法用于从防火墙中删除数据。您必须设置要删除的实体以及要删除的对象的名称,除了对象名称之外不能删除任何其他内容。
例子:
// Remove the IPv4 host 'IP_TEST'
$ entities = [
' IPHost ' => [
' IP_TEST '
]
];
// Remove the IPv4 hosts 'IP_TEST' and 'IP_TEST2'
$ entities = [
' IPHost ' => [
' IP_TEST ' ,
' IP_TEST2 '
]
];
// Remove the IPv4 hosts 'IP_TEST' and 'IP_TEST2' and QOS policy 'QOS_TEST'
$ entities = [
' IPHost ' => [
' IP_TEST ' ,
' IP_TEST2 '
],
' QoSPolicy ' => [
' QOS_TEST '
]
];
try {
$ result = $ firewall -> remove ( $ entites );
} catch ( Exception $ e ) {
echo ( ' Handle error : ' . $ e -> getMessage ());
}