Пример #1
0
 public static function set_flag($nick, $chan, $flag, $param)
 {
     $mode = $flag[0];
     $r_flag = $flag[1];
     // get the real flag, eg. V, v and mode
     if (in_array($r_flag, str_split(self::$p_flags)) && $param == '' && $mode == '+') {
         services::communicate(core::$config->chanserv->nick, $nick, &chanserv::$help->CS_FLAGS_NEEDS_PARAM, array('flag' => $flag));
         return false;
     }
     // are they issuing a flag, that HAS to have a parameter?
     // only if mode is + and parameter is empty.
     if ($r_flag == 'd') {
         $param_field = 'desc';
     }
     if ($r_flag == 'u') {
         $param_field = 'url';
     }
     if ($r_flag == 'e') {
         $param_field = 'email';
     }
     if ($r_flag == 'w') {
         $param_field = 'welcome';
     }
     if ($r_flag == 'm') {
         $param_field = 'modelock';
     }
     if ($r_flag == 't') {
         $param_field = 'topicmask';
     }
     // translate. some craq.
     if (in_array($r_flag, str_split(self::$p_flags)) && $mode == '+') {
         if ($r_flag == 'e' && services::valid_email($param) === false) {
             services::communicate(core::$config->chanserv->nick, $nick, &chanserv::$help->CS_FLAGS_INVALID_E, array('flag' => $flag));
             return false;
         }
         // is the email invalid?
         if ($r_flag == 't' && strpos($param, '*') === false) {
             services::communicate(core::$config->chanserv->nick, $nick, &chanserv::$help->CS_FLAGS_INVALID_T, array('flag' => $flag));
             return false;
         }
         // is the topicmask invalid?
         if ($r_flag == 'm') {
             $mode_string = explode(' ', $param);
             if (strstr($mode_string[0], 'r') || strstr($mode_string[0], 'q') || strstr($mode_string[0], 'a') || strstr($mode_string[0], 'o') || strstr($mode_string[0], 'h') || strstr($mode_string[0], 'v') || strstr($mode_string[0], 'b')) {
                 services::communicate(core::$config->chanserv->nick, $nick, &chanserv::$help->CS_FLAGS_INVALID_M, array('flag' => $flag));
                 return false;
             }
         }
         // is the modelock invalid?
     }
     // check for invalid values
     if (chanserv::check_flags($chan, array($r_flag))) {
         $chan_flag_q = database::select('chans_flags', array('id', 'channel', 'flags'), array('channel', '=', $chan));
         if ($mode == '-') {
             if (strpos(self::$set[$target], '+') === false) {
                 self::$set[$target] .= '+';
             }
             // ok, no + ?
             $chan_flag = database::fetch($chan_flag_q);
             // get the flag record
             $new_chan_flags = str_replace($r_flag, '', $chan_flag->flags);
             if (in_array($r_flag, str_split(self::$p_flags))) {
                 database::update('chans_flags', array('flags' => $new_chan_flags, $param_field => $param), array('channel', '=', $chan));
                 // update the row with the new flags.
             } else {
                 database::update('chans_flags', array('flags' => $new_chan_flags), array('channel', '=', $chan));
                 // update the row with the new flags.
             }
             self::$set[$chan] .= $r_flag;
             // some magic :O
             return true;
         }
         if ($mode == '+') {
             if (!in_array($r_flag, str_split(self::$p_flags))) {
                 self::$already_set[$chan] .= $r_flag;
                 // some magic :O
                 return false;
             }
             if (strpos(self::$set[$target], '+') === false) {
                 self::$set[$target] .= '+';
             }
             // ok, no + ?
             $chan_flag = database::fetch($chan_flag_q);
             // get the flag record
             database::update('chans_flags', array($param_field => $param), array('channel', '=', $chan));
             // update the row with the new flags.
             self::$set[$chan] .= $r_flag;
             // some magic :O
             return true;
         }
         // the flag IS set, so now we check whether they are trying to -, or + it
         // if they are trying to - it, go ahead, error if they are trying to + it.
     } else {
         $chan_flag_q = database::select('chans_flags', array('id', 'channel', 'flags'), array('channel', '=', $chan));
         if ($mode == '+') {
             if (strpos(self::$set[$target], '+') === false) {
                 self::$set[$target] .= '+';
             }
             // ok, no + ?
             $chan_flag = database::fetch($chan_flag_q);
             // get the flag record
             $new_chan_flags = $chan_flag->flags . $r_flag;
             if (!in_array($r_flag, str_split(self::$p_flags))) {
                 database::update('chans_flags', array('flags' => $new_chan_flags), array('channel', '=', $chan));
                 // update the row with the new flags.
                 self::$set[$chan] .= $r_flag;
                 // some magic :O
                 return true;
             } else {
                 database::update('chans_flags', array('flags' => $new_chan_flags, $param_field => $param), array('channel', '=', $chan));
                 // update the row with the new flags.
                 self::$set[$chan] .= $r_flag;
                 // some magic :O
                 return true;
             }
         }
         // the flag ISNT set, so now we check whether they are trying to -, or + it
         // if they are trying to + it, go ahead, error if they are trying to _ it.
         if ($mode == '-') {
             self::$not_set[$chan] .= $r_flag;
             // some magic :O
             return false;
         }
     }
     // check if the flag is already set?
 }
Пример #2
0
    public static function register_command($nick, $ircdata = array())
    {
        $password = $ircdata[0];
        $email = $ircdata[1];
        if (trim($password) == '' || trim($email) == '') {
            services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_SYNTAX_RE, array('help' => 'REGISTER'));
            return false;
        }
        // wrong syntax
        if (strtolower($password) == strtolower($nick)) {
            services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_PASSWORD_NICK);
            return false;
        }
        // are they using a reasonable password, eg. != their nick, lol.
        if (services::valid_email($email) === false) {
            services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_INVALID_EMAIL);
            return false;
        }
        // is the email valid?
        if ($user = services::user_exists($nick, false, array('display', 'id'))) {
            services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_ALREADY_REGISTERED);
            return false;
        }
        // are we registered?
        // apprently not, let's move on!
        $check_e = database::select('users_flags', array('email'), array('email', '=', $email));
        if (database::num_rows($check_e) > 0) {
            services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_EMAIL_IN_USE);
            return false;
        }
        // check if the email is in use.
        $salt = '';
        for ($i = 0; $i < 8; $i++) {
            $possible = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
            $salt .= substr($possible, rand(0, strlen($possible) - 1), 1);
        }
        $user_info = array('display' => $nick, 'pass' => sha1($password . $salt), 'salt' => $salt, 'last_hostmask' => core::get_full_hostname($nick), 'last_timestamp' => core::$network_time, 'timestamp' => core::$network_time, 'identified' => 0, 'validated' => core::$config->nickserv->force_validation === true ? 0 : 1, 'real_user' => 1);
        // setup the user info array.
        $flags = core::$config->nickserv->default_flags;
        $flags = str_replace('u', '', $flags);
        $flags = str_replace('e', '', $flags);
        // ignore parameter flags
        database::insert('users', $user_info);
        database::insert('users_flags', array('nickname' => $nick, 'flags' => $flags . 'e', 'email' => $email));
        // insert it into the database.
        if (core::$config->nickserv->force_validation === true) {
            $validation_code = mt_rand();
            core::alog(core::$config->nickserv->nick . ': ' . $nick . ' requested by ' . core::get_full_hostname($nick));
            // logchan
            database::insert('validation_codes', array('nick' => $nick, 'code' => $validation_code));
            // insert the random code to the database
            $to = $nick . ' <' . $email . '>';
            $subject = 'Registration';
            $headers = 'From: ' . core::$config->server->network_name . ' <' . isset(core::$config->email_from) ? core::$config->email_from : core::$config->service_user . '>\\n';
            $message = '
Thank you for using ' . core::$config->server->network_name . '

Nickname: ' . $nick . '
Password: '******'
Confirmation Code: ' . $validation_code . '

To confirm your nickname type the following when connected to ' . core::$config->server->network_name . '
/msg ' . core::$config->nickserv->nick . ' confirm ' . $validation_code . '

You will then be able to identify with the password you chose by typing
/msg ' . core::$config->nickserv->nick . ' identify ' . $password . '
			';
            // generate the email information
            @mail($to, $subject, $message, $headers);
            // let's send the email
            services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_NICK_REQUESTED, array('email' => $email));
        } else {
            services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_NICK_REGISTERED);
            core::alog(core::$config->nickserv->nick . ': ' . $nick . ' registered by ' . core::get_full_hostname($nick));
            // logchan
            core::alog('register_command(): ' . $nick . ' registered by ' . core::get_full_hostname($nick), 'BASIC');
            // log what we need to log.
        }
    }
Пример #3
0
 public static function set_flag($nick, $target, $flag, $param)
 {
     $mode = $flag[0];
     $r_flag = $flag[1];
     // get the real flag, eg. V, v and mode
     if (in_array($r_flag, str_split(self::$p_flags)) && $param == '' && $mode == '+') {
         services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_FLAGS_NEEDS_PARAM, array('flag' => $flag));
         return false;
     }
     // are they issuing a flag, that HAS to have a parameter?
     // only if mode is + and parameter is empty.
     if ($r_flag == 'e') {
         $param_field = 'email';
     }
     if ($r_flag == 'u') {
         $param_field = 'url';
     }
     if ($r_flag == 'm') {
         $param_field = 'msn';
     }
     // translate. some craq.
     if ($r_flag == 'e' && $mode == '-') {
         services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_FLAGS_CANT_UNSET, array('flag' => $flag));
         return false;
     }
     // we're not allowed to let +e be unset
     if (in_array($r_flag, str_split(self::$p_flags)) && $mode == '+') {
         $check_e = database::select('users_flags', array('id', 'email'), array('email', '=', $param));
         if ($r_flag == 'e' && database::num_rows($check_e) > 0) {
             services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_EMAIL_IN_USE);
             return false;
         }
         // check if the email is in use.
         if ($r_flag == 'e' && services::valid_email($param) === false) {
             services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_FLAGS_INVALID_E, array('flag' => $flag));
             return false;
         }
         // is the email invalid?
         if ($r_flag == 'm' && services::valid_email($param) === false) {
             services::communicate(core::$config->nickserv->nick, $nick, &nickserv::$help->NS_FLAGS_INVALID_E, array('flag' => $flag));
             return false;
         }
         // is the email invalid?
     }
     // check for invalid values
     if (nickserv::check_flags($target, array($r_flag))) {
         $nick_flag_q = database::select('users_flags', array('id', 'nickname', 'flags'), array('nickname', '=', $target));
         if ($mode == '-') {
             if (strpos(self::$set[$target], '-') === false) {
                 self::$set[$target] .= '-';
             }
             // ok, no - ?
             $nick_flag = database::fetch($nick_flag_q);
             // get the flag record
             $new_nick_flags = str_replace($r_flag, '', $nick_flag->flags);
             if (in_array($r_flag, str_split(self::$p_flags))) {
                 database::update('users_flags', array('flags' => $new_nick_flags, $param_field => $param), array('nickname', '=', $target));
                 // update the row with the new flags.
             } else {
                 database::update('users_flags', array('flags' => $new_nick_flags), array('nickname', '=', $target));
                 // update the row with the new flags.
             }
             self::$set[$target] .= $r_flag;
             // some magic :O
             return true;
         }
         if ($mode == '+') {
             if (!in_array($r_flag, str_split(self::$p_flags))) {
                 self::$already_set[$target] .= $r_flag;
                 // some magic :O
                 return false;
             }
             if (strpos(self::$set[$target], '+') === false) {
                 self::$set[$target] .= '+';
             }
             // ok, no + ?
             $nick_flag = database::fetch($nick_flag_q);
             // get the flag record
             database::update('user_flags', array($param_field => $param), array('nickname', '=', $target));
             // update the row with the new flags.
             self::$set[$target] .= $r_flag;
             // some magic :O
             return true;
         }
         // the flag IS set, so now we check whether they are trying to -, or + it
         // if they are trying to - it, go ahead, error if they are trying to + it.
     } else {
         $nick_flag_q = database::select('users_flags', array('id', 'nickname', 'flags'), array('nickname', '=', $target));
         if ($mode == '+') {
             if (strpos(self::$set[$target], '+') === false) {
                 self::$set[$target] .= '+';
             }
             // ok, no + ?
             $nick_flag = database::fetch($nick_flag_q);
             // get the flag record
             $new_nick_flags = $nick_flag->flags . $r_flag;
             if (!in_array($r_flag, str_split(self::$p_flags))) {
                 database::update('users_flags', array('flags' => $new_nick_flags), array('nickname', '=', $target));
                 // update the row with the new flags.
                 self::$set[$target] .= $r_flag;
                 // some magic :O
                 return true;
             } else {
                 database::update('users_flags', array('flags' => $new_nick_flags, $param_field => $param), array('nickname', '=', $target));
                 // update the row with the new flags.
                 self::$set[$target] .= $r_flag;
                 // some magic :O
                 return true;
             }
         }
         // the flag ISNT set, so now we check whether they are trying to -, or + it
         // if they are trying to + it, go ahead, error if they are trying to _ it.
         if ($mode == '-') {
             self::$not_set[$target] .= $r_flag;
             // some magic :O
             return false;
         }
     }
     // check if the flag is already set?
 }