New Extension for Plesk. Antivirus Protection to enhance your server security. Why choose Flex Antivirus?
Integrates IP blocking functionality directly into your web application if it belongs to a specific country. Compatible with classic ASP and PHP via the extension's COM object.
BlockIp(IP,Rulename)From your web page — in your index.asp, index.php, or any section of your application — you can call this function to block an IP address through Firewall Manager. It requires valid credentials for a domain in Plesk.
| Parameter | Type | Required | Description |
|---|---|---|---|
| Username | String | Required | Plesk domain user with access to the extension. |
| Password | String | Required | Password for the Plesk domain user. |
| FormatOutput | String | Optional | Response format: xml (default) or json. |
| IP | String | Required | IPv4 or IPv6 address to be blocked. |
| Rulename | String | Optional | Name of the rule where the IP address should be assigned. Do not use by default. |
Important: Use this function on pages protected with your own authentication. Exposing the call without protection allows any user to block arbitrary IPs.
Instantiate the FlexFirewallManager.Admin COM object, set the credentials, and call UnlockIP(). The response is parsed as XML.
' Create COM object instance
Set App = CreateObject("FlexFirewallManager.Admin")
App.FormatOutput = "xml"
App.Username = "Plesk Domain User"
App.Password = "Plesk Domain Password"
' IP to block
Dim strCountry : strIP = Request.ServerVariables("HTTP_X_FIREWALL_COUNTRY")
Dim strIP : strIP = Request.ServerVariables("HTTP_X_FIREWALL_IP")
If strIP = "" Then strIP = Request.ServerVariables("REMOTE_ADDR")
' Method 1
If strCountry = "CN" Then
App.BlockIp(strIP)
End If
' Method 2
Dim returnstring : returnstring = App.InfoIP(strIP)
' Parse XML response
Set objxml = CreateObject("Msxml2.DOMDocument")
objxml.LoadXml(returnstring)
If LCase(objxml.SelectSingleNode("/output/result").text) = "true" Then
If UCase(objxml.SelectSingleNode("/output/countrycode").text) = "RU" Then
App.BlockIp(strIP)
End If
End If
You can use FormatOutput = "json" if you prefer to parse the response with JSON.parse instead of XML. JSON format is recommended for modern applications.
In PHP, instantiate the COM object with new COM(). Use json format to parse the response directly with json_decode().
// Create COM object instance
$app = new COM("FlexFirewallManager.Admin");
$app->FormatOutput = "json";
$app->Username = "Plesk Domain User";
$app->Password = "Plesk Domain Password";
// IP to block
$strCountry = $_SERVER['HTTP_X_FIREWALL_COUNTRY'];;
$strIP = $_SERVER['HTTP_X_FIREWALL_IP'];;
if ($strIP=="") { $strIP = $_SERVER['REMOTE_ADDR'];; }
// Method 1
if ($strCountry == "CN") {
$app->BlockIp($strIP);
}
// Method 2
$returnstring = $app->InfoIP($strIP);
// Parse JSON response
$appjson = json_decode($returnstring);
if ($appjson->result) {
if ($appjson->countrycode == "RU") {
$app->BlockIp($strIP);
}
}
Tip: You can combine this function with an internal administration form so your users can self-manage blocking their own IP without needing access to the Plesk panel.
Keep the following in mind when integrating this function into your application:
BlockIp() with an authenticated user session.
FlexFirewallManager.Admin COM object requires Windows Server with the extension installed.