PageRenderTime 48ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-content/plugins/sabre/classes/sabre_class.php

https://bitbucket.org/crypticrod/sr_wp_code
PHP | 1662 lines | 1326 code | 201 blank | 135 comment | 232 complexity | e41e4c5557b57f79d981252aaad6e5de MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, LGPL-2.1, GPL-3.0, LGPL-2.0, AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. include(SABREPATH.'classes/wordgen_class.php');
  3. class Sabre {
  4. var $DB_VERSION = 7;
  5. var $VERSION = '1.2.0';
  6. var $custom_logo;
  7. /***********************************************************************/
  8. /* Initialization */
  9. /***********************************************************************/
  10. function init() {
  11. load_plugin_textdomain('sabre', false, SABREDIR . '/languages');
  12. }
  13. /***********************************************************************/
  14. /* Add Sabre page in the Admin/Manage menu */
  15. /***********************************************************************/
  16. function options() {
  17. if ((!is_multisite() && current_user_can( 'manage_options' )) || (is_multisite() && is_super_admin()))
  18. add_management_page(__('Sabre Options', 'sabre'), 'Sabre', 'administrator', "sabre", array(&$this, 'option_page'));
  19. }
  20. /***********************************************************************/
  21. /* Handling of Sabre in the Admin/Manage menu */
  22. /***********************************************************************/
  23. function option_page() {
  24. require_once(SABREPATH . 'classes/sabre_class_admin.php');
  25. }
  26. /**********************************************************************/
  27. /* Get Sabre options */
  28. /**********************************************************************/
  29. function get_option($key, $default=false) {
  30. if (is_multisite())
  31. return get_site_option($key, $default);
  32. else
  33. return get_option($key, $default);
  34. }
  35. /**********************************************************************/
  36. /* Update Sabre options */
  37. /**********************************************************************/
  38. function update_option($key, $value) {
  39. if (is_multisite())
  40. return update_site_option($key, $value);
  41. else
  42. return update_option($key, $value);
  43. }
  44. /**********************************************************************/
  45. /* Delete Sabre options */
  46. /**********************************************************************/
  47. function delete_option($key) {
  48. if (is_multisite())
  49. return delete_site_option($key);
  50. else
  51. return delete_option($key);
  52. }
  53. /***********************************************************************/
  54. /* Add tests to registration form */
  55. /***********************************************************************/
  56. function change_registration_form($errors='') {
  57. global $wpdb;
  58. if ( !is_wp_error($errors) )
  59. $errors = new WP_Error();
  60. $sabre_opt = $this->get_option('sabre_opt');
  61. if (is_array($sabre_opt))
  62. extract ($sabre_opt, EXTR_OVERWRITE) ;
  63. // Choose the sequence of tests
  64. if ($sabre_seq == 'Random') {
  65. $arr1 = array();
  66. $arr2 = array( 'enable_captcha' => 'false',
  67. 'enable_math' => 'false',
  68. 'enable_text' => 'false' );
  69. if ($enable_captcha == 'true')
  70. $arr1[] = 'enable_captcha';
  71. if ($enable_math == 'true')
  72. $arr1[] = 'enable_math';
  73. if ($enable_text == 'true')
  74. $arr1[] = 'enable_text';
  75. $dice = mt_rand(0,(count($arr1) - 1));
  76. $arr2[$arr1[$dice]] = 'true';
  77. extract ($arr2, EXTR_OVERWRITE);
  78. }
  79. if ($enable_captcha == 'true') {
  80. $max = strlen($acceptedChars)-1;
  81. for($i=0; $i < $stringlength; $i++)
  82. $password .= $acceptedChars{mt_rand(0, $max)};
  83. }
  84. if ($enable_math == 'true') {
  85. $max = strlen($math_ops)-1;
  86. $mathop = $math_ops{mt_rand(0, $max)};
  87. $nb1 = mt_rand(1, 20);
  88. $nb2 = mt_rand(1, 20);
  89. switch ($mathop) {
  90. case '-' :
  91. if ($nb1 > $nb2) {
  92. $mathcode = $nb1 - $nb2;
  93. $mathstring = $nb1 . ' - ' . $nb2;
  94. }
  95. else {
  96. $mathcode = $nb2 - $nb1;
  97. $mathstring = $nb2 . ' - ' . $nb1;
  98. }
  99. break;
  100. case '*' :
  101. $mathcode = $nb1 * $nb2;
  102. $mathstring = $nb1 . ' * ' . $nb2;
  103. break;
  104. case '+' :
  105. default :
  106. $mathcode = $nb1 + $nb2;
  107. $mathstring = $nb1 . ' + ' . $nb2;
  108. break;
  109. }
  110. }
  111. if ($enable_text == 'true') {
  112. $ord = array('first', 'second', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth', 'last');
  113. $myWord = new wordGenerator();
  114. $t_word = strtoupper($myWord->create(5,10,true));
  115. $t_index = mt_rand(0, strlen($t_word)-1);
  116. $t_letter = $t_word[$t_index];
  117. $t_ord = __($ord[($t_index==strlen($t_word)-1 ? 9 : $t_index)], 'sabre');
  118. unset($myWord);
  119. unset($ord);
  120. }
  121. $curdate = current_time('timestamp', 0);
  122. $stordate = date("Y-m-d H:i:s", $curdate);
  123. @$wpdb->query("INSERT INTO `" . SABRE_TABLE . "` SET `user_IP` = '" . $_SERVER['REMOTE_ADDR'] . "', `first_mod` = '" . $stordate . "', `last_mod` = '" . $stordate . "'" . (isset($password) ? ", `captcha` = '" . $password . "'" : "") . (isset($mathcode) ? ", `math` = " . $mathcode : "") . (isset($t_letter) ? ", `letter` = '" . $t_letter . "'" : ""));
  124. $id = $wpdb->insert_id;
  125. if ($user_pwd == 'true') {
  126. echo '<p id="sabre_pwd">';
  127. echo '<label>' . __('Please enter your password twice:', 'sabre') . '<br />';
  128. if ( $errmsg = $errors->get_error_message('sabre_no_user_pwd') )
  129. echo '<p class="error">' .$errmsg .'</p>';
  130. if ( $errmsg = $errors->get_error_message('sabre_mismatch_user_pwd') )
  131. echo '<p class="error">' .$errmsg .'</p>';
  132. if ( $errmsg = $errors->get_error_message('sabre_short_user_pwd') )
  133. echo '<p class="error">' .$errmsg .'</p>';
  134. echo '<input type="password" name="user_pwd1" id="user_pwd1" class="input" value="" size="20" tabindex="25" /></label>';
  135. echo '<input type="password" name="user_pwd2" id="user_pwd2" class="input" value="" size="20" tabindex="26" /></label><br />';
  136. echo '<strong>' . __('Strength indicator', 'sabre') . '</strong>';
  137. echo '<label id="pass-strength-result">' . __('Too short', 'sabre') . '</label><br />' . __('Hint: Your password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ &amp; ).', 'sabre');
  138. echo '</p>';
  139. }
  140. if ($enable_captcha == 'true') {
  141. $sabre_id = $sabre_opt;
  142. $sabre_id['captcha'] = $password;
  143. echo '<p>';
  144. echo '<img src="' . SABREURL . 'sabre_captcha.php?sabre_id=' . base64_encode($this->Encrypt_Decrypt($password)) . '&acceptedChars=' . $acceptedChars . '&stringlength=' . $stringlength . '&contrast=' . $contrast . '&num_polygons=' . $num_polygons . '&num_ellipses=' . $num_ellipses . '&num_lines=' . $num_lines . '&num_dots=' . $num_dots . '&min_thickness=' . $min_thickness . '&max_thickness=' . $max_thickness . '&min_radius=' . $min_radius . '&max_radius=' . $max_radius . '&object_alpha=' . $object_alpha . '&white_bg=' . $white_bg . '" border="0" alt="captcha image" /><br />';
  145. echo '<label>' . __('Please enter the code shown above:', 'sabre') . '<br />';
  146. if ( $errmsg = $errors->get_error_message('sabre_captcha') )
  147. echo '<p class="error">' .$errmsg .'</p>';
  148. echo '<input type="text" name="captcha" id="captcha" class="input" value="" size="25" tabindex="30" /></label>';
  149. echo '</p>';
  150. }
  151. if ($enable_math == 'true') {
  152. echo '<p>';
  153. echo '<label>' . sprintf(__('Please enter the result: %s', 'sabre'), $mathstring) . '<br />';
  154. if ( $errmsg = $errors->get_error_message('sabre_math') )
  155. echo '<p class="error">' .$errmsg .'</p>';
  156. echo '<input type="text" name="math" id="math" class="input" value="" size="10" tabindex="40" /></label>';
  157. echo '</p>';
  158. }
  159. if ($enable_text == 'true') {
  160. echo '<p>';
  161. echo '<label>' . sprintf(__('Please enter the %s letter of the word %s', 'sabre'), $t_ord, $t_word) . '<br />';
  162. if ( $errmsg = $errors->get_error_message('sabre_text') )
  163. echo '<p class="error">' .$errmsg .'</p>';
  164. echo '<input type="text" name="letter" id="letter" class="input" value="" size="2" tabindex="42" /></label>';
  165. echo '</p>';
  166. }
  167. if ($enable_policy == 'true') {
  168. echo '<p><label>';
  169. if (empty($policy_link))
  170. echo htmlentities(stripslashes($policy_name), ENT_QUOTES, 'UTF-8') . '<br />';
  171. else
  172. echo '<a href="' . $policy_link . '" target="_blank">' . htmlentities(stripslashes($policy_name), ENT_QUOTES, 'UTF-8') . '</a><br />';
  173. if (!empty($policy_text))
  174. echo '<textarea rows="10" cols="25" readonly>' . htmlentities(stripslashes($policy_text), ENT_QUOTES, 'UTF-8') . '</textarea><br />';
  175. if ( $errmsg = $errors->get_error_message('sabre_no_policy') )
  176. echo '<p class="error">' .$errmsg .'</p>';
  177. echo '<input type="checkbox" name="policy" id="policy" value="yes" tabindex="43" />';
  178. _e('I agree', 'sabre');
  179. echo '</label></p>';
  180. }
  181. if ($enable_invite == 'true') {
  182. echo '<p>';
  183. echo '<label>' . __('Please enter your invitation code:', 'sabre') . '<br />';
  184. if ( $errmsg = $errors->get_error_message('sabre_invitation') )
  185. echo '<p class="error">' .$errmsg .'</p>';
  186. echo '<input type="text" name="invite_code" id="invite_code" class="input" value="" size="20" tabindex="45" /></label>';
  187. echo '</p>';
  188. }
  189. // Add anti-bot fields
  190. if ($enable_stealth == 'true') {
  191. // Verify fake user
  192. $fakeField = "X" . md5($id . $magic_seed . $_SERVER['REMOTE_ADDR'] . $curdate);
  193. echo '<p id="sabre_spectre">';
  194. echo '<label>' . __("Please don't modify this field:", 'sabre') . '<br />';
  195. echo "<input type=\"text\" name=\"$fakeField\" id=\"$fakeField\" class=\"input\" value=\"\" size=\"10\" tabindex=\"50\" /></label>";
  196. echo '</p>';
  197. // Verify Javascript capabilities
  198. $max = rand(5, 9);
  199. $tot = $str = 1;
  200. for ($i = 0; $i < $max; $i++) {
  201. $op = rand(0, 8);
  202. $num = rand(1, 42);
  203. switch ($op) {
  204. case 0:
  205. case 8:
  206. $str = "(" . $str . " + " . $num . ")";
  207. $tot += $num;
  208. break;
  209. case 1:
  210. $str = "(" . $str . " - " . $num . ")";
  211. $tot -= $num;
  212. break;
  213. case 2:
  214. $str = "(" . $str . " * " . $num . ")";
  215. $tot *= $num;
  216. break;
  217. case 3:
  218. $str = "Math.round ( Math.abs(" . $str . " / " . $num . "))";
  219. $tot = round(abs($tot / $num));
  220. break;
  221. case 4:
  222. $str = "Math.min(" . $str . ", " . $num . ")";
  223. $tot = min($tot, $num);
  224. break;
  225. case 5:
  226. $str = "Math.max(" . $str . ", " . $num . ")";
  227. $tot = max($tot, $num);
  228. break;
  229. case 6:
  230. $str = "Math.round ( Math.abs(" . $str . " % " . $num . "))";
  231. $tot = round(abs($tot % $num));
  232. break;
  233. case 7:
  234. $str = "(" . $str . " + Math.round( Math.abs(100*Math.sin(" . $num . ")) ) )";
  235. $tot = $tot + round(abs(100*sin($num)));
  236. break;
  237. }
  238. }
  239. $js_command = "Math.round ( Math.abs(" . $str . "))" ;
  240. $tot = round(abs($tot));
  241. $check1 = $this->magic_seed(10);
  242. $check2 = md5($tot . $check1 . $magic_seed);
  243. echo '<input type="hidden" id="sabre_js_check1" name="sabre_js_check1" value="' . $check1 . '" />';
  244. echo '<input type="hidden" id="sabre_js_check2" name="sabre_js_check2" value="' . $check2 . '" />';
  245. echo "\n<script type=\"text/javascript\">";
  246. echo "\n<!--";
  247. echo "\ndocument.write('<input type=\"hidden\" id=\"sabre_js_payload\" name=\"sabre_js_payload\" value=\"');";
  248. echo "\ndocument.write($js_command);";
  249. echo "\ndocument.write('\" />');";
  250. echo "\n-->";
  251. echo "\n</script>";
  252. }
  253. echo '<input type="hidden" name="sabre_id" id="sabre_id" class="input" value="' . $id . '" />';
  254. if ( $errmsg = $errors->get_error_message('sabre_generic') )
  255. echo '<p class="error">' .$errmsg .'</p>';
  256. // Add Sabre banner
  257. if ($show_banner == 'true')
  258. echo '<p id="sabre_banner">' . __('Protected by', 'sabre') . ' <a id="sabre_link" href="http://didier.lorphelin.free.fr/blog/index.php/wordpress/sabre">Sabre</a>.' . ($total_stopped ? sprintf(__ngettext(' %s alien stopped.', ' %s aliens stopped.', $total_stopped, 'sabre'), $total_stopped) : '') . '</p>';
  259. }
  260. /***********************************************************************/
  261. /* Test the info entered by the user */
  262. /***********************************************************************/
  263. function check_entry($stuff) {
  264. global $wpdb;
  265. if (!is_multisite())
  266. $errors = $stuff;
  267. else
  268. extract($stuff);
  269. // To speed up things, check the user entry only if no error was detected before calling Sabre
  270. if ( !$errors->get_error_code()) {
  271. $sabre_opt = $this->get_option('sabre_opt');
  272. if (is_array($sabre_opt))
  273. extract ($sabre_opt, EXTR_OVERWRITE) ;
  274. $sabre_errors = array();
  275. $error_head_text = __('<strong>ERROR</strong>: ', 'sabre');
  276. $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . SABRE_TABLE . "` WHERE `id` = %d", (int)$_POST['sabre_id']));
  277. $curdate = current_time('timestamp', 0);
  278. $stordate = date("Y-m-d H:i:s", $curdate);
  279. if (empty($result->id)) {
  280. $error_msg_text = __('Unknown session.', 'sabre');
  281. $errors->add('sabre_session', $error_head_text . $error_msg_text);
  282. $sabre_errors['sabre_session'] = $error_msg_text;
  283. }
  284. if ($result->status != 'pending') {
  285. $error_msg_text = __('Invalid session status.', 'sabre');
  286. $errors->add('sabre_session_status', $error_head_text . $error_msg_text);
  287. $sabre_errors['sabre_session_status'] = $error_msg_text;
  288. }
  289. if ($enable_stealth == 'true') {
  290. // Check user IP
  291. if ($result->user_IP <> $_SERVER['REMOTE_ADDR']) {
  292. $error_msg_text = __('Invalid IP address.', 'sabre');
  293. $errors->add('sabre_IP', $error_head_text . $error_msg_text);
  294. $sabre_errors['sabre_IP'] = $error_msg_text;
  295. }
  296. // Check banned IP
  297. if ($check_banned_IP == 'true') {
  298. $error_msg_text = __('Banned IP address.', 'sabre');
  299. $spammer_IP = $_SERVER['REMOTE_ADDR'];
  300. $reverse_IP = array_reverse(explode('.', $spammer_IP));
  301. $checked_domaine = implode('.', $reverse_IP) . '.' . 'zen.spamhaus.org';
  302. if ($checked_domaine != gethostbyname($checked_domaine)) {
  303. $errors->add('sabre_banIP', $error_head_text . $error_msg_text);
  304. $sabre_errors['sabre_banIP'] = $error_msg_text;
  305. }
  306. $checked_domaine = implode('.', $reverse_IP) . '.' . 'l1.spews.dnsbl.sorbs.net';
  307. if ($checked_domaine != gethostbyname($checked_domaine)) {
  308. $errors->add('sabre_banIP', $error_head_text . $error_msg_text);
  309. $sabre_errors['sabre_banIP'] = $error_msg_text;
  310. }
  311. }
  312. // Check session time out
  313. if (strtotime($result->last_mod) + (int)$session_timeout < $curdate) {
  314. $error_msg_text = __('Session timed out.', 'sabre');
  315. $errors->add('sabre_timeout', $error_head_text . $error_msg_text);
  316. $sabre_errors['sabre_timeout'] = $error_msg_text;
  317. }
  318. // Check excessive speed
  319. if (strtotime($result->last_mod) + (int)$speed_limit > $curdate) {
  320. $error_msg_text = __('Speedy Gonzales was here.', 'sabre');
  321. $errors->add('sabre_speed', $error_head_text . $error_msg_text);
  322. $sabre_errors['sabre_speed'] = $error_msg_text;
  323. }
  324. // Check false fields
  325. $fakeField = "X" . md5($result->id . $magic_seed . $result->user_IP . strtotime($result->last_mod));
  326. if (!isset($_POST[$fakeField]) || !empty($_POST[$fakeField])) {
  327. $error_msg_text = __('Fake user.', 'sabre');
  328. $errors->add('sabre_fake_user', $error_head_text . $error_msg_text);
  329. $sabre_errors['sabre_fake_user'] = $error_msg_text;
  330. }
  331. // Check Javascript capabilities
  332. if (empty($_POST['sabre_js_payload']) || empty($_POST['sabre_js_check1'])) {
  333. if ($js_support == 'true') {
  334. $error_msg_text = __('No Javascript capabilities.', 'sabre');
  335. $errors->add('sabre_js', $error_head_text . $error_msg_text);
  336. $sabre_errors['sabre_js'] = $error_msg_text;
  337. }
  338. }
  339. else {
  340. if ($_POST['sabre_js_check2'] != md5($_POST['sabre_js_payload'] . $_POST['sabre_js_check1'] . $magic_seed)) {
  341. $error_msg_text = __('Fake Javascript capabilities.', 'sabre');
  342. $errors->add('sabre_fake_js', $error_head_text . $error_msg_text);
  343. $sabre_errors['sabre_fake_js'] = $error_msg_text;
  344. }
  345. }
  346. }
  347. if ($user_pwd == 'true') {
  348. if(empty($_POST['user_pwd1']) || $_POST['user_pwd1'] == '' || empty($_POST['user_pwd2']) || $_POST['user_pwd2'] == ''){
  349. $error_msg_text = __('Missing password.', 'sabre');
  350. $errors->add('sabre_no_user_pwd', $error_head_text . $error_msg_text);
  351. $sabre_errors['sabre_no_user_pwd'] = $error_msg_text;
  352. }elseif($_POST['user_pwd1'] !== $_POST['user_pwd2']){
  353. $error_msg_text = __('Mismatch between password fields.', 'sabre');
  354. $errors->add('sabre_mismatch_user_pwd', $error_head_text . $error_msg_text);
  355. $sabre_errors['sabre_mismatch_user_pwd'] = $error_msg_text;
  356. }elseif(strlen($_POST['user_pwd1'])<6){
  357. $error_msg_text = __('Password length is less than 6 characters.', 'sabre');
  358. $errors->add('sabre_short_user_pwd', $error_head_text . $error_msg_text);
  359. $sabre_errors['sabre_short_user_pwd'] = $error_msg_text;
  360. }
  361. }
  362. if ($enable_policy == 'true') {
  363. if($_POST['policy'] != 'yes'){
  364. $error_msg_text = __('Policy not accepted.', 'sabre');
  365. $errors->add('sabre_no_policy', $error_head_text . $error_msg_text);
  366. $sabre_errors['sabre_no_policy'] = $error_msg_text;
  367. }
  368. }
  369. if ($result->captcha != NULL) {
  370. $string = strtoupper($result->captcha);
  371. $userstring = strtoupper($_POST['captcha']);
  372. if (($string <> $userstring) || (strlen($userstring) <> $stringlength)) {
  373. $error_msg_text = __('Invalid code.', 'sabre');
  374. $errors->add('sabre_captcha', $error_head_text . $error_msg_text);
  375. $sabre_errors['sabre_captcha'] = $error_msg_text;
  376. }
  377. }
  378. if ($result->math != NULL) {
  379. if ($result->math <> $_POST['math']) {
  380. $error_msg_text = __('Invalid math result.', 'sabre');
  381. $errors->add('sabre_math', $error_head_text . $error_msg_text);
  382. $sabre_errors['sabre_math'] = $error_msg_text;
  383. }
  384. }
  385. if ($result->letter != NULL) {
  386. if ($result->letter <> strtoupper($_POST['letter'])) {
  387. $error_msg_text = __('Invalid letter.', 'sabre');
  388. $errors->add('sabre_text', $error_head_text . $error_msg_text);
  389. $sabre_errors['sabre_text'] = $error_msg_text;
  390. }
  391. }
  392. if ($enable_invite == 'true') {
  393. for ($i=0; $i < count($invite_codes); $i++)
  394. $invite_arr[$i] = $invite_codes[$i]['code'];
  395. if(!in_array(strtoupper($_POST['invite_code']), $invite_arr)){
  396. $error_msg_text = __('Invalid invitation code.', 'sabre');
  397. $errors->add('sabre_invitation', $error_head_text . $error_msg_text);
  398. $sabre_errors['sabre_invitation'] = $error_msg_text;
  399. }
  400. else {
  401. $key = array_keys($invite_arr, strtoupper($_POST['invite_code']));
  402. if (!empty($invite_codes[$key[0]]['date'])) {
  403. if ($invite_codes[$key[0]]['date'] < $curdate) {
  404. $error_msg_text = __('Invalid invitation code.', 'sabre');
  405. $errors->add('sabre_invitation', $error_head_text . $error_msg_text);
  406. $sabre_errors['sabre_invitation'] = $error_msg_text;
  407. }
  408. }
  409. if (is_numeric($invite_codes[$key[0]]['number']) && empty($sabre_errors)) {
  410. --$invite_codes[$key[0]]['number'];
  411. if ($invite_codes[$key[0]]['number'] < 0) {
  412. $invite_codes[$key[0]]['number'] = 0;
  413. $error_msg_text = __('Invalid invitation code.', 'sabre');
  414. $errors->add('sabre_invitation', $error_head_text . $error_msg_text);
  415. $sabre_errors['sabre_invitation'] = $error_msg_text;
  416. }
  417. $sabre_opt['invite_codes'] = $invite_codes;
  418. }
  419. }
  420. }
  421. if (!empty($sabre_errors)) {
  422. $error_msg_text = __('Registration stopped by Sabre.', 'sabre');
  423. $errors->add('sabre_generic', $error_head_text . $error_msg_text);
  424. @$wpdb->query($wpdb->prepare("UPDATE `" . SABRE_TABLE . "` SET `user` = %s, `email` = %s, `msg` = '" . maybe_serialize($sabre_errors) . "', `invite` = %s, `last_mod` = '" . $stordate ."', `status` = 'ko', `md5_id` = %s WHERE `id` = %d", !is_multisite() ? $_POST['user_login'] : $_POST['user_name'], $_POST['user_email'], $_POST['invite_code'], md5($_POST['sabre_id']), (int)$_POST['sabre_id']));
  425. $sabre_opt['total_stopped'] += 1;
  426. }
  427. elseif ($enable_confirm != 'none') {
  428. @$wpdb->query($wpdb->prepare("UPDATE `" . SABRE_TABLE . "` SET `user` = %s, `email` = %s, `invite` = %s, `msg` = '', `last_mod` = '" . $stordate ."', `status` = 'to confirm', `md5_id` = %s WHERE `id` = %d", !is_multisite() ? $_POST['user_login'] : $_POST['user_name'], $_POST['user_email'], $_POST['invite_code'], md5($_POST['sabre_id']), (int)$_POST['sabre_id']));
  429. }
  430. else {
  431. @$wpdb->query($wpdb->prepare("UPDATE `" . SABRE_TABLE . "` SET `user` = %s, `email` = %s, `invite` = %s, `msg` = '', `last_mod` = '" . $stordate ."', `status` = 'ok', `md5_id` = %s WHERE `id` = %d", !is_multisite() ? $_POST['user_login'] : $_POST['user_name'], $_POST['user_email'], $_POST['invite_code'], md5($_POST['sabre_id']), (int)$_POST['sabre_id']));
  432. $sabre_opt['total_accepted'] += 1;
  433. do_action('sabre_accepted_registration');
  434. }
  435. $this->update_option('sabre_opt', $sabre_opt);
  436. }
  437. if (!is_multisite())
  438. $stuff = $errors;
  439. else
  440. $stuff = array('user_name' => $user_name, 'orig_username' => $orig_username, 'user_email' => $user_email, 'errors' => $errors);
  441. return $stuff;
  442. }
  443. /***********************************************************************/
  444. /* Check the login header */
  445. /***********************************************************************/
  446. function login_head() {
  447. global $error, $wpdb;
  448. if (isset($_REQUEST['sabre_confirm']) && !empty($_REQUEST['sabre_confirm'])) {
  449. $sabre_opt = $this->get_option('sabre_opt');
  450. if (is_array($sabre_opt))
  451. extract ($sabre_opt, EXTR_OVERWRITE) ;
  452. $sabre_errors = array();
  453. $error_head_text = __('<strong>ERROR</strong>: ', 'sabre');
  454. $curdate = current_time('timestamp', 0);
  455. $stordate = date("Y-m-d H:i:s", $curdate);
  456. if ($enable_confirm == 'user') {
  457. $result = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . SABRE_TABLE . "` WHERE `md5_id` = %s", $_REQUEST['sabre_confirm']));
  458. if ((strtotime($result->last_mod) + (int)$period*24*60*60 >= $curdate) && ('to confirm' == $result->status)) {
  459. $error = __('Registration confirmed. You can now use your credentials to enter in this site.', 'sabre');
  460. @$wpdb->query($wpdb->prepare("UPDATE `" . SABRE_TABLE . "` SET `last_mod` = '" . $stordate ."', `status` = 'ok' WHERE `md5_id` = %s", $_REQUEST['sabre_confirm']));
  461. $sabre_opt['total_accepted'] += 1;
  462. $this->update_option('sabre_opt', $sabre_opt);
  463. do_action('sabre_accepted_registration');
  464. if ($mail_confirm == 'true')
  465. $this->new_user_confirmation($result->user_id);
  466. }
  467. else {
  468. if ('to confirm' == $result->status) {
  469. if ($delete_user == 'true') wp_delete_user($result->user_id);
  470. $error_msg_text = __('Exceeded period for confirmation of registration.', 'sabre');
  471. $error = $error_head_text . $error_msg_text;
  472. $sabre_errors['sabre_confirm'] = $error_msg_text;
  473. @$wpdb->query($wpdb->prepare("UPDATE `" . SABRE_TABLE . "` SET `msg` = '" . maybe_serialize($sabre_errors) . "', `last_mod` = '" . $stordate ."', `status` = 'ko' WHERE `md5_id` = %s", $_REQUEST['sabre_confirm']));
  474. $sabre_opt['total_stopped'] += 1;
  475. $this->update_option('sabre_opt', $sabre_opt);
  476. }
  477. else
  478. $error = $error_head_text . __('Unexpected confirmation of registration.', 'sabre');
  479. }
  480. }
  481. }
  482. }
  483. /***********************************************************************/
  484. /* Check the login data */
  485. /***********************************************************************/
  486. function check_login($user, $pass) {
  487. global $wpdb;
  488. $sabre_opt = $this->get_option('sabre_opt');
  489. if (is_array($sabre_opt))
  490. extract ($sabre_opt, EXTR_OVERWRITE) ;
  491. $curdate = current_time('timestamp', 0);
  492. $stordate = date("Y-m-d H:i:s", $curdate);
  493. if ($enable_confirm != 'none') {
  494. $sabre_errors = array();
  495. $error_head_text = __('<strong>ERROR</strong>: ', 'sabre');
  496. $cu = new WP_User($user->ID);
  497. if (!$cu->has_cap('edit_users')) {
  498. $result = $wpdb->get_row("SELECT * FROM `" . SABRE_TABLE . "` WHERE `user_id` = " . (int)$user->ID);
  499. if ('ok' != $result->status) {
  500. if ('to confirm' == $result->status) {
  501. if ($enable_confirm == 'user') {
  502. if (strtotime($result->last_mod) + (int)$period*24*60*60 < $curdate) {
  503. $error_msg_text = __('Exceeded period for confirmation of registration.', 'sabre');
  504. $sabre_errors['sabre_login'] = $error_msg_text;
  505. @$wpdb->query("UPDATE `" . SABRE_TABLE . "` SET `msg` = '" . maybe_serialize($sabre_errors) . "', `last_mod` = '" . $stordate ."', `status` = 'ko' WHERE `id` = " . (int)$result->id);
  506. $sabre_opt['total_stopped'] += 1;
  507. $this->update_option('sabre_opt', $sabre_opt);
  508. if ($delete_user == 'true')
  509. wp_delete_user($user->ID);
  510. return new WP_Error('sabre_login', $error_head_text . $error_msg_text);
  511. }
  512. elseif ($no_entry == 'true') {
  513. $error_msg_text = __('Confirmation pending. See registration e-mail.', 'sabre');
  514. $sabre_errors['sabre_login'] = $error_msg_text;
  515. return new WP_Error('sabre_login', $error_head_text . $error_msg_text);
  516. }
  517. }
  518. else {
  519. $error_msg_text = __('Registration not yet validated by the site\'s administrator. Wait for confirmation e-mail.', 'sabre');
  520. $sabre_errors['sabre_login'] = $error_msg_text;
  521. return new WP_Error('sabre_login', $error_head_text . $error_msg_text);
  522. }
  523. }
  524. else {
  525. $error_msg_text = __('Invalid registration status.', 'sabre');
  526. $sabre_errors['sabre_login'] = $error_msg_text;
  527. return new WP_Error('sabre_login', $error_head_text . $error_msg_text);
  528. }
  529. }
  530. }
  531. }
  532. return $user;
  533. }
  534. /***********************************************************************/
  535. /* New user creation */
  536. /***********************************************************************/
  537. function new_user_created($user_id) {
  538. global $wpdb;
  539. $user = new WP_User( (int)$user_id);
  540. @$wpdb->query($wpdb->prepare("UPDATE `" . SABRE_TABLE . "` SET `user_id` = %d WHERE `user` = %s and `status` in ('ok', 'to confirm')", (int)$user->ID, $user->user_login));
  541. }
  542. /***********************************************************************/
  543. /* User confirmation function */
  544. /***********************************************************************/
  545. function new_user_confirmation($user_id) {
  546. global $wpdb;
  547. $user = new WP_User($user_id);
  548. $user_login = stripslashes($user->user_login);
  549. $user_email = stripslashes($user->user_email);
  550. $sabre_opt = $this->get_option('sabre_opt');
  551. $mail_from = "From: ";
  552. $mail_from .= (!empty($sabre_opt['mail_from_name']) ? $sabre_opt['mail_from_name'] : get_option('blogname')) . " <";
  553. $mail_from .= (!empty($sabre_opt['mail_from_mail']) ? $sabre_opt['mail_from_mail'] : get_option('admin_email')) . ">";
  554. $message = sprintf(__('New user registration confirmed on your site %s:', 'sabre'), get_option('blogname')) . "\r\n\r\n";
  555. $message .= sprintf(__('Username: %s', 'sabre'), $user_login) . "\r\n\r\n";
  556. $message .= sprintf(__('E-mail: %s', 'sabre'), $user_email) . "\r\n";
  557. @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration Confirmation', 'sabre'), get_option('blogname')), $message, $mail_from);
  558. }
  559. /***********************************************************************/
  560. /* Admin confirmation function */
  561. /***********************************************************************/
  562. function new_admin_confirmation($user_id) {
  563. global $wpdb;
  564. $user = new WP_User($user_id);
  565. $user_login = stripslashes($user->user_login);
  566. $user_email = stripslashes($user->user_email);
  567. $sabre_opt = $this->get_option('sabre_opt');
  568. $mail_from = "From: ";
  569. $mail_from .= (!empty($sabre_opt['mail_from_name']) ? $sabre_opt['mail_from_name'] : get_option('blogname')) . " <";
  570. $mail_from .= (!empty($sabre_opt['mail_from_mail']) ? $sabre_opt['mail_from_mail'] : get_option('admin_email')) . ">";
  571. $message = sprintf(__('Your registration on %s is now confirmed. You can freely sign in using the credentials given in a previous mail. Thank you for your interest.', 'sabre'), get_option('blogname')) . "\r\n\r\n";
  572. $message .= sprintf(__('Username: %s', 'sabre'), $user_login) . "\r\n\r\n";
  573. $message .= get_option('siteurl') . "/wp-login.php\r\n";
  574. @wp_mail($user_email, sprintf(__('[%s] New User Registration Confirmation', 'sabre'), get_option('blogname')), $message, $mail_from);
  575. }
  576. /***********************************************************************/
  577. /* Option checked/unchecked */
  578. /***********************************************************************/
  579. function magic_seed($size) {
  580. $core = "0123456789abcdefghijklmnopqrstuvwxyz";
  581. for ($i=0; $i < $size; $i++)
  582. $SeedOfLove .= substr($core, rand(0, strlen($core)-1), 1);
  583. return $SeedOfLove;
  584. }
  585. /***********************************************************************/
  586. /* Option checked/unchecked */
  587. /***********************************************************************/
  588. function checked($var1, $var2) {
  589. if ($var1 == $var2)
  590. return 'checked';
  591. else
  592. return '';
  593. }
  594. /***********************************************************************/
  595. /* Option selected/unselected */
  596. /***********************************************************************/
  597. function selected($var1, $var2) {
  598. if ($var1 == $var2)
  599. return 'selected';
  600. else
  601. return '';
  602. }
  603. /***********************************************************************/
  604. /* Register manually a user */
  605. /***********************************************************************/
  606. function add_reg_user($reguser) {
  607. global $wpdb;
  608. check_admin_referer('sabre-manage_registration');
  609. $curdate = current_time('timestamp', 0);
  610. $stordate = date("Y-m-d H:i:s", $curdate);
  611. $user_info = new WP_User($reguser);
  612. if($user_info->user_login == $reguser) {
  613. if (!$user_info->has_cap('edit_users')) {
  614. if (!$wpdb->get_var("SELECT COUNT(*) FROM `" . SABRE_TABLE . "` WHERE `status` in ('ok', 'to confirm') AND `user_id` = '" . $user_info->ID . "'")) {
  615. @$wpdb->query("INSERT INTO `" . SABRE_TABLE . "` SET `user_IP` = 'none', `first_mod` = '" . $stordate ."', `last_mod` = '" . $stordate ."', `status` = 'ok', `user` = '" . $user_info->user_login . "', `email` = '" . $user_info->user_email . "', `user_id` = '" . $user_info->ID . "'");
  616. if (!mysql_error()) {
  617. $id = $wpdb->insert_id;
  618. @$wpdb->query("UPDATE `" . SABRE_TABLE . "` SET `md5_id` = '" . md5($id) . "' WHERE `id` = " . (int)$id);
  619. if (!mysql_error()) {
  620. $msg = __('WordPress user successfully registered.', 'sabre');
  621. do_action('sabre_accepted_registration');
  622. }
  623. else
  624. $msg = __('Unexpected SQL error. Current operation failed.', 'sabre');
  625. }
  626. else $msg = __('Unexpected SQL error. Current operation failed.', 'sabre');
  627. }
  628. else $msg = __('WordPress user is already registered. Manual registration ineffective.', 'sabre');
  629. }
  630. else $msg = __("WordPress user doesn't need to confirm registration. Manual registration ineffective.", 'sabre');
  631. }
  632. else $msg = __('Unknown WordPress user. Manual registration failed.', 'sabre');
  633. return $msg;
  634. }
  635. /***********************************************************************/
  636. /* Register manually all existing users */
  637. /***********************************************************************/
  638. function add_all_users() {
  639. check_admin_referer('sabre-manage_registration');
  640. $users = get_users_of_blog();
  641. $total = 0;
  642. $added = 0;
  643. $msg = __('WordPress user successfully registered.', 'sabre');
  644. foreach ($users as $user) {
  645. $total += 1;
  646. $ret = $this->add_reg_user($user->user_login);
  647. if ($ret == $msg) $added += 1;
  648. }
  649. return sprintf(__ngettext('%s/%s WordPress user successfully registered.','%s/%s WordPress users successfully registered.', $added, 'sabre'), $added, $total);
  650. }
  651. /***********************************************************************/
  652. /* Unregister manually a user */
  653. /***********************************************************************/
  654. function del_reg_user($list) {
  655. global $wpdb;
  656. check_admin_referer('sabre-manage_registration');
  657. $curdate = current_time('timestamp', 0);
  658. $stordate = date("Y-m-d H:i:s", $curdate);
  659. $error[0] = __("Manually unregistered", 'sabre');
  660. $sabre_opt = $this->get_option('sabre_opt');
  661. foreach ($list as $selid => $delid) {
  662. if ($sabre_opt['delete_user'] == 'true') {
  663. $user = $wpdb->get_var("SELECT `user_id` FROM `" . SABRE_TABLE . "` WHERE `id` = " . (int)$delid);
  664. if (isset($user)) wp_delete_user($user);
  665. }
  666. $removed += @$wpdb->query("UPDATE `" . SABRE_TABLE . "` SET `status` = 'ko', `last_mod` = '" . $stordate ."', `user_id` = NULL, `msg` = '" . maybe_serialize($error) . "' WHERE `id` = " . (int)$delid);
  667. do_action('sabre_cancelled_registration');
  668. }
  669. if (!mysql_error())
  670. return sprintf(__ngettext('%s user manually unregistered.', '%s users manually unregistered.', $removed, 'sabre'), $removed);
  671. else
  672. return __('Unexpected SQL error. Current operation failed.', 'sabre');
  673. }
  674. /***********************************************************************/
  675. /* Purge unregistered user log */
  676. /***********************************************************************/
  677. function del_unreg_user($days) {
  678. global $wpdb;
  679. check_admin_referer('sabre-manage_registration');
  680. $curdate = current_time('timestamp', 0);
  681. $stordate = date("Y-m-d H:i:s", $curdate);
  682. $removed = $wpdb->query("DELETE FROM `" . SABRE_TABLE . "` WHERE `status` = 'ko' AND `last_mod` < DATE_SUB('$stordate', INTERVAL $days DAY)");
  683. if (!mysql_error())
  684. return sprintf(__ngettext('%s record deleted.', '%s records deleted.', $removed, 'sabre'), $removed);
  685. else
  686. return __('Unexpected SQL error. Current operation failed.', 'sabre');
  687. }
  688. /***********************************************************************/
  689. /* Refuse manually a registration */
  690. /***********************************************************************/
  691. function unconfirm_reg_user($list) {
  692. global $wpdb;
  693. check_admin_referer('sabre-manage_registration');
  694. $curdate = current_time('timestamp', 0);
  695. $stordate = date("Y-m-d H:i:s", $curdate);
  696. $error[0] = __("Registration refused by admin", 'sabre');
  697. $sabre_opt = $this->get_option('sabre_opt');
  698. foreach ($list as $selid => $delid) {
  699. if ($sabre_opt['delete_user'] == 'true') {
  700. $user = $wpdb->get_var("SELECT `user_id` FROM `" . SABRE_TABLE . "` WHERE `id` = " . (int)$delid);
  701. if (isset($user)) wp_delete_user($user);
  702. }
  703. $removed += @$wpdb->query("UPDATE `" . SABRE_TABLE . "` SET `status` = 'ko', `last_mod` = '" . $stordate ."', `user_id` = NULL, `msg` = '" . maybe_serialize($error) . "' WHERE `id` = " . (int)$delid);
  704. }
  705. if (!mysql_error()) {
  706. $sabre_opt['total_stopped'] += $removed;
  707. $this->update_option('sabre_opt', $sabre_opt);
  708. return sprintf(__ngettext('%s registration refused.', '%s registrations refused.', $removed, 'sabre'), $removed);
  709. }
  710. else
  711. return __('Unexpected SQL error. Current operation failed.', 'sabre');
  712. }
  713. /***********************************************************************/
  714. /* Confirm manually a registration */
  715. /***********************************************************************/
  716. function confirm_reg_user($list) {
  717. global $wpdb;
  718. check_admin_referer('sabre-manage_registration');
  719. $curdate = current_time('timestamp', 0);
  720. $stordate = date("Y-m-d H:i:s", $curdate);
  721. $error[0] = __("Registration confirmed by admin", 'sabre');
  722. $sabre_opt = $this->get_option('sabre_opt');
  723. foreach ($list as $selid => $delid) {
  724. $user = $wpdb->get_var("SELECT `user_id` FROM `" . SABRE_TABLE . "` WHERE `id` = " . (int)$delid);
  725. if (isset($user)) $this->new_admin_confirmation($user);
  726. $confirmed += @$wpdb->query("UPDATE `" . SABRE_TABLE . "` SET `status` = 'ok', `last_mod` = '" . $stordate ."', `msg` = '" . maybe_serialize($error) . "' WHERE `id` = " . (int)$delid);
  727. do_action('sabre_accepted_registration');
  728. }
  729. if (!mysql_error()) {
  730. $sabre_opt['total_accepted'] += $confirmed;
  731. $this->update_option('sabre_opt', $sabre_opt);
  732. return sprintf(__ngettext('%s registration confirmed.', '%s registrations confirmed.', $confirmed, 'sabre'), $confirmed);
  733. }
  734. else
  735. return __('Unexpected SQL error. Current operation failed.', 'sabre');
  736. }
  737. /***********************************************************************/
  738. /* Save Sabre options */
  739. /***********************************************************************/
  740. function save_options($form_values) {
  741. $invite_gen = array_search(__("Gen", 'sabre'), $form_values);
  742. $invite_del = array_search(__("Del", 'sabre'), $form_values);
  743. if ($invite_gen || $invite_del)
  744. $this->check_invite_codes($invite_gen, $invite_del, $form_values);
  745. if (isset($form_values['sabre_option_save'])) {
  746. check_admin_referer('sabre-manage_option');
  747. $sabre_opt = $this->get_option('sabre_opt');
  748. $sabre_opt['enable_captcha'] = (isset($form_values['sabre_enable_captcha']) ? 'true' : 'false');
  749. $sabre_opt['white_bg'] = (isset($form_values['sabre_white_bg']) ? 'true' : 'false');
  750. $sabre_opt['acceptedChars'] = (!empty($form_values['sabre_acceptedChars']) ? $form_values['sabre_acceptedChars'] : 'ABCEFGHJKMNPRSTVWXYZ123456789');
  751. $sabre_opt['stringlength'] = (!empty($form_values['sabre_stringlength']) ? (int)$form_values['sabre_stringlength'] : 5);
  752. $sabre_opt['contrast'] = (int)$form_values['sabre_contrast'];
  753. $sabre_opt['num_polygons'] = (int)$form_values['sabre_num_polygons'];
  754. $sabre_opt['num_ellipses'] = (int)$form_values['sabre_num_ellipses'];
  755. $sabre_opt['num_lines'] = (int)$form_values['sabre_num_lines'];
  756. $sabre_opt['num_dots'] = (int)$form_values['sabre_num_dots'];
  757. $sabre_opt['min_thickness'] = (int)$form_values['sabre_min_thickness'];
  758. $sabre_opt['max_thickness'] = (int)$form_values['sabre_max_thickness'];
  759. $sabre_opt['min_radius'] = (int)$form_values['sabre_min_radius'];
  760. $sabre_opt['max_radius'] = (int)$form_values['sabre_max_radius'];
  761. $sabre_opt['object_alpha'] = (int)$form_values['sabre_object_alpha'];
  762. $sabre_opt['enable_math'] = (isset($form_values['sabre_enable_math']) ? 'true' : 'false');
  763. $sabre_opt['math_ops'] = (!empty($form_values['sabre_math_ops']) ? $form_values['sabre_math_ops'] : '+-*');
  764. $sabre_opt['enable_text'] = (isset($form_values['sabre_enable_text']) ? 'true' : 'false');
  765. $sabre_opt['enable_confirm'] = (isset($form_values['sabre_enable_confirm']) ? $form_values['sabre_enable_confirm'] : 'none');
  766. $sabre_opt['period'] = (1 > (int)$form_values['sabre_confirm_period'] ? 1 : (int)$form_values['sabre_confirm_period']);
  767. $sabre_opt['no_entry'] = (isset($form_values['sabre_no_entry']) ? 'true' : 'false');
  768. $sabre_opt['delete_user'] = (isset($form_values['sabre_delete_user']) ? 'true' : 'false');
  769. $sabre_opt['mail_confirm'] = (isset($form_values['sabre_mail_confirm']) ? 'true' : 'false');
  770. $sabre_opt['sabre_seq'] = $form_values['sabre_test_seq'];
  771. $sabre_opt['enable_stealth'] = (isset($form_values['sabre_enable_stealth']) ? 'true' : 'false');
  772. $sabre_opt['js_support'] = (isset($form_values['sabre_enable_js']) ? 'true' : 'false');
  773. $sabre_opt['session_timeout'] = (int)$form_values['sabre_timeout'];
  774. $sabre_opt['speed_limit'] = (int)$form_values['sabre_speed'];
  775. $sabre_opt['check_banned_IP'] = (isset($form_values['sabre_banned_IP']) ? 'true' : 'false');
  776. $sabre_opt['user_pwd'] = (isset($form_values['sabre_user_pwd']) ? 'true' : 'false');
  777. $sabre_opt['show_banner'] = (isset($form_values['sabre_show_banner']) ? 'true' : 'false');
  778. $sabre_opt['show_dashboard'] = (isset($form_values['sabre_show_dashboard']) ? 'true' : 'false');
  779. $sabre_opt['show_user'] = (isset($form_values['sabre_show_user']) ? 'true' : 'false');
  780. $sabre_opt['suppress_sabre'] = (isset($form_values['sabre_suppress_sabre']) ? 'true' : 'false');
  781. $sabre_opt['enable_policy'] = (isset($form_values['sabre_enable_policy']) ? 'true' : 'false');
  782. $sabre_opt['policy_name'] = $form_values['sabre_policy_name'];
  783. $sabre_opt['policy_link'] = $form_values['sabre_policy_link'];
  784. $sabre_opt['policy_text'] = $form_values['sabre_policy_text'];
  785. $sabre_opt['enable_invite'] = (isset($form_values['sabre_enable_invite']) ? 'true' : 'false');
  786. $sabre_opt['invite_codes'] = $this->shrink_invite_codes($form_values);
  787. $sabre_opt['mail_from_name'] = $form_values['sabre_mail_from_name'];
  788. $sabre_opt['mail_from_mail'] = $form_values['sabre_mail_from_mail'];
  789. $this->update_option('sabre_opt', $sabre_opt);
  790. return TRUE;
  791. }
  792. return FALSE;
  793. }
  794. /***********************************************************************/
  795. /* Load CSS for Sabre admin page */
  796. /***********************************************************************/
  797. function sabre_css ()
  798. {
  799. if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'sabre')
  800. include_once(SABREPATH . 'sabre_css.php');
  801. }
  802. /***********************************************************************/
  803. /* Load CSS for login form */
  804. /***********************************************************************/
  805. function login_css ()
  806. {
  807. if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'register' && !is_multisite()) {
  808. wp_register_script('password-strength-meter', '/wp-admin/js/password-strength-meter.js', array('jquery'), '20070405');
  809. wp_localize_script( 'password-strength-meter', 'pwsL10n', array(
  810. 'short' => __('Too short', 'sabre'),
  811. 'bad' => __('Bad', 'sabre'),
  812. 'good' => __('Good', 'sabre'),
  813. 'strong' => __('Strong', 'sabre'),
  814. 'mismatch' => __('Mismatch', 'sabre')
  815. ) );
  816. wp_print_scripts('password-strength-meter');
  817. ?>
  818. <script type="text/javascript">
  819. function check_pass_strength ( ) {
  820. var pass = jQuery('#user_pwd1').val();
  821. var user = jQuery('#user_login').val();
  822. var pass2 = jQuery('#user_pwd2').val();
  823. // get the result as an object, i'm tired of typing it
  824. var res = jQuery('#pass-strength-result');
  825. var strength = passwordStrength(pass, user, pass2);
  826. jQuery(res).removeClass('short bad good strong');
  827. if ( strength == 2 ) {
  828. jQuery(res).addClass('bad');
  829. jQuery(res).html( pwsL10n.bad );
  830. }
  831. else if ( strength == 3 ) {
  832. jQuery(res).addClass('good');
  833. jQuery(res).html( pwsL10n.good );
  834. }
  835. else if ( strength == 4 ) {
  836. jQuery(res).addClass('strong');
  837. jQuery(res).html( pwsL10n.strong );
  838. }
  839. else if ( strength == 5 ) {
  840. jQuery(res).addClass('short');
  841. jQuery(res).html( pwsL10n.mismatch );
  842. }
  843. else {
  844. // this catches 'Too short' and the off chance anything else comes along
  845. jQuery(res).addClass('short');
  846. jQuery(res).html( pwsL10n.short );
  847. }
  848. }
  849. jQuery(document).ready(function($) {
  850. $('#user_pwd1').keyup( check_pass_strength );
  851. $('#user_pwd2').keyup( check_pass_strength );
  852. $('.color-palette').click(function(){$(this).siblings('input[name=admin_color]').attr('checked', 'checked')});
  853. } );
  854. jQuery(document).ready( function() {
  855. jQuery('#user_pwd1,#user_pwd2').attr('autocomplete','off');
  856. });
  857. </script>
  858. <?php
  859. }
  860. echo "<link rel=\"stylesheet\" href=\"" . SABREURL . "sabre_login.css" . "\" type=\"text/css\" />\r\n\r\n";
  861. if ($this->custom_logo && !is_multisite())
  862. echo '<style type="text/css"> h1 a {background: url(' . SABREURL . 'images/sabre-login.gif) no-repeat; width: 292px; height: 66px; text-indent: -9999px; overflow: hidden; padding-bottom: 15px; display: block;} </style>';
  863. }
  864. /***********************************************************************/
  865. /* Change default header url in login form */
  866. /***********************************************************************/
  867. function header_url ($header_url) {
  868. return get_bloginfo('url');
  869. }
  870. /***********************************************************************/
  871. /* Change default header title in login form */
  872. /***********************************************************************/
  873. function header_title ($header_title) {
  874. return get_bloginfo('name');
  875. }
  876. /***********************************************************************/
  877. /* Automatic cleanup */
  878. /***********************************************************************/
  879. function auto_clean () {
  880. global $wpdb;
  881. // Disable unconfirmed registration
  882. $sabre_opt = $this->get_option('sabre_opt');
  883. if (is_array($sabre_opt))
  884. extract ($sabre_opt, EXTR_OVERWRITE) ;
  885. $curdate = current_time('timestamp', 0);
  886. $stordate = date("Y-m-d H:i:s", $curdate);
  887. if ($enable_confirm == 'user') {
  888. $error[0] = __('Exceeded period for confirmation of registration.', 'sabre');
  889. $days = (int)$period;
  890. if ($delete_user == 'true') {
  891. $users = $wpdb->get_results("SELECT `user_id` FROM `" . SABRE_TABLE . "` WHERE `status` = 'to confirm' AND `last_mod` < DATE_SUB('$stordate', INTERVAL $days DAY)");
  892. if ($users) {
  893. foreach ($users as $user) {
  894. wp_delete_user($user->user_id);
  895. }
  896. }
  897. }
  898. @$wpdb->query("UPDATE `" . SABRE_TABLE . "` SET `status` = 'ko', `last_mod` = '" . $stordate ."', `user_id` = NULL, `msg` = '" . maybe_serialize($error) . "' WHERE `status` = 'to confirm' AND `last_mod` < DATE_SUB('$stordate', INTERVAL $days DAY)");
  899. }
  900. // Clean the table
  901. $purge = (int)$purge_days;
  902. if ($purge > 0) {
  903. $query = "DELETE FROM `" . SABRE_TABLE . "` WHERE `last_mod` < DATE_SUB('$stordate', INTERVAL $purge DAY) AND `status` not in ('ok','to confirm')";
  904. $removed = $wpdb->query($query);
  905. }
  906. }
  907. /***********************************************************************/
  908. /* Get new spam blocked since last visit */
  909. /***********************************************************************/
  910. function get_new_spam () {
  911. global $wpdb;
  912. $sabre_opt = $this->get_option('sabre_opt');
  913. return $wpdb->get_var("SELECT COUNT(*) FROM `" . SABRE_TABLE . "` WHERE `status`= 'ko' AND `last_mod` > " . strftime("'%Y-%m-%d %H:%M:%S'", (int)$sabre_opt['last_spam_check']));
  914. }
  915. /***********************************************************************/
  916. /* Get new registrations accepted since last visit */
  917. /***********************************************************************/
  918. function get_new_users () {
  919. global $wpdb;
  920. $sabre_opt = $this->get_option('sabre_opt');
  921. return $wpdb->get_var("SELECT COUNT(*) FROM `" . SABRE_TABLE . "` WHERE `status`= 'ok' AND `last_mod` > " . strftime("'%Y-%m-%d %H:%M:%S'", (int)$sabre_opt['last_approved_check']));
  922. }
  923. /***********************************************************************/
  924. /* Get new registrations to confirm since last visit */
  925. /***********************************************************************/
  926. function get_new_confirm () {
  927. global $wpdb;
  928. $sabre_opt = $this->get_option('sabre_opt');
  929. return $wpdb->get_var("SELECT COUNT(*) FROM `" . SABRE_TABLE . "` WHERE `status`= 'to confirm' AND `last_mod` > " . strftime("'%Y-%m-%d %H:%M:%S'", (int)$sabre_opt['last_confirm_check']));
  930. }
  931. /***********************************************************************/
  932. /* Display the list of invitation codes in the option form */
  933. /***********************************************************************/
  934. function display_invite_codes () {
  935. $sabre_opt = $this->get_option('sabre_opt');
  936. $invite_codes = $sabre_opt['invite_codes'];
  937. If (!is_array($invite_codes))
  938. $invite_codes = array();
  939. for ($i=0; $i < count($invite_codes); $i++) {
  940. $invite_string .= '<li><input type="text" size="15" name="sabre_invite_code[]" id="sabre_invite_code_' . $i . '" value="' . $invite_codes[$i]['code'] . '" /><input type="text" size="6" name="sabre_invite_number[]" id="sabre_invite_number_' . $i .'" value="' . $invite_codes[$i]['number'] . '" /><input type="text" size="10" name="sabre_invite_date[]" id="sabre_invite_date_' . $i . '" value="' . (is_numeric($invite_codes[$i]['date']) ? date('Y-m-d', $invite_codes[$i]['date']) : '') . '" /><input type="submit" name="sabre_invite_action-gen-' . $i . '" value="'. __("Gen", 'sabre') . '" class="button" /><input type="submit" name="sabre_invite_action-del-' . $i . '" value="'. __("Del", 'sabre') . '" class="button" /></li>';
  941. }
  942. $invite_string .= '<li><input type="text" size="15" name="sabre_invite_code[]" id="sabre_invite_code_' . $i . '" value="" /><input type="text" size="6" name="sabre_invite_number[]" id="sabre_invite_number_' . $i .'" value="" /><input type="text" size="10" name="sabre_invite_date[]" id="sabre_invite_date_' . $i . '" value="" /><input type="submit" name="sabre_invite_action-gen-' . $i . '" value="'. __("Gen", 'sabre') . '" class="button" /></li>';
  943. return $invite_string;
  944. }
  945. /***********************************************************************/
  946. /* Check the list of invitation codes in the option form */
  947. /***********************************************************************/
  948. function check_invite_codes($gen, $del, $form_values) {
  949. if (

Large files files are truncated, but you can click here to view the full file