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,19 +68,22 @@ 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;
}
}
}
$database = $spooldir . '/' . $group . '-data.db3';
$table = "threads";
@ -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);
}
}
}

View File

@ -602,8 +602,8 @@ function groups_show($gruppen)
return;
global $file_thread, $text_groups;
$logfile = $logdir . '/debug.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';
}
$c = count($gruppen);
$acttype = "keins";
@ -639,13 +639,15 @@ function groups_show($gruppen)
$found = 0;
// Get last article info from article database
// First check memcache
if ($memcacheD) {
$lar_memcache = $memcache_key_prefix . '_' . 'lastarticleinfo-' . $g->name;
if ($enable_cache) {
$memcache_key = $cache_key_prefix . '_' . 'lastarticleinfo-' . $g->name;
$groupfile = $spooldir . '/' . $g->name . '-lastarticleinfo.dat';
if ($lastarticleinfo = unserialize($memcacheD->get($lar_memcache))) {
$lar = cache_get($memcache_key, $memcacheD);
if ($lar) {
if ($lastarticleinfo = unserialize($lar)) {
if ($lastarticleinfo && file_exists($groupfile) && filemtime($groupfile) <= $lastarticleinfo['date']) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . ' (cache hit) lastarticleinfo for ' . $g->name, FILE_APPEND);
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . ' (cache hit) ' . $memcache_key, FILE_APPEND);
}
$found = 1;
} else {
@ -653,6 +655,7 @@ function groups_show($gruppen)
}
}
}
}
if (! isset($lastarticleinfo['date'])) {
if ($CONFIG['article_database'] == '1') {
$database = $spooldir . '/' . $g->name . '-articles.db3';
@ -685,15 +688,15 @@ function groups_show($gruppen)
}
if ($found == 1) {
$lastarticleinfo = $row;
if ($memcacheD) {
if ($enable_cache) {
touch($groupfile, $lastarticleinfo['date']);
$nicole = $memcacheD->delete($lar_memcache);
$memcacheD->add($lar_memcache, serialize($row), $memcache_ttl);
if ($enable_memcache_logging) {
$nicole = cache_delete($memcache_key, $memcacheD);
cache_add($memcache_key, serialize($row), $cache_ttl, $memcacheD);
if ($enable_cache_logging) {
if ($nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache update) $lar_memcache", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " (cache update) $memcache_key", FILE_APPEND);
} else {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $lar_memcache", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) $memcache_key", FILE_APPEND);
}
}
}
@ -1619,18 +1622,20 @@ function get_date_interval($value)
function get_newsgroups_by_msgid($msgid, $noarray = false)
{
global $spooldir, $config_dir, $logdir, $CONFIG;
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';
}
if ($memcacheD) {
$key = $memcache_key_prefix . '_' . 'get_newsgroups_by_msgid-' . $msgid;
if ($groups = $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) {
$memcache_key = $cache_key_prefix . '_' . 'get_newsgroups_by_msgid-' . $msgid;
if ($getgroups = cache_get($memcache_key, $memcacheD)) {
if ($groups = unserialize($getgroups)) {
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache hit) $memcache_key", FILE_APPEND);
}
}
}
if (! $groups) {
}
if (! isset($groups)) {
$database = $spooldir . '/articles-overview.db3';
$table = 'overview';
$overview_dbh = overview_db_open($database, $table);
@ -1648,10 +1653,10 @@ function get_newsgroups_by_msgid($msgid, $noarray = false)
$groups = null;
}
$overview_dbh = null;
if ($groups && $memcacheD) {
$nicole = $memcacheD->add($key, $groups, $memcache_ttl);
if ($enable_memcache_logging && $nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $key", FILE_APPEND);
if ($groups && $enable_cache) {
$nicole = cache_add($memcache_key, serialize($groups), $cache_ttl, $memcacheD);
if ($enable_cache_logging && $nicole) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) $memcache_key", FILE_APPEND);
}
}
}
@ -1900,20 +1905,20 @@ function np_get_db_article($article, $group, $makearray = 1, $dbh = null)
global $config_dir, $path, $groupconfig, $config_name, $logdir, $spooldir;
$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';
}
$msg2 = "";
$closeme = 0;
$ok_article = 0;
// Check memcache
if ($memcacheD) {
$article_key = $memcache_key_prefix . '_' . 'article.db3-' . $group . ':' . $article;
if ($msg2 = $memcacheD->get($article_key)) {
if ($enable_cache) {
$article_key = $cache_key_prefix . '_' . 'article.db3-' . $group . ':' . $article;
if ($msg2 = gzuncompress(cache_get($article_key, $memcacheD))) {
$ok_article = 1;
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $article_key", FILE_APPEND);
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache hit) $article_key", FILE_APPEND);
}
}
}
@ -1946,10 +1951,10 @@ function np_get_db_article($article, $group, $makearray = 1, $dbh = null)
break;
}
}
if ($ok_article == 1 && $memcacheD) {
$nicole = $memcacheD->add($article_key, $msg2, $memcache_ttl);
if ($enable_memcache_logging && $nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $article_key", FILE_APPEND);
if ($ok_article == 1 && $enable_cache) {
$nicole = cache_add($article_key, gzcompress($msg2), $cache_ttl, $memcacheD);
if ($enable_cache_logging && $nicole) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) $article_key", FILE_APPEND);
}
}
}
@ -2094,14 +2099,15 @@ function disable_page_by_user_agent($client_device, $useragent, $script = "Page"
}
}
function throttle_hits($client_device)
function throttle_hits($client_device = null)
{
global $CONFIG, $OVERRIDES, $logdir, $config_name;
$logfile = $logdir . '/newsportal.log';
if (! $client_device) {
$client_device = get_client_user_agent_info();
}
$client_device = strtolower($client_device);
$useragent = strtolower($useragent);
$_SESSION['rsactive'] = true;
@ -2112,7 +2118,7 @@ function throttle_hits($client_device)
file_put_contents($logfile, "\n" . format_log_date() . " " . $config_name . " Blocking " . $_SERVER['REMOTE_ADDR'] . " '" . $user_agent . "' listed in block list", FILE_APPEND);
$_SESSION['throttled'] = true;
header("HTTP/1.0 403 Forbidden");
exit;
exit();
}
}
}
@ -2469,14 +2475,14 @@ function insert_article_from_array($this_article, $check_duplicates = true)
unlink($grouppath . "/" . $this_article['local']);
$article_dbh = null;
// Add to memcache
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';
}
if ($memcacheD) {
$article_key = $memcache_key_prefix . '_' . 'article.db3-' . $group . ':' . $this_article['local'];
$nicole = $memcacheD->add($article_key, $this_article['article'], $memcache_ttl);
if ($enable_memcache_logging && $nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) (new) $article_key", FILE_APPEND);
if ($enable_cache) {
$article_key = $cache_key_prefix . '_' . 'article.db3-' . $group . ':' . $this_article['local'];
$nicole = cache_add($article_key, gzcompress($this_article['article']), $cache_ttl, $memcacheD);
if ($enable_cache_logging && $nicole) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) (new) $article_key", FILE_APPEND);
}
}
} else {
@ -2548,15 +2554,15 @@ function clear_history_by_group($group)
function get_db_data_from_msgid($msgid, $group)
{
global $spooldir, $config_dir, $logdir;
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';
}
if ($memcacheD) {
$row_cache = $memcache_key_prefix . '_' . 'get_db_data_from_msgid-' . $msgid;
if ($row = $memcacheD->get($row_cache)) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $row_cache", FILE_APPEND);
if ($enable_cache) {
$row_cache = $cache_key_prefix . '_' . 'get_db_data_from_msgid-' . $msgid;
if ($row = unserialize(gzuncompress(cache_get($row_cache, $memcacheD)))) {
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache hit) $row_cache", FILE_APPEND);
}
return $row;
}
@ -2578,10 +2584,10 @@ function get_db_data_from_msgid($msgid, $group)
}
$dbh = null;
if ($found) {
if ($memcacheD) {
$nicole = $memcacheD->add($row_cache, $row, $memcache_ttl);
if ($enable_memcache_logging && $nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $row_cache", FILE_APPEND);
if ($enable_cache) {
$nicole = cache_add($row_cache, gzcompress(serialize($row)), $cache_ttl, $memcacheD);
if ($enable_cache_logging && $nicole) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) $row_cache", FILE_APPEND);
}
}
return $row;
@ -2618,19 +2624,19 @@ function get_group_array_from_msgid($msgid)
function get_data_from_msgid($msgid, $thisgroup = null)
{
global $spooldir, $config_dir, $logdir, $CONFIG;
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';
}
if ($CONFIG['article_database'] == '1' && isset($thisgroup)) {
return get_db_data_from_msgid($msgid, $thisgroup);
}
if ($memcacheD) {
$row_cache = $memcache_key_prefix . '_' . 'get_data_from_msgid-' . $msgid;
if ($row = $memcacheD->get($row_cache)) {
if ($enable_memcache_logging) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache hit) $row_cache", FILE_APPEND);
if ($enable_cache) {
$row_cache = $cache_key_prefix . '_' . 'get_data_from_msgid-' . $msgid;
if ($row = cache_get($row_cache, $memcacheD)) {
if ($enable_cache_logging) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache hit) $row_cache", FILE_APPEND);
}
return $row;
}
@ -2657,10 +2663,10 @@ function get_data_from_msgid($msgid, $thisgroup = null)
}
$dbh = null;
if ($found) {
if ($memcacheD) {
$nicole = $memcacheD->add($row_cache, $row, $memcache_ttl);
if ($enable_memcache_logging && $nicole) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " (cache write) $row_cache", FILE_APPEND);
if ($enable_cache) {
$nicole = cache_add($row_cache, $row, $cache_ttl, $memcacheD);
if ($enable_cache_logging && $nicole) {
file_put_contents($cache_log, "\n" . format_log_date() . " (cache write) $row_cache", FILE_APPEND);
}
}
return $row;
@ -2743,8 +2749,8 @@ function send_admin_message($admin, $from, $subject, $message)
function delete_message($messageid, $group = null, $overview_dbh = null)
{
global $logfile, $logdir, $config_dir, $spooldir, $CONFIG, $webserver_group;
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';
}
if ($group == null) {
$grouplist = get_newsgroups_by_msgid($messageid);
@ -2811,14 +2817,14 @@ function delete_message($messageid, $group = null, $overview_dbh = null)
':msgid' => $messageid
]);
// Delete article from memcache
if ($memcacheD) {
$article_key = $memcache_key_prefix . '_' . 'article.db3-' . $group . ':' . $row['number'];
$result = $memcacheD->delete($article_key);
if ($enable_memcache_logging) {
if ($enable_cache) {
$article_key = $cache_key_prefix . '_' . 'article.db3-' . $group . ':' . $row['number'];
$result = cache_delete($article_key, $memcacheD);
if ($enable_cache_logging) {
if ($result) {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Deleted $article_key", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " Deleted $article_key", FILE_APPEND);
} else {
file_put_contents($logdir . '/memcache.log', "\n" . format_log_date() . " Failed to delete (or not found) $article_key", FILE_APPEND);
file_put_contents($cache_log, "\n" . format_log_date() . " Failed to delete (or not found) $article_key", FILE_APPEND);
}
}
}
@ -2926,6 +2932,7 @@ function delete_message_from_overboard($config_name, $group, $messageid)
$cachefile = $spooldir . "/" . $config_name . "-overboard.dat";
if (is_file($cachefile)) {
$cached_overboard = unserialize(file_get_contents($cachefile));
if (isset($cached_overboard['msgids'][$messageid])) {
if ($target = $cached_overboard['msgids'][$messageid]) {
unset($cached_overboard['threads'][$target['date']]);
unset($cached_overboard['msgids'][$messageid]);
@ -2933,9 +2940,11 @@ function delete_message_from_overboard($config_name, $group, $messageid)
file_put_contents($cachefile, serialize($cached_overboard));
}
}
}
$cachefile = $spooldir . "/" . $group . "-overboard.dat";
if (is_file($cachefile)) {
$cached_overboard = unserialize(file_get_contents($cachefile));
if (isset($cached_overboard['msgids'][$messageid])) {
if ($target = $cached_overboard['msgids'][$messageid]) {
unset($cached_overboard['threads'][$target['date']]);
unset($cached_overboard['msgids'][$messageid]);
@ -2944,3 +2953,65 @@ function delete_message_from_overboard($config_name, $group, $messageid)
}
}
}
}
function cache_add($cache_key, $data, $cache_ttl, $memcacheD = null)
{
global $enable_cache, $cache_dir, $cache_log, $low_spool_disk_space;
$cache_key = base64_encode($cache_key);
if ($enable_cache == 'memcached') {
if ($memcacheD) {
if ($nicole = $memcacheD->add($cache_key, $data, $cache_ttl)) {
return $nicole;
}
}
}
if ($enable_cache == 'diskcache') {
if ($low_spool_disk_space) {
file_put_contents($cache_log, "\n" . format_log_date() . " " . $config_name . " Low Disk Space (less than " . $min_spool_disk_space . "Gb available for cache). Pausing diskcache", FILE_APPEND);
return false;
}
if ($nicole = file_put_contents($cache_dir . '/' . $cache_key, $data)) {
return $nicole;
}
}
return false;
}
function cache_delete($cache_key, $memcacheD = null)
{
global $enable_cache, $cache_dir;
$cache_key = base64_encode($cache_key);
if ($enable_cache == 'memcached') {
if ($memcacheD) {
if ($nicole = $memcacheD->delete($cache_key)) {
return $nicole;
}
}
}
if ($enable_cache == 'diskcache') {
if (file_exists($cache_dir . '/' . $cache_key)) {
return unlink($cache_dir . '/' . $cache_key);
}
}
return false;
}
function cache_get($cache_key, $memcacheD = null)
{
global $enable_cache, $cache_dir;
$cache_key = base64_encode($cache_key);
if ($enable_cache == 'memcached') {
if ($memcacheD) {
if ($nicole = $memcacheD->get($cache_key)) {
return $nicole;
}
}
}
if ($enable_cache == 'diskcache') {
if (file_exists($cache_dir . '/' . $cache_key)) {
return file_get_contents($cache_dir . '/' . $cache_key);
}
}
return false;
}

View File

@ -308,7 +308,9 @@ function display_threads($threads, $oldest)
$style = 0;
$results = 0;
foreach ($nicole as $key => $value) {
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";
@ -262,9 +262,9 @@ 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?

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

@ -142,6 +142,14 @@ 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";
@ -161,7 +169,8 @@ 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);
function expire_files() {
function expire_files()
{
global $spooldir, $logdir;
$now = time();
// Days to prune
@ -203,7 +212,6 @@ function expire_files() {
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,18 +204,29 @@ 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');