Moved user defined dangerous functions to template
Catch all exceptions to be sure
Whitelist subnets

Fixes #1501
Take port into account for subnet whitelisting