source: trunk/scripts/init-blog-comments @ 1184

Revision 997, 2.1 KB checked in by strat.cristian@…, 3 years ago (diff)

Log remote IP and X-Forwarded-For header on job submit, textblock create/edit, and attachment upload. For privacy considerations, IP addresses are only displayed to admins and helpers.

  • Contains database migration script.
  • Adds new simplified security action. (sensitive-info)
  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3require_once(dirname($argv[0]) . "/utilities.php");
4require_once(IA_ROOT_DIR . "common/db/blog.php");
5require_once(IA_ROOT_DIR."common/textblock.php");
6
7ini_set("memory_limit", "128M");
8
9db_connect();
10
11$query = "DROP TABLE IF EXISTS `ia_blog_forum`";
12db_query($query);
13$query = "CREATE TABLE `ia_blog_forum` (
14   `textblock` VARCHAR(64) NOT NULL,
15   `topic_id` int(11) NOT NULL
16) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE latin1_general_ci;";
17db_query($query);
18
19
20$blog_posts = blog_get_range('', 0, 666013);
21$pattern = '/==\ *BlogCommentCount\(\ *topic_id="\ *([0-9]*).*0*\ *"\ *\)\ *==/i';
22foreach ($blog_posts as $post) {
23    $content = $post['text'];
24    if (preg_match($pattern, $content, $matches)) {
25        $topic_id = $matches[1];
26        log_print($post['name'].' -> '.$topic_id);
27        $query = sprintf("INSERT INTO ia_blog_forum VALUES('%s', %s)", db_escape($post['name']), db_escape($topic_id));
28        db_query($query);
29
30        $content = preg_replace($pattern, "", $content);
31
32        // Build new page
33        $new_page['name'] = $post['name'];
34        $new_page['text'] = $content;
35        $new_page['title'] = $post['title'];
36        $new_page['security'] = $post['security'];
37        $new_page['creation_timestamp'] = $post['creation_timestamp'];
38        $new_page['timestamp'] = null;
39        $new_page['user_id'] = 1; // update as "domino" :)
40        $new_page['remote_ip_info'] = getattr($post, 'remote_ip_info');
41
42        // It worked
43        if (!textblock_validate($new_page)) {
44            textblock_add_revision($new_page['name'], $new_page['title'],
45                                   $new_page['text'], $new_page['user_id'],
46                                   $new_page['security'], $new_page['timestamp'],
47                                   $new_page['creation_timestamp'],
48                                   $new_page['remote_ip_info']);
49        } else {
50            log_error('Eroare la validarea textblock-ului!');
51            return false;
52        }
53    }
54    else {
55        log_warn('Nu s-a gasit topic pentru "'.$post['title'].'"!');
56    }
57}
58
59?>
Note: See TracBrowser for help on using the repository browser.