Commit 899557c4 authored by Franco Fichtner's avatar Franco Fichtner

filter: improve status reload page

(cherry picked from commit 877ad265)
parent e29b8461
...@@ -169,7 +169,7 @@ function filter_configure_sync($delete_states_if_needed = true) ...@@ -169,7 +169,7 @@ function filter_configure_sync($delete_states_if_needed = true)
filter_pflog_start(); filter_pflog_start();
update_filter_reload_status(gettext("Initializing")); update_filter_reload_status(gettext("Initializing"), true);
/* Get interface list to work with. */ /* Get interface list to work with. */
filter_generate_optcfg_array(); filter_generate_optcfg_array();
......
...@@ -1115,9 +1115,19 @@ function format_bytes($bytes) { ...@@ -1115,9 +1115,19 @@ function format_bytes($bytes) {
} }
} }
function update_filter_reload_status($text) function update_filter_reload_status($text, $first = false)
{ {
file_put_contents('/var/run/filter_reload_status', $text); $filter_reload_status = '/var/run/filter_reload_status';
if ($first) {
@unlink($filter_reload_status);
}
file_put_contents(
$filter_reload_status,
sprintf("%s: %s\n", microtime(true), $text),
FILE_APPEND
);
} }
/****** util/return_dir_as_array /****** util/return_dir_as_array
......
...@@ -31,14 +31,15 @@ require_once("guiconfig.inc"); ...@@ -31,14 +31,15 @@ require_once("guiconfig.inc");
$pgtitle = array(gettext("Status"),gettext("Filter Reload Status")); $pgtitle = array(gettext("Status"),gettext("Filter Reload Status"));
$shortcut_section = "firewall"; $shortcut_section = "firewall";
if (file_exists('/var/run/filter_reload_status')) {
$status = file_get_contents('/var/run/filter_reload_status');
}
if($_GET['getstatus']) { if($_GET['getstatus']) {
echo "|{$status}|"; $status = '';
if (file_exists('/var/run/filter_reload_status')) {
$status = file_get_contents('/var/run/filter_reload_status');
}
echo $status;
exit; exit;
} }
if($_POST['reloadfilter']) { if($_POST['reloadfilter']) {
configd_run("filter reload"); configd_run("filter reload");
if ( isset($config['hasync']['synchronizetoip']) && trim($config['hasync']['synchronizetoip']) != "") { if ( isset($config['hasync']['synchronizetoip']) && trim($config['hasync']['synchronizetoip']) != "") {
...@@ -71,24 +72,13 @@ include("head.inc"); ...@@ -71,24 +72,13 @@ include("head.inc");
<div class="content-box "> <div class="content-box ">
<div class="col-xs-12"> <div class="col-xs-12">
<br /> <p><form action="status_filter_reload.php" method="post" name="filter">
<form action="status_filter_reload.php" method="post" name="filter">
<input type="submit" value="Reload Filter" class="btn btn-primary" name="reloadfilter" id="reloadfilter" /> <input type="submit" value="Reload Filter" class="btn btn-primary" name="reloadfilter" id="reloadfilter" />
<?php if ($config['hasync'] && $config['hasync']["synchronizetoip"] != ""): ?> <?php if ($config['hasync'] && $config['hasync']["synchronizetoip"] != ""): ?>
<input type="submit" value="Force Config Sync" class="btn btn-primary" name="syncfilter" id="syncfilter" /> <input type="submit" value="Force Config Sync" class="btn btn-primary" name="syncfilter" id="syncfilter" />
<?php endif; ?> <?php endif; ?>
</form> </form></p>
<br /><br /><br /> <pre id="status"></pre>
<div id="status" class="well">
<?php echo $status; ?>
</div>
</div>
<br/>
<div id="reloadinfo"><?=gettext("This page will automatically refresh every 3 seconds until the filter is done reloading"); ?>.</div>
</div> </div>
</div> </div>
</section> </section>
...@@ -105,22 +95,8 @@ function update_status_thread() { ...@@ -105,22 +95,8 @@ function update_status_thread() {
} }
function update_data(obj) { function update_data(obj) {
var result_text = obj.content; var result_text = obj.content;
var result_text_split = result_text.split("|"); jQuery('#status').html(result_text);
result_text = result_text_split[1]; window.setTimeout('update_status_thread()', 200);
result_text = result_text.replace("\n","");
result_text = result_text.replace("\r","");
if (result_text) {
jQuery('#status').html('<span class="glyphicon glyphicon-refresh"></span> ' + result_text + '...');
} else {
jQuery('#status').html('<span class="glyphicon glyphicon-refresh"></span> Obtaining filter status...');
}
if(result_text == "Initializing") {
jQuery('#status').html('<span class="glyphicon glyphicon-refresh"></span> Initializing...');
} else if(result_text == "Done") {
jQuery('#status').html('Done. The filter rules have been reloaded.');
jQuery('#reloadinfo').css("visibility","hidden");
}
window.setTimeout('update_status_thread()', 2500);
} }
//]]> //]]>
</script> </script>
...@@ -170,7 +146,7 @@ if (typeof getURL == 'undefined') { ...@@ -170,7 +146,7 @@ if (typeof getURL == 'undefined') {
http_request.send(null); http_request.send(null);
} }
} }
window.setTimeout('update_status_thread()', 2500); update_status_thread();
//]]> //]]>
</script> </script>
......
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