summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorStephen Beaver <sbeaver@netgate.com>2015-09-29 09:23:31 -0400
committerStephen Beaver <sbeaver@netgate.com>2015-09-29 09:24:25 -0400
commiteb3743d898f322ef4a08929e68e2be95aebb8047 (patch)
tree5cf8137ea478ca2374830ba55cab484c0eec0e2d /src
parent490920ef4ea7502033679db1022dad48d585e436 (diff)
downloadpfsense-eb3743d898f322ef4a08929e68e2be95aebb8047.zip
pfsense-eb3743d898f322ef4a08929e68e2be95aebb8047.tar.gz
Fil;e conversion complete. Tested against multiple packages
Diffstat (limited to 'src')
-rw-r--r--src/usr/local/www/pkg_edit.php1694
-rw-r--r--src/usr/local/www/pkg_mgr.php9
-rw-r--r--src/usr/local/www/pkg_mgr_install.php4
3 files changed, 957 insertions, 750 deletions
diff --git a/src/usr/local/www/pkg_edit.php b/src/usr/local/www/pkg_edit.php
index 544279d..0609200 100644
--- a/src/usr/local/www/pkg_edit.php
+++ b/src/usr/local/www/pkg_edit.php
@@ -78,27 +78,6 @@ function pfSenseHeader($location) {
header("Location: " . $location);
}
-function gentitle_pkg($pgname) {
- global $pfSense_config;
- return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname;
-}
-
-function domTT_title($title_msg) {
- if (!empty($title_msg)) {
- $title_msg = preg_replace("/\s+/", " ", $title_msg);
- $title_msg = preg_replace("/'/", "\'", $title_msg);
- return "onmouseout=\"this.style.color = ''; domTT_mouseout(this, event);\" onmouseover=\"domTT_activate(this, event, 'content', '{$title_msg}', 'trail', true, 'delay', 0, 'fade', 'both', 'fadeMax', 93, 'delay', 300, 'styleClass', 'niceTitle');\"";
- }
-}
-
-// Turn an embedded table into a bootstrap class table
-function bootstrapTable($text) {
- $t = strpos($text, '<table') + strlen('<table'); // Find the <table tag
- $c = strpos($text, '>', $t); // And its closing bracket
-
- return(substr_replace($text, ' class="table table-dtriped table-hover table-condensed"', $t, ($c - $t)));
-}
-
$xml = htmlspecialchars($_GET['xml']);
if ($_POST['xml']) {
$xml = htmlspecialchars($_POST['xml']);
@@ -321,6 +300,236 @@ if ($pkg['custom_php_after_head_command']) {
include("head.inc");
}
+// Turn an embedded table into a bootstrap class table. This is for backward compatibility.
+// We remove any table attributes in the XML and replace them with Bootstrap table classes
+function bootstrapTable($text) {
+ $t = strpos($text, '<table') + strlen('<table'); // Find the <table tag
+ $c = strpos($text, '>', $t); // And its closing bracket
+
+ // Substitute everything inbetween with our new classes
+ if($t && $c && (($c - $t) < 200) ) {
+ return(substr_replace($text, ' class="table table-striped table-hover table-condensed"', $t, ($c - $t)));
+ }
+}
+
+/*
+ * ROW helper function. Creates one element in the row from a PHP table by adding
+ * the specified element to $group
+ */
+function display_row($trc, $value, $fieldname, $type, $rowhelper, $description) {
+ global $text, $group;
+
+ switch ($type) {
+ case "input":
+ $group->add(new Form_Input(
+ $fieldname . $trc,
+ null,
+ 'text',
+ $value
+ ))->setHelp($description);
+
+ break;
+ case "checkbox":
+ $group->add(new Form_Checkbox(
+ $fieldname . $trc,
+ null,
+ null,
+ $value,
+ 'ON'
+ ))->setHelp($description);
+
+ break;
+ case "password":
+ $group->add(new Form_Input(
+ $fieldname . $trc,
+ null,
+ 'password',
+ $value
+ ))->setHelp($description);
+ break;
+ case "textarea":
+ $group->add(new Form_TextArea(
+ $fieldname . $trc,
+ null,
+ $value
+ ))->setHelp($description);
+
+ break;
+ case "select":
+ $options = array();
+ foreach ($rowhelper['options']['option'] as $rowopt) {
+ $options[$rowopt['value']] = $rowopt['name'];
+ }
+
+ $group->add(new Form_Select(
+ $fieldname . $trc,
+ null,
+ $value,
+ $options
+ ))->setHelp($description);
+
+ break;
+ case "interfaces_selection":
+ $size = ($size ? "size=\"{$size}\"" : '');
+ $multiple = '';
+ if (isset($rowhelper['multiple'])) {
+ $multiple = "multiple=\"multiple\"";
+ }
+ echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$size} {$multiple}>\n";
+ $ifaces = get_configured_interface_with_descr();
+ $additional_ifaces = $rowhelper['add_to_interfaces_selection'];
+ if (!empty($additional_ifaces)) {
+ $ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
+ }
+
+ if (is_array($value)) {
+ $values = $value;
+ } else {
+ $values = explode(',', $value);
+ }
+
+ $ifaces["lo0"] = "loopback";
+ $options = array();
+ $selected = array();
+
+ foreach ($ifaces as $ifname => $iface) {
+ $options[$ifname] = $iface;
+
+ if(in_array($ifname, $values)) {
+ array_push($selected, $ifname);
+ }
+ }
+
+ $group->add(new Form_Select(
+ $fieldname . $trc,
+ null,
+ ($multiple) ? $selected:$selected[0],
+ $options,
+ $multiple
+ ))->setHelp($description);
+
+ //echo "</select>\n";
+ break;
+ case "select_source":
+ $options = array();
+ $selected = array();
+
+ if (isset($rowhelper['show_disable_value'])) {
+ $options[$rowhelper['show_disable_value']] = $rowhelper['show_disable_value'];
+ }
+
+ $source_url = $rowhelper['source'];
+ eval("\$pkg_source_txt = &$source_url;");
+
+ foreach ($pkg_source_txt as $opt) {
+ $source_name = ($rowhelper['source_name'] ? $opt[$rowhelper['source_name']] : $opt[$rowhelper['name']]);
+ $source_value = ($rowhelper['source_value'] ? $opt[$rowhelper['source_value']] : $opt[$rowhelper['value']]);
+ $options[$source_value] = $source_name;
+
+ if($source_value == $value) {
+ array_push($selected, $value);
+ }
+ }
+
+ $group->add(new Form_Select(
+ $fieldname . $trc,
+ null,
+ ($multiple) ? $selected:$selected[0],
+ $options,
+ $multiple
+ ))->setHelp($description);
+
+ break;
+ }
+}
+
+function fixup_string($string) {
+ global $config;
+ // fixup #1: $myurl -> http[s]://ip_address:port/
+ $https = "";
+ $port = $config['system']['webguiport'];
+ if ($port != "443" and $port != "80") {
+ $urlport = ":" . $port;
+ } else {
+ $urlport = "";
+ }
+
+ if ($config['system']['webgui']['protocol'] == "https") {
+ $https = "s";
+ }
+ $myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
+ $newstring = str_replace("\$myurl", $myurl, $string);
+ $string = $newstring;
+ // fixup #2: $wanip
+ $curwanip = get_interface_ip();
+ $newstring = str_replace("\$wanip", $curwanip, $string);
+ $string = $newstring;
+ // fixup #3: $lanip
+ $lancfg = $config['interfaces']['lan'];
+ $lanip = $lancfg['ipaddr'];
+ $newstring = str_replace("\$lanip", $lanip, $string);
+ $string = $newstring;
+ // fixup #4: fix'r'up here.
+ return $newstring;
+}
+
+/*
+ * Parse templates if they are defined
+ */
+function parse_package_templates() {
+ global $pkg;
+ if ($pkg['templates']['template'] != "") {
+ foreach ($pkg['templates']['template'] as $pkg_template_row) {
+ $filename = $pkg_template_row['filename'];
+ $template_text = $pkg_template_row['templatecontents'];
+ /* calculate total row helpers count and */
+ /* change fields defined as fieldname_fieldvalue to their value */
+ foreach ($pkg['fields']['field'] as $fields) {
+ switch ($fields['type']) {
+ case "rowhelper":
+ // save rowhelper items.
+ $row_helper_total_rows = 0;
+ $row_helper_data = "";
+ foreach ($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
+ foreach ($_POST as $key => $value) {
+ if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/", $key, $matches)) {
+ $row_helper_total_rows++;
+ $row_helper_data .= $value;
+ $sep = "";
+ ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
+ foreach ($sep as $se) {
+ $separator = $se;
+ }
+ if ($separator != "") {
+ $row_helper_data = ereg_replace(" ", $separator, $row_helper_data);
+ $template_text = ereg_replace("\[{$separator}\]", "", $template_text);
+ }
+ $template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
+ }
+ }
+ }
+ break;
+ default:
+ $fieldname = $fields['fieldname'];
+ $fieldvalue = $_POST[$fieldname];
+ $template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
+ }
+ }
+ /* replace $domain_total_rows with total rows */
+ $template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
+
+ /* replace cr's */
+ $template_text = str_replace("\\n", "\n", $template_text);
+
+ /* write out new template file */
+ $fout = fopen($filename, "w");
+ fwrite($fout, $template_text);
+ fclose($fout);
+ }
+ }
+}
+
+// Start of page display
require_once('classes/Form.class.php');
if ($input_errors)
@@ -329,15 +538,7 @@ if ($input_errors)
if ($savemsg)
print_info_box($savemsg, 'success');
-$form = new Form();
-
-$form->addGlobal(new Form_Input(
- 'xml',
- null,
- 'hidden',
- $xml
-));
-
+// Create any required tabs
if ($pkg['tabs'] != "") {
$tab_array = array();
foreach ($pkg['tabs']['tab'] as $tab) {
@@ -346,30 +547,36 @@ if ($pkg['tabs'] != "") {
} else {
$tab_level = 1;
}
+
if (isset($tab['active'])) {
$active = true;
} else {
$active = false;
}
+
if (isset($tab['no_drop_down'])) {
$no_drop_down = true;
}
+
$urltmp = "";
if ($tab['url'] != "") {
$urltmp = $tab['url'];
}
+
if ($tab['xml'] != "") {
$urltmp = "pkg_edit.php?xml=" . $tab['xml'];
}
$addresswithport = getenv("HTTP_HOST");
$colonpos = strpos($addresswithport, ":");
+
if ($colonpos !== False) {
//my url is actually just the IP address of the pfsense box
$myurl = substr($addresswithport, 0, $colonpos);
} else {
$myurl = $addresswithport;
}
+
// eval url so that above $myurl item can be processed if need be.
$url = str_replace('$myurl', $myurl, $urltmp);
@@ -387,155 +594,105 @@ if ($pkg['tabs'] != "") {
}
}
-?>
+$cols = 0;
+$savevalue = gettext("Save");
+if ($pkg['savetext'] != "") {
+ $savevalue = $pkg['savetext'];
+}
-<?php
- $cols = 0;
- $savevalue = gettext("Save");
- if ($pkg['savetext'] != "") {
- $savevalue = $pkg['savetext'];
- }
- /* If a package's XML has <advanced_options/> configured, then setup
- * the table rows for the fields that have <advancedfield/> set.
- * These fields will be placed below other fields in a separate area titled 'Advanced Features'.
- * These advanced fields are not normally configured and generally left to default to 'default settings'.
- */
-
- if ($pkg['advanced_options'] == "enabled") {
- $advfield_count = 0;
- $advanced = new Form_Section(gettext("Advanced features"));
- $advanced->addClass('advancedoptions');
- }
+$grouping = false; // Indicates the elements we are composing are part of a combined group
- $js_array = array();
+$form = new Form(new Form_Button(
+ 'submit',
+ $savevalue
+));
- foreach ($pkg['fields']['field'] as $pkga) {
- if ($pkga['type'] == "sorting") {
- continue;
- }
+$form->addGlobal(new Form_Input(
+ 'xml',
+ null,
+ 'hidden',
+ $xml
+));
- // Generate a new section
+/* If a package's XML has <advanced_options/> configured, then setup
+ * ta section for the fields that have <advancedfield/> set.
+ * These fields will be placed below other fields in a separate area titled 'Advanced Features'.
+ * These advanced fields are not normally configured and generally left to default to 'default settings'.
+ */
- if ($pkga['type'] == "listtopic") {
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced->addInput(new Form_StaticText(
- $pkga['name'],
- null
- ));
+if ($pkg['advanced_options'] == "enabled") {
+ $advfield_count = 0;
+ $advanced = new Form_Section(gettext("Advanced features"));
+ $advanced->addClass('advancedoptions');
+}
- $advfield_count++;
- } else {
- if(isset($section))
- $form->add($section);
+$js_array = array();
- $section = new Form_Section($pkga['name']);
- }
+// Now loop through all of hte fields defined in the XML
+foreach ($pkg['fields']['field'] as $pkga) {
- continue;
- }
+ if ($pkga['type'] == "sorting") {
+ continue;
+ }
- if ($pkga['combinefields'] == "begin") {
- print('begin not yet converted<br />');
-/*
- $input="<tr valign='top' id='tr_{$pkga['fieldname']}'>";
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced .= $input;
- } else {
- echo $input;
- }
-*/
- }
+ // Generate a new section
+ if ($pkga['type'] == "listtopic") {
+ if (isset($pkga['advancedfield']) && isset($advfield_count)) {
+ $advanced->addInput(new Form_StaticText(
+ strip_tags($pkga['name']),
+ null
+ ));
- $size = "";
- $colspan="";
-/*
- if (isset($pkga['dontdisplayname'])) {
- $input="";
- // If this is in a set of combined fields and;
- // - it is a "begin" (case already handled above) or
- // - usecolspan2 is in effect (so we want to spread all the combined fields horizontally)
- // then we do not want this "tr" to be inserted.
- // Thus only insert the "tr" if the not (!) of the above condition.
- if (!((isset($pkga['combinefields'])) && (($pkga['combinefields'] == "begin") || (isset($pkga['usecolspan2']))))) {
- $input .= "<tr valign='top' id='tr_{$pkga['fieldname']}'>";
- }
- if (isset($pkga['usecolspan2'])) {
- $colspan="colspan='2'";
- } else {
- $input .= "<td width='22%' class='vncell{$req}'>&nbsp;</td>";
- }
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced .= $input;
- $advfield_count++;
- } else {
- echo $input;
- }
- } else if (!isset($pkga['placeonbottom'])) {
- unset($req);
- if (isset($pkga['required'])) {
- $req = 'req';
- }
- $input="";
- // If this is in a set of combined fields and;
- // - it is a "begin" (case already handled above) or
- // - usecolspan2 is in effect (so we want to spread all the combined fields horizontally)
- // then we do not want this "tr" to be inserted.
- // Thus only insert the "tr" if the not (!) of the above condition.
- if (!((isset($pkga['combinefields'])) && (($pkga['combinefields'] == "begin") || (isset($pkga['usecolspan2']))))) {
- $input .= "<tr>";
- }
- $input .= "<td valign='top' width=\"22%\" class=\"vncell{$req}\">";
- $input .= fixup_string($pkga['fielddescr']);
- $input .= "</td>";
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced .= $input;
- $advfield_count++;
- } else {
- echo $input;
- }
- }
+ $advfield_count++;
+ } else {
+ if(isset($section))
+ $form->add($section);
- if ($pkga['combinefields'] == "begin") {
- $input="<td class=\"vncell\"><table summary=\"advanced\"><tr>";
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced .= $input;
- } else {
- echo $input;
- }
+ $section = new Form_Section(strip_tags($pkga['name']));
}
- $class=(isset($pkga['combinefields']) ? '' : 'class="vtable"');
- if (!isset($pkga['placeonbottom'])) {
- $input="<td valign='top' {$colspan} {$class}>";
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced .= $input;
- $advfield_count++;
- } else {
- echo $input;
- }
+ continue;
+ }
+
+ // 'begin' starts a form group. ('end' ends it)
+ if ($pkga['combinefields'] == "begin") {
+ $group = new Form_Group(strip_tags($pkga['fielddescr']));
+ $grouping = true;
+ }
+
+ $size = "";
+ $colspan="";
+
+ // if user is editing a record, load in the data.
+ $fieldname = $pkga['fieldname'];
+ unset($value);
+ if ($get_from_post) {
+ $value = $_POST[$fieldname];
+ if (is_array($value)) {
+ $value = implode(',', $value);
}
-*/
- // if user is editing a record, load in the data.
- $fieldname = $pkga['fieldname'];
- unset($value);
- if ($get_from_post) {
- $value = $_POST[$fieldname];
- if (is_array($value)) {
- $value = implode(',', $value);
- }
+ } else {
+ if (isset($id) && isset($a_pkg[$id][$fieldname])) {
+ $value = $a_pkg[$id][$fieldname];
} else {
- if (isset($id) && isset($a_pkg[$id][$fieldname])) {
- $value = $a_pkg[$id][$fieldname];
- } else {
- if (isset($pkga['default_value'])) {
- $value = $pkga['default_value'];
- }
+ if (isset($pkga['default_value'])) {
+ $value = $pkga['default_value'];
}
}
+ }
- switch ($pkga['type']) {
- // Creat an input element
- case "input":
+ switch ($pkga['type']) {
+ // Creat an input element. The format is slightly different depending on whether we are composing a group,
+ // section, or advanced section. This is true for every element type
+ case "input":
+ if($grouping) {
+ $group->add(new Form_Input(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ 'text',
+ $value
+ ))->setHelp($pkga['description']);
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Input(
$pkga['fieldname'],
@@ -551,11 +708,20 @@ if ($pkg['tabs'] != "") {
$value
))->setHelp($pkga['description']);
}
+ }
- break;
+ break;
- case "password":
- // Creat a password element
+ case "password":
+ // Creat a password element
+ if($grouping) {
+ $group->add(new Form_Input(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ 'password',
+ $value
+ ))->setHelp($pkga['description']);
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Input(
$pkga['fieldname'],
@@ -571,67 +737,72 @@ if ($pkg['tabs'] != "") {
$value
))->setHelp($pkga['description']);
}
+ }
- break;
-
- case "info":
- // If the info containe a table we should detect and Bootstrap it
+ break;
- if (strpos($pkga['description'], '<table') !== FALSE)
- $info = bootstrapTable($pkga['description']);
- else
- $info = $pkga['description'];
+ case "info":
+ // If the info containe a table we should detect and Bootstrap it
+ if (strpos($pkga['description'], '<table') !== FALSE)
+ $info = bootstrapTable($pkga['description']);
+ else
+ $info = $pkga['description'];
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced->addInput(new Form_StaticText(
- null,
- $info
- ));
- } else {
- $section->addInput(new Form_StaticText(
- null,
- $info
- ));
- }
+ if (isset($pkga['advancedfield']) && isset($advfield_count)) {
+ $advanced->addInput(new Form_StaticText(
+ strip_tags($pkga['fielddescr']),
+ $info
+ ));
+ } else {
+ $section->addInput(new Form_StaticText(
+ strip_tags($pkga['fielddescr']),
+ $info
+ ));
+ }
- break;
+ break;
- case "select":
- // Create a select element
- $optionlist = array();
- $selectedlist = array();
+ case "select":
+ // Create a select element
+ $optionlist = array();
+ $selectedlist = array();
- $fieldname = $pkga['fieldname'];
+ $fieldname = $pkga['fieldname'];
- if (isset($pkga['multiple'])) {
- $multiple = 'multiple="multiple"';
- $items = explode(',', $value);
- $fieldname .= "[]";
- } else {
- $multiple = '';
- $items = array($value);
- }
+ if (isset($pkga['multiple'])) {
+ $multiple = 'multiple="multiple"';
+ $items = explode(',', $value);
+ $fieldname .= "[]";
+ } else {
+ $multiple = '';
+ $items = array($value);
+ }
- $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
+ $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
- foreach ($pkga['options']['option'] as $opt) {
- $optionlist[$opt['value']] = $opt['name'];
+ foreach ($pkga['options']['option'] as $opt) {
+ $optionlist[$opt['value']] = $opt['name'];
- if (in_array($opt['value'], $items)) {
- array_push($selectedlist, $opt['value']);
- }
+ if (in_array($opt['value'], $items)) {
+ array_push($selectedlist, $opt['value']);
}
+ }
- $section->addInput(new Form_Select(
- $pkga['fieldname'],
- $pkga['fielddescr'],
- isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
- $optionlist,
- isset($pkga['multiple'])
- ))->setHelp($pkga['description'])->setOnchange($onchange);
-
+ if (isset($pkga['advancedfield']) && isset($advfield_count))
+ $function = $grouping ? $advanced->add:$advanced->addInput;
+ else
+ $function = ($grouping) ? $section->add:$section->addInput;
+ if($grouping) {
+ $group->add(new Form_Select(
+ $pkga['fieldname'],
+ strip_tags($pkga['fielddescr']),
+ isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
+ $optionlist,
+ isset($pkga['multiple'])
+ ))->setHelp($pkga['description'])->setOnchange($onchange)->setAttribute('size', $pkga['size']);
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Select(
$pkga['fieldname'],
@@ -639,57 +810,67 @@ if ($pkg['tabs'] != "") {
isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
$optionlist,
isset($pkga['multiple'])
- ))->setHelp($pkga['description'])->setOnchange($onchange);
+ ))->setHelp($pkga['description'])->setOnchange($onchange)->setAttribute('size', $pkga['size']);
} else {
$section->addInput(new Form_Select(
$pkga['fieldname'],
- $pkga['fielddescr'],
+ strip_tags($pkga['fielddescr']),
isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
$optionlist,
isset($pkga['multiple'])
- ))->setHelp($pkga['description'])->setOnchange($onchange);
+ ))->setHelp($pkga['description'])->setOnchange($onchange)->setAttribute('size', $pkga['size']);
}
+ }
- break;
+ break;
- case "select_source":
+ case "select_source":
- if (isset($pkga['multiple'])) {
- $items = explode(',', $value);
- $fieldname .= "[]";
- } else {
- $items = array($value);
- }
+ if (isset($pkga['multiple'])) {
+ $items = explode(',', $value);
+ $fieldname .= "[]";
+ } else {
+ $items = array($value);
+ }
- $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
+ $onchange = (isset($pkga['onchange']) ? "onchange=\"{$pkga['onchange']}\"" : '');
- $source_url = $pkga['source'];
- eval("\$pkg_source_txt = &$source_url;");
+ $source_url = $pkga['source'];
+ eval("\$pkg_source_txt = &$source_url;");
- #check if show disable option is present on xml
- if (isset($pkga['show_disable_value'])) {
- array_push($pkg_source_txt,
- array(($pkga['source_name']? $pkga['source_name'] : $pkga['name'])=> $pkga['show_disable_value'], ($pkga['source_value']? $pkga['source_value'] : $pkga['value'])=> $pkga['show_disable_value']));
- }
+ #check if show disable option is present on xml
+ if (isset($pkga['show_disable_value'])) {
+ array_push($pkg_source_txt,
+ array(($pkga['source_name']? $pkga['source_name'] : $pkga['name'])=> $pkga['show_disable_value'], ($pkga['source_value']? $pkga['source_value'] : $pkga['value'])=> $pkga['show_disable_value']));
+ }
- $srcoptions = array();
- $srcselected = array();
+ $srcoptions = array();
+ $srcselected = array();
- foreach ($pkg_source_txt as $opt) {
- $source_name =($pkga['source_name']? $opt[$pkga['source_name']] : $opt[$pkga['name']]);
- $source_value =($pkga['source_value'] ? $opt[$pkga['source_value']] : $opt[$pkga['value']]);
- $srcoptions[$source_value] = $source_name;
+ foreach ($pkg_source_txt as $opt) {
+ $source_name =($pkga['source_name']? $opt[$pkga['source_name']] : $opt[$pkga['name']]);
+ $source_value =($pkga['source_value'] ? $opt[$pkga['source_value']] : $opt[$pkga['value']]);
+ $srcoptions[$source_value] = $source_name;
- if(in_array($source_value, $items))
- array_push($srcselected, $source_value);
- }
+ if(in_array($source_value, $items))
+ array_push($srcselected, $source_value);
+ }
+ if($grouping) {
+ $group->add(new Form_Select(
+ $pkga['fieldname'],
+ $pkga['name'],
+ isset($pkga['multiple']) ? $srcselected:$srcselected[0],
+ $srcoptions,
+ isset($pkga['multiple'])
+ ))->setOnchange($onchange);
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Select(
$pkga['fieldname'],
$pkga['name'],
isset($pkga['multiple']) ? $srcselected:$srcselected[0],
- $sourceoptions,
+ $srcoptions,
isset($pkga['multiple'])
))->setOnchange($onchange);
} else {
@@ -697,21 +878,30 @@ if ($pkg['tabs'] != "") {
$pkga['fieldname'],
$pkga['name'],
isset($pkga['multiple']) ? $srcselected:$srcselected[0],
- $sourceoptions,
+ $srcoptions,
isset($pkga['multiple'])
))->setOnchange($onchange);
}
+ }
- break;
+ break;
- case "vpn_selection" :
- $vpnlist = array();
+ case "vpn_selection" :
+ $vpnlist = array();
- foreach ($config['ipsec']['phase1'] as $vpn) {
- $vpnlist[$vpn['descr']] = $vpn['descr'];
+ foreach ($config['ipsec']['phase1'] as $vpn) {
+ $vpnlist[$vpn['descr']] = $vpn['descr'];
- }
+ }
+ if($grouping) {
+ $group->add(new Form_Select(
+ $pkga['fieldname'],
+ null,
+ false,
+ $vpnlist
+ ))->setHelp(fixup_string($pkga['description']));
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Select(
$pkga['fieldname'],
@@ -727,18 +917,29 @@ if ($pkg['tabs'] != "") {
$vpnlist
))->setHelp(fixup_string($pkga['description']));
}
+ }
+ break;
- break;
-
- // Create a checkbox element
- case "checkbox":
- $onchange = (isset($pkga['onchange']) ? "{$pkga['onchange']}" : '');
- if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
- $onclick = 'javascript:enablechange();';
- else
- $onclick = '';
-
+ // Create a checkbox element
+ case "checkbox":
+ $onchange = (isset($pkga['onchange']) ? "{$pkga['onchange']}" : '');
+ if (isset($pkga['enablefields']) || isset($pkga['checkenablefields']))
+ $onclick = 'javascript:enablechange();';
+ else
+ $onclick = '';
+
+ if($grouping) {
+ $group->add(new Form_Checkbox(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ 'Show log entries in reverse order (newest entries on top)',
+ ($value == "on"),
+ 'on'
+ ))->setHelp(fixup_string($pkga['description']))
+ ->setOnclick($onclick)
+ ->setOnchange($onchange);
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Checkbox(
$pkga['fieldname'],
@@ -760,23 +961,31 @@ if ($pkg['tabs'] != "") {
->setOnclick($onclick)
->setOnchange($onchange);
}
+ }
- break;
+ break;
- // Creat textarea element
- case "textarea":
- if ($pkga['rows']) {
- $rows = " rows='{$pkga['rows']}' ";
- }
- if ($pkga['cols']) {
- $cols = " cols='{$pkga['cols']}' ";
- }
- if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) {
- $value = base64_decode($value);
- }
+ // Creat textarea element
+ case "textarea":
+ if ($pkga['rows']) {
+ $rows = " rows='{$pkga['rows']}' ";
+ }
+ if ($pkga['cols']) {
+ $cols = " cols='{$pkga['cols']}' ";
+ }
+ if (($pkga['encoding'] == 'base64') && !$get_from_post && !empty($value)) {
+ $value = base64_decode($value);
+ }
- $wrap =($pkga['wrap'] == "off" ? 'wrap="off" style="white-space:nowrap;"' : '');
+ $wrap =($pkga['wrap'] == "off" ? 'wrap="off" style="white-space:nowrap;"' : '');
+ if ($grouping) {
+ $group->add(new Form_TextArea(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ $value
+ ))->setHelp(fixup_string($pkga['description']));
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_TextArea(
$pkga['fieldname'],
@@ -790,34 +999,24 @@ if ($pkg['tabs'] != "") {
$value
))->setHelp(fixup_string($pkga['description']));
}
+ }
- break;
+ break;
- case "aliases":
- // Todo
- print('aliases not yet converted<br />');
-/*
- // Use xml tag <typealiases> to filter type aliases
- $size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
- $fieldname = $pkga['fieldname'];
- $a_aliases = &$config['aliases']['alias'];
- $addrisfirst = 0;
- $aliasesaddr = "";
- $value = "value='{$value}'";
-
- if (isset($a_aliases)) {
- if (!empty($pkga['typealiases'])) {
- foreach ($a_aliases as $alias) {
- if ($alias['type'] == $pkga['typealiases']) {
- if ($addrisfirst == 1) {
- $aliasesaddr .= ",";
- }
- $aliasesaddr .= "'" . $alias['name'] . "'";
- $addrisfirst = 1;
- }
- }
- } else {
- foreach ($a_aliases as $alias) {
+ case "aliases":
+
+ // Use xml tag <typealiases> to filter type aliases
+ $size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
+ $fieldname = $pkga['fieldname'];
+ $a_aliases = &$config['aliases']['alias'];
+ $addrisfirst = 0;
+ $aliasesaddr = "";
+ $value = "value='{$value}'";
+
+ if (isset($a_aliases)) {
+ if (!empty($pkga['typealiases'])) {
+ foreach ($a_aliases as $alias) {
+ if ($alias['type'] == $pkga['typealiases']) {
if ($addrisfirst == 1) {
$aliasesaddr .= ",";
}
@@ -825,100 +1024,143 @@ if ($pkg['tabs'] != "") {
$addrisfirst = 1;
}
}
+ } else {
+ foreach ($a_aliases as $alias) {
+ if ($addrisfirst == 1) {
+ $aliasesaddr .= ",";
+ }
+ $aliasesaddr .= "'" . $alias['name'] . "'";
+ $addrisfirst = 1;
+ }
}
+ }
- $input = "<input name='{$fieldname}' type='text' class='formfldalias' id='{$fieldname}' {$size} {$value} />\n<br />";
- $input .= fixup_string($pkga['description']) . "\n";
+ if(grouping) {
+ $group->add(new Form_Input(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ 'text',
+ $value
+ ))->setHelp($pkga['description']);
+ } else {
+ if (isset($pkga['advancedfield']) && isset($advfield_count)) {
+ $advanced->addInput(new Form_Input(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ 'text',
+ $value
+ ))->setHelp($pkga['description']);
+ } else {
+ $section->addInput(new Form_Input(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ 'text',
+ $value
+ ))->setHelp($pkga['description']);
+ }
+ }
- $script = "<script type='text/javascript'>\n";
- $script .= "//<![CDATA[\n";
- $script .= "var aliasarray = new Array({$aliasesaddr})\n";
- $script .= "var oTextbox1 = new AutoSuggestControl(document.getElementById('{$fieldname}'), new StateSuggestions(aliasarray))\n";
- $script .= "//]]>\n";
- $script .= "</script>";
+ $script = "<script type='text/javascript'>\n";
+ $script .= "//<![CDATA[\n";
+ $script .= "events.push(function(){\n";
+ $script .= " var aliasarray = new Array({$aliasesaddr})\n";
+ $script .= " $('#' + '{$fieldname}').autocomplete({\n";
+ $script .= " source: aliasarray\n";
+ $script .= " })\n";
+ $script .= "});\n";
+ $script .= "//]]>\n";
+ $script .= "</script>";
- echo $input;
- echo $script;
-*/
- break;
-
- case "interfaces_selection":
- $ips = array();
- $interface_regex=(isset($pkga['hideinterfaceregex']) ? $pkga['hideinterfaceregex'] : "nointerfacestohide");
- if (is_array($config['interfaces'])) {
- foreach ($config['interfaces'] as $iface_key=>$iface_value) {
- if (isset($iface_value['enable']) && !preg_match("/$interface_regex/", $iface_key)) {
- $iface_description=($iface_value['descr'] !="" ? strtoupper($iface_value['descr']) : strtoupper($iface_key));
- if (isset($pkga['showips'])) {
- $iface_description .= " address";
- }
- $ips[] = array('ip'=> $iface_key, 'description'=> $iface_description);
+ echo $script;
+
+ break;
+
+ case "interfaces_selection":
+ $ips = array();
+ $interface_regex=(isset($pkga['hideinterfaceregex']) ? $pkga['hideinterfaceregex'] : "nointerfacestohide");
+ if (is_array($config['interfaces'])) {
+ foreach ($config['interfaces'] as $iface_key=>$iface_value) {
+ if (isset($iface_value['enable']) && !preg_match("/$interface_regex/", $iface_key)) {
+ $iface_description=($iface_value['descr'] !="" ? strtoupper($iface_value['descr']) : strtoupper($iface_key));
+ if (isset($pkga['showips'])) {
+ $iface_description .= " address";
}
+ $ips[] = array('ip'=> $iface_key, 'description'=> $iface_description);
}
}
+ }
- if (is_array($config['virtualip']) && isset($pkga['showvirtualips'])) {
- foreach ($config['virtualip']['vip'] as $vip) {
- if (!preg_match("/$interface_regex/", $vip['interface'])) {
- $vip_description=($vip['descr'] !="" ? " ({$vip['descr']}) " : " ");
- }
- switch ($vip['mode']) {
- case "ipalias":
- case "carp":
- $ips[] = array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
- break;
- case "proxyarp":
- if ($vip['type'] == "network") {
- $start = ip2long32(gen_subnet($vip['subnet'], $vip['subnet_bits']));
- $end = ip2long32(gen_subnet_max($vip['subnet'], $vip['subnet_bits']));
- $len = $end - $start;
- for ($i = 0; $i <= $len; $i++) {
- $ips[]= array('ip' => long2ip32($start+$i), 'description' => long2ip32($start+$i)." from {$vip['subnet']}/{$vip['subnet_bits']} {$vip_description}");
- }
- } else {
- $ips[]= array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
+ if (is_array($config['virtualip']) && isset($pkga['showvirtualips'])) {
+ foreach ($config['virtualip']['vip'] as $vip) {
+ if (!preg_match("/$interface_regex/", $vip['interface'])) {
+ $vip_description=($vip['descr'] !="" ? " ({$vip['descr']}) " : " ");
+ }
+ switch ($vip['mode']) {
+ case "ipalias":
+ case "carp":
+ $ips[] = array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
+ break;
+ case "proxyarp":
+ if ($vip['type'] == "network") {
+ $start = ip2long32(gen_subnet($vip['subnet'], $vip['subnet_bits']));
+ $end = ip2long32(gen_subnet_max($vip['subnet'], $vip['subnet_bits']));
+ $len = $end - $start;
+ for ($i = 0; $i <= $len; $i++) {
+ $ips[]= array('ip' => long2ip32($start+$i), 'description' => long2ip32($start+$i)." from {$vip['subnet']}/{$vip['subnet_bits']} {$vip_description}");
}
- break;
- }
+ } else {
+ $ips[]= array('ip' => $vip['subnet'], 'description' => "{$vip['subnet']} $vip_description");
+ }
+ break;
}
}
+ }
- sort($ips);
- if (isset($pkga['showlistenall'])) {
- array_unshift($ips, array('ip' => 'All', 'description' => 'Listen on All interfaces/ip addresses '));
- }
-
- if (!preg_match("/$interface_regex/", "loopback")) {
- $iface_description=(isset($pkga['showips']) ? "127.0.0.1 (loopback)" : "loopback");
- array_push($ips, array('ip' => 'lo0', 'description' => $iface_description));
- }
+ sort($ips);
+ if (isset($pkga['showlistenall'])) {
+ array_unshift($ips, array('ip' => 'All', 'description' => 'Listen on All interfaces/ip addresses '));
+ }
- #show interfaces array on gui
- $size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
- $multiple = '';
- $fieldname = $pkga['fieldname'];
- if (isset($pkga['multiple'])) {
- $fieldname .= '[]';
- $multiple = 'multiple="multiple"';
- }
+ if (!preg_match("/$interface_regex/", "loopback")) {
+ $iface_description=(isset($pkga['showips']) ? "127.0.0.1 (loopback)" : "loopback");
+ array_push($ips, array('ip' => 'lo0', 'description' => $iface_description));
+ }
- $selectedlist = array();
- $optionlist = array();
+ #show interfaces array on gui
+ $size = ($pkga['size'] ? "size=\"{$pkga['size']}\"" : '');
+ $multiple = '';
+ $fieldname = $pkga['fieldname'];
+ if (isset($pkga['multiple'])) {
+ $fieldname .= '[]';
+ $multiple = 'multiple="multiple"';
+ }
- if (is_array($value)) {
- $values = $value;
- } else {
- $values = explode(',', $value);
- }
+ $selectedlist = array();
+ $optionlist = array();
- foreach ($ips as $iface) {
- if (in_array($iface['ip'], $values)) {
- array_push($selectedlist, $iface['ip']);
- }
+ if (is_array($value)) {
+ $values = $value;
+ } else {
+ $values = explode(',', $value);
+ }
- $optionlist[$iface['ip']] = $iface['description'];
+ foreach ($ips as $iface) {
+ if (in_array($iface['ip'], $values)) {
+ array_push($selectedlist, $iface['ip']);
}
+ $optionlist[$iface['ip']] = $iface['description'];
+ }
+
+ if($grouping) {
+ $group->add(new Form_Select(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ isset($pkga['multiple']) ? $selectedlist:$selectedlist[0],
+ $optionlist,
+ isset($pkga['multiple'])
+ ))->setHelp($pkga['description']);
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Select(
$pkga['fieldname'],
@@ -936,11 +1178,21 @@ if ($pkg['tabs'] != "") {
isset($pkga['multiple'])
))->setHelp($pkga['description']);
}
+ }
- break;
+ break;
- // Create radio button
- case "radio":
+ // Create radio button
+ case "radio":
+ if($grouping) {
+ $group->add(new Form_Checkbox(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ 'Show log entries in reverse order (newest entries on top)',
+ ($value == "on"),
+ 'on'
+ ))->setHelp(fixup_string($pkga['description']))->displayAsRadio();
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Checkbox(
$pkga['fieldname'],
@@ -958,44 +1210,67 @@ if ($pkg['tabs'] != "") {
'on'
))->setHelp(fixup_string($pkga['description']))->displayAsRadio();
}
+ }
- break;
+ break;
- // Create form button
- case "button":
- $newbtn = new Form_Button(
- $pkga['fieldname'],
- $pkga['fieldname']
- );
+ // Create form button
+ case "button":
+ $newbtn = new Form_Button(
+ $pkga['fieldname'],
+ $pkga['fieldname']
+ );
+ if(grouping) {
+ $group->add(new Form_StaticText(
+ null,
+ $newbtn . '<br />' . '<div class="help-block">' . fixup_string($pkga['description']) . '</div>'
+ ));
+ } else {
+ if (isset($pkga['advancedfield']) && isset($advfield_count)) {
+ $advanced->addInput(new Form_StaticText(
+ null,
+ $newbtn . '<br />' . '<div class="help-block">' . fixup_string($pkga['description']) . '</div>'
+ ));
+ } else {
$section->addInput(new Form_StaticText(
null,
$newbtn . '<br />' . '<div class="help-block">' . fixup_string($pkga['description']) . '</div>'
));
+ }
+ }
- break;
+ break;
- case "schedule_selection":
+ case "schedule_selection":
- $input = "<select id='{$pkga['fieldname']}' name='{$pkga['fieldname']}'>\n";
- $schedules = array();
- $schedules[] = "none";
- if (is_array($config['schedules']['schedule'])) {
- foreach ($config['schedules']['schedule'] as $schedule) {
- if ($schedule['name'] != "") {
- $schedules[] = $schedule['name'];
- }
+ $input = "<select id='{$pkga['fieldname']}' name='{$pkga['fieldname']}'>\n";
+ $schedules = array();
+ $schedules[] = "none";
+ if (is_array($config['schedules']['schedule'])) {
+ foreach ($config['schedules']['schedule'] as $schedule) {
+ if ($schedule['name'] != "") {
+ $schedules[] = $schedule['name'];
}
}
+ }
- foreach ($schedules as $schedule) {
- if ($schedule == "none") {
- $schedlist[""] = $schedule;
- } else {
- $schedlist[$schedule] = $schedule;
- }
+ foreach ($schedules as $schedule) {
+ if ($schedule == "none") {
+ $schedlist[""] = $schedule;
+ } else {
+ $schedlist[$schedule] = $schedule;
}
+ }
+ if($grouping) {
+ $group->add(new Form_Select(
+ $pkga['fieldname'],
+ $pkga['fielddescr'],
+ $value,
+ $schedlist
+ ))->setHelp(fixup_string($pkga['description']));
+ } else {
if (isset($pkga['advancedfield']) && isset($advfield_count)) {
$advanced->addInput(new Form_Select(
$pkga['fieldname'],
@@ -1011,230 +1286,323 @@ if ($pkg['tabs'] != "") {
$schedlist
))->setHelp(fixup_string($pkga['description']));
}
+ }
- break;
-/*
- case "rowhelper":
- #$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
- $rowhelpername="row";
- ?>
- <script type="text/javascript">
- //<![CDATA[
- <?php
- $rowcounter = 0;
- $fieldcounter = 0;
- foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
- echo "rowname[{$fieldcounter}] = \"{$rowhelper['fieldname']}\";\n";
- echo "rowtype[{$fieldcounter}] = \"{$rowhelper['type']}\";\n";
- echo "rowsize[{$fieldcounter}] = \"{$rowhelper['size']}\";\n";
- $fieldcounter++;
- }
- ?>
- //]]>
- </script>
- <table id="maintable" summary="main table">
- <tr id='<?="tr_{$pkga['fieldname']}"?>'>
- <?php
- foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
- echo "<td ".domTT_title($rowhelper['description'])."><b>" . fixup_string($rowhelper['fielddescr']) . "</b></td>\n";
- }
+ break;
- $rowcounter = 0;
- $trc = 0;
+ case "rowhelper":
- //Use assigned $a_pkg or create an empty array to enter loop
- if (isset($a_pkg[$id][$rowhelpername])) {
- $saved_rows=$a_pkg[$id][$rowhelpername];
- } else {
- $saved_rows[] = array();
- }
+ $rowhelpername="row";
- foreach ($saved_rows as $row) {
- echo "</tr>\n<tr class=\"sortable\" id=\"id_{$rowcounter}\">\n";
- foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
- unset($value);
- if ($rowhelper['value'] != "") {
- $value = $rowhelper['value'];
- }
- $fieldname = $rowhelper['fieldname'];
- // if user is editing a record, load in the data.
- if (isset($id) && $a_pkg[$id]) {
- $value = $row[$fieldname];
- }
- $type = $rowhelper['type'];
- $fieldname = $rowhelper['fieldname'];
- if ($rowhelper['size']) {
- $size = $rowhelper['size'];
- } else if ($pkga['size']) {
- $size = $pkga['size'];
- } else {
- $size = "8";
- }
- display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size);
+ $rowcounter = 0;
+ $trc = 0;
+
+ //Use assigned $a_pkg or create an empty array to enter loop
+ if (isset($a_pkg[$id][$rowhelpername])) {
+ $saved_rows=$a_pkg[$id][$rowhelpername];
+ } else {
+ $saved_rows[] = array();
+ }
+
+ $numrows = count($saved_rows) - 1;
+
+ foreach ($saved_rows as $row) {
+ $group = new Form_Group(($rowcounter == 0) ? $pkga['fielddescr']:null);
+ $group->addClass('repeatable');
+
+ foreach ($pkga['rowhelper']['rowhelperfield'] as $rowhelper) {
+ unset($value);
+ if ($rowhelper['value'] != "") {
+ $value = $rowhelper['value'];
+ }
+ $fieldname = $rowhelper['fieldname'];
+ $fielddescr = $rowhelper['fielddescr'];
- $text = "";
- $trc++;
+ // if user is editing a record, load in the data.
+ if (isset($id) && $a_pkg[$id]) {
+ $value = $row[$fieldname];
}
- $rowcounter++;
- echo "<td>";
- #echo "<a onclick=\"removeRow(this); return false;\" href=\"#\"><img border=\"0\" src=\"./themes/".$g['theme']."/images/icons/icon_x.gif\" alt=\"remove\" /></a>";
- echo "<a class='delete' href=\"#\"><img border='0' src='./themes/{$g['theme']}/images/icons/icon_x.gif' alt='delete' /></a>";
- echo "</td>\n";
+
+ $type = $rowhelper['type'];
+ $fieldname = $rowhelper['fieldname'];
+
+ if ($rowhelper['size']) {
+ $size = $rowhelper['size'];
+ } else if ($pkga['size']) {
+ $size = $pkga['size'];
+ } else {
+ $size = "8";
+ }
+
+ display_row($rowcounter, $value, $fieldname, $type, $rowhelper, ($numrows == $rowcounter) ? $fielddescr:null);
+
+ $text = "";
+ $trc++;
}
- ?>
- </tr>
- <tbody></tbody>
- </table>
-
- <!-- <br /><a onclick="javascript:addRowTo('maintable'); return false;" href="#"><img border="0" src="./themes/<?#= $g['theme']; ?>/images/icons/icon_plus.gif" alt="add" /></a>-->
- <br /><a class="add" href="#"><img border="0" src="./themes/<?= $g['theme']; ?>/images/icons/icon_plus.gif" alt="add" /></a>
- <br /><?php if ($pkga['description'] != "") echo $pkga['description']; ?>
- <script type="text/javascript">
- //<![CDATA[
- field_counter_js = <?= $fieldcounter ?>;
- rows = <?= $rowcounter ?>;
- totalrows = <?=$rowcounter; ?>;
- loaded = <?=$rowcounter; ?>;
- //typesel_change();
- //]]>
- </script>
-
- <?php
- break;
-*/
- }
-/*
- #check typehint value
- if ($pkga['typehint']) {
- echo " " . $pkga['typehint'];
- }
- #check combinefields options
- if (isset($pkga['combinefields'])) {
- // At the end of each combined-fields field we always want to end a td tag.
- $input = "</td>";
- // The tr tag end is used to end the whole set of combined fields,
- // but also if usecolspan2 is not in effect then we also put each combined field in its own tr.
- if (($pkga['combinefields'] == "end") || (!isset($pkga['usecolspan2']))) {
- $input .= "</tr>";
- }
- // At the end of the combined fields we finish up the table that encloses the combined fields...
- if ($pkga['combinefields'] == "end") {
- $input .= "</table></td></tr>";
- }
- } else {
- $input = "</td></tr>";
- if ($pkga['usecolspan2']) {
- $input .= "</tr><br />";
- }
- }
+ // Delete row button
+ $group->add(new Form_Button(
+ 'deleterow' . $rowcounter,
+ 'Delete'
+ ))->removeClass('btn-primary')->addClass('btn-warning btn-sm');
+
+ $rowcounter++;
+ $section->add($group);
+ }
+
+ // Add row button
+ $section->addInput(new Form_Button(
+ 'addrow',
+ 'Add'
+ ))->removeClass('btn-primary')->addClass('btn-success');
+
+ break;
- if (isset($pkga['advancedfield']) && isset($advfield_count)) {
- $advanced .= "{$input}\n";
- } else {
- echo "{$input}\n";
- }
-*/
- #increment counter
- $i++;
}
- $form->add($section);
+ if ($pkga['combinefields'] == "end") {
+ $group->add(new Form_StaticText(
+ null,
+ null
+ ));
- $form->addGlobal(new Form_Input(
- 'id',
- null,
- 'hidden',
- $id
- ));
+ if($advanced)
+ $advanced->add($group);
+ else
+ $section->add($group);
- // If we created and advanced section, add it here
- if(!empty($advanced)) {
- $form->addGlobal(new Form_Button(
- 'showadv',
- 'Show advanced options'
- ))->removeClass('btn-primary')->addClass('btn-default');
+ $grouping = false;
+ }
- $form->add($advanced);
- }
+ #increment counter
+ $i++;
+} // e-o-foreach field described in the XML
- print($form);
+$form->add($section);
- if ($pkg['note'] != "") {
- print_info_box($pkg['note']);
+$form->addGlobal(new Form_Input(
+ 'id',
+ null,
+ 'hidden',
+ $id
+));
- if ($pkg['custom_php_after_form_command'])
- eval($pkg['custom_php_after_form_command']); ?>
+// If we created an advanced section, add it (and a button) to the form here
+if(!empty($advanced)) {
+ $form->addGlobal(new Form_Button(
+ 'showadv',
+ 'Show advanced options'
+ ))->removeClass('btn-primary')->addClass('btn-default');
-<?php
+ $form->add($advanced);
+}
+
+print($form);
+
+if ($pkg['note'] != "") {
+ print_info_box($pkg['note']);
+
+if ($pkg['custom_php_after_form_command'])
+ eval($pkg['custom_php_after_form_command']);
}
if ($pkg['fields']['field'] != "") { ?>
<script type="text/javascript">
//<![CDATA[
- //Everything inside it will load as soon as the DOM is loaded and before the page contents are loaded
events.push(function(){
- // Hide the advanced section
+ function setMasks() {
+ // Find all ipaddress masks and make dynamic based on address family of input
+ $('span.pfIpMask + select').each(function (idx, select){
+ var input = $(select).prevAll('input[type=text]');
- var advanced_visible = false;
+ input.on('change', function(e){
+ var isV6 = (input.val().indexOf(':') != -1), min = 0, max = 128;
+ if (!isV6)
+ max = 32;
- // Hide on page load
- $('.advancedoptions').hide();
+ if (input.val() == "")
+ return;
- // But show it if you click the showadv button
- $('#showadv').prop('type', 'button');
+ while (select.options.length > max)
+ select.remove(0);
- $("#showadv").click(function() {
- advanced_visible = !advanced_visible;
+ if (select.options.length < max)
+ {
+ for (var i=select.options.length; i<=max; i++)
+ select.options.add(new Option(i, i), 0);
+ }
+ });
- if(advanced_visible) {
- $('.advancedoptions').show();
- $("#showadv").prop('value', 'Hide advanced Options');
- }
- else {
- $('.advancedoptions').hide();
- $("#showadv").prop('value', 'Show advanced Options');
+ // Fire immediately
+ input.change();
+ });
+ }
+
+ // Complicated function to move all help text associated with this input id to the same id
+ // on the row above. That way if you delete the last row, you don't lose the help
+ function moveHelpText(id) {
+ $('#' + id).parent('div').parent('div').find('input').each(function() { // For each <span></span>
+ var fromId = this.id;
+ var toId = decrStringInt(fromId);
+ var helpSpan;
+
+ if(!$(this).hasClass('pfIpMask') && !$(this).hasClass('btn')) {
+
+ helpSpan = $('#' + fromId).parent('div').parent('div').find('span:last').clone();
+ if($(helpSpan).hasClass('help-block')) {
+ if($('#' + decrStringInt(fromId)).parent('div').hasClass('input-group'))
+ $('#' + decrStringInt(fromId)).parent('div').after(helpSpan);
+ else
+ $('#' + decrStringInt(fromId)).after(helpSpan);
+ }
}
});
+ }
+
+ // Increment the number at the end of the string
+ function bumpStringInt( str ) {
+ var data = str.match(/(\D*)(\d+)(\D*)/), newStr = "";
+
+ if( data )
+ newStr = data[ 1 ] + ( Number( data[ 2 ] ) + 1 ) + data[ 3 ];
+
+ return newStr || str;
+ }
+
+ // Decrement the number at the end of the string
+ function decrStringInt( str ) {
+ var data = str.match(/(\D*)(\d+)(\D*)/), newStr = "";
+
+ if( data )
+ newStr = data[ 1 ] + ( Number( data[ 2 ] ) - 1 ) + data[ 3 ];
+
+ return newStr || str;
+ }
+
+ // Called after a delete so that there are no gaps in the numbering. Most of the time the config system doesn't care about
+ // gaps, but I do :)
+ function renumber() {
+ var idx = 0;
+
+ $('.repeatable').each(function() {
+
+ $(this).find('input').each(function() {
+ $(this).prop("id", this.id.replace(/\d+$/, "") + idx);
+ $(this).prop("name", this.name.replace(/\d+$/, "") + idx);
+ });
+
+ $(this).find('select').each(function() {
+ $(this).prop("id", this.id.replace(/\d+$/, "") + idx);
+ $(this).prop("name", this.name.replace(/\d+$/, "") + idx);
+ });
+
+ $(this).find('label').attr('for', $(this).find('label').attr('for').replace(/\d+$/, "") + idx);
+
+ idx++;
+ });
+ }
+ function delete_row(row) {
+ $('#' + row).parent('div').parent('div').remove();
+ renumber();
+ }
+
+ function add_row() {
+ // Find the lst repeatable group
+ var lastRepeatableGroup = $('.repeatable:last');
+
+ // Clone it
+ var newGroup = lastRepeatableGroup.clone(true);
- //Sortable function
- jQuery('#mainarea table tbody').sortable({
- items: 'tr.sortable',
- cursor: 'move',
- distance: 10,
- opacity: 0.8,
- helper: function(e, ui) {
- ui.children().each(function() {
- jQuery(this).width(jQuery(this).width());
- });
- return ui;
- },
+ // Increment the suffix number for each input elemnt in the new group
+ $(newGroup).find('input').each(function() {
+ $(this).prop("id", bumpStringInt(this.id));
+ $(this).prop("name", bumpStringInt(this.name));
+ if(!$(this).is('[id^=delete]'))
+ $(this).val('');
});
- //delete current line jQuery function
- jQuery('#maintable td .delete').on('click', function() {
- //do not remove first line
- if (jQuery("#maintable tr").length > 2) {
- jQuery(this).parent().parent().remove();
- return false;
+ // Do the same for selectors
+ $(newGroup).find('select').each(function() {
+ $(this).prop("id", bumpStringInt(this.id));
+ $(this).prop("name", bumpStringInt(this.name));
+ // If this selector lists mask bits, we need it to be reset to all 128 options
+ // and no items selected, so that automatic v4/v6 selection still works
+ if($(this).is('[id^=address_subnet]')) {
+ $(this).empty();
+ for(idx=128; idx>0; idx--) {
+ $(this).append($('<option>', {
+ value: idx,
+ text: idx
+ }));
+ }
}
});
- //add new line jQuery function
- jQuery('#mainarea table .add').click(function() {
- //get table size and assign as new id
- var c_id=jQuery("#maintable tr").length;
- var new_row=jQuery("table#maintable tr:last").html().replace(/(name|id)="(\w+)(\d+)"/g,"$1='$2"+c_id+"'");
- //apply new id to created line rowhelperid
- jQuery("table#maintable tr:last").after("<tr>"+new_row+"<\/tr>");
- return false;
+ // And for "for" tags
+ $(newGroup).find('label').attr('for', bumpStringInt($(newGroup).find('label').attr('for')));
+ $(newGroup).find('label').text(""); // Clear the label. We only want it on the very first row
+
+ // Insert the updated/cloned row
+ $(lastRepeatableGroup).after(newGroup);
+
+ // Delete any help text from the group we have cloned
+ $(lastRepeatableGroup).find('.help-block').each(function() {
+ $(this).remove();
+ });
+
+ setMasks();
+
+ $('[id^=address]').autocomplete({
+ source: addressarray
});
- // Call enablechange function
- enablechange();
+ }
+
+ // These are action buttons, not submit buttons
+ $('[id^=addrow]').prop('type','button');
+ $('[id^=delete]').prop('type','button');
+
+ // on click . .
+ $('[id^=addrow]').click(function() {
+ add_row();
});
+ $('[id^=delete]').click(function(event) {
+ if($('.repeatable').length > 1) {
+ moveHelpText(event.target.id);
+ delete_row(event.target.id);
+ }
+ else
+ alert('<?php echo gettext("You may not delete the last one!")?>');
+ });
+
+ // Hide the advanced section
+ var advanced_visible = false;
+
+ // Hide on page load
+ $('.advancedoptions').hide();
+
+ // But show it if you click the showadv button
+ $('#showadv').prop('type', 'button');
+
+ $("#showadv").click(function() {
+ advanced_visible = !advanced_visible;
+
+ if(advanced_visible) {
+ $('.advancedoptions').show();
+ $("#showadv").prop('value', 'Hide advanced Options');
+ }
+ else {
+ $('.advancedoptions').hide();
+ $("#showadv").prop('value', 'Show advanced Options');
+ }
+ });
+
+ // Call enablechange function
+ enablechange();
+});
+
function enablechange() {
<?php
foreach ($pkg['fields']['field'] as $field) {
@@ -1287,171 +1655,3 @@ if ($pkg['fields']['field'] != "") { ?>
}
include("foot.inc");
-
-
-/*
- * ROW Helpers function
- */
-function display_row($trc, $value, $fieldname, $type, $rowhelper, $size) {
- global $text;
- echo "<td>\n";
- switch ($type) {
- case "input":
- echo "<input size='{$size}' name='{$fieldname}{$trc}' id='{$fieldname}{$trc}' class='formfld unknown' value=\"" . htmlspecialchars($value) . "\" />\n";
- break;
- case "checkbox":
- echo "<input size='{$size}' type='checkbox' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' value='ON' ".($value?"CHECKED":"")." />\n";
- break;
- case "password":
- echo "<input size='{$size}' type='password' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' class='formfld pwd' value=\"" . htmlspecialchars($value) . "\" />\n";
- break;
- case "textarea":
- echo "<textarea rows='2' cols='12' id='{$fieldname}{$trc}' class='formfld unknown' name='{$fieldname}{$trc}'>{$value}</textarea>\n";
- case "select":
- echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$title}>\n";
- foreach ($rowhelper['options']['option'] as $rowopt) {
- $text .= "<option value='{$rowopt['value']}'>{$rowopt['name']}</option>";
- echo "<option value='{$rowopt['value']}'".($rowopt['value'] == $value?" selected=\"selected\"":"").">{$rowopt['name']}</option>\n";
- }
- echo "</select>\n";
- break;
- case "interfaces_selection":
- $size = ($size ? "size=\"{$size}\"" : '');
- $multiple = '';
- if (isset($rowhelper['multiple'])) {
- $fieldname .= '[]';
- $multiple = "multiple=\"multiple\"";
- }
- echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}' {$size} {$multiple}>\n";
- $ifaces = get_configured_interface_with_descr();
- $additional_ifaces = $rowhelper['add_to_interfaces_selection'];
- if (!empty($additional_ifaces)) {
- $ifaces = array_merge($ifaces, explode(',', $additional_ifaces));
- }
- if (is_array($value)) {
- $values = $value;
- } else {
- $values = explode(',', $value);
- }
- $ifaces["lo0"] = "loopback";
- echo "<option><name></name><value></value></option>/n";
- foreach ($ifaces as $ifname => $iface) {
- $text .="<option value=\"{$ifname}\">$iface</option>";
- echo "<option value=\"{$ifname}\" ".(in_array($ifname, $values) ? 'selected="selected"' : '').">{$iface}</option>\n";
- }
- echo "</select>\n";
- break;
- case "select_source":
- echo "<select style='height:22px;' id='{$fieldname}{$trc}' name='{$fieldname}{$trc}'>\n";
- if (isset($rowhelper['show_disable_value'])) {
- echo "<option value='{$rowhelper['show_disable_value']}'>{$rowhelper['show_disable_value']}</option>\n";
- }
- $source_url = $rowhelper['source'];
- eval("\$pkg_source_txt = &$source_url;");
- foreach ($pkg_source_txt as $opt) {
- $source_name = ($rowhelper['source_name'] ? $opt[$rowhelper['source_name']] : $opt[$rowhelper['name']]);
- $source_value = ($rowhelper['source_value'] ? $opt[$rowhelper['source_value']] : $opt[$rowhelper['value']]);
- $text .= "<option value='{$source_value}'>{$source_name}</option>";
- echo "<option value='{$source_value}'".($source_value == $value?" selected=\"selected\"":"").">{$source_name}</option>\n";
- }
- echo "</select>\n";
- break;
- }
- echo "</td>\n";
-}
-
-function fixup_string($string) {
- global $config;
- // fixup #1: $myurl -> http[s]://ip_address:port/
- $https = "";
- $port = $config['system']['webguiport'];
- if ($port != "443" and $port != "80") {
- $urlport = ":" . $port;
- } else {
- $urlport = "";
- }
-
- if ($config['system']['webgui']['protocol'] == "https") {
- $https = "s";
- }
- $myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlport;
- $newstring = str_replace("\$myurl", $myurl, $string);
- $string = $newstring;
- // fixup #2: $wanip
- $curwanip = get_interface_ip();
- $newstring = str_replace("\$wanip", $curwanip, $string);
- $string = $newstring;
- // fixup #3: $lanip
- $lancfg = $config['interfaces']['lan'];
- $lanip = $lancfg['ipaddr'];
- $newstring = str_replace("\$lanip", $lanip, $string);
- $string = $newstring;
- // fixup #4: fix'r'up here.
- return $newstring;
-}
-
-/*
- * Parse templates if they are defined
- */
-function parse_package_templates() {
- global $pkg;
- if ($pkg['templates']['template'] != "") {
- foreach ($pkg['templates']['template'] as $pkg_template_row) {
- $filename = $pkg_template_row['filename'];
- $template_text = $pkg_template_row['templatecontents'];
- /* calculate total row helpers count and */
- /* change fields defined as fieldname_fieldvalue to their value */
- foreach ($pkg['fields']['field'] as $fields) {
- switch ($fields['type']) {
- case "rowhelper":
- // save rowhelper items.
- $row_helper_total_rows = 0;
- $row_helper_data = "";
- foreach ($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
- foreach ($_POST as $key => $value) {
- if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/", $key, $matches)) {
- $row_helper_total_rows++;
- $row_helper_data .= $value;
- $sep = "";
- ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep);
- foreach ($sep as $se) {
- $separator = $se;
- }
- if ($separator != "") {
- $row_helper_data = ereg_replace(" ", $separator, $row_helper_data);
- $template_text = ereg_replace("\[{$separator}\]", "", $template_text);
- }
- $template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text);
- }
- }
- }
- break;
- default:
- $fieldname = $fields['fieldname'];
- $fieldvalue = $_POST[$fieldname];
- $template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text);
- }
- }
- /* replace $domain_total_rows with total rows */
- $template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text);
-
- /* replace cr's */
- $template_text = str_replace("\\n", "\n", $template_text);
-
- /* write out new template file */
- $fout = fopen($filename, "w");
- fwrite($fout, $template_text);
- fclose($fout);
- }
- }
-}
-
-/* Return html div fields */
-function display_advanced_field($fieldname) {
- $div = "<div id='showadv_{$fieldname}'>\n";
- $div .= "<input type='button' onclick='show_{$fieldname}()' value='" . gettext("Advanced") . "' /> - " . gettext("Show advanced option") ."</div>\n";
- $div .= "<div id='show_{$fieldname}' style='display:none'>\n";
- return $div;
-}
-
-?>
diff --git a/src/usr/local/www/pkg_mgr.php b/src/usr/local/www/pkg_mgr.php
index 46a0455..3debabf 100644
--- a/src/usr/local/www/pkg_mgr.php
+++ b/src/usr/local/www/pkg_mgr.php
@@ -102,7 +102,7 @@ if($pkg_info) {
}
}
- ksort($categories);
+ ksort($categories, SORT_STRING|SORT_FLAG_CASE);
$cm_count=0;
$tab_array = array();
$visible_categories=array();
@@ -134,6 +134,10 @@ if($pkg_info) {
display_top_tabs($tab_array);
}
+function compareName($a, $b) {
+ return(strcasecmp ($a['name'], $b['name']));
+}
+
if(!$pkg_info || !is_array($pkg_info)):?>
<div class="alert alert-warning">
<?=gettext("There are currently no packages available for installation.")?>
@@ -154,6 +158,9 @@ if(!$pkg_info || !is_array($pkg_info)):?>
<tbody>
<?php
+ // Sort case insensitve (so we get AbCdEf not ACEcdf)
+ usort($pkg_info, 'compareName');
+
foreach($pkg_info as $index):
if(get_package_id($index['name']) >= 0 ) {
diff --git a/src/usr/local/www/pkg_mgr_install.php b/src/usr/local/www/pkg_mgr_install.php
index 450f80b..5870282 100644
--- a/src/usr/local/www/pkg_mgr_install.php
+++ b/src/usr/local/www/pkg_mgr_install.php
@@ -197,8 +197,8 @@ if ($_GET) {
filter_configure();
break;
case 'reinstallxml':
- pkg_fetch_config_file($pkgid);
- pkg_fetch_additional_files($pkgid);
+// pkg_fetch_config_file($pkgid);
+// pkg_fetch_additional_files($pkgid);
break;
case 'reinstallpkg':
delete_package_xml($pkgid);
OpenPOWER on IntegriCloud