]>
jfr.im git - irc/quakenet/snircd.git/blob - tools/convert-conf.py
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.8 2005/04/25 04:04:17 isomer Exp $
33 f
= open(sys
.argv
[1], "r")
39 feats
= [ ("OPLEVELS","FALSE")]
44 "LOG", "DOMAINNAME", "RELIABLE_CLOCK", "BUFFERPOOL",
45 "HAS_FERGUNSON_FLUSHER", "CLIENT_FLOOD", "SERVER_PORT", "NODEFAULTMOTD",
46 "MOTD_BANNER", "KILL_IPMISMATCH", "IDLE_FROM_MSG", "HUB",
47 "WALLOPS_OPER_ONLY", "NODNS", "RANDOM_SEED", "DEFAULT_LIST_PARAM",
48 "NICKNAMEHISTORYLENGTH", "NETWORK", "HOST_HIDING", "HIDDEN_HOST",
49 "HIDDEN_IP", "KILLCHASETIMELIMIT", "MAXCHANNELSPERUSER", "NICKLEN",
50 "AVBANLEN", "MAXBANS", "MAXSILES", "HANGONGOODLINK", "HANGONRETRYDELAY",
51 "CONNECTTIMEOUT", "MAXIMUM_LINKS", "PINGFREQUENCY", "CONNECTFREQUENCY",
52 "DEFAULTMAXSENDQLENGTH", "GLINEMAXUSERCOUNT", "MPATH", "RPATH", "PPATH",
53 "TOS_SERVER", "TOS_CLIENT", "POLLS_PER_LOOP", "IRCD_RES_TIMEOUT",
54 "IRCD_RES_RETRIES", "AUTH_TIMEOUT", "IPCHECK_CLONE_LIMIT",
55 "IPCHECK_CLONE_PERIOD", "IPCHECK_CLONE_DELAY", "CONFIG_OPERCMDS",
56 "OPLEVELS", "LOCAL_CHANNELS", "ANNOUNCE_INVITES", "HIS_SNOTICES",
57 "HIS_DEBUG_OPER_ONLY", "HIS_WALLOPS", "HIS_MAP", "HIS_LINKS",
58 "HIS_TRACE", "HIS_STATS_a", "HIS_STATS_c", "HIS_STATS_d", "HIS_STATS_e",
59 "HIS_STATS_f", "HIS_STATS_g", "HIS_STATS_i", "HIS_STATS_j",
60 "HIS_STATS_J", "HIS_STATS_k", "HIS_STATS_l", "HIS_STATS_L",
61 "HIS_STATS_m", "HIS_STATS_M", "HIS_STATS_o", "HIS_STATS_p",
62 "HIS_STATS_q", "HIS_STATS_r", "HIS_STATS_R", "HIS_STATS_t",
63 "HIS_STATS_T", "HIS_STATS_u", "HIS_STATS_U", "HIS_STATS_v",
64 "HIS_STATS_v", "HIS_STATS_w", "HIS_STATS_x", "HIS_STATS_z",
65 "HIS_WHOIS_SERVERNAME", "HIS_WHOIS_IDLETIME", "HIS_WHOIS_LOCALCHAN",
66 "HIS_WHO_SERVERNAME", "HIS_WHO_HOPCOUNT"," HIS_BANWHO", "HIS_KILLWHO",
67 "HIS_REWRITE", "HIS_REMOTE", "HIS_NETSPLIT", "HIS_SERVERNAME",
68 "HIS_SERVERINFO", "HIS_URLSERVERS"
70 deprecated_features
= [
74 # [ "old feature" => ( local oper priv, global oper priv ) ]
75 # None means don't add this
77 "UNLIMIT_OPER_QUERY" : ("unlimit_query","unlimit_query"),
78 "OPER_WALK_THROUGH_LMODES" : (None, "walk_lchan"),
79 "NO_OPER_DEOP_LCHAN" : (None, "deop_lchan"),
83 return replace(s
,'"','\\"')
86 return str(int(strip(s
)))
91 print "\tname = \"%s\";" % qstr(parts
[1])
95 for i
in split(parts
[2],","):
99 if not connects
.has_key(lower(parts
[3])):
100 connects
[lower(parts
[3])]={
101 "name" : lower(parts
[3])
103 connects
[lower(parts
[3])]["hub"] = parts
[1]
106 if not connects
.has_key(lower(parts
[3])):
107 connects
[lower(parts
[3])]={
108 "name" : lower(parts
[3])
110 del connects
[lower(parts
[3])]["hub"]
114 print "\tport = %s;" % istr(parts
[4])
116 print "\tmask = \"%s\";" % qstr(parts
[1])
118 print "\tvhost = \"%s\";" % qstr(parts
[2])
119 if count(parts
[3], 'S'):
120 print "\tserver = yes;"
121 if count(parts
[3], 'H'):
122 print "\thidden = yes;"
127 feats
.append((parts
[1], parts
[2]))
131 sys
.stderr
.write("WARNING: Wrong number of parameters on line %i\n" % lno
)
133 letter
,host
,reason
,user
=parts
137 sys
.stderr
.write("WARNING: Empty realname kline on line %i\n" % lno
)
139 print '\thost = "%s@*";' % qstr(user
)
140 print "\trealname = \"%s\";" % qstr(host
[2:])
142 print "\thost = \"%s@%s\";" % (qstr(user
),qstr(host
))
144 print "\tfile = \"%s\";" % qstr(reason
[1:])
146 print "\treason = \"%s\";" % qstr(reason
)
152 sys
.stderr
.write("WARNING: I:line doesn't have enough fields on line %i\n" % lno
)
154 iline
,ip
,password
,hostname
,dummy
,clss
= parts
156 mask
= [ip
,hostname
][i
]
157 # Ignore things that aren't masks
158 if "." not in mask
and "*" not in mask
and "@" not in mask
:
161 user
,host
= split(mask
,"@")
164 if i
==0 and not re
.match("^[0-9\.\*]+$",host
):
165 sys
.stderr
.write("WARNING: Bad IP mask in line %s (%s)\n" % (lno
,repr(mask
)))
168 if re
.match("^[1-9][1-9]?$",password
):
169 print "\tmaxlinks = %s;" % int(password
)
171 print "\tpassword = \"%s\";" % qstr(password
)
172 print "\tclass = \"%s\";" % clss
174 print "\tip = \"%s\";" % qstr(host
)
176 print "\thost = \"%s\";" % qstr(host
)
178 print "\tusername = \"%s\";" % qstr(user
)
184 if not connects
.has_key(name
):
186 connects
[name
]["host"]=parts
[1]
187 connects
[name
]["password"]=parts
[2]
188 connects
[name
]["name"]=parts
[3]
189 if parts
[4].strip()!="":
190 connects
[name
]["port"]=parts
[4]
191 connects
[name
]["class"]=parts
[5]
195 print '\t"%s" = "%s";' % (qstr(parts
[1]),qstr(parts
[2]))
202 'M': ('General', ('name', 'vhost', 'description', '-', '!numeric'), ''),
203 'A': ('Admin', ('location', 'contact', 'contact'), ''),
204 'Y': ('Class', ('name', '!pingfreq', '!connectfreq', '!maxlinks', '!sendq'), ''),
206 'T': ('motd', ('host', 'file'), ''),
213 'D': ('CRULE', ('server', '', 'rule'), '\tall = yes;'),
214 'd': ('CRULE', ('server', '', 'rule'), ''),
217 'Q': ('Quarintine', ('channel','reason', '', '', ''), ''),
223 for line
in f
.readlines():
232 parts
= split(line
, ":")
234 # This statemachine is pretty much directly stolen from ircu
235 # to give an "authentic" parser :)
246 parts
[-1]=parts
[-1]+i
252 parts
[-1]=parts
[-1]+i
255 parts
[-1]=parts
[-1]+"\b\f\n\r\t\v"[index("bfnrtv",i
)]
257 parts
[-1]=parts
[-1]+i
260 sys
.stderr
.write("WARNING: No closing quote on line %i\n"%lno
)
263 if not cvtmap
.has_key(parts
[0]):
264 print "#Unknown:",line
266 if callable(cvtmap
[parts
[0]]):
267 cvtmap
[parts
[0]](parts
)
269 (block
, items
, extra
) = cvtmap
[parts
[0]]
274 if idx
>= len(parts
):
276 # This field is ignored
279 if len(parts
[idx
]) and not len(item
):
280 sys
.stderr
.write("WARNING: Unknown field %i on line %i\n" % (idx
,lno
))
281 if len(parts
[idx
]) and len(item
):
283 print "\t%s = %s;" % (item
[1:], istr(parts
[idx
]))
285 print "\t%s = \"%s\";" % (item
, qstr(parts
[idx
]))
295 print '\tname = "%s";' % qstr(i
[3])
296 print '\thost = "%s";' % qstr(i
[1])
297 print '\tpassword = "%s";' % qstr(i
[2])
298 print '\tclass = "%s";' % qstr(i
[5])
300 print '\tlocal = no;'
302 print '\tlocal = yes;'
304 if (j
[0].startswith("LOCOP_") and i
[0]=='o'):
306 if j
[1].lower()=="true":
307 print '\t%s = yes;'% (j
[0][6:].lower())
309 print '\t%s = no;' % (j
[0][6:].lower())
310 if (j
[0].startswith("OPER_") and i
[0]=='O'):
311 if j
[1].lower()=="true":
312 print '\t%s = yes;'% (j
[0][5:].lower())
314 print '\t%s = no;' % (j
[0][5:].lower())
315 if feature_to_priv
.has_key(j
[0]):
316 if i
[0]=="o" and feature_to_priv
[j
[0]][0]:
317 if j
[1].lower()=="true":
318 print '\t%s = yes;' % feature_to_priv
[j
[0]][0]
320 print '\t%s = yes;' % feature_to_priv
[j
[0]][0]
321 if i
[0]=="O" and feature_to_priv
[j
[0]][1]:
322 if j
[1].lower()=="true":
323 print '\t%s = yes;' % feature_to_priv
[j
[0]][1]
325 print '\t%s = yes;' % feature_to_priv
[j
[0]][1]
332 print "\tnick = \"%s\";" % qstr(nick
)
336 if len(connects
.keys()):
337 for i
in connects
.keys():
339 print "\tname = \"%s\";" % qstr(connects
[i
]["name"])
340 print "\thost = \"%s\";" % qstr(connects
[i
]["host"])
341 print "\tpassword = \"%s\";" % qstr(connects
[i
]["password"])
342 if connects
[i
].has_key("port"):
343 print "\tport = %s;" % connects
[i
]["port"]
344 print "\tclass = \"%s\";" % qstr(connects
[i
]["class"])
345 if connects
[i
].has_key("hub"):
346 print "\thub = \"%s\";" % qstr(connects
[i
]["hub"])
349 if not connects
[i
].has_key("port"):
350 print "# You can now specify ports without implying autoconnect"
351 print "#\tport = 4400;"
352 print "\tautoconnect = no;"
353 sys
.stderr
.write("NOTE: You should add a port for \"%s\", autoconnect is now specified seperately\n" % qstr(connects
[i
]["name"]))
359 for (name
, value
) in feats
:
360 if name
in useable_features
:
361 print "\t\"%s\" = \"%s\";" % (qstr(name
), qstr(value
))
363 if feature_to_priv
.has_key(name
):
364 print '# Option converted to privilege "%s"' % \
365 qstr(feature_to_priv
[name
][1])
366 elif name
.startswith("LOCOP_"):
367 print "# Option converted to locop privilege"
368 elif name
.startswith("OPER_"):
369 print "# Option converted to oper privilege"
370 elif name
in deprecated_features
:
371 print "# Option is deprecated"
373 print "# Unknown option"
374 sys
.stderr
.write("WARNING: Unknown option \"%s\"\n" % qstr(name
))
375 print "#\t\"%s\" = \"%s\";" % (qstr(name
), qstr(value
))