+POST_DEINSTALL.post
[...]function add_alias_if_not_exist($name, $description, $proto) { $model = new OPNsense\Firewall\Alias(); foreach ($model->aliases->alias->iterateItems() as $alias) { if ((string)$alias->name == $name) { return; } } $new_alias = $model->aliases->alias->Add(); $new_alias->name = $name; $new_alias->description = $description; $new_alias->proto = $proto; $new_alias->type = 'external'; $model->serializeToConfig(); Config::getInstance()->save();}function crowdsec_firewall(\OPNsense\Firewall\Plugin $fw){ if (!bouncer_enabled()) { return; } add_alias_if_not_exist('crowdsec_blacklists', 'CrowdSec (IPv4)', 'IPv4'); $fw->registerFilterRule( 1, /* priority */ array( 'ipprotocol' => 'inet', 'descr' => 'CrowdSec (IPv4)', 'from' => '$crowdsec_blacklists', # $ to reference an alias 'type' => 'block', 'quick' => true ), null ); add_alias_if_not_exist('crowdsec6_blacklists', 'CrowdSec (IPv6)', 'IPv6'); $fw->registerFilterRule( 1, /* priority */ array( 'ipprotocol' => 'inet6', 'descr' => 'CrowdSec (IPv6)', 'from' => '$crowdsec6_blacklists', # $ to reference an alias 'type' => 'block', 'quick' => true ), null );}[...]
#!/bin/sh/usr/local/bin/php << 'EOT'<?php@include_once("config.inc");@include_once("certs.inc");@include_once("util.inc");use OPNsense\Firewall\Alias;use OPNsense\Core\Config;function removeAlias($name){ $model = new Alias(); foreach ($model->aliases->alias->iterateItems() as $index => $alias) { if (strval($alias->name) == $name) { if ($model->aliases->alias->del($index)) { $model->serializeToConfig(); } } }}removeAlias('crowdsec_blacklists');removeAlias('crowdsec6_blacklists');EOT