Browse Source

BugFix - Small bugfix to Archive Code

main
PupperWoff 7 years ago
committed by discomrade
parent
commit
e74c54601e
  1. 8
      UPDATE_SCRIPT__ARCHIVING_OF_THREADS.php
  2. 171
      UPDATE_SCRIPT__HASHING_OF_IP_ADDRESSES.php
  3. 9
      inc/archive.php
  4. 48
      inc/config.php

8
ARCHIVE_UPDATE_SCRIPT.php → UPDATE_SCRIPT__ARCHIVING_OF_THREADS.php

@ -55,10 +55,10 @@ switch($step)
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['archive'] . $config['dir']['img'] . ". Check permissions.<br/>";
if (!file_exists($_board['dir'] . $config['dir']['archive'] . $config['dir']['thumb']))
@mkdir($_board['dir'] . $config['dir']['archive'] . $config['dir']['thumb'], 0777)
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['archive'] . $config['dir']['img'] . ". Check permissions.<br/>";
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['archive'] . $config['dir']['thumb'] . ". Check permissions.<br/>";
if (!file_exists($_board['dir'] . $config['dir']['archive'] . $config['dir']['res']))
@mkdir($_board['dir'] . $config['dir']['archive'] . $config['dir']['res'], 0777)
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['archive'] . $config['dir']['img'] . ". Check permissions.<br/>";
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['archive'] . $config['dir']['res'] . ". Check permissions.<br/>";
// Create Featured threads Folders
if (!file_exists($_board['dir'] . $config['dir']['featured']))
@mkdir($_board['dir'] . $config['dir']['featured'], 0777)
@ -68,10 +68,10 @@ switch($step)
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['featured'] . $config['dir']['img'] . ". Check permissions.<br/>";
if (!file_exists($_board['dir'] . $config['dir']['featured'] . $config['dir']['thumb']))
@mkdir($_board['dir'] . $config['dir']['featured'] . $config['dir']['thumb'], 0777)
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['featured'] . $config['dir']['img'] . ". Check permissions.<br/>";
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['featured'] . $config['dir']['thumb'] . ". Check permissions.<br/>";
if (!file_exists($_board['dir'] . $config['dir']['featured'] . $config['dir']['res']))
@mkdir($_board['dir'] . $config['dir']['featured'] . $config['dir']['res'], 0777)
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['featured'] . $config['dir']['img'] . ". Check permissions.<br/>";
or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['featured'] . $config['dir']['res'] . ". Check permissions.<br/>";
}
if (!empty($sql_errors))

171
UPDATE_SCRIPT__HASHING_OF_IP_ADDRESSES.php

@ -0,0 +1,171 @@
<?php
// require 'inc/config.php';
// require 'inc/config_instance.php';
require 'inc/functions.php';
global $config;
// Check so only ADMIN can run script
check_login(true);
if (!$mod || $mod['type'] != ADMIN)
die("You need to be logged in as admin");
$page['title'] = 'Updating Database Hashing IP';
$step = isset($_GET['step']) ? round($_GET['step']) : 0;
switch($step)
{
default:
case 0:
$page['body'] = '<p style="text-align:center">You are about to update the entries in the database to hashed version.<br/>THIS IS CAH NOT BE UNDONE!<br/>If any error occure during update and you run the update again some ip data might be wrong in db and not recoverable.</p>';
$page['body'] .= '<p style="text-align:center"><a href="?step=2">Click here to update database entries. WARNING: UPDATE IS IRREVERSABLE.</a></p>';
break;
case 2:
$page['body'] = '<p style="text-align:center">All database IP entries have been hashed.</p>';
$sql_errors = "";
// Update bans table to hashed ip
$query = prepare("SELECT DISTINCT `ipstart` FROM ``bans`` WHERE `ipstart` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter bans<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``bans`` SET `ipstart` = :ip, `ipend` = NULL WHERE `ipstart` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ipstart']));
$update_query->bindValue(':ip_org', $entry['ipstart']);
$update_query->execute() or $sql_errors .= '<li>Alter bans<br/>' . db_error() . '</li>';
}
// Update custom_geoip table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``custom_geoip`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>custom_geoip<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``custom_geoip`` SET `ip` = :ip WHERE `ip` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter custom_geoip<br/>' . db_error() . '</li>';
}
// Update flood table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``flood`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter flood<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``flood`` SET `ip` = :ip WHERE `ip` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter flood<br/>' . db_error() . '</li>';
}
// Update ip_notes table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``ip_notes`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter ip_notes<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``ip_notes`` SET `ip` = :ip WHERE `ip` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter ip_notes<br/>' . db_error() . '</li>';
}
// Update modlogs table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``modlogs`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter modlogs<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``modlogs`` SET `ip` = :ip WHERE `ip` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter modlogs<br/>' . db_error() . '</li>';
}
// Update mutes table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``mutes`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter mutes<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``mutes`` SET `ip` = :ip WHERE `ip` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter mutes<br/>' . db_error() . '</li>';
}
// Update posts_* table to hashed ip
// Get list of boards
$boards = listBoards();
foreach ($boards as &$_board) {
$query = prepare(sprintf("SELECT DISTINCT `ip` FROM ``posts_%s`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'", $_board['uri']));
$query->execute() or $sql_errors .= '<li>posts_*<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare(sprintf("UPDATE ``posts_%s`` SET `ip` = :ip WHERE `ip` = :ip_org", $_board['uri']));
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter posts_*<br/>' . db_error() . '</li>';
}
}
// Update reports table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``reports`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter reports<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``reports`` SET `ip` = :ip WHERE `ip` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter reports<br/>' . db_error() . '</li>';
}
// Update nicenotices table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``nicenotices`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter nicenotices<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``nicenotices`` SET `ip` = :ip WHERE `ip` = :ip_org");
$query->bindValue(':ip', get_ip_hash($entry['ip']));
$query->bindValue(':ip_org', $entry['ip']);
$query->execute() or $sql_errors .= '<li>Alter nicenotices<br/>' . db_error() . '</li>';
}
// Update search_queries table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``search_queries`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter search_queries<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``search_queries`` SET `ip` = :ip WHERE `ip` = :ip_org");
$query->bindValue(':ip', get_ip_hash($entry['ip']));
$query->bindValue(':ip_org', $entry['ip']);
$query->execute() or $sql_errors .= '<li>Alter search_queries<br/>' . db_error() . '</li>';
}
// Update warnings table to hashed ip
$query = prepare("SELECT DISTINCT `ip` FROM ``warnings`` WHERE `ip` REGEXP '^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$'");
$query->execute() or $sql_errors .= '<li>Alter warnings<br/>' . db_error() . '</li>';
while($entry = $query->fetch()) {
$update_query = prepare("UPDATE ``warnings`` SET `ip` = :ip WHERE `ip` = :ip_org");
$update_query->bindValue(':ip', get_ip_hash($entry['ip']));
$update_query->bindValue(':ip_org', $entry['ip']);
$update_query->execute() or $sql_errors .= '<li>Alter warnings<br/>' . db_error() . '</li>';
}
if (!empty($sql_errors))
$page['body'] .= '<div class="ban"><h2>SQL errors</h2><p>SQL errors were encountered when trying to update the database and hashing ip addresses.</p><p>The errors encountered were:</p><ul>' . $sql_errors . '</ul></div>';
break;
}
echo Element('page.html', $page);
?>
<!-- There is probably a much better way to do this, but eh. -->
<link rel="stylesheet" type="text/css" href="stylesheets/style.css" />

9
inc/archive.php

@ -114,7 +114,7 @@ class Archive {
// Delete all static pages and files for archived threads that has timed out
$query = prepare(sprintf("SELECT `id`, `files` FROM ``archive_%s`` WHERE `lifetime` < :lifetime AND `featured` = 0", $board['uri']));
$query->bindValue(':lifetime', strtotime("+".$config['archive']['lifetime']." days"), PDO::PARAM_INT);
$query->bindValue(':lifetime', strtotime("-" . $config['archive']['lifetime']), PDO::PARAM_INT);
$query->execute() or error(db_error($query));
while($thread = $query->fetch(PDO::FETCH_ASSOC)) {
// Delete Files
@ -128,8 +128,11 @@ class Archive {
}
// Delete Archive Entries
if($query->rowCount() != 0)
$query = query(sprintf("DELETE FROM ``archive_%s`` WHERE `lifetime` < %d AND `featured` = 0", $board['uri'], time())) or error(db_error());
if($query->rowCount() != 0) {
$query = prepare(sprintf("DELETE FROM ``archive_%s`` WHERE `lifetime` < %d AND `featured` = 0", $board['uri'], time())) or error(db_error());
$query->bindValue(':lifetime', strtotime("-" . $config['archive']['lifetime']), PDO::PARAM_INT);
$query->execute() or error(db_error($query));
}
return $query->rowCount();
}

48
inc/config.php

@ -1309,25 +1309,6 @@
// Directory for "Featured Threads" (threads makred for permanent storage)
$config['dir']['featured'] = 'featured/';
// Indicate if threads should be archived
$config['archive']['threads'] = true;
// Indicate if it is possible to mark threads as featured (stored forever)
$config['feature']['threads'] = true;
// Indicate if link to featured archive should be shown on post and thread page
$config['feature']['link_post_page'] = false;
// Days to keep archived threads before deletion (if set to false all archived threads are kept forever)
$config['archive']['lifetime'] = 3;
// Number of chars in snippet
$config['archive']['snippet_len'] = 400;
// If any is set to run in crom both will be run in cron regardless
// Archiving is run in cron job
$config['archive']['cron_job']['archiving'] = false;
// Purging of archive is run in cron job
$config['archive']['cron_job']['purge'] = false;
// For load balancing, having a seperate server (and domain/subdomain) for serving static content is
// possible. This can either be a directory or a URL. Defaults to $config['root'] . 'static/'.
@ -1368,6 +1349,35 @@
// Try not to build pages when we shouldn't have to.
$config['try_smarter'] = true;
/*
* ====================
* Archive settings
* ====================
*/
// Indicate if threads should be archived
$config['archive']['threads'] = true;
// Indicate if it is possible to mark threads as featured (stored forever)
$config['feature']['threads'] = true;
// Indicate if link to featured archive should be shown on post and thread page
$config['feature']['link_post_page'] = false;
// Days to keep archived threads before deletion (ex. "60 minutes", "6 hours", "1 day", "1 week"), if set to false all archived threads are kept forever
$config['archive']['lifetime'] = "3 days";
// Number of chars in snippet
$config['archive']['snippet_len'] = 400;
// If any is set to run in crom both will be run in cron regardless
// Archiving is run in cron job
$config['archive']['cron_job']['archiving'] = false;
// Purging of archive is run in cron job
$config['archive']['cron_job']['purge'] = false;
/*
* ====================
* Advanced build

Loading…
Cancel
Save