Changeset 2450387
- Timestamp:
- 01/05/2021 07:25:24 AM (5 years ago)
- Location:
- vigilantor/trunk
- Files:
-
- 3 edited
-
templates/admin.phtml (modified) (3 diffs)
-
templates/flagged_users.phtml (modified) (1 diff)
-
vigilantor.php (modified) (42 diffs)
Legend:
- Unmodified
- Added
- Removed
-
vigilantor/trunk/templates/admin.phtml
r2303090 r2450387 206 206 <?php _e('Exit list update frequency:', 'vigilantor') ?> 207 207 <select name="vitor_el_update_frequency"> 208 <?php foreach($this-> _updateFrequencies as $name => $freq): ?>208 <?php foreach($this->updateFrequencies as $name => $freq): ?> 209 209 <option value="<?php echo $name ?>"<?php if ($name == get_option('vitor_el_update_frequency', '_10m')): ?> selected="selected"<?php endif; ?>><?php echo $freq['display'] ?></option> 210 210 <?php endforeach; ?> … … 218 218 <br> 219 219 <em> 220 <?php if ($this-> _hasUdpSupport()): ?>220 <?php if ($this->hasUdpSupport()): ?> 221 221 <?php printf(__('You can use the real-time checks as %s streams are enabled.'), '<code>udp://</code>'); ?> 222 222 <?php else: ?> … … 289 289 toggleShowBlockedMessage(); 290 290 291 <?php if (!$this-> _hasUdpSupport()): ?>291 <?php if (!$this->hasUdpSupport()): ?> 292 292 jQuery('#vitor_enable_realtime').prop('disabled', true); 293 293 jQuery('#vitor_realtime_timeout').prop('disabled', true); -
vigilantor/trunk/templates/flagged_users.phtml
r1700970 r2450387 1 1 <h3>Flagged Registrations</h3> 2 2 3 <?php $users = $this-> _getFlaggedRegistrations(); ?>3 <?php $users = $this->getFlaggedRegistrations(); ?> 4 4 5 5 <div id="vitor_no_flagged_registrations"<?php if (sizeof($users) > 0) echo ' style="display: none"'; ?>> -
vigilantor/trunk/vigilantor.php
r2450376 r2450387 45 45 class VigilanTorWP 46 46 { 47 private $ _wpdb;48 private $ _menuSlug = 'vigilantor';49 private $ _updateFrequencies;50 private $ _exitList;51 private $ _customBlockList;52 private $ _realtimeEnabled = false;53 private $ _useCustomBlockList = false;54 private $ _blockedByCustomList = false;55 private $ _cloudflareEnabled = false;56 private static $ _instance = null;47 private $wpdb; 48 private $menuSlug = 'vigilantor'; 49 private $updateFrequencies; 50 private $exitList; 51 private $customBlockList; 52 private $realtimeEnabled = false; 53 private $useCustomBlockList = false; 54 private $blockedByCustomList = false; 55 private $cloudflareEnabled = false; 56 private static $instance = null; 57 57 58 58 // These lists contain all addresses from the Tor bulk exit list in addition to IPv6 exit addresses and exit nodes … … 67 67 global $wpdb; 68 68 69 $this-> _wpdb = $wpdb;70 71 $this-> _updateFrequencies = array(69 $this->wpdb = $wpdb; 70 71 $this->updateFrequencies = array( 72 72 '_10m' => array('interval' => 600, 'display' => __('Every 10 minutes')), 73 73 '_20m' => array('interval' => 1200, 'display' => __('Every 20 minutes')), … … 83 83 add_action ('wp_ajax_vitor_clear_flag', array(&$this, 'clearFlagAction')); 84 84 add_filter ('widget_text', 'do_shortcode'); 85 add_filter ('cron_schedules', array(&$this, ' _addSchedules'));85 add_filter ('cron_schedules', array(&$this, 'addSchedules')); 86 86 add_shortcode('tor_users', array(&$this, 'doTorUserShortcode')); 87 87 add_shortcode('non_tor_users', array(&$this, 'doNonTorUserShortcode')); … … 89 89 90 90 if (true == get_option('vitor_enable_realtime', 0)) { 91 $this-> _realtimeEnabled = true;91 $this->realtimeEnabled = true; 92 92 } 93 93 94 94 if (true == get_option('vitor_custom_blocklist_enabled', 0)) { 95 $this-> _useCustomBlockList= true;95 $this->useCustomBlockList= true; 96 96 } 97 97 … … 111 111 add_action('bp_signup_validate', array(&$this, 'processBPRegistrationAction'), 0); 112 112 } 113 } else if (true == get_option('vitor_flag_registration', 0)) {113 } elseif (true == get_option('vitor_flag_registration', 0)) { 114 114 global $wp_version; 115 115 … … 131 131 132 132 if (true == get_option('vitor_cloudflare_enabled', 0)) { 133 $this->_cloudflareEnabled = true; 134 } 135 } 136 137 public function wpAuthCallback(&$username, &$password) { 138 // get instance (PHP 5.3). PHP 5.4+ could reference $this here 139 $vt = VigilanTorWP::run(); 140 if ($vt->isTorUser()) { 141 $vt->_blockLogin = true; 133 $this->cloudflareEnabled = true; 134 } 135 } 136 137 public function wpAuthCallback(&$username, &$password) 138 { 139 if ($this->isTorUser()) { 140 $this->blockLogin = true; 142 141 $username = $password = null; 143 142 } … … 146 145 public static function run() 147 146 { 148 if (self::$ _instance) {149 return self::$ _instance;147 if (self::$instance) { 148 return self::$instance; 150 149 } else { 151 self::$ _instance = new self();152 return self::$ _instance;150 self::$instance = new self(); 151 return self::$instance; 153 152 } 154 153 } … … 166 165 $updated = 0; 167 166 // only update if the list is older than the update interval 168 if (time() - $lastUpdate > $this-> _updateFrequencies[$frequency]['interval']) {167 if (time() - $lastUpdate > $this->updateFrequencies[$frequency]['interval']) { 169 168 $this->updateExitList(); 170 169 $updated = 1; … … 188 187 189 188 if (!empty($captchaType)) { 190 if ($this-> _checkCookie() === true) {189 if ($this->checkCookie() === true) { 191 190 return ; 192 191 } 193 192 194 $captcha = $this-> _getCaptchaHtml($captchaType);193 $captcha = $this->getCaptchaHtml($captchaType); 195 194 } 196 195 … … 200 199 201 200 if ($block_page_id == 0 || !($post = get_post($block_page_id))) { 202 if ($this-> _blockedByCustomList) {201 if ($this->blockedByCustomList) { 203 202 $message = get_option('vitor_custom_block_message', null); 204 203 if (empty($message)) { … … 356 355 global $bp; 357 356 358 $error = '';359 357 if ($this->isTorUser()) { 360 358 update_site_option('vitor_stat_registration', (int)get_site_option('vitor_stat_registration') + 1); 361 359 $error = __('Sorry, you are not allowed to register for this site while using Tor!', 'vigilantor'); 362 360 $bp->signup->errors['vitor'] = $error; // have to set some error otherwise registration is allowed 363 $GLOBALS[' _vitor_bp_registration_error'] = $error;361 $GLOBALS['vitor_bp_registration_error'] = $error; 364 362 add_action('bp_before_account_details_fields', array(&$this, 'bpOutputRegistrationError')); 365 363 return false; … … 369 367 } 370 368 371 public function bpOutputRegistrationError() { 372 global $_vitor_bp_registration_error; 373 374 echo "<div><div class='error'>{$_vitor_bp_registration_error}</div></div>"; 369 public function bpOutputRegistrationError() 370 { 371 global $vitor_bp_registration_error; 372 373 echo "<div><div class='error'>{$vitor_bp_registration_error}</div></div>"; 375 374 } 376 375 … … 391 390 public function processLoginAction($user, $username, $password) 392 391 { 393 if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($this-> _blockLogin) && $this->_blockLogin === true) {392 if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($this->blockLogin) && $this->blockLogin === true) { 394 393 update_site_option('vitor_stat_login', (int)get_site_option('vitor_stat_login') + 1); 395 394 $error = new WP_Error(); … … 426 425 $frequency = get_option('vitor_el_update_frequency', '_10m'); 427 426 428 if (time() - $lastUpdate > $this-> _updateFrequencies[$frequency]['interval']) {427 if (time() - $lastUpdate > $this->updateFrequencies[$frequency]['interval']) { 429 428 // workaround for sites where wp-cron isn't working for one reason or another 430 429 if (!$called) { … … 442 441 $ip = $this->getClientIpAddress(); 443 442 444 if ($this-> _realtimeEnabled) {443 if ($this->realtimeEnabled) { 445 444 if ($this->doRealTimeLookup($ip) === true) { 446 445 return true; … … 452 451 } 453 452 454 if ($this-> _useCustomBlockList) {453 if ($this->useCustomBlockList) { 455 454 if ($this->findInCustomBlocklist($ip)) { 456 $this-> _blockedByCustomList = true;455 $this->blockedByCustomList = true; 457 456 return true; 458 457 } … … 499 498 } 500 499 501 $hook = add_options_page('Tor Blocking Settings', 'VigilanTor Settings', 'manage_options', $this-> _menuSlug, array(&$this, 'adminPage'));500 $hook = add_options_page('Tor Blocking Settings', 'VigilanTor Settings', 'manage_options', $this->menuSlug, array(&$this, 'adminPage')); 502 501 add_action('admin_init', array(&$this, 'registerSettings')); 503 502 add_action('load-' . $hook, array(&$this, 'addHelpMenu')); … … 590 589 591 590 if (isset($_GET['settings-updated']) && $_GET['settings-updated'] == 'true') { 592 $this-> _scheduleUpdate();591 $this->scheduleUpdate(); 593 592 } 594 593 … … 650 649 public function getPluginSettingsUrl() 651 650 { 652 return network_admin_url() . 'options-general.php?page=' . $this-> _menuSlug;651 return network_admin_url() . 'options-general.php?page=' . $this->menuSlug; 653 652 } 654 653 … … 663 662 { 664 663 $instance = self::run(); 665 $instance-> _install();664 $instance->doInstall(); 666 665 } 667 666 … … 672 671 } 673 672 674 public function _scheduleUpdate()673 public function scheduleUpdate() 675 674 { 676 675 wp_clear_scheduled_hook('vitor_update_lists'); … … 680 679 } 681 680 682 private function _install()683 { 684 $this-> _scheduleUpdate();681 private function doInstall() 682 { 683 $this->scheduleUpdate(); 685 684 $this->updateExitList(); 686 685 } … … 696 695 $message = __('No user ID given', 'vigilantor'); 697 696 } else { 698 $deleted = $this-> _wpdb->delete(699 $this-> _wpdb->base_prefix . 'usermeta',697 $deleted = $this->wpdb->delete( 698 $this->wpdb->base_prefix . 'usermeta', 700 699 array('user_id' => $user_id, 'meta_key' => 'vitor_flagged_registration'), 701 700 array('%d', '%s') … … 718 717 } 719 718 720 public function _addSchedules($schedules)721 { 722 $temp = $this-> _updateFrequencies;719 public function addSchedules($schedules) 720 { 721 $temp = $this->updateFrequencies; 723 722 unset($temp['_60m']); 724 723 … … 728 727 private function findInExitList($ip_address) 729 728 { 730 return false !== $this-> _arrayBinarySearch($ip_address, $this->getExitList());729 return false !== $this->arrayBinarySearch($ip_address, $this->getExitList()); 731 730 } 732 731 … … 803 802 set_site_transient('vitor_list_updating', '1', 30); 804 803 805 $list = $this-> _downloadExitList();804 $list = $this->downloadExitList(); 806 805 if (!$list) return false; 807 806 … … 834 833 public function getExitList() 835 834 { 836 if ($this-> _exitList !== null) {837 return $this-> _exitList;835 if ($this->exitList !== null) { 836 return $this->exitList; 838 837 } 839 838 … … 841 840 842 841 if ($list === false) { 843 if ($this-> _downloadExitList()) {842 if ($this->downloadExitList()) { 844 843 $list = get_option('vitor_exit_list'); 845 844 } … … 847 846 848 847 if (is_array($list) && sizeof($list) > 0) { 849 $this-> _exitList = $list;848 $this->exitList = $list; 850 849 } 851 850 … … 855 854 public function getCustomBlocklist() 856 855 { 857 if ($this-> _customBlockList !== null) {858 return $this-> _customBlockList;856 if ($this->customBlockList !== null) { 857 return $this->customBlockList; 859 858 } 860 859 … … 884 883 } 885 884 886 private function _downloadExitList()885 private function downloadExitList() 887 886 { 888 887 $use_ssl = false; … … 893 892 $use_ssl = true; 894 893 } 895 } else if (in_array('https', stream_get_wrappers())) {894 } elseif (in_array('https', stream_get_wrappers())) { 896 895 $use_ssl = true; 897 896 } … … 933 932 $ipAddress = $_SERVER['REMOTE_ADDR']; 934 933 935 if ($this-> _cloudflareEnabled) {934 if ($this->cloudflareEnabled) { 936 935 // NB: If the cloudflare setting is enabled and the site is not using cloudflare, this header cannot be trusted. 937 936 if (!empty($_SERVER['HTTP_CF_REQUEST_ID']) && !empty($_SERVER['HTTP_CF_CONNECTING_IP'])) { … … 945 944 } 946 945 947 private function _getFlaggedRegistrations()946 private function getFlaggedRegistrations() 948 947 { 949 948 $query = "SELECT t1.user_id, t1.meta_value AS tor_ip, t2.user_login, t2.user_email, t2.user_registered " … … 951 950 ."WHERE meta_key = 'vitor_flagged_registration'"; 952 951 953 $t1 = $this-> _wpdb->base_prefix . 'usermeta';954 $t2 = $this-> _wpdb->base_prefix . 'users';955 $users = $this-> _wpdb->get_results(sprintf($query, $t1, $t2));952 $t1 = $this->wpdb->base_prefix . 'usermeta'; 953 $t2 = $this->wpdb->base_prefix . 'users'; 954 $users = $this->wpdb->get_results(sprintf($query, $t1, $t2)); 956 955 957 956 return $users; … … 964 963 * @return bool true if the cookie is valid, false if not or not set 965 964 */ 966 private function _checkCookie()965 private function checkCookie() 967 966 { 968 967 if (isset($_COOKIE['_vitor_access_token']) && … … 979 978 $t = get_site_transient('vitor_token:' . $token_id); 980 979 if ($t === $value) { 981 $this-> _setVitorCookie($token_id); // update cookie with new value (prevents sharing cookies)980 $this->setVitorCookie($token_id); // update cookie with new value (prevents sharing cookies) 982 981 return true; 983 982 } … … 1049 1048 } 1050 1049 1051 private function _getCaptchaHtml($captchaType)1050 private function getCaptchaHtml($captchaType) 1052 1051 { 1053 1052 $captcha_error = ''; … … 1087 1086 1088 1087 if ($valid) { 1089 $this-> _setVitorCookie();1088 $this->setVitorCookie(); 1090 1089 $_SERVER['REQUEST_METHOD'] = 'GET'; 1091 1090 wp_redirect($_SERVER['REQUEST_URI']); … … 1104 1103 } 1105 1104 1106 private function _setVitorCookie()1105 private function setVitorCookie() 1107 1106 { 1108 1107 $token_id = sha1(sha1(wp_generate_password(mt_rand(64, 128), true, true)) . sha1(wp_generate_password(mt_rand(128, 256), true, true))); … … 1132 1131 * @return boolean|number false if not found, or index if found 1133 1132 */ 1134 pr ivate function _arrayBinarySearch($needle, $haystack)1133 protected function arrayBinarySearch($needle, $haystack) 1135 1134 { 1136 1135 $high = count($haystack); … … 1153 1152 } 1154 1153 1155 private function _hasUdpSupport()1154 private function hasUdpSupport() 1156 1155 { 1157 1156 return in_array('udp', stream_get_transports());
Note: See TracChangeset
for help on using the changeset viewer.