예제 #1
0
 public static function global_notice($nick, $mask, $message)
 {
     core::alog('global_notice(): sent from ' . $nick, 'BASIC');
     // debug info
     foreach (core::$nicks as $user => $data) {
         $hostname = core::get_full_hostname($user);
         // hostname
         if ($data['server'] != core::$config->server->name && services::match($hostname, $mask)) {
             services::communicate($nick, $user, $message);
         }
     }
 }
예제 #2
0
 public static function check_levels($nick, $chan, $flags, $force = true, $ident = true, $return = false, $or_check = true)
 {
     if ($ident && !($user = services::user_exists($nick, true, array('id', 'display')))) {
         return false;
     }
     // they aint even identified..
     $user_flags_q = database::select('chans_levels', array('id', 'channel', 'target', 'flags', 'reason'), array('channel', '=', $chan));
     // get our flags records
     $hostname = core::get_full_hostname($nick);
     // generate a hostname
     while ($chan_flags = database::fetch($user_flags_q)) {
         if ($or_check && core::$nicks[$nick]['override']) {
             return true;
         }
         // is override enabled for this user?
         if ($nick == $chan_flags->target || $force && (strpos($chan_flags->target, '@') !== false && services::match($hostname, $chan_flags->target))) {
             foreach ($flags as $flag) {
                 if (strpos($chan_flags->flags, $flag) !== false) {
                     if ($return) {
                         return $chan_flags->reason;
                     } else {
                         return true;
                     }
                 }
                 // hurrah, we've found a match!
             }
             // loop through the flags, if we find a match, return true
             continue;
         }
         // only trigger if this is the user we are in question of.
     }
     // loop through the flag records
     return false;
 }
예제 #3
0
 public static function identify_command($nick, $ircdata = array())
 {
     $password = $ircdata[0];
     if (trim($password) == '') {
         services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_SYNTAX_RE, array('help' => 'IDENTIFY'));
         return false;
     }
     // wrong syntax damit!
     if ($user = services::user_exists($nick, false, array('display', 'pass', 'identified', 'validated', 'salt', 'vhost'))) {
         if ($user->validated == 0) {
             services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_AWAITING_VALIDATION);
             return false;
         } elseif ($user->identified == 1) {
             services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_ALREADY_IDENTIFIED);
             return false;
         } else {
             if ($user->pass == sha1($password . $user->salt)) {
                 timer::remove(array('ns_identify', 'secured_callback', array($nick)));
                 // remove the secured timer. if there is one
                 ircd::on_user_login($nick);
                 // registered mode
                 database::update('users', array('identified' => 1, 'last_hostmask' => core::get_full_hostname($nick), 'last_timestamp' => 0), array('display', '=', $nick));
                 services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_IDENTIFIED);
                 // right, standard identify crap
                 core::alog(core::$config->nickserv->nick . ': ' . core::get_full_hostname($nick) . ' identified for nick ' . core::$nicks[$nick]['nick']);
                 // logchan
                 if ($user->vhost != '' && isset(modules::$list['os_vhost'])) {
                     if (substr_count($user->vhost, '@') == 1) {
                         $new_host = explode('@', $user->vhost);
                         $ident = $new_host[0];
                         $host = $new_host[1];
                         ircd::setident(core::$config->operserv->nick, $user->display, $ident);
                         ircd::sethost(core::$config->operserv->nick, $user->display, $host);
                     } else {
                         ircd::sethost(core::$config->operserv->nick, $user->display, $user->vhost);
                     }
                 }
                 // first thing we do, check if they have a vhost, if they do, apply it.
                 $failed_attempts = database::select('failed_attempts', array('nick', 'mask', 'time'), array('nick', '=', $nick));
                 if (database::num_rows($failed_attempts) > 0) {
                     services::communicate(core::$config->nickserv->nick, $nick, '' . database::num_rows($failed_attempts) . ' failed login(s) since last login.');
                     while ($row = database::fetch($failed_attempts)) {
                         services::communicate(core::$config->nickserv->nick, $nick, 'Failed login from: ' . $row->mask . ' on ' . date("F j, Y, g:i a", $row->time) . '');
                     }
                     // loop through the failed attempts messaging them to the user
                     database::delete('failed_attempts', array('nick', '=', $nick));
                     // clear them now that they've been seen
                 }
                 // we got any failed attempts? HUMM
                 $hostname = core::get_full_hostname($nick);
                 // generate a hostname.
                 if (core::$config->settings->mode_on_id == 'yes' && isset(modules::$list['cs_levels'])) {
                     foreach (core::$chans as $chan => $cdata) {
                         $access_array = cs_levels::get_access($chan);
                         // get the access array
                         if ($nick == core::$config->chanserv->nick) {
                             continue;
                         }
                         // skip us :D
                         $hostname = core::get_full_hostname($nick);
                         // get the hostname ready.
                         foreach ($access_array as $target => $access) {
                             if ($target == $nick) {
                                 $remove_access = false;
                                 // don't remove access
                                 cs_levels::give_access($chan, $nick, $access, chanserv::check_flags($chan, array('S')));
                                 // give them access
                                 continue 2;
                                 // continue to next loop cause we've found a match
                             } elseif (strpos($target, '@') !== false && services::match($hostname, $target)) {
                                 $remove_access = false;
                                 // don't remove access
                                 cs_levels::give_access($chan, $nick, $access, chanserv::check_flags($chan, array('S')));
                                 // give them access
                                 continue 2;
                                 // continue to next loop cause we've found a match
                             } elseif (strpos(core::$chans[$chan]['users'][$nick], 'o') !== false) {
                                 $remove_access = true;
                                 // set remove access to true
                                 continue 1;
                                 // continue to next loop to check other access records
                             } else {
                                 continue 1;
                                 // continue to next loop to check other access records
                             }
                             // we check if the user has access, if they do break;
                             // we also check if they dont have access and have op, if they do remove it.
                         }
                         // loop through the access records
                     }
                     // loop through channels, check if they are in any
                 }
                 // check if mode_on_id is set, also cs_access is enabled, and lets do a remote access gain :D
             } else {
                 services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_PASSWORD);
                 core::alog(core::$config->nickserv->nick . ': Invalid password from ' . core::get_full_hostname($nick));
                 // some logging stuff
                 database::insert('failed_attempts', array('nick' => $nick, 'mask' => core::get_full_hostname($nick), 'time' => core::$network_time));
                 core::$nicks[$nick]['failed_attempts']++;
                 // ooh, we have something to log :)
                 if (core::$nicks[$nick]['failed_attempts'] == 5) {
                     ircd::kill(core::$config->nickserv->nick, $nick, 'Maxmium FAILED login attempts reached.');
                 }
                 // have they reached the failed attempts limit? we gonna f*****g KILL mwhaha
             }
             // invalid password? HAX!!
         }
         // are they already identifed?
     } else {
         services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_UNREGISTERED);
         return false;
         // doesn't even exist..
     }
     // right now we need to check if the user exists, and password matches
 }
예제 #4
0
 public static function on_create($nusers, $channel)
 {
     $access_array = self::get_access($channel->channel);
     // get the access array
     foreach ($nusers as $nick => $modes) {
         if ($nick == core::$config->chanserv->nick) {
             continue;
         }
         // skip us :D
         $hostname = core::get_full_hostname($nick);
         // get the hostname ready.
         if ($reason = chanserv::check_levels($nick, $channel->channel, array('b'), true, false, true)) {
             ircd::mode(core::$config->chanserv->nick, $channel->channel, '+b *@' . core::$nicks[$nick]['host']);
             ircd::kick(core::$config->chanserv->nick, $nick, $channel->channel, $reason);
         }
         // check for bans before access
         foreach ($access_array as $target => $access) {
             if ($target == $nick) {
                 $remove_access = false;
                 // don't remove access
                 self::give_access($channel->channel, $nick, $access, chanserv::check_flags($chan, array('S')));
                 // give them access
                 continue 2;
                 // continue to next loop cause we've found a match
             } elseif (strpos($target, '@') !== false && services::match($hostname, $target)) {
                 $remove_access = false;
                 // don't remove access
                 self::give_access($channel->channel, $nick, $access, chanserv::check_flags($chan, array('S')));
                 // give them access
                 continue 2;
                 // continue to next loop cause we've found a match
             } elseif (strpos(core::$chans[$channel->channel]['users'][$nick], 'o') !== false) {
                 $remove_access = true;
                 // set remove access to true
                 continue 1;
                 // continue to next loop to check other access records
             } elseif (strpos(core::$chans[$channel->channel]['users'][$nick], 'h') !== false) {
                 $remove_access = true;
                 // set remove access to true
                 continue 1;
                 // continue to next loop to check other access records
             } else {
                 continue 1;
                 // continue to next loop to check other access records
             }
             // we check if the user has access, if they do break;
             // we also check if they dont have access and have op, if they do remove it.
         }
         // loop through the access records
         if ($remove_access) {
             ircd::mode(core::$config->chanserv->nick, $channel->channel, '-oh ' . $nick . ' ' . $nick);
         }
         // easy fix to stop stuff like this below happening.
         // [20:27:19] * ChanServ sets mode: -o N0valyfe
         // [20:27:19] * ChanServ sets mode: +o N0valyfe
     }
     // loop through the users
 }
예제 #5
0
 public static function type_check($chan, $level, $mode, $cnick)
 {
     $part = explode(':', $level);
     $nicks = array();
     if ($part[1] == '') {
         return false;
     }
     // we need to make sure we're actually given something.
     if ($mode[0] != '+' && $mode[0] != '-') {
         return false;
     }
     // make sure we're getting +/-
     if (strpos('qaohv', $mode[1]) === false) {
         return false;
     }
     // we can only set on these modes, for now.
     if (count(core::$chans[$chan]['users']) == 0) {
         return false;
     }
     // is the channel empty?
     if ($part[0] == 'level') {
         if ($part[1] == '0') {
             foreach (core::$chans[$chan]['users'] as $nick => $modes) {
                 if (strpos($modes, 'o') === false && strpos($modes, 'h') === false && strpos($modes, 'v') === false) {
                     $nicks[] .= $nick;
                 }
             }
             // loop through, finding users that are level 0, or more
             // commonly, don't have any status modes.
         } elseif ($part[1] == 'v' || $part[1] == ircd::$prefix_modes['v']) {
             foreach (core::$chans[$chan]['users'] as $nick => $modes) {
                 if (strpos($modes, 'v') !== false) {
                     $nicks[] .= $nick;
                 }
             }
             // again we loop, finding users that have voice.
         } elseif (($part[1] == 'h' || $part[1] == ircd::$prefix_modes['h']) && ircd::$halfop) {
             foreach (core::$chans[$chan]['users'] as $nick => $modes) {
                 if (strpos($modes, 'h') !== false) {
                     $nicks[] .= $nick;
                 }
             }
             // again we loop, finding users that have halfop.
         } elseif ($part[1] == 'o' || $part[1] == ircd::$prefix_modes['o']) {
             foreach (core::$chans[$chan]['users'] as $nick => $modes) {
                 if (strpos($modes, 'o') !== false) {
                     $nicks[] .= $nick;
                 }
             }
             // again we loop, finding users that have operator.
         } elseif (($part[1] == 'a' || $part[1] == ircd::$prefix_modes['a']) && ircd::$protect) {
             foreach (core::$chans[$chan]['users'] as $nick => $modes) {
                 if (strpos($modes, 'a') !== false) {
                     $nicks[] .= $nick;
                 }
             }
             // again we loop, finding users that have admin.
         } elseif (($part[1] == 'q' || $part[1] == ircd::$prefix_modes['q']) && ircd::$owner) {
             foreach (core::$chans[$chan]['users'] as $nick => $modes) {
                 if (strpos($modes, 'q') !== false) {
                     $nicks[] .= $nick;
                 }
             }
             // again we loop, finding users that have owner.
         } elseif ($part[1] == '*') {
             foreach (core::$chans[$chan]['users'] as $nick => $modes) {
                 $nicks[] .= $nick;
             }
             // and last but not least, all :)
             // note we don't need to do any checks here.
         } else {
             return false;
         }
     } elseif ($part[0] == 'mask') {
         if (strpos($part[1], '@') === false) {
             $part[1] = '*@' . $part[1];
         }
         if (strpos($part[1], '!') === false) {
             $part[1] = '*!' . $part[1];
         }
         // mask is malformed
         foreach (core::$chans[$chan]['users'] as $nick => $modes) {
             $hostname = core::get_full_hostname($nick);
             if (services::match($hostname, $part[1])) {
                 $nicks[] .= $nick;
             }
             // this needs tested, although i'm purty confident i'll work.
         }
         // loop through our users, and find a matching mask >:D
     } else {
         return false;
     }
     // something is invalid here, back out.
     if (count($nicks) == 0) {
         return false;
     }
     // empty array :(
     foreach ($nicks as $id => $nick) {
         if ($nick == $cnick) {
             unset($nicks[$id]);
         }
     }
     // we don't want chanserv in our list, eww.
     $i = 0;
     $x = count($nicks);
     $mode_string = $mode[0];
     $nick_string = ' ';
     foreach ($nicks as $id => $nick) {
         $i++;
         // plus plus
         $mode_string .= $mode[1];
         $nick_string .= $nick . ' ';
         // add stuff to the strings.
         if ($i == ircd::$max_params || $i == $x) {
             ircd::mode($cnick, $chan, trim($mode_string . $nick_string));
             // send the modes
             $i = 0;
             $mode_string = $mode[0];
             $nick_string = ' ';
             // reset all our strings :D
         } else {
             unset($nicks[$id]);
         }
         // bit of maths, well, not much, lol.
     }
     // ok, so we've got our list, instead of sending the modes one by one, here's
     // what we're gonna do, we're gonna compress it into a mode string, setting
     // 6 at a time, sound good? indeed it does.
     if (count($nicks) > 0) {
         ircd::mode($cnick, $chan, trim($mode_string . $nick_string));
     }
     // send the remaining modes
     unset($nicks);
 }