1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Feature: Added support for logfile display in admin/

This commit is contained in:
Philipp Schafft 2020-10-02 11:03:09 +00:00
parent de270c535d
commit 4896d73d3a
4 changed files with 141 additions and 0 deletions

View File

@ -11,6 +11,7 @@
<ul>
<li class="adminlink"><a href="/admin/stats.xsl">Server status</a></li>
<li class="adminlink"><a href="/admin/listmounts.xsl">Mountpoint list</a></li>
<li class="adminlink"><a href="/admin/showlog.xsl">Logfiles</a></li>
<xsl:for-each select="(/report/extension/icestats | /icestats | /iceresponse)/modules/module">
<xsl:if test="@management-url and @management-title">
<li class="adminlink"><a href="{@management-url}"><xsl:value-of select="@management-title" /></a></li>

24
admin/showlog.xsl Normal file
View File

@ -0,0 +1,24 @@
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" xmlns="http://www.w3.org/1999/xhtml">
<xsl:output omit-xml-declaration="no" method="xml" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" indent="yes" encoding="UTF-8" />
<xsl:include href="includes/page.xsl"/>
<xsl:variable name="title">Logfiles</xsl:variable>
<xsl:template name="content">
<h2><xsl:value-of select="$title" /></h2>
<xsl:for-each select="/report/incident">
<section class="box">
<h3 class="box_title">Logfile <code><xsl:value-of select="resource[@name='logcontent']/value/value[@member='logfile']/@value" /></code></h3>
<ul class="boxnav">
<xsl:for-each select="resource[@name='logfiles']/value/value">
<li><a href="?logfile={@value}"><xsl:value-of select="@value" /></a></li>
</xsl:for-each>
</ul>
<ul class="codeblock">
<xsl:for-each select="resource[@name='logcontent']/value/value[@member='lines']/value">
<li><pre><xsl:value-of select="@value" /></pre></li>
</xsl:for-each>
</ul>
</section>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

View File

@ -35,6 +35,7 @@
#include "xslt.h"
#include "fserve.h"
#include "errors.h"
#include "reportxml.h"
#include "format.h"
@ -89,6 +90,8 @@
#define MANAGEAUTH_HTML_REQUEST "manageauth.xsl"
#define UPDATEMETADATA_RAW_REQUEST "updatemetadata"
#define UPDATEMETADATA_HTML_REQUEST "updatemetadata.xsl"
#define SHOWLOG_RAW_REQUEST "showlog"
#define SHOWLOG_HTML_REQUEST "showlog.xsl"
#define DEFAULT_RAW_REQUEST ""
#define DEFAULT_HTML_REQUEST ""
#define BUILDM3U_RAW_REQUEST "buildm3u"
@ -112,6 +115,7 @@ static void command_kill_source (client_t *client, source_t *source, adm
static void command_manageauth (client_t *client, source_t *source, admin_format_t response);
static void command_updatemetadata (client_t *client, source_t *source, admin_format_t response);
static void command_buildm3u (client_t *client, source_t *source, admin_format_t response);
static void command_show_log (client_t *client, source_t *source, admin_format_t response);
static const admin_command_handler_t handlers[] = {
{ "*", ADMINTYPE_GENERAL, ADMIN_FORMAT_HTML, NULL, NULL}, /* for ACL framework */
@ -143,6 +147,8 @@ static const admin_command_handler_t handlers[] = {
{ UPDATEMETADATA_RAW_REQUEST, ADMINTYPE_MOUNT, ADMIN_FORMAT_RAW, command_updatemetadata, NULL},
{ UPDATEMETADATA_HTML_REQUEST, ADMINTYPE_MOUNT, ADMIN_FORMAT_HTML, command_updatemetadata, NULL},
{ BUILDM3U_RAW_REQUEST, ADMINTYPE_MOUNT, ADMIN_FORMAT_RAW, command_buildm3u, NULL},
{ SHOWLOG_RAW_REQUEST, ADMINTYPE_GENERAL, ADMIN_FORMAT_RAW, command_show_log, NULL},
{ SHOWLOG_HTML_REQUEST, ADMINTYPE_GENERAL, ADMIN_FORMAT_HTML, command_show_log, NULL},
{ DEFAULT_HTML_REQUEST, ADMINTYPE_HYBRID, ADMIN_FORMAT_HTML, command_stats, NULL},
{ DEFAULT_RAW_REQUEST, ADMINTYPE_HYBRID, ADMIN_FORMAT_HTML, command_stats, NULL}
};
@ -1259,3 +1265,98 @@ static void command_updatemetadata(client_t *client,
UPDATEMETADATA_HTML_REQUEST);
xmlFreeDoc(doc);
}
static void command_show_log (client_t *client, source_t *source, admin_format_t response)
{
static const char *logs[] = {"error", "access", "playlist"};
reportxml_t *report;
reportxml_node_t *incident;
reportxml_node_t *resource;
reportxml_node_t *loglist_value_list;
reportxml_node_t *logfile;
reportxml_node_t *parent;
const char *logfilestring;
char **loglines;
int logid;
size_t i;
COMMAND_OPTIONAL(client, "logfile", logfilestring);
if (!logfilestring || !strcmp(logfilestring, "error")) {
logfilestring = "error";
logid = errorlog;
} else if (!strcmp(logfilestring, "access")) {
logid = accesslog;
} else if (!strcmp(logfilestring, "playlist")) {
logid = playlistlog;
} else {
logfilestring = "error";
logid = errorlog;
}
report = client_get_reportxml("b20a2bf2-1278-448c-81f3-58183d837a86", NULL, NULL);
incident = reportxml_get_node_by_type(report, REPORTXML_NODE_TYPE_INCIDENT, 0);
resource = reportxml_node_new(REPORTXML_NODE_TYPE_RESOURCE, NULL, NULL, NULL);
reportxml_node_set_attribute(resource, "type", "related");
reportxml_node_set_attribute(resource, "name", "logfiles");
loglist_value_list = reportxml_node_new(REPORTXML_NODE_TYPE_VALUE, NULL, NULL, NULL);
reportxml_node_set_attribute(loglist_value_list, "type", "list");
for (i = 0; i < (sizeof(logs)/sizeof(*logs)); i++) {
reportxml_node_t *value = reportxml_node_new(REPORTXML_NODE_TYPE_VALUE, NULL, NULL, NULL);
reportxml_node_set_attribute(value, "type", "string");
reportxml_node_set_attribute(value, "value", logs[i]);
reportxml_node_add_child(loglist_value_list, value);
refobject_unref(value);
}
reportxml_node_add_child(resource, loglist_value_list);
refobject_unref(loglist_value_list);
reportxml_node_add_child(incident, resource);
refobject_unref(resource);
resource = reportxml_node_new(REPORTXML_NODE_TYPE_RESOURCE, NULL, NULL, NULL);
reportxml_node_set_attribute(resource, "type", "result");
reportxml_node_set_attribute(resource, "name", "logcontent");
logfile = reportxml_node_new(REPORTXML_NODE_TYPE_VALUE, NULL, NULL, NULL);
reportxml_node_set_attribute(logfile, "type", "structure");
parent = reportxml_node_new(REPORTXML_NODE_TYPE_VALUE, NULL, NULL, NULL);
reportxml_node_set_attribute(parent, "type", "string");
reportxml_node_set_attribute(parent, "member", "logfile");
reportxml_node_set_attribute(parent, "value", logfilestring);
reportxml_node_add_child(logfile, parent);
refobject_unref(parent);
parent = reportxml_node_new(REPORTXML_NODE_TYPE_VALUE, NULL, NULL, NULL);
reportxml_node_set_attribute(parent, "type", "list");
reportxml_node_set_attribute(parent, "member", "lines");
loglines = log_contents_array(logid);
for (i = 0; loglines[i]; i++) {
reportxml_node_t *value = reportxml_node_new(REPORTXML_NODE_TYPE_VALUE, NULL, NULL, NULL);
reportxml_node_set_attribute(value, "type", "string");
reportxml_node_set_attribute(value, "value", loglines[i]);
reportxml_node_add_child(parent, value);
refobject_unref(value);
free(loglines[i]);
}
free(loglines);
reportxml_node_add_child(logfile, parent);
refobject_unref(parent);
reportxml_node_add_child(resource, logfile);
refobject_unref(logfile);
reportxml_node_add_child(incident, resource);
refobject_unref(resource);
refobject_unref(incident);
client_send_reportxml(client, report, DOCUMENT_DOMAIN_ADMIN, SHOWLOG_HTML_REQUEST, response, 200, NULL);
}

View File

@ -302,6 +302,21 @@ aside {
margin: 0.4em;
}
.codeblock {
list-style: none;
width: 100%;
overflow-x: auto;
padding: 0 0 0.4em 0;
}
.codeblock > li > pre {
margin: 0;
}
.codeblock > li > pre:hover {
background-color: #cccccc;
}
/* Error messages */
.error {