#!/usr/bin/python import cgi import os import re import urllib hostname_file = "/tmp/nexedi-dls_dyndns-hostname" def executeCommand(command): try: f=os.popen(command, 'r') try: command_result=f.readlines() finally: f.close() except IOError: command_result="" return command_result #header print "Content-Type: text/html" print print ''' Nexedi DLS

Desktop Linux Server

Home

Initial Configuration

Dynamic DNS

Users Managment

VNC Clients

''' form = cgi.FieldStorage() action = len(form.getlist('action')) and form.getlist('action')[0] or 'display_form' hostname = len(form.getlist('hostname')) and form.getlist('hostname')[0] or '' ipaddress = len(form.getlist('ipaddress')) and form.getlist('ipaddress')[0] or '' if action == 'display_form' : print '
' print '''''' if action == 'display_form' : # Fetches hostname try : f = open(hostname_file) try : hostname = f.readline() finally : f.close() except IOError : hostname = '' # determines DLS IP address f = os.popen('/sbin/ip address show', 'r') ip_addr_lines = f.readlines() f.close() for line in ip_addr_lines : if 'inet ' in line and 'scope global' in line : ip_addr=re.sub("^.*inet ([0-9]+(\.[0-9]+){3})/[0-9]+.*$", "\\1", line) break # displays form print '''''' % (hostname, ip_addr) elif action == 'register' : # Stores hostname try : f = open(hostname_file, 'w') try : f.write(hostname) finally : f.close() except IOError : pass # sends request and gets result result = 'Unknown error' try : f = urllib.urlopen('http://dls.nexedi.org/cgi-bin/dyndns.cgi?hostname=%s&ipaddress=%s' % (hostname, ipaddress)) try : result = f.readline() finally : f.close() except IOError, data : result = 'Error : %s' % data.strerror.args[1] print "" % result print '
Dynamic DNS registration
Hostname The name will be hostname.dls.nexedi.org
It must be specific enough to guarantee you it will be unique, our system does not detect collisions.
IP address This system's address was autodetected, but you can change it, if you are sure of what you do.
%s
' if action == 'display_form' : print '''  
''' #footer print '''
'''