For fence breaches, you can use Advance Failsafe.
You can set the AFS_TERM_PIN for the PIN (although you will need an inverter since it goes high at termination)
If you don’t set the AFS_TERM_ACTION to 42/43 then the AFS actions (crashing the plane deliberately or qland) will not be invoked, but the PIN you set will be switched to high.
If you need a scripting solution, which includes distance from the fence you will need custom firmware, where the relevant functions are bound to Lua. For that either get familiar with the source code and the dev environment, or contact somebody from the list of partners Commercial Support and Tools — Mission Planner documentation who will do it for you for a modest fee.
Perhaps I read wrong, but Cat5 and Cat6 does not state that “providing means to prevent the operation volume” means that it should do a flight termination. I think the current fence implementation alongside with a remote pilot operated termination will satisfy the requirements of Cat5 and Cat6.