Merge branch 'devel'

This commit is contained in:
Retro_Guy 2024-06-15 06:27:24 -07:00
commit d3c10082d6
10 changed files with 3161 additions and 3013 deletions

View File

@ -1 +1 @@
0.9.12
0.9.133

View File

@ -185,7 +185,7 @@ function message_parse($rawmessage)
*/
function message_read($id, $bodynum = 0, $group = "")
{
global $CONFIG, $config_name, $cache_articles, $spooldir, $spoolpath, $logdir, $text_error, $ns;
global $CONFIG, $config_dir, $config_name, $cache_articles, $spooldir, $spoolpath, $logdir, $text_error, $ns;
$logfile = $logdir . '/newsportal.log';
if (! testGroup($group)) {
echo $text_error["read_access_denied"];
@ -194,6 +194,24 @@ function message_read($id, $bodynum = 0, $group = "")
if (! is_numeric($id)) {
return false;
}
// MEMCACHE if ($id, 0, $group)
if ($bodynum == 0 && $group != "") {
if (file_exists($config_dir . '/cache.inc.php')) {
include $config_dir . '/cache.inc.php';
}
}
if ($enable_cache) {
$cache_key = $cache_key_prefix . '_' . 'message_read-' . $id . '-0-' . $group;
$message_data = cache_get($cache_key, $memcacheD);
if ($message_data) {
if ($message = unserialize(gzuncompress($message_data))) {
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache hit) $cache_key", FILE_APPEND);
}
return $message;
}
}
}
$message = new messageType();
if ((isset($cache_articles)) && ($cache_articles == true)) {
// Try to load a cached article
@ -287,6 +305,13 @@ function message_read($id, $bodynum = 0, $group = "")
}
}
}
// MEMCACHE if ($id, 0, $group)
if ($enable_cache) {
$nicole = cache_add($cache_key, gzcompress(serialize($message)), $cache_ttl, $memcacheD);
if ($enable_cache_logging && $nicole) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) " . $cache_key, FILE_APPEND);
}
}
return $message;
}
@ -615,9 +640,7 @@ function display_full_headers($article, $group, $name, $from, $getface = false)
} else {
$message = $current_message;
}
if (isset($sendface)) {
unlink($sendface);
}
$sendface = null;
$isface = 0;
$return = '';
foreach ($message as $line) {
@ -805,8 +828,11 @@ function message_show($group, $id, $attachment = 0, $article_data = false, $maxl
}
if (($block_xnoarchive) && (isset($head->xnoarchive)) && ($head->xnoarchive == "yes")) {
echo $text_article["block-xnoarchive"];
} else if (($head->content_type[$attachment] == "text/plain") && ($attachment == 0)) {
echo '<hr><p class=np_ob_posted_date>' . $text_article["block-xnoarchive"] . '(article #' . $id . ')</p><hr>';
return "no-archive";
}
if (($head->content_type[$attachment] == "text/plain") && ($attachment == 0)) {
show_header($head, $group, $local_poster);
// X-Face
if (($face = display_full_headers($head->number, $group, $head->name, $head->from, true)) && ($OVERRIDES['disable_xface'] != true)) {

View File

@ -68,17 +68,20 @@ function thread_pageselect($group, $article_count, $first)
function thread_cache_load($group)
{
global $spooldir, $config_dir, $logdir, $compress_spoolfiles;
if (file_exists($config_dir . '/memcache.inc.php')) {
include $config_dir . '/memcache.inc.php';
if (file_exists($config_dir . '/cache.inc.php')) {
include $config_dir . '/cache.inc.php';
}
// Check memcache
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
if ($headers = unserialize(gzuncompress($memcacheD->get($key)))) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $key", FILE_APPEND);
if ($enable_cache) {
$cache_key = $cache_key_prefix . '_' . 'thread_cache-' . $group;
$message_data = cache_get($cache_key, $memcacheD);
if ($message_data) {
if ($headers = unserialize(gzuncompress($message_data))) {
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache hit) $cache_key", FILE_APPEND);
}
return $headers;
}
return $headers;
}
}
@ -93,24 +96,22 @@ function thread_cache_load($group)
}
$dbh = null;
}
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
if ($enable_cache) {
$add_thread = gzcompress(serialize($headers), 9);
$thread_bytes = strlen($add_thread);
$too_big = false;
if($thread_bytes < $memcache_maxitemsize) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
if ($thread_bytes < $cache_maxitemsize) {
$nicole = cache_add($cache_key, $add_thread, $cache_ttl, $memcacheD);
} else {
$nicole = false;
$too_big = true;
}
if ($nicole && $enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $key (" . strlen($add_thread) . " bytes)", FILE_APPEND);
if ($nicole && $enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) $cache_key (" . strlen($add_thread) . " bytes)", FILE_APPEND);
}
if ($too_big) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " $cache_key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
}
}
return ($headers);
@ -127,8 +128,8 @@ function thread_cache_save($headers, $group)
global $spooldir, $compress_spoolfiles, $config_dir, $logdir, $config_name;
$logfile = $logdir . '/newsportal.log';
if (file_exists($config_dir . '/memcache.inc.php')) {
include $config_dir . '/memcache.inc.php';
if (file_exists($config_dir . '/cache.inc.php')) {
include $config_dir . '/cache.inc.php';
}
$database = $spooldir . '/' . $group . '-data.db3';
@ -150,27 +151,27 @@ function thread_cache_save($headers, $group)
]);
$dbh->commit();
$dbh = null;
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'thread_cache-' . $group;
$del = $memcacheD->delete($key);
if ($enable_cache) {
$cache_key = $cache_key_prefix . '_' . 'thread_cache-' . $group;
$del = cache_delete($cache_key, $memcacheD);
$add_thread = gzcompress(serialize($headers), 9);
$thread_bytes = strlen($add_thread);
$too_big = false;
if($thread_bytes < $memcache_maxitemsize) {
$nicole = $memcacheD->add($key, $add_thread, $memcache_ttl);
if ($thread_bytes < $cache_maxitemsize) {
$nicole = cache_add($cache_key, $add_thread, $cache_ttl, $memcacheD);
} else {
$too_big = true;
$nicole = false;
}
if ($enable_memcache_logging) {
if ($enable_cache_logging) {
if ($del) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache delete) $key", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " (cache delete) $cache_key", FILE_APPEND);
}
if ($nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $key (" . $thread_bytes . " bytes)", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) $cache_key (" . $thread_bytes . " bytes)", FILE_APPEND);
}
if ($too_big) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " $key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " $cache_key too large (" . $thread_bytes . " bytes)", FILE_APPEND);
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -308,7 +308,9 @@ function display_threads($threads, $oldest)
$style = 0;
$results = 0;
foreach ($nicole as $key => $value) {
$target_head = $this_overboard['msgids'][$key];
if (isset($this_overboard['msgids'][$key])) {
$target_head = $this_overboard['msgids'][$key];
}
if (! isset($target_head['msgid'])) {
$target_head = get_data_from_msgid($key);
}
@ -333,7 +335,6 @@ function display_threads($threads, $oldest)
}
}
$results ++;
$lone == '';
$skip = '';
if ($nohead) {
if (($style % 2) == 0) {

View File

@ -42,7 +42,7 @@ if (! isset($_SESSION['remote_address'])) {
$ip_pass = true;
}
}
if ($ip_pass && $_SESSION['pass']) {
if ($ip_pass && (isset($_SESSION['pass']) && $_SESSION['pass'] === true)) {
$logged_in = true;
} else {
$logged_in = false;
@ -141,7 +141,7 @@ if (function_exists("npreg_get_email")) {
if (! strcmp($name, $CONFIG['anonusername']) && (isset($CONFIG['anonuser']))) {
$userpass = $CONFIG['anonuserpass'];
$email = $name . $CONFIG['email_tail'];
$_SESSION['pass'] = '0';
$_SESSION['pass'] = false;
} else {
$userpass = $email;
$request = "email";
@ -251,10 +251,10 @@ if ($type == "post") {
return;
}
}
// Wrap long lines in message body
$body = wrap_post($body);
if (isset($_FILES["photo"]) && $_FILES["photo"]["error"] == 0) {
$_FILES['photo']['name'] = preg_replace('/[^a-zA-Z0-9\.]/', '_', $_FILES['photo']['name']);
// There is an attachment to handle
@ -262,10 +262,10 @@ if ($type == "post") {
} else {
$message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes($body), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname']);
/*
$message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(mb_wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname'], null, true);
} else {
$message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(mb_wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname']);
*/
* $message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(mb_wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname'], null, true);
* } else {
* $message = message_post(quoted_printable_encode($subject), $nemail . " (" . quoted_printable_encode($name) . ")", $newsgroups, $references_array, addslashes(mb_wordwrap($body, 75)), $_POST['encryptthis'], $_POST['encryptto'], strtolower($name), $_POST['fromname']);
*/
}
// Article sent without errors, or duplicate?
if ((substr($message, 0, 3) == "240") || (substr($message, 0, 7) == "441 435")) {
@ -371,7 +371,7 @@ if ($show == 1) {
$ngroups = preg_split("/[\s,]+/", $newsgroups);
$found = false;
foreach ($ngroups as $group) {
if(get_section_by_group($group)) {
if (get_section_by_group($group)) {
$found = true;
break;
}
@ -379,7 +379,7 @@ if ($show == 1) {
// show post form
$fieldencrypt = md5(rand(1, 10000000));
echo '<h1 class="np_post_headline">' . $text_post["group_head"] . group_display_name($newsgroups) . $text_post["group_tail"];
if(!$found) {
if (! $found) {
echo ' (posting will fail - no such group)';
}
echo '</h1>';
@ -404,7 +404,7 @@ if ($show == 1) {
echo '<input type="radio" id="hasfollowup" name="fgroups" value="' . $head->followup . '" checked>';
echo '</td><td>';
echo '<label for="followup">' . $head->followup . ' (followup-to is set';
if(!get_section_by_group($head->followup)) {
if (! get_section_by_group($head->followup)) {
echo ' but <b><i>posting will fail - no such group </i></b>';
}
echo ')</label></td>';

View File

@ -0,0 +1,81 @@
<?php
global $enable_cache, $rslight_version, $spooldir, $logdir, $cache_dir, $cache_log;
/*
* Set $enable_cache to the cache type you want to use
* memcached and php-memcached must be installed
* if using memcached.
* $enable_cache = 'memcached';
*
* This will use a directory for caching, no memcache
* $enable_cache = 'diskcache';
*
* or set to false (no quotes) to disable caching:
* $enable_cache = false;
*/
// $enable_cache = 'memcached';
// $enable_cache = 'diskcache';
$enable_cache = false;
// Enable logging to file (log file may be large)
$enable_cache_logging = false;
// Server & port details if using memcached
$memcache_server = '127.0.0.1';
$memcache_port = 11211;
/*
* Maximum size of data (in bytes) to save per key in memcache
*
* If using memcached This must be less than or equal to
* MAXITEMSIZE in memcached, which is 1MiB by default
* Increasing this here will not work unless it is also
* increased in memcached configuration
*
* If using diskcache, pruning by size is only done daily
*
* You probably do not need to change this
*/
$cache_maxitemsize = 1024000;
// Time in seconds to cache data
$cache_ttl = 14400;
/*
* A string to prepend to cached key names
* Necessary if using more than one rslight instance
* with one memcache instance
*/
$cache_key_prefix = 'mysite';
// Directory to cache data if using diskcache
$cache_dir = $spooldir . '/cache/';
/* PLEASE DO NOT EDIT BELOW THIS LINE */
$cache_log = $logdir . '/cache.log';
@mkdir($cache_dir);
// Add version to prefix to avoid errors if upgrading
// and not restarting memcached
$cache_key_prefix .= trim(preg_replace('/\./', '', $rslight_version));
/* IF MEMCACHED */
if ($enable_cache == 'memcached') {
$memcacheD = new Memcached('memcacheD');
$memcacheD->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$memcacheD->setOption(Memcached::OPT_CONNECT_TIMEOUT, 1000);
if (! count($memcacheD->getServerList())) {
if (! $memcacheD->addServers(array(
array(
$memcache_server,
$memcache_port
)
))) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . ' Failed to connect memcache ' . $memcache_server . ':' . $memcache_port, FILE_APPEND);
} else {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . ' Connected memcache ' . $memcache_server . ':' . $memcache_port, FILE_APPEND);
}
}
} else {
$memcacheD = null;
}
/* END IF MEMCACHED */

View File

@ -1,55 +0,0 @@
<?php
/* memcached and php-memcached must be installed */
// Set to true to enable memcache
$enable_memcache = false;
// Server & port details
$memcache_server = '127.0.0.1';
$memcache_port = 11211;
// Enable logging to file (log file may be large)
$enable_memcache_logging = false;
// Time in seconds to cache data
$memcache_ttl = 14400;
/*
* Maximum size of data (in bytes) to save per key in memcache
* This must be less than or equal to
* MAXITEMSIZE in memcached, which is 1MiB by default
* Increasing this here will not work unless it is also
* increased in memcached configuration
* You probably do not need to change this
*/
$memcache_maxitemsize = 1024000;
/*
* A string to prepend to cached key names
* Required if using more than one rslight instance
* with one memcache instance
*/
$memcache_key_prefix = 'rsl';
/* PLEASE DO NOT EDIT BELOW THIS LINE */
if ($enable_memcache) {
$memcacheD = new Memcached('memcacheD');
$memcacheD->setOption(Memcached::OPT_LIBKETAMA_COMPATIBLE, true);
$memcacheD->setOption(Memcached::OPT_CONNECT_TIMEOUT, 1000);
if (! count($memcacheD->getServerList())) {
if (! $memcacheD->addServers(array(
array(
$memcache_server,
$memcache_port
)
))) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . ' Failed to connect memcache ' . $memcache_server . ':' . $memcache_port, FILE_APPEND);
} else {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . ' Connected memcache ' . $memcache_server . ':' . $memcache_port, FILE_APPEND);
}
}
}
}

View File

@ -12,7 +12,7 @@ if (file_exists($config_dir . '/cron.disable') || file_exists($spooldir . '/cron
chown($logfile, $CONFIG['webserver_user']);
exit();
} else {
file_put_contents($logfile, "\n" . date('M d H:i:s') . " " . $config_name . " cron ".$pid." started...", FILE_APPEND);
file_put_contents($logfile, "\n" . date('M d H:i:s') . " " . $config_name . " cron " . $pid . " started...", FILE_APPEND);
chown($logfile, $CONFIG['webserver_user']);
}
@ -40,16 +40,16 @@ if (isset($CONFIG['enable_nntp']) && $CONFIG['enable_nntp'] == true) {
}
}
}
$disabled_php = ini_get('disable_functions');
echo $disabled_php;
if(strpos($disabled_php, 'pcntl_fork') !== false) {
if (strpos($disabled_php, 'pcntl_fork') !== false) {
echo "\nERROR: pcntl_fork() disabled in php ini file, cannot fork (nntp server will not start).";
file_put_contents($logfile, "\n" . format_log_date() . " ERROR: pcntl_fork() disabled in php ini file, cannot fork (nntp server will not start).", FILE_APPEND);
} else {
exec($CONFIG['php_exec'] . " " . $config_dir . "/scripts/nntp.php > /dev/null 2>&1");
if (is_numeric($CONFIG['local_ssl_port'])) {
exec($CONFIG['php_exec'] . " " . $config_dir . "/scripts/nntp-ssl.php > /dev/null 2>&1");
exec($CONFIG['php_exec'] . " " . $config_dir . "/scripts/nntp-ssl.php > /dev/null 2>&1");
}
}
}
@ -75,7 +75,7 @@ $keydir = preg_replace('/spoolnews/', 'pubkey/', $cwd);
@chgrp($ssldir, $uinfo["gid"]);
$alias_file = $config_dir . '/aliases.conf';
if(!file_exists($alias_file)) {
if (! file_exists($alias_file)) {
touch($alias_file);
}
@chown($alias_file, $uinfo["uid"]);
@ -142,11 +142,19 @@ foreach ($menulist as $menu) {
echo "Expired articles\n";
}
# Expire diskcache
if (file_exists($config_dir . '/cache.inc.php')) {
include $config_dir . '/cache.inc.php';
if ($enable_cache == 'diskcache') {
prune_dir_by_days($cache_dir, $cache_ttl / 86400);
}
}
# Run RSS Feeds
exec($CONFIG['php_exec'] . " " . $config_dir . "/scripts/rss-feeds.php");
echo "RSS Feeds updated\n";
# Reload grouplist
if ((filemtime($grouplist_cache_filename) < (time() - ($grouplist_cache_time - 600)) || !file_exists($grouplist_cache_filename))) {
if ((filemtime($grouplist_cache_filename) < (time() - ($grouplist_cache_time - 600)) || ! file_exists($grouplist_cache_filename))) {
exec($CONFIG['php_exec'] . " ../common/grouplist.php .RELOAD");
echo "Refreshed grouplist\n";
}
@ -159,9 +167,10 @@ echo "Keys rotated\n";
# Expire files
expire_files();
echo "Removed old files\n";
file_put_contents($logfile, "\n" . date('M d H:i:s') . " " . $config_name . " cron ".$pid." completed...", FILE_APPEND);
file_put_contents($logfile, "\n" . date('M d H:i:s') . " " . $config_name . " cron " . $pid . " completed...", FILE_APPEND);
function expire_files() {
function expire_files()
{
global $spooldir, $logdir;
$now = time();
// Days to prune
@ -171,39 +180,38 @@ function expire_files() {
// Dirs to prune
$nocem_processed = $spooldir . "/nocem/processed/";
$nocem_failed = $spooldir . "/nocem/failed/";
if(!is_dir($nocem_processed)) {
if (! is_dir($nocem_processed)) {
@mkdir($nocem_processed, 0755, 'recursive');
@chown($nocem_processed, $uinfo["uid"]);
@chgrp($nocem_processed, $uinfo["gid"]);
}
if(!is_dir($nocem_failed)) {
if (! is_dir($nocem_failed)) {
@mkdir($nocem_failed, 0755, 'recursive');
@chown($nocem_failed, $uinfo["uid"]);
@chgrp($nocem_failed, $uinfo["gid"]);
}
// $nocem_processed
$filenames = array_diff(scandir($nocem_processed), array(
'..',
'.'
));
foreach($filenames as $one) {
if(filemtime($nocem_processed.$one) < $nocem) {
unlink($nocem_processed.$one);
foreach ($filenames as $one) {
if (filemtime($nocem_processed . $one) < $nocem) {
unlink($nocem_processed . $one);
}
}
// $nocem_failed
$filenames = array_diff(scandir($nocem_failed), array(
'..',
'.'
));
foreach($filenames as $one) {
if(filemtime($nocem_failed.$one) < $nocem) {
unlink($nocem_failed.$one);
foreach ($filenames as $one) {
if (filemtime($nocem_failed . $one) < $nocem) {
unlink($nocem_failed . $one);
}
}
}
function log_rotate()

View File

@ -67,6 +67,9 @@ if ($argv[1][0] == '-') {
default:
echo "-help: This help page\n";
echo "-version: Display version\n";
echo "******************* IMPORTANT **************************\n";
echo "*** PLEASE DISABLE cron.php WHEN RUNNING THIS SCRIPT ***\n";
echo "********************************************************\n";
echo "-clean: Remove extraneous group db3 files\n";
echo "-import: Import articles from a .db3 file (-import alt.test-articles)\n";
echo " You must first add group name to <config_dir>/<section>/groups.txt manually\n";
@ -172,7 +175,8 @@ function reset_group($group, $remove = 0)
$config_location = $spooldir . '/' . $section;
$config_files = array_diff(scandir($config_location), array(
'..',
'.'
'.',
'outgoing'
));
foreach ($config_files as $config_file) {
@ -200,19 +204,30 @@ function remove_articles($group)
$group = trim($group);
# Overview
$dbh = overview_db_open($spooldir . '/articles-overview.db3');
$clear_stmt = $dbh->prepare("DELETE FROM overview WHERE newsgroup=:group");
$clear_stmt->bindParam(':group', $group);
$clear_stmt->execute();
$dbh = null;
$overview_dbh = overview_db_open($spooldir . '/articles-overview.db3');
$fetch_stmt = $overview_dbh->prepare("SELECT msgid FROM overview WHERE newsgroup=:group");
$fetch_stmt->bindParam(':group', $group);
$fetch_stmt->execute();
$del_array = array();
while ($row = $fetch_stmt->fetch()) {
if (isset($row['msgid'])) {
$del_array[] = $row['msgid'];
}
}
$overview_dbh = null;
foreach($del_array as $delme) {
delete_message($delme, $group);
echo "Deleting " . $delme . " from " . $group . "\n";
}
# History
$dbh = history_db_open($spooldir . '/history.db3');
$clear_stmt = $dbh->prepare("DELETE FROM history WHERE newsgroup=:group");
$history_dbh = history_db_open($spooldir . '/history.db3');
$clear_stmt = $history_dbh->prepare("DELETE FROM history WHERE newsgroup=:group");
$clear_stmt->bindParam(':group', $group);
$clear_stmt->execute();
$dbh = null;
$history_dbh = null;
rename($spooldir . '/' . $group . '-articles.db3', $spooldir . '/' . $group . '-articles.db3-removed');
unlink($spooldir . '/' . $group . '-data.db3');
unlink($spooldir . '/' . $group . '-info.txt');