From 03afdafaab503af22ce5c98ad06b9f6bbc459974 Mon Sep 17 00:00:00 2001 From: NOYB Date: Sun, 17 Apr 2016 00:18:33 -0700 Subject: Alias Tables RAM Disk Store If ramdisk is enabled keep a copy of the alias tables to restore at boot time. Otherwise unpredictable behavior may occur due to some aliases not being available when the firewall rules load. Because alias tables are typically somewhat static, the following strategies are employed to keep write cycles to a minimum for SSD and flash drive type devices friendliness. 1) Back up during reboot/shutdown only if a backup copy of the alias table does not already exists. This is typically during the reboot when ramdisk is first enabled. 2) Update the backup copy only when the alias table is updated with a new download, typically 1 or more days, as configured in the firewall alias. --- src/etc/inc/pfsense-utils.inc | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'src/etc/inc/pfsense-utils.inc') diff --git a/src/etc/inc/pfsense-utils.inc b/src/etc/inc/pfsense-utils.inc index 77ca8e2..71219fb 100644 --- a/src/etc/inc/pfsense-utils.inc +++ b/src/etc/inc/pfsense-utils.inc @@ -2151,7 +2151,7 @@ function pfs_version_compare($cur_time, $cur_text, $remote) { return $v; } function process_alias_urltable($name, $url, $freq, $forceupdate=false, $validateonly=false) { - global $config; + global $g, $config; $urltable_prefix = "/var/db/aliastables/"; $urltable_filename = $urltable_prefix . $name . ".txt"; @@ -2187,6 +2187,13 @@ function process_alias_urltable($name, $url, $freq, $forceupdate=false, $validat file_put_contents($urltable_filename, implode("\n", $urltable)); } } + /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ + if (($g['platform'] == $g['product_name']) && !isset($config['system']['use_mfs_tmpvar'])) { + unlink_if_exists("{$g['cf_conf_path']}/RAM_Disk_Store{$urltable_filename}.tgz"); + } else { + /* Update the RAM disk store with the new/updated table file. */ + mwexec("cd / && /usr/bin/tar -czf \"{$g['cf_conf_path']}/RAM_Disk_Store{$urltable_filename}.tgz\" -C / \"{$urltable_filename}\""); + } unlink_if_exists($tmp_urltable_filename); } else { if (!$validateonly) { @@ -3085,4 +3092,36 @@ function pkg_call_plugins($plugin_type, $plugin_params) { return $results; } +function restore_aliastables() { + global $g, $config; + + $dbpath = "{$g['vardb_path']}/aliastables/"; + + /* restore the alias tables, if we have them */ + $files = glob("{$g['cf_conf_path']}/RAM_Disk_Store{$dbpath}*.tgz"); + if (count($files)) { + echo "Restoring alias tables..."; + foreach ($files as $file) { + if (file_exists($file)) { + $aliastablesrestore = ""; + $aliastablesreturn = ""; + exec("cd /;LANG=C /usr/bin/tar -xzf {$file} 2>&1", $aliastablesrestore, $aliastablesreturn); + $aliastablesrestore = implode(" ", $aliastablesrestore); + if ($aliastablesreturn <> 0) { + log_error(sprintf(gettext('Alias table restore failed exited with %1$s, the error is: %2$s %3$s%4$s'), $aliastablesreturn, $aliastablesrestore, $file, "\n")); + } else { + log_error(sprintf(gettext('Alias table restore succeeded exited with %1$s, the result is: %2$s %3$s%4$s'), $aliastablesreturn, $aliastablesrestore, $dbpath.basename($file, ".tgz"), "\n")); + } + } + /* If this backup is still there on a full install, but we aren't going to use ram disks, remove the archive since this is a transition. */ + if (($g['platform'] == $g['product_name']) && !isset($config['system']['use_mfs_tmpvar'])) { + unlink_if_exists("{$file}"); + } + } + echo "done.\n"; + return true; + } + return false; +} + ?> -- cgit v1.1