1874.patch

php scripts - Botanic, 03/01/2012 08:45 am

Download (23 kB)

b/code/ryzom/tools/server/www/login/accountfunc.php Wed Feb 29 23:41:42 2012 -0800
1
<?PHP
2

  
3

  
4
function validEmail($email)
5
{
6
   $isValid = true;
7
   $atIndex = strrpos($email, "@");
8
   if (is_bool($atIndex) && !$atIndex)
9
   {
10
      $isValid = false;
11
   }
12
   else
13
   {
14
      $domain = substr($email, $atIndex+1);
15
      $local = substr($email, 0, $atIndex);
16
      $localLen = strlen($local);
17
      $domainLen = strlen($domain);
18
      if ($localLen < 1 || $localLen > 64)
19
      {
20
         // local part length exceeded
21
         $isValid = false;
22
      }
23
      else if ($domainLen < 1 || $domainLen > 255)
24
      {
25
         // domain part length exceeded
26
         $isValid = false;
27
      }
28
      else if ($local[0] == '.' || $local[$localLen-1] == '.')
29
      {
30
         // local part starts or ends with '.'
31
         $isValid = false;
32
      }
33
      else if (preg_match('/\\.\\./', $local))
34
      {
35
         // local part has two consecutive dots
36
         $isValid = false;
37
      }
38
      else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
39
      {
40
         // character not valid in domain part
41
         $isValid = false;
42
      }
43
      else if (preg_match('/\\.\\./', $domain))
44
      {
45
         // domain part has two consecutive dots
46
         $isValid = false;
47
      }
48
      else if
49
(!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/',
50
                 str_replace("\\\\","",$local)))
51
      {
52
         // character not valid in local part unless 
53
         // local part is quoted
54
         if (!preg_match('/^"(\\\\"|[^"])+"$/',
55
             str_replace("\\\\","",$local)))
56
         {
57
            $isValid = false;
58
         }
59
      }
60
      if ($isValid && !(checkdnsrr($domain,"MX") || checkdnsrr($domain,"A")))
61
      {
62
         // domain not found in DNS
63
         $isValid = false;
64
      }
65
   }
66
   return $isValid;
67
}
68

  
69
function generateSALT ($length = 2)
70
  {
71

  
72
    // start with a blank salt
73
    $salt = "";
74

  
75
    // define possible characters - any character in this string can be
76
    // picked for use in the salt, so if you want to put vowels back in
77
    // or add special characters such as exclamation marks, this is where
78
    // you should do it
79
    $possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
80

  
81
    // we refer to the length of $possible a few times, so let's grab it now
82
    $maxlength = strlen($possible);
83
  
84
    // check for length overflow and truncate if necessary
85
    if ($length > $maxlength) {
86
      $length = $maxlength;
87
    }
88
	
89
    // set up a counter for how many characters are in the salt so far
90
    $i = 0; 
91
    
92
    // add random characters to $salt until $length is reached
93
    while ($i < $length) { 
94

  
95
      // pick a random character from the possible ones
96
      $char = substr($possible, mt_rand(0, $maxlength-1), 1);
97
        
98
      // have we already used this character in $salt?
99
      if (!strstr($salt, $char)) { 
100
        // no, so it's OK to add it onto the end of whatever we've already got...
101
        $salt .= $char;
102
        // ... and increase the counter by one
103
        $i++;
104
      }
105

  
106
    }
107

  
108
    // done!
109
    return $salt;
110

  
111
  }
112
function do_encrypt($pass,$user)
113
{
114
    $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
115
    
116
    $iv_size = mcrypt_enc_get_iv_size($cipher);
117
    //printf("iv_size = %d\n", $iv_size);
118
    
119
    //must take 16 byte key
120
	$key128 = 'fmaksdmf44Afwgnk';
121
    
122
    $iv = 'ag0ka93kAsfewA3';
123
    
124
    //printf("iv: %s\n", bin2hex($iv));
125
    //printf("key128: %s\n", bin2hex($key128));
126
    
127
    // This is the plain-text to be encrypted:
128
    $cleartext = $pass.$pass.$user.$user;
129
    //printf("plainText: %s\n\n", $cleartext);
130
    
131
    // Now let's do 128-bit encryption:
132
    if (mcrypt_generic_init($cipher, $key128, $iv) != -1) {
133
        // PHP pads with NULL bytes if $cleartext is not a multiple of the block size..
134
        $cipherText = mcrypt_generic($cipher, $cleartext);
135
        mcrypt_generic_deinit($cipher);
136
        
137
        // Display the result in hex.
138
        //printf("128-bit encrypted result:\n%s\n\n", bin2hex($cipherText));
139
    }
140
	return bin2hex($cipherText);
141
}
142

  
143
function checkUser () {
144
	if (isset($_POST["Username"])) {
145
		if (strlen($_POST["Username"])>12) {
146
			return  "Username must be no more than 12 characters.";
147
			} elseif (strlen($_POST["Username"])<5) {
148
			return "Username must be 5 or more characters.";
149
			} elseif (!preg_match('/^[a-z0-9\.]*$/', $_POST["Username"])) {
150
			return "Username can only contain numbers and letters.";
151
			} else {
152
			return "success";
153
		}
154
	} else {
155
		return "success";
156
	}
157
}
158

  
159
function checkPassword () {
160
	if (isset($_POST["Password"])) {
161
		if (strlen($_POST["Password"])>8) {
162
			return "Password must be no more than 8 characters.";
163
			} elseif (strlen($_POST["Password"])<5) {
164
			return "Password must be more than 5 characters.";
165
			} else {
166
			return "success";
167
		}
168
	}
169
}
170

  
171
function confirmPassword () {
172
	if (($_POST["Password"]) != ($_POST["ConfirmPass"])) {
173
			return "Passwords do not match.";
174
		} else {
175
			return "success";
176
		}
177
}
178

  
179

  
180
function checkEmail () {
181
	if (isset($_POST["Email"])) {
182
		if (!validEmail($_POST["Email"])) {
183
			return "Email address is not valid.";
184
		} else {
185
			return "success";
186
		}
187
	} else {
188
		return "success";
189
	}
190
}
191

  
192
	// see errorMsg
193
	function errorMsgBlock($errNum=GENERIC_ERROR_NUM) // $mixedArgs
194
	{
195
		$args = func_get_args();
196
		return '0:'.call_user_func_array('errorMsg', $args);
197
	}
198

  
199
function createUser () {
200
    $salt = generateSALT();
201
    $login = $_POST["Username"];
202
    $password = crypt($_POST["Password"], $salt);
203
    $email = $_POST["Email"];
204
	global $DBHost;
205
	global $DBHost;
206
	global $DBUserName;
207
	global $DBPassword;
208
	global $DBName;
209

  
210
	global $RingDBUserName;
211
	global $RingDBName;
212
	global $RingDBPassword;
213
	
214
    $link = mysql_connect($DBHost, $DBUserName, $DBPassword) or die (errorMsgBlock(3004, 'main', $DBHost, $DBUserName));
215
	mysql_select_db ($DBName) or die (errorMsgBlock(3005, 'main', $DBName, $DBHost, $DBUserName));
216
    
217
    // login doesn't exist, create it
218
    $query = "INSERT INTO user (Login, Password, Email) VALUES ('$login', '$password', '$email')";
219
    $result = mysql_query ($query) or die (errorMsgBlock(2005, 'main', $DBHost, $DBUserName));
220
    
221
    // get the user to have his UId
222
    $query = "SELECT * FROM user WHERE Login='$login'";
223
    $result = mysql_query ($query) or die (errorMsgBlock(2004, $query, 'main', $DBName, $DBHost, $DBUserName, mysql_error()));
224
    
225
    
226
    if (mysql_num_rows ($result) == 1)
227
    {
228
        $reason = errorMsg(3008, $login);
229
        $row = mysql_fetch_array ($result);
230
        $id = $row["UId"];
231
        $priv = $row["Privilege"];
232
        $extended = $row["ExtendedPrivilege"];
233
        
234
        // add the default permissions
235
        $query = "INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES ('$id', 'r2', 'OPEN')";
236
        $result = mysql_query ($query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysql_error()));
237
        $query = "INSERT INTO permission (UId, ClientApplication, AccessPrivilege) VALUES ('$id', 'ryzom_open', 'OPEN')";
238
        $result = mysql_query ($query) or die (errorMsgBlock(3006, $query, 'main', $DBName, $DBHost, $DBUserName, mysql_error()));
239
        
240
        $res = false;
241
        return true;
242
    }
243
} 
244

  
245
function webpageSuccess () {
246
	echo '
247
	<html>
248
		<head>
249
						  <link rel="shortcut icon" href="http://www.tempestintheaether.org/templates/rhuk_milkyway_ta/favicon.ico">
250
						  <link rel="stylesheet" href="style.css" type="text/css">
251

  
252
						  <title>Tempest in the Aether</title>
253
						  
254

  
255
						  
256
							
257
						</head>
258

  
259
		<body>
260
						  <table width="100%" cellspacing="0" cellpadding="0">
261
							<tbody>
262
							  <tr>
263
								<td align="center" valign="top">
264
								  <div id="main">
265

  
266
									<br>
267

  
268
									<div style="text-align:right">
269
									  <a href="http://www.tempestintheaether.org"><img border="0" src="http://www.tempestintheaether.org/templates/rhuk_milkyway_ta/images/ta_logo.png"></a><br>
270
									  </div>
271

  
272
									<div id="top"></div>
273

  
274
									<div id="middle">
275
									  <div class="title">
276
										<br />
277
										TEMPEST IN THE AETHER REGISTRATION<br />
278
									  </div>
279

  
280
									  <div>
281
									  <br>
282
										Congratulations!<br><br />
283
										Your account is now registered! <a href="http://www.tempestintheaether.org/index.php/download">Click HERE to download the client.</a><br>
284
									  </div>
285
									  <br>
286
									  <div style="clear:both;"></div>
287
									</div>
288
									<div id="bottom"></div>
289
								  </div>
290
								</td>
291
							  </tr>
292
							</tbody>
293
						  </table>
294

  
295
						
296
						
297
				</body>
298
	</html>';
299
	exit;
300
}
b/code/ryzom/tools/server/www/login/config.php Wed Feb 29 23:41:42 2012 -0800
20 20

  
21 21
// If true, the server will add automatically unknown user in the database
22 22
// (in nel.user, nel.permission, ring.ring_user and ring.characters
23
$AcceptUnknownUser = true;
23
$AcceptUnknownUser = false;
24 24
// if true, the login service automaticaly create a ring user and a editor character if needed
25
$AutoCreateRingInfo = true;
25
$AutoCreateRingInfo = false;
26 26

  
27 27
?>
b/code/ryzom/tools/server/www/login/register.php Wed Feb 29 23:41:42 2012 -0800
1
<?PHP
2

  
3
	error_reporting(E_ERROR | E_PARSE);
4
	set_error_handler('err_callback');
5

  
6
	// For error handling, buffer all output
7
	ob_start('ob_callback_r2login');
8

  
9
	include_once('accountfunc.php');
10
	include_once('config.php');
11
	include_once('login_translations.php');
12
	include_once('../tools/nel_message.php');
13
	include_once('../tools/domain_info.php');
14
	include_once('login_service_itf.php');
15
	include_once('../ring/join_shard.php');
16
		//check values
17
		$user = checkUser();
18
		$pass = checkPassword();
19
		$cpass = confirmPassword();
20
		$email = checkEmail();
21
		
22
		//if all are good then create user
23
		if (($user == "success") and ($pass == "success") and ($cpass == "success") and ($email == "success") and (isset($_POST["TaC"]))) {
24
			if (createUser()) {
25
				//if created user suceeds then check if webpage or client
26
				if (!isset($_SERVER[HTTP_USER_AGENT])) {
27
					//header location is required to get contragulations screen
28
					header('Location: email_sent.php');
29
					exit;
30
				} else {
31
					//show congragulations page
32
					webpageSuccess();
33
					exit;
34
				}
35
			}	
36
		} else {
37
			//check if the client is the request
38
			if (!isset($_SERVER[HTTP_USER_AGENT])) {
39
				echo '
40
				<div class="title">TEMPEST IN THE AETHER REGISTRATION</div>
41
				
42
				<div>Welcome! Please fill in the following fields to get your new Tempest in the Aether account:</div>
43
				
44
				<form name=\'Page1\' method=\'post\' action=\'register.php\'>
45
				
46
				<table>
47
					<tr>
48
						<td width="33%" ';
49
												if ($user != "success") {
50
													echo 'class="error" ';
51
												}
52
												echo 'id="caption-Username" >Desired Username: </td>
53
						<td width="25%" >
54
							<input type=\'text\' name=\'Username\' value="" maxlength="12" onfocus="javascript:showTooltip(\'5-12 lower-case characters and numbers. The login (username) you create here will be your login name. The name of your game characters will be chosen later on.\', this);" /></td>
55
						';
56
												if ($user != "success") {
57
													echo '<td id="comment-Username" class="error" width="42%">'.$user.'</td>';
58
												} else {
59
													'<td width="42%" id="comment-Username" >';
60
												}
61
												echo '</td>
62
					</tr>
63
					
64
					<tr>
65
						<td width="33%" ';
66
												if ($pass != "success") {
67
													echo 'class="error" ';
68
												}
69
												echo 'id="caption-Password" >Desired Password: </td>
70
						<td width="25%" ><input type=\'password\' name=\'Password\' value="" maxlength="8" onkeyup="testPassword(document.Page1.Password.value, \'comment-Password\')" onfocus="javascript:showTooltip(\' 5-8 alpha-numerical characters.\', this);" /></td>
71
						';
72
												if ($pass != "success") {
73
													echo '<td id="comment-Password" class="error" width="42%">'.$pass.'</td>';
74
												} else {
75
													'<td width="42%" id="comment-Password" >';
76
												}
77
												echo '
78
					</tr>
79
					
80
					<tr>
81
						<td width="33%" ';
82
												if ($cpass != "success") {
83
													echo 'class="error" ';
84
												}
85
												echo 'id="caption-ConfirmPass" >Confirm Password: </td>
86
						<td width="25%" >
87
						<input type=\'password\' name=\'ConfirmPass\' value="" maxlength="8" onfocus="javascript:showTooltip(\'Retype your Password\', this);" />
88
						</td>
89
						';
90
												if ($cpass != "success") {
91
													echo '<td id="comment-ConfirmPass" class="error" width="42%">'.$cpass.'</td>';
92
												} else {
93
													'<td width="42%" id="comment-ConfirmPass" >';
94
												}
95
												echo '
96
						</td>
97
					</tr>
98
					
99
					<tr>
100
						<td width="33%" ';
101
												if ($email != "success") {
102
													echo 'class="error" ';
103
												}
104
												echo 'id="caption-Email" >Email Address (to which a confirmation email will be sent): 
105
						</td><td width="25%" ><input type=\'text\' name=\'Email\' value="" maxlength="255" onfocus="javascript:showTooltip(\'Please verify that the e-mail address you enter here is valid and will remain valid in the future. It will only be used to manage your Tempest in the Aether account.\', this);" /></td>';
106
												if ($email != "success") {
107
													echo '<td id="comment-Email" class="error" width="42%">'.$email.'</td>';
108
												} else {
109
													'<td width="42%" id="comment-Email" >';
110
												}
111
												echo '</td>
112
					</tr>
113
						
114
					<tr><td width="33%" ';
115
												if (!isset($_POST["TaC"])) {
116
													echo 'class="error" ';
117
												}
118
												echo 'colspan=2 ><input type=\'checkbox\' name=\'TaC\' value="1"  onfocus="javascript:showTooltip(\'\', this);" /><span id="caption-TaC">YES, I agree to the terms of use</span></td>';
119
												if (!isset($_POST["TaC"])) {
120
													echo '<td id="comment-TaC" class="error" width="42%">You must accept the Terms of Service</td>';
121
												} else {
122
													'<td width="42%" id="comment-TaC" >';
123
												}
124
												echo '</td>
125
					</tr>
126
				
127
				</table>
128
				
129
					<div style=\'text-align:left; padding-top:0.5em; padding-bottom:0.5em;\'>
130
						<input type=\'submit\' name=\'Submit\' value=\'Continue\' />	
131
					</div>
132
				
133
				</form>
134
				
135
				<div id=signupTooltip style=\'border: 1px inset white;\'></div>
136
				<div id=tooltip-Username>5-12 lower-case characters and numbers. The login (username) you create here will be your login name. The name of your game characters will be chosen later on.</div>
137
				<div id=tooltip-Password>5-8 alpha-numerical characters.</div>
138
				<div id=tooltip-ConfirmPass>Retype your Password</div>
139
				<div id=tooltip-Email>Please verify that the e-mail address you enter here is valid and will remain valid in the future. It will only be used to manage your Tempest in the Aether account.</div>
140
				<div id=tooltip-TaC></div>';
141
			} else {
142
				//must be webpage so display webpage
143
				echo '
144
					<html xmlns="http://www.w3.org/1999/xhtml">
145
						<head>
146
						  <meta name="generator" content=
147
						  "HTML Tidy for Linux/x86 (vers 11 February 2007), see www.w3.org" />
148
						  <link href="http://www.tempestintheaether.org/templates/rhuk_milkyway_ta/favicon.ico"
149
						  rel="shortcut icon" />
150
						  <link type="text/css" href="style.css" rel=
151
						  "stylesheet" />
152

  
153
						  <title>Tempest in the Aether</title>
154
						  <style type="text/css">
155
						/*<![CDATA[*/
156
								.error { color: red; }
157
						  .title { padding: 0.5em; text-align: center; font-weight: bold; font-size: small; }
158
						  /*]]>*/
159
						  </style>
160

  
161
						  <script language="JavaScript">
162
							function showTooltip(text, ctrl) {
163
								document.getElementById("signupTooltip").innerHTML = text;
164
							}
165
							function setLogin(name)	{
166
								document.Page1.Username.value = name;
167
							}
168
							function focusCtrl(ctrlName) {
169
								document.getElementsByName(ctrlName)[0].focus();
170
							}
171
							var VerdictStr = "<font color=#000000>Strength: </font>";
172
							</script>
173
							
174
						</head>
175

  
176
						<body>
177
						  <table width="100%" cellspacing="0" cellpadding="0">
178
							<tbody>
179
							  <tr>
180
								<td align="center" valign="top">
181
								  <div id="main">
182

  
183
									<br />
184

  
185
									<div style="text-align:right">
186
									  <a href="http://www.tempestintheaether.org"><img border="0" src=
187
									  "http://www.tempestintheaether.org/templates/rhuk_milkyway_ta/images/ta_logo.png" /></a><br />
188
									  </div>
189

  
190
									<div id="top"></div>
191

  
192
									<div id="middle">
193
									  <div class="title">
194

  
195
										TEMPEST IN THE AETHER REGISTRATION
196
									  </div>
197

  
198
									  <div>
199
										Welcome!<br />
200
										Please fill in the following fields to get your new Tempest in the Aether
201
										account:<br />
202
									  </div>
203

  
204
									  <form action="register.php" method="post" name="Page1" id="Page1">
205

  
206
										<table>
207
										  <tbody>
208
											<tr>
209
											  <td width="33%" id="caption-Username">Desired Username:</td>
210

  
211
											  <td width="25%"><input type="text" onfocus=
212
											  "javascript:showTooltip(\'&lt;b&gt;Desired Username: &lt;/b&gt;&lt;br&gt;5-12 lower-case characters and numbers.&lt;br&gt; The login (username) you create here will be only used to login to the client. The name of your game characters will be chosen later on. \', this);"
213
											  maxlength="12" value="'.$_POST["Username"].'" name="Username" /></td>
214
											  ';
215
												if ($user != "success") {
216
													echo '<td width="42%" class="error" id="comment-Username">'.$user.'<br></td>';
217
												}
218
												echo '
219

  
220
											  <td width="42%" id="comment-Username"></td>
221
											</tr>
222

  
223
											<tr>
224
											  <td width="33%" id="caption-Password">Desired Password:</td>
225

  
226
											  <td width="25%"><input type="password" onfocus=
227
											  "javascript:showTooltip(\'&lt;b&gt;Desired Password: &lt;/b&gt;&lt;br&gt; 5-8 alpha-numerical characters.\', this);"
228
											  onkeyup=
229
											  "testPassword(document.Page1.Password.value, \'comment-Password\')"
230
											  maxlength="8" value="" name="Password" /></td>';
231
												if ($pass != "success") {
232
													echo '<td width="42%" class="error" id="comment-Password">'.$pass.'<br></td>';
233
												}
234
												echo '
235

  
236
											  <td width="42%" id="comment-Password"></td>
237
											  
238
											</tr>
239

  
240
											<tr>
241

  
242
											  <td width="33%" id="caption-ConfirmPass">Confirm Password:</td>
243

  
244
											  <td width="25%"><input type="password" onfocus=
245
											  "javascript:showTooltip(\'&lt;b&gt;Confirm Password: &lt;/b&gt;&lt;br&gt; Please type your password again.\', this);"
246
											  maxlength="8" value="" name="ConfirmPass" /></td>
247

  
248
											  <td width="42%" id="comment-ConfirmPass"></td>
249
											</tr>
250

  
251
											<tr>
252
											  <td width="33%" id="caption-Email">Email Address (to which a
253
											  confirmation email will be sent):</td>
254

  
255
											  <td width="25%"><input type="text" onfocus=
256
											  "javascript:showTooltip(\'&lt;b&gt;Email Address (to which a confirmation email will be sent): &lt;/b&gt;&lt;br&gt;Please verify that the e-mail address you enter here is valid and will remain valid in the future (caution with full mailboxes and with webmails that disable your address if you dont connect often enough). It will only be used to manage your Ryzom subscription.&lt;br&gt;&lt;a href=\'javascript:popUpExt(&quot;terms_of_use.php?privacy=1&quot;)\'&gt;More information about your privacy&lt;/a&gt;\', this);"
257
											  maxlength="255" value="'.$_POST["Email"].'" name="Email" /></td>
258
											  ';
259
												if ($email != "success") {
260
													echo '<td width="42%" class="error" id="comment-Email">'.$email.'<br></td>';
261
												}
262
												echo '
263

  
264
											  <td width="42%" id="comment-Email"></td>
265
											</tr>
266
											<tr>
267
											
268
												<td width="33%" colspan=2 >
269
													<input type="checkbox" name="TaC" value="1"  onfocus="javascript:showTooltip(\'\', this);" ';
270
												if ((isset($_POST["TaC"])) and (isset($_POST["Submit"]))) {
271
													echo 'checked="checked"';
272
												}
273
												echo '
274
													
275
													/>
276
													<span id="caption-TaC">YES, I agree to the terms of use';
277
												if ((!isset($_POST["TaC"])) and (isset($_POST["Submit"]))) {
278
													echo '<br /><td class="error">													
279
													You must agree to the Terms of Use</td>';
280
												}
281
												echo '
282
													</span>
283
													
284
													</td><td width="25%" id="comment-TaC" >
285
												</td>
286
												
287
											
288
										</tr>
289

  
290
										  </tbody>
291
										</table>
292

  
293
										<div style="text-align:left; padding-top:0.5em; padding-bottom:0.5em;">
294
										  <input type="submit" value="Continue" name="Submit" />
295

  
296
										</div>
297
									  </form>
298

  
299
									  <div style="border: 1px inset white;" id="signupTooltip">
300
										<b>Desired Username:</b><br />
301
										5-12 lower-case characters and numbers.<br />
302
										The login (username) you create here will be your public name in the
303
										official forum and chat ("Klients"). The name of your game characters
304
										will be chosen later on.
305
									  </div>
306
									  
307
									  <br />
308

  
309
									  <div style="clear:both;"></div>
310
									</div>
311

  
312
									<div id="bottom"></div>
313
								  </div>
314
								</td>
315
							  </tr>
316
							</tbody>
317
						  </table>
318

  
319
						</body>
320
						</html>
321
				';			
322

  
323
			}
324
		}
325
	
326
	
327
?>