]> git.parisson.com Git - telecaster-client.git/commitdiff
add setting param examples, add host context_processor
authorGuillaume Pellerin <yomguy@parisson.com>
Mon, 15 Jul 2013 21:07:01 +0000 (23:07 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Mon, 15 Jul 2013 21:07:01 +0000 (23:07 +0200)
example/settings.py [new file with mode: 0644]
telecaster/context_processors.py [new file with mode: 0644]

diff --git a/example/settings.py b/example/settings.py
new file mode 100644 (file)
index 0000000..e8a4fbb
--- /dev/null
@@ -0,0 +1,16 @@
+
+
+TEMPLATE_CONTEXT_PROCESSORS = (
+    "telecaster.context_processors.host",
+)
+
+TELECASTER_MASTER_SERVER = 'teleforma.parisson.com'
+
+TELECASTER_CONF = [{'type':'mp3','server_type':'icecast','conf':'/etc/telecaster/deefuzzer/telecaster_mp3_default.xml', 'port':'8000'},
+                   {'type':'webm','server_type':'stream-m','conf':'/etc/telecaster/deefuzzer/telecaster_webm_default.xml', 'port':'8080'}, ]
+
+TELECASTER_RSYNC_SERVER = 'telecaster@jimi.parisson.com:archives/'
+
+TELECASTER_RSYNC_LOG = '/var/log/telecaster/rsync.log'
+
+
diff --git a/telecaster/context_processors.py b/telecaster/context_processors.py
new file mode 100644 (file)
index 0000000..84236d1
--- /dev/null
@@ -0,0 +1,85 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2013 Parisson SARL
+
+# This software is a computer program whose purpose is to backup, analyse,
+# transcode and stream any audio content with its metadata over a web frontend.
+
+# This software is governed by the CeCILL  license under French law and
+# abiding by the rules of distribution of free software.  You can  use,
+# modify and/ or redistribute the software under the terms of the CeCILL
+# license as circulated by CEA, CNRS and INRIA at the following URL
+# "http://www.cecill.info".
+
+# As a counterpart to the access to the source code and  rights to copy,
+# modify and redistribute granted by the license, users are provided only
+# with a limited warranty  and the software's author,  the holder of the
+# economic rights,  and the successive licensors  have only  limited
+# liability.
+
+# In this respect, the user's attention is drawn to the risks associated
+# with loading,  using,  modifying and/or developing or reproducing the
+# software by the user in light of its specific status of free software,
+# that may mean  that it is complicated to manipulate,  and  that  also
+# therefore means  that it is reserved for developers  and  experienced
+# professionals having in-depth computer knowledge. Users are therefore
+# encouraged to load and test the software's suitability as regards their
+# requirements in conditions enabling the security of their systems and/or
+# data to be ensured and,  more generally, to use and operate it in the
+# same conditions as regards security.
+
+# The fact that you are presently reading this means that you have had
+# knowledge of the CeCILL license and that you accept its terms.
+#
+# Authors: Guillaume Pellerin <yomguy@parisson.com>
+
+
+from django.conf import settings
+import socket
+import fcntl
+import struct
+
+interfaces = ['eth0', 'eth1', 'eth2', 'eth0-eth2', 'eth3', 'eth4',
+                  'wlan0', 'wlan1', 'wlan2', 'wlan3', 'wlan4']
+
+
+def get_ip_address(ifname):
+    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+    ip = socket.inet_ntoa(fcntl.ioctl(
+            s.fileno(),
+            0x8915,  # SIOCGIFADDR
+            struct.pack('256s', ifname[:15])
+            )[20:24])
+    return ip
+
+def get_local_host():
+    ip = ''
+    for interface in interfaces:
+        try:
+            ip = get_ip_address(interface)
+            if ip:
+                local_ip = ip
+                break
+        except:
+            local_ip = '127.0.0.1'
+    return local_ip
+
+
+def get_http_host(request):
+    host = request.META['REMOTE_ADDR']
+    if ':' in host:
+        host = host.split(':')[0]
+    return host
+
+
+def host(request):
+    request_host = get_http_host(request)
+    local_host = get_local_host()
+
+    if request_host.split('.')[0] == local_host.split('.')[0] or \
+                                 request_host == '127.0.0.1' or request_host == 'localhost':
+        # LAN access
+        ip = local_host
+    else:
+        ip = settings.ROUTER_IP
+
+    return {'HOST': ip }