|
Revision 1716, 1.5 kB
(checked in by alo, 4 months ago)
|
--
|
| Line | |
|---|
| 1 |
#!/usr/bin/env python |
|---|
| 2 |
|
|---|
| 3 |
## |
|---|
| 4 |
## Cherokee 0.7.x to 0.8.x configuration converter |
|---|
| 5 |
## |
|---|
| 6 |
## Copyright: Alvaro Lopez Ortega <alvaro@alobbs.com> |
|---|
| 7 |
## Licensed: GPL v2 |
|---|
| 8 |
## |
|---|
| 9 |
|
|---|
| 10 |
import sys |
|---|
| 11 |
|
|---|
| 12 |
sys.path.append('../admin/') |
|---|
| 13 |
from config import * |
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
def save_result (content, file): |
|---|
| 17 |
tmp = content.split('\n') |
|---|
| 18 |
tmp.sort() |
|---|
| 19 |
|
|---|
| 20 |
cont = "# Converted by 07to08.py \n" |
|---|
| 21 |
cont += '\n'.join(tmp) |
|---|
| 22 |
|
|---|
| 23 |
f = open(file, "w+") |
|---|
| 24 |
f.write (cont) |
|---|
| 25 |
f.close() |
|---|
| 26 |
|
|---|
| 27 |
def domain_cmp (x, y): |
|---|
| 28 |
if x == 'default': |
|---|
| 29 |
return -1 |
|---|
| 30 |
elif y == 'default': |
|---|
| 31 |
return 1 |
|---|
| 32 |
else: |
|---|
| 33 |
return cmp (x[::-1], y[::-1]) |
|---|
| 34 |
|
|---|
| 35 |
def convert (fin, fout): |
|---|
| 36 |
n = 1 |
|---|
| 37 |
cin = Config(fin) |
|---|
| 38 |
|
|---|
| 39 |
# Sort the vservers |
|---|
| 40 |
vservers = list(cin['vserver']) |
|---|
| 41 |
vservers.sort(domain_cmp) |
|---|
| 42 |
|
|---|
| 43 |
for vserver in vservers: |
|---|
| 44 |
if vserver == 'default': |
|---|
| 45 |
prio = 1 |
|---|
| 46 |
else: |
|---|
| 47 |
n += 1 |
|---|
| 48 |
prio = n |
|---|
| 49 |
|
|---|
| 50 |
# Rename the virtual server entry |
|---|
| 51 |
to = "vserver!%03d" % (prio) |
|---|
| 52 |
orig = "vserver!%s" % (vserver) |
|---|
| 53 |
cin.rename (orig, to) |
|---|
| 54 |
|
|---|
| 55 |
# Add the 'nick' and 'domain' properties |
|---|
| 56 |
cin['%s!nick'%(to)] = vserver |
|---|
| 57 |
if not cin['%s!domain'%(to)]: |
|---|
| 58 |
cin['%s!domain!1'%(to)] = vserver |
|---|
| 59 |
|
|---|
| 60 |
save_result (str(cin), fout) |
|---|
| 61 |
|
|---|
| 62 |
|
|---|
| 63 |
def main (): |
|---|
| 64 |
if len(sys.argv) < 3: |
|---|
| 65 |
print "USAGE:" |
|---|
| 66 |
print " %s /path/cherokee.conf.07 /path/cherokee.conf.08" % (sys.argv[0]) |
|---|
| 67 |
print |
|---|
| 68 |
raise SystemExit |
|---|
| 69 |
|
|---|
| 70 |
convert (sys.argv[1], sys.argv[2]) |
|---|
| 71 |
|
|---|
| 72 |
if __name__ == "__main__": |
|---|
| 73 |
main() |
|---|