|
1 <?php |
|
2 |
|
3 require_once('recaptchalib.php'); |
|
4 require_once('config.php'); |
|
5 |
|
6 if(!array_key_exists('backend', $config)) |
|
7 die("Please specify a backend in config.php!"); |
|
8 |
|
9 if($config['debug']) |
|
10 include('backend_'.$config['backend'].'.php'); |
|
11 else |
|
12 @include('backend_'.$config['backend'].'.php'); |
|
13 |
|
14 if(class_exists("RegistrationBackend")) |
|
15 { |
|
16 $registration_backend = new RegistrationBackend(); |
|
17 } |
|
18 else |
|
19 { |
|
20 echo('Failed to initialize backend "'.$config['backend'].'": '); |
|
21 |
|
22 if(!$config['debug']) |
|
23 echo('enable debug in the config for more info.'); |
|
24 else |
|
25 include('backend_'.$config['backend'].'.php'); |
|
26 die(); |
|
27 } |
|
28 |
|
29 header( 'Content-type: text/html; charset=utf-8' ); |
|
30 |
|
31 ?> |
|
32 <html> |
|
33 <head> |
|
34 <link rel='stylesheet' href='themes/<?php echo $config['theme']; ?>/style.css' /> |
|
35 </head> |
|
36 <body> |
|
37 |
|
38 <?php @include('themes/'.$config['theme'].'/header.php'); ?> |
|
39 |
|
40 <div id="box"> |
|
41 |
|
42 <?php |
|
43 if (!$_POST["submit"]) |
|
44 { |
|
45 ?> |
|
46 |
|
47 <h2>Register a <?php echo ucfirst($config['host']); ?> account</h2> |
|
48 <p>Use the form below to create an account.</p> |
|
49 <form method="post"> |
|
50 <table> |
|
51 <tr><td class="label">Username:</td><td><input type="text" class="edit username" name="username" size="10" />@<?php echo $config['host']; ?></td></tr> |
|
52 <tr><td class="label">Password:</td><td><input type="password" class="edit" name="password" size="15"/></td></tr> |
|
53 <tr><td class="label">Re-type password:</td><td><input type="password" class="edit" name="password2" size="15"/></td></tr> |
|
54 <tr><td colspan="2" style="text-align:center; margin-left:auto; margin-right:auto;" align="center"> |
|
55 <center> |
|
56 <div id="captcha"> |
|
57 <?php echo recaptcha_get_html($config['recaptchaPublicKey'], null, !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off'); ?> |
|
58 </div> |
|
59 </center> |
|
60 </td></tr> |
|
61 <tr><td colspan="2" style="text-align:center;"> |
|
62 <input type="submit" name="submit" value="Register" /> |
|
63 </td></tr> |
|
64 </form> |
|
65 |
|
66 <?php |
|
67 } |
|
68 else |
|
69 { |
|
70 // Process submission |
|
71 $resp = recaptcha_check_answer ($config['recaptchaPrivateKey'], |
|
72 $_SERVER["REMOTE_ADDR"], |
|
73 $_POST["recaptcha_challenge_field"], |
|
74 $_POST["recaptcha_response_field"]); |
|
75 if ($resp->is_valid) |
|
76 { |
|
77 $registration_backend->init($config); |
|
78 $user = $_POST['username']; |
|
79 $pass = $_POST['password']; |
|
80 $pass2 = $_POST['password2']; |
|
81 |
|
82 $ok = true; |
|
83 |
|
84 if (!$user) |
|
85 { |
|
86 echo '<p>Sorry, you didn\'t tell us which username you want! Please <a href="./">go back</a> and try again.</p>'; |
|
87 $ok = false; |
|
88 } |
|
89 |
|
90 if($pass !== $pass2) |
|
91 { |
|
92 echo '<p>The two passwords you typed are not the same, please <a href="./">go back</a> and try more carefully! :-)</p>'; |
|
93 $ok = false; |
|
94 } |
|
95 |
|
96 if($ok) |
|
97 { |
|
98 if(!mb_check_encoding($user, 'UTF-8') || !mb_check_encoding($pass, 'UTF-8')) |
|
99 { |
|
100 echo '<p>Sorry, your browser sent an invalid form entry. Try removing special characters from your username/password.</p>'; |
|
101 echo '<p>Alternatively please try a different browser and re-submit <a href="./">the form</a>.</p>'; |
|
102 $ok = false; |
|
103 } |
|
104 else |
|
105 { |
|
106 $user = mb_strtolower($user, 'UTF-8'); |
|
107 } |
|
108 } |
|
109 |
|
110 // Check that username is valid for a JID |
|
111 if ($ok && strlen($user) > 255) |
|
112 { |
|
113 echo '<p>Sorry, the username you entered is waaaaay too long. <a href="./">Please try</a> something shorter!</p>'; |
|
114 $ok = false; |
|
115 } |
|
116 |
|
117 if ($ok) |
|
118 { |
|
119 if (strcspn($user, "\"&'/:<>@".chr(127)) !== strlen($user)) |
|
120 { |
|
121 echo '<p>Sorry, that username contains invalid characters (such as &, <, >, / etc.). Please remove them and <a href="./">try again</a>.</p>'; |
|
122 echo strcspn($user, "\"&'/:<>@".chr(127))." vs ".strlen($user); |
|
123 $ok = false; |
|
124 } |
|
125 else if (strpos($user, chr(255).chr(254)) || strpos($user, chr(255.255))) |
|
126 { |
|
127 echo '<p>Sorry, that username contains invalid characters. Please remove them and <a href="./">try again</a>.</p>'; |
|
128 $ok = false; |
|
129 } |
|
130 else |
|
131 { |
|
132 $charfreq = array_keys(count_chars($user, 1)); |
|
133 if (min($charfreq) <= 32) |
|
134 { |
|
135 echo '<p>Sorry, that username contains invalid characters. For example you cannot use spaces in a username. Please <a href="./">go back</a>, remove them, and try again.</p>'; |
|
136 $ok = false; |
|
137 } |
|
138 } |
|
139 |
|
140 } |
|
141 |
|
142 if ($ok && (strlen($pass) < 6)) |
|
143 { |
|
144 echo '<p>Your password isn\'t long enough. It needs to be at least 6 characters long, to make sure that it can\'t be easily guessed. <a href="./">Go back</a> and try again.</p>'; |
|
145 $ok = false; |
|
146 } |
|
147 |
|
148 if ($ok) |
|
149 { |
|
150 $backend_message = $registration_backend->validate($user, $pass); |
|
151 if($backend_message) |
|
152 { |
|
153 echo "<p>".htmlentities($backend_message)." Please <a href='./'>go back</a> and try again.</p>"; |
|
154 $ok = false; |
|
155 } |
|
156 } |
|
157 |
|
158 // Check that username does not already exist |
|
159 if ($ok) |
|
160 { |
|
161 if($registration_backend->exists($user)) |
|
162 { |
|
163 echo '<p>A user with that name already exists, please <a href="./">go back</a> and choose a different username.</p>'; |
|
164 $ok = false; |
|
165 } |
|
166 } |
|
167 |
|
168 if ($ok) |
|
169 { |
|
170 $result = $registration_backend->create($user, $pass); |
|
171 if ($result) |
|
172 { |
|
173 echo '<p>You successfully registered the Jabber ID<br/><b>'.$_POST["username"].'@'.$config['host'].'</b></p>'; |
|
174 echo "<div style='text-align:left;'>"; |
|
175 echo "<p>If you haven't already, now is a good time to "; |
|
176 echo "<a href='http://www.jabber.org/index.php/download-a-client/'>download a client</a> which you can "; |
|
177 echo 'use to log into your new account.</p>'; |
|
178 echo '<p>Wondering what you can do with your new <a href="'.$config['website'].'">'.$config['host'].'</a> account? '; |
|
179 echo 'Here are some services at which you can use your Jabber ID:</p>'; |
|
180 echo '<ul>'; |
|
181 echo '<li><a href="http://identi.ca/">identi.ca</a> - Open microblogging service</li>'; |
|
182 echo '<li><a href="http://speeqe.com/">Speeqe</a> - Web-based Jabber chatrooms</li>'; |
|
183 echo '</ul>'; |
|
184 echo '<p><b>Did you know?</b> <a href="http://www.google.com/talk/">Google Talk</a> is one of the many other '; |
|
185 echo '<a href="http://xmpp.org/services/">Jabber-compatible services</a>, which '; |
|
186 echo 'means you can add your Gmail and Google Apps friends directly to your '.ucfirst($config['host']).' contact list!</p>'; |
|
187 echo '</div>'; |
|
188 } |
|
189 else |
|
190 echo '<p>There was a problem creating your account. If the problem persists, please <a href="http://speeqe.com/room/jabber@conference.jabber.org/">contact us</a>.</p>'; |
|
191 } |
|
192 $registration_backend->close(); |
|
193 } |
|
194 else |
|
195 { |
|
196 echo '<p>Sorry, the CAPTCHA text you entered was incorrect, please <a href="./">go back</a> and try again.</p>'; |
|
197 if($config['debug']) |
|
198 echo '('.$resp->error.')'; |
|
199 } |
|
200 } |
|
201 ?> |
|
202 |
|
203 </div> |
|
204 <?php @include('themes/'.$config['theme'].'/footer.php'); ?> |
|
205 </body> |
|
206 </html> |