Skip to content

Instantly share code, notes, and snippets.

@BBcan177

BBcan177/pfSense_python.inc Secret

Created Jan 4, 2019
Embed
What would you like to do?
pfSense python integration start-up code
// Mount lib and bin folders
$base_unbound = '/var/unbound';
$base_py = '/usr/local';
foreach (array('/bin', '/lib') as $dir) {
$validate = exec("/sbin/mount | {$pfb['grep']} '{$base_unbound}{$base_py}{$dir}' 2>&1");
if ($mode == 'enabled' && empty($validate)) {
if (!is_dir("{$base_unbound}{$base_py}{$dir}")) {
pfb_logger("\n Creating: {$base_unbound}{$base_py}{$dir}", 1);
exec("/bin/mkdir -p {$base_unbound}{$base_py}{$dir} 2>&1");
}
$pfbpython = TRUE;
pfb_logger("\n Mounting: /usr/local{$dir}", 1);
exec("/sbin/mount_nullfs -o ro /usr/local{$dir} {$base_unbound}{$base_py}{$dir} 2>&1", $output, $retval);
if ($retval != 0) {
pfb_logger("\n Failed to mount [ /usr/local{$dir} ] to [ {$base_unbound}{$base_py}{$dir} ]!", 1);
}
}
elseif ($mode == 'disabled' && !empty($validate)) {
$pfbpython = TRUE;
pfb_logger("\n Unmounting: /usr/local{$dir}", 1);
exec("/sbin/umount -t nullfs {$base_unbound}{$base_py}{$dir} 2>&1", $output, $retval;\
if ($retval != 0) {
pfb_logger("\n Failed to unmount [ {$base_unbound}{$base_py}{$dir} ]!", 1);
}
}
if ($mode == 'disabled') {
foreach (array( "/usr/local{$dir}", '/usr/local', '/usr') as $folder) {
if (is_dir("{$base_unbound}{$folder}")) {
pfb_logger("\n Removing: {$base_unbound}{$folder}", 1);
rmdir("{$base_unbound}{$folder}");
}
// Delete remaining subfolders on next loop
if ($dir == '/bin') {
break;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment