#!/usr/bin/python
import os
import xml.dom.minidom
import re
print 'Content-TYpe: text/html\n'
form_template = '''
Nexedi DLS
'''
def getElement(my_conf, name):
return my_conf.getElementsByTagName(name) and my_conf.getElementsByTagName(name)[0].childNodes and my_conf.getElementsByTagName(name)[0].childNodes[0].data or ''
def getSelected(my_conf, name, value):
return my_conf.getElementsByTagName(name) and my_conf.getElementsByTagName(name)[0].childNodes and my_conf.getElementsByTagName(name)[0].childNodes[0].data == value and 'selected' or ''
def getTimezoneOptions(my_conf = None):
# Obtain a list of timezone files. Is there a canonical way?
timezone_list = []
for dirpath, dirnames, filenames in os.walk('/usr/share/zoneinfo'):
dirpath = dirpath[20:]
if len(dirpath) == 0 or dirpath[0].isupper():
for name in filenames:
if name[0].isupper():
timezone_list.append(os.path.join(dirpath, name))
timezone_list.sort()
timezone_options = ''
if my_conf:
cur_tz = getElement(my_conf, 'time_zone')
else:
cur_tz = None
for tz in timezone_list:
if tz == cur_tz:
selected = ' selected'
else:
selected = ''
timezone_options += '' % (selected, tz)
return timezone_options
def getLocaleOptions(my_conf = None):
# Obtain a list locales.
locale_list = []
# We want only lang_COUNTRY.
valid_pattern = re.compile('^[a-z]+_[A-Z]+$')
for path in os.listdir('/usr/share/locale'):
if valid_pattern.match(path) and os.access(os.path.join('/usr/share/locale', path, 'LC_IDENTIFICATION'), os.F_OK):
locale_list.append(path)
locale_list.sort()
locale_options = ''
if my_conf:
cur_locale = getElement(my_conf, 'system_language')
else:
cur_locale = None
for locale in locale_list:
if locale == cur_locale:
selected = ' selected'
else:
selected = ''
locale_options += '' % (selected, locale)
return locale_options
if os.access('/home/dlsadmin/nexedi-dls/config.xml', os.R_OK):
my_conf = xml.dom.minidom.parse('/home/dlsadmin/nexedi-dls/config.xml')
nameservers = getElement(my_conf, "nameservers").split()
if len(nameservers) == 0: nameservers = ['', '']
elif len(nameservers) == 1: nameservers += ['']
[nameserver1,nameserver2] = nameservers
print form_template % (getElement(my_conf, "hostname"),
getElement(my_conf, "domainname"),
'-hidden-', # getElement("root_password"),
'-hidden-', # getElement("web_password"),
getTimezoneOptions(my_conf),
getLocaleOptions(my_conf),
getSelected(my_conf, 'connection_type', 'dhcp'),
getSelected(my_conf, 'connection_type', 'static'),
getSelected(my_conf, 'network_device', 'eth0'),
getSelected(my_conf, 'network_device', 'eth1'),
getSelected(my_conf, 'network_device', 'wifi0'),
getSelected(my_conf, 'network_device', 'wlan0'),
getElement(my_conf, "ip_address"),
getElement(my_conf, "netmask"),
getElement(my_conf, "network_address"),
getElement(my_conf, "broadcast_address"),
getElement(my_conf, "gateway"),
nameserver1, nameserver2,
getElement(my_conf, "wlan_wep_key"),
getElement(my_conf, "wlan_essid"),
getElement(my_conf, "wlan_channel"),
'Configuration can only be generated once, please use drakconf or your favorite text editor for future changes.
',
'disabled')
else:
print form_template % (('',) * 4 + (getTimezoneOptions(), getLocaleOptions()) + ('',) * 18)