From db7c85189178535b0173108ce385c2135b5345ee Mon Sep 17 00:00:00 2001 From: Retro_Guy Date: Thu, 2 Dec 2021 04:02:31 +0000 Subject: [PATCH] Add RSS pull and post feature --- Rocksolid_Light/debian-install.sh | 1 + Rocksolid_Light/freebsd-install.sh | 1 + Rocksolid_Light/rocksolid/lib/post.inc.php | 5 +- Rocksolid_Light/rocksolid/post.php | 11 ++- Rocksolid_Light/rslight/scripts/cron.php | 3 + Rocksolid_Light/rslight/scripts/rss-feeds.php | 93 +++++++++++++++++++ Rocksolid_Light/spoolnews/lib | 1 + Rocksolid_Light/spoolnews/post.php | 1 + 8 files changed, 111 insertions(+), 5 deletions(-) create mode 100755 Rocksolid_Light/rslight/scripts/rss-feeds.php create mode 120000 Rocksolid_Light/spoolnews/lib create mode 120000 Rocksolid_Light/spoolnews/post.php diff --git a/Rocksolid_Light/debian-install.sh b/Rocksolid_Light/debian-install.sh index 540aed9..2748575 100755 --- a/Rocksolid_Light/debian-install.sh +++ b/Rocksolid_Light/debian-install.sh @@ -74,6 +74,7 @@ mkdir -p $spoolpath echo "done" echo -n "$configpath..." mkdir -p $configpath +mkdir -p $configpath/rss mkdir -p $configpath/users mkdir -p $configpath/userconfig echo "done" diff --git a/Rocksolid_Light/freebsd-install.sh b/Rocksolid_Light/freebsd-install.sh index 99ca126..c40772f 100755 --- a/Rocksolid_Light/freebsd-install.sh +++ b/Rocksolid_Light/freebsd-install.sh @@ -73,6 +73,7 @@ mkdir -p $spoolpath echo "done" echo -n "$configpath..." mkdir -p $configpath +mkdir -p $configpath/rss mkdir -p $configpath/users mkdir -p $configpath/userconfig echo "done" diff --git a/Rocksolid_Light/rocksolid/lib/post.inc.php b/Rocksolid_Light/rocksolid/lib/post.inc.php index 4a61f6c..9455716 100644 --- a/Rocksolid_Light/rocksolid/lib/post.inc.php +++ b/Rocksolid_Light/rocksolid/lib/post.inc.php @@ -194,7 +194,7 @@ function check_rate_limit($name,$set=0,$gettime=0) { * $ref: The references of the article * $body: The article itself */ -function message_post($subject,$from,$newsgroups,$ref,$body,$encryptthis,$encryptto,$authname) { +function message_post($subject,$from,$newsgroups,$ref,$body,$encryptthis=null,$encryptto=null,$authname=null,$followupto=null) { global $server,$port,$send_poster_host,$text_error,$CONFIG; global $www_charset,$config_dir,$spooldir; global $msgid_generate,$msgid_fqdn; @@ -259,6 +259,9 @@ function message_post($subject,$from,$newsgroups,$ref,$body,$encryptthis,$encryp } } fputs($ns,'From: '.$from."\r\n"); + if($followupto !== null) { + fputs($ns,'Followup-To: '.$followupto."\r\n"); + } fputs($ns,'Newsgroups: '.$newsgroups."\r\n"); $sitekey=password_hash($CONFIG['thissitekey'].$msgid, PASSWORD_DEFAULT); fputs($ns,'X-Rslight-Site: '.$sitekey."\r\n"); diff --git a/Rocksolid_Light/rocksolid/post.php b/Rocksolid_Light/rocksolid/post.php index 687c859..f094704 100644 --- a/Rocksolid_Light/rocksolid/post.php +++ b/Rocksolid_Light/rocksolid/post.php @@ -260,7 +260,11 @@ if ($type=="post") { } } // echo '

'.$text_post["button_back"].' '.$text_post["button_back2"].' '.group_display_name($returngroup[0]).'

'; - echo '

Back to Previous Page

'; + if(isset($_REQUEST['returngroup']) && $_REQUEST['returngroup'] !== '') { + echo '

Your post will appear in '.group_display_name($_REQUEST['returngroup']).'

'; + } else { + echo '

Back to Previous Page

'; + } } else { // article not accepted by the newsserver $type="retry"; @@ -342,7 +346,6 @@ if ($newsgroups == "") { } else { // show post form $fieldencrypt=md5(rand(1,10000000)); - echo '

'.$text_post["group_head"].group_display_name($newsgroups) .$text_post["group_tail"].'

'; @@ -438,16 +441,16 @@ function quoten() { echo captcha::form($text_post["captchainfo1"],$text_post["captchainfo2"]); echo ''; } ?> + - + - diff --git a/Rocksolid_Light/rslight/scripts/cron.php b/Rocksolid_Light/rslight/scripts/cron.php index d668dfb..1d331a8 100755 --- a/Rocksolid_Light/rslight/scripts/cron.php +++ b/Rocksolid_Light/rslight/scripts/cron.php @@ -74,6 +74,9 @@ foreach($menulist as $menu) { exec($CONFIG['php_exec']." ".$config_dir."/scripts/expire.php"); echo "Expired articles\n"; } +# Run RSS Feeds + exec($CONFIG['php_exec']." ".$config_dir."/scripts/rss-feeds.php"); + echo "RSS Feeds updated\n"; # Rotate log files log_rotate(); echo "Log files rotated\n"; diff --git a/Rocksolid_Light/rslight/scripts/rss-feeds.php b/Rocksolid_Light/rslight/scripts/rss-feeds.php new file mode 100755 index 0000000..65f2c28 --- /dev/null +++ b/Rocksolid_Light/rslight/scripts/rss-feeds.php @@ -0,0 +1,93 @@ +#!/usr/local/bin/php + time()) { + if(!is_file($rssdir.'/debug')) { + continue; + } + } + $xmlData = file_get_contents($RSS['url']); + $xml = simplexml_load_string($xmlData); + if($RSS['root'] != '') { + $xmlstart = $xml->{$RSS['root']}; + } else { + $xmlstart = $xml; + } + foreach($xmlstart->{$RSS['item']} as $item) + { + if(trim($item->{$RSS['link']}) == '') { + $item->{$RSS['link']} = $item->{$RSS['link']}[href]; + } else { + $item->{$RSS['link']} = $item->{$RSS['link']}; + } + $body.=$item->{$RSS['title']}."\n"; + if(isset($RSS['urlprefix']) && ($RSS['urlprefix'] !== '')) { + $url = $RSS['urlprefix'].$item->{$RSS['link']}; + } else { + $url = $item->{$RSS['link']}; + } + if(isset($RSS['urlprefixalt']) && ($RSS['urlprefixalt'] !== '')) { + $urlalt = $RSS['urlprefixalt'].$item->{$RSS['link']}; + } else { + $urlalt = ''; + } + if(substr($url,0,4) !== "http") { + $urlprefix = explode('/', $RSS['url']); + $url = $urlprefix[0].'/'.$urlprefix[1].'/'.$urlprefix[2].$item->{$RSS['link']}; + } + $body.=$url."\n"; + if($urlalt !== '') { + $body.=$urlalt."\n"; + } + if(isset($RSS['date_namespaceuri']) && ($RSS['date_namespaceuri'] !== '')) { + $dc_date = $item->children($RSS['date_namespaceuri']); + $body.=date("F j, Y, g:i A", strtotime($dc_date)); + } else { + $body.=date("F j, Y, g:i A", strtotime($item->{$RSS['date']})); + } + $body.="\n"; + $body.=trim($item->{$RSS['content']}); + $body.="\n--------------------\n"; + } + if(strpos($RSS['postfrom'], '@') === false) { + $RSS['postfrom'] = $RSS['postfrom'].$CONFIG['email_tail']; + } + if(isset($RSS['followupto']) && ($RSS['followupto'] !== '')) { + $followupto = $RSS['followupto']; + } else { + $followupto = null; + } + $body = strip_tags($body); + + if(is_file($rssdir.'/debug')) { + echo $body; + } else { + echo message_post($RSS['message_subject'], $RSS['postfrom'], $RSS['newsgroup'], null, $body, null, null, null, $followupto)."\n"; + touch($spooldir.'/'.$rssfile.'-rss-timer'); + } + } + + function get_rss_config($rssfile) { + $RSS = include($rssfile); + return($RSS); + } +?> diff --git a/Rocksolid_Light/spoolnews/lib b/Rocksolid_Light/spoolnews/lib new file mode 120000 index 0000000..79e163b --- /dev/null +++ b/Rocksolid_Light/spoolnews/lib @@ -0,0 +1 @@ +../rocksolid/lib \ No newline at end of file diff --git a/Rocksolid_Light/spoolnews/post.php b/Rocksolid_Light/spoolnews/post.php new file mode 120000 index 0000000..60deb78 --- /dev/null +++ b/Rocksolid_Light/spoolnews/post.php @@ -0,0 +1 @@ +../rocksolid/post.php \ No newline at end of file