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