summaryrefslogtreecommitdiffstats
path: root/src/etc/inc/pfsense-utils.inc
diff options
context:
space:
mode:
authorNOYB <Al_Stu@Frontier.com>2016-04-17 00:18:33 -0700
committerNOYB <Al_Stu@Frontier.com>2016-04-17 00:18:33 -0700
commit03afdafaab503af22ce5c98ad06b9f6bbc459974 (patch)
tree73e6ea94d27823d65e3b3547fdcb03b08edb036d /src/etc/inc/pfsense-utils.inc
parent34515250ca726f096071b139fcebd5d18601162a (diff)
downloadpfsense-03afdafaab503af22ce5c98ad06b9f6bbc459974.zip
pfsense-03afdafaab503af22ce5c98ad06b9f6bbc459974.tar.gz
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.
Diffstat (limited to 'src/etc/inc/pfsense-utils.inc')
-rw-r--r--src/etc/inc/pfsense-utils.inc41
1 files changed, 40 insertions, 1 deletions
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;
+}
+
?>
OpenPOWER on IntegriCloud