From: Jaroslav Kysela Date: Thu, 25 May 2017 13:52:44 +0000 (+0200) Subject: comet: allow to watch the logs only with the administrator priviledges, fixes #4186 X-Git-Tag: v4.2.3~55 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7129754a4c580b6f7f3b4538fdbb2643694bc6c5;p=thirdparty%2Ftvheadend.git comet: allow to watch the logs only with the administrator priviledges, fixes #4186 --- diff --git a/src/tvhlog.c b/src/tvhlog.c index c06007eb7..693188dfe 100644 --- a/src/tvhlog.c +++ b/src/tvhlog.c @@ -281,8 +281,10 @@ tvhlog_process /* Comet (debug must still be enabled??) */ if (msg->notify && msg->severity < LOG_TRACE) { - htsmsg_t *m = htsmsg_create_map(); snprintf(buf, sizeof(buf), "%s %s", t, msg->msg); + comet_mailbox_add_logmsg(buf, msg->severity >= LOG_DEBUG, 0); + + htsmsg_t *m = htsmsg_create_map(); htsmsg_add_str(m, "notificationClass", "logmessage"); htsmsg_add_str(m, "logtxt", buf); comet_mailbox_add_message(m, msg->severity >= LOG_DEBUG, 0); diff --git a/src/webui/comet.c b/src/webui/comet.c index 705e2e6ab..213047797 100644 --- a/src/webui/comet.c +++ b/src/webui/comet.c @@ -57,6 +57,7 @@ int comet_running; typedef struct comet_mailbox { char *cmb_boxid; /* SHA-1 hash */ char *cmb_lang; /* UI language */ + int cmb_restricted; /* !admin */ htsmsg_t *cmb_messages; /* A vector */ int64_t cmb_last_used; LIST_ENTRY(comet_mailbox) cmb_link; @@ -242,6 +243,7 @@ comet_mailbox_poll(http_connection_t *hc, const char *remain, void *opaque) comet_mailbox_t *cmb = NULL; const char *cometid = http_arg_get(&hc->hc_req_args, "boxid"); const char *immediate = http_arg_get(&hc->hc_req_args, "immediate"); + const char *lang = hc->hc_access->aa_lang_ui; int im = immediate ? atoi(immediate) : 0, e; int64_t mono; htsmsg_t *m; @@ -261,11 +263,19 @@ comet_mailbox_poll(http_connection_t *hc, const char *remain, void *opaque) break; if(cmb == NULL) { - cmb = comet_mailbox_create(hc->hc_access->aa_lang_ui); + cmb = comet_mailbox_create(lang); comet_access_update(hc, cmb); comet_serverIpPort(hc, cmb); } cmb->cmb_last_used = 0; /* Make sure we're not flushed out */ + if (http_access_verify(hc, ACCESS_ADMIN)) { + if (!cmb->cmb_restricted) { + pthread_mutex_unlock(&comet_mutex); + comet_mailbox_add_logmsg(tvh_gettext_lang(lang, N_("Restricted log mode (no administrator)")), 0, 0); + pthread_mutex_lock(&comet_mutex); + cmb->cmb_restricted = 1; + } + } if(!im && cmb->cmb_messages == NULL) { mono = mclk() + sec2mono(10); @@ -306,6 +316,8 @@ comet_mailbox_dbg(http_connection_t *hc, const char *remain, void *opaque) { comet_mailbox_t *cmb = NULL; const char *cometid = http_arg_get(&hc->hc_req_args, "boxid"); + const char *lang = hc->hc_access->aa_lang_ui; + const char *s; if(cometid == NULL) return 400; @@ -319,15 +331,22 @@ comet_mailbox_dbg(http_connection_t *hc, const char *remain, void *opaque) if(cmb->cmb_messages == NULL) cmb->cmb_messages = htsmsg_create_list(); - + + if(cmb->cmb_restricted || http_access_verify(hc, ACCESS_ADMIN)) + s = N_("Only admin can watch the realtime log."); + else if(cmb->cmb_debug) + s = N_("Loglevel debug: enabled"); + else + s = N_("Loglevel debug: disabled"); + snprintf(buf, sizeof(buf), "%s", tvh_gettext_lang(lang, s)); + htsmsg_t *m = htsmsg_create_map(); htsmsg_add_str(m, "notificationClass", "logmessage"); - snprintf(buf, sizeof(buf), "Loglevel debug: %sabled", - cmb->cmb_debug ? "en" : "dis"); htsmsg_add_str(m, "logtxt", buf); htsmsg_add_msg(cmb->cmb_messages, NULL, m); - + tvh_cond_signal(&comet_cond, 1); + break; } } pthread_mutex_unlock(&comet_mutex); @@ -416,9 +435,12 @@ comet_mailbox_add_message(htsmsg_t *m, int isdebug, int rewrite) if (atomic_get(&comet_running)) { LIST_FOREACH(cmb, &mailboxes, cmb_link) { - if(isdebug && !cmb->cmb_debug) + if(cmb->cmb_restricted) continue; + if(isdebug && !cmb->cmb_debug) + continue; + if(cmb->cmb_messages == NULL) cmb->cmb_messages = htsmsg_create_list(); e = htsmsg_copy(m); @@ -431,3 +453,16 @@ comet_mailbox_add_message(htsmsg_t *m, int isdebug, int rewrite) pthread_mutex_unlock(&comet_mutex); } + +/** + * + */ +void +comet_mailbox_add_logmsg(const char *txt, int isdebug, int rewrite) +{ + htsmsg_t *m = htsmsg_create_map(); + htsmsg_add_str(m, "notificationClass", "logmessage"); + htsmsg_add_str(m, "logtxt", txt); + comet_mailbox_add_message(m, isdebug, 0); + htsmsg_destroy(m); +} diff --git a/src/webui/webui.h b/src/webui/webui.h index 2ce29a71b..fa5578137 100644 --- a/src/webui/webui.h +++ b/src/webui/webui.h @@ -64,6 +64,8 @@ void comet_done(void); void comet_mailbox_add_message(htsmsg_t *m, int isdebug, int rewrite); +void comet_mailbox_add_logmsg(const char *txt, int isdebug, int rewrite); + void comet_flush(void); #endif /* WEBUI_H_ */