"") $nextmta = $ss['nextmta']; if($ss['greylistingparms'] <> "") $passtime = " -G " . $ss['greylistingparms']; if($ss['identifier'] <> "") $identifier = " -n \"" . $ss['identifier'] . "\""; // Default is greylisting, turn on blacklisting if not checked. if($ss['greylisting'] <> "on") $greylisting = " -b"; if($ss['maxblack'] <> "") $maxblack = " -B " . $ss['maxblack']; if($ss['maxcon'] <> "") $maxcon = " -c " . $ss['maxcon']; if($ss['stuttersecs'] <> "") $stuttersecs = " -S " . $ss['stuttersecs']; if($ss['delaysecs'] <> "") $delaysecs = " -s " . $ss['delaysecs']; if($ss['window'] <> "") $window = " -w " . $ss['window']; if($ss['passtime'] <> "") $passtime = $ss['passtime']; if($ss['greyexp'] <> "") $greyexp = $ss['greyexp']; if($ss['whiteexp'] <> "") $whiteexp = $ss['whiteexp']; } } $greyparms = " -G {$passtime}:{$greyexp}:{$whiteexp}"; $start = "if [ `mount | grep -v grep | grep fdescfs | wc -l` -lt 1 ]; then \n" . "/sbin/mount -t fdescfs fdescfs /dev/fd\n" . "fi\n" . "/usr/local/sbin/spamd-setup -d &\n" . "/sbin/pflogd &\n" . "$localpath/libexec/spamd {$greyparms}{$identifier}{$greylisting}{$maxcon}{$maxblack}{$window}{$replysmtperror} 127.0.0.1 &\n" . "$localpath/libexec/spamlogd\n"; $stop = "/usr/bin/killall spamd-setup\n" . "/usr/bin/killall spamlogd\n" . "/usr/bin/killall spamd\n" . "/usr/bin/killall pflogd\n" . "sleep 2"; log_error("Writing rc_file"); write_rcfile(array( "file" => "spamd.sh", "start" => $start, "stop" => $stop ) ); log_error("Installing CRON"); spamd_install_cron(true); log_error("Mounting RO"); conf_mount_ro(); log_error("Restart cron"); mwexec("killall -HUP cron"); log_error("Setting up spamd.conf symlink"); unlink_if_exists("$localpath/etc/spamd/spamd.conf"); symlink("/etc/spamd.conf", "$localpath/etc/spamd/spamd.conf"); log_error("Stopping spamd"); mwexec("/usr/local/etc/rc.d/spamd.sh stop"); sleep(1); log_error("Starting spamd"); mwexec_bg("/usr/local/etc/rc.d/spamd.sh start"); log_error("Reconfiguring filter"); filter_configure(); log_error("SpamD 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['nextmta']; $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 $g, $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, $g; 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, $g; unlink_if_exists("/usr/local/pkg/pf/spamd_rules.php"); spamd_install_cron(false); filter_configure(); } function spamd_install_cron($should_install) { global $config, $g; $is_installed = false; if(!$config['cron']['item']) return; $x=0; foreach($config['cron']['item'] as $item) { if(strstr($item['command'], "spamd-setup")) { $is_installed = true; break; } $x++; } switch($should_install) { case true: if(!$is_installed) { $cron_item = array(); $cron_item['minute'] = "*/120"; $cron_item['hour'] = "*"; $cron_item['mday'] = "*"; $cron_item['month'] = "*"; $cron_item['wday'] = "*"; $cron_item['who'] = "root"; $cron_item['command'] = "/usr/bin/nice -n20 /usr/local/sbin/spamd-setup"; $config['cron']['item'][] = $cron_item; write_config("Installed SPAMD crontab entries."); configure_cron(); } break; case false: if($is_installed == true) { if($x > 0) { unset($config['cron']['item'][$x]); write_config(); } configure_cron(); } break; } } function spamd_validate_input($post, &$input_errors) { global $config, $g; $nextmta = str_replace("$", "", $post['nextmta']); if(stristr($nextmta, "{")) { /* item is an alias, make sure the name exists */ $nextmta = str_replace("$", "", $nextmta); $found = false; if($config['aliases']['alias']) { foreach($config['aliases']['alias'] as $alias) { if($alias['name'] == $nextmta) { $found = true; } } } if($found == false) $intput_errors = "Could not locate alias named " . htmlentities($nextmta); } } ?>