persist\n"; $natrules .= "table persist\n"; $natrules .= "table persist\n"; if (file_exists("/var/db/whitelist.txt")) { $natrules .= "table persist file \"/var/db/whitelist.txt\"\n"; } if (is_array($config['installedpackages']['spamdsettings']['config'])) { $spamdconfig = $config['installedpackages']['spamdsettings']['config']['0']; } else { $spamdconfig = $config['installedpackages']['spamdsettings']['config']; } if ($spamdconfig) { $nextmta = $spamdconfig['next_mta']; $spamdbinds = explode(',', $spamdconfig['spamdbinds_array']); if (is_array($spamdbinds)) { foreach ($spamdbinds as $interface) { $wanif = get_real_interface($interface); if (!isset($wanif)) { continue; } $natrules .= "rdr pass on {$wanif} proto tcp from to port smtp -> 127.0.0.1 port spamd\n"; $natrules .= "rdr pass on {$wanif} proto tcp from to port smtp -> 127.0.0.1 port spamd\n"; $natrules .= "rdr pass on {$wanif} proto tcp from ! to port smtp -> 127.0.0.1 port spamd\n"; if ($nextmta != "") { $natrules .= "rdr pass on {$wanif} proto tcp from to port smtp -> {$nextmta} port smtp\n"; } } } } $natrules .= "\n"; break; } return $natrules; } function remove_spaces($string) { $string = str_replace(" ", "", $string); return $string; } function sync_spamd_config_to_backup() { global $config; if (is_array($config['installedpackages']['carpsettings']['config'])) { foreach ($config['installedpackages']['carpsettings']['config'] as $carp) { if ($carp['synchronizetoip'] != "" ) { $synctoip = $carp['synchronizetoip']; $password = $carp['password']; if ($config['system']['username']) { $username = $config['system']['username']; } else { $username = "admin"; } } } } if ($synctoip and $password) { if ($config['system']['webgui']['protocol'] != "") { $synchronizetoip = $config['system']['webgui']['protocol']; $synchronizetoip .= "://"; } $port = $config['system']['webgui']['port']; /* if port is empty lets rely on the protocol selection */ if ($port == "") { if ($config['system']['webgui']['protocol'] == "http") { $port = "80"; } else { $port = "443"; } } $params = array(XML_RPC_encode($password),XML_RPC_encode($xml)); /* create files to sync array */ $filetosync = array("/var/db/spamd", "/var/db/whitelist.txt"); /* loop through files to sync list and sync them up */ foreach ($filetosync as $f2s) { $f2c_contents = file_get_contents($f2s); xmlrpc_sync_file($url, $password, $f2s, $f2c_contents, $port); } /* signal remote process config reload */ xmlrpc_exec_shell($url, $password, "/usr/bin/killall -HUP spamlogd", $port); xmlrpc_exec_shell($url, $password, "/usr/bin/killall -HUP spamd", $port); } } function custom_php_install_command() { global $config; system("touch /var/db/whitelist.txt"); system("touch /var/db/blacklist.txt"); exec("/usr/sbin/pw usermod _spamd -g proxy -G _spamd,proxy"); sync_package_spamd(); } function custom_php_deinstall_command() { global $config; unlink_if_exists("/usr/local/pkg/pf/spamd_rules.php"); install_cron_job("/usr/bin/nice -n20 /usr/local/sbin/spamd-setup", false); /* clean up user/groups */ if (exec("/usr/sbin/pw groupshow proxy | /usr/bin/grep _spamd")) { exec ("/usr/sbin/pw groupmod proxy -d _spamd"); } if (exec("/usr/sbin/pw usershow _spamd")) { exec("/usr/sbin/pw userdel _spamd"); } if (exec("/usr/sbin/pw groupshow _spamd")) { exec("/usr/sbin/pw groupdel _spamd"); } /* unmount fdescfs if needed */ if (trim(shell_exec("/sbin/mount | /usr/bin/grep '[f]descfs' | /usr/bin/wc -l")) != 0 ) { log_error("[spamd] Unmounting fdescfs."); mwexec("/sbin/umount /dev/fd"); } unlink_if_exists("/var/db/spamd"); filter_configure(); } function spamd_validate_input($post, &$input_errors) { if (!empty($post["next_mta"])) { if (!is_ipaddrv4($post['next_mta'])) { $input_errors[] = "NextMTA is not a valid IPv4 address"; } } } ?>