Changeset 8257 in genesis
- Timestamp:
- Aug 8, 2010, 8:12:51 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
nodes/gformat.py
r8242 r8257 16 16 __version__ = '$Id$' 17 17 18 19 18 files = [ 20 19 'authorized_keys', … … 25 24 ] 26 25 26 27 27 28 def 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 30 68 31 69 32 70 def print_node(node): 71 """ Print overview of all files available for node """ 33 72 print "\n".join(files) 73 74 34 75 35 76 def generate_header(ctag="#"): … … 41 82 """ % { 'ctag' : ctag, 'date' : time.ctime(), 'host' : socket.gethostname() } 42 83 84 85 43 86 def parseaddr(s): 87 """ Process IPv4 CIDR notation addr to a (binary) number """ 44 88 f = s.split('.') 45 89 return (long(f[0]) << 24L) + \ … … 48 92 long(f[3]) 49 93 94 95 50 96 def showaddr(a): 97 """ Display IPv4 addr in (dotted) CIDR notation """ 51 98 return "%d.%d.%d.%d" % ((a >> 24) & 0xff, (a >> 16) & 0xff, (a >> 8) & 0xff, a & 0xff) 52 99 100 101 53 102 def netmask2subnet(netmask): 103 """ Given a 'netmask' return corresponding CIDR """ 54 104 return showaddr(0xffffffff & (0xffffffff << (32 - int(netmask)))) 55 105 106 107 56 108 def generate_dnsmasq_conf(datadump): 109 """ Generate configuration file '/usr/local/etc/dnsmasq.conf' """ 57 110 output = generate_header() 58 111 output += """\ … … 72 125 73 126 try: 74 (dhcp_start, dhcp_stop) = datadump[iface ]['dhcp'].split('-')127 (dhcp_start, dhcp_stop) = datadump[iface_key]['dhcp'].split('-') 75 128 (ip, netmask) = datadump[iface_key]['ip'].split('/') 76 129 datadump[iface_key]['subnet'] = netmask2subnet(netmask) … … 86 139 return output 87 140 141 142 88 143 def generate_rc_conf_local(datadump): 144 """ Generate configuration file '/etc/rc.conf.local' """ 89 145 output = generate_header("#"); 90 146 output += """\ … … 104 160 output += "tproxy_enable='NO'\n" 105 161 106 107 162 output += '\n' 108 163 # lo0 configuration: … … 177 232 return output 178 233 234 235 179 236 def get_yaml(item): 237 """ Get configuration yaml for 'item'""" 180 238 gfile = item + '/wleiden.yaml' 181 239 gfile = 'test.yaml' … … 187 245 return datadump 188 246 247 248 189 249 def generate_resolv_conf(datadump): 250 """ Generate configuration file '/etc/resolv.conf' """ 190 251 output = generate_header("#"); 191 252 output += """\ … … 207 268 output += "nameserver %-15s # %s\n" % (proxy_ip, proxy) 208 269 return output 270 209 271 210 272 … … 227 289 228 290 291 229 292 def print_config(node, config): 293 """ Print configuration file 'config' of 'node' """ 230 294 try: 231 295 # Load config file … … 257 321 print "[ERROR] Config file not found" 258 322 259 nodelist = glob.glob("CNode*") 260 323 324 # 325 # Main worker 326 327 # Update repository if requested 261 328 form = cgi.FieldStorage() 262 329 if form.getvalue("action") == "update": … … 268 335 sys.exit(0) 269 336 270 print "Content-type:text/plain\r\n\r\n", 337 nodelist = glob.glob("CNode*") 338 271 339 uri = os.environ['PATH_INFO'].strip('/').split('/') 272 340 if not uri[0]: 273 341 print_title() 274 342 elif len(uri) == 1: 343 print "Content-type:text/plain\r\n\r\n", 275 344 print_node(uri[0]) 276 345 elif len(uri) == 2: 346 print "Content-type:text/plain\r\n\r\n", 277 347 print_config(uri[0], uri[1]) 278 348 else:
Note:
See TracChangeset
for help on using the changeset viewer.