Changeset 8257 in genesis


Ignore:
Timestamp:
Aug 8, 2010, 8:12:51 AM (14 years ago)
Author:
rick
Message:

Ready for testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nodes/gformat.py

    r8242 r8257  
    1616__version__ = '$Id$'
    1717
    18 
    1918files = [
    2019    'authorized_keys',
     
    2524    ]
    2625
     26
     27
    2728def print_title():
    28   print "Title view"
    29   print nodelist
     29  """ Main overview page """
     30  items = {'root' : os.environ['SCRIPT_NAME'] }
     31  print """
     32<html>
     33  <head>
     34    <title>Wireless leiden Configurator - GFormat</title>
     35    <style type="text/css">
     36     th        {background-color: #999999}
     37     tr:nth-child(odd)    {background-color: #cccccc}
     38     tr:nth-child(even)   {background-color: #ffffff}
     39     th, td    {padding: 0.1em 1em}
     40    </style>
     41  </head>
     42  <body>
     43    <center>
     44    <form type="GET" action="">
     45      <input type="hidden" name="action" value="update">
     46      <input type="submit" value="Update Configuration Database (SVN)">
     47    </form>
     48    <table>
     49     <caption><h3>Wireless Leiden Configurator</h3></caption>
     50  """ % items
     51
     52  for node in sorted(nodelist):
     53    items['node'] = node
     54    print '<tr><td><a href="%(root)s/%(node)s">%(node)s</a></td>' % items
     55    for config in files:
     56      items['config'] = config
     57      print '<td><a href="%(root)s/%(node)s/%(config)s">%(config)s</a></td>' % items
     58    print "</tr>"
     59  print """
     60    </table>
     61    <hr />
     62    <em>%s</em>
     63    </center>
     64  </body>
     65</html>
     66  """ % __version__
     67
    3068
    3169
    3270def print_node(node):
     71  """ Print overview of all files available for node """
    3372  print "\n".join(files)
     73
     74
    3475
    3576def generate_header(ctag="#"):
     
    4182""" % { 'ctag' : ctag, 'date' : time.ctime(), 'host' : socket.gethostname() }
    4283
     84
     85
    4386def parseaddr(s):
     87  """ Process IPv4 CIDR notation addr to a (binary) number """
    4488  f = s.split('.')
    4589  return (long(f[0]) << 24L) + \
     
    4892    long(f[3])
    4993
     94
     95
    5096def showaddr(a):
     97  """ Display IPv4 addr in (dotted) CIDR notation """
    5198  return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff)
    5299
     100
     101
    53102def netmask2subnet(netmask):
     103  """ Given a 'netmask' return corresponding CIDR """
    54104  return showaddr(0xffffffff & (0xffffffff << (32 - int(netmask))))
    55105
     106
     107
    56108def generate_dnsmasq_conf(datadump):
     109  """ Generate configuration file '/usr/local/etc/dnsmasq.conf' """
    57110  output = generate_header()
    58111  output += """\
     
    72125
    73126    try:
    74       (dhcp_start, dhcp_stop) = datadump[iface]['dhcp'].split('-')
     127      (dhcp_start, dhcp_stop) = datadump[iface_key]['dhcp'].split('-')
    75128      (ip, netmask) = datadump[iface_key]['ip'].split('/')
    76129      datadump[iface_key]['subnet'] = netmask2subnet(netmask)
     
    86139  return output
    87140
     141
     142
    88143def generate_rc_conf_local(datadump):
     144  """ Generate configuration file '/etc/rc.conf.local' """
    89145  output = generate_header("#");
    90146  output += """\
     
    104160    output += "tproxy_enable='NO'\n"
    105161 
    106 
    107162  output += '\n'
    108163  # lo0 configuration:
     
    177232  return output
    178233
     234
     235
    179236def get_yaml(item):
     237  """ Get configuration yaml for 'item'"""
    180238  gfile = item + '/wleiden.yaml'
    181239  gfile = 'test.yaml'
     
    187245  return datadump
    188246
     247
     248
    189249def generate_resolv_conf(datadump):
     250  """ Generate configuration file '/etc/resolv.conf' """
    190251  output = generate_header("#");
    191252  output += """\
     
    207268    output += "nameserver %-15s # %s\n" % (proxy_ip, proxy)
    208269  return output
     270
    209271
    210272
     
    227289
    228290
     291
    229292def print_config(node, config):
     293  """ Print configuration file 'config' of 'node' """
    230294  try:
    231295    # Load config file
     
    257321    print "[ERROR] Config file not found"
    258322
    259 nodelist = glob.glob("CNode*")
    260 
     323
     324#
     325# Main worker
     326
     327# Update repository if requested
    261328form = cgi.FieldStorage()
    262329if form.getvalue("action") == "update":
     
    268335  sys.exit(0)
    269336
    270 print "Content-type:text/plain\r\n\r\n",
     337nodelist = glob.glob("CNode*")
     338
    271339uri = os.environ['PATH_INFO'].strip('/').split('/')
    272340if not uri[0]:
    273341  print_title()
    274342elif len(uri) == 1:
     343  print "Content-type:text/plain\r\n\r\n",
    275344  print_node(uri[0])
    276345elif len(uri) == 2:
     346  print "Content-type:text/plain\r\n\r\n",
    277347  print_config(uri[0], uri[1])
    278348else:
Note: See TracChangeset for help on using the changeset viewer.