Commit 4a674804 authored by Ad Schellevis's avatar Ad Schellevis

(legacy) refactor system_advanced_sysctl.php

parent 1d744002
...@@ -32,90 +32,109 @@ ...@@ -32,90 +32,109 @@
require_once("guiconfig.inc"); require_once("guiconfig.inc");
require_once("system.inc"); require_once("system.inc");
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_advanced_sysctl.php'); if (!isset($config['sysctl']['item']) || !is_array($config['sysctl']['item'])) {
if (!is_array($config['sysctl']['item'])) {
$config['sysctl']['item'] = array(); $config['sysctl']['item'] = array();
} }
$a_tunable = &$config['sysctl']['item']; $a_tunable = &$config['sysctl']['item'];
if (is_numericint($_GET['id'])) { if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['id']) && isset($a_tunable[$_GET['id']])) {
$id = $_GET['id']; $id = $_GET['id'];
} }
if (isset($_POST['id']) && is_numericint($_POST['id'])) { if (isset($_GET['act'])) {
$id = $_POST['id']; $act = $_GET['act'];
} } else {
$act = null;
$act = $_GET['act']; }
if (isset($_POST['act'])) { $pconfig = array();
$act = $_POST['act']; if (isset($id)) {
}
if ($act == "edit") {
if ($a_tunable[$id]) {
$pconfig['tunable'] = $a_tunable[$id]['tunable']; $pconfig['tunable'] = $a_tunable[$id]['tunable'];
$pconfig['value'] = $a_tunable[$id]['value']; $pconfig['value'] = $a_tunable[$id]['value'];
$pconfig['descr'] = $a_tunable[$id]['descr']; $pconfig['descr'] = $a_tunable[$id]['descr'];
} else {
$pconfig['tunable'] = null;
$pconfig['value'] = null;
$pconfig['descr'] = null;
} }
} } elseif ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_POST['id']) && isset($a_tunable[$_POST['id']])) {
$id = $_POST['id'];
}
if (isset($_POST['act'])) {
$act = $_POST['act'];
} else {
$act = null;
}
$pconfig = $_POST;
if ($act == "del") { if (isset($id) && $act == "del") {
if ($a_tunable[$id]) {
if (!$input_errors) {
unset($a_tunable[$id]); unset($a_tunable[$id]);
write_config(); write_config();
mark_subsystem_dirty('sysctl'); mark_subsystem_dirty('sysctl');
header("Location: system_advanced_sysctl.php"); header("Location: system_advanced_sysctl.php");
exit; exit;
} } else if (!empty($pconfig['apply'])) {
}
}
if ($_POST) {
unset($input_errors);
$pconfig = $_POST;
if ($_POST['apply']) {
$retval = 0;
system_setup_sysctl(); system_setup_sysctl();
$savemsg = get_std_save_message();
clear_subsystem_dirty('sysctl'); clear_subsystem_dirty('sysctl');
} header("Location: system_advanced_sysctl.php");
exit;
if ($_POST['Submit'] == gettext("Save")) { } elseif (!empty($pconfig['Submit'])) {
$tunableent = array(); $tunableent = array();
$tunableent['tunable'] = $pconfig['tunable'];
$tunableent['value'] = $pconfig['value'];
$tunableent['descr'] = $pconfig['descr'];
$tunableent['tunable'] = $_POST['tunable']; if (isset($id)) {
$tunableent['value'] = $_POST['value'];
$tunableent['descr'] = $_POST['descr'];
if (isset($id) && $a_tunable[$id]) {
$a_tunable[$id] = $tunableent; $a_tunable[$id] = $tunableent;
} else { } else {
$a_tunable[] = $tunableent; $a_tunable[] = $tunableent;
} }
mark_subsystem_dirty('sysctl'); mark_subsystem_dirty('sysctl');
write_config(); write_config();
header("Location: system_advanced_sysctl.php"); header("Location: system_advanced_sysctl.php");
exit; exit;
} }
} }
$pgtitle = array(gettext('System'), gettext('Settings'), gettext('Tunables')); legacy_html_escape_form_data($a_tunable);
if ($act != 'edit') { if ($act != 'edit') {
$main_buttons = array( $main_buttons = array(
array('href' => 'system_advanced_sysctl.php?act=edit', 'label' => gettext('Add a new tunable')), array('href' => 'system_advanced_sysctl.php?act=edit', 'label' => gettext('Add a new tunable')),
); );
} }
include("head.inc"); include("head.inc");
?> ?>
<body> <body>
<script type="text/javascript">
$( document ).ready(function() {
// delete entry
$(".act_delete").click(function(event){
event.preventDefault();
var id = $(this).data('id');
BootstrapDialog.show({
type:BootstrapDialog.TYPE_INFO,
title: "<?= gettext("Tunable");?>",
message: "<?=gettext("Do you really want to delete this entry?");?>",
buttons: [{
label: "<?=gettext("No");?>",
action: function(dialogRef) {
dialogRef.close();
}}, {
label: "<?=gettext("Yes");?>",
action: function(dialogRef) {
$("#id").val(id);
$("#action").val("del");
$("#iform").submit()
}
}]
});
});
});
</script>
<?php include("fbegin.inc"); ?> <?php include("fbegin.inc"); ?>
...@@ -123,76 +142,59 @@ include("head.inc"); ...@@ -123,76 +142,59 @@ include("head.inc");
<section class="page-content-main"> <section class="page-content-main">
<div class="container-fluid"> <div class="container-fluid">
<div class="row"> <div class="row">
<form action="system_advanced_sysctl.php" method="post"> <?php
<?php
if (isset($input_errors) && count($input_errors) > 0) {
print_input_errors($input_errors);
}
if (isset($savemsg)) { if (isset($savemsg)) {
print_info_box($savemsg); print_info_box($savemsg);
} }
if (is_subsystem_dirty('sysctl') && ($act != "edit" )) { if (is_subsystem_dirty('sysctl') && ($act != "edit" )) {
print_info_box_apply(gettext("The firewall tunables have changed. You must apply the configuration to take affect.")); print_info_box_apply(gettext("The firewall tunables have changed. You must apply the configuration to take affect."));
} }
?> ?>
<form action="system_advanced_sysctl.php" method="post" id="iform">
<input type="hidden" id="id" name="id" value="" />
<input type="hidden" id="action" name="act" value="" />
</form> </form>
<section class="col-xs-12"> <section class="col-xs-12">
<div class="table-responsive content-box tab-content" style="overflow: auto;"> <div class="table-responsive content-box tab-content" style="overflow: auto;">
<?php if ($act != "edit") : <?php
?> if ($act != "edit") :?>
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="main area" class="table table-striped"> <table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th width="20%"><?=gettext("Tunable Name"); ?></th> <th><?=gettext("Tunable Name"); ?></th>
<th width="60%"><?=gettext("Description"); ?></th> <th><?=gettext("Description"); ?></th>
<th width="20%" colspan="2"><?=gettext("Value"); ?></th> <th><?=gettext("Value"); ?></th>
<th></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $i = 0; foreach ($config['sysctl']['item'] as $tunable) : <?php
?> $i = 0;
foreach ($a_tunable as $tunable) :?>
<tr> <tr>
<td class="listlr" ondblclick="document.location='system_advanced_sysctl.php?act=edit&amp;id=<?=$i;?>';"> <td><?=$tunable['tunable']; ?></td>
<?php echo $tunable['tunable']; ?> <td><?=$tunable['descr']; ?></td>
<td>
<?=$tunable['value']; ?>
<?=$tunable['value'] == "default" ? "(" . get_default_sysctl_value($tunable['tunable']) . ")" : "";?>
</td> </td>
<td class="listr" align="left" ondblclick="document.location='system_advanced_sysctl.php?act=edit&amp;id=<?=$i;?>';"> <td>
<?php echo $tunable['descr']; ?>
</td>
<td class="listr" align="left" ondblclick="document.location='system_advanced_sysctl.php?act=edit&amp;id=<?=$i;?>';">
<?php echo $tunable['value']; ?>
<?php
if ($tunable['value'] == "default") {
echo "(" . get_default_sysctl_value($tunable['tunable']) . ")";
}
?>
</td>
<td class="list nowrap">
<table border="0" cellspacing="0" cellpadding="1" summary="edit delete">
<tr>
<td valign="middle">
<a href="system_advanced_sysctl.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs"> <a href="system_advanced_sysctl.php?act=edit&amp;id=<?=$i;?>" class="btn btn-default btn-xs">
<span data-toggle="tooltip" data-placement="left" title="<?=gettext("Edit Tunable"); ?>" class="glyphicon glyphicon-pencil"></span> <span data-toggle="tooltip" data-placement="left" title="<?=gettext("Edit Tunable"); ?>" class="glyphicon glyphicon-pencil"></span>
</a> </a>
</td> <a id="del_<?=$i;?>" data-id="<?=$i;?>" title="<?=gettext("Delete Tunable"); ?>" data-toggle="tooltip" class="act_delete btn btn-default btn-xs">
<td valign="middle"> <span class="glyphicon glyphicon-remove"></span>
<a href="system_advanced_sysctl.php?act=del&amp;id=<?=$i;
?>" onclick="return confirm('<?=gettext("Do you really want to delete this entry?"); ?>')" class="btn btn-default btn-xs">
<span data-toggle="tooltip" data-placement="left" title="<?=gettext("Delete Tunable"); ?>" class="glyphicon glyphicon-remove"></span>
</a> </a>
</td> </td>
</tr> </tr>
</table> <?php
</td> $i++; endforeach; ?>
</tr>
<?php $i++; endforeach; ?>
</tbody> </tbody>
</table> </table>
<?php else : ?> <?php
<form action="system_advanced_sysctl.php" method="post" name="iform" id="iform"> else : ?>
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="edit system tunable" class="table table-striped"> <form action="system_advanced_sysctl.php" method="post">
<table class="table table-striped">
<thead> <thead>
<tr> <tr>
<th colspan="2" valign="top" class="listtopic"><?=gettext("Edit system tunable"); ?></th> <th colspan="2" valign="top" class="listtopic"><?=gettext("Edit system tunable"); ?></th>
...@@ -200,46 +202,44 @@ include("head.inc"); ...@@ -200,46 +202,44 @@ include("head.inc");
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Tunable"); ?></td> <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Tunable"); ?></td>
<td width="78%" class="vtable"> <td>
<input size="65" name="tunable" type="text" value="<?php echo $pconfig['tunable']; ?>" /> <input type="text" name="tunable" value="<?=$pconfig['tunable']; ?>" />
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Description"); ?></td> <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Description"); ?></td>
<td width="78%" class="vtable"> <td>
<textarea name="descr"><?php echo $pconfig['descr']; ?></textarea> <textarea name="descr"><?=$pconfig['descr']; ?></textarea>
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top" class="vncellreq"><?=gettext("Value"); ?></td> <td><i class="fa fa-info-circle text-muted"></i> <?=gettext("Value"); ?></td>
<td width="78%" class="vtable"> <td>
<input size="65" name="value" type="text" value="<?php echo $pconfig['value']; ?>" /> <input name="value" type="text" value="<?=$pconfig['value']; ?>" />
</td> </td>
</tr> </tr>
<tr> <tr>
<td width="22%" valign="top">&nbsp;</td> <td>&nbsp;</td>
<td width="78%"> <td>
<input id="submit" name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" /> <input name="Submit" type="submit" class="btn btn-primary" value="<?=gettext("Save"); ?>" />
<input type="button" class="btn btn-default" value="<?=gettext("Cancel"); <input type="button" class="btn btn-default" value="<?=gettext("Cancel");?>" onclick="window.location.href='<?=(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/system_advanced_sysctl.php');?>'" />
?>" onclick="window.location.href='<?=$referer;?>'" />
<?php if (isset($id) && $a_tunable[$id]) : <?php
?> if (isset($id)) :?>
<input name="id" type="hidden" value="<?=htmlspecialchars($id);?>" /> <input name="id" type="hidden" value="<?=$id;?>" />
<?php <?php
endif; ?> endif; ?>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
</form> </form>
<?php <?php
endif; ?> endif; ?>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</section> </section>
<?php include("foot.inc"); <?php include("foot.inc");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment