diff --git a/src/www/interfaces_gif_edit.php b/src/www/interfaces_gif_edit.php index 88eef0334..a47e50d34 100644 --- a/src/www/interfaces_gif_edit.php +++ b/src/www/interfaces_gif_edit.php @@ -1,30 +1,30 @@ "") - interface_configure($confif); - - header("Location: interfaces_gif.php"); - exit; - } - } +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + // read form data + if (!empty($a_gifs[$_GET['id']])) { + $id = $_GET['id']; + } + $pconfig = array(); + + // copy fields + $copy_fields = array('gifif', 'remote-addr', 'tunnel-remote-net', 'tunnel-local-addr', 'tunnel-remote-addr', 'descr'); + foreach ($copy_fields as $fieldname) { + $pconfig[$fieldname] = isset($a_gifs[$id][$fieldname]) ? $a_gifs[$id][$fieldname] : null; + } + // bool fields + $pconfig['link0'] = isset($a_gifs[$id]['link0']); + $pconfig['link1'] = isset($a_gifs[$id]['link1']); + + // construct interface + if (!empty($a_gifs[$id]['ipaddr'])) { + $pconfig['if'] = $pconfig['if'] . '|' . $a_gifs[$id]['ipaddr']; + } elseif (!empty($a_gifs[$id]['if'])) { + $pconfig['if'] = $a_gifs[$id]['if']; + } else { + $pconfig['if'] = null; + } +} elseif ($_SERVER['REQUEST_METHOD'] === 'POST') { + // validate and save form data + if (!empty($a_gifs[$_POST['id']])) { + $id = $_POST['id']; + } + + $input_errors = array(); + $pconfig = $_POST; + + /* input validation */ + $reqdfields = explode(" ", "if tunnel-remote-addr tunnel-remote-net tunnel-local-addr"); + $reqdfieldsn = array(gettext("Parent interface,Local address, Remote tunnel address, Remote tunnel network, Local tunnel address")); + + do_input_validation($pconfig, $reqdfields, $reqdfieldsn, $input_errors); + + if (!is_ipaddr($pconfig['tunnel-local-addr']) || !is_ipaddr($pconfig['tunnel-remote-addr']) || !is_ipaddr($pconfig['remote-addr'])) { + $input_errors[] = gettext("The tunnel local and tunnel remote fields must have valid IP addresses."); + } + + $alias = strstr($pconfig['if'],'|'); + if ((is_ipaddrv4($alias) && !is_ipaddrv4($pconfig['remote-addr'])) || + (is_ipaddrv6($alias) && !is_ipaddrv6($pconfig['remote-addr'])) + ) { + $input_errors[] = gettext("The alias IP address family has to match the family of the remote peer address."); + } + + foreach ($a_gifs as $gif) { + if (isset($id) && $a_gifs[$id] === $gif) { + continue; + } + /* FIXME: needs to perform proper subnet checks in the feature */ + if ($gif['if'] == $interface && $gif['tunnel-remote-addr'] == $pconfig['tunnel-remote-addr']) { + $input_errors[] = sprintf(gettext("A gif with the network %s is already defined."), $gif['tunnel-remote-addr']); + break; + } + } + + if (count($input_errors) == 0) { + $gif = array(); + // copy fields + $copy_fields = array('tunnel-local-addr', 'tunnel-remote-addr', 'tunnel-remote-net', 'remote-addr', 'descr', 'gifif'); + foreach ($copy_fields as $fieldname) { + $gif[$fieldname] = $pconfig[$fieldname]; + } + // bool fields + $gif['link1'] = !empty($pconfig['link1']); + $gif['link0'] = !empty($pconfig['link0']); + + // interface and optional bind address + if (strpos($pconfig['if'], '|') !== false) { + list($gif['if'], $gif['ipaddr']) = explode("|",$pconfig['if']); + } else { + $gif['if'] = $pconfig['if']; + $gif['ipaddr'] = null; + } + + $gif['gifif'] = interface_gif_configure($gif); + if ($gif['gifif'] == "" || !stristr($gif['gifif'], "gif")) { + $input_errors[] = gettext("Error occurred creating interface, please retry."); + } else { + if (isset($id)) { + $a_gifs[$id] = $gif; + } else { + $a_gifs[] = $gif; + } + write_config(); + $confif = convert_real_interface_to_friendly_interface_name($gif['gifif']); + if ($confif <> "") { + interface_configure($confif); + } + header("Location: interfaces_gif.php"); + exit; + } + } } +legacy_html_escape_form_data($pconfig); include("head.inc"); - ?> - + - -
-
-
- - 0) print_input_errors($input_errors); ?> -
- - -
- -
- -
-

-
- -
- -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- -
-
- -
-
- -
-
- - - - - -
- - - -
-
-
- /> -
-
- /> -
- - -
- -
  - - " /> - " onclick="window.location.href=''" /> - - - -
-
-
-
-
-
-
-
+
+
+
+ 0) print_input_errors($input_errors); ?> +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +   +
+ + +
+ + +
+ + +
+ + + + + +
+ + + +
+ +
+ /> + +
+ /> + +
+ + +
  + + " /> + " onclick="window.location.href=''" /> + + + +
+
+
+
+
+
+
+