-
Notifications
You must be signed in to change notification settings - Fork 15
/
import_authkeys.php
89 lines (60 loc) · 2.28 KB
/
import_authkeys.php
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
<?
set_time_limit(50000);
error_reporting(E_ALL); // was 0 (off)
function is_number($Str) {
$Return = true;
if ($Str < 0) {
$Return = false;
}
// We're converting input to a int, then string and comparing to original
$Return = ($Str == strval(intval($Str)) ? true : false);
return $Return;
}
function make_secret2($Length = 32) {
$Secret = '';
$Chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
for ($i = 0; $i < $Length; $i++) {
$Rand = mt_rand(0, strlen($Chars) - 1);
$Secret .= substr($Chars, $Rand, 1);
}
return str_shuffle($Secret);
}
require('/var/www/emp3/classes/config.php');
$time_start = microtime(true);
echo "connecting to database<br/>";
$link = mysqli_connect(SQLHOST, SQLLOGIN, SQLPASS, SQLDB, SQLPORT, SQLSOCK); // defined in config.php
if (!$link) {
echo "error connection to db ".mysqli_connect_errno().' '. mysqli_connect_error().'<br/>';
}
echo "Update users: generate new authkeys, CatchupTime=UTC_TIMESTAMP()<br/>";
$sqltime = date('Y-m-d H:i:s', time());
if (!mysqli_query($link, "UPDATE gazelle.users_info
SET AuthKey =
MD5(
CONCAT(
AuthKey, RAND(), '".mysqli_real_escape_string($link, make_secret2())."',
SHA1(
CONCAT(
RAND(), RAND(), '".mysqli_real_escape_string($link, make_secret2())."'
)
)
)
), CatchupTime='$sqltime';")) {
die(mysqli_error($link));
}
echo "creating new invite_tree table for users<br/>";
$result = mysqli_query($link, 'select ID from gazelle.users_main');
if (!$result) die(mysqli_error($link));
$TreeIndex = 2;
$values = array();
$comma = "";
while (($row = mysqli_fetch_assoc($result))) {
$values[] = "(".$row["ID"].", 0, $TreeIndex, 0, 2)";
$TreeIndex++;
}
if (!mysqli_query($link, "TRUNCATE TABLE gazelle.invite_tree;")) die(mysqil_error($link));
if (!mysqli_query($link, "insert into gazelle.invite_tree values ".implode(',',$values)))
die(mysqil_error($link));
$time = microtime(true) - $time_start;
echo "<br/>execution time: $time seconds<br/>";
?>