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 ());
}