'deleted.content.message.txt',
'deletedbadfilename' => 'deleted.filename.message.txt',
'deletedvirus' =>'deleted.virus.message.txt',
'deletedsize' => 'deleted.size.message.txt',
'storedbadcontent' => 'stored.content.message.txt',
'storedbadfilename' => 'stored.filename.message.txt',
'storedvirus' => 'stored.virus.message.txt',
'storedsize' => 'stored.size.message.txt',
'disinfected' => 'disinfected.report.txt',
'sendercontent' => 'sender.content.report.txt',
'sendererror' => 'sender.error.report.txt',
'senderbadfilename' => 'sender.filename.report.txt',
'sendervirus' => 'sender.virus.report.txt',
'sendersize' => 'sender.size.report.txt',
'senderrbl' => 'sender.spam.rbl.report.txt',
'sendersa' => 'sender.spam.sa.report.txt',
'sendermcp' => 'sender.mcp.report.txt',
'senderspam'=>'sender.spam.report.txt',
'recipientmcp'=>'recipient.mcp.report.txt',
'recipientspam'=>'recipient.spam.report.txt',
'rejection' =>'rejection.report.txt');
foreach ($report_files as $key_r => $file_r){
if ($report[$key_r] == ""){
#$input_errors[]= $key;
$config['installedpackages']['msreport']['config'][0][$key_r]=base64_encode(file_get_contents($report_dir.'/'.$file_r.'.sample'));
file_put_contents($report_dir.'/'.$file_r,ms_text_area_decode($config['installedpackages']['msreport']['config'][0][$key_r]),LOCK_EX);
$load_samples++;
}
#print $key_r ."X $file_r X". base64_encode(file_get_contents($report_dir.'/'.$file_r.'.sample')) ."
";
if ($alert['sig']){
if($alert['sig_html'] == ""){
$config['installedpackages']['msalerts']['config'][0]['sig_html']=base64_encode(file_get_contents($report_dir.'/inline.sig.html'));
$load_samples++;
}
if($alert['sig_txt'] == ""){
$config['installedpackages']['msalerts']['config'][0]['sig_txt']=base64_encode(file_get_contents($report_dir.'/inline.sig.txt'));
$load_samples++;
}
}
if ($alert['warning']){
if($alert['warning_html'] == ""){
$config['installedpackages']['msalerts']['config'][0]['warning_html']=base64_encode(file_get_contents($report_dir.'/inline.warning.html'));
$load_samples++;
}
if($alert['warning_txt'] == ""){
$config['installedpackages']['msalerts']['config'][0]['warning_txt']=base64_encode(file_get_contents($report_dir.'/inline.warning.txt'));
$load_samples++;
}
}
}
#exit;
if($load_samples > 0)
write_config();
/*
Phishing Safe Sites File = %etc-dir%/phishing.safe.sites.conf
Phishing Bad Sites File = %etc-dir%/phishing.bad.sites.conf
Country Sub-Domains List = %etc-dir%/country.domains.conf
*/
#create MailScanner.conf$deliver_silent
$mc=<< Filename = signature.jpg
Inline HTML Warning = %report-dir%/inline.warning.html
Inline Text Warning = %report-dir%/inline.warning.txt
Sender Content Report = %report-dir%/sender.content.report.txt
Sender Error Report = %report-dir%/sender.error.report.txt
Sender Bad Filename Report = %report-dir%/sender.filename.report.txt
Sender Virus Report = %report-dir%/sender.virus.report.txt
Sender Size Report = %report-dir%/sender.size.report.txt
Hide Incoming Work Dir = {$hide_incoming_work_dir}
Include Scanner Name In Reports = {$include_scanner_name}
#
# Changes to Message Headers
# --------------------------
#
Mail Header = X-%org-name%-MailScanner:
Spam Header = X-%org-name%-MailScanner-SpamCheck:
Spam Score Header = X-%org-name%-MailScanner-SpamScore:
Information Header = X-%org-name%-MailScanner-Information:
Add Envelope From Header = yes
Add Envelope To Header = no
Envelope From Header = X-%org-name%-MailScanner-From:
Envelope To Header = X-%org-name%-MailScanner-To:
ID Header = X-%org-name%-MailScanner-ID:
IP Protocol Version Header = # X-%org-name%-MailScanner-IP-Protocol:
Spam Score Character = s
SpamScore Number Instead Of Stars = no
Minimum Stars If On Spam List = 0
Clean Header Value = Found to be clean
Infected Header Value = Found to be infected
Disinfected Header Value = Disinfected
Information Header Value = Please contact the ISP for more information
Detailed Spam Report = yes
Include Scores In SpamAssassin Report = yes
Always Include SpamAssassin Report = no
Multiple Headers = append
Place New Headers At Top Of Message = no
Hostname = the %org-name% ($HOSTNAME) MailScanner
Sign Messages Already Processed = no
Sign Clean Messages = yes
Attach Image To Signature = no
Attach Image To HTML Message Only = yes
Allow Multiple HTML Signatures = no
Dont Sign HTML If Headers Exist = # In-Reply-To: References:
Mark Infected Messages = yes
Mark Unscanned Messages = yes
Unscanned Header Value = Not scanned: please contact your Internet E-Mail Service Provider for details
Remove These Headers = X-Mozilla-Status: X-Mozilla-Status2:
Deliver Cleaned Messages = yes
#
# Notifications back to the senders of blocked messages
# -----------------------------------------------------
#
Notify Senders = {$notify_sender}
Notify Senders Of Viruses = {$notify_sender_viruses}
Notify Senders Of Blocked Filenames Or Filetypes = {$notify_sender_fileytypes}
Notify Senders Of Blocked Size Attachments = {$notify_sender_attachments}
Notify Senders Of Other Blocked Content = {$notify_sender_contents}
Never Notify Senders Of Precedence = list bulk
#
# Changes to the Subject: line
# ----------------------------
#
Scanned Modify Subject = no # end
Scanned Subject Text = [Scanned]
Virus Modify Subject = start
Virus Subject Text = [Virus?]
Filename Modify Subject = start
Filename Subject Text = [Filename?]
Content Modify Subject = start
Content Subject Text = [Dangerous Content?]
Size Modify Subject = start
Size Subject Text = [Size]
Disarmed Modify Subject = start
Disarmed Subject Text = [Disarmed]
Phishing Modify Subject = no
Phishing Subject Text = [Fraude?]
Spam Modify Subject = start
Spam Subject Text = [Spam?]
High Scoring Spam Modify Subject = start
High Scoring Spam Subject Text = [Spam?]
#
# Changes to the Message Body
# ---------------------------
#
Warning Is Attachment = yes
Attachment Warning Filename = %org-name%-Attachment-Warning.txt
Attachment Encoding Charset = ISO-8859-1
#
# Mail Archiving and Monitoring
# -----------------------------
#
Archive Mail =
Missing Mail Archive Is = directory
#
# Notices to System Administrators
# --------------------------------
#
Send Notices = {$send_notices}
Notices Include Full Headers = {$notices_include_header}
Hide Incoming Work Dir in Notices = {$hide_incoming_work_dir_notices}
Notice Signature = {$notice_signature}
Notices From = ${$notice_from}
Notices To = ${$notice_to}
Local Postmaster = postmaster
#
# Spam Detection and Virus Scanner Definitions
# --------------------------------------------
#
Spam List Definitions = %etc-dir%/spam.lists.conf
Virus Scanner Definitions = %etc-dir%/virus.scanners.conf
#
# Spam Detection and Spam Lists (DNS blocklists)
# ----------------------------------------------
#
Spam Checks = yes
Spam List = # spamhaus-ZEN # You can un-comment this to enable them
Spam Domain List =
Spam Lists To Be Spam = 1
Spam Lists To Reach High Score = 3
Spam List Timeout = 10
Max Spam List Timeouts = 7
Spam List Timeouts History = 10
Is Definitely Not Spam = %rules-dir%/spam.whitelist.rules
Is Definitely Spam = no
Definite Spam Is High Scoring = no
Ignore Spam Whitelist If Recipients Exceed = 20
Max Spam Check Size = 200k
#
# Watermarking
# ------------
#
Use Watermarking = no
Add Watermark = yes
Check Watermarks With No Sender = yes
Treat Invalid Watermarks With No Sender as Spam = nothing
Check Watermarks To Skip Spam Checks = yes
Watermark Secret = %org-name%-Secret
Watermark Lifetime = 604800
Watermark Header = X-%org-name%-MailScanner-Watermark:
#
# SpamAssassin
# ------------
#
Use SpamAssassin = {$use_sa}
Max SpamAssassin Size = {$sa_max}
Required SpamAssassin Score = {$sa_score}
High SpamAssassin Score = {$hi_score}
SpamAssassin Auto Whitelist = {$sa_auto_whitelist}
SpamAssassin Timeout = 75
Max SpamAssassin Timeouts = 10
SpamAssassin Timeouts History = 30
Check SpamAssassin If On Spam List = {$check_sa_if_on_spam_list}
Include Binary Attachments In SpamAssassin = {$include_sa_bin_attachments}
Spam Score = {$spam_score}
Cache SpamAssassin Results = {$cache_spamassassin_results}
SpamAssassin Cache Database File = /var/spool/MailScanner/incoming/SpamAssassin.cache.db
Rebuild Bayes Every = {$rebuild_bayes}
Wait During Bayes Rebuild = {$wait_during_bayes_rebuild}
#
# Custom Spam Scanner Plugin
# --------------------------
#
Use Custom Spam Scanner = no
Max Custom Spam Scanner Size = 20k
Custom Spam Scanner Timeout = 20
Max Custom Spam Scanner Timeouts = 10
Custom Spam Scanner Timeout History = 20
#
# What to do with spam
# --------------------
#
Spam Actions = {$spam_actions} header "X-Spam-Status: Yes"
High Scoring Spam Actions = {$hispam_actions} header "X-Spam-Status: Yes"
Non Spam Actions = deliver header "X-Spam-Status: No"
SpamAssassin Rule Actions =
Sender Spam Report = %report-dir%/sender.spam.report.txt
Sender Spam List Report = %report-dir%/sender.spam.rbl.report.txt
Sender SpamAssassin Report = %report-dir%/sender.spam.sa.report.txt
Inline Spam Warning = %report-dir%/inline.spam.warning.txt
Recipient Spam Report = %report-dir%/recipient.spam.report.txt
Enable Spam Bounce = %rules-dir%/bounce.rules
Bounce Spam As Attachment = no
#
# Logging
# -------
#
Syslog Facility = {$syslog_facility}
Log Speed = {$log_speed}
Log Spam = {$log_spam}
Log Non Spam = {$log_non_spam}
Log Delivery And Non-Delivery = {$log_delivery}
Log Permitted Filenames = {$log_filenames}
Log Permitted Filetypes = {$log_filetypes}
Log Permitted File MIME Types = {$log_mime}
Log Silent Viruses = {$log_silent}
Log Dangerous HTML Tags = {$log_dangerous}
Log SpamAssassin Rule Actions = {$log_sa_rule_action}
#
# Advanced SpamAssassin Settings
# ------------------------------
#
SpamAssassin Temporary Dir = /var/spool/MailScanner/incoming/SpamAssassin-Temp
SpamAssassin User State Dir =
SpamAssassin Install Prefix =
SpamAssassin Site Rules Dir = /usr/local/etc/mail/spamassassin
SpamAssassin Local Rules Dir =
SpamAssassin Local State Dir = # /var/lib/spamassassin
SpamAssassin Default Rules Dir =
#
# MCP (Message Content Protection)
# -----------------------------
#
MCP Checks = {$mcp_checks}
First Check = spam
MCP Required SpamAssassin Score = {$mcp_score}
MCP High SpamAssassin Score = {$hi_mcp_score}
MCP Error Score = 1
MCP Header = X-%org-name%-MailScanner-MCPCheck:
Non MCP Actions = deliver
MCP Actions = {$mcp_action}
High Scoring MCP Actions = {$mcp_hi_action}
Bounce MCP As Attachment = {$bounce_mcp}
MCP Modify Subject = start
MCP Subject Text = [MCP?]
High Scoring MCP Modify Subject = start
High Scoring MCP Subject Text = [MCP?]
Is Definitely MCP = {$is_mcp}
Is Definitely Not MCP = {$is_not_mcp}
Definite MCP Is High Scoring = {$mcp_is_high_score}
Always Include MCP Report = {$include_mcp_report}
Detailed MCP Report = {$detailled_mcp_report}
Include Scores In MCP Report = {$score_mcp_report}
Log MCP = {$log_mcp}
MCP Max SpamAssassin Timeouts = 20
MCP Max SpamAssassin Size = {$mcp_max}
MCP SpamAssassin Timeout = 10
MCP SpamAssassin Prefs File = %mcp-dir%/mcp.spam.assassin.prefs.conf
MCP SpamAssassin User State Dir =
MCP SpamAssassin Local Rules Dir = %mcp-dir%
MCP SpamAssassin Default Rules Dir = %mcp-dir%
MCP SpamAssassin Install Prefix = %mcp-dir%
Recipient MCP Report = %report-dir%/recipient.mcp.report.txt
Sender MCP Report = %report-dir%/sender.mcp.report.txt
#
# Advanced Settings
# -----------------
#
Use Default Rules With Multiple Recipients = {$default_rule_multiple}
Read IP Address From Received Header = {$read_ipaddress}
Spam Score Number Format = {$spam_score_format}
MailScanner Version Number = 4.83.5
SpamAssassin Cache Timings = {$cache_timings}
Debug = {$debug}
Debug SpamAssassin = {$debug_spam}
Run In Foreground = {$foreground}
Always Looked Up Last = {$look_up_last}
Always Looked Up Last After Batch = {$look_up_last_batch}
Deliver In Background = {$deliver_background}
Delivery Method = {$mailscanner['deliver_method']}
Split Exim Spool = {$split_exim_spool}
Lockfile Dir = /var/spool/MailScanner/incoming/Locks
Custom Functions Dir = /usr/local/lib/MailScanner/MailScanner/CustomFunctions
Lock Type =
Syslog Socket Type =
Automatic Syntax Check = {$syntax_check}
Minimum Code Status = {$mailscanner['minimum_code']}
include /usr/local/etc/MailScanner/conf.d/*
EOF;
#write files
conf_mount_rw();
if (!is_dir("/var/spool/MailScanner/incoming")){
mkdir("/var/spool/MailScanner/incoming", 0755,true);
chown ('/var/spool/MailScanner/incoming','postfix');
}
if (!is_dir("/var/spool/MailScanner/quarantine")){
mkdir("/var/spool/MailScanner/quarantine", 0755,true);
chown ('/var/spool/MailScanner/quarantine','postfix');
}
chown ('/var/spool/postfix','postfix');
$mlang=strtolower($report['language']);
$mfiles[]="/usr/local/etc/MailScanner/virus.scanners.conf";
$mfiles[]="/usr/local/share/MailScanner/reports/{$mlang}/inline.spam.warning.txt";
$mfiles[]="/usr/local/share/MailScanner/reports/{$mlang}/languages.conf";
foreach ($mfiles as $mfile)
if (! file_exists ($mfile))
copy($mfile.".sample",$mfile);
#update spam.assassin.prefs.conf
$sa_temp=ms_text_area_decode($config['installedpackages']['msantispam']['config'][0]['sa_pref_file']);
$pattern[0]='/#ifplugin/';
$pattern[1]='/#pyzor_path/';
$pattern[2]='/usr.bin.pyzor/';
$pattern[3]='/#dcc_path/';
$pattern[4]='/#endif/';
$replacement[0]="ifplugin";
$replacement[1]="pyzor_path";
$replacement[2]="usr/local/bin/pyzor";
$replacement[3]="dcc_path";
$replacement[4]="endif";
if (preg_match('/use_razor/',$antispam['safeatures'])){
$pattern[5]='/\nuse_razor2\s+0/';
$replacement[5]="\n".'# use_razor2 0';
}
else{
$pattern[5]='/\n#\s+use_razor2\s+0/';
$replacement[5]="\n".'use_razor2 0';
}
if (preg_match('/use_dcc/',$antispam['safeatures'])){
$pattern[6]='/\nuse_dcc\s+0/';
$replacement[6]="\n".'# use_dcc 0';
}
else{
$pattern[6]='/\n#\s+use_dcc\s+0/';
$replacement[6]="\n".'use_dcc 0';
}
if (preg_match('/use_pyzor/',$antispam['safeatures'])){
$pattern[7]='/\nuse_pyzor\s+0/';
$replacement[7]="\n".'# use_pyzor 0';
}
else{
$pattern[7]='/\n#\s+use_pyzor\s+0/';
$replacement[7]="\n".'# use_pyzor 0';
}
if (preg_match('/use_auto_learn_bayes/',$antispam['safeatures'])){
$pattern[8]='/\nbayes_auto_learn\s+0/';
$replacement[8]="\n".'# bayes_auto_learn 0';
}
else{
$pattern[8]='/\n#\s+bayes_auto_learn\s+0/';
$replacement[8]="\n".'bayes_auto_learn 0';
}
if (preg_match('/use_bayes/',$antispam['safeatures'])){
$pattern[9]='/\nuse_bayes\s+0/';
$replacement[9]="\n".'# use_bayes 0';
}
else{
$pattern[9]='/\n#\s+use_bayes\s+0/';
$replacement[9]="\n".'use_bayes 0';
}
if (preg_match('/sa_auto_whitelist/',$antispam['safeatures'])){
$pattern[10]='/\nuse_auto_whitelist\s+0/';
$replacement[10]="\n".'# use_auto_whitelist 0';
}
else{
$pattern[10]='/\n#\s*use_auto_whitelist 0/';
$replacement[10]="\n".'use_auto_whitelist 0';
}
if ($antispam['rblchecks']){
$pattern[11]='/\nskip_rbl_checks\s+1/';
$replacement[11]="\n".'# skip_rbl_checks 1';
}
else{
$pattern[11]='/\n#\s+skip_rbl_checks\s+\d/';
$replacement[11]="\n".'skip_rbl_checks 1';
}
$pattern[12]='/bayes_ignore_header ([a-zA-Z0-9_.-]+)MailScanner/';
$replacement[12]="bayes_ignore_header ".($mailscanner['orgname']!=""?$mailscanner['orgname']:"pfsense")."-MailScanner";
$pattern[13]='/envelope_sender_header X([a-zA-Z0-9_.-]+)MailScanner-From/';
$replacement[13]="envelope_sender_header X-".($mailscanner['orgname']!=""?$mailscanner['orgname']:"pfsense")."-MailScanner-From";
$sa_temp=preg_replace($pattern,$replacement,$sa_temp);
#rint "pre".$sa_temp;exit;
$config['installedpackages']['msantispam']['config'][0]['sa_pref_file']=base64_encode($sa_temp);
write_config();
file_put_contents($mailscanner_dir."/MailScanner.conf", $mc, LOCK_EX);
file_put_contents($mailscanner_dir."/filename.rules.conf",ms_text_area_decode($config['installedpackages']['msattachments']['config'][0]['filename_rules']),LOCK_EX);
file_put_contents($mailscanner_dir."/filetype.rules.conf",ms_text_area_decode($config['installedpackages']['msattachments']['config'][0]['filetype_rules']),LOCK_EX);
file_put_contents($mailscanner_dir."/archives.filename.rules.conf",ms_text_area_decode($config['installedpackages']['msattachments']['config'][0]['filename_rules']),LOCK_EX);
file_put_contents($mailscanner_dir."/archives.filetype.rules.conf",ms_text_area_decode($config['installedpackages']['msattachments']['config'][0]['filetype_rules']),LOCK_EX);
file_put_contents($mailscanner_dir."/phishing.safe.sites.conf",ms_text_area_decode($config['installedpackages']['mscontent']['config'][0]['phishing_safe']),LOCK_EX);
file_put_contents($mailscanner_dir."/phishing.bad.sites.conf",ms_text_area_decode($config['installedpackages']['mscontent']['config'][0]['phishing_bad']),LOCK_EX);
file_put_contents($mailscanner_dir."/country.domains.conf",ms_text_area_decode($config['installedpackages']['mscontent']['config'][0]['country_domains']),LOCK_EX);
file_put_contents($mailscanner_dir.'/spam.assassin.prefs.conf',$sa_temp,LOCK_EX);
file_put_contents($mailscanner_dir.'/spam.lists.conf',ms_text_area_decode($config['installedpackages']['msantispam']['config'][0]['rbl_file']),LOCK_EX);
file_put_contents($mailscanner_dir.'/mcp/mcp.spam.assassin.prefs.conf',ms_text_area_decode($config['installedpackages']['msantispam']['config'][0]['mcp_pref_file']),LOCK_EX);
file_put_contents($mailscanner_dir.'/rules/bounce.rules',ms_text_area_decode($config['installedpackages']['msantispam']['config'][0]['bounce']),LOCK_EX);
file_put_contents($mailscanner_dir.'/rules/max.message.size.rules',ms_text_area_decode($config['installedpackages']['msantispam']['config'][0]['max_message_size']),LOCK_EX);
file_put_contents($mailscanner_dir.'/rules/spam.whitelist.rules',ms_text_area_decode($config['installedpackages']['msantispam']['config'][0]['spam_whitelist']),LOCK_EX);
foreach ($report_files as $key_r => $file_r)
file_put_contents($report_dir.'/'.$file_r,ms_text_area_decode($config['installedpackages']['msreport']['config'][0][$key_r]),LOCK_EX);
if ($alert['sig']){
$sig_html=ms_text_area_decode($config['installedpackages']['msalerts']['config'][0]['sig_html']);
$sig_txt=ms_text_area_decode($config['installedpackages']['msalerts']['config'][0]['sig_txt']);}
else{
$sig_html="";
$sig_txt="";}
file_put_contents($report_dir.'/inline.sig.txt',$sig_txt,LOCK_EX);
file_put_contents($report_dir.'/inline.sig.html',$sig_html,LOCK_EX);
if ($alert['warning']){
$warning_html=ms_text_area_decode($config['installedpackages']['msalerts']['config'][0]['warning_html']);
$warning_txt=ms_text_area_decode($config['installedpackages']['msalerts']['config'][0]['warning_txt']);}
else{
$warning_html="";
$warning_txt="";}
file_put_contents($report_dir.'/inline.warning.txt',$warning_txt,LOCK_EX);
file_put_contents($report_dir.'/inline.warning.html',$warning_html,LOCK_EX);
#check virus_scanner options
$libexec_dir="/usr/local/libexec/MailScanner/";
if ($virus_scanning == "yes"){
if ($antivirus['virus_scanner'] =="none"){
unlink_if_exists($libexec_dir.'clamav-autoupdate');
unlink_if_exists($libexec_dir.'clamav-wrapper');
}
else{
if (file_exists('/var/run/clamav/'))
chown('/var/run/clamav/', 'postfix');
if (file_exists('/var/log/clamav/'))
chown('/var/log/clamav/', 'postfix');
if (file_exists('/var/db/clamav/'))
chown('/var/db/clamav/', 'postfix');
if (file_exists('/var/db/clamav/bytecode.cld'))
chown('/var/db/clamav/bytecode.cld', 'postfix');
if (file_exists('/var/db/clamav/daily.cld'))
chown('/var/db/clamav/daily.cld', 'postfix');
if (file_exists('/var/db/clamav/main.cvd'))
chown('/var/db/clamav/main.cvd', 'postfix');
if (file_exists('/var/db/clamav/mirrors.dat'))
chown('/var/db/clamav/mirrors.dat', 'postfix');
if (file_exists('/var/log/clamav/clamd.log'))
chown('/var/log/clamav/clamd.log', 'postfix');
if (file_exists('/var/log/clamav/freshclam.log'))
chown('/var/log/clamav/freshclam.log', 'postfix');
copy($libexec_dir.'clamav-autoupdate.sample',$libexec_dir.'clamav-autoupdate');
chmod ($libexec_dir.'clamav-autoupdate',0755);
copy($libexec_dir.'clamav-wrapper.sample',$libexec_dir.'clamav-wrapper');
chmod ($libexec_dir.'clamav-autoupdate',0755);
if (!file_exists('/var/db/clamav/main.cvd')){
log_error('No clamav database found, running freshclam in background.');
mwexec_bg('/usr/local/bin/freshclam');
}
#clamav-wrapper file
$cconf=$libexec_dir."clamav-wrapper";
$cconf_file=file_get_contents($cconf);
if (preg_match('/"clamav"/',$cconf_file)){
$cconf_file=preg_replace('/"clamav"/','"postfix"',$cconf_file);
file_put_contents($cconf, $cconf_file, LOCK_EX);
}
#freshclam conf file
$cconf="/usr/local/etc/freshclam.conf";
$cconf_file=file_get_contents($cconf);
if (preg_match('/DatabaseOwner clamav/',$cconf_file)){
$cconf_file=preg_replace("/DatabaseOwner clamav/","DatabaseOwner postfix",$cconf_file);
file_put_contents($cconf, $cconf_file, LOCK_EX);
}
#clamd conf file
$cconf="/usr/local/etc/clamd.conf";
$cconf_file=file_get_contents($cconf);
if (preg_match('/User clamav/',$cconf_file)){
$cconf_file=preg_replace("/User clamav/","User postfix",$cconf_file);
file_put_contents($cconf, $cconf_file, LOCK_EX);
}
#clamd script file
$script='/usr/local/etc/rc.d/clamav-clamd';
$script_file=file($script);
foreach ($script_file as $script_line){
if(preg_match("/command=/",$script_line)){
$new_clamav_startup.= "/bin/mkdir /var/run/clamav\n";
$new_clamav_startup.= "chown postfix /var/run/clamav\n";
$new_clamav_startup.=$script_line;
}
elseif(!preg_match("/(mkdir|chown|sleep|mailscanner)/",$script_line)) {
$new_clamav_startup.=preg_replace("/NO/","YES",$script_line);
}
}
file_put_contents($script, $new_clamav_startup, LOCK_EX);
chmod ($script,0755);
mwexec("$script stop");
mwexec_bg("$script start");
}
}
else{
unlink_if_exists($libexec_dir.'clamav-autoupdate');
unlink_if_exists($libexec_dir.'clamav-wrapper');
}
#check dcc startup script
$script='/usr/local/etc/rc.d/dccifd';
$script_file=file_get_contents($script);
if (preg_match('/NO/',$script_file)){
$script_file=preg_replace("/NO/","YES",$script_file);
file_put_contents($script, $script_file, LOCK_EX);
chmod ($script,0755);
}
#check dcc config file
$script='/usr/local/dcc/dcc_conf';
$script_file=file_get_contents($script);
if (preg_match('/DCCIFD_ENABLE=off/',$script_file)){
$script_file=preg_replace("/DCCIFD_ENABLE=off/","DCCIFD_ENABLE=on",$script_file);
file_put_contents($script, $script_file, LOCK_EX);
}
mwexec("$script stop");
mwexec_bg("$script start");
$script='/usr/local/etc/rc.d/mailscanner';
#fix MIME::ToolUtils deprecated function and usecure dependency calls in /usr/local/sbin/mailscanner
$cconf="/usr/local/sbin/mailscanner";
$cconf_file=file_get_contents($cconf);
$pattern2[0]='/perl\W+I/';
$pattern2[1]='/\smy .current = config MIME::ToolUtils/';
$replacement2[0]='perl -U -I';
$replacement2[1]=' #my $current = config MIME::ToolUtils';
if (preg_match('/perl\W+I/',$cconf_file)){
$cconf_file=preg_replace($pattern2,$replacement2,$cconf_file);
file_put_contents($cconf, $cconf_file, LOCK_EX);
#force old process stop
mwexec("$script stop");
}
$script_file=file_get_contents($script);
if (preg_match('/NO/',$script_file)){
$script_file=preg_replace("/NO/","YES",$script_file);
file_put_contents($script, $script_file, LOCK_EX);
chmod ($script,0755);
}
if($config['installedpackages']['mailscanner']['config'][0]['enable']){
log_error("Reload mailscanner");
chmod ($script,0755);
mwexec("$script stop");
sleep(2);
mwexec_bg("$script start");
}
else{
log_error("Stopping mailscanner if running");
mwexec("$script stop");
chmod ($script,0444);
}
conf_mount_ro();
$synconchanges = $config['installedpackages']['mailscannersync']['config'][0]['synconchanges'];
if(!$synconchanges && !$syncondbchanges)
return;
log_error("[mailscanner] mailscanner_xmlrpc_sync.php is starting.");
foreach ($config['installedpackages']['mailscannersync']['config'] as $rs ){
foreach($rs['row'] as $sh){
$sync_to_ip = $sh['ipaddress'];
$password = $sh['password'];
$sync_type = $sh['sync_type'];
if($password && $sync_to_ip)
mailscanner_do_xmlrpc_sync($sync_to_ip, $password,$sync_type);
}
}
log_error("[postfix] postfix_xmlrpc_sync.php is ending.");
}
function mailscanner_validate_input($post, &$input_errors) {
foreach ($post as $key => $value) {
if (empty($value))
continue;
if (substr($key, 0, 6) == "domain" && is_numeric(substr($key, 6))) {
if (!is_domain($value))
$input_errors[] = "{$value} is not a valid domain name.";
} else if (substr($key, 0, 12) == "mailserverip" && is_numeric(substr($key, 12))) {
if (empty($post['domain' . substr($key, 12)]))
$input_errors[] = "Domain for {$value} cannot be blank.";
if (!is_ipaddr($value) && !is_hostname($value))
$input_errors[] = "{$value} is not a valid IP address or host name.";
}
}
}
function mailscanner_php_install_command() {
sync_package_mailscanner();
}
function mailscanner_php_deinstall_command() {
mwexec("/usr/local/etc/rc.d/mailscanner.sh stop");
sleep(1);
conf_mount_rw();
unlink_if_exists("/usr/local/etc/rc.d/mailscanner.sh");
conf_mount_ro();
}
function mailscanner_do_xmlrpc_sync($sync_to_ip, $password,$sync_type) {
global $config, $g;
if(!$password)
return;
if(!$sync_to_ip)
return;
$xmlrpc_sync_neighbor = $sync_to_ip;
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";
}
$synchronizetoip .= $sync_to_ip;
/* xml will hold the sections to sync */
$xml = array();
$sync_xml=$config['installedpackages']['mailscannersync']['config'][0]['synconchanges'];
if ($sync_xml){
log_error("Include mailscanner config");
$xml['mailscanner'] = $config['installedpackages']['mailscanner'];
$xml['msreport'] = $config['installedpackages']['msreport'];
$xml['mscontent'] = $config['installedpackages']['mscontent'];
$xml['msantivirus'] = $config['installedpackages']['msantivirus'];
$xml['msantispam'] = $config['installedpackages']['msantispam'];
$xml['msalerts'] = $config['installedpackages']['msalerts'];
}
if (count($xml) > 0){
/* assemble xmlrpc payload */
$params = array(
XML_RPC_encode($password),
XML_RPC_encode($xml)
);
/* set a few variables needed for sync code borrowed from filter.inc */
$url = $synchronizetoip;
log_error("Beginning mailscanner XMLRPC sync to {$url}:{$port}.");
$method = 'pfsense.merge_installedpackages_section_xmlrpc';
$msg = new XML_RPC_Message($method, $params);
$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
$cli->setCredentials('admin', $password);
if($g['debug'])
$cli->setDebug(1);
/* send our XMLRPC message and timeout after 250 seconds */
$resp = $cli->send($msg, "250");
if(!$resp) {
$error = "A communications error occurred while attempting mailscanner XMLRPC sync with {$url}:{$port}.";
log_error($error);
file_notice("sync_settings", $error, "Mailscanner Settings Sync", "");
} elseif($resp->faultCode()) {
$cli->setDebug(1);
$resp = $cli->send($msg, "250");
$error = "An error code was received while attempting mailscanner XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
log_error($error);
file_notice("sync_settings", $error, "mailscanner Settings Sync", "");
} else {
log_error("mailscanner XMLRPC sync successfully completed with {$url}:{$port}.");
}
/* tell postfix to reload our settings on the destionation sync host. */
$method = 'pfsense.exec_php';
$execcmd = "require_once('/usr/local/pkg/mailscanner.inc');\n";
$execcmd .= "sync_package_mailscanner();";
/* assemble xmlrpc payload */
$params = array(
XML_RPC_encode($password),
XML_RPC_encode($execcmd)
);
log_error("mailscanner XMLRPC reload data {$url}:{$port}.");
$msg = new XML_RPC_Message($method, $params);
$cli = new XML_RPC_Client('/xmlrpc.php', $url, $port);
$cli->setCredentials('admin', $password);
$resp = $cli->send($msg, "250");
if(!$resp) {
$error = "A communications error occurred while attempting mailscanner XMLRPC sync with {$url}:{$port} (pfsense.exec_php).";
log_error($error);
file_notice("sync_settings", $error, "mailscanner Settings Sync", "");
} elseif($resp->faultCode()) {
$cli->setDebug(1);
$resp = $cli->send($msg, "250");
$error = "An error code was received while attempting mailscanner XMLRPC sync with {$url}:{$port} - Code " . $resp->faultCode() . ": " . $resp->faultString();
log_error($error);
file_notice("sync_settings", $error, "mailscanner Settings Sync", "");
} else {
log_error("mailscanner XMLRPC reload data success with {$url}:{$port} (pfsense.exec_php).");
}
}
}
?>