Ejemplo n.º 1
0
 /**
  * Get blocking information
  * @access private
  * @param bool $bFromSlave Specify whether to check slave or master. To improve performance,
  *  non-critical checks are done against slaves. Check when actually saving should be done against
  *  master.
  *
  * Note that even if $bFromSlave is false, the check is done first against slave, then master.
  * The logic is that if blocked on slave, we'll assume it's either blocked on master or
  * just slightly outta sync and soon corrected - safer to block slightly more that less.
  * And it's cheaper to check slave first, then master if needed, than master always.
  */
 function getBlockedStatus($bFromSlave = true)
 {
     global $wgIP, $wgBlockCache, $wgProxyList, $wgEnableSorbs, $wgProxyWhitelist;
     if (-1 != $this->mBlockedby) {
         return;
     }
     $this->mBlockedby = 0;
     # User blocking
     if ($this->mId) {
         $block = new Block();
         $block->forUpdate($bFromSlave);
         if ($block->load($wgIP, $this->mId)) {
             $this->mBlockedby = $block->mBy;
             $this->mBlockreason = $block->mReason;
             $this->spreadBlock();
         }
     }
     # IP/range blocking
     if (!$this->mBlockedby) {
         # Check first against slave, and optionally from master.
         $block = $wgBlockCache->get($wgIP, true);
         if (!$block && !$bFromSlave) {
             # Not blocked: check against master, to make sure.
             $wgBlockCache->clearLocal();
             $block = $wgBlockCache->get($wgIP, false);
         }
         if ($block !== false) {
             $this->mBlockedby = $block->mBy;
             $this->mBlockreason = $block->mReason;
         }
     }
     # Proxy blocking
     if (!$this->isSysop() && !in_array($wgIP, $wgProxyWhitelist)) {
         # Local list
         if (array_key_exists($wgIP, $wgProxyList)) {
             $this->mBlockedby = wfMsg('proxyblocker');
             $this->mBlockreason = wfMsg('proxyblockreason');
         }
         # DNSBL
         if (!$this->mBlockedby && $wgEnableSorbs && !$this->getID()) {
             if ($this->inSorbsBlacklist($wgIP)) {
                 $this->mBlockedby = wfMsg('sorbs');
                 $this->mBlockreason = wfMsg('sorbsreason');
             }
         }
     }
 }
Ejemplo n.º 2
0
 function enumBlocks($callback, $tag, $flags = 0)
 {
     global $wgAntiLockFlags;
     $block = new Block();
     if ($flags & EB_FOR_UPDATE) {
         $db =& wfGetDB(DB_MASTER);
         if ($wgAntiLockFlags & ALF_NO_BLOCK_LOCK) {
             $options = '';
         } else {
             $options = 'FOR UPDATE';
         }
         $block->forUpdate(true);
     } else {
         $db =& wfGetDB(DB_SLAVE);
         $options = '';
     }
     $ipblocks = $db->tableName('ipblocks');
     $sql = "SELECT * FROM {$ipblocks} ORDER BY ipb_timestamp DESC {$options}";
     $res = $db->query($sql, 'Block::enumBans');
     while ($row = $db->fetchObject($res)) {
         $block->initFromRow($row);
         if (!($flags & EB_KEEP_EXPIRED)) {
             if (!$block->deleteIfExpired()) {
                 $callback($block, $tag);
             }
         } else {
             $callback($block, $tag);
         }
     }
     wfFreeResult($res);
 }
Ejemplo n.º 3
0
 function enumBlocks($callback, $tag, $flags = 0)
 {
     global $wgAntiLockFlags;
     $block = new Block();
     if ($flags & Block::EB_FOR_UPDATE) {
         $db = wfGetDB(DB_MASTER);
         if ($wgAntiLockFlags & ALF_NO_BLOCK_LOCK) {
             $options = '';
         } else {
             $options = 'FOR UPDATE';
         }
         $block->forUpdate(true);
     } else {
         $db = wfGetDB(DB_SLAVE);
         $options = '';
     }
     if ($flags & Block::EB_RANGE_ONLY) {
         $cond = " AND ipb_range_start <> ''";
     } else {
         $cond = '';
     }
     $now = wfTimestampNow();
     list($ipblocks, $user) = $db->tableNamesN('ipblocks', 'user');
     $sql = "SELECT {$ipblocks}.*,user_name FROM {$ipblocks},{$user} " . "WHERE user_id=ipb_by {$cond} ORDER BY ipb_timestamp DESC {$options}";
     $res = $db->query($sql, 'Block::enumBlocks');
     $num_rows = $db->numRows($res);
     while ($row = $db->fetchObject($res)) {
         $block->initFromRow($row);
         if ($flags & Block::EB_RANGE_ONLY && $block->mRangeStart == '') {
             continue;
         }
         if (!($flags & Block::EB_KEEP_EXPIRED)) {
             if ($block->mExpiry && $now > $block->mExpiry) {
                 $block->delete();
             } else {
                 call_user_func($callback, $block, $tag);
             }
         } else {
             call_user_func($callback, $block, $tag);
         }
     }
     $db->freeResult($res);
     return $num_rows;
 }
Ejemplo n.º 4
0
 /**
  * Find out if a given IP address is blocked
  *
  * @param String $ip   IP address
  * @param bool $bFromSlave True means to load check against slave, else check against master.
  */
 function get($ip, $bFromSlave)
 {
     $this->load($bFromSlave);
     $ipint = ip2long($ip);
     $blocked = false;
     foreach ($this->mData as $networkBits => $blockInts) {
         if (array_key_exists($ipint >> 32 - $networkBits, $blockInts)) {
             $blocked = true;
             break;
         }
     }
     if ($blocked) {
         # Clear low order bits
         if ($networkBits != 32) {
             $ip .= '/' . $networkBits;
             $ip = Block::normaliseRange($ip);
         }
         $block = new Block();
         $block->forUpdate($bFromSlave);
         $block->load($ip);
     } else {
         $block = false;
     }
     return $block;
 }