Commit 9f7895bd authored by Ed "oddsock" Zaleski's avatar Ed "oddsock" Zaleski

created an auth page which can be used to serve appropriate m3u's which...

created an auth page which can be used to serve appropriate m3u's which contain authentication information.

svn path=/icecast/trunk/icecast/; revision=6612
parent 52e52dfb
......@@ -73,6 +73,9 @@
#define COMMAND_TRANSFORMED_KILL_CLIENT 401
#define COMMAND_TRANSFORMED_KILL_SOURCE 402
/* Admin commands requiring no auth */
#define COMMAND_BUILDM3U 501
#define FALLBACK_RAW_REQUEST "fallbacks"
#define FALLBACK_TRANSFORMED_REQUEST "fallbacks.xsl"
#define METADATA_REQUEST "metadata"
......@@ -96,6 +99,7 @@
#define MANAGEAUTH_TRANSFORMED_REQUEST "manageauth.xsl"
#define DEFAULT_RAW_REQUEST ""
#define DEFAULT_TRANSFORMED_REQUEST ""
#define BUILDM3U_RAW_REQUEST "buildm3u"
#define RAW 1
#define TRANSFORMED 2
......@@ -142,6 +146,8 @@ int admin_get_command(char *command)
return COMMAND_RAW_MANAGEAUTH;
else if(!strcmp(command, MANAGEAUTH_TRANSFORMED_REQUEST))
return COMMAND_TRANSFORMED_MANAGEAUTH;
else if(!strcmp(command, BUILDM3U_RAW_REQUEST))
return COMMAND_BUILDM3U;
else if(!strcmp(command, DEFAULT_TRANSFORMED_REQUEST))
return COMMAND_TRANSFORMED_STATS;
else if(!strcmp(command, DEFAULT_RAW_REQUEST))
......@@ -162,6 +168,8 @@ static void command_kill_client(client_t *client, source_t *source,
int response);
static void command_manageauth(client_t *client, source_t *source,
int response);
static void command_buildm3u(client_t *client, source_t *source,
int response);
static void command_kill_source(client_t *client, source_t *source,
int response);
static void admin_handle_mount_request(client_t *client, source_t *source,
......@@ -260,6 +268,7 @@ void admin_handle_request(client_t *client, char *uri)
{
char *mount, *command_string;
int command;
int noauth = 0;
if(strncmp("/admin/", uri, 7)) {
ERROR0("Internal error: admin request isn't");
......@@ -284,13 +293,18 @@ void admin_handle_request(client_t *client, char *uri)
if(mount != NULL) {
source_t *source;
if (command == COMMAND_BUILDM3U) {
noauth = 1;
}
/* This is a mount request, handle it as such */
if(!connection_check_admin_pass(client->parser)) {
if(!connection_check_source_pass(client->parser, mount)) {
INFO1("Bad or missing password on mount modification admin "
"request (command: %s)", command_string);
client_send_401(client);
return;
if (!noauth) {
if(!connection_check_admin_pass(client->parser)) {
if(!connection_check_source_pass(client->parser, mount)) {
INFO1("Bad or missing password on mount modification admin "
"request (command: %s)", command_string);
client_send_401(client);
return;
}
}
}
......@@ -423,6 +437,9 @@ static void admin_handle_mount_request(client_t *client, source_t *source,
case COMMAND_RAW_MANAGEAUTH:
command_manageauth(client, source, RAW);
break;
case COMMAND_BUILDM3U:
command_buildm3u(client, source, RAW);
break;
default:
WARN0("Mount request not recognised");
client_send_400(client, "Mount request unknown");
......@@ -581,6 +598,38 @@ static void command_show_listeners(client_t *client, source_t *source,
client_destroy(client);
}
static void command_buildm3u(client_t *client, source_t *source,
int response)
{
char *username = NULL;
char *password = NULL;
char *host = NULL;
int port = 0;
ice_config_t *config;
COMMAND_REQUIRE(client, "username", username);
COMMAND_REQUIRE(client, "password", password);
config = config_get_config();
host = config->hostname;
port = config->port;
client->respcode = 200;
sock_write(client->con->sock,
"HTTP/1.0 200 OK\r\n"
"Content-Type: audio/x-mpegurl\r\n"
"Content-Disposition = attachment; filename=listen.m3u\r\n\r\n"
"http://%s:%s@%s:%d%s\r\n",
username,
password,
host,
port,
source->mount
);
client_destroy(client);
config_release_config();
}
static void command_manageauth(client_t *client, source_t *source,
int response)
{
......
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >
<xsl:output method="html" indent="yes" />
<xsl:template match = "/icestats" >
<html>
<head>
<title>Icecast Streaming Media Server</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body bgcolor="black">
<table border="0" width="100%%">
<tr>
<td width="50"></td>
<td>
<h2>Authorization Page</h2>
<div class="roundcont">
<div class="roundtop">
<img src="corner_topleft.jpg" class="corner" style="display: none" />
</div>
<div class="newscontent">
<xsl:for-each select="source">
<xsl:choose>
<xsl:when test="listeners">
<xsl:if test="authenticator">
<xsl:if test="server_name"><xsl:value-of select="server_name" /> </xsl:if>
<h3>(<xsl:value-of select="@mount" />)</h3>
<form method="GET" action="/admin/buildm3u">
<table border="0" cellpadding="4">
<tr><td>Username : <input type="text" name="username"/></td></tr>
<tr><td>Password : <input type="password" name="password"/></td></tr>
<tr><td><input type="Submit" value="Login"/></td></tr>
</table>
<input type="hidden" name="mount" value="{@mount}"/>
</form>
</xsl:if>
</xsl:when>
<xsl:otherwise>
<h3><xsl:value-of select="@mount" /> - Not Connected</h3>
</xsl:otherwise>
</xsl:choose>
<br></br>
<br></br>
</xsl:for-each>
</div>
<div class="roundbottom">
<img src="corner_bottomleft.jpg" class="corner" style="display: none" />
</div>
</div>
<br></br><br></br>
</td>
<td width="25"></td></tr>
</table>
<div class="poster"><img align="left" src="/icecast.png" />Support icecast development at <a class="nav" href="http://www.icecast.org">www.icecast.org</a></div>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
......@@ -22,7 +22,9 @@
<xsl:when test="listeners">
<h3>
<xsl:if test="server_name"><xsl:value-of select="server_name" /> </xsl:if>
(<xsl:value-of select="@mount" />)</h3>
(<xsl:value-of select="@mount" />)
<xsl:if test="authenticator"> <a href="/auth.xsl"><img border="0" src="/key.gif"/></a> </xsl:if>
</h3>
<table border="0" cellpadding="4">
<xsl:if test="server_name">
<tr><td>Stream Title:</td><td class="streamdata"> <xsl:value-of select="server_name" /></td></tr>
......@@ -47,7 +49,16 @@
</xsl:if>
<tr><td>Current Song:</td><td class="streamdata">
<xsl:if test="artist"><xsl:value-of select="artist" /> - </xsl:if><xsl:value-of select="title" /></td></tr>
<tr><td>Listen:</td><td class="streamdata"> <a href="{@mount}.m3u">Click to Listen</a></td></tr>
<tr><td>Listen:</td><td class="streamdata">
<xsl:choose>
<xsl:when test="authenticator">
<a href="auth.xsl">Click to Listen</a>
</xsl:when>
<xsl:otherwise>
<a href="{@mount}.m3u">Click to Listen</a>
</xsl:otherwise>
</xsl:choose>
</td></tr>
</table>
</xsl:when>
<xsl:otherwise>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment