-
Notifications
You must be signed in to change notification settings - Fork 1
/
import.php
265 lines (238 loc) · 8.27 KB
/
import.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
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/*-----------------------------------------------------------------------------
| Bitsand - an online booking system for Live Role Play events
|
| File import.php
| Author: Russell Phillips
| Copyright: (C) 2006 - 2015 The Bitsand Project
| (http://github.com/PeteAUK/bitsand)
|
| Bitsand is free software; you can redistribute it and/or modify it under the
| terms of the GNU General Public License as published by the Free Software
| Foundation, either version 3 of the License, or (at your option) any later
| version.
|
| Bitsand is distributed in the hope that it will be useful, but WITHOUT ANY
| WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
| FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
| details.
|
| You should have received a copy of the GNU General Public License along with
| Bitsand. If not, see <http://www.gnu.org/licenses/>.
+---------------------------------------------------------------------------*/
//Do not check that user is logged in
$bLoginCheck = False;
include ('inc/inc_head_db.php');
$key = CRYPT_KEY;
$db_prefix = DB_PREFIX;
//Check e-mail address is not already registered
$sql = "SELECT plEmail FROM {$db_prefix}players WHERE plEmail " .
"LIKE '" . ba_db_real_escape_string ($link, $_POST ['email']) . "'";
$result = ba_db_query ($link, $sql);
if (ba_db_num_rows ($result) > 0) {
$msg = "<html><body>\n";
$msg .= "<span style = 'color: red; font-weight: bold;'>\n";
$msg .= "The e-mail address " . htmlentities ($_POST ['email']);
$msg .= " is already registered.</span><br>\n";
$msg .= "You can <a href = 'retrieve.php?text=";
$msg .= urlencode ($_POST ['email']);
$msg .= "'>reset your password</a>.";
$msg .= "</body></html>\n";
die ($msg);
}
$sURL = $_POST['selSystem'];
//Create POST headers
if (isset($_POST ['ic']))
$ic = 1;
else
$ic = 0;
$data = array('email' => $_POST['email'], 'password' => $_POST['password'], 'ic' => $ic);
$data = http_build_query($data);
// Get players details - use Curl as a preference
if (function_exists('curl_init')) {
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
// Use the following for debugging
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_STDERR, fopen('php://stderr', 'w'));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$url = trim($sURL) . '?' . $data;
curl_setopt($curl, CURLOPT_URL, $url);
$response = curl_exec($curl);
if ($response === false) {
$response = 'ERROR: ' . sprintf('curl error (#%d): %s<br/>\n', curl_errno($curl), htmlspecialchars(curl_error($curl)));
}
} else {
$opts = array(
'http' => array(
'method' => 'POST',
'header'=> 'Content-type: application/x-www-form-urlencoded',
'content' => $data
)
);
$context = stream_context_create($opts);
$fp = @fopen(trim($sURL), 'rb', false, $context);
if ($fp) {
$response = @stream_get_contents($fp);
}
}
if (!$response || substr($response, 0, 6) == "ERROR:") {
$msg = "<html><body>The remote system returned the following error:<br>\n";
$msg .= "<span style= 'color: red; font-weight: bold;'>";
if ($response) {
$msg .= substr($response, 7);
} else {
$msg .= 'Unable to connect to remote server';
}
$msg .= "</span>\n";
$msg .= "</body></html>\n";
die($msg);
} else {
$response = array_filter(explode("\n", $response));
}
// OOC details
$sPlayerCSV = explode (",", trim ($response[0]));
$sFirstName = ba_db_real_escape_string ($link, $sPlayerCSV [0]);
$sSurname = ba_db_real_escape_string ($link, $sPlayerCSV [1]);
$sEmail = ba_db_real_escape_string ($link, $sPlayerCSV [9]);
$sDOB = ba_db_real_escape_string ($link, $sPlayerCSV [10]);
$sEmergencyName = ba_db_real_escape_string ($link, $sPlayerCSV [12]);
$sEmergencyRelationship = ba_db_real_escape_string ($link, $sPlayerCSV [14]);
$sCarRegistration = ba_db_real_escape_string ($link, $sPlayerCSV [15]);
$sDietary = ba_db_real_escape_string ($link, $sPlayerCSV [16]);
$sAddress1 = ba_db_real_escape_string ($link, $sPlayerCSV [2]);
$sAddress2 = ba_db_real_escape_string ($link, $sPlayerCSV [3]);
$sAddress3 = ba_db_real_escape_string ($link, $sPlayerCSV [4]);
$sAddress4 = ba_db_real_escape_string ($link, $sPlayerCSV [5]);
$sPostcode = ba_db_real_escape_string ($link, $sPlayerCSV [6]);
$sTelephone = ba_db_real_escape_string ($link, $sPlayerCSV [7]);
$sMobile = ba_db_real_escape_string ($link, $sPlayerCSV [8]);
$sMedicalInfo = ba_db_real_escape_string ($link, $sPlayerCSV [11]);
$sEmergencyNumber = ba_db_real_escape_string ($link, $sPlayerCSV [13]);
//Get salted hash of password
$sHashPass = sha1 ($_POST ['password'] . PW_SALT);
//Build up OOC SQL
$sql = "INSERT INTO {$db_prefix}players (" .
"plPassword, " .
"plFirstName, " .
"plSurname, " .
"pleAddress1, " .
"pleAddress2, " .
"pleAddress3, " .
"pleAddress4, " .
"plePostcode, " .
"pleTelephone, " .
"pleMobile, " .
"plEmail, " .
"plDOB, " .
"pleMedicalInfo, " .
"plEmergencyName, " .
"pleEmergencyNumber, " .
"plEmergencyRelationship, " .
"plCarRegistration, " .
"plDietary," .
"plAccess) " .
"VALUES (" .
"'$sHashPass', " .
"'$sFirstName', " .
"'$sSurname', " .
"AES_ENCRYPT('$sAddress1', '$key'), " .
"AES_ENCRYPT('$sAddress2', '$key'), " .
"AES_ENCRYPT('$sAddress3', '$key'), " .
"AES_ENCRYPT('$sAddress4', '$key'), " .
"AES_ENCRYPT('$sPostcode', '$key'), " .
"AES_ENCRYPT('$sTelephone', '$key'), " .
"AES_ENCRYPT('$sMobile', '$key'), " .
"'$sEmail', " .
"'$sDOB', " .
"AES_ENCRYPT('$sMedicalInfo', '$key'), " .
"'$sEmergencyName', " .
"AES_ENCRYPT('$sEmergencyNumber', '$key'), " .
"'$sEmergencyRelationship', " .
"'$sCarRegistration', " .
($sDietary ? "'$sDietary'" : 'NULL') . "," .
"'')";
// Insert OOC info
ba_db_query ($link, $sql);
// Get new player ID
$sql = "SELECT plPlayerID FROM {$db_prefix}players " .
"WHERE plEmail = '$sEmail' AND " .
"plPassword = '$sHashPass'";
$result = ba_db_query ($link, $sql);
$row = ba_db_fetch_assoc ($result);
$iPlayerID = (int) $row ['plPlayerID'];
// Check if IC details were exported
if ($ic == 1) {
// Character details
$sCharacterCSV = explode (",", trim ($response[1]));
$sName = ba_db_real_escape_string ($link, $sCharacterCSV [0]);
$sPreferredname = ba_db_real_escape_string ($link, $sCharacterCSV [1]);
$sRace = ba_db_real_escape_string ($link, $sCharacterCSV [2]);
$sGender = ba_db_real_escape_string ($link, $sCharacterCSV [3]);
$sFaction = ba_db_real_escape_string ($link, $sCharacterCSV [4]);
$sNpc = ba_db_real_escape_string ($link, $sCharacterCSV [5]);
$sNotes = ba_db_real_escape_string ($link, $sCharacterCSV [6]);
$sSpecial = ba_db_real_escape_string ($link, $sCharacterCSV [7]);
//Build up character SQL
$sql = "INSERT INTO {$db_prefix}characters (" .
"chPlayerID, " .
"chName, " .
"chPreferredName, " .
"chRace, " .
"chGender, " .
"chFaction, " .
"chNPC, " .
"chNotes, " .
"chOSP, " .
"chGroupSel, " .
"chGroupText, " .
"chAncestor, " .
"chLocation) " .
"VALUES (" .
"$iPlayerID, " .
"'$sName', " .
"'$sPreferredname', " .
"'$sRace', " .
($sGender ? "'$sGender'" : 'Male') . ", " .
"'$sFaction', " .
($sNpc ? "'$sNpc'" : '0') . ", " .
"'$sNotes', " .
"'$sSpecial', " .
"'', " .
"'', " .
"'', " .
"'')";
// Insert character details
ba_db_query ($link, $sql);
// Guilds
$sGuildCSV = explode (",", trim ($response[2]));
foreach ($sGuildCSV as $guild) {
$sql = "INSERT INTO {$db_prefix}guildmembers (gmPlayerID, gmName) " .
"VALUES ($iPlayerID, '$guild')";
ba_db_query ($link, $sql);
}
// Skills
$sSkillsCSV = explode (",", trim ($response[3]));
foreach ($sSkillsCSV as $skill) {
$sql = "INSERT INTO {$db_prefix}skillstaken (stPlayerID, stSkillID) " .
"VALUES ($iPlayerID, $skill)";
ba_db_query ($link, $sql);
}
// OSPs
$sOspCSV = explode (",", trim ($response[4]));
foreach ($sOspCSV as $osp) {
$sql = "INSERT INTO {$db_prefix}ospstaken (otPlayerID, otOspID) " .
"VALUES ($iPlayerID, $osp)";
ba_db_query ($link, $sql);
}
}
//Close link to database
ba_db_close ($link);
//Redirect to index page
$sURL = fnSystemURL () . "index.php";
$sURL .= "?green=" . urlencode ("Details imported. Please log in and check your details to ensure that they are correct");
header ("Location: $sURL");