Commit 9bd5527e authored by Zenon Mousmoulas's avatar Zenon Mousmoulas

Finish the servdata consumer script (including changes

necessary for templates).
parent 1a81f10a
......@@ -7,9 +7,9 @@ import re
#{{{${' ' + inst['id'] if 'id' in inst else ''}
% for client in inst['clients']:
client ${client} {
secret = ${hosts[client]['secret']}
secret = ${clients[client]['secret']}
<%
ipaddr = re.split(r'/(?=[0-9]{1,2}$)', hosts[client]['host'])
ipaddr = re.split(r'/(?=[0-9]{1,2}$)', clients[client]['host'])
%>\
ipaddr = ${ipaddr[0]}
% if len(ipaddr) > 1:
......
......@@ -32,15 +32,15 @@ for srv in inst_servers:
</%doc>\
% for srv in set([s for r in inst['realms'] for s in inst['realms'][r]['proxy_to'] if 'proxy_to' in inst['realms'][r]]):
home_server ${srv} {
type = ${hosts[srv]['rad_pkt_type']}
ipaddr = ${hosts[srv]['host']}
port = ${hosts[srv]['auth_port'] if hosts[srv]['rad_pkt_type'] in ('auth', 'auth+acct') else hosts[srv]['acct_port']}
secret = ${hosts[srv]['secret']}
type = ${servers[srv]['rad_pkt_type']}
ipaddr = ${servers[srv]['host']}
port = ${servers[srv]['auth_port'] if servers[srv]['rad_pkt_type'] in ('auth', 'auth+acct') else servers[srv]['acct_port']}
secret = ${servers[srv]['secret']}
response_window = 20
zombie_period = 40
revive_interval = 120
status_check = ${'status-server' if hosts[srv]['status_server'] else 'request'}
% if not hosts[srv]['status_server']:
status_check = ${'status-server' if servers[srv]['status_server'] else 'request'}
% if not servers[srv]['status_server']:
username = "eduroam-status_check"
password = "eduroam-status_check"
% endif
......
......@@ -4,7 +4,7 @@
import sys, os
import re
from optparse import OptionParser, OptionValueError, OptionGroup
import argparse
from yaml import load
try:
from yaml import \
......@@ -15,6 +15,18 @@ import requests
from mako.template import Template
from mako.lookup import TemplateLookup
SETTINGS = {
"template_directory" : "/srv/www/djnro/extras",
"template_cc_dir" : "/tmp",
"templates" : [ "freeradius-clients",
"freeradius-proxy",
"radsecproxy" ],
"description" :
"""This program reads "servdata" and produces
configuration for various software using the respective
templates."""
}
def exit_with_error(msg = ""):
sys.stderr.write(msg + "\n")
sys.exit(1)
......@@ -88,37 +100,62 @@ class ServerDataWriter:
return t.render(**self.tpls.parmap[tpl])
def main():
sr = ServerDataReader('https://www.eduroam.gr/static/admins/serv_data')
parser = argparse.ArgumentParser(
description=SETTINGS["description"],
)
parser.add_argument('--input',
required=True,
help="""read servdata from this
file or http(s) URL"""
)
parser.add_argument('--tpl-dir',
action='append',
help="""look for templates in this
directory (may be used more than once) [default: %s]"""
% SETTINGS["template_directory"]
)
parser.add_argument('--tpl-cc',
help="""compile templates
(written by default to %(const)s)""",
nargs='?',
const=SETTINGS["template_cc_dir"])
for t in SETTINGS["templates"]:
parser.add_argument('--%s' % t,
metavar=t.replace("-", "_").upper(),
help="""generate %(dest)s output
(write to %(metavar)s or stdout)""",
nargs='?',
type=argparse.FileType('w'),
const=sys.stdout,
default=None)
opts = parser.parse_args()
sr = ServerDataReader(opts.input)
tpls = { 'files': {},
'parmap': {} }
for t in SETTINGS["templates"]:
tpls['files'][t] = "%s.tpl" % t
tpls['parmap'][t] = {
"insts": sr.get_data('institutions'),
"clients": sr.get_data('clients'),
"servers": sr.get_data('servers')
}
if opts.tpl_dir is None:
opts.tpl_dir = [SETTINGS["template_directory"]]
sw_kwargs = { "tpls": tpls,
"tpldirs": opts.tpl_dir }
if opts.tpl_cc:
sw_kwargs.update({ "tplccdir": opts.tpl_cc })
sw = ServerDataWriter(**sw_kwargs)
t = 'freeradius-clients'
tpls['files'][t] = "%s.tpl" % t
tpls['parmap'][t] = {
"insts": sr.get_data('institutions'),
"hosts": sr.get_data('clients')
}
t = 'freeradius-proxy'
tpls['files'][t] = "%s.tpl" % t
tpls['parmap'][t] = {
"insts": sr.get_data('institutions'),
"hosts": sr.get_data('servers')
}
t = 'radsecproxy'
tpls['files'][t] = "%s.tpl" % t
tpls['parmap'][t] = {
"insts": sr.get_data('institutions'),
"clients": sr.get_data('clients'),
"servers": sr.get_data('servers')
}
sw = ServerDataWriter(tplccdir="/tmp",
tpldirs=["/home/zmousm"],
tpls=tpls)
print sw.render_tpl('radsecproxy')
for t in SETTINGS["templates"]:
to = t.replace('-', '_')
if getattr(opts, to, None) is not None:
getattr(opts, to).write(sw.render_tpl(t))
if __name__ == "__main__":
main()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment