Пример #1
0
char* CL_IsBanned(int uid, char* pbguid, netadr_t addr){
    banList_t *this;
    int i;

    this = svse.banList;
    if(!this)
        return NULL;

    for(i = 0 ; i < current_banindex; this++, i++){

        if(uid && this->playeruid == uid){

            if(this->expire == (time_t)-1){
                SV_PlayerAddBanByip(addr, this->reason, this->playeruid , this->adminuid, -1);
                return va("\nEnforcing prior ban\nPermanent ban issued onto this gameserver\nYou will be never allowed to join this gameserver again\n Your UID is: %i    Banning admin UID is: %i\nReason for this ban:\n%s\n",
                this->playeruid,this->adminuid,this->reason);
            }

            if(this->expire > realtime){

		int remaining = (int)(this->expire - realtime);
                SV_PlayerAddBanByip(addr, this->reason, this->playeruid, this->adminuid, this->expire);
		int d = remaining/(60*60*24);
		remaining = remaining%(60*60*24);
		int h = remaining/(60*60);
		remaining = remaining%(60*60);
		int m = remaining/60;

                return va("\nEnforcing prior kick/ban\nTemporary ban issued onto this gameserver\nYou are not allowed to rejoin this gameserver for another\n %i days %i hours %i minutes\n Your UID is: %i    Banning admin UID is: %i\nReason for this ban:\n%s\n",
                d,h,m,this->playeruid,this->adminuid,this->reason);
            }
        }else if(pbguid && !Q_strncmp(this->pbguid, &pbguid[24], 8)){

            if(this->expire == (time_t)-1){
                return va("Permanent ban issued onto this gameserver\nYou will be never allowed to join this gameserver again\n Your GUID is: %s\nReason for this ban:\n%s\n",
                this->pbguid, this->reason);
            }

            if(this->expire > realtime){

		int remaining = (int)(this->expire - realtime);
		int d = remaining/(60*60*24);
		remaining = remaining%(60*60*24);
		int h = remaining/(60*60);
		remaining = remaining%(60*60);
		int m = remaining/60;

                return va("Temporary ban issued onto this gameserver\nYou are not allowed to rejoin this gameserver for another\n %i days %i hours %i minutes\n Your GUID is: %s\nReason for this ban:\n%s\n",
                d,h,m, this->pbguid, this->reason);
            }

        }
    }
    return NULL;

}
Пример #2
0
void Webadmin_BanClient( xml_t* xmlobj, httpPostVals_t* values, int uid)
{
	const char* arg1;
	const char* reason;
	int cid, cluid;
	mvabuf;

	if(Auth_GetClPowerByUID(uid) < Cmd_GetPower("permban"))
	{
		XA("Insufficient permissions");
		return;
	}

	if( (reason = Webadmin_GetPostVal(values, "reason")) )
	{
		if( (arg1 = Webadmin_GetPostVal(values, "cid")) )
		{
			cid = atoi(arg1);
			if (cid >= 0 && cid < sv_maxclients->integer) {
				if(uid > 0 || strlen(svs.clients[cid].pbguid) == 32)
				{
					SV_AddBan(svs.clients[cid].uid, uid, svs.clients[cid].pbguid, svs.clients[cid].name, (time_t)-1, (char*)reason);
				}
				SV_PlayerAddBanByip(&svs.clients[cid].netchan.remoteAddress, (char*)reason, svs.clients[cid].uid, svs.clients[cid].pbguid, uid, -1);
				XA("Banned player"); 
				XA(svs.clients[cid].name);
			}
		}else if( (arg1 = Webadmin_GetPostVal(values, "uid")) ){
			cluid = atoi(arg1);
			if (cluid > 0) {
				SV_AddBan(cluid, uid, NULL, "N/A", (time_t)-1, (char*)reason);
				XA(va("Banned player with uid %d", cluid)); 
			}
		}else if ( (arg1 = Webadmin_GetPostVal(values, "guid"))) {
			if (strlen(arg1) == 32)
			{
				SV_AddBan(0, uid, (char*)arg1, "N/A", (time_t)-1, (char*)reason);
				XA("Banned player with guid ");
				XA(arg1);
			}
		}
	}

}
qboolean HTTPCreateWebadminMessage(ftRequest_t* request, msg_t* msg, char* sessionkey, httpPostVals_t* values)
{
	byte *buf;
	char qpath[MAX_QPATH];
	int len;
	const char *session;
	char banmsg[1024];

	buf = NULL;

	MSG_Init(msg, buf, 0);
	Com_Printf("URL: %s\n", request->url);
	if(!Q_strncmp(request->url, "/files", 6))
	{
		if(request->url[6] != '/' || request->url[7] == '\0')
		{
			return qfalse;
		}
		Com_sprintf(qpath, sizeof(qpath), "/webadmindata/%s", &request->url[7]);

		if(strstr(qpath, "..") != NULL || strstr(qpath, "::") != NULL)
		{
			return qfalse;
		}
		len = FS_ReadFile(qpath, (void**)&buf);

		if(len < 0)
		{
			return qfalse;
		}
		msg->data = buf;
		msg->cursize = len;
		msg->maxsize = len;
		FS_FreeFileKeepBuf( );
		return qtrue;
	}

	len = 0x20000;

	buf = Z_Malloc(len);
	if(buf == NULL)
	{
		return qfalse;
	}

	msg->data = buf;
	msg->cursize = 0;
	msg->maxsize = len;

	if (Q_stricmpn(request->url, "/webadmin", 9))
	{
		Webadmin_BuildMessage(msg, NULL, qfalse, NULL ,request->url, values);
		return qtrue;
	}

	qboolean invalidlogin = qfalse;
	const char* username = NULL;
	const char* password = NULL;


	if(SV_PlayerBannedByip(&request->remote, banmsg, sizeof(banmsg)))
	{
		Webadmin_BuildMessage(msg, NULL, qfalse, banmsg, request->url, values);
		return qtrue;
	}

	username = Auth_FindSessionID(sessionkey);

	if(username == NULL)
	{

		username = HTTP_GetFormDataItem(values, "username");
		password = HTTP_GetFormDataItem(values, "password");

		if(username[0] && password[0])
		{
			session = Auth_GetSessionId(username, password);
			if(session == NULL)
			{
				Com_Printf("^1Invalid login\n");
				invalidlogin = qtrue;
				SV_PlayerAddBanByip(&request->remote, "Invalid login attempt. You have to wait 20 seconds", Com_GetRealtime() + 10);
				username = NULL;
			}else {
				Com_Printf("^2Successful login with username: %s\n", username);
			}


		}else {
			Com_Printf("No login!\n");
			session = NULL;
			username = NULL;
		}

		/* not longer than 127 or overflow */
		if(session != NULL)
		{
			strcpy(sessionkey, session);
		}
	}else{
		Com_Printf("Already logged in as: %s\n", username);
	}

	Webadmin_BuildMessage(msg, username, invalidlogin, NULL, request->url, values);

	return qtrue;
}
Пример #4
0
tcpclientstate_t HL2Rcon_SourceRconAuth(netadr_t *from, msg_t *msg, int *connectionId){

	int packetlen;
	int packettype;
	int packetid;
	char* loginstring;
	char* username;
	char* password;
	byte msgbuf[32];
	msg_t sendmsg;
	rconUser_t* user;
	int i;
	char buf[MAX_STRING_CHARS];
	char stringlinebuf[MAX_STRING_CHARS];

	MSG_BeginReading(msg);
	packetlen = MSG_ReadLong(msg);

	if(packetlen != msg->cursize - 4){//Not a source rcon packet

		Com_Printf("Not a source rcon packet: len %d size %d\n", packetlen, msg->cursize);

		return TCP_AUTHNOTME;
	}
	packetid = MSG_ReadLong(msg);

	packettype = MSG_ReadLong(msg);

	if(packettype != SERVERDATA_AUTH)//Not a source rcon auth-packet
		return TCP_AUTHNOTME;

	if(SV_PlayerBannedByip(from, buf, sizeof(buf))){
		return TCP_AUTHBAD;
	}
	
	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);
	MSG_WriteLong(&sendmsg, 0);
	MSG_WriteLong(&sendmsg, SERVERDATA_RESPONSE_VALUE);
	MSG_WriteShort(&sendmsg, 0);
	if(NET_SendData(from->sock, &sendmsg) < 1)
	{
		return TCP_AUTHBAD;
	}

	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);

	loginstring = MSG_ReadStringLine(msg, stringlinebuf, sizeof(stringlinebuf));

	Cmd_TokenizeString(loginstring);

	if(Cmd_Argc() != 2){
		goto badrcon;
	}
	username = Cmd_Argv(0);
	password = Cmd_Argv(1);

	if(strlen(password) < 6){
		goto badrcon;
	}

	if(Auth_Authorize(username, password) < 0)
	{
		goto badrcon;
	}

	Com_Printf("Rcon login from: %s Name: %s\n", NET_AdrToString (from), username);

	Cmd_EndTokenizedString();

	for(i = 0, user = sourceRcon.activeRconUsers; i < MAX_RCONUSERS; i++, user++){
		if(user->remote.type == NA_BAD)
			break;
	}

	if(i == MAX_RCONUSERS){
		return TCP_AUTHBAD; //Close connection
	}


	user->remote = *from;
	user->uid = Auth_GetUID(username);
//	user->rconPower = login->power;
	Q_strncpyz(user->rconUsername, username, sizeof(user->rconUsername));
	user->streamchat = 0;
	user->streamlog = 0;
	user->lastpacketid = packetid;
	*connectionId = i;

	MSG_WriteLong(&sendmsg, user->lastpacketid);
	MSG_WriteLong(&sendmsg, SERVERDATA_AUTH_RESPONSE);
	MSG_WriteShort(&sendmsg, 0);
	if(NET_SendData(from->sock, &sendmsg) < 1)
	{
		return TCP_AUTHBAD;
	}

	return TCP_AUTHSUCCESSFULL;


badrcon:
	Cmd_EndTokenizedString();
	Com_Printf ("Bad rcon from %s (TCP)\n", NET_AdrToString (from) );
	//Don't allow another attempt for 20 seconds
	SV_PlayerAddBanByip(from, "Bad rcon", 0, NULL, 0, Com_GetRealtime() + 20);

	MSG_Init(&sendmsg, msgbuf, sizeof(msgbuf));
	MSG_WriteLong(&sendmsg, 10);
	MSG_WriteLong(&sendmsg, -1);
	MSG_WriteLong(&sendmsg, SERVERDATA_AUTH_RESPONSE);
	MSG_WriteShort(&sendmsg, 0);
	NET_SendData(from->sock, &sendmsg);
	return TCP_AUTHBAD;

}
Пример #5
0
P_P_F void Plugin_BanClient( unsigned int clientnum, int duration, int invokerid, char *banreason )
{
    
	client_t *cl;
	char* guid;
	time_t expire;
	char* temp;
    time_t aclock;
	char endtime[32];
    char dropmsg[MAX_STRING_CHARS];

	if(clientnum > sv_maxclients->integer)
		return;
	
	cl = &svs.clients[clientnum];

	time(&aclock);
	
	if(duration == -1)
	{
		expire = duration;
		Q_strncpyz(endtime, "never", sizeof(endtime));
	}
	else
	{
		expire = (aclock+(time_t)(duration*60));
		temp = ctime(&expire);
		temp[strlen(temp)-1] = 0;
		Q_strncpyz(endtime, temp, sizeof(endtime));
	
	}
	
	if(strlen(cl->pbguid) == 32)
	{
		guid = &cl->pbguid[24];
	}
	else if(cl->uid < 1)
	{
		Com_Printf("Error: This player has no valid ID and got banned by IP only\n");
		SV_DropClient(cl, "Invalid ID\n");
		SV_PlayerAddBanByip(&cl->netchan.remoteAddress, "INVALID USER", 0, "INVALID", 0, expire);
		return;
	}
	
	if(banreason == NULL)
	{
		banreason = "N/A";
	}
	
	SV_AddBan(cl->uid, invokerid, guid, cl->name, expire, banreason);

	if( cl->uid > 0 )
	{
		Com_Printf( "Banrecord added for player: %s uid: %i\n", cl->name, cl->uid);
		SV_PrintAdministrativeLog( "Banned player: %s uid: %i until %s with the following reason: %s", cl->name, cl->uid, endtime, banreason);
		Com_sprintf(dropmsg, sizeof(dropmsg), "You have been banned from this server\nYour ban will expire on: %s\nYour UID is: %i    Banning admin UID is: %i\nReason for this ban:\n%s",
			endtime, cl->uid, invokerid, banreason);

	}else{
		Com_Printf( "Banrecord added for player: %s guid: %s\n", cl->name, cl->pbguid);
		SV_PrintAdministrativeLog( "Banned player: %s guid: %s until %s with the following reason: %s", cl->name, cl->pbguid, endtime, banreason);
		Com_sprintf(dropmsg, sizeof(dropmsg), "You have been banned from this server\nYour ban will expire on: %s\nYour GUID is: %s    Banning admin UID is: %i\nReason for this ban:\n%s",
			endtime, cl->pbguid, invokerid, banreason);

		if(cl->authentication < 1)
		{
			SV_PlayerAddBanByip(&cl->netchan.remoteAddress, banreason, 0, cl->pbguid, 0, expire);
		}
	}
	SV_DropClient(cl, dropmsg);
}