[Slim-Checkins] r33826 - in /7.7/trunk/platforms/readynas/addon_template: SQUEEZEBOX.js SQUEEZEBOX_HANDLER.pl

[email protected] Mon, 13 Feb 2012 15:10:49 -0000
Newsgroups gmane.music.equipment.slimdevices.cvs
Message-ID <[email protected]>
Author: mherger
Date: Mon Feb 13 07:10:49 2012
New Revision: 33826

URL: http://svn.slimdevices.com/slim?rev=33826&view=rev
Log:
Bug: n/a
Description: read http port web UI from server.prefs

Modified:
    7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX.js
    7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX_HANDLER.pl

Modified: 7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX.js
URL: http://svn.slimdevices.com/slim/7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX.js?rev=33826&r1=33825&r2=33826&view=diff
==============================================================================
--- 7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX.js (original)
+++ 7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX.js Mon Feb 13 07:10:49 2012
@@ -5,8 +5,20 @@
 self.SQUEEZEBOX_onloadaction = function()
 {
 	// set a link to the Logitech Media Server web UI
-	// TODO: read the port from the server's configuration
-	$('#sbwebui').html('<a href="http://' + window.location.hostname + ':9000" target="_blank">Free Your Music!</a>');
+	$.ajax({
+		url: NasState.otherAddOnHash['SQUEEZEBOX'].DisplayAtom.set_url + '?OPERATION=get_web_port',
+		success: function(xmlPayLoad) {
+			var port = xmlPayLoad.getElementsByTagName('content').item(0);
+			
+			if (port.firstChild.data)
+				port = port.firstChild.data;
+				
+			if (isNaN(parseInt(port)))
+				port = 9000;
+			
+			$('#sbwebui').html('<a href="http://' + window.location.hostname + ':' + port + '" target="_blank">Free Your Music!</a>');
+		}
+	});
 	
 	toggleCleanupOptions();
 }

Modified: 7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX_HANDLER.pl
URL: http://svn.slimdevices.com/slim/7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX_HANDLER.pl?rev=33826&r1=33825&r2=33826&view=diff
==============================================================================
--- 7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX_HANDLER.pl (original)
+++ 7.7/trunk/platforms/readynas/addon_template/SQUEEZEBOX_HANDLER.pl Mon Feb 13 07:10:49 2012
@@ -46,6 +46,9 @@
 # handle Squeezebox cleanup requests
 elsif ($operation eq 'cleanup') {
 	run_cleanup($command);
+}
+elsif ($operation eq 'get_web_port') {
+	$xml_payload .= get_web_port();
 }
 
 print $xml_payload;
@@ -99,4 +102,26 @@
 	}
 }
 
+sub get_web_port
+{
+	my $port = 9000;
+	my $prefFile = '/c/.squeezeboxserver/pres/server.prefs';
+	
+	if (-r $prefFile) {
+		if (open(PREF, $prefFile)) {
+			local $_;
+			while (<PREF>) {
+				if (/^httpport(:| \=)? (\d+)$/) {
+					$port = $2;
+					last;
+				}
+			}
+
+			close(PREF);
+		}
+	}
+	
+	return "<payload><content>$port</content><warning>No Warnings</warning><error>No Errors</error></payload>";
+}
+
 1;