You can find our user documentation at docs.cpanel.net.

Check out our new API beta site!

Child pages
  • WHM API 1 Functions - modsec_check_rule
Skip to end of metadata
Go to start of metadata

Description

This function checks a ModSecurity™ rule's validity.

Important:

In cPanel & WHM version 76 and later, when you disable the Web Server role, the system disables this function.

Examples 


 JSON API
https://hostname.example.com:2087/cpsess##########/json-api/modsec_check_rule?api.version=1&rule=SecAction%20%22pass%2Cid%3A1234567%22
 XML API
https://hostname.example.com:2087/cpsess##########/xml-api/modsec_check_rule?api.version=1&rule=SecAction%20%22pass%2Cid%3A1234567%22
 Command Line
whmapi1 modsec_check_rule rule=SecAction'"\pass,id:1234567\"'


Notes:

  • Unless otherwise noted, you must URI-encode values.
  • For more information and additional output options, read our Guide to WHM API 1 documentation or run the whmapi1 --help command.
  • If you run CloudLinux™, you must use the full path of the whmapi1 command:

    /usr/local/cpanel/bin/whmapi1

 Output (JSON)
{  
   "metadata":{  
      "reason":"OK Invalid Rule",
      "version":1,
      "result":1,
      "command":"modsec_check_rule"
   },
   "data":{  
      "problem":"(XID 2zm4ka) The rule is invalid. Apache returned the following error: AH00526: Syntax error on line 1 of /var/tmp/15500._USR_LOCAL_CPANEL_WHOSTMGR_BIN_XML_API__.gl2t8wZ1.tmp/validate.conf:\nInvalid command 'OWASP', perhaps misspelled or defined by a module not included in the server configuration\n",
      "valid":0
   }
}
 Output (XML)
<result>
  <data>
    <problem>The rule is invalid. Apache returned the following error: AH00526: Syntax error on line 1 of /var/tmp/15500._USR_LOCAL_CPANEL_WHOSTMGR_BIN_XML_API__.gl2t8wZ1.tmp/validate.conf:\nInvalid command 'OWASP', perhaps misspelled or defined by a module not included in the server configuration\n</problem>
	<valid>0</valid>
  </data>
  <metadata>
    <version>1</version>
    <reason>OK invalid rule</reason>
    <result>1</result>
    <command>modsec_check_rule</command>
  </metadata>
</result>


Note:

Use WHM's API Shell interface (WHM >> Home >> Development >> API Shell) to directly test WHM API calls.

Parameters

ParameterTypeDescriptionPossible valuesExample
rulestring

Required

The rule to check.

A valid ModSecurity rule.


 Click to view...
SecAction'"\pass,id:1234567\"'

Returns

ReturnTypeDescriptionPossible valuesExample
problemstring

A string that describes any errors with the ModSecurity rule.

The function only returns this value if an error occurred.

A string value.
 Click to view...
The rule is invalid. Apache returned the following error: AH00526: Syntax error on line 1 of /var/tmp/15500._USR_LOCAL_CPANEL_WHOSTMGR_BIN_XML_API__.gl2t8wZ1.tmp/validate.conf:\nInvalid command 'OWASP', perhaps misspelled or defined by a module not included in the server configuration\n

valid

Boolean

Whether the rule is valid.

  • 1 — Valid rule.
  • 0 — Invalid rule.

0