Permalink
Browse files

changes

  • Loading branch information...
1 parent 60c82f4 commit 791c455eaf606cf3dc9e2593159b7b33d33238d5 @airtonix committed May 20, 2011
Showing with 0 additions and 152 deletions.
  1. +0 −27 avahi-add-alias
  2. +0 −50 avahi-publish-aliases
  3. +0 −53 avahi-publish-domain-alias
  4. +0 −22 avahi-remove-alias
View
@@ -1,27 +0,0 @@
-#!/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")
-
View
@@ -1,50 +0,0 @@
-#!/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")
View
@@ -1,53 +0,0 @@
-#! /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"
View
@@ -1,22 +0,0 @@
-#!/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")
-

0 comments on commit 791c455

Please sign in to comment.