Esempio n. 1
0
/* count actions for ignore list */
unsigned int check_ignore(const char *nick, const char *hostmask)
{
  igninfo *ignore;
  int left;

  if (*nick == '#') /* don't count channel */
    return 0;

  if (verifyshell(&gdata.autoignore_exclude, hostmask))
    return 0; /* host matches autoignore_exclude */

  ignore = get_ignore(hostmask);
  ++(ignore->bucket);
  ignore->lastcontact = gdata.curtime;

  if (ignore->flags & IGN_IGNORING)
    return 1;

  if (ignore->bucket < gdata.autoignore_rate)
    return 0;

  left = gdata.autoignore_threshold * (ignore->bucket + 1);
  ignore->flags |= IGN_IGNORING;

  ioutput(OUT_S|OUT_L|OUT_D, COLOR_NO_COLOR,
          "Auto-ignore activated for %s (%s) lasting %i%c%i%c",
          nick, hostmask,
          left < 3600 ? left/60 : left/60/60 ,
          left < 3600 ? 'm' : 'h',
          left < 3600 ? left%60 : (left/60)%60 ,
          left < 3600 ? 's' : 'm');

  notice(nick,
         "Auto-ignore activated for %s (%s) lasting %i%c%i%c" ". Further messages will increase duration.",
         nick, hostmask,
         left < 3600 ? left/60 : left/60/60 ,
         left < 3600 ? 'm' : 'h',
         left < 3600 ? left%60 : (left/60)%60 ,
         left < 3600 ? 's' : 'm');

  write_statefile();
  return 1;
}
/* check if a transfer will use more  connections per user than allowed */
static void t_check_duplicateip(transfer *const newtr)
{
    igninfo *ignore;
    char *bhostmask;
    transfer *tr;
    unsigned int found;
    unsigned int num;

    if (gdata.ignore_duplicate_ip == 0)
        return;

    if (gdata.maxtransfersperperson == 0)
        return;

    updatecontext();

    if (newtr->con.family != AF_INET)
        return;

    found = 0;
    for (tr = irlist_get_head(&gdata.trans);
            tr;
            tr = irlist_get_next(tr)) {
        if (tr->tr_status != TRANSFER_STATUS_SENDING)
            continue;
        if (tr->remoteip != newtr->remoteip)
            continue;
        if (!strcmp(tr->hostname, "man")) /* NOTRANSLATE */
            continue;

        ++found;
    }

    if (found <= gdata.maxtransfersperperson)
        return;

    num = gdata.ignore_duplicate_ip * 60; /* n hours */
    for (tr = irlist_get_head(&gdata.trans);
            tr;
            tr = irlist_get_next(tr)) {
        if (tr->tr_status != TRANSFER_STATUS_SENDING)
            continue;
        if (tr->remoteip != newtr->remoteip)
            continue;
        if (!strcmp(tr->hostname, "man")) /* NOTRANSLATE */
            continue;

        t_closeconn(tr, "You are being punished for parallel downloads", 0);
        queue_punish_abuse( "You are being punished for parallel downloads", tr->net, tr->nick);

        bhostmask = to_hostmask( "*", tr->hostname); /* NOTRANSLATE */
        ignore = get_ignore(bhostmask);
        ignore->flags |= IGN_IGNORING;
        ignore->flags |= IGN_MANUAL;
        ignore->bucket = (num*60)/gdata.autoignore_threshold;

        ioutput(OUT_S|OUT_L|OUT_D, COLOR_NO_COLOR,
                "same IP detected, Ignore activated for %s which will last %u min",
                bhostmask, num);
        mydelete(bhostmask);
    }

    write_statefile();
}
Esempio n. 3
0
void t_checkminspeed(transfer * const t) {
   char *hostmask;
   char *tempstr2;

   updatecontext();

   if (t->tr_status != TRANSFER_STATUS_SENDING)      return; /* no checking unless we're sending */
   if (t->con.connecttime+MIN_TL > gdata.curtime)    return; /* no checking until time has passed */
   if (t->nomin || (t->xpack->minspeed) == 0.0)      return; /* no minspeed for this transfer */
   if ( t->lastspeed+0.11 > t->xpack->minspeed )     return; /* over minspeed */
   
   if (gdata.no_minspeed_on_free)
     {
        if (irlist_size(&gdata.trans) < gdata.slotsmax) return; /* free slots */
     }
   
   tempstr2 = mymalloc(maxtextlength);
   snprintf(tempstr2, maxtextlength,
        "Under Min Speed Requirement, %2.1fK/sec is less than %2.1fK/sec",
         t->lastspeed,t->xpack->minspeed);
   t_closeconn(t,tempstr2,0);
   mydelete(tempstr2);
   
   if (gdata.punishslowusers)
     {
       igninfo *ignore;
       transfer *tr;
       gnetwork_t *backup;
       
       for (tr = irlist_get_head(&gdata.trans); tr; tr = irlist_get_next(tr))
         {
           if ((tr->tr_status != TRANSFER_STATUS_DONE) &&
               (strcasecmp(tr->nick,t->nick) == 0))
             {
               t_closeconn(tr, "You are being punished for your slowness", 0);
             }
         }
       
       queue_punish_abuse("You are being punished for your slowness", t->net, t->nick);
       
       hostmask = to_hostmask( "*", t->hostname);
       ignore = get_ignore(hostmask);
       mydelete(hostmask);
       ignore->flags |= IGN_IGNORING;
       ignore->bucket = (gdata.punishslowusers*60)/gdata.autoignore_threshold;
       
       backup = gnetwork;
       gnetwork = &(gdata.networks[t->net]);
       ioutput(OUT_S|OUT_L|OUT_D, COLOR_NO_COLOR,
               "Punish-ignore activated for (%s on %s) (%s) %u minutes",
               t->nick, gdata.networks[ t->net ].name,
               ignore->hostmask,
               gdata.punishslowusers);
       
       notice(t->nick, "Punish-ignore activated for %s (%s) %u minutes",
              t->nick,
              ignore->hostmask,
              gdata.punishslowusers);
       
       gnetwork = backup;
       write_statefile();
     }
   
   }
Esempio n. 4
0
/**
 * Split from do_send, this way we can easily send a memo from any point.
 *
 * @param u User Struct
 * @param name Target of the memo
 * @param text Memo Text
 * @param z type see info
 * @param source Nickname of the alias the memo originates from.
 *	0 - reply to user
 *	1 - silent
 *	2 - silent with no delay timer
 *	3 - reply to user and request read receipt
 * @return void
 */
void memo_send_from(User * u, char *name, char *text, int z, char *source)
{
    int ischan;
    int isforbid;
    Memo *m;
    MemoInfo *mi;
    time_t now = time(NULL);
    int is_servoper = is_services_oper(u);

    if (readonly) {
        notice_lang(s_MemoServ, u, MEMO_SEND_DISABLED);
    } else if (checkDefCon(DEFCON_NO_NEW_MEMOS)) {
        notice_lang(s_MemoServ, u, OPER_DEFCON_DENIED);
        return;
    } else if (!text) {
        if (z == 0)
            syntax_error(s_MemoServ, u, "SEND", MEMO_SEND_SYNTAX);

        if (z == 3)
            syntax_error(s_MemoServ, u, "RSEND", MEMO_RSEND_SYNTAX);

    } else if (!nick_recognized(u)) {
        if (z == 0 || z == 3)
            notice_lang(s_MemoServ, u, NICK_IDENTIFY_REQUIRED, s_NickServ);

    } else if (!(mi = getmemoinfo(name, &ischan, &isforbid))) {
        if (z == 0 || z == 3) {
            if (isforbid) {
                notice_lang(s_MemoServ, u,
                            ischan ? CHAN_X_FORBIDDEN :
                            NICK_X_FORBIDDEN, name);
            } else {
                notice_lang(s_MemoServ, u,
                            ischan ? CHAN_X_NOT_REGISTERED :
                            NICK_X_NOT_REGISTERED, name);
            }
        }
    } else if (z != 2 && MSSendDelay > 0 &&
               u && u->lastmemosend + MSSendDelay > now && !is_servoper) {
        u->lastmemosend = now;
        if (z == 0)
            notice_lang(s_MemoServ, u, MEMO_SEND_PLEASE_WAIT, MSSendDelay);

        if (z == 3)
            notice_lang(s_MemoServ, u, MEMO_RSEND_PLEASE_WAIT,
                        MSSendDelay);

    } else if (mi->memomax == 0 && !is_servoper) {
        if (z == 0 || z == 3)
            notice_lang(s_MemoServ, u, MEMO_X_GETS_NO_MEMOS, name);

    } else if (mi->memocount >= 32767 || (mi->memomax > 0 && mi->memocount >= mi->memomax
               && !is_servoper)) {
        if (z == 0 || z == 3)
            notice_lang(s_MemoServ, u, MEMO_X_HAS_TOO_MANY_MEMOS, name);

    } else {
        u->lastmemosend = now;
        mi->memocount++;
        mi->memos = srealloc(mi->memos, sizeof(Memo) * mi->memocount);
        m = &mi->memos[mi->memocount - 1];
        strscpy(m->sender, source, NICKMAX);
        m->moduleData = NULL;
        if (mi->memocount > 1) {
            m->number = m[-1].number + 1;
            if (m->number < 1) {
                int i;
                for (i = 0; i < mi->memocount; i++) {
                    mi->memos[i].number = i + 1;
                }
            }
        } else {
            m->number = 1;
        }
        m->time = time(NULL);
        m->text = sstrdup(text);
        m->flags = MF_UNREAD;
#ifdef USE_MYSQL
	m->id = 0;
#endif
        /* Set notify sent flag - DrStein */
        if (z == 2) {
            m->flags |= MF_NOTIFYS;
        }
        /* Set receipt request flag */
        if (z == 3)
            m->flags |= MF_RECEIPT;
        if (z == 0 || z == 3)
            notice_lang(s_MemoServ, u, MEMO_SENT, name);
        if (!ischan) {
            NickAlias *na;
            NickCore *nc = (findnick(name))->nc;

            if (MSNotifyAll) {
                if ((nc->flags & NI_MEMO_RECEIVE)
                    && get_ignore(name) == NULL) {
                    int i;

                    for (i = 0; i < nc->aliases.count; i++) {
                        na = nc->aliases.list[i];
                        if (na->u && nick_identified(na->u))
                            notice_lang(s_MemoServ, na->u,
                                        MEMO_NEW_MEMO_ARRIVED, source,
                                        s_MemoServ, m->number);
                    }
                } else {
                    if ((u = finduser(name)) && nick_identified(u)
                        && (nc->flags & NI_MEMO_RECEIVE))
                        notice_lang(s_MemoServ, u, MEMO_NEW_MEMO_ARRIVED,
                                    source, s_MemoServ, m->number);
                }               /* if (flags & MEMO_RECEIVE) */
            }
            /* if (MSNotifyAll) */
            /* let's get out the mail if set in the nickcore - certus */
            if (nc->flags & NI_MEMO_MAIL)
                new_memo_mail(nc, m);
        } else {
            struct c_userlist *cu, *next;
            Channel *c;

            if (MSNotifyAll && (c = findchan(name))) {
                for (cu = c->users; cu; cu = next) {
                    next = cu->next;
                    if (check_access(cu->user, c->ci, CA_MEMO)) {
                        if (cu->user->na
                            && (cu->user->na->nc->flags & NI_MEMO_RECEIVE)
                            && get_ignore(cu->user->nick) == NULL) {
                            notice_lang(s_MemoServ, cu->user,
                                        MEMO_NEW_X_MEMO_ARRIVED,
                                        c->ci->name, s_MemoServ,
                                        c->ci->name, m->number);
                        }
                    }
                }
            }                   /* MSNotifyAll */
        }                       /* if (!ischan) */
    }                           /* if command is valid */
}