Firewall
The /firewall resource exposes the options from Admin > Security > GeoIP/Fail2Ban Filters, the allowed country list, and cached firewall status from the PBX nodes. It applies to the entire installation.
Authentication and application
Use a global API key and omit tenant. Full and read-only global keys can read configuration and status. Changes require a full global key. Tenant keys and extension Dial API Keys cannot use this resource.
Send the key using X-API-Key or Authorization: Bearer. The examples use fictional addresses and keys. Replace them with your own values.
Writes save the same database options as the web interface. The normal scheduled firewall processes apply them on the nodes. A successful save returns application: "scheduled"; it does not confirm that every node has applied the configuration. Check the cached status and warnings separately. The API does not execute an immediate firewall reload, restart, ban/unban, or GeoIP database download.
Routes
| Method | Path | Behavior |
|---|---|---|
| GET | /firewall | Read all supported options, selected countries, and the GeoIP warning flags shown on the Security page. |
| POST, PUT, PATCH | /firewall | Create or update supplied option overrides and optionally replace the selected countries. Unspecified fields are preserved for all three methods. |
| GET | /firewall/settings/{code} | Read one known option, its value and its reset default. |
| POST, PUT, PATCH | /firewall/settings/{code} | Set one option using an object containing only value. |
| DELETE | /firewall/settings/{code} | Reset that option to its web default. This does not delete the entire firewall configuration. |
| GET | /firewall/countries | List country codes and names, with an allowed boolean. |
| POST, PUT, PATCH | /firewall/countries | Replace the selection using {"countries":["IT","NL"]}. |
| DELETE | /firewall/countries | Clear the selected countries. |
| GET | /firewall/status | Read cached Fail2Ban and SIP rate status, including checker warnings, paginated by node. |
| GET | /firewall/status/{nodeId} | Read the same cached status for one PBX node. |
The compatibility form openapi.php?object=firewall reads configuration. Use action=status for status, action=countries for the country catalog, or action=settings&code=F2BBLOCKEDIP for one option.
Read and update options
curl -H 'X-API-Key: GLOBAL_API_KEY' \
'https://pbx.example.com/pbx/openapi.php/firewall'
curl -H 'X-API-Key: GLOBAL_API_KEY' \
'https://pbx.example.com/pbx/openapi.php/firewall/settings/F2BBLOCKEDIP'
curl -X PATCH \
-H 'X-API-Key: GLOBAL_API_KEY' \
-H 'Content-Type: application/json' \
--data '{"settings":{"F2BBLOCKEDIP":"203.0.113.10\n2001:db8::/32","FAIL2BAN":true,"F2BMAXATTEMPTS":5},"countries":["IT","NL"]}' \
'https://pbx.example.com/pbx/openapi.php/firewall'
The root request accepts either a settings object or the setting names directly, for example {"F2BBLOCKEDIP":"203.0.113.10"}. Do not supply the same option twice through different spellings or wrappers. Unknown options and attempts to write status fields are rejected.
Configuration responses contain settings and countries. Flag values use the stored "on" or empty-string form; numeric options are returned as strings. Missing options use the defaults listed below. Existing blank numeric options use the same display defaults as the web page.
Supported settings
| Code | Accepted value | Reset default |
|---|---|---|
GEOIPFILTER | Enable the full server country filter. | Off |
WEBGEOIPFILTER | Enable the web interface country filter. | Off |
FAIL2BAN | Enable VoIP Fail2Ban. | Off |
WEBFAIL2BAN | Enable web interface Fail2Ban. | Off |
F2BMAXATTEMPTS | Integer from 1 to 2147483647. | 5 |
F2BBANTIME | Seconds, from -1 to 2147483647. -1 represents a permanent ban. | 600 |
F2BFINDTIME | Seconds, from 1 to 2147483647. | 600 |
F2BNOTIFY | Notify ban activity. | Off |
F2BNOTIFYEMAIL | Notification email address or a list separated by commas, semicolons or whitespace. Lists are normalized to one comma-separated line. | Empty |
F2BNOTIFYSENDEREMAIL | One sender email address. | Empty |
F2BTRUSTCUSTOMHEADERS | Trust a custom client-IP header. Enable only behind a trusted reverse proxy that strips untrusted client-supplied headers. | Off |
F2BREVERSEPROXY | PHP server header name, for example HTTP_X_FORWARDED_FOR. Used when custom headers are trusted. | Empty |
F2BVOIPPORTS | Comma-separated ports, or an array of port numbers. Each port must be from 1 to 65535. | 5060,5061,5080,5081,5082 |
F2BWEBPORTS | The same port format. | 80,443 |
F2BSSHPORTS | The same port format. | 22 |
SIPRATELIMIT | Enable SIP rate limiting. | Off |
SIPPACKETSSEC | Integer from 1 to 2147483647. | 50 |
F2BALWAYSALLOWED | Whitelisted IPv4/IPv6 addresses or CIDR networks, as text or an array of strings. | Empty |
F2BTENANTWHITELIST | Autowhitelist from tenant IP restrictions. | Off |
F2BTENANTCONNWHITELIST | Autowhitelist from tenant registrations. | Off |
SIPEXPLICITALLOW | Allow SIP connections only from allowed IPs. | Off |
F2BCUSTOMRULES | IPv4 iptables rule arguments for the CustomRules chain, one rule per line, as on the web page. | Empty |
F2BCUSTOMRULES6 | IPv6 rule arguments for CustomRules, one per line. Applied only on nodes with IPv6 enabled. | Empty |
BLOCKSIPSCANNERS | Enable blocking of configured SIP scanner signatures. | Off |
SIPSCANNER | Scanner signatures, one per line. | Empty |
F2BBLOCKEDIP | Manually blocked IPv4/IPv6 addresses or CIDR networks, as text or an array of strings. | Empty |
Flags accept JSON booleans, 0/1, or the strings on, off, yes, no, 1, 0 and an empty string. A JSON null resets an option. Text network lists accept spaces, new lines, commas and semicolons; a # starts a comment. Pipes are not network separators. Extended text is limited to 1 MiB per option; ordinary settings use a 255-byte limit.
DELETE resets the option instead of removing required parameters from the generated jail configuration. Numeric and port defaults are persisted; flags and text options are cleared. Settings omitted from a request are unchanged.
curl -X PATCH \
-H 'X-API-Key: GLOBAL_API_KEY' \
-H 'Content-Type: application/json' \
--data '{"value":["203.0.113.10","2001:db8::/32"]}' \
'https://pbx.example.com/pbx/openapi.php/firewall/settings/F2BBLOCKEDIP'
curl -X DELETE -H 'X-API-Key: GLOBAL_API_KEY' \
'https://pbx.example.com/pbx/openapi.php/firewall/settings/F2BBLOCKEDIP'
Allowed countries
Read the available codes using GET /firewall/countries. Supply up to 1000 codes using countries. Codes must exist in the country catalog; lowercase codes are normalized to uppercase and duplicates are removed. Country updates replace the complete selection. An empty array or DELETE /firewall/countries clears it.
Read node status
curl -H 'X-API-Key: GLOBAL_READ_ONLY_API_KEY' \
'https://pbx.example.com/pbx/openapi.php/firewall/status?limit=10&offset=0'
curl -H 'X-API-Key: GLOBAL_READ_ONLY_API_KEY' \
'https://pbx.example.com/pbx/openapi.php/firewall/status/1?jail=asterisk-udp'
Status is paginated by node. limit defaults to 10 and is capped at 100; offset defaults to 0. Follow next_offset while has_more is true. Use node_id or the node ID in the path to select one node. The optional jail filter selects Fail2Ban rows, for example asterisk-udp, asterisk-tcp or sshd.
{
"object": "firewall_status",
"cached": true,
"data": [
{
"node_id": 1,
"node_name": "PBX node 1",
"peer_name": "pbx01.example.com",
"warning": "",
"fail2ban": [{"jail":"asterisk-udp","status":"Status at ..."}],
"sip_rate_status": "..."
}
],
"limit": 10,
"offset": 0,
"has_more": false,
"next_offset": null
}
The status text comes from fs_fail2banstatus and sr_sipratestatus, as displayed in the Security page. warning contains the node's CHECKGEOIPF2B-* message. These are stored observations, not live commands. They can be stale; no current timestamp is invented. Node credentials are never returned. Status and warning fields cannot be created, overwritten or deleted through this endpoint.
Atomicity and errors
The configuration tables se_settings, se_settings_max and ge_geoip must use InnoDB for API writes. Configuration changes use a checked transaction, read-back verification, and a database lock to serialize API writers. Validation failures, storage warnings or write failures roll back the change. Successful changes are recorded in the activity log.
| Status/code | Meaning |
|---|---|
400 invalid_firewall | Invalid value, malformed JSON structure, conflicting option values or invalid country/node filter. |
400 tenant_not_applicable | Remove the tenant selector; this resource is global. |
403 admin_required | A global API key is required. |
403 read_only_api_key | The key cannot modify firewall settings. |
404 firewall_setting_not_found | The requested code is not one of the supported firewall options. |
404 node_not_found | The requested PBX node does not exist. |
405 method_not_allowed | The operation is not available, including writes to observed status or deleting the entire configuration. |
500 database_error, database_warning or firewall_verification_failed | The change could not be saved and verified. The transaction is rolled back. |
503 transactional_tables_required | Convert se_settings, se_settings_max and ge_geoip to InnoDB before API writes. |
503 firewall_busy | Another API writer holds the configuration lock. Retry later. |
503 firewall_commit_unknown | The save outcome is uncertain. Read the configuration before retrying; do not assume that it was rolled back. |
No comments to display
No comments to display