Commit e17ce08f authored by Franco Fichtner's avatar Franco Fichtner

src: merge updated files from master

Looks like fixes and additions, these will do good and
no harm.  :)
parent 07ec29d7
......@@ -895,7 +895,7 @@ function filter_generate_optcfg_array()
if (!empty($vips)) {
foreach ($vips as $vipidx => $vip) {
if (is_ipaddrv4($vip['subnet'])) {
if (!is_array($oic['vips']))
if (!isset($oic['vips']))
$oic['vips'] = array();
$oic['vips'][$vipidx]['ip'] = $vip['subnet'];
if (empty($vip['subnet_bits']))
......@@ -1319,11 +1319,11 @@ function filter_nat_rules_automatic_tonathosts($with_descr = false) {
foreach($FilterIflist as $ocname => $oc) {
if(interface_has_gateway($ocname))
continue;
if(is_ipaddr($oc['alias-address'])) {
if(isset($oc['alias-address']) && is_ipaddr($oc['alias-address'])) {
$tonathosts[] = "{$oc['alias-address']}/{$oc['alias-subnet']}";
$descriptions[] = $oc['descr'] . " " . gettext("DHCP alias address");
}
if($oc['sa']) {
if(!empty($oc['sa'])) {
$tonathosts[] = "{$oc['sa']}/{$oc['sn']}";
$descriptions[] = $oc['descr'];
if (isset($oc['vips']) && is_array($oc['vips'])) {
......
......@@ -56,6 +56,16 @@ function configd_run($cmd, $detach = false)
return $backend->configdRun("{$cmd}", $detach);
}
/*************************************************************************************************
* Legacy helper functions, only to be used in old (legacy) code.
* Some patterns are very common in the old code, this section contains functions to help
* cleanup the old code by performing less repetition.
*
* Never use these functions in new style OPNsense software, their only purpose is to help
* migrating to something new.
*
************************************************************************************************/
/**
* simple function to perform htmlspecialchars recursively on all attributes
* @param $settings array type form data
......@@ -72,3 +82,74 @@ function legacy_html_escape_form_data(&$settings)
}
}
}
/**
* list aliasses by type
* @param string $type type port or network
*/
function legacy_list_aliasses($type) {
global $config;
$result = array();
if (isset($config['aliases']['alias'])) {
foreach ($config['aliases']['alias'] as $alias) {
if ($type == "port") {
if (preg_match("/port/i", $alias['type'])) {
$result[] = $alias;
}
} else {
if (!preg_match("/port/i", $alias['type'])){
$result[] = $alias;
}
}
}
}
return $result;
}
/**
* Function to move selected array items before another one.
* Mainly used in form processing.
* @param array $source config section to apply move on
* @param int $id item number to move selected to (before)
* @param array $items item numbers to move
* @return new constructed list
*/
function legacy_move_config_list_items($source, $id, $items) {
$new_config = array();
if (!is_array($source)) {
// input of wrong type, return empty array
return array();
} elseif ( !is_array($items) || !is_numericint($id)) {
// selected items isn't an array or selected item isn't an int, return input
return $source;
} else {
// input types are valid, move items around
// copy all rules before selected target ($id) and not in items
for ($i = 0; $i < min($id, count($source)); $i++) {
if (!in_array($i, $items)) {
$new_config[] = $source[$i];
}
}
// next copy all selected rules (=before $id)
for ($i = 0; $i < count($source); $i++) {
if ($i != $id && in_array($i, $items)) {
$new_config[] = $source[$i];
}
}
// copy $id rule
if ($id < count($source)) {
$new_config[] = $source[$id];
}
/* copy all rules > $id and not selected */
for ($i = $id+1; $i < count($source); $i++) {
if (!in_array($i, $items)) {
$new_config[] = $source[$i];
}
}
return $new_config;
}
}
......@@ -9,3 +9,10 @@ command:/usr/local/etc/rc.filter_synchronize
parameters:%s
type:script
message:Syncing firewall %s
[refresh_url_alias]
command:/usr/local/etc/rc.update_alias_url_data;/usr/local/etc/rc.update_urltables now
parameters:
type:script
message:refresh url table aliasses
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment