Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 180 lines (149 sloc) 5.97 kB
ff20af9 @alobbs Adds the new admin
alobbs authored
1 import configured
2
3 # Converts from 0.99.30 to 0.99.31
4 def upgrade_to_0_99_31 (cfg):
5 # verver!_!logger!error is vserver!_!error_writer now.
6 # Must be relocated on each virtual server.
7 #
8 for v in cfg.keys('vserver'):
9 pre = 'vserver!%s' % (v)
10 if cfg['vserver!%s!logger!error' %(v)]:
11 cfg.clone ('vserver!%s!logger!error' %(v),
12 'vserver!%s!error_writer' %(v))
13 del(cfg['vserver!%s!logger!error' %(v)])
14
15 # Converts from 0.99.31-39 to 0.99.40
16 def upgrade_to_0_99_40 (cfg):
17 # The encoder related configuration changed. What used to be
18 # vserver!10!rule!600!encoder!gzip = 1 is now
19 # vserver!10!rule!600!encoder!gzip = allow
20 #
21 # There are three possible options: "allow", "deny" and empty.
22 # The previous "1" turns "allow", "0" is default so those entries
23 # are removed and the brand new "deny" key is not assigned.
24 #
25 to_del = []
26 for v in cfg.keys('vserver'):
27 for r in cfg.keys('vserver!%s!rule'%(v)):
28 if cfg['vserver!%s!rule!%s!encoder' %(v,r)]:
29 for e in cfg['vserver!%s!rule!%s!encoder' %(v,r)]:
30 pre = 'vserver!%s!rule!%s!encoder!%s' %(v,r,e)
31 if cfg.get_val(pre) == "1":
32 cfg[pre] = "allow"
33 else:
34 to_del.append(pre)
35 for pre in to_del:
36 del(cfg[pre])
37
36acdf4 @alobbs Fixes some broken configuration files caused by the 'source!None' bug,
alobbs authored
38 # Converts from 0.99.40 to 0.99.45
39 def upgrade_to_0_99_45 (cfg):
40 # Remove some broken 'source' entries:
41 # http://bugs.cherokee-project.com/768
42 if 'None' in cfg.keys('source'):
43 del (cfg['source!None'])
44
235add8 @alobbs Adds code to solve an old issue (0.99.xx series). Fixes bug #910:
alobbs authored
45 # 'icons!suffix!package.png' included the 'z' and 'Z' extensions
46 # when the property is meant to be caseless.
47 tmp = cfg.get_val('icons!suffix!package.png')
48 if tmp:
49 cfg['icons!suffix!package.png'] = tmp.replace ('Z,', '')
50
ff79141 @alobbs Adds a new stage to the automatic configuration upgrade mechanism. It
alobbs authored
51 # Converts from 0.99.45 to 1.0.7
52 def upgrade_to_1_0_7 (cfg):
53 # Adds 'check_local_file' to Extension php
54 # http://bugs.cherokee-project.com/951
55 for v in cfg.keys('vserver'):
56 for r in cfg.keys('vserver!%s!rule'%(v)):
57 if cfg.get_val('vserver!%s!rule!%s!match'%(v,r)) == 'extensions' and \
58 cfg.get_val('vserver!%s!rule!%s!match!extensions'%(v,r)) == 'php':
59 cfg['vserver!%s!rule!%s!match!check_local_file'%(v,r)] = '1'
60
88b6150 @alobbs Adds a new stage to the configuration file converter. It fixes the
alobbs authored
61 # Converts from 1.0.7 to 1.0.13
62 def upgrade_to_1_0_13 (cfg):
63 # Converts !encoder!<x> = '1' to 'allow', and remove '0's
64 for v in cfg.keys('vserver'):
65 for r in cfg.keys('vserver!%s!rule'%(v)):
66 for e in cfg.keys('vserver!%s!rule!%s!encoder'%(v,r)):
67 key = 'vserver!%s!rule!%s!encoder!%s'%(v,r,e)
68 val = cfg.get_val(key)
69 if val == '1':
70 cfg[key] = 'allow'
71 elif val == '0':
72 del(cfg[key])
73
299a8ca @davidjb Ensure configuration uses correct HTTP methods as per RFC 3253. Provi…
davidjb authored
74 # Converts to 1.2.102
75 METHODS_MAP = {'baseline_control': 'baseline-control',
76 'version_control': 'version-control'
77 }
78 def update_rules_methods(cfg, key, node):
79 if node.value == 'method':
80 method_key = '%s!method' % key
81 method_value = cfg.get_val(method_key)
82 # Check rule's method key value and replace if problematic
83 if method_value in METHODS_MAP:
84 cfg[method_key] = METHODS_MAP[method_value]
85 else:
86 for k in node.keys():
87 child_key = '%s!%s' % (key, k)
88 child_node = cfg[child_key]
89 update_rules_methods(cfg, child_key, child_node)
90
91 def upgrade_to_1_2_102 (cfg):
92 # Update HTTP method specifications for those that were incorrect
93
94 for v in cfg.keys('vserver'):
95 for r in cfg.keys('vserver!%s!rule' % (v)):
96 # Traverse rules and look for HTTP method 'match' elements
97 rule_key = 'vserver!%s!rule!%s!match' % (v,r)
98 rule_node = cfg[rule_key]
99 update_rules_methods(cfg, rule_key, rule_node)
ff20af9 @alobbs Adds the new admin
alobbs authored
100
101 def config_version_get_current():
102 ver = configured.VERSION.split ('b')[0]
103 v1,v2,v3 = ver.split (".")
104
105 major = int(v1)
106 minor = int(v2)
107 micro = int(v3)
108
109 return "%03d%03d%03d" %(major, minor, micro)
110
111
112 def config_version_cfg_is_up_to_date (cfg):
113 # Cherokee's version
114 ver_cherokee = config_version_get_current()
115
116 # Configuration file version
117 ver_config = cfg.get_val("config!version")
118 if not ver_config:
119 cfg["config!version"] = "000099028"
120 return False
121
122 # Cherokee 0.99.26 bug: 990250 is actually 99025
123 if int(ver_config) == 990250:
124 ver_config = "000099025"
125 cfg['config!version'] = ver_config
126 return False
127
128 # Compare both of them
129 if int(ver_config) > int(ver_cherokee):
130 print "WARNING!! Running a new configuration file (version %d)" % int(ver_config)
131 print " with an older version of Cherokee (version %d)" % int(ver_cherokee)
132 return True
133
134 elif int(ver_config) == int(ver_cherokee):
135 return True
136
137 else:
138 return False
139
140
141 def config_version_update_cfg (cfg):
142 # Do not proceed if it's empty
143 if not cfg.has_tree():
144 return False
145
146 # Update only when it's outdated
147 if config_version_cfg_is_up_to_date (cfg):
148 return False
149
150 ver_release_s = config_version_get_current()
151 ver_config_s = cfg.get_val("config!version")
152 ver_config_i = int(ver_config_s)
153
154 # Update to.. 0.99.31
155 if ver_config_i < 99031:
156 upgrade_to_0_99_31 (cfg)
157
158 # Update to.. 0.99.40
159 if ver_config_i < 99040:
160 upgrade_to_0_99_40 (cfg)
161
36acdf4 @alobbs Fixes some broken configuration files caused by the 'source!None' bug,
alobbs authored
162 # Update to.. 0.99.45
163 if ver_config_i < 99045:
164 upgrade_to_0_99_45 (cfg)
165
ff79141 @alobbs Adds a new stage to the automatic configuration upgrade mechanism. It
alobbs authored
166 # Update to.. 1.0.7
167 if ver_config_i < 1000007:
168 upgrade_to_1_0_7 (cfg)
169
88b6150 @alobbs Adds a new stage to the configuration file converter. It fixes the
alobbs authored
170 # Update to.. 1.0.13
171 if ver_config_i < 1000013:
172 upgrade_to_1_0_13 (cfg)
173
299a8ca @davidjb Ensure configuration uses correct HTTP methods as per RFC 3253. Provi…
davidjb authored
174 # Update to.. 1.2.102
175 if ver_config_i < 1002102:
176 upgrade_to_1_2_102 (cfg)
177
ff20af9 @alobbs Adds the new admin
alobbs authored
178 cfg["config!version"] = ver_release_s
179 return True
Something went wrong with that request. Please try again.