diff --git a/ARCHIVE_UPDATE_SCRIPT.php b/UPDATE_SCRIPT__ARCHIVING_OF_THREADS.php similarity index 93% rename from ARCHIVE_UPDATE_SCRIPT.php rename to UPDATE_SCRIPT__ARCHIVING_OF_THREADS.php index a3db6daf..83f13819 100644 --- a/ARCHIVE_UPDATE_SCRIPT.php +++ b/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.
"; 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.
"; + or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['archive'] . $config['dir']['thumb'] . ". Check permissions.
"; 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.
"; + or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['archive'] . $config['dir']['res'] . ". Check permissions.
"; // 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.
"; 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.
"; + or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['featured'] . $config['dir']['thumb'] . ". Check permissions.
"; 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.
"; + or $file_errors .= "Couldn't create " . $_board['dir'] . $config['dir']['featured'] . $config['dir']['res'] . ". Check permissions.
"; } if (!empty($sql_errors)) diff --git a/UPDATE_SCRIPT__HASHING_OF_IP_ADDRESSES.php b/UPDATE_SCRIPT__HASHING_OF_IP_ADDRESSES.php new file mode 100644 index 00000000..f2fd152a --- /dev/null +++ b/UPDATE_SCRIPT__HASHING_OF_IP_ADDRESSES.php @@ -0,0 +1,171 @@ +You are about to update the entries in the database to hashed version.
THIS IS CAH NOT BE UNDONE!
If any error occure during update and you run the update again some ip data might be wrong in db and not recoverable.

'; + $page['body'] .= '

Click here to update database entries. WARNING: UPDATE IS IRREVERSABLE.

'; + break; + case 2: + $page['body'] = '

All database IP entries have been hashed.

'; + + $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 .= '
  • Alter bans
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter bans
    ' . db_error() . '
  • '; + } + + // 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 .= '
  • custom_geoip
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter custom_geoip
    ' . db_error() . '
  • '; + } + + // 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 .= '
  • Alter flood
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter flood
    ' . db_error() . '
  • '; + } + + + // 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 .= '
  • Alter ip_notes
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter ip_notes
    ' . db_error() . '
  • '; + } + + + // 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 .= '
  • Alter modlogs
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter modlogs
    ' . db_error() . '
  • '; + } + + // 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 .= '
  • Alter mutes
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter mutes
    ' . db_error() . '
  • '; + } + + // 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 .= '
  • posts_*
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter posts_*
    ' . db_error() . '
  • '; + } + } + // 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 .= '
  • Alter reports
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter reports
    ' . db_error() . '
  • '; + } + // 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 .= '
  • Alter nicenotices
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter nicenotices
    ' . db_error() . '
  • '; + } + // 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 .= '
  • Alter search_queries
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter search_queries
    ' . db_error() . '
  • '; + } + // 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 .= '
  • Alter warnings
    ' . db_error() . '
  • '; + + 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 .= '
  • Alter warnings
    ' . db_error() . '
  • '; + } + + if (!empty($sql_errors)) + $page['body'] .= '

    SQL errors

    SQL errors were encountered when trying to update the database and hashing ip addresses.

    The errors encountered were:

    '; + + break; +} + + +echo Element('page.html', $page); + +?> + + diff --git a/inc/archive.php b/inc/archive.php index b4eca253..5824a36e 100644 --- a/inc/archive.php +++ b/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(); } diff --git a/inc/config.php b/inc/config.php index 0f0fd61f..ffcdf84d 100644 --- a/inc/config.php +++ b/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