From eb3743d898f322ef4a08929e68e2be95aebb8047 Mon Sep 17 00:00:00 2001 From: Stephen Beaver Date: Tue, 29 Sep 2015 09:23:31 -0400 Subject: Fil;e conversion complete. Tested against multiple packages --- src/usr/local/www/pkg_edit.php | 1694 ++++++++++++++++++++++------------------ 1 file changed, 947 insertions(+), 747 deletions(-) (limited to 'src/usr/local/www/pkg_edit.php') 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, '', $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, '', $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 "\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']; +} + +$grouping = false; // Indicates the elements we are composing are part of a combined group - configured, then setup - * the table rows for the fields that have 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'); - } +$form = new Form(new Form_Button( + 'submit', + $savevalue +)); - $js_array = array(); +$form->addGlobal(new Form_Input( + 'xml', + null, + 'hidden', + $xml +)); - foreach ($pkg['fields']['field'] as $pkga) { - if ($pkga['type'] == "sorting") { - continue; - } +/* If a package's XML has configured, then setup + * ta section for the fields that have 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'. + */ - // Generate a new section +if ($pkg['advanced_options'] == "enabled") { + $advfield_count = 0; + $advanced = new Form_Section(gettext("Advanced features")); + $advanced->addClass('advancedoptions'); +} - if ($pkga['type'] == "listtopic") { - if (isset($pkga['advancedfield']) && isset($advfield_count)) { - $advanced->addInput(new Form_StaticText( - $pkga['name'], - null - )); +$js_array = array(); - $advfield_count++; - } else { - if(isset($section)) - $form->add($section); +// Now loop through all of hte fields defined in the XML +foreach ($pkg['fields']['field'] as $pkga) { - $section = new Form_Section($pkga['name']); - } + if ($pkga['type'] == "sorting") { + continue; + } - continue; - } + // 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 + )); - if ($pkga['combinefields'] == "begin") { - print('begin not yet converted
'); -/* - $input=""; - if (isset($pkga['advancedfield']) && isset($advfield_count)) { - $advanced .= $input; - } else { - echo $input; - } -*/ - } + $advfield_count++; + } else { + if(isset($section)) + $form->add($section); - $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 .= ""; - } - if (isset($pkga['usecolspan2'])) { - $colspan="colspan='2'"; - } else { - $input .= " "; - } - 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 .= ""; - } - $input .= ""; - $input .= fixup_string($pkga['fielddescr']); - $input .= ""; - if (isset($pkga['advancedfield']) && isset($advfield_count)) { - $advanced .= $input; - $advfield_count++; - } else { - echo $input; - } + $section = new Form_Section(strip_tags($pkga['name'])); } - if ($pkga['combinefields'] == "begin") { - $input=""; - if (isset($pkga['advancedfield']) && isset($advfield_count)) { - $advanced .= $input; - } else { - echo $input; - } - } + continue; + } - $class=(isset($pkga['combinefields']) ? '' : 'class="vtable"'); - if (!isset($pkga['placeonbottom'])) { - $input=""; - } - // At the end of the combined fields we finish up the table that encloses the combined fields... - if ($pkga['combinefields'] == "end") { - $input .= "
"; - if (isset($pkga['advancedfield']) && isset($advfield_count)) { - $advanced .= $input; - $advfield_count++; - } else { - echo $input; - } + // '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'], '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
'); -/* - // Use xml tag 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 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 = "\n
"; - $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 = ""; - 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 . '
' . '
' . fixup_string($pkga['description']) . '
' + )); + } else { + if (isset($pkga['advancedfield']) && isset($advfield_count)) { + $advanced->addInput(new Form_StaticText( + null, + $newbtn . '
' . '
' . fixup_string($pkga['description']) . '
' + )); + } else { $section->addInput(new Form_StaticText( null, $newbtn . '
' . '
' . fixup_string($pkga['description']) . '
' )); + } + } - break; + break; - case "schedule_selection": + case "schedule_selection": - $input = "\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"; - ?> - - - '> - " . fixup_string($rowhelper['fielddescr']) . "\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 "\n\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 "\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++; } - ?> - - -
"; - #echo "\"remove\""; - echo "delete"; - echo "
- - -
add -
- - - "; - // 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 .= "
"; - } - } else { - $input = ""; - if ($pkga['usecolspan2']) { - $input .= "
"; - } - } + // 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'); -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'] != "") { ?>