mirror of
https://github.com/unrealircd/unrealircd.git
synced 2026-07-09 12:13:12 +02:00
Add unrealircd.org/json-log CAP, which sends JSON logs to IRCOps.
This basically enhances the regular snomask/ircop notices with JSON logs, the same logs that are logged to disk (with type 'json'). This allows bots/machines to much more easily parse server notices such as connect notices or.. anything. Note that JSON logs are quite large, so make sure the ircop has a BIG class::sendq! Also, everyone can set the cap but it is only effective for IRCOps.
This commit is contained in:
@@ -1106,6 +1106,7 @@ void do_unreal_log_ircops(LogLevel loglevel, char *subsystem, char *event_id, ch
|
||||
char *client_snomasks;
|
||||
char *p;
|
||||
char found;
|
||||
MessageTag *mtags = NULL;
|
||||
|
||||
/* If not fully booted then we don't have a logging to snomask mapping so can't do much.. */
|
||||
if (!loop.ircd_booted)
|
||||
@@ -1125,6 +1126,14 @@ void do_unreal_log_ircops(LogLevel loglevel, char *subsystem, char *event_id, ch
|
||||
if (snomask_destinations && !strcmp(snomask_destinations, "*"))
|
||||
snomask_destinations = NULL;
|
||||
|
||||
/* Prepare message tag for those who have CAP unrealircd.org/json-log */
|
||||
if (json_serialized)
|
||||
{
|
||||
mtags = safe_alloc(sizeof(MessageTag));
|
||||
safe_strdup(mtags->name, "unrealircd.org/json-log");
|
||||
safe_strdup(mtags->value, json_serialized);
|
||||
}
|
||||
|
||||
/* To specific snomasks... */
|
||||
list_for_each_entry(client, &oper_list, special_node)
|
||||
{
|
||||
@@ -1148,11 +1157,15 @@ void do_unreal_log_ircops(LogLevel loglevel, char *subsystem, char *event_id, ch
|
||||
log_level_color(loglevel), log_level_valtostring(loglevel), COLOR_NONE,
|
||||
COLOR_DARKGREY, subsystem, event_id, COLOR_NONE,
|
||||
msg);*/
|
||||
sendnotice(client, "%s%s.%s%s %s[%s]%s %s",
|
||||
sendto_one(client, mtags, ":%s NOTICE %s :%s%s.%s%s %s[%s]%s %s",
|
||||
me.name, client->name,
|
||||
COLOR_DARKGREY, subsystem, event_id, COLOR_NONE,
|
||||
log_level_color(loglevel), log_level_valtostring(loglevel), COLOR_NONE,
|
||||
msg);
|
||||
}
|
||||
|
||||
if (mtags)
|
||||
free_message_tags(mtags);
|
||||
}
|
||||
|
||||
void do_unreal_log_remote(LogLevel loglevel, char *subsystem, char *event_id, char *msg, char *json_serialized)
|
||||
|
||||
@@ -31,21 +31,30 @@ ModuleHeader MOD_HEADER
|
||||
"unrealircd-5",
|
||||
};
|
||||
|
||||
/* Variables */
|
||||
long CAP_JSON_LOG = 0L;
|
||||
|
||||
/* Forward declarations */
|
||||
int json_log_mtag_is_ok(Client *client, char *name, char *value);
|
||||
int json_log_mtag_can_send(Client *target);
|
||||
|
||||
MOD_INIT()
|
||||
{
|
||||
{
|
||||
ClientCapabilityInfo cap;
|
||||
ClientCapability *c;
|
||||
MessageTagHandlerInfo mtag;
|
||||
|
||||
MARK_AS_OFFICIAL_MODULE(modinfo);
|
||||
|
||||
memset(&cap, 0, sizeof(cap));
|
||||
cap.name = "unrealircd.org/json-log";
|
||||
c = ClientCapabilityAdd(modinfo->handle, &cap, &CAP_JSON_LOG);
|
||||
|
||||
memset(&mtag, 0, sizeof(mtag));
|
||||
mtag.name = "unrealircd.org/json-log";
|
||||
mtag.is_ok = json_log_mtag_is_ok;
|
||||
mtag.can_send = json_log_mtag_can_send;
|
||||
mtag.flags = MTAG_HANDLER_FLAGS_NO_CAP_NEEDED;
|
||||
mtag.clicap_handler = c;
|
||||
MessageTagHandlerAdd(modinfo->handle, &mtag);
|
||||
|
||||
return MOD_SUCCESS;
|
||||
@@ -75,7 +84,7 @@ int json_log_mtag_is_ok(Client *client, char *name, char *value)
|
||||
/** Outgoing filter for this message tag */
|
||||
int json_log_mtag_can_send(Client *target)
|
||||
{
|
||||
if (IsServer(target) || IsOper(target))
|
||||
if (IsServer(target) || (target->local && IsOper(target) && HasCapabilityFast(target, CAP_JSON_LOG)))
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user