Merge pull request #1881 from evbevz/firewall-register-table

Firewall plugin: register table
This commit is contained in:
Ad Schellevis 2017-10-18 18:29:49 +02:00 committed by GitHub
commit 65a6fb2cda
2 changed files with 34 additions and 0 deletions

View File

@ -405,6 +405,8 @@ function filter_configure_sync($verbose = false)
}
$aliases = filter_generate_aliases($cnfint);
$aliases .= "\n# Plugins tables\n";
$aliases .= $fw->tablesToText();
if ($verbose) {
echo '.';

View File

@ -42,6 +42,7 @@ class Plugin
private $interfaceMapping = array();
private $gatewayMapping = array();
private $systemDefaults = array();
private $tables = array();
/**
* init firewall plugin component
@ -232,4 +233,35 @@ class Plugin
}
return $output;
}
/**
* register a pf table
* @param string $name table name
* @param boolean $persist persistent
* @param string $file get table from file
*/
public function registerTable($name, $persist = false, $file = null)
{
$this->tables[] = array('name' => $name, 'persist' => $persist, 'file' => $file);
}
/**
* fetch tables as text (pf tables part)
* @return string
*/
public function tablesToText()
{
$result = "";
foreach ($this->tables as $table) {
$result .= "table <{$table['name']}>";
if ($table['persist']) {
$result .= " persist";
}
if (!empty($table['file'])) {
$result .= " file \"{$table['file']}\"";
}
$result .= "\n";
}
return $result;
}
}