Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

No commit message

  • Loading branch information...
commit 757a6b25396a41deaf2cfaf769bbb8bd845ccf24 0 parents
@airtonix authored
27 avahi-add-alias
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+import os,sys
+from subprocess import Popen, PIPE
+
+args = sys.argv[1:]
+
+for alias in args :
+ alias_file = open("/etc/avahi/aliases")
+ alias_found = False
+
+ for line in alias_file :
+ line = line.rstrip("\n")
+ print("looking for [%s] to match [%s]", (alias, line) )
+ if alias == line :
+ print("%s : already exists : " % alias)
+ alias_found = True
+
+ alias_file.close()
+
+ if not alias_found :
+ print("%s : added" % alias)
+ alias_file = open("/etc/avahi/aliases","a")
+ alias_file.write("%s\n" % alias)
+ alias_file.close()
+
+os.system("avahi-publish-aliases")
+
50 avahi-publish-aliases
@@ -0,0 +1,50 @@
+#!/usr/bin/env python
+
+import os, sys
+from subprocess import Popen
+
+
+def ensure_file (path):
+ """
+ Looks for file at provided path, creates it if it does not exist.
+ Returns the file.
+ """
+ rfile = None
+ if not os.path.exists(path) and os.path.isfile(path) :
+ rfile = open(path,"w+");
+ print("ensuring file : %s " % path)
+
+ print("file ensured : %s " % path)
+ return rfile
+
+
+command = '/usr/bin/avahi-publish-domain-alias'
+alias_pid_path = "/tmp/avahi-publish-alias.pid"
+alias_file_path = "/etc/avahi/aliases"
+
+alias_file = open(alias_file_path)
+if not os.path.exists(alias_pid_path) :
+ open(alias_pid_path,"w").close()
+
+alias_pid = open(alias_pid_path,"r")
+
+
+for line in alias_pid :
+ txt = line.strip('\n')
+ if len(txt) > 0 :
+ print("kill %s" % txt )
+ os.system("kill %s" % txt)
+
+alias_pid.close()
+alias_pid = open("/tmp/avahi-publish-alias.pid","w+")
+
+for line in alias_file :
+ txt = line.strip('\n')
+ if len(txt) > 0 :
+ print("publishing : << %s >>" % txt)
+ process = Popen([command, txt])
+ alias_pid.write("%s\n" % str(process.pid))
+
+alias_pid.close()
+
+print("done")
53 avahi-publish-domain-alias
@@ -0,0 +1,53 @@
+#! /usr/bin/env python
+# avahi-alias.py
+
+import avahi, dbus
+from encodings.idna import ToASCII
+
+# Got these from /usr/include/avahi-common/defs.h
+CLASS_IN = 0x01
+TYPE_CNAME = 0x05
+
+TTL = 60
+
+def publish_cname(cname):
+ bus = dbus.SystemBus()
+ server = dbus.Interface(bus.get_object(avahi.DBUS_NAME, avahi.DBUS_PATH_SERVER),
+ avahi.DBUS_INTERFACE_SERVER)
+ group = dbus.Interface(bus.get_object(avahi.DBUS_NAME, server.EntryGroupNew()),
+ avahi.DBUS_INTERFACE_ENTRY_GROUP)
+
+ rdata = createRR(server.GetHostNameFqdn())
+ cname = encode_dns(cname)
+
+ group.AddRecord(avahi.IF_UNSPEC, avahi.PROTO_UNSPEC, dbus.UInt32(0),
+ cname, CLASS_IN, TYPE_CNAME, TTL, rdata)
+ group.Commit()
+
+
+def encode_dns(name):
+ out = []
+ for part in name.split('.'):
+ if len(part) == 0: continue
+ out.append(ToASCII(part))
+ return '.'.join(out)
+
+def createRR(name):
+ out = []
+ for part in name.split('.'):
+ if len(part) == 0: continue
+ out.append(chr(len(part)))
+ out.append(ToASCII(part))
+ out.append('\0')
+ return ''.join(out)
+
+if __name__ == '__main__':
+ import time, sys, locale
+ for each in sys.argv[1:]:
+ name = unicode(each, locale.getpreferredencoding())
+ publish_cname(name)
+ try:
+ # Just loop forever
+ while 1: time.sleep(60)
+ except KeyboardInterrupt:
+ print "Exiting"
22 avahi-remove-alias
@@ -0,0 +1,22 @@
+#!/usr/bin/env python
+import os,sys
+from subprocess import Popen, PIPE
+
+args = sys.argv[1:]
+
+for alias in args :
+
+ alias_file = open("/etc/avahi/aliases")
+ alias_output = []
+
+ for line in alias_file :
+ if line != alias :
+ alias_output.append(line)
+
+ alias_file.close()
+ alias_file = open("/etc/avahi/aliases","w")
+ alias_file.writelines(alias_output)
+ alias_file.close()
+
+os.system("avahi-publish-aliases")
+
25 install.sh
@@ -0,0 +1,25 @@
+#!/bin/sh
+#IPADDRESS=`ifconfig | head -n2 | tail -n1 | awk '{print $2}' | awk -F : '{print $2}'`
+#HOSTNAME=`avahi-resolve-host-name -a | awk '{ print $2 }'`
+SCRIPT_PATH=${0%/*}
+. $SCRIPT_PATH/lib/coloured_messages.sh
+
+message "Install Avahi Aliases Manager" "header"
+for file in `ls ./package/*`;do
+ message "${file}"
+ sudo chmod 777 ${file}
+ sudo chmod +x ${file}
+ sudo chown root:root ${file}
+ sudo cp ${file} /usr/bin/
+done
+
+message "Making avahi-aliases list directory" "header"
+message "Use this directory to place individual lists of avahi-aliases."
+sudo mkdir /etc/avahi/aliases.d/
+
+message "Making central avahi-aliases file" "header"
+sudo touch /etc/avahi/aliases
+#message "Fill this with aliases (one per line) to ${HOSTNAME}" "result"
+
+message "Installation of Avahi-Aliases Done" "success"
+
Please sign in to comment.
Something went wrong with that request. Please try again.