45
$do_unorged_users = FALSE;
46
$delete_not_updated = FALSE;
47
$show_org_names = TRUE;
48
$show_character_names = FALSE;
49
require ('whois-update.conf');
45
$do_unorged_users = false;
46
$delete_not_updated = false;
47
$show_org_names = true;
48
$show_character_names = false;
49
require('whois-update.conf');
50
50
// disable execution timeout:
56
56
if (@!dl("php_curl.dll")) {
57
57
echo "Curl not available\n";
60
59
echo "Curl extension loaded\n";
61
60
if (!extension_loaded("sockets")) {
62
61
if (!dl("php_sockets.dll")) {
69
67
if (function_exists('curl_init')) {
70
68
echo "Curl extension loaded\n";
73
70
echo "Curl not available\n";
74
71
if (!extension_loaded("sockets")) {
75
72
die("Sockets extention required to run this script");
83
80
if (!dl("php_mysql.dll")) {
84
81
die("Loading php_mysql.dll failed. MySQL extention required to run this script");
88
84
die("MySQL support required to run this script");
92
88
echo "Connecting to the database.\n\n";
93
$link = ($GLOBALS["___mysqli_ston"] = mysqli_connect($dbserver, $username, $password)) or die("Could not connect : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
89
$link = ($GLOBALS["___mysqli_ston"] = mysqli_connect(
93
)) or die("Could not connect : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error(
94
$GLOBALS["___mysqli_ston"]
95
) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
94
96
((bool)mysqli_query($GLOBALS["___mysqli_ston"], "USE $dbname")) or die("Could not select database");
95
97
// Get all org ids out of the whois table, get the org infos, and add/update all user:
96
98
$sqlquery = "SELECT org_id, org_name FROM (SELECT org_id, org_name, count(nickname) AS count FROM " . $tablename;
97
99
$sqlquery .= " WHERE org_id != '' GROUP BY org_name) AS temp_whois ORDER BY count DESC;";
98
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
100
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object(
101
$GLOBALS["___mysqli_ston"]
102
)) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error(
103
)) ? $___mysqli_res : false)));
99
104
// simple counter, increased by one each time a get_site() call is made:
100
105
$httpqueries = 0;
101
106
// same for REPLACE/UPDATE in db:
104
109
$failedrosterlookup = 0;
105
110
// same for failed person lookups:
106
111
$failedpersonlookup = 0;
107
while ($orgid = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
112
while ($orgid = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
108
113
if ($show_org_names) {
109
114
echo gmdate("H:i:s") . " - Querying roster for " . $orgid['org_name'] . " (" . $orgid['org_id'] . ")...\n";
111
$org_cont = get_site($baseurl . "/org/stats/d/" . $dimension . "/name/" . $orgid['org_id'] . "/basicstats.xml", 0, 60, 60);
116
$org_cont = get_site(
117
$baseurl . "/org/stats/d/" . $dimension . "/name/" . $orgid['org_id'] . "/basicstats.xml",
113
123
if (!$org_cont) {
114
124
echo " Could not get roster for " . $orgid['org_name'] . " (" . $orgid['org_id'] . ")!\n";
115
125
$failedrosterlookup++;
118
127
$starttime = time();
119
128
$orgname = $this->bot->db->real_escape_string(xmlparse($org_cont, "name"));
120
129
$orgfaction = xmlparse($org_cont, "side");
142
151
if (empty($who["nickname"])) {
143
152
echo " Warning! Missing members nickname!\n";
144
153
$failedpersonlookup++;
147
155
if (empty($who["level"])) {
148
156
echo " Warning! Missing members level! (" . $who["nickname"] . ")\n";
149
157
$failedpersonlookup++;
152
159
if (empty($who["gender"])) {
153
160
echo " Warning! Missing members gender! (" . $who["nickname"] . ")\n";
154
161
$failedpersonlookup++;
157
163
if (empty($who["breed"])) {
158
164
echo " Warning! Missing members breed! (" . $who["nickname"] . ")\n";
159
165
$failedpersonlookup++;
162
167
if (empty($who["profession"])) {
163
168
echo " Warning! Missing members profession! (" . $who["nickname"] . ")\n";
164
169
$failedpersonlookup++;
167
171
if (empty($who["faction"])) {
168
172
echo " Warning! Missing members faction! (" . $who["nickname"] . ")\n";
169
173
$failedpersonlookup++;
172
175
if (empty($who["rank"])) {
173
176
echo " Warning! Missing members rank! (" . $who["nickname"] . ")\n";
174
177
$failedpersonlookup++;
177
179
if (empty($who["org"])) {
178
180
echo " Warning! Missing members organization name! (" . $who["nickname"] . ")\n";
179
181
$failedpersonlookup++;
182
183
if (empty($who["org_id"])) {
183
184
echo " Warning! Missing members organization ID! (" . $who["nickname"] . ")\n";
184
185
$failedpersonlookup++;
187
187
// INSERT new entries into DB, UPDATE existing ones:
188
188
$query = "INSERT INTO " . $tablename . " (nickname, firstname, lastname, level, gender, breed, faction,"
189
189
. " profession, defender_rank_id, org_id, org_name, org_rank, org_rank_id, pictureurl, updated)" . " VALUES ('"
202
202
. "faction = VALUES(faction), profession = VALUES(profession), org_id = VALUES(org_id), "
203
203
. "defender_rank_id = VALUES(defender_rank_id), pictureurl = VALUES(pictureurl), updated = "
204
204
. "VALUES(updated), org_name = VALUES(org_name), org_rank = VALUES(org_rank), org_rank_id = " . "VALUES(org_rank_id)";
205
mysqli_query($GLOBALS["___mysqli_ston"], $query) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
206
$GLOBALS["___mysqli_ston"],
208
) or die("Query failed : " . ((is_object(
209
$GLOBALS["___mysqli_ston"]
211
$GLOBALS["___mysqli_ston"]
212
) : (($___mysqli_res = mysqli_connect_error(
213
)) ? $___mysqli_res : false)));
206
214
$sqlquerycount++;
217
225
// Unset all org entries that are still not updated but pointing to the current org id
218
226
$query = "UPDATE whois SET org_id = 0, org_name = '', updated = updated - 86400 WHERE org_id = " . $orgid['org_id'] . " AND updated < " . $thistime . " - 10";
219
mysqli_query($GLOBALS["___mysqli_ston"], $query) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
227
mysqli_query($GLOBALS["___mysqli_ston"], $query) or die("Query failed : " . ((is_object(
228
$GLOBALS["___mysqli_ston"]
229
)) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error(
230
)) ? $___mysqli_res : false)));
221
232
echo " " . $i . " members completed in " . (time() - $starttime) . " seconds\n";
237
248
// Now work on all not updated entries left over (no org/switched org):
238
249
$comptime = $thistime - 10;
239
250
$sqlquery = "SELECT nickname FROM " . $tablename . " WHERE updated < " . $comptime;
240
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
241
while ($user = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
251
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object(
252
$GLOBALS["___mysqli_ston"]
253
)) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error(
254
)) ? $___mysqli_res : false)));
255
while ($user = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
242
256
if ($show_character_names) {
243
257
echo "Reading current stats for character " . $user['nickname'] . "...\n";
245
$content_arr = get_site($baseurl . "/character/bio/d/" . $dimension . "/name/" . strtolower($user['nickname']) . "/bio.xml");
259
$content_arr = get_site(
260
$baseurl . "/character/bio/d/" . $dimension . "/name/" . strtolower($user['nickname']) . "/bio.xml"
247
263
if ($content_arr) {
248
264
$content = $content_arr;
279
295
. $who["gender"] . "', breed='" . $who["breed"] . "', faction='" . $who["faction"] . "', profession='" . $who["profession"] . "', defender_rank_id='"
280
296
. $who["at"] . "', org_id='" . $who["org_id"] . "', org_name='" . $who["org"] . "', org_rank='" . $who["rank"] . "', org_rank_id='" . $who["rank_id"]
281
297
. "', updated='" . $thistime . "', pictureurl = '" . $who["pictureurl"] . "'" . " WHERE nickname='" . $who["nick"] . "';";
282
mysqli_query($GLOBALS["___mysqli_ston"], $query) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
298
mysqli_query($GLOBALS["___mysqli_ston"], $query) or die("Query failed : " . ((is_object(
299
$GLOBALS["___mysqli_ston"]
300
)) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error(
301
)) ? $___mysqli_res : false)));
283
302
$sqlquerycount++;
285
304
// delay next parsing by $delaytime in seconds:
292
311
$deletetime = $thistime - $hours * 3600;
293
312
// Clean org infos on seriously outdated entries (using same value as for deleting):
294
313
$query = "UPDATE whois SET org_id = 0, org_name = '' WHERE updated < " . $deletetime;
295
mysqli_query($GLOBALS["___mysqli_ston"], $query) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
314
mysqli_query($GLOBALS["___mysqli_ston"], $query) or die("Query failed : " . ((is_object(
315
$GLOBALS["___mysqli_ston"]
316
)) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error(
317
)) ? $___mysqli_res : false)));
296
318
// Only delete non-updated entries if explicitly wished:
297
319
if ($delete_not_updated) {
298
320
// all not-updated entries:
299
321
$sqlquery = "DELETE FROM " . $tablename . " WHERE updated < " . $deletetime;
300
mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
322
mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object(
323
$GLOBALS["___mysqli_ston"]
324
)) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error(
325
)) ? $___mysqli_res : false)));
302
327
// do some statistics:
303
328
$sqlquery = "SELECT count(*) as count FROM " . $tablename;
304
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)));
305
$count = mysqli_fetch_array($result, MYSQLI_ASSOC);
329
$result = mysqli_query($GLOBALS["___mysqli_ston"], $sqlquery) or die("Query failed : " . ((is_object(
330
$GLOBALS["___mysqli_ston"]
331
)) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error(
332
)) ? $___mysqli_res : false)));
333
$count = mysqli_fetch_array($result, MYSQLI_ASSOC);
306
334
((mysqli_free_result($result) || (is_object($result) && (get_class($result) == "mysqli_result"))) ? true : false);
307
335
$runtime = time() - $thistime;
308
336
$mins = floor($runtime / 60);
319
347
echo $mins . "min " . $sec . "sec total runtime!\n";
320
348
echo "================================================\n";
321
349
if (file_exists($addons) && is_readable($addons)) {
324
352
((is_null($___mysqli_res = mysqli_close($link))) ? false : $___mysqli_res);
327
function get_site($url, $strip_headers = FALSE, $read_timeout = FALSE)
355
function get_site($url, $strip_headers = false, $read_timeout = false)
329
357
echo " Fetching $url";
330
358
$starttime = time();
332
360
if (!function_exists('curl_init')) {
333
361
$return = get_site_sock($url, $strip_headers, $read_timeout);
336
363
$return = get_site_curl($url, $strip_headers, $read_timeout);
340
367
echo " .... completed in " . (time() - $starttime) . " seconds\n";
349
function get_site_sock($url, $strip_headers = FALSE, $read_timeout = FALSE)
375
function get_site_sock($url, $strip_headers = false, $read_timeout = false)
351
377
$return = get_site_data($url, $strip_headers, $read_timeout);
361
387
Gets the data from a URL
363
389
function get_site_data(
364
$url, $strip_headers = FALSE, $read_timeout = FALSE,
391
$strip_headers = false,
392
$read_timeout = false,
368
395
$get_url = parse_url($url);
369
396
// Check to see if we're using a proxy, and get the IP address for the target host.
370
397
if (!empty($proxy)) {
371
398
$proxy_address = explode(":", $proxy);
372
399
$address = gethostbyname($proxy_address[0]);
373
400
$service_port = $proxy_address[1];
376
402
$address = gethostbyname($get_url['host']);
377
403
/* Get the port for the WWW service. */
378
404
$service_port = getservbyname('www', 'tcp');
380
406
/* Create a TCP/IP socket. */
381
407
$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
382
408
// Check to see if the socket failed to create.
383
if ($socket === FALSE) {
409
if ($socket === false) {
384
410
echo "Failed to create socket. Error was: " . socket_strerror(socket_last_error());
388
414
// Set some sane read timeouts to prevent the bot from hanging forever.
393
419
socket_set_option(
394
$socket, SOL_SOCKET, SO_RCVTIMEO, array(
395
"sec" => $read_timeout,
424
"sec" => $read_timeout,
400
429
$connect_result = @socket_connect($socket, $address, $service_port);
402
431
// Make sure we have a connection
403
if ($connect_result === FALSE) {
404
echo "Failed to connect to server " . $address . ":" . $service_port . " (" . $url . ") Error was: " . socket_strerror(socket_last_error());
432
if ($connect_result === false) {
433
echo "Failed to connect to server " . $address . ":" . $service_port . " (" . $url . ") Error was: " . socket_strerror(
407
438
// Rebuild the full query after parse_url
408
439
$url = $get_url["path"];
415
446
$in .= "User-Agent: \r\n\r\n";
416
447
$write_result = @socket_write($socket, $in, strlen($in));
417
448
// Make sure we wrote to the server okay.
418
if ($write_result === FALSE) {
449
if ($write_result === false) {
419
450
echo "Failed to write to server: " . socket_strerror(socket_last_error());
422
453
$return["content"] = "";
423
454
$read_result = @socket_read($socket, 2048);
424
while ($read_result != "" && $read_result !== FALSE) {
455
while ($read_result != "" && $read_result !== false) {
425
456
$return .= $read_result;
426
457
$read_result = @socket_read($socket, 2048);
428
459
// Make sure we got a response back from the server.
429
if ($read_result === FALSE) {
460
if ($read_result === false) {
430
461
echo "Failed to read response: " . socket_strerror(socket_last_error());
433
464
$close_result = @socket_close($socket);
434
465
// Make sure we closed our socket properly. Open sockets are bad!
435
if ($close_result === FALSE) {
466
if ($close_result === false) {
436
467
echo "Failed to close socket: " . socket_strerror(socket_last_error());
439
470
// Did the calling function want http headers stripped?
440
471
if ($strip_headers) {
474
507
// CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if
475
508
// CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a
476
509
// common name and also verify that it matches the hostname provided)
477
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
510
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
478
511
// Optional: Return the result instead of printing it
479
512
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
480
513
// Specify a timeout