[xiph-cvs] r6612 - in icecast/trunk/icecast: src web

oddsock at xiph.org oddsock at xiph.org
Tue May 4 21:30:42 PDT 2004



Author: oddsock
Date: 2004-04-30 13:32:34 -0400 (Fri, 30 Apr 2004)
New Revision: 6612

Added:
   icecast/trunk/icecast/web/auth.xsl
Modified:
   icecast/trunk/icecast/src/admin.c
   icecast/trunk/icecast/web/status.xsl
Log:
created an auth page which can be used to serve appropriate m3u's which contain authentication information.

<p>Modified: icecast/trunk/icecast/src/admin.c
===================================================================
--- icecast/trunk/icecast/src/admin.c	2004-04-30 16:44:32 UTC (rev 6611)
+++ icecast/trunk/icecast/src/admin.c	2004-04-30 17:32:34 UTC (rev 6612)
@@ -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 @@
         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 @@
         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 @@
 {
     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 @@
     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 @@
         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 @@
     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)
 {

Added: icecast/trunk/icecast/web/auth.xsl
===================================================================
--- icecast/trunk/icecast/web/auth.xsl	2004-04-30 16:44:32 UTC (rev 6611)
+++ icecast/trunk/icecast/web/auth.xsl	2004-04-30 17:32:34 UTC (rev 6612)
@@ -0,0 +1,56 @@
+<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>

<p>Property changes on: icecast/trunk/icecast/web/auth.xsl
___________________________________________________________________
Name: svn:executable
   + *

Modified: icecast/trunk/icecast/web/status.xsl
===================================================================
--- icecast/trunk/icecast/web/status.xsl	2004-04-30 16:44:32 UTC (rev 6611)
+++ icecast/trunk/icecast/web/status.xsl	2004-04-30 17:32:34 UTC (rev 6612)
@@ -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"> Click to Listen</td></tr>
+<tr><td>Listen:</td><td class="streamdata"> 
+<xsl:choose>
+<xsl:when test="authenticator">
+Click to Listen
+</xsl:when>
+<xsl:otherwise>
+Click to Listen
+</xsl:otherwise>
+</xsl:choose>
+</td></tr>
 </table>
 </xsl:when>
 <xsl:otherwise>

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list