This has serious quality issues and any competent and nice sysadmin should say _nope_ to run this in any serious environment, for your own good ;-)
IP addresses are just strings? At least parse/validate for IPv4/IPv6.
Why yet another database? Can't the rules be loaded from the running system?
Why not just ipset-persistent + knockd + portsentry? I know it is easy to get overexcited with a new pet project, but just be careful to not put this kind of stuff in a production system kidos.