Virtualizor uses linux's iptables to manage the server firewall. The Firewall API allows you to manage the server firewall where you can perform multiple operations such as blocking/allowing ports and restarting firewall and much more. The API response will contain the "output" key which consists of the output of the iptables after execution of the firewall rule.
HTTP Request
https://hostname:4085/index.php?act=firewall
Parameters
Name | Method | Value | Description | Required |
---|---|---|---|---|
act | GET | firewall | The action specified to perform operation on the firewall of the server | Yes |
start | POST | 1/0 | Start the firewall service if parameter is set | No |
stop | POST | 1/0 | Stop the firewall service if parameter is set | No |
status | POST | 1/0 | Send status fo the firewall service | No |
restart | POST | 1/0 | Restart the firewal service | No |
version | POST | 1/0 | Returns the version of the firewall | No |
block | POST | 1/0 | Blocks the specified port | No |
allow | POST | 1/0 | Allows the specified port | No |
port | POST | Int | The port which needs to be blocked or allowed | No |
ip_block | POST | 1/0 | Blocks the specified IP Address | No |
ip_allow | POST | 1/0 | Allows the specified IP Address | No |
search | POST | 1/0 | Searches rule for the ip specified | No |
ip | POST | text | The ip that needs to be blocked or allowed | No |
Sample Code
<?php
require_once('/usr/local/virtualizor/sdk/admin.php');
$key = 'your_api_key';
$pass = 'your_api_pass';
$ip = 'your_server_ip';
$admin = new Virtualizor_Admin_API($ip, $key, $pass);
$post = array();
$post['status'] = 1; //here status is set, which will return the status of the firewall
$output = $admin->firewall($post);
print_r(json_encode($output));
?>
Output
{
"title": "Firewall Services ",
"output": ["iptables: Firewall is not running."],
"timenow": "1471411564",
"time_taken": "0.113"
}