Belirtilen Komutları Loglama Modülü

Aytac

nicktag
Yönetici
Developer
Katılım
4 Şub 2020
Mesajlar
395
Tepkime puanı
144
Puanları
43
Konum
ircland
Web sitesi
www.ircalem.net
Modül adı: m_commandlog.c

* Modülü kullanacak olanlar ve bilmeyenler için ön açıklama yapıyorum: -> unrealircd.conf dosyanızı açın ve set bloğunu bulun, bulduktan sonra bir alt satırına veya herhangi bir satırına aşağıda ki bölümü ekleyin.

Kod:
log-commands "version,motd,list";

Yukarıda ki örnekte gördüğünüz gibi, (motd, list, version) komutları bulunmakta bu komutları uygulayan kişi veya kişileri belirtilen dizinde, belirtilen dosyaya..

03/13/15, 03:55 PM (EET) - Entrance ([email protected]) used command LIST (params: <10000)

Şeklinde kayıt etmektedir. Çoğaltmak içinde aynı mantığı kullanarak istediğiniz/görmek istediğiniz loglamasını istediğiniz komutları ekleyiniz. ayrıyetten modül içerisinde,

Kod:
#define COMMAND_LOGFILE "/home/kullanıcıadı/Unreal3.2.10.1/uline.log"

Bu bölümü düzenlemeyi unutmayınız. Modül AngryWolf-un yapmış olduğu commandsno.c üzerinden yabancılar tarafından edit/düzenlenmiştir.

Kod:
/*
  m_svslog.c, an edit of commandsno by angrywolf
  cranked is a pretty cool guy
  but novasquirrel is even cooler
 */
#define COMMAND_LOGFILE "/home/kullanıcıadı/Unreal3.2.10.1/uline.log"

#include "config.h"
#include "struct.h"
#include "common.h"
#include "sys.h"
#include "numeric.h"
#include "msg.h"
#include "channel.h"
#include <time.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <io.h>
#endif
#include <fcntl.h>
#include "h.h"
#ifdef STRIPBADWORDS
#include "badwords.h"
#endif
#ifdef _WIN32
#include "version.h"
#endif

typedef struct _cmdovr CmdOvr;

struct _cmdovr
{
	CmdOvr			*prev, *next;
	Cmdoverride		*ovr;
	char			*cmd;
};

extern void			sendto_one(aClient *to, char *pattern, ...);
extern void			sendto_realops(char *pattern, ...);

#define FLAG_CMD		'C'
#define DelOverride(cmd, ovr)	if (ovr && CommandExists(cmd)) CmdoverrideDel(ovr); ovr = NULL
#define DelHook(x)      	if (x) HookDel(x); x = NULL
#define DelSnomask(x)		if (x) SnomaskDel(x); x = NULL
#define MaxSize			(sizeof(mybuf) - strlen(mybuf) - 1)

static Cmdoverride		*AddOverride(char *msg, iFP cb);
static Snomask			*AddSnomask(Module *module, char flag, iFP allowed, long *mode);
static int			override_cmd(Cmdoverride *, aClient *, aClient *, int, char *[]);
static int			cb_config_test(ConfigFile *, ConfigEntry *, int, int *);
static int			cb_config_run(ConfigFile *, ConfigEntry *, int);
static int			cb_stats(aClient *sptr, char *stats);
static int			cb_config_rehash();
static int			cb_rehash_complete();
static inline void		InitConf();
static void			FreeConf();

Cmdoverride			*OvrMap, *OvrLinks;
Hook				*HookConfTest, *HookConfRun;
Hook				*HookConfRehash, *HookStats;
Hook				*HookConfRehash, *HookRehashDone;
Snomask				*SnomaskCmd;
CmdOvr				*OvrList;
char				*cmdlist, mybuf[BUFSIZE];
long				SNO_COMMAND;
static u_char			module_loaded = 0;

#ifndef STATIC_LINKING
static ModuleInfo		*MyModInfo;
 #define MyMod			MyModInfo->handle
 #define SAVE_MODINFO		MyModInfo = modinfo;
#else
 #define MyMod			NULL
 #define SAVE_MODINFO
#endif

ModuleHeader MOD_HEADER(commandsno)
  = {
	"command logger",
	"edit of commandsno",
	"logs svs commands",
	"3.2-b8-1",
	NULL 
    };

DLLFUNC int MOD_TEST(commandsno)(ModuleInfo *modinfo)
{
	HookConfTest = HookAddEx(modinfo->handle, HOOKTYPE_CONFIGTEST, cb_config_test);
	return MOD_SUCCESS;
}

DLLFUNC int MOD_INIT(commandsno)(ModuleInfo *modinfo)
{
	SAVE_MODINFO
//#ifndef STATIC_LINKING
//	ModuleSetOptions(modinfo->handle, MOD_OPT_PERM);
//#endif
	OvrList = NULL;
	InitConf();

	HookConfRun	= HookAddEx(modinfo->handle, HOOKTYPE_CONFIGRUN, cb_config_run);
	HookConfRehash	= HookAddEx(modinfo->handle, HOOKTYPE_REHASH, cb_config_rehash);
	HookRehashDone	= HookAddEx(modinfo->handle, HOOKTYPE_REHASH_COMPLETE, cb_rehash_complete);

    return MOD_SUCCESS;
}

DLLFUNC int MOD_LOAD(commandsno)(int module_load)
{
	cb_rehash_complete();
	return MOD_SUCCESS;
}

DLLFUNC int MOD_UNLOAD(commandsno)(int module_unload)
{
	FreeConf();

	DelHook(HookRehashDone);
	DelHook(HookConfRehash);
	DelHook(HookConfRun);
	DelHook(HookConfTest);

	return MOD_SUCCESS;
}

static inline void InitConf()
{
	cmdlist = NULL;
}

static void FreeConf()
{
	CmdOvr		*o;
	ListStruct	*next;

	for (o = OvrList; o; o = (CmdOvr *) next)
	{
		next = (ListStruct *) o->next;
		DelListItem(o, OvrList);
		DelOverride(o->cmd, o->ovr);
		MyFree(o->cmd);
		MyFree(o);
	}

	MyFree(cmdlist);
}

static int cb_config_rehash()
{
	module_loaded = 0;
	FreeConf();
	InitConf();

	return 1;
}

static int cb_rehash_complete()
{
	if (!module_loaded)
	{
		module_loaded = 1;

		if (cmdlist)
		{
			char		*cmd, *tmp, *p;
			Cmdoverride	*ovr;
			CmdOvr		*o;

			tmp = strdup(cmdlist);
			for (cmd = strtoken(&p, tmp, ","); cmd;
			    cmd = strtoken(&p, NULL, ","))
	        	{
				if (!(ovr = AddOverride(cmd, override_cmd)))
					continue;

				o = (CmdOvr *) MyMallocEx(sizeof(CmdOvr));
				o->ovr = ovr;
				o->cmd = strdup(cmd);
				AddListItem(o, OvrList);
			}
			MyFree(tmp);
		}
	}

	return 0;
}

static int cb_config_test(ConfigFile *cf, ConfigEntry *ce, int type, int *errs)
{
	int errors = 0;

	if (type != CONFIG_SET)
		return 0;

    int Found = 0;
	if (!strcmp(ce->ce_varname, "log-commands"))
	{
        Found = 1;
		if (!ce->ce_vardata)
		{
			config_error("%s:%i: set::%s without contents",
					ce->ce_fileptr->cf_filename,
					ce->ce_varlinenum, ce->ce_varname);
			errors++;
		}

		*errs = errors;
		return errors ? -1 : 1;
	}

	return 0;
}

static int cb_config_run(ConfigFile *cf, ConfigEntry *ce, int type)
{
	if (type != CONFIG_SET)
		return 0;

	if (!strcmp(ce->ce_varname, "log-commands"))
	{
		if (!cmdlist)
			cmdlist = strdup(ce->ce_vardata);

		return 1;		
	}

	return 0;
}

Cmdoverride *AddOverride(char *msg, iFP cb)
{
	Cmdoverride *ovr = CmdoverrideAdd(MyMod, msg, cb);

#ifndef STATIC_LINKING
        if (ModuleGetError(MyMod) != MODERR_NOERROR || !ovr)
#else
        if (!ovr)
#endif
	{
#ifndef STATIC_LINKING
		config_error("Error replacing command %s when loading module %s: %s",
			msg, MOD_HEADER(commandsno).name, ModuleGetErrorStr(MyMod));
#else
		config_error("Error replacing command %s when loading module %s",
			msg, MOD_HEADER(commandsno).name);
#endif
		return NULL;
	}

	return ovr;
}

static int override_cmd(Cmdoverride *ovr, aClient *cptr, aClient *sptr, int parc, char *parv[])
{
	if (IsPerson(sptr))
	{
		int i;

		mybuf[0] = 0;

		for (i = 1; i < parc; i++)
		{
			if (mybuf[0])
				strncat(mybuf, " ", MaxSize);
			strncat(mybuf, parv[i], MaxSize);
		}

		if (!mybuf[0])
			strcpy(mybuf, "<none>");

        char Temp[100];
        time_t rawtime;
        struct tm *timeinfo;
        time(&rawtime);
        timeinfo = localtime(&rawtime);
        strftime(Temp,80,"%x, %I:%M %p (%Z)",timeinfo);

        FILE *File = fopen(COMMAND_LOGFILE,"a");
        if(File!=NULL) {
          fprintf(File, "%s - %s (%s@%s) used command %s (params: %s)\n",
			Temp,sptr->name, sptr->user->username, sptr->user->realhost,
			ovr->command->cmd, mybuf);
          fclose(File);
        }
	}

	return CallCmdoverride(ovr, cptr, sptr, parc, parv);
}
 
Geri
Üst