/usr/share/cherokee/admin/config_version.py is in cherokee-admin 1.2.101-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | import configured
# Converts from 0.99.30 to 0.99.31
def upgrade_to_0_99_31 (cfg):
# verver!_!logger!error is vserver!_!error_writer now.
# Must be relocated on each virtual server.
#
for v in cfg.keys('vserver'):
pre = 'vserver!%s' % (v)
if cfg['vserver!%s!logger!error' %(v)]:
cfg.clone ('vserver!%s!logger!error' %(v),
'vserver!%s!error_writer' %(v))
del(cfg['vserver!%s!logger!error' %(v)])
# Converts from 0.99.31-39 to 0.99.40
def upgrade_to_0_99_40 (cfg):
# The encoder related configuration changed. What used to be
# vserver!10!rule!600!encoder!gzip = 1 is now
# vserver!10!rule!600!encoder!gzip = allow
#
# There are three possible options: "allow", "deny" and empty.
# The previous "1" turns "allow", "0" is default so those entries
# are removed and the brand new "deny" key is not assigned.
#
to_del = []
for v in cfg.keys('vserver'):
for r in cfg.keys('vserver!%s!rule'%(v)):
if cfg['vserver!%s!rule!%s!encoder' %(v,r)]:
for e in cfg['vserver!%s!rule!%s!encoder' %(v,r)]:
pre = 'vserver!%s!rule!%s!encoder!%s' %(v,r,e)
if cfg.get_val(pre) == "1":
cfg[pre] = "allow"
else:
to_del.append(pre)
for pre in to_del:
del(cfg[pre])
# Converts from 0.99.40 to 0.99.45
def upgrade_to_0_99_45 (cfg):
# Remove some broken 'source' entries:
# http://bugs.cherokee-project.com/768
if 'None' in cfg.keys('source'):
del (cfg['source!None'])
# 'icons!suffix!package.png' included the 'z' and 'Z' extensions
# when the property is meant to be caseless.
tmp = cfg.get_val('icons!suffix!package.png')
if tmp:
cfg['icons!suffix!package.png'] = tmp.replace ('Z,', '')
# Converts from 0.99.45 to 1.0.7
def upgrade_to_1_0_7 (cfg):
# Adds 'check_local_file' to Extension php
# http://bugs.cherokee-project.com/951
for v in cfg.keys('vserver'):
for r in cfg.keys('vserver!%s!rule'%(v)):
if cfg.get_val('vserver!%s!rule!%s!match'%(v,r)) == 'extensions' and \
cfg.get_val('vserver!%s!rule!%s!match!extensions'%(v,r)) == 'php':
cfg['vserver!%s!rule!%s!match!check_local_file'%(v,r)] = '1'
# Converts from 1.0.7 to 1.0.13
def upgrade_to_1_0_13 (cfg):
# Converts !encoder!<x> = '1' to 'allow', and remove '0's
for v in cfg.keys('vserver'):
for r in cfg.keys('vserver!%s!rule'%(v)):
for e in cfg.keys('vserver!%s!rule!%s!encoder'%(v,r)):
key = 'vserver!%s!rule!%s!encoder!%s'%(v,r,e)
val = cfg.get_val(key)
if val == '1':
cfg[key] = 'allow'
elif val == '0':
del(cfg[key])
def config_version_get_current():
ver = configured.VERSION.split ('b')[0]
v1,v2,v3 = ver.split (".")
major = int(v1)
minor = int(v2)
micro = int(v3)
return "%03d%03d%03d" %(major, minor, micro)
def config_version_cfg_is_up_to_date (cfg):
# Cherokee's version
ver_cherokee = config_version_get_current()
# Configuration file version
ver_config = cfg.get_val("config!version")
if not ver_config:
cfg["config!version"] = "000099028"
return False
# Cherokee 0.99.26 bug: 990250 is actually 99025
if int(ver_config) == 990250:
ver_config = "000099025"
cfg['config!version'] = ver_config
return False
# Compare both of them
if int(ver_config) > int(ver_cherokee):
print "WARNING!! Running a new configuration file (version %d)" % int(ver_config)
print " with an older version of Cherokee (version %d)" % int(ver_cherokee)
return True
elif int(ver_config) == int(ver_cherokee):
return True
else:
return False
def config_version_update_cfg (cfg):
# Do not proceed if it's empty
if not cfg.has_tree():
return False
# Update only when it's outdated
if config_version_cfg_is_up_to_date (cfg):
return False
ver_release_s = config_version_get_current()
ver_config_s = cfg.get_val("config!version")
ver_config_i = int(ver_config_s)
# Update to.. 0.99.31
if ver_config_i < 99031:
upgrade_to_0_99_31 (cfg)
# Update to.. 0.99.40
if ver_config_i < 99040:
upgrade_to_0_99_40 (cfg)
# Update to.. 0.99.45
if ver_config_i < 99045:
upgrade_to_0_99_45 (cfg)
# Update to.. 1.0.7
if ver_config_i < 1000007:
upgrade_to_1_0_7 (cfg)
# Update to.. 1.0.13
if ver_config_i < 1000013:
upgrade_to_1_0_13 (cfg)
cfg["config!version"] = ver_release_s
return True
|