# STEP 'WEB' # This step copies/uploads any weapons and maps in the 'weapons' and 'maps' directories in the 'web/images' directory # sub step_web_init { return 1_000_000; } sub step_web { my $in = $conf->{install}; my $DONE = 0; my @files = grep { !/(web.images.(?:maps|weapons)|web.themes|\.bak$)/ } sort pathsort processpath('web'); # get all 'web' related files (except images) # my @files = sort pathsort processpath('web'); my @weapons = sort pathsort processpath(catfile('web', 'images', 'weapons')); my @maps = sort pathsort processpath(catfile('web', 'images', 'maps')); my $php = []; my $numupdated = 0; $wiz->wraptext($lang->{web_start}); # --- NOW we finally handle the theme files ... Upload or copy them to the proper directories # $in->{themedir} = $wiz->unixpath($conf->{theme}{statsroot},"themes") unless $in->{themedir}; $in->{webhost} = 'localhost' unless $in->{webhost}; $in->{ftpuser} = ($OS eq 'MSWin32' ? $conf->{ $conf->{savetype} }{username} || '' : getpwuid($>) || $conf->{ $conf->{savetype} }{username}) unless $in->{ftpuser}; $in->{ftppass} = '' unless $in->{ftppass}; $in->{ftpport} = 21 unless $in->{ftpport}; $in->{ftppasv} = 0 unless $in->{ftppasv}; while (!$DONE) { # i don't remember why I put this in a !$DONE loop, I don't really use $DONE below my $proceed = 1; $wiz->get_ftp_info($in) if !defined $wiz->{ftp} and !$args->{useconfonly}; if (lc $in->{webhost} eq 'localhost' or $in->{webhost} eq '127.0.0.1') { # WEBSITE IS LOCAL $DONE = 1; $conf->{install}{themedir} = catfile(getcwd(), 'themes', ''); $conf->{install}{compiledir} = catfile(getcwd(), 'themes_compiled', ''); web_update_configphp($conf); $wiz->wraptext($lang->{web_php}, undef, { action => 'Copying' }); copyfiles('statsroot', 'web', \@files); $wiz->wraptext($lang->{web_weapons}, undef, { action => 'Copying' }); copyfiles('weaponsroot', 'weapons', \@weapons); $wiz->wraptext($lang->{web_maps}, undef, { action => 'Copying' }); copyfiles('mapsroot', 'maps', \@maps); } else { # WEBSITE IS REMOTE while (!$wiz->ftpconnect) { die "Error logging into FTP. Prompting disabled (-useconfonly)." if $args->{useconfonly}; last unless $wiz->prompt_yesno(1,$lang->{yn_ftpconf}); $wiz->get_ftp_info($in,undef,1); } $ftp = $wiz->{ftp} or last; $DONE = 1; # $wiz->wraptext($lang->{init_themedir}); # $wiz->wraptext($lang->{init_themedir2}); # $conf->{themedir} = $wiz->promptfor("Theme directory [$conf->{themedir}]: ", $conf->{themedir}); web_update_configphp($conf); $wiz->ftpcwdroot; $wiz->wraptext($lang->{web_php}, undef, { action => 'Uploading' }); uploadfiles('statsroot', 'web', \@files); $wiz->ftpcwdroot; $wiz->wraptext($lang->{web_weapons}, undef, { action => 'Uploading' }); uploadfiles('weaponsroot', 'weapons', \@weapons); $wiz->ftpcwdroot; $wiz->wraptext($lang->{web_maps}, undef, { action => 'Uploading' }); uploadfiles('mapsroot', 'maps', \@maps); } # if website is remote } # while !$DONE confupdate($conf,0,1); # no need to inform the user that we're updating the config here } sub _path { return $wiz->unixpath($_[1]); # return the 2nd arg for now, this function is not used my $path = shift; my $dirsep = index($path, '/') != -1 ? '/' : '\\'; while (shift) { $_ .= $dirsep if substr($_, -1) ne $dirsep; # add trailing slash if it's not present $path .= $_; } return $path; } sub web_update_configphp { my ($c) = @_; $php = slurpfile(catfile('web','config.php')); # remove leading/trailing blank lines shift(@$php) && ++$numupdated while scalar @$php and $php->[0] =~ /^\s*$/; pop(@$php) && ++$numupdated while scalar @$php and $php->[ scalar @$php - 1 ] =~ /^\s*$/; $numupdated += web_update_config($php, 'servername', $c->{servername}); $numupdated += web_update_config($php, 'serverip', $c->{serverip}); $numupdated += web_update_config($php, 'gametype', $c->{gametype}); $numupdated += web_update_config($php, 'modtype', $c->{modtype}); $numupdated += web_update_config($php, 'uniqueid', $c->{uniqueid}); $numupdated += web_update_config($php, 'theme', $c->{theme}{source}); $numupdated += web_update_config($php, 'dbuser', $c->{ $c->{savetype} }{username}); $numupdated += web_update_config($php, 'dbpass', $c->{ $c->{savetype} }{password}); $numupdated += web_update_config($php, 'dbhost', $c->{ $c->{savetype} }{host}); $numupdated += web_update_config($php, 'dbname', $c->{ $c->{savetype} }{dbname}); $numupdated += web_update_config($php, 'dbtblprefix', $c->{ $c->{savetype} }{tableprefix}); # $numupdated += web_update_config($php, 'template_dir', _path($c->{install}{ftpchroot}, $c->{install}{themedir})); # $numupdated += web_update_config($php, 'compile_dir', _path($c->{install}{ftpchroot}, $c->{install}{compiledir})); $numupdated += web_update_config($php, 'statsroot', $wiz->unixpath($c->{theme}{statsroot}) . '/'); # $numupdated += web_update_config($php, 'imagesroot', $wiz->unixpath($c->{theme}{imagesroot}) . '/'); # $numupdated += web_update_config($php, 'weaponsroot', $wiz->unixpath($c->{theme}{weaponsroot}) . '/'); # $numupdated += web_update_config($php, 'mapsroot', $wiz->unixpath($c->{theme}{mapsroot}) . '/'); # $numupdated += web_update_config($php, 'statsurl', $c->{theme}{statsurl}); # $numupdated += web_update_config($php, 'imagesurl', $c->{theme}{imagesurl}); # $numupdated += web_update_config($php, 'weaponsurl', $c->{theme}{weaponsurl}); # $numupdated += web_update_config($php, 'mapsurl', $c->{theme}{mapsurl}); if ($numupdated) { $wiz->wraptext($lang->{web_modify1}); my $file = catfile('web', 'config.php'); # copy($file, $file . '.bak'); # backup original file if (open(F, ">$file")) { # overwrite original file with new config print F join('', @$php); close(F); } else { $wiz->wraptext($lang->{web_mod_err}, undef, { 'error' => $! }); } $wiz->wraptext($lang->{web_modify3}); } else { # $wiz->wraptext($lang->{web_no_modify}); } } sub web_update_config { my ($lines, $var, $value) = @_; my $idx; my $found = 0; for ($idx=0; $idx < @$lines; $idx++) { # loop through lines, matching the var we want my $line = $lines->[$idx]; my $varmatch = ''; my ($match, $oldvalue) = split(/=/, $line, 2); $oldvalue =~ s/^\s+//; # strip off whitespace $oldvalue =~ s/\s+$//; # ... $oldvalue =~ s/\s*(\/\/|#).+$//; # strip off comments $oldvalue = substr($oldvalue,0,-1) if substr($oldvalue,-1) eq ';'; # remove trailing semi-colon ';' $oldvalue = substr($oldvalue,1,-1) if $oldvalue =~ /^(['"]).*\1$e/; # strip off surrounding quotes (if present) $match =~ s/^\s+//; $match =~ s/\s+$//; next unless $match =~ /\[['"]?([\w\d]+)['"]?\]/; # extract var from ['var'] $match = $1 || next; next unless $match eq $var; # this line is not what we want ... next!! return 0 if $value eq $oldvalue; # no need to update if it's the same # $wiz->wraptext($lang->{web_modify2}, undef, { 'var' => $var, 'value' => $value }); $lines->[$idx] = "\$conf['$var'] \t= '" . web_quote($value) . "';\n"; return 1; # break out of the loop, we found what we want } if (index($lines->[ scalar @$lines - 1 ], '?>') >= 0) { pop(@$lines); # remove last line: "?>" pop(@$lines) while scalar @$lines and $lines->[ scalar @$lines - 1 ] =~ /^\s*$/; # remove any blank lines from the end # push(@$lines, "\n"); push(@$lines, "\$conf['$var'] \t= '" . web_quote($value) . "';\n"); push(@$lines, "?>"); return 1; } return 0; } # backslashes any single (') or (\) in the string so it can safely be used inside single quotes ('str\'ing\\str2') sub web_quote { my $str = shift; $str =~ s/([\\'])/"\\$1"/ge; return $str; } 1;