Add staged ModSecurity rule

This function adds a new rule to a ModSecurity™ configuration staging file. For example, if you choose to add a rule for the example.conf file, the function stages the rule in the example.conf. STAGE file.

Important:

This function does not actually deploy the rule. To deploy the rule, use the WHM API 1 Functions - modsec_deploy_all_rule_changes function.

Important:

When you disable the Web Server role, the system disables this function.

SecurityBasicAuth
Request
query Parameters
config
required
string

The ModSecurity configuration file.

Example: config=modsec2.user.conf
rule
required
string

The rule's text.

Example: rule=SecAction "phase:1,id:168,nolog,pass,setvar:tx.REMOTE_ADDR=/%{REMOTE_ADDR}/"
Responses
200

HTTP Request was successful.

Response Schema: application/json
object
object
get/modsec_add_rule
Request samples
whmapi1 --output=jsonpretty \
  modsec_add_rule \
  config='modsec2.user.conf' \
  rule='SecAction "phase:1,id:168,nolog,pass,setvar:tx.REMOTE_ADDR=/%{REMOTE_ADDR}/"'
Response samples
application/json
{
  • "data": {
    • "rule": {
      • "config": null,
      • "config_active": null,
      • "disabled": 0,
      • "duplicate": 0,
      • "id": 168,
      • "meta_msg": "Example rule message",
      • "rule": "SecAction \\\"phase:1,id:168,nolog,pass,setvar:tx.REMOTE_ADDR=/%{REMOTE_ADDR}/\\\"",
      • "staged": null,
      • "vendor_active": null,
      • "vendor_id": null
      }
    },
  • "metadata": {
    • "command": "modsec_add_rule",
    • "reason": "OK",
    • "result": 1,
    • "version": 1
    }
}