"spamd.sh", "start" => $start, "stop" => $stop ) ); log_error("[spamd] Installing cron job"); install_cron_job("/usr/bin/nice -n20 /usr/local/sbin/spamd-setup", true, "*/120"); log_error("[spamd] Setting up spamd.conf symlink"); unlink_if_exists("$localpath/etc/spamd/spamd.conf"); symlink("/etc/spamd.conf", "$localpath/etc/spamd/spamd.conf"); conf_mount_ro(); log_error("[spamd] Restarting spamd"); restart_service("spamd"); log_error("[spamd] Reconfiguring filter"); filter_configure(); log_error("[spamd] Package setup completed"); } function sync_package_spamd_whitelist() { global $config; conf_mount_rw(); /* write out ip to the whitelist db */ $fd = fopen("/var/db/whitelist.txt","w"); if ($config['installedpackages']['spamdwhitelist']['config'] != "") { foreach ($config['installedpackages']['spamdwhitelist']['config'] as $spamd) { fwrite($fd, $spamd['ip'] . "\n"); } } fclose($fd); /* signal a reload of all files */ mwexec("/usr/bin/killall -HUP spamlogd"); mwexec("/sbin/pfctl -t spamd-white -T add {$spamd['ip']}"); conf_mount_ro(); } function spamd_generate_rules($type) { global $config; $natrules = ""; switch($type) { case 'nat': $natrules .= "\n# spam table \n"; $natrules .= "table 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"); } 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"; } } } ?>