Пример #1
0
 function loadBadnicks()
 {
     $res = db_query('select * from ns_badnicks order by badnick_id asc');
     while ($row = mysql_fetch_assoc($res)) {
         $badnick = new DB_BadNick($row);
         $badnick_key = strtolower($badnick->getMask());
         $this->db_badnicks[$badnick_key] = $badnick;
     }
     debugf('Loaded %d badnicks.', count($this->db_badnicks));
 }
Пример #2
0
 /**
  * isBlacklistedDns is a generic function to provide extensibility
  * for easily checking DNS based blacklists. It has three arguments:
  * 	host:    The IP address of the host you wish to check.
  * 	suffix:    The DNS suffix for the DNSBL service.
  *    pos_resp:  An array containing responses that should be considered
  * 	           a positive match. If not provided, will assume that ANY
  * 	           successful DNS resolution against the DNSBL should be
  * 	           considered a positive match.
  * 
  * For example:
  * 	isBlacklistedDns('1.2.3.4', 'dnsbl.com')
  * 		Returns true if 4.3.2.1.dnsbl.com returns any DNS resolution.
  * 	isBlacklistedDns('1.2.3.4', 'dnsbl.com', 2)
  * 		Returns true if 4.3.2.1.dnsbl.com contains '127.0.0.2' in its 
  * 		response.
  * 	isBlacklistedDns('1.2.3.4', 'dnsbl.com', array(2, 3))
  * 		Returns true if 4.3.2.1.dnsbl.com contains either 127.0.0.2 or 
  * 		127.0.0.3 in its response.
  */
 function isBlacklistedDns($host, $dns_suffix, $pos_responses = -1)
 {
     // Don't waste time checking private class IPs.
     if (isPrivateIp($host)) {
         return false;
     }
     $start_ts = microtime(true);
     /**
      * DNS blacklists work by storing records for ipaddr.dnsbl.com,
      * but with DNS all octets are reversed. So to check if 1.2.3.4
      * is blacklisted in a DNSBL, we need to query for the hostname
      * 4.3.2.1.dnsbl.com.
      */
     $octets = explode('.', $host);
     $reverse_octets = implode('.', array_reverse($octets));
     $lookup_addr = $reverse_octets . '.' . $dns_suffix . '.';
     debugf('DNSBL checking %s', $lookup_addr);
     $dns_result = @dns_get_record($lookup_addr, DNS_A);
     if (count($dns_result) > 0) {
         $dns_result = $dns_result[0]['ip'];
         $resolved = true;
     } else {
         $dns_result = $lookup_addr;
         $resolved = false;
     }
     $end_ts = microtime(true);
     debugf('DNSBL check time elapsed: %0.4f seconds (%s = %s)', $end_ts - $start_ts, $lookup_addr, $dns_result);
     // If it didn't resolve, don't check anything
     if (!$resolved) {
         return false;
     }
     // Check for any successful resolution
     if ($resolved && $pos_responses == -1 || empty($pos_responses)) {
         return true;
     }
     // Check for a match against the provided string
     if (is_string($pos_responses) && !empty($pos_responses) && $dns_result == '127.0.0.' . $pos_responses) {
         return true;
     }
     // Check for a match within the provided array
     if (is_array($pos_responses)) {
         foreach ($pos_responses as $tmp_match) {
             $tmp_match = '127.0.0.' . $tmp_match;
             if ($tmp_match == $dns_result) {
                 return true;
             }
         }
     }
     // All checks failed; host tested negative.
     return false;
 }
Пример #3
0
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. Neither the name of ircPlanet nor the names of its contributors may be
 *    used to endorse or promote products derived from this software without 
 *    specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/**
 * Check for expired mutes
 */
$expiredMutes = array();
foreach ($this->mutes as $muteKey => $mute) {
    if ($mute->hasExceededLifetime()) {
        debugf('*** Removing expired mute %s', $mute->getMask());
        $expiredMutes[] = $muteKey;
    }
}
foreach ($expiredMutes as $muteKey) {
    $this->removeMute($muteKey);
}
Пример #4
0
 function notifyServices($type, $request, $primary_id, $secondary_id = 0)
 {
     $text = '|IPSVC|' . $type . '|' . $request . '|' . $primary_id . '|';
     if ($type == NOTIFY_CHANNEL_ACCESS && $secondary_id > 0) {
         $text .= $secondary_id . '|';
     } elseif ($type == NOTIFY_CHANNEL_ACCESS) {
         return false;
     }
     debugf('Notify text: %s', $text);
     foreach ($this->users as $numeric => $user) {
         if (!$user->isService()) {
             debugf('%s is not a service, skipping (%s)', $user->getNick(), $user->getModes());
             continue;
         }
         debugf('%s *IS* a service, sending notice (%s)', $user->getNick(), $user->getModes());
         $this->default_bot->notice($user, $text);
     }
 }
Пример #5
0
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
$active = $args[3][0] == '+';
$mask = substr($args[3], 1);
$duration = $args[4];
$lastmod = $num_args >= 7 ? $args[5] : 0;
$lifetime = $num_args >= 8 ? $args[6] : 0;
$reason = $args[$num_args - 1];
$mute = $this->getMute($mask);
if ($mute && $lastmod > $mute->getLastMod()) {
    if ($active) {
        debugf('*** Re-activating Mute %s', $mute->getMask());
        $mute->setActive();
    } else {
        debugf('*** De-activating Mute %s', $mute->getMask());
        $mute->setInactive();
    }
    $mute->setDuration($duration);
    $mute->setLastMod($lastmod);
    $mute->setLifetime($lifetime);
    $mute->setReason($reason);
    if (method_exists($this, 'serviceChangeMute')) {
        $this->serviceChangeMute($mute);
    }
} elseif (!$mute) {
    $mute = $this->addMute($mask, $duration, time(), $lastmod, $lifetime, $reason, $active);
}
Пример #6
0
 function loadBadchans()
 {
     $res = db_query('select * from cs_badchans order by badchan_id asc');
     while ($row = mysql_fetch_assoc($res)) {
         $badchan = new DB_BadChan($row);
         $badchan_key = strtolower($badchan->getMask());
         $this->db_badchans[$badchan_key] = $badchan;
     }
     debugf('Loaded %d badchans.', count($this->db_badchans));
 }
Пример #7
0
    switch ($modes[$i]) {
        case 'o':
            $chan->clearOps();
            break;
        case 'v':
            $chan->clearVoices();
            break;
        case 'b':
            $chan->clearBans();
            break;
        case 'p':
        case 's':
        case 'm':
        case 't':
        case 'i':
        case 'n':
        case 'k':
            // the Channel class takes care of clearing the key
        // the Channel class takes care of clearing the key
        case 'l':
            // the Channel class takes care of setting the limit to 0
        // the Channel class takes care of setting the limit to 0
        case 'r':
        case 'D':
            $chan->removeMode($modes[$i]);
            break;
        default:
            debugf('Received unknown or disallowed mode change in CLEARMODE for %s', $chan->getName());
            break;
    }
}
Пример #8
0
    }
} elseif (preg_match($access_pattern, $cmd_msg)) {
    $nargs = explode('|', $cmd_msg);
    $cmd = $nargs[3];
    $channel_id = $nargs[4];
    $account_id = $nargs[5];
    $reload = $cmd == 'R';
    $delete = $cmd == 'D';
    debugf('Received channel access %s command from %s, channel %d, account %d', $cmd, $user->getNick(), $channel_id, $account_id);
    $channel = $this->getChannelRegById($channel_id);
    if (!$channel) {
        debugf('Cannot locate channel ID %d!', $channel_id);
        return false;
    }
    $access = $channel->getLevelById($account_id);
    if (!$access) {
        debugf('Cannot locate channel %s access record for account %d!', $channel->getName(), $account_id);
        return false;
    }
    if ($reload) {
        $access->refresh();
        if ($access->getUserId() == $account_id) {
            debugf('Successfully refreshed access on %s for %s', $channel->getName(), $account->getName());
        } else {
            debugf('Something is wrong... account ID was %d, now is %d?', $account_id, $access->getUserId());
        }
    } elseif ($delete) {
        $channel->removeAccess($account_id);
        debugf('Successfully removed access on %s from %s', $channel->getName(), $account->getName());
    }
}
Пример #9
0
 * POSSIBILITY OF SUCH DAMAGE.
 */
$uplink = SERVER_NUM;
$name = $args[1];
$start_ts = $args[4];
$numeric = substr($args[6], 0, BASE64_SERVLEN);
$max_users = irc_base64ToInt(substr($args[6], BASE64_SERVLEN));
$desc = $args[$num_args - 1];
$modes = '';
if ($args[$num_args - 2][0] == '+') {
    $modes = $args[$num_args - 2];
}
$server = $this->addServer($uplink, $numeric, $name, $desc, $start_ts, $max_users, $modes);
if (function_exists('setproctitle')) {
    global $argv;
    $procTitle = sprintf('%s: %s@%s (connected to %s)', implode(' ', $argv), BOT_NICK, SERVER_NAME, $server->getName());
    debugf('Setting process title to [%s]', $procTitle);
    setproctitle($procTitle);
}
if (!defined('UPLINK_NUM')) {
    define('UPLINK_NUM', $numeric);
} else {
    debug("*** FATAL ERROR :: Received a second uplink... I'm confused!");
    exit;
}
$this->servicePreburst();
$this->burstGlines();
$this->burstServers();
$this->burstUsers();
$this->burstChannels();
$this->sendf(FMT_ENDOFBURST, SERVER_NUM);
Пример #10
0
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
$active = $args[3][0] == '+';
$server = substr($args[3], 1);
$duration = $args[4];
$lastmod = $num_args >= 7 ? $args[5] : 0;
$lifetime = $num_args >= 8 ? $args[6] : 0;
$reason = $args[$num_args - 1];
$jupe = $this->getJupe($server);
if ($jupe && $lastmod > $jupe->getLastMod()) {
    if ($active) {
        debugf('*** Re-activating jupe %s', $jupe->getServer());
        $gline->setActive();
    } else {
        debugf('*** De-activating jupe %s', $jupe->getServer());
        $gline->setInactive();
    }
    $jupe->setDuration($duration);
    $jupe->setLastMod($lastmod);
    $jupe->setReason($reason);
    if (method_exists($this, 'serviceChangeJupe')) {
        $this->serviceChangeJupe($jupe);
    }
} else {
    $jupe = $this->addJupe($server, $duration, time(), $lastmod, $reason, $active);
}
Пример #11
0
 *    this list of conditions and the following disclaimer in the documentation
 *    and/or other materials provided with the distribution.
 * 3. Neither the name of ircPlanet nor the names of its contributors may be
 *    used to endorse or promote products derived from this software without 
 *    specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
/**
 * Check for expired glines
 */
$expired_glines = array();
foreach ($this->glines as $gline_key => $gline) {
    if ($gline->hasExceededLifetime()) {
        debugf('*** Removing expired G-line %s', $gline->getMask());
        $expired_glines[] = $gline_key;
    }
}
foreach ($expired_glines as $gline_key) {
    $this->removeGline($gline_key);
}
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
if (!defined('MAX_CHAN_AGE') || MAX_CHAN_AGE == 0) {
    return;
}
foreach ($this->db_channels as $chan_key => $reg) {
    if ($reg->isPermanent()) {
        continue;
    }
    $youngest_ts = 0;
    foreach ($reg->getLevels() as $user_id => $level) {
        $user = $this->getAccountById($user_id);
        if (!$user) {
            debugf('Found an orphaned access record for user ID %d in %s, deleting', $user_id, $reg->getName(), $reg->removeAccess($user_id));
            $level->delete();
            continue;
        }
        if ($level->getLevel() == 500 && $youngest_ts < $user->getLastseenTs()) {
            $youngest_ts = $user->getLastseenTs();
        }
    }
    if ($youngest_ts == 0) {
        continue;
    }
    $age_days = (time() - $youngest_ts) / 86400;
    if ($age_days > MAX_CHAN_AGE) {
        debug("Channel " . $reg->getName() . " age is {$age_days} days");
        $this->removeChannelReg($reg);
        $reg->delete();
Пример #13
0
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
$active = $args[3][0] == '+';
$mask = substr($args[3], 1);
$duration = $args[4];
$lastmod = $num_args >= 7 ? $args[5] : 0;
$lifetime = $num_args >= 8 ? $args[6] : 0;
$reason = $args[$num_args - 1];
$gline = $this->getGline($mask);
if ($gline && $lastmod > $gline->getLastMod()) {
    if ($active) {
        debugf('*** Re-activating G-line %s', $gline->getMask());
        $gline->setActive();
    } else {
        debugf('*** De-activating G-line %s', $gline->getMask());
        $gline->setInactive();
    }
    $gline->setDuration($duration);
    $gline->setLastMod($lastmod);
    $gline->setLifetime($lifetime);
    $gline->setReason($reason);
    if (method_exists($this, 'serviceChangeGline')) {
        $this->serviceChangeGline($gline);
    }
} elseif (!$gline) {
    $gline = $this->addGline($mask, $duration, time(), $lastmod, $lifetime, $reason, $active);
}