[vlma-devel] commit: HTTP Basic authentication for the watchdog. (Adrien Grand )

git version control git at videolan.org
Mon Oct 27 22:30:59 CET 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Mon Oct 27 22:20:57 2008 +0100| [a97a67896871549f5a3c0d073be3774c6b82584d] | committer: Adrien Grand 

HTTP Basic authentication for the watchdog.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=a97a67896871549f5a3c0d073be3774c6b82584d
---

 .../videolan/vlma/retriever/HttpDataRetriever.java |    4 ++++
 vlma-daemon/src/main/resources/config.properties   |    2 ++
 vlma-watchdog/src/vlc.py                           |    7 +++++++
 3 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/retriever/HttpDataRetriever.java b/vlma-core/src/main/java/org/videolan/vlma/retriever/HttpDataRetriever.java
index 4e40b1c..2d9ae67 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/retriever/HttpDataRetriever.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/retriever/HttpDataRetriever.java
@@ -46,6 +46,10 @@ public class HttpDataRetriever implements DataRetriever {
                     + configuration.getInt("vlc.monitor.http.port") + "/monitor/");
             URLConnection conn;
             conn = url.openConnection();
+            String userPassword = configuration.getString("vlc.monitor.http.login") + ":"
+                + configuration.getString("vlc.monitor.http.password");
+            String encodedUserPassword = new sun.misc.BASE64Encoder().encode (userPassword.getBytes());
+            conn.setRequestProperty("Authorization", "Basic " + encodedUserPassword);
             ServerState state = ServerState.parseFrom(conn.getInputStream());
             for(Data data : Data.values()) {
                 switch(data) {
diff --git a/vlma-daemon/src/main/resources/config.properties b/vlma-daemon/src/main/resources/config.properties
index 1e84326..fca2d2b 100644
--- a/vlma-daemon/src/main/resources/config.properties
+++ b/vlma-daemon/src/main/resources/config.properties
@@ -8,6 +8,8 @@ vlc.snmp.oid.vlc_cpu = 1.3.6.1.4.1.2021.2016.13.4.1.2.7.118.108.99.95.99.112.117
 vlc.snmp.oid.vlc_mem = 1.3.6.1.4.1.2021.2016.14.4.1.2.7.118.108.99.95.109.101.109.1
 vlc.snmp.oid.traffic_in = 1.3.6.1.4.1.2021.2016.11.4.1.2.10.116.114.97.102.102.105.99.95.105.110.1
 vlc.snmp.oid.traffic_out = 1.3.6.1.4.1.2021.2016.12.4.1.2.11.116.114.97.102.102.105.99.95.111.117.116.1
+vlc.monitor.http.login = videolan
+vlc.monitor.http.password = admin
 vlc.monitor.http.port = 4213
 vlc.monitor.impl = HTTP
 vlc.stream.dvb-bandwidth = 8
diff --git a/vlma-watchdog/src/vlc.py b/vlma-watchdog/src/vlc.py
index 78cf087..76ee56e 100644
--- a/vlma-watchdog/src/vlc.py
+++ b/vlma-watchdog/src/vlc.py
@@ -14,12 +14,15 @@ VLC_MEMORY_THRESHOLD = 80.0
 NETWORK_INTERFACE = "eth0"
 
 SERVER_PORT = 4213
+SERVER_LOGIN = "videolan"
+SERVER_PASSWORD = "admin"
 
 # Imports
 
 import logging, os, signal, sys, threading, time
 from twisted.web import server, resource
 from twisted.internet import reactor
+from twisted.protocols import http
 from data_pb2 import ServerState
 
 global vlcInstance
@@ -164,6 +167,10 @@ class ServerStateResource(resource.Resource):
     self.monitor = monitor
 
   def render_GET(self, request):
+    if(request.getUser() != SERVER_LOGIN or request.getPassword() != SERVER_PASSWORD):
+      request.setResponseCode(http.UNAUTHORIZED)
+      request.setHeader('WWW-authenticate', 'basic realm="VLC monitor HTTP interface"')
+      return "Authentication needed"
     state = ServerState()
     state.cpuLoad = self.monitor.getCpuLoad()
     state.vlcCpu = self.monitor.getVlcCpu()



More information about the vlma-devel mailing list