Exemplo n.º 1
0
unsigned int settopic(USERS *user, CHANNEL *chan, const char *topic, acetables *g_ape)
{
    RAW *newraw;
    userslist *list;
    json *jlist;

    list = getuchan(user, chan);

    if (list == NULL || list->level < 3 || strlen(topic)+1 > MAX_TOPIC_LEN) {

        send_error(user, "SETTOPIC_ERROR", "111", g_ape);

    } else {
        memcpy(chan->topic, topic, strlen(topic)+1);

        jlist = NULL;

        set_json("user", NULL, &jlist);
        json_attach(jlist, get_json_object_user(user), JSON_OBJECT);

        set_json("pipe", NULL, &jlist);
        json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

        newraw = forge_raw(RAW_SETTOPIC, jlist);
        post_raw_channel(newraw, chan, g_ape);

        return 1;
    }
    return 0;
}
Exemplo n.º 2
0
void ban(CHANNEL *chan, USERS *banner, const char *ip, char *reason, unsigned int expire, acetables *g_ape) // Ban IP
{
    userslist *uTmp, *tUtmp;
    RAW *newraw;
    json *jlist;
    BANNED *blist, *bTmp;

    unsigned int isban = 0;

    long int nextime = (expire * 60)+time(NULL); // NOW !

    if (chan == NULL) {
        return;
    }

    uTmp = chan->head;
    bTmp = chan->banned;

    while (uTmp != NULL) {

        if (strcmp(ip, uTmp->userinfo->ip) == 0) { // We find somebody with the same IP
            jlist = NULL;

            set_json("reason", reason, &jlist);
            if (banner != NULL) {
                set_json("banner", NULL, &jlist);
                json_attach(jlist, get_json_object_user(banner), JSON_OBJECT);
            } else {
                set_json("banner", NULL, &jlist);
                json_attach(jlist, get_json_object_user(NULL), JSON_OBJECT);
            }
            set_json("pipe", NULL, &jlist);
            json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

            newraw = forge_raw(RAW_BAN, jlist);

            post_raw(newraw, uTmp->userinfo, g_ape);

            if (isban == 0) {
                blist = xmalloc(sizeof(*blist));

                strncpy(blist->ip, ip, 16);
                strncpy(blist->reason, reason, 256);
                blist->expire = nextime;
                blist->next = bTmp;
                chan->banned = blist;
                isban = 1;
            }
            tUtmp = uTmp->next;
            left(uTmp->userinfo, chan, g_ape); // if the user is the last : "chan" is free (rmchan())
            uTmp = tUtmp;
            continue;
        }
        uTmp = uTmp->next;
    }

}
Exemplo n.º 3
0
unsigned int cmd_ban(callbackp *callbacki)
{
	CHANNEL *chan;
	RAW *newraw;
	json *jlist;
	
	USERS *victim;

	if ((chan = getchan(callbacki->param[2], callbacki->g_ape)) == NULL) {
		send_error(callbacki->call_user, "UNKNOWN_CHANNEL", "103", callbacki->g_ape);
		
	
	} else if (!isonchannel(callbacki->call_user, chan)) {

		send_error(callbacki->call_user, "NOT_IN_CHANNEL", "104", callbacki->g_ape);
	
	} else if (getuchan(callbacki->call_user, chan)->level < 3) {

		
		send_error(callbacki->call_user, "CANT_BAN", "107", callbacki->g_ape);
		
	} else {
		victim = seek_user(callbacki->param[3], chan->name, callbacki->g_ape);
		
		if (victim == NULL) {

			send_error(callbacki->call_user, "UNKNOWN_USER", "102", callbacki->g_ape);
			
		} else if (victim->flags & FLG_NOKICK) {
			send_error(callbacki->call_user, "USER_PROTECTED", "106", callbacki->g_ape);
			
			// Bad boy :-)
			jlist = NULL;
			set_json("banner", NULL, &jlist);
			json_attach(jlist, get_json_object_user(callbacki->call_user), JSON_OBJECT);
			
			set_json("channel", NULL, &jlist);
			json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);
						
			newraw = forge_raw("TRY_BAN", jlist);
			
			post_raw(newraw, victim, callbacki->g_ape);
			
		} else if (strlen(callbacki->param[4]) > 255 || atoi(callbacki->param[5]) > 44640) { // 31 days max

			send_error(callbacki->call_user, "REASON_OR_TIME_TOO_LONG", "107", callbacki->g_ape);
		} else {
			ban(chan, callbacki->call_user, victim->ip, callbacki->param[4], atoi(callbacki->param[5]), callbacki->g_ape);
		}
		
	}
	
	return (FOR_NOTHING);
}
Exemplo n.º 4
0
struct json *get_json_object_user(USERS *user)
{
	json *jstr = NULL;
	
	if (user != NULL) {
	
		set_json("pubid", user->pipe->pubid, &jstr);
		set_json("casttype", "uni", &jstr);
		
		if (user->properties != NULL) {
			int has_prop = 0;
			
			json *jprop = NULL;
						
			extend *eTmp = user->properties;
			
			while (eTmp != NULL) {
				if (eTmp->visibility == EXTEND_ISPUBLIC) {
					if (!has_prop) {
						has_prop = 1;
						set_json("properties", NULL, &jstr);
					}
					if (eTmp->type == EXTEND_JSON) {
						json *jcopy = json_copy(eTmp->val);
						
						set_json(eTmp->key, NULL, &jprop);
						
						json_attach(jprop, jcopy, JSON_OBJECT);
					} else {
						set_json(eTmp->key, eTmp->val, &jprop);
					}			
				}
				eTmp = eTmp->next;
			}
			if (has_prop) {
				json_attach(jstr, jprop, JSON_OBJECT);
			}
		}

	} else {
		set_json("pubid", SERVER_NAME, &jstr);
	}
	return jstr;
}
Exemplo n.º 5
0
struct json *get_json_object_channel(CHANNEL *chan)
{
    json *jstr = NULL;

    //set_json("topic", chan->topic, &jstr);
    //set_json("name", chan->name, &jstr); // See below
    set_json("pubid", chan->pipe->pubid, &jstr);
    set_json("casttype", "multi", &jstr);

    //if (chan->properties != NULL) {
    json *jprop = NULL;
    set_json("properties", NULL, &jstr);

    extend *eTmp = chan->properties;

    while (eTmp != NULL) {
        if (eTmp->visibility == EXTEND_ISPUBLIC) {
            if (eTmp->type == EXTEND_JSON) {
                json *jcopy = json_copy(eTmp->val);

                set_json(eTmp->key, NULL, &jprop);

                json_attach(jprop, jcopy, JSON_OBJECT);
            } else {
                set_json(eTmp->key, eTmp->val, &jprop);
            }
        }

        eTmp = eTmp->next;
    }
    /* a little hack to have the same behaviour than user */
    set_json("name", chan->name, &jprop);
    json_attach(jstr, jprop, JSON_OBJECT);
    //}

    return jstr;
}
Exemplo n.º 6
0
void sendback_session(USERS *user, session *sess, acetables *g_ape)
{
	subuser *current = user->subuser;
	
	while (current != NULL) {
		if (current->need_update) {
			json *jlist = NULL, *jobj = NULL;
			RAW *newraw;
			
			current->need_update = 0;
			set_json("sessions", NULL, &jlist);
			set_json(sess->key, (sess != NULL ? sess->val : NULL), &jobj);
			json_attach(jlist, jobj, JSON_OBJECT);
			newraw = forge_raw("SESSIONS", jlist);
			newraw->priority = 1;
			post_raw_sub(newraw, current, g_ape);
		}
		current = current->next;
	}	
	
}
Exemplo n.º 7
0
unsigned int cmd_session(callbackp *callbacki)
{
	if (strcmp(callbacki->param[2], "set") == 0 && (callbacki->nParam == 4 || callbacki->nParam == 5)) {
		if (callbacki->nParam == 5) {
			subuser *tmpSub = getsubuser(callbacki->call_user, callbacki->host);
		
			if (tmpSub != NULL) {
				tmpSub->need_update = 0;
			}
		}
		if (set_session(callbacki->call_user, callbacki->param[3], callbacki->param[4], (callbacki->nParam == 4 ? 0 : 1), callbacki->g_ape) == NULL) {
			send_error(callbacki->call_user, "SESSION_ERROR", "203", callbacki->g_ape);
		}
	} else if (strcmp(callbacki->param[2], "get") == 0 && callbacki->nParam >= 3) {
		int i;
		json *jlist = NULL, *jobj = NULL;
		RAW *newraw;
		
		set_json("sessions", NULL, &jlist);
		
		for (i = 3; i <= callbacki->nParam; i++) {
			if (strlen(callbacki->param[i]) > 32) {
				continue;
			}
			session *sTmp = get_session(callbacki->call_user, callbacki->param[i]);

			set_json(callbacki->param[i], (sTmp != NULL ? sTmp->val : NULL), &jobj);

		}
		json_attach(jlist, jobj, JSON_OBJECT);
		newraw = forge_raw("SESSIONS", jlist);
		newraw->priority = 1;
		/* Only sending to current subuser */
		post_raw_sub(newraw, getsubuser(callbacki->call_user, callbacki->host), callbacki->g_ape);

	} else {
		send_error(callbacki->call_user, "SESSION_ERROR_PARAMS", "108", callbacki->g_ape);
	}
	return (FOR_NOTHING);
}
Exemplo n.º 8
0
unsigned int cmd_proxy_connect(callbackp *callbacki)
{
	ape_proxy *proxy;
	RAW *newraw;
	json *jlist = NULL;
	
	proxy = proxy_init_by_host_port(callbacki->param[2], callbacki->param[3], callbacki->g_ape);
	
	if (proxy == NULL) {
		send_error(callbacki->call_user, "PROXY_INIT_ERROR", "204", callbacki->g_ape);
	} else {
		proxy_attach(proxy, callbacki->call_user->pipe->pubid, 1, callbacki->g_ape);
		
		set_json("pipe", NULL, &jlist);
		json_attach(jlist, get_json_object_proxy(proxy), JSON_OBJECT);
	
		newraw = forge_raw(RAW_PROXY, jlist);
		post_raw(newraw, callbacki->call_user, callbacki->g_ape);		
	}
	
	return (FOR_NOTHING);
}
Exemplo n.º 9
0
unsigned int cmd_kick(callbackp *callbacki)
{
	CHANNEL *chan;
	RAW *newraw;
	json *jlist;
	
	USERS *victim;

	if ((chan = getchan(callbacki->param[2], callbacki->g_ape)) == NULL) {
		send_error(callbacki->call_user, "UNKNOWN_CHANNEL", "103", callbacki->g_ape);
		
	} else if (!isonchannel(callbacki->call_user, chan)) {
		send_error(callbacki->call_user, "NOT_IN_CHANNEL", "104", callbacki->g_ape);
		
	} else if (getuchan(callbacki->call_user, chan)->level < 3) {
		send_error(callbacki->call_user, "CANT_KICK", "105", callbacki->g_ape);
		
	} else {
		victim = seek_user(callbacki->param[3], chan->name, callbacki->g_ape);
		
		if (victim == NULL) {

			send_error(callbacki->call_user, "UNKNOWN_USER", "102", callbacki->g_ape);
		} else if (victim->flags & FLG_NOKICK) {
			
			send_error(callbacki->call_user, "USER_PROTECTED", "106", callbacki->g_ape);
			// haha ;-)
			
			jlist = NULL;
			set_json("kicker", NULL, &jlist);
			json_attach(jlist, get_json_object_user(callbacki->call_user), JSON_OBJECT);
			
			set_json("channel", NULL, &jlist);
			json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);
						
			newraw = forge_raw("TRY_KICK", jlist);
			
			post_raw(newraw, victim, callbacki->g_ape);
			
		} else {
			jlist = NULL;
			
			set_json("kicker", NULL, &jlist);
			json_attach(jlist, get_json_object_user(callbacki->call_user), JSON_OBJECT);
			
			set_json("channel", NULL, &jlist);
			json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);
						
			newraw = forge_raw(RAW_KICK, jlist);
			
			post_raw(newraw, victim, callbacki->g_ape);
			
			left(victim, chan, callbacki->g_ape); // chan may be removed
			
		}
		
	}
	
	return (FOR_NOTHING);
	
}
Exemplo n.º 10
0
void subuser_restor(subuser *sub, acetables *g_ape)
{
	CHANLIST *chanl;
	CHANNEL *chan;
	
	json *jlist = NULL;
	RAW *newraw;
	USERS *user = sub->user;
	userslist *ulist;
	
	char level[8];
	
	chanl = user->chan_foot;

	while (chanl != NULL) {
		jlist = NULL;
		chan = chanl->chaninfo;
		
		if (chan->interactive) {

			ulist = chan->head;
			set_json("users", NULL, &jlist);
			
			while (ulist != NULL) {
	
				struct json *juser = NULL;
		
				if (ulist->userinfo != user) {
					//make_link(user, ulist->userinfo);
				}
		
				sprintf(level, "%i", ulist->level);
				set_json("level", level, &juser);
				
				json_concat(juser, get_json_object_user(ulist->userinfo));
	
				json_attach(jlist, juser, JSON_ARRAY);

				ulist = ulist->next;
			}
		}
		set_json("pipe", NULL, &jlist);
		
		json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

		newraw = forge_raw(RAW_CHANNEL, jlist);
		newraw->priority = 1;
		post_raw_sub(newraw, sub, g_ape);
		chanl = chanl->next;
	}

	
	jlist = NULL;
	
	set_json("user", NULL, &jlist);
	json_attach(jlist, get_json_object_user(user), JSON_OBJECT);	
	
	newraw = forge_raw("IDENT", jlist);
	newraw->priority = 1;
	post_raw_sub(newraw, sub, g_ape);
	
}
Exemplo n.º 11
0
// TODO : Rewrite this f***g ugly function
unsigned int setlevel(USERS *user_actif, USERS *user_passif, CHANNEL *chan, unsigned int lvl, acetables *g_ape)
{
    RAW *newraw;
    userslist *user_passif_chan, *user_actif_chan;
    json *jlist;

    char level[8];

    user_passif_chan = getuchan(user_passif, chan);

    if (user_actif != NULL) {
        user_actif_chan = getuchan(user_actif, chan);

        if (user_passif_chan == NULL || user_actif_chan == NULL || ((user_actif_chan->level < lvl || user_actif_chan->level < user_passif_chan->level) && !(user_actif->flags & FLG_AUTOOP)) || lvl < 1 || lvl > 32) {
            send_error(user_actif, "SETLEVEL_ERROR", "110", g_ape);

            return 0;
        }

        user_passif_chan->level = lvl;

        if (chan->interactive) {
            jlist = NULL;

            set_json("ope", NULL, &jlist);
            json_attach(jlist, get_json_object_user(user_passif), JSON_OBJECT);

            set_json("opeur", NULL, &jlist);
            json_attach(jlist, get_json_object_user(user_actif), JSON_OBJECT);

            set_json("level", itos(lvl, level), &jlist);
            set_json("pipe", NULL, &jlist);
            json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

            newraw = forge_raw(RAW_SETLEVEL, jlist);
            post_raw_channel(newraw, chan, g_ape);
        }
        return 1;
    } else if (user_passif_chan != NULL && lvl > 0 && lvl < 32) {
        user_passif_chan->level = lvl;

        if (chan->interactive) {
            jlist = NULL;

            set_json("ope", NULL, &jlist);
            json_attach(jlist, get_json_object_user(user_passif), JSON_OBJECT);

            set_json("opeur", NULL, &jlist);
            json_attach(jlist, get_json_object_user(NULL), JSON_OBJECT);

            set_json("level", itos(lvl, level), &jlist);
            set_json("pipe", NULL, &jlist);
            json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

            newraw = forge_raw(RAW_SETLEVEL, jlist);
            post_raw_channel(newraw, chan, g_ape);

        }
        return 1;
    }
    return 0;
}
Exemplo n.º 12
0
void left(USERS *user, CHANNEL *chan, acetables *g_ape) // Vider la liste chainée de l'user
{
    userslist *list, *prev;

    CHANLIST *clist, *ctmp;
    RAW *newraw;
    json *jlist;

    FIRE_EVENT_NULL(left, user, chan, g_ape);

    if (!isonchannel(user, chan)) {
        return;
    }
    list = chan->head;
    prev = NULL;

    clist = user->chan_foot;
    ctmp = NULL;

    while (clist != NULL) {
        if (clist->chaninfo == chan) {
            if (ctmp != NULL) {
                ctmp->next = clist->next;
            } else {
                user->chan_foot = clist->next;
            }
            free(clist);
            clist = NULL;
            break;
        }
        ctmp = clist;
        clist = clist->next;
    }


    while (list != NULL && list->userinfo != NULL) {
        if (list->userinfo == user) {
            if (prev != NULL) {
                prev->next = list->next;
            } else {
                chan->head = list->next;
            }
            free(list);
            list = NULL;
            if (chan->head != NULL && chan->interactive) {
                jlist = NULL;

                set_json("user",  NULL, &jlist);
                json_attach(jlist, get_json_object_user(user), JSON_OBJECT);


                set_json("pipe", NULL, &jlist);
                json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

                newraw = forge_raw(RAW_LEFT, jlist);
                post_raw_channel(newraw, chan, g_ape);
            } else if (chan->head == NULL) {
                rmchan(chan, g_ape); // A verifier
            }
            break;
        }
        prev = list;
        list = list->next;
    }

}
Exemplo n.º 13
0
void join(USERS *user, CHANNEL *chan, acetables *g_ape)
{
    userslist *list, *ulist;

    CHANLIST *chanl;

    FIRE_EVENT_NULL(join, user, chan, g_ape);

    RAW *newraw;
    json *jlist = NULL;
    char level[8];

    if (isonchannel(user, chan)) {
        return;
    }

    list = (userslist *)xmalloc(sizeof(*list)); // is it free ?
    list->userinfo = user;
    list->level = 1;
    list->next = chan->head;

    chan->head = list;

    chanl = (CHANLIST *)xmalloc(sizeof(*chanl)); // is it free ?
    chanl->chaninfo = chan;
    chanl->next = user->chan_foot;

    user->chan_foot = chanl;


    if (chan->interactive) {
        jlist = NULL;

        set_json("user", NULL, &jlist);
        json_attach(jlist, get_json_object_user(user), JSON_OBJECT);

        set_json("pipe", NULL, &jlist);
        json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

        newraw = forge_raw(RAW_JOIN, jlist);
        post_raw_channel_restricted(newraw, chan, user, g_ape);

        jlist = NULL;
        set_json("users", NULL, &jlist);

        ulist = chan->head;
        while (ulist != NULL) {

            struct json *juser = NULL;

            if (ulist->userinfo != user) {
                //make_link(user, ulist->userinfo);
            }

            sprintf(level, "%i", ulist->level);
            set_json("level", level, &juser);

            json_concat(juser, get_json_object_user(ulist->userinfo));

            json_attach(jlist, juser, JSON_ARRAY);

            ulist = ulist->next;
        }
    }


    set_json("pipe", NULL, &jlist);
    json_attach(jlist, get_json_object_channel(chan), JSON_OBJECT);

    newraw = forge_raw(RAW_CHANNEL, jlist);
    post_raw(newraw, user, g_ape);

#if 0
    if (user->flags & FLG_AUTOOP) {
        setlevel(NULL, user, chan, 3);
    }
#endif

}