From 9737f0e8ea88bf6d67996552560af6a4ef628b7a Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Sat, 29 Jul 2023 10:00:27 -0700 Subject: [PATCH] Minor fixes to send and spoolnews. Continue work on Mail features. --- .../rslight/scripts/create_gpg_keys.sh | 2 +- Rocksolid_Light/rslight/scripts/cron.php | 9 +- .../rslight/scripts/interBBS_mail.php | 272 ++++++++++++++++++ Rocksolid_Light/rslight/scripts/send.php | 5 +- Rocksolid_Light/rslight/scripts/spoolnews.php | 10 +- 5 files changed, 290 insertions(+), 8 deletions(-) create mode 100644 Rocksolid_Light/rslight/scripts/interBBS_mail.php diff --git a/Rocksolid_Light/rslight/scripts/create_gpg_keys.sh b/Rocksolid_Light/rslight/scripts/create_gpg_keys.sh index 5709cd1..82af4a9 100755 --- a/Rocksolid_Light/rslight/scripts/create_gpg_keys.sh +++ b/Rocksolid_Light/rslight/scripts/create_gpg_keys.sh @@ -7,6 +7,6 @@ domain="$4" export GNUPGHOME=$gnupghome -gpg --batch --passphrase '' --quick-gen-key $domain rsa4096 default 0 +gpg --batch --passphrase '' --quick-gen-key $domain default default 0 gpg --export -a $domain > $server_pub_key gpg --fingerprint $domain | sed '2!d' > $fingerprint \ No newline at end of file diff --git a/Rocksolid_Light/rslight/scripts/cron.php b/Rocksolid_Light/rslight/scripts/cron.php index 13cc26e..0189a96 100755 --- a/Rocksolid_Light/rslight/scripts/cron.php +++ b/Rocksolid_Light/rslight/scripts/cron.php @@ -78,11 +78,14 @@ if(isset($CONFIG['enable_nocem']) && $CONFIG['enable_nocem'] == true) { } // Set up server gpg keys if($rslight_gpg['enable'] == '1') { - if(!is_file($webtmp.'/server_pubkey.key')) { + if(!is_file($webtmp.'/server_pubkey.txt')) { $domain = 'rslight@'.$rslight_gpg['domain_name']; - $interBBS_mail = $config_dir.'/scripts/create_gpg_keys.sh "'.$gnupg.'" "'.$webtmp.'/server_pubkey.key" '.$domain; - exec($interBBS_mail); + $pubkey = $webtmp.'/server_pubkey.txt'; + $fingerprint = $webtmp.'/server_fingerprint.txt'; + $create_gpg_keys = $config_dir.'/scripts/create_gpg_keys.sh "'.$gnupg.'" "'.$pubkey.'" "'.$fingerprint.'" "'.$domain.'"'; + exec($create_gpg_keys); } + exec($CONFIG['php_exec']." ".$config_dir."/scripts/interBBS_mail.php"); } reset($menulist); diff --git a/Rocksolid_Light/rslight/scripts/interBBS_mail.php b/Rocksolid_Light/rslight/scripts/interBBS_mail.php new file mode 100644 index 0000000..6d8bedd --- /dev/null +++ b/Rocksolid_Light/rslight/scripts/interBBS_mail.php @@ -0,0 +1,272 @@ + 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"; +} + diff --git a/Rocksolid_Light/rslight/scripts/send.php b/Rocksolid_Light/rslight/scripts/send.php index e182802..af8fb7f 100755 --- a/Rocksolid_Light/rslight/scripts/send.php +++ b/Rocksolid_Light/rslight/scripts/send.php @@ -24,7 +24,10 @@ set_time_limit(900); include "config.inc.php"; include ("$file_newsportal"); - + +if ($CONFIG['remote_server'] == '') { + exit(); +} $logfile=$logdir.'/spoolnews.log'; @mkdir($spooldir."/".$config_name,0755,'recursive'); diff --git a/Rocksolid_Light/rslight/scripts/spoolnews.php b/Rocksolid_Light/rslight/scripts/spoolnews.php index 56e1d8a..8fd406f 100755 --- a/Rocksolid_Light/rslight/scripts/spoolnews.php +++ b/Rocksolid_Light/rslight/scripts/spoolnews.php @@ -106,6 +106,7 @@ $enable_rslight=0; } if ($CONFIG['remote_server'] != '') { + file_put_contents($logfile, "\n".format_log_date()." ".$config_name." remote_server: ".$CONFIG['remote_server'], FILE_APPEND); $ns=nntp2_open($CONFIG['remote_server'], $CONFIG['remote_port']); $ns2=nntp_open(); if(!$ns) { @@ -198,10 +199,12 @@ function get_articles($ns, $group) { $article = $detail[2]; } // Broken message on last run? Let's try again. +/* if($article > ($detail[3])) { $article = $detail[3]; } - # Prepare databases +*/ +# Prepare databases $database = $spooldir.'/articles-overview.db3'; $table = 'overview'; $dbh = rslight_db_open($database, $table); @@ -361,8 +364,9 @@ function get_articles($ns, $group) { } if((strpos($rslight_gpg['nntp_group'], $group) !== false) && ($rslight_gpg['enable'] == '1')) { if(strpos($subject[1], $bbsmail_check) !== false) { - $bbsmail_file = tempnam($spooldir."/bbsmail", "bbsmail-".$group."-"); - copy($grouppath."/".$local, $bbsmail_file); + $bbsmail_file = preg_replace('/@@RSL /', '', $subject[1]); + $bbsmail_filename = $spooldir."/bbsmail/in/bbsmail-".$bbsmail_file; + copy($grouppath."/".$local, $bbsmail_filename); } } // Overview