All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/*
pfSense_BUILDER_BINARIES: /sbin/ifconfig
pfSense_MODULE: pkgs
*/
##|+PRIV
##|*IDENT=page-package-edit
##|*NAME=Package: Edit page
##|*DESCR=Allow access to the 'Package: Edit' page.
##|*MATCH=pkg_edit.php*
##|-PRIV
ini_set('max_execution_time', '0');
require("guiconfig.inc");
require_once("functions.inc");
require_once("filter.inc");
require_once("shaper.inc");
require_once("pkg-utils.inc");
/* dummy stubs needed by some code that was MFC'd */
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');\"";
}
}
$xml = htmlspecialchars($_GET['xml']);
if ($_POST['xml']) {
$xml = htmlspecialchars($_POST['xml']);
}
$xml_fullpath = realpath('/usr/local/pkg/' . $xml);
if ($xml == "" || $xml_fullpath === false ||
substr($xml_fullpath, 0, strlen('/usr/local/pkg/')) != '/usr/local/pkg/') {
print_info_box_np(gettext("ERROR: No valid package defined."));
die;
} else {
$pkg = parse_xml_config_pkg($xml_fullpath, "packagegui");
}
if ($pkg['include_file'] <> "") {
require_once($pkg['include_file']);
}
if (!isset($pkg['adddeleteeditpagefields'])) {
$only_edit = true;
} else {
$only_edit = false;
}
$id = $_GET['id'];
if (isset($_POST['id'])) {
$id = htmlspecialchars($_POST['id']);
}
// Not posting? Then user is editing a record. There must be a valid id
// when editing a record.
if (!$id && !$_POST) {
$id = "0";
}
if (!is_numeric($id)) {
header("Location: /");
exit;
}
if ($pkg['custom_php_global_functions'] <> "") {
eval($pkg['custom_php_global_functions']);
}
// grab the installedpackages->package_name section.
if ($config['installedpackages'] && !is_array($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'])) {
$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'] = array();
}
// If the first entry in the array is an empty tag, kill it.
if ($config['installedpackages'] && (count($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']) > 0)
&& ($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'][0] == "")) {
array_shift($config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config']);
}
$a_pkg = &$config['installedpackages'][xml_safe_fieldname($pkg['name'])]['config'];
if ($_GET['savemsg'] <> "") {
$savemsg = htmlspecialchars($_GET['savemsg']);
}
if ($pkg['custom_php_command_before_form'] <> "") {
eval($pkg['custom_php_command_before_form']);
}
if ($_POST) {
$rows = 0;
$input_errors = array();
$reqfields = array();
$reqfieldsn = array();
foreach ($pkg['fields']['field'] as $field) {
if (($field['type'] == 'input') && isset($field['required'])) {
if ($field['fieldname']) {
$reqfields[] = $field['fieldname'];
}
if ($field['fielddescr']) {
$reqfieldsn[] = $field['fielddescr'];
}
}
}
do_input_validation($_POST, $reqfields, $reqfieldsn, $input_errors);
if ($pkg['custom_php_validation_command']) {
eval($pkg['custom_php_validation_command']);
}
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($pkg['delete_string']);
// 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 (!$input_errors && $pkg['custom_add_php_command']) {
if ($pkg['donotsave'] <> "" or $pkg['preoutput'] <> "") {
?>
";
}
eval($pkg['custom_add_php_command']);
if ($pkg['preoutput']) {
echo "";
}
}
}
// donotsave is enabled. lets simply exit.
if (empty($pkg['donotsave'])) {
// store values in xml configuration file.
if (!$input_errors) {
$pkgarr = array();
foreach ($pkg['fields']['field'] as $fields) {
switch ($fields['type']) {
case "rowhelper":
// save rowhelper items.
#$rowhelpername=($fields['fieldname'] ? $fields['fieldname'] : "row");
$rowhelpername="row";
foreach ($fields['rowhelper']['rowhelperfield'] as $rowhelperfield) {
foreach ($_POST as $key => $value) {
$matches = array();
if (preg_match("/^{$rowhelperfield['fieldname']}(\d+)$/", $key, $matches)) {
$pkgarr[$rowhelpername][$matches[1]][$rowhelperfield['fieldname']] = $value;
}
}
}
break;
default:
$fieldname = $fields['fieldname'];
if ($fieldname == "interface_array") {
$fieldvalue = $_POST[$fieldname];
} elseif (is_array($_POST[$fieldname])) {
$fieldvalue = implode(',', $_POST[$fieldname]);
} else {
$fieldvalue = trim($_POST[$fieldname]);
if ($fields['encoding'] == 'base64') {
$fieldvalue = base64_encode($fieldvalue);
}
}
if ($fieldname) {
$pkgarr[$fieldname] = $fieldvalue;
}
}
}
if (isset($id) && $a_pkg[$id]) {
$a_pkg[$id] = $pkgarr;
} else {
$a_pkg[] = $pkgarr;
}
write_config($pkg['addedit_string']);
// late running code
if ($pkg['custom_add_php_command_late'] <> "") {
eval($pkg['custom_add_php_command_late']);
}
if (isset($pkg['filter_rules_needed'])) {
filter_configure();
}
// 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'] <> "") {
pfSenseHeader($pkg['aftersaveredirect']);
} elseif (!$pkg['adddeleteeditpagefields']) {
pfSenseHeader("pkg_edit.php?xml={$xml}&id=0");
} elseif (!$pkg['preoutput']) {
pfSenseHeader("pkg.php?xml=" . $xml);
}
exit;
} else {
$get_from_post = true;
}
} elseif (!$input_errors) {
exit;
}
}
if ($pkg['title'] <> "") {
$edit = ($only_edit ? '' : ": " . gettext("Edit"));
$pgtitle = $pkg['title'] . $edit;
} else {
$pgtitle = gettext("Package Editor");
}
if ($pkg['custom_php_after_head_command']) {
$closehead = false;
include("head.inc");
eval($pkg['custom_php_after_head_command']);
echo "\n";
} else {
include("head.inc");
}
?>
"") { ?>
\n";
echo "//\n";
echo "\n";
}
?>