The version of vichan running on lainchan.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

36 line
1.1KB

  1. <?php
  2. // A script to recount bumps to recover from a last-page-bump attack
  3. // or to be run after the KusabaX Migration.
  4. require dirname(__FILE__) . '/inc/cli.php';
  5. if (!isset ($argv[1])) {
  6. die("Usage: tools/recount-bumps.php board_uri\n");
  7. }
  8. $board = $argv[1];
  9. $q = query(sprintf("SELECT `id`, `bump`, `time` FROM ``posts_%s``
  10. WHERE `thread` IS NULL", $board));
  11. while ($val = $q->fetch()) {
  12. $lc = prepare(sprintf('SELECT MAX(`time`) AS `aq` FROM ``posts_%s``
  13. WHERE ((`thread` = :thread and
  14. `email` != "sage" ) OR `id` = :thread', $board));
  15. $lc->bindValue(":thread", $val['id']);
  16. $lc->execute();
  17. $f = $lc->fetch();
  18. if ($val['bump'] != $f['aq']) {
  19. $query = prepare(sprintf("UPDATE ``posts_%s`` SET `bump`=:bump
  20. WHERE `id`=:id", $board));
  21. $query->bindValue(":bump", $f['aq']);
  22. $query->bindValue(":id", $val['id']);
  23. echo("Thread $val[id] - to be $val[bump] -> $f[aq]\n");
  24. }
  25. else {
  26. echo("Thread $val[id] ok\n");
  27. }
  28. }
  29. echo("done\n");