time()) { //false if(is_file($config_dir.'/bbs-mail-debug')) { //true $do_mail_update = true; } } else { //true $do_mail_update = true; } if($do_mail_update == true) { echo "Sending keys to ".$rslight_gpg['nntp_group']."\n"; send_keys_to_group($res, $rslight_gpg); touch($spooldir.'/bbs-mail-update-timer'); } function inspect_message($message, $filename) { global $logfile, $config_name; $header = array(); $body = array(); $return_data = array(); if(strpos($message, 'bbsmail-MAILKEY notice')) { file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Found MAILKEY message ".$filename, FILE_APPEND); } else { if(strpos($message, 'bbsmail-BBSMAIL notice')) { $return_data['type'] = 'bbsmail'; file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Found BBSMAIL message ".$filename, FILE_APPEND); } else { file_put_contents($logfile, "\n".format_log_date()." ".$config_name." Found UNKNOWN message ".$filename, FILE_APPEND); return false; } } $raw_message = file($message); $is_header = 1; $mailkey_header = 0; $mailkey_body = 0; foreach($raw_message as $line) { if(trim($line) == '') { $is_header = 0; continue; } if($is_header == 1) { if(strpos($line, 'From: ') !== false) { $from_line = explode("From: ", $line); $from = trim($from_line[1]); $return_data['from'] = $from; } if(strpos($line, 'Subject: ') !== false) { $subject_line = explode("Subject: ", $line); $subject = trim($subject_line[1]); if(strpos($subject, '@@RSL MAILKEY notice') !== false) { $return_data['type'] = 'mailkey'; } else { if(strpos($subject, '@@RSL BBSMAIL notice') !== false) { $return_data['type'] = 'bbsmail'; } else { return false; } } } $header[] = $line; } else { if($return_data['type'] == 'mailkey') { if(strpos($line, '@@BEGIN MAILKEY HEADERS') !== false) { $mailkey_header = 1; } if($mailkey_header == 1) { if(strpos($line, 'From: ') !== false) { $mailkey = explode("From: ", $line); $return_data['mailkey_from'] = trim($mailkey[1]); } else { if(strpos($line, 'Version: ') !== false) { $mailkey = explode("Version: ", $line); $return_data['mailkey_version'] = trim($mailkey[1]); } else { if(strpos($line, 'Notice-ID: ') !== false) { $mailkey = explode("Notice-ID: ", $line); $return_data['mailkey_notice-id'] = trim($mailkey[1]); } } } } if(strpos($line, '@@BEGIN MAILKEY BODY') !== false) { $mailkey_body = 1; $mailkey_header = 0; } if($mailkey_body == 1) { if(strpos($line, 'Key: ') !== false) { $mailkey = explode("Key: ", $line); $return_data['mailkey_key'] = trim($mailkey[1]); } else { if(strpos($line, 'Location: ') !== false) { $mailkey = explode("Location: ", $line); $return_data['mailkey_location'] = trim($mailkey[1]); } else { if(strpos($line, 'Domain: ') !== false) { $mailkey = explode("Domain: ", $line); $return_data['mailkey_domain'] = trim($mailkey[1]); } } } } if(trim($line) == '.') { $line = ' '; } $body[] = rtrim($line); } else { $body[] = rtrim($line); } } } $return_data['body'] = implode("\n", $body); return($return_data); } function send_keys_to_group($res, $rslight_gpg) { global $spooldir, $config_name, $mail_update_time, $CONFIG, $rslight_version; $cwd = getcwd(); $webtmp = preg_replace('/spoolnews/','tmp/',$cwd); $key_location = "/tmp/server_pubkey.txt"; $signing_key = trim(file_get_contents($webtmp.'/server_fingerprint.txt')); $fingerprint_clean = preg_replace('/\ /', '', $signing_key); gnupg_addsignkey($res,$fingerprint_clean)."\n"; $start="@@BEGIN MAILKEY HEADERS"; $begin="@@BEGIN MAILKEY BODY"; $end="@@END MAILKEY BODY"; /* Get days since last sent for creating message-id * (Don't allow posting more than once per day) */ $date1 = date_create(date("Y-m-d", time() - $mail_update_time)); $date2 = date_create(date("Y-m-d", time())); $diff_days = date_diff($date1,$date2); $outgoing_dir = $spooldir.'/'.$config_name.'/outgoing'; if(!is_dir($outgoing_dir)) { mkdir($outgoing_dir, 0700, true); } $domain = $rslight_gpg['domain_name']; $organization = $CONFIG['organization']; $from = $rslight_gpg['from_email']; $contact = $rslight_gpg['contact']; $outgoing_file = tempnam($outgoing_dir, 'bbsmail-'); $body=''; $body.="******************************************************\n"; $body.="THIS IS A TEST POST! DO NOT USE THIS FOR A REAL SITE!\n"; $body.="******************************************************\n\n"; $body.="You may use this to import the public key for $domain.\n"; $body.="This message is automatically generated by $from.\n\n"; $body.="This message was signed using the following key:\n"; $body.="$signing_key\n\n"; $body.="The GPG key needed to verify the signature of messages\n"; $body.="issued by $from is available at:\n"; $body.="$domain$key_location\n\n"; $body.="For information contact $contact.\n\n"; $body.=$start."\n"; $body.=' Version: '.$rslight_version."\n"; $body.=' From: '.$from."\n"; $hashtail = hash('crc32', $domain.$organization.$from.$rslight_gpg['nntp_group']); $thishash = hash('crc32', $body.$diff_days->format("%a").$hashtail).hash('crc32', $signing_key); $body.=" Notice-ID: ".$thishash."\n"; $body.=$begin."\n"; $body.=" Key: ".$signing_key."\n"; $body.=" Location: ".$domain.$key_location."\n"; $body.=" Domain: ".$domain."\n"; $body.=$end."\n"; $header=''; $header.="From: $from\n"; $header.="Newsgroups: ".$rslight_gpg['nntp_group']."\n"; $header.="Subject: @@RSL MAILKEY notice ".$thishash."\n"; $header.="Message-ID: <$thishash@$domain>\n"; $header.="Content-Type: text/plain; charset=utf-8; format=flowed\n"; $header.="Content-Transfer-Encoding: 8bit\n"; $header.="Organization: $organization\n\n"; $signed_body = gnupg_sign($res, $body); file_put_contents($outgoing_file, $header.$signed_body); echo "Posted <".$thishash."@".$domain.">\n\n"; }