#!/usr/local/bin/php Testing Tab url to go to Testing Tab 2 filename of xml */ require_once("guiconfig.inc"); require_once("xmlparse_pkg.inc"); require_once("pkg-utils.inc"); $pfSense_config = $config; // copy this since we will be parsing // another xml file which will be clobbered. function gentitle_pkg($pgname) { global $pfSense_config; return $pfSense_config['system']['hostname'] . "." . $pfSense_config['system']['domain'] . " - " . $pgname; } // XXX: Make this input safe. $xml = $_GET['xml']; if($_POST['xml']) $xml = $_POST['xml']; if($xml == "") { $xml = "not_defined"; print_info_box_np("ERROR: Could not open " . $xml . "."); die; } else { $pkg = parse_xml_config_pkg("/usr/local/pkg/" . $xml, "packagegui"); } $package_name = $pkg['menu'][0]['name']; $section = $pkg['menu'][0]['section']; $config_path = $pkg['configpath']; $name = $pkg['name']; $title = $section . ": " . $package_name; $id = $_GET['id']; if (isset($_POST['id'])) $id = $_POST['id']; if($pkg['custom_php_global_functions'] <> "") eval($pkg['custom_php_global_functions']); // grab the installedpackages->package_name section. $toeval = "\$a_pkg = &\$config['installedpackages']['" . $name . "']['config'];"; eval($toeval); $toeval = "if (!is_array(\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'])) \$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'] = array();"; eval($toeval); $toeval = "\$a_pkg = &\$config['installedpackages']['" . xml_safe_fieldname($pkg['name']) . "']['config'];"; eval($toeval); if($pkg['custom_php_command_before_form'] <> "") eval($pkg['custom_php_command_before_form']); if ($_POST) { if($_POST['act'] == "del") { if($pkg['custom_delete_php_command']) { if($pkg['custom_php_command_before_form'] <> "") eval($pkg['custom_php_command_before_form']); eval($pkg['custom_delete_php_command']); } write_config(); // resync the configuration file code if defined. if($pkg['custom_php_resync_config_command'] <> "") { if($pkg['custom_php_command_before_form'] <> "") eval($pkg['custom_php_command_before_form']); eval($pkg['custom_php_resync_config_command']); } } else { if($pkg['custom_add_php_command']) { if($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") { ?> <?=gentitle_pkg($title);?>

"; eval($pkg['custom_add_php_command']); if($pkg['preoutput']) echo ""; } } // donotsave is enabled. lets simply exit. if($pkg['donotsave'] <> "") exit; $firstfield = ""; $rows = 0; // store values in xml configration file. if (!$input_errors) { $pkgarr = array(); foreach ($pkg['fields']['field'] as $fields) { if($fields['type'] == "rowhelper") { // save rowhelper items. for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form. // XXX: this really is not helping embedded platforms. foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) { if($firstfield == "") { $firstfield = $rowhelperfield['fieldname']; } else { if($firstfield == $rowhelperfield['fieldname']) $rows++; } $comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];"; //echo($comd . "
"); eval($comd); if($value <> "") { $comd = "\$pkgarr['row'][" . $x . "]['" . $rowhelperfield['fieldname'] . "'] = \"" . $value . "\";"; //echo($comd . "
"); eval($comd); } } } } else { // simply loop through all field names looking for posted // values matching the fieldnames. if found, save to package // configuration area. $fieldname = $fields['fieldname']; $fieldvalue = $_POST[$fieldname]; $toeval = "\$pkgarr['" . $fieldname . "'] = \"" . $fieldvalue . "\";"; eval($toeval); } } if (isset($id) && $a_pkg[$id]) $a_pkg[$id] = $pkgarr; else $a_pkg[] = $pkgarr; write_config(); // late running code if($pkg['custom_add_php_command_late'] <> "") { eval($pkg['custom_add_php_command_late']); } // resync the configuration file code if defined. if($pkg['custom_php_resync_config_command'] <> "") { eval($pkg['custom_php_resync_config_command']); } parse_package_templates(); /* if start_command is defined, restart w/ this */ if($pkg['start_command'] <> "") exec($pkg['start_command'] . ">/dev/null 2&>1"); /* if restart_command is defined, restart w/ this */ if($pkg['restart_command'] <> "") exec($pkg['restart_command'] . ">/dev/null 2&>1"); if($pkg['aftersaveredirect'] <> "") { header("Location: " . $pkg['aftersaveredirect']); } else { if(!$pkg['preoutput']) header("Location: pkg.php?xml=" . $xml); } exit; } } ?> "") $title = $pkg['title']; ?> <?=gentitle_pkg($title);?>

"") { echo ""; echo ""; echo ""; echo "
"; echo "
    "; foreach($pkg['tabs']['tab'] as $tab) { $active = "tabinact"; if(isset($tab['active'])) $active = "tabact"; $urltmp = ""; $title = $tab['text']; if($tab['url'] <> "") $urltmp = $tab['url']; if($tab['xml'] <> "") $urltmp = "pkg_edit.php?xml=" . $tab['xml']; $toeval = "\$myurl = \"" . getenv("HTTP_HOST") . "\"; \n"; eval($toeval); // eval url so that above $myurl item can be processed if need be. $toeval = "\$url = \"" . $urltmp . "\"; \n"; eval($toeval); if($active == "tabinact") { echo "
  • "; echo ""; echo $title; echo ""; echo "
  • "; } else { echo "
  • "; echo $title; echo "
  • "; } } echo "
"; echo "
"; } ?> "") $savevalue = $pkg['savetext']; foreach ($pkg['fields']['field'] as $pkga) { ?> "; ?> "; echo fixup_string($pkga['fielddescr']); echo ""; } if(!$pkga['dontcombinecells']) echo ""; $i++; } ?>
"; // if user is editing a record, load in the data. if (isset($id) && $a_pkg[$id]) { $fieldname = $pkga['fieldname']; $toeval = "\$value = \$a_pkg[" . $id . "]['" . $fieldname . "'];"; echo "\n"; eval($toeval); } if($pkga['type'] == "input") { if($pkga['size']) $size = " size='" . $pkga['size'] . "' "; echo "\n"; echo "
" . fixup_string($pkga['description']) . "\n"; } else if($pkga['type'] == "password") { echo "\n"; echo "
" . fixup_string($pkga['description']) . "\n"; } else if($pkga['type'] == "select") { // XXX: TODO: set $selected if($pkga['size']) $size = " size='" . $pkga['size'] . "' "; if($pkga['multiple'] == "yes") $multiple = "MULTIPLE "; echo "\n"; echo "
" . fixup_string($pkga['description']) . "\n"; } else if($pkga['type'] == "vpn_selection") { echo "\n"; echo "
" . fixup_string($pkga['description']) . "\n"; } else if($pkga['type'] == "checkbox") { $checkboxchecked = ""; if($value == "on") $checkboxchecked = " CHECKED"; echo "\n"; echo "
" . fixup_string($pkga['description']) . "\n"; } else if($pkga['type'] == "textarea") { if($pkga['rows']) $rows = " rows='" . $pkga['rows'] . "' "; if($pkga['cols']) $cols = " cols='" . $pkga['cols'] . "' "; echo "\n"; echo "
" . fixup_string($pkga['description']) . "\n"; } else if($pkga['type'] == "interfaces_selection") { $size = ""; $multiple = ""; $fieldname = $pkga['fieldname']; if($pkga['size'] <> "") $size = " size=\"" . $pkga['size'] . "\""; if($pkga['multiple'] <> "" and $pkga['multiple'] <> "0") { $multiple = " multiple=\"multiple\""; $fieldname .= "[]"; } echo "\n"; echo "
" . fixup_string($pkga['description']) . "\n"; } else if($pkga['type'] == "radio") { echo ""; } else if($pkga['type'] == "rowhelper") { ?> " . fixup_string($rowhelper['fielddescr']) . "\n"; } echo ""; echo ""; echo ""; // XXX: traverse saved fields, add back needed rows. echo ""; echo "\n"; $rowcounter = 0; $trc = 0; if(isset($a_pkg[$id]['row'])) { foreach($a_pkg[$id]['row'] as $row) { /* * loop through saved data for record if it exists, populating rowhelper */ foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) { 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]) { $toeval = "\$value = \$row['" . $fieldname . "'];"; echo "\n"; eval($toeval); echo "\n"; } $options = ""; $type = $rowhelper['type']; $fieldname = $rowhelper['fieldname']; if($type == "option") $options = &$rowhelper['options']['option']; $size = "8"; if($rowhelper['size'] <> "") $size = $rowhelper['size']; display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size); // javascript helpers for row_helper_dynamic.js echo "\n"; echo "\n"; $text = ""; $trc++; } $rowcounter++; echo "\n"; echo "\n"; } } if($trc == 0) { /* * no records loaded. * just show a generic line non-populated with saved data */ foreach($pkga['rowhelper']['rowhelperfield'] as $rowhelper) { if($rowhelper['value'] <> "") $value = $rowhelper['value']; $fieldname = $rowhelper['fieldname']; $options = ""; $type = $rowhelper['type']; $fieldname = $rowhelper['fieldname']; if($type == "option") $options = &$rowhelper['options']['option']; $size = "8"; if($rowhelper['size'] <> "") $size = $rowhelper['size']; display_row($rowcounter, $value, $fieldname, $type, $rowhelper, $size); // javascript helpers for row_helper_dynamic.js echo "\n"; echo "\n"; $text = ""; $trc++; } $rowcounter++; } ?>
"; echo ""; echo "

 
 
"") { echo "
"; } ?> "") echo "
" . $pkga['note'] . "
"; ?>
\n"; if($type == "input") { echo "\n"; } else if($type == "password") { echo "\n"; } else if($type == "textarea") { echo "\n"; } else if($type == "select") { echo "\n"; } } function fixup_string($string) { global $config; // fixup #1: $myurl -> http[s]://ip_address:port/ $https = ""; $port = ""; $urlport = ""; $port = $config['system']['webguiport']; if($port <> "443" and $port <> "80") $urlport = ":" . $port; if($config['system']['webguiproto'] == "https") $https = "s"; $myurl = "http" . $https . "://" . getenv("HTTP_HOST") . $urlportport; $newstring = str_replace("\$myurl", $myurl, $string); $string = $newstring; // fixup #2: $wanip $curwanip = get_current_wan_address(); $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, $config; 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 */ foreach ($pkg['fields']['field'] as $fields) { if($fields['type'] == "rowhelper") { // save rowhelper items. $row_helper_total_rows = 0; for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form. foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) { if($firstfield == "") { $firstfield = $rowhelperfield['fieldname']; } else { if($firstfield == $rowhelperfield['fieldname']) $rows++; } $comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];"; eval($comd); if($value <> "") { //$template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $template_text); } else { $row_helper_total_rows = $rows; break; } } } } } /* replace $domain_total_rows with total rows */ $template_text = str_replace("$domain_total_rows", $row_helper_total_rows, $template_text); /* change fields defined as fieldname_fieldvalue to their value */ foreach ($pkg['fields']['field'] as $fields) { if($fields['type'] == "rowhelper") { // save rowhelper items. for($x=0; $x<99; $x++) { // XXX: this really should be passed from the form. $row_helper_data = ""; $isfirst = 0; foreach($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) { if($firstfield == "") { $firstfield = $rowhelperfield['fieldname']; } else { if($firstfield == $rowhelperfield['fieldname']) $rows++; } $comd = "\$value = \$_POST['" . $rowhelperfield['fieldname'] . $x . "'];"; eval($comd); if($value <> "") { if($isfirst == 1) $row_helper_data .= " " ; $row_helper_data .= $value; $isfirst = 1; } ereg($rowhelperfield['fieldname'] . "_fieldvalue\[(.*)\]", $template_text, $sep); foreach ($sep as $se) $seperator = $se; if($seperator <> "") { $row_helper_data = ereg_replace(" ", $seperator, $row_helper_data); $template_text = ereg_replace("\[" . $seperator . "\]", "", $template_text); } $template_text = str_replace($rowhelperfield['fieldname'] . "_fieldvalue", $row_helper_data, $template_text); } } } else { $fieldname = $fields['fieldname']; $fieldvalue = $_POST[$fieldname]; $template_text = str_replace($fieldname . "_fieldvalue", $fieldvalue, $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); } } ?>