3 # phpwiki configuration file migration script
4 # index.php => config.ini
6 # Author: Matt Brown <matt@mattb.net.nz>,
7 # Reini Urban <rurban@x-ray.at>
10 # Run this script without any arguments for usage information.
12 # This script is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU General Public License as published by
14 # the Free Software Foundation; either version 2 of the License, or
15 # (at your option) any later version.
17 # PhpWiki is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
22 # You should have received a copy of the GNU General Public License along
23 # with PhpWiki; if not, write to the Free Software Foundation, Inc.,
24 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 # In the form $values{$varname} = (value, comment_state)
28 # Where value is the value in index.php and comment_state indicates
29 # whether the line was commented or not
35 # Check we got a index.php to read from
37 print "Usage: ./phpwiki-migrate-config <../path/to/index.php>\n\n";
38 print "Takes an old style (<= 1.3.9) index.php configuration file\n";
39 print "for phpwiki and outputs a new style (>= 1.3.10) ./config.ini\n";
40 print "configuration file for phpwiki, based on a set of\n";
41 print "./config-{dist,default}.ini files.\n";
43 print "The values extracted from the old config file will be\n";
44 print "substituted into a new config.ini file as necessary. Commented\n";
45 print "directives in index.php will remain commented in config.ini\n";
50 # Read in values from index.php
52 open INDEXPHP, "< $infile" or die "Cannot read $infile: $!\n";
53 my $inifile = "config.ini";
54 my $distfile = "config-dist.ini";
55 my $defaultfile = "config-default.ini";
56 die "$inifile already exists.\n" if -e $inifile;
58 # Write out config.ini, substituting values as needed
59 open OUT, "> $inifile"
60 or die "Failed to write $inifile. $!\n";
61 open CONFDIST, "< $distfile"
62 or die "Failed to open $distfile: $!\n";
63 open CONFDEFAULT, "< $defaultfile"
64 or die "Failed to open $defaultfile: $!\n";
70 my ($name, $value) = ('','');
71 # Check if the line starts with a comment (# or / char)
72 my $is_comment = /^[#\/]/;
77 # Process expire parameters
79 ($value) = (/'keep'\s*=>\s*(.*)\)/);
89 # Skip some known bad options
90 if (/ALLOW_LDAP_LOGIN/) {
92 } elsif (/ALLOW_IMAP_LOGIN/) {
95 # Process defined values
96 } elsif (/define\s*\(/) {
97 # Extract the name of the define and the value of it
98 ($name, $value) = (/define\s*\(\s*['"](.*)['"]\s*,\s*['"]*([^'"]*)['"]*\s*\)/);
100 # Process PHP variable values
101 } elsif (/HTML_DUMP_SUFFIX\s*=/) {
102 ($name, $value) = (/\$(\w*)\s*=\s*['"](.*)['"];\s*/);
103 } elsif (/AllowedProtocols\s*=/) {
104 ($value) = (/\$\w*\s*=\s*(.*);\s*/);
105 $name = "ALLOWED_PROTOCOLS";
106 } elsif (/InlineImages\s*=/) {
107 ($value) = (/\$\w*\s*=\s*(.*);\s*/);
108 $name = "INLINE_IMAGES";
109 } elsif (/WikiNameRegexp\s*=/) {
110 ($value) = (/\$\w*\s*=\s*(.*);\s*/);
111 $name = "WIKI_NAME_REGEXP";
113 # Process arrays that need to be converted
114 } elsif (/GenericPages\s*=/) {
115 ($value) = (/\$\w*\s*=\s*array\((.*)\)/);
116 $name = "DEFAULT_WIKI_PAGES";
119 $value = "\"$value\""
120 } elsif (/keywords\s*=/) {
121 ($value) = (/\$\w*\s*=\s*array\((.*)\)/);
125 $value = "\"$value\""
127 # Process database paramters
128 } elsif (/'dbtype'\s*=>/) {
129 ($value) = (/'dbtype'\s*=>\s*['"](.*)['"]/);
130 $name = "DATABASE_TYPE";
131 } elsif (/'dsn'\s*=>/) {
132 ($value) = (/'dsn'\s*=>\s*['"](.*)['"]/);
133 $name = "DATABASE_DSN";
134 } elsif (/'timeout'\s*=>/) {
135 ($value) = (/'timeout'\s*=>\s*(.*)\s*,/);
136 $name = "DATABASE_TIMEOUT";
137 } elsif (/'db_session_table'\s*=>/) {
138 ($value) = (/'db_session_table'\s*=>\s*['"](.*)['"]/);
139 $name = "DATABASE_SESSION_TABLE";
140 } elsif (/'prefix'\s*=>/) {
141 ($value) = (/'prefix'\s*=>\s*['"](.*)['"]/);
142 $name = "DATABASE_PREFIX";
143 } elsif (/'directory'\s*=>/) {
144 ($value) = (/'directory'\s*=>\s*['"](.*)['"]/);
145 $name = "DATABASE_DIRECTORY";
146 } elsif (/'dba_handler'\s*=>/) {
147 ($value) = (/'dba_handler'\s*=>\s*['"](.*)['"]/);
148 $name = "DATABASE_DBA_HANDLER";
150 # Process Expire Parameters
151 } elsif (/\$ExpireParams\['major'\]\s*=/) {
152 ($value) = (/'max_age'\s*=>\s*(.*),/);
153 $name = "MAJOR_MAX_AGE";
155 } elsif (/\$ExpireParams\['minor'\]\s*=/) {
156 ($value) = (/'max_age'\s*=>\s*(.*),/);
157 $name = "MINOR_MAX_AGE";
160 # Process include path
161 } elsif (/ini_set.*include_path'/) {
162 ($value) = (/ini_set.*include_path'\s*,\s*(.*)\s*\)/);
163 $name = "INCLUDE_PATH";
170 # Put it into the array
171 if (exists $values{$name} && $is_comment) {
172 # If we already have a value and this one is commented, skip it
175 #print "$name => $value ($is_comment)\n";
176 $values{$name} = [$value, $is_comment];
181 # Print values we got
182 #for my $name ( keys %values ) {
183 # ($value, $is_comment) = @{$values{$name}};
184 # print "$name => $value";
185 # if ($is_comment) { print " (commented)"; }
190 # Write out migration header
191 print "; phpwiki 1.3.x configuration automatically generated from $infile\n";
192 print "; by migrate-phpwiki-config script\n\n";
195 # Look for config var lines
200 my ($name, $value, $is_comment);
201 ($name) = (/(\w*) = /);
202 if (!exists $values{$name}) {
206 ($value, $is_comment) = @{$values{$name}};
208 print "; $name = $value\n";
210 print "$name = $value\n";