Show client status on our basic presentation page.

This commit is contained in:
Justin Maggard 2014-01-07 10:14:26 -08:00
parent eeffcf47dd
commit a75bdadce1

View File

@ -577,31 +577,68 @@ sendXMLdesc(struct upnphttp * h, char * (f)(int *))
free(desc); free(desc);
} }
#ifdef READYNAS
static void
SendResp_readynas_admin(struct upnphttp * h)
{
char body[128];
int l;
h->respflags = FLAG_HTML;
l = snprintf(body, sizeof(body), "<meta http-equiv=\"refresh\" content=\"0; url=https://%s/admin/\">",
lan_addr[h->iface].str);
BuildResp_upnphttp(h, body, l);
SendResp_upnphttp(h);
CloseSocket_upnphttp(h);
}
#endif
static void static void
SendResp_presentation(struct upnphttp * h) SendResp_presentation(struct upnphttp * h)
{ {
char body[1024]; struct string_s str;
int l; char body[4096];
int a, v, p, i;
str.data = body;
str.size = sizeof(body);
str.off = 0;
h->respflags = FLAG_HTML; h->respflags = FLAG_HTML;
#ifdef READYNAS
l = snprintf(body, sizeof(body), "<meta http-equiv=\"refresh\" content=\"0; url=https://%s/admin/\">",
lan_addr[h->iface].str);
#else
int a, v, p;
a = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'a*'"); a = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'a*'");
v = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'v*'"); v = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'v*'");
p = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'i*'"); p = sql_get_int_field(db, "SELECT count(*) from DETAILS where MIME glob 'i*'");
l = snprintf(body, sizeof(body), strcatf(&str,
"<HTML><HEAD><TITLE>" SERVER_NAME " " MINIDLNA_VERSION "</TITLE></HEAD>" "<HTML><HEAD><TITLE>" SERVER_NAME " " MINIDLNA_VERSION "</TITLE></HEAD>"
"<BODY><div style=\"text-align: center\">" "<BODY><div style=\"text-align: center\">"
"<h3>" SERVER_NAME " status</h3>" "<h2>" SERVER_NAME " status</h2></div>");
"Audio files: %d<br>"
"Video files: %d<br>" strcatf(&str,
"Image files: %d</div>" "<h3>Media library</h3>"
"</BODY></HTML>\r\n", a, v, p); "<table border=1 cellpadding=10>"
#endif "<tr><td>Audio files</td><td>%d</td></tr>"
BuildResp_upnphttp(h, body, l); "<tr><td>Video files</td><td>%d</td></tr>"
"<tr><td>Image files</td><td>%d</td></tr>"
"</table>", a, v, p);
strcatf(&str,
"<h3>Connected clients</h3>"
"<table border=1 cellpadding=10>"
"<tr><td>ID</td><td>Type</td><td>IP Address</td><td>HW Address</td></tr>");
for (i = 0; i < CLIENT_CACHE_SLOTS; i++)
{
if (!clients[i].addr.s_addr)
continue;
strcatf(&str, "<tr><td>%d</td><td>%s</td><td>%s</td><td>%02X:%02X:%02X:%02X:%02X:%02X</td></tr>",
i, client_types[clients[i].type].name, inet_ntoa(clients[i].addr),
clients[i].mac[0], clients[i].mac[1], clients[i].mac[2],
clients[i].mac[3], clients[i].mac[4], clients[i].mac[5]);
}
strcatf(&str, "</table></BODY></HTML>\r\n");
BuildResp_upnphttp(h, str.data, str.off);
SendResp_upnphttp(h); SendResp_upnphttp(h);
CloseSocket_upnphttp(h); CloseSocket_upnphttp(h);
} }
@ -954,10 +991,18 @@ ProcessHttpQuery_upnphttp(struct upnphttp * h)
{ {
SendResp_caption(h, HttpUrl+10); SendResp_caption(h, HttpUrl+10);
} }
else if(strcmp(HttpUrl, "/") == 0) else if(strcmp(HttpUrl, "/status/") == 0)
{ {
SendResp_presentation(h); SendResp_presentation(h);
} }
else if(strcmp(HttpUrl, "/") == 0)
{
#ifdef READYNAS
SendResp_readynas_admin(h);
#else
SendResp_presentation(h);
#endif
}
else else
{ {
DPRINTF(E_WARN, L_HTTP, "%s not found, responding ERROR 404\n", HttpUrl); DPRINTF(E_WARN, L_HTTP, "%s not found, responding ERROR 404\n", HttpUrl);