1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
|
<html>
<body>
<?php
// --------------------------------
//
function decode_ip($int_ip)
{
$hexipbang = explode('.', chunk_split($int_ip, 2, '.'));
return hexdec($hexipbang[0]). '.' . hexdec($hexipbang[1]) . '.' . hexdec($hexipbang[2]) . '.' . hexdec($hexipbang[3]);
}
//
// --------------------------------
define('IN_PHPBB', 1);
$phpbb_root_path='./../';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'config.'.$phpEx);
include($phpbb_root_path . 'includes/constants.'.$phpEx);
include($phpbb_root_path . 'includes/functions.'.$phpEx);
include($phpbb_root_path . 'includes/db.'.$phpEx);
$sql = "SELECT config_value
FROM " . CONFIG_TABLE . "
WHERE config_name = 'version'";
if ( !($result = $db->sql_query($sql)) )
{
die("Couldn't obtain version info");
}
if ( $row = $db->sql_fetchrow($result) )
{
$sql = array();
switch ( $row['config_value'] )
{
case '.0.0':
case '.1.0 [20020402]':
echo 'Updating from [20020402] :: ';
flush();
$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
VALUES ('session_gc', '3600')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
VALUES ('session_last_gc', '0')";
echo '<span style="color:green">DONE</span><br /><br />';
case '.1.0 [20020420]':
switch ( SQL_LAYER )
{
case 'mysql':
case 'mysql4':
$sql[] = "CREATE TABLE " . $table_prefix . "forums_watch (forum_id smallint(5) UNSIGNED NOT NULL DEFAULT '0', user_id mediumint(8) NOT NULL DEFAULT '0', notify_status tinyint(1) NOT NULL default '0', KEY forum_id (forum_id), KEY user_id (user_id), KEY notify_status (notify_status))";
break;
case 'mssql-odbc':
case 'mssql':
$sql[] = "CREATE TABLE [" . $table_prefix . "forums_watch] ([forum_id] [int] NOT NULL , [user_id] [int] NOT NULL , [notify_status] [smallint] NOT NULL ) ON [PRIMARY]";
$sql[] = "CREATE INDEX [IX_" . $table_prefix . "forums_watch] ON [" . $table_prefix . "forums_watch]([forum_id], [user_id]) ON [PRIMARY]";
break;
case 'postgresql':
$sql[] = "CREATE TABLE " . $table_prefix . "forums_watch (forum_id int4, user_id int4, notify_status int2 NOT NULL default '0')";
$sql[] = "CREATE INDEX forum_id_" . $table_prefix . "forums_watch_index ON " . $table_prefix . "forums_watch (forum_id)";
$sql[] = "CREATE INDEX user_id_" . $table_prefix . "forums_watch_index ON " . $table_prefix . "forums_watch (user_id)";
default:
die("No DB LAYER found!");
break;
}
case '.1.0 [20020421]':
$user_data_sql = "SELECT COUNT(user_id) AS total_users, MAX(user_id) AS newest_user_id FROM " . USERS_TABLE . " WHERE user_id <> " . ANONYMOUS;
if($result = $db->sql_query($user_data_sql))
{
$row = $db->sql_fetchrow($result);
$user_count = $row['total_users'];
$newest_user_id = $row['newest_user_id'];
$username_sql = "SELECT username FROM " . USERS_TABLE . " WHERE user_id = $newest_user_id";
if(!$result = $db->sql_query($username_sql))
{
die('Could not get username to update to [20020430]');
}
$row = $db->sql_fetchrow($result);
$newest_username = $row['username'];
}
else
{
die('Could not get user count for update to [20020430]');
}
$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
VALUES ('newest_user_id', $newest_user_id)";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
VALUES ('newest_username', '$newest_username')";
$sql[] = "INSERT INTO " . CONFIG_TABLE . " (config_name, config_value)
VALUES ('num_users', $user_count)";
case '.1.0 [20020430]':
switch ( SQL_LAYER )
{
case 'mysql':
case 'mysql4':
$sql[] = "ALTER TABLE " . BANLIST_TABLE . "
MODIFY ban_email char(60) NULL,
MODIFY ban_ip char(40) NOT NULL";
$sql[] = "ALTER TABLE " . DISALLOW_TABLE . "
MODIFY disallow_username char(30) NOT NULL";
$sql[] = "ALTER TABLE " . POSTS_TABLE . "
MODIFY poster_ip char(40) NOT NULL,
MODIFY post_username char(30) NULL";
$sql[] = "ALTER TABLE " . PRIVMSGS_TABLE . "
MODIFY privmsgs_subject char(60) NOT NULL,
MODIFY privmsgs_ip char(40) NOT NULL";
$sql[] = "ALTER TABLE " . SESSIONS_TABLE . "
MODIFY session_ip char(40) NOT NULL";
$sql[] = "ALTER TABLE " . USERS_TABLE . "
ADD COLUMN user_ip char(40) NOT NULL";
$sql[] = "ALTER TABLE " . VOTE_USERS_TABLE . "
MODIFY COLUMN vote_user_ip char(40) NOT NULL";
break;
case 'mssql-odbc':
case 'mssql':
$sql[] = "";
break;
case 'postgresql':
$sql[] = "";
default:
die("No DB LAYER found!");
break;
}
break;
default;
echo 'No updates made<br /><br />';
}
if ( count($sql) )
{
for($i = 0; $i < count($sql); $i++)
{
$db->sql_query($sql[$i]);
}
}
$sql_update = array();
switch ( $row['config_value'] )
{
case '.1.0 [20020430]':
$sql = "SELECT ban_id, ban_ip
FROM " . BANLIST_TABLE;
$result = $db->sql_query($sql);
if ( $row = $db->sql_fetchrow($result) )
{
do
{
$ban_ip = str_replace('255', '256', decode_ip($row['ban_ip']));
$sql_update[] = "UPDATE " . BANLIST_TABLE . "
SET ban_ip = '$ban_ip'
WHERE ban_id = " . $row['ban_id'];
}
while ( $row = $db->sql_fetchrow($result) );
}
$sql = "SELECT DISTINCT poster_ip
FROM " . POSTS_TABLE . "
WHERE poster_ip NOT LIKE '%.%'";
$result = $db->sql_query($sql);
if ( $row = $db->sql_fetchrow($result) )
{
do
{
$sql_update[] = "UPDATE " . POSTS_TABLE . "
SET poster_ip = '" . decode_ip($row['poster_ip']) . "'
WHERE poster_ip LIKE '" . $row['poster_ip'] . "'";
}
while ( $row = $db->sql_fetchrow($result) );
}
$sql = "SELECT DISTINCT privmsgs_ip
FROM " . PRIVMSGS_TABLE;
$result = $db->sql_query($sql);
if ( $row = $db->sql_fetchrow($result) )
{
do
{
$sql_update[] = "UPDATE " . PRIVMSGS_TABLE . "
SET privmsgs_ip = '" . decode_ip($row['privmsgs_ip']) . "'
WHERE privmsgs_ip LIKE '" . $row['privmsgs_ip'] . "'";
}
while ( $row = $db->sql_fetchrow($result) );
}
$sql = "SELECT DISTINCT vote_user_ip
FROM " . VOTE_USERS_TABLE;
$result = $db->sql_query($sql);
if ( $row = $db->sql_fetchrow($result) )
{
do
{
$sql_update[] = "UPDATE " . VOTE_USERS_TABLE . "
SET vote_user_ip = '" . decode_ip($row['vote_user_ip']) . "'
WHERE vote_user_ip LIKE '" . $row['vote_user_ip'] . "'";
}
while ( $row = $db->sql_fetchrow($result) );
}
break;
}
if ( count($sql_update) )
{
echo 'Updating existing data :: ';
flush();
for($i = 0; $i < count($sql_update); $i++)
{
if ( !$db->sql_query($sql_update[$i]) )
{
die("Couldn't run update >> " . $sql_update[$i]);
}
}
echo "DONE<br /><br />\n";
}
}
$sql = "UPDATE " . CONFIG_TABLE . "
SET config_value = '.1.0 [20020905]'
WHERE config_name = 'version'";
$result = $db->sql_query($sql);
echo "\n<br />\n<b>COMPLETE!</b><br />\n";
echo "\n<p>Don't forget to delete this file!</p>\n";
?>
</body>
</html>
|