For application level firewalling like you describe I use:

https://github.com/tnodir/fort