3 # IRC - Internet Relay Chat, tools/convert-conf.py
4 # Copyright (C) 2002 Alex Badea <vampire@p16.pub.ro>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 1, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 # Configuration file converter from 2.10.11 to 2.10.12 format
23 # convert-conf.py < old.conf > new.conf
25 # $Id: convert-conf.py,v 1.2 2005-02-19 21:50:48 isomer Exp $
33 f = open(sys.argv[1], "r")
39 feats = [ ("OPLEVELS","FALSE")]
42 return replace(s,'"','\\"')
45 return str(int(strip(s)))
50 print "\tname = \"%s\";" % qstr(parts[1])
54 for i in split(parts[2],","):
58 if not connects.has_key(lower(parts[3])):
59 connects[lower(parts[3])]={
60 "name" : lower(parts[3])
62 connects[lower(parts[3])]["hub"] = parts[1]
65 if not connects.has_key(lower(parts[3])):
66 connects[lower(parts[3])]={
67 "name" : lower(parts[3])
69 del connects[lower(parts[3])]["hub"]
73 print "\tport = %s;" % istr(parts[4])
75 print "\tmask = \"%s\";" % qstr(parts[1])
77 print "\tvhost = \"%s\";" % qstr(parts[2])
78 if count(parts[3], 'S'):
79 print "\tserver = yes;"
80 if count(parts[3], 'H'):
81 print "\thidden = yes;"
86 feats.append((parts[1], parts[2]))
90 sys.stderr.write("WARNING: Wrong number of parameters on line %i\n" % lno)
92 letter,host,reason,user=parts
96 sys.stderr.write("WARNING: Empty realname kline on line %i\n" % lno)
97 print "\trealname = \"%s\";" % qstr(host[2:])
99 print "\thost = \"%s@%s\";" % (qstr(user),qstr(host))
101 print "\tfile = \"%s\";" % qstr(reason[1:])
103 print "\treason = \"%s\";" % qstr(reason)
109 sys.stderr.write("WARNING: I:line doesn't have enough fields on line %i\n" % lno)
111 iline,ip,password,host,dummy,clss = parts
114 # Ignore things that aren't masks
115 if "." not in mask and "*" not in mask and "@" not in mask:
118 user,host = split(mask,"@")
121 if i==0 and not re.match("^[0-9\.\*]+$",host):
122 sys.stderr.write("WARNING: Bad IP mask in line %s (%s)\n" % (lno,repr(mask)))
125 if re.match("^[1-9][1-9]?$",password):
126 print "\tmaxlinks = %s;" % int(password)
128 print "\tpassword = \"%s\";" % qstr(password)
129 print "\tclass = \"%s\";" % clss
131 print "\tip = \"%s\";" % qstr(host)
133 print "\thost = \"%s\";" % qstr(host)
135 print "\tusername = \"%s\";" % qstr(user)
141 if not connects.has_key(name):
143 connects[name]["host"]=parts[1]
144 connects[name]["password"]=parts[2]
145 connects[name]["name"]=parts[3]
146 connects[name]["port"]=parts[4]
147 connects[name]["class"]=parts[5]
150 'M': ('General', ('name', 'vhost', 'description', '', '!numeric'), ''),
151 'A': ('Admin', ('location', 'contact', 'contact'), ''),
152 'Y': ('Class', ('name', '!pingfreq', '!connectfreq', '!maxlinks', '!sendq'), ''),
154 'T': ('motd', ('host', 'file'), ''),
161 'D': ('CRULE', ('server', '', 'rule'), '\tall = yes;'),
162 'd': ('CRULE', ('server', '', 'rule'), ''),
163 'O': ('Operator', ('host', 'password', 'name', '', 'class'), '\tlocal = no;'),
164 'o': ('Operator', ('host', 'password', 'name', '', 'class'), '\tlocal = yes;'),
170 for line in f.readlines():
179 parts = split(line, ":")
181 # This statemachine is pretty much directly stolen from ircu
182 # to give an "authentic" parser :)
193 parts[-1]=parts[-1]+i
199 parts[-1]=parts[-1]+i
202 parts[-1]=parts[-1]+"\b\f\n\r\t\v"[index("bfnrtv",i)]
204 parts[-1]=parts[-1]+i
207 sys.stderr.write("WARNING: No closing quote on line %i\n"%lno)
210 if not cvtmap.has_key(parts[0]):
211 print "#Unknown:",line
213 if callable(cvtmap[parts[0]]):
214 cvtmap[parts[0]](parts)
216 (block, items, extra) = cvtmap[parts[0]]
221 if idx >= len(parts):
223 if len(parts[idx]) and len(item):
225 print "\t%s = %s;" % (item[1:], istr(parts[idx]))
227 print "\t%s = \"%s\";" % (item, qstr(parts[idx]))
237 print "\tnick = \"%s\";" % qstr(nick)
241 if len(connects.keys()):
242 for i in connects.keys():
244 print "\tname = \"%s\";" % qstr(connects[i]["name"])
245 print "\thost = \"%s\";" % qstr(connects[i]["host"])
246 print "\tpassword = \"%s\";" % qstr(connects[i]["password"])
247 print "\tport = %s;" % connects[i]["port"]
248 print "\tclass = \"%s\";" % qstr(connects[i]["class"])
249 if connects[i].has_key("hub"):
250 print "\thub = \"%s\";" % qstr(connects[i]["hub"])
252 print "\tleaf = \"yes\";"
258 for (name, value) in feats:
259 print "\t\"%s\" = \"%s\";" % (qstr(name), qstr(value))