sub step_conf_init { return 200; } sub step_conf { my (@list, $roots, $in, $val); my $doupload = 0; # if true, the stats.cfg will be uploaded to the users FTP server if the conf was changed my %c = (); goto THEMEINFO if $args->{themeinfo}; $wiz->wraptext($lang->{conf_start}); ## $wiz->wraptext($lang->{conf_confirm}); # if $args->{step} has any contents we know the user specifically requested -step conf on the cmdline, so there's no reason # to ask the user if they want to continue # if (@{$args->{step}} || $wiz->prompt_yesno(1,$lang->{yn_proceed})) { if (1) { $wiz->wraptext($lang->{conf_qa}); my @logs = ( ref $conf->{logsource} eq 'ARRAY' ? @{$conf->{logsource}} : $conf->{logsource} ); shift(@logs) while scalar @logs && !$logs[0]; # remove empty log sources from the beginning of the list $wiz->wraptext($lang->{conf_logsource}) if defined $lang->{conf_logsource}; while (1) { my $idx = scalar @logs + 1; $wiz->wraptext($lang->{conf_logsource2}); $wiz->wraptext($lang->{conf_logsource3}, undef, { source => '* none *', idx => '0' }) if scalar @logs == 0; my $count = 0; foreach $src (@logs) { $count++; $wiz->wraptext($lang->{conf_logsource3}, undef, { source => -d $src ? $src : "* $src", idx => sprintf("%2d",$count) }); } $in = $wiz->promptfor("LOGSOURCE $idx: "); if ($in ne '') { if ($in =~ /^\d+$/) { # allow user to delete a previous directory next if $in > scalar @logs; my @new = (); for (my $i=0; $i < scalar @logs; $i++) { # print "$i = " . $logs[$i] . "\n"; push(@new, $logs[$i]) if $i+1 != $in; # do not add the log if its index equals the one entered } @logs = @new; } else { push(@logs, $in); } } else { last if scalar @logs; $wiz->wraptext($lang->{conf_logsource4}); } } if (scalar @logs) { $c{logsource} = [ @logs ]; } while (1) { $in = ''; @list = validdirs('games'); if (scalar @list > 1) { $wiz->{data}->{list} = join(", ", sort @list); $wiz->wraptext($lang->{conf_gametype}) if defined $lang->{conf_gametype}; $in = lc $wiz->confinput('gametype'); # lowercase last if grep { /^\Q$in\E$/ } @list or $in eq '' or !scalar @list; # exit loop if we have a valid option $wiz->wraptext($lang->{conf_invalid}); } else { # default/force the only gametype available w/o prompting the user $in = $list[0]; last; } } if ($in ne '' and $in ne $conf->{gametype}) { $c{gametype} = $in; } while (1) { $in = ''; @list = grep { !/^(subs)$/ } validdirs(catfile('games', $c{gametype} || $conf->{gametype})); $wiz->{data}->{list} = join(", ", sort @list); $wiz->wraptext($lang->{conf_modtype}) if defined $lang->{conf_modtype}; $in = lc $wiz->confinput('modtype'); # lowercase last if grep { /^\Q$in\E$/ } @list or $in eq '' or !scalar @list; # exit loop if we have a valid option $wiz->wraptext($lang->{conf_invalid}); } if ($in ne '' and $in ne $conf->{modtype}) { $c{modtype} = $in; } while (1) { $in = ''; @list = qw(wonid steamid worldid name ipaddr); $wiz->{data}->{list} = join(", ", sort @list); $wiz->wraptext($lang->{conf_uniqueid}) if defined $lang->{conf_uniqueid}; $in = $wiz->confinput('uniqueid'); last if grep { /^\Q$in\E$/ } @list or $in eq '' or !scalar @list; # exit loop if we have a valid option $wiz->wraptext($lang->{conf_invalid}); } if ($in ne '' and $in ne $conf->{uniqueid}) { $c{uniqueid} = $in; } # while (1) { # $in = ''; # $wiz->wraptext($lang->{conf_maxdays}) if defined $lang->{conf_maxdays}; # $in = $wiz->confinput('maxdays'); # last if $in eq '' or ($in =~ /^\d+$/ and $in ne '0'); # exit loop if we have a valid option # $wiz->wraptext($lang->{conf_invalid}); # } # if ($in ne '' and $in ne $conf->{maxdays}) { # $c{maxdays} = $in; # } # while (1) { # $in = ''; # $wiz->wraptext($lang->{conf_rankmaxdays}) if defined $lang->{conf_rankmaxdays}; # $in = $wiz->confinput('rankmaxdays'); # last if $in eq '' or ($in =~ /^\d+$/ and $in ne '0'); # exit loop if we have a valid option # $wiz->wraptext($lang->{conf_invalid}); # } # if ($in ne '' and $in ne $conf->{rankmaxdays}) { # $c{rankmaxdays} = $in; # } while (1) { $in = ''; $wiz->wraptext($lang->{conf_decayskill}) if defined $lang->{conf_decayskill}; $in = $wiz->confinput('skill', 'decay'); last if $in eq '' or ($in =~ /^[-+]?(\d+(?:\.\d+)?)%?$/ and $in < 100); # exit loop if we have a valid option $wiz->wraptext($lang->{conf_invalid}); } if ($in ne '' and $in ne $conf->{decay}{skill}) { $c{decay}{skill} = $in; } while (1) { $in = ''; $wiz->wraptext($lang->{conf_minskill}) if defined $lang->{conf_minskill}; $in = $wiz->confinput('minskill', 'decay'); last if $in eq '' or ($in =~ /^-?\d+(\.[0-9]+)*?$/); # exit loop if we have a valid option $wiz->wraptext($lang->{conf_invalid}); } if ($in ne '' and $in ne $conf->{decay}{minskill}) { $c{decay}{minskill} = $in; } while (1) { $in = ''; $wiz->wraptext($lang->{conf_servername}) if defined $lang->{conf_servername}; $in = $wiz->confinput('servername'); last; # exit loop if we have a valid option $wiz->wraptext($lang->{conf_invalid}); } if ($in ne '' and $in ne $conf->{servername}) { $c{servername} = $in; } while (1) { $in = ''; $wiz->wraptext($lang->{conf_serverip}) if defined $lang->{conf_serverip}; $in = $wiz->confinput('serverip'); last; # exit loop if we have a valid option $wiz->wraptext($lang->{conf_invalid}); } if ($in ne '' and $in ne $conf->{serverip}) { $c{serverip} = $in; } THEMEINFO: print "\n"; my $base = ""; if ($OS eq 'MSWin32') { $base = 'c:\\inetpub\\wwwroot\\stats\\'; } else { # common locations for apache to be installed on linux machines. Quick and simple check to try an determine a good default $base = (-d '/usr/local/apache/htdocs') ? '/usr/local/apache/htdocs/stats/' : '/var/www/html/stats/'; } $conf->{theme}{statsroot} = $base unless $conf->{theme}{statsroot}; # these checks are now performed AFTER the statsroot and url have been specified... # $conf->{theme}{imagesroot} = $OS eq 'MSWin32' ? $base .'images\\' : $base . 'images/' unless $conf->{theme}{imagesroot}; # $conf->{theme}{mapsroot} = $OS eq 'MSWin32' ? $base .'images\\maps\\' : $base . 'images/maps/' unless $conf->{theme}{mapsroot}; # $conf->{theme}{weaponsroot} = $OS eq 'MSWin32' ? $base .'images\\weapons\\' : $base . 'images/weapons/' unless $conf->{theme}{weaponsroot}; # $conf->{theme}{statsurl} = '/stats/' unless $conf->{theme}{statsurl}; # $conf->{theme}{imagesurl} = '/stats/images/' unless $conf->{theme}{imagesurl}; # $conf->{theme}{mapsurl} = '/stats/images/maps/' unless $conf->{theme}{mapsurl}; # $conf->{theme}{weaponsurl} = '/stats/images/weapons/' unless $conf->{theme}{weaponsurl}; $wiz->{conf} = $conf; my $themeconf = { 'statsurl' => '', 'imagesurl' => '', 'weaponsurl' => '', 'mapsurl' => '', 'statsroot' => '', 'imagesroot' => '', 'weaponsroot' => '', 'mapsroot' => '', %{$conf->{theme}} }; my $t = $conf->{theme}; my $oldstatsroot = $conf->{theme}{statsroot}; my $oldstatsurl = $conf->{theme}{statsurl}; my $skipverify = 0; my $force = 1; #(!$t->{statsroot} || !$t->{imagesroot} || !$t->{mapsroot} || !$t->{weaponsroot}); $in = $conf->{install}; $wiz->wraptext($lang->{conf_themeinfo}, undef, $themeconf); # $wiz->wraptext($lang->{conf_chrootnote}) if $in->{ftpchroot}; if ($force || $wiz->prompt_yesno(0,$lang->{yn_changeroot})) { # if we're working with a remote host we want to make sure we can connect first... if (lc $in->{webhost} ne 'localhost' and $in->{webhost} ne '127.0.0.1') { # REMOTE HOST while (!$wiz->ftpconnect) { last unless $wiz->prompt_yesno(1,$lang->{yn_ftpconf}); $wiz->get_ftp_info(undef,undef,1); } $skipverify = (!defined $wiz->{ftp}); $wiz->wraptext($lang->{conf_skipverify}) if ($skipverify); } # @list = qw(statsroot imagesroot weaponsroot mapsroot); @list = qw(statsroot); foreach my $root (@list) { my $rootvalid = 0; my $name = substr($root, 0, -4); # strip off last 4 chars 'root' while (!$rootvalid) { # default roots to be subdirs of statsroot, if they're empty or statsroot was changed if ($root ne 'statsroot' and ($conf->{theme}{$root} eq '' or ($conf->{theme}{statsroot} ne $oldstatsroot and $oldstatsroot ne ''))) { my $dirsep = index($conf->{theme}{statsroot}, '/') != -1 ? '/' : '\\'; $conf->{theme}{$root} = $conf->{theme}{statsroot}; $conf->{theme}{$root} .= $dirsep if substr($conf->{theme}{$root}, -1) != $dirsep; $conf->{theme}{$root} .= 'images' . $dirsep unless $name eq 'images'; $conf->{theme}{$root} .= $name . $dirsep; } while (1) { $wiz->wraptext($lang->{"conf_$root"}) if defined $lang->{"conf_$root"}; $val = $wiz->confinput($root, "theme"); $wiz->{data}{path} = $val = ($val ne '') ? $val : $conf->{theme}{$root}; last if $val ne ''; # do not allow any blank values } if (lc $in->{webhost} eq 'localhost' or $in->{webhost} eq '127.0.0.1') { # LOCAL HOST $rootvalid = -d $val; if (!$rootvalid) { $wiz->wraptext($lang->{dirnotexists}); eval { mkpath([$val]) }; $wiz->{data}{error} = $@; $rootvalid = $@ ? 0 : 1; if (!$rootvalid) { $wiz->{data}{error} =~ s/ at .+//; # remove extra crap from error msg $wiz->wraptext($lang->{direrror}); last unless $wiz->prompt_yesno(1,$lang->{yn_tryagaindir}); } else { $wiz->wraptext($lang->{dircreated}); } } } else { # REMOTE HOST last if $skipverify; my $ftp = $wiz->{ftp}; if (defined $ftp and $ftp->pwd) { $wiz->ftpcwdroot; $rootvalid = $ftp->cwd($val); if (!$rootvalid) { $wiz->wraptext($lang->{dirnotexists}); $rootvalid = $ftp->mkdir($val,1); if (!$rootvalid) { chomp($wiz->{data}{error} = $ftp->message); $wiz->wraptext($lang->{direrror}); last unless $wiz->prompt_yesno(1,$lang->{yn_tryagaindir}); } else { $doupload = 1; $wiz->wraptext($lang->{dircreated}); } } } } } # while !$rootvalid if ($val ne '' and $val ne $conf->{theme}{$root}) { $doupload = (defined $wiz->{ftp}); my $dirsep = index($val, '/') != -1 ? '/' : '\\'; $val .= $dirsep unless substr($val, -1) =~ /[\/\\]/; $conf->{theme}{$root} = $val; # note: we're editing the 'real' conf hash } } # foreach $root } print "\n"; # my $urlbase = conf_find_base(); my $urlbase = $conf->{theme}{statsroot}; $urlbase =~ s|\\|/|g; # change \ to / $urlbase = '/' . (split('/', $urlbase))[-1] . '/'; # default base to last directory in root $force = 1; #(($oldstatsroot ne $conf->{theme}{statsroot}) || !$t->{statsurl} || !$t->{imagesurl} || !$t->{mapsurl} || !$t->{weaponsurl}); if ($force || $wiz->prompt_yesno(0,$lang->{yn_changeurl})) { # @list = qw(statsurl imagesurl weaponsurl mapsurl); @list = qw(statsurl); foreach my $url (@list) { my $name = substr($url, 0, -3); # strip off last 3 chars 'url' # default url to the last subdir of the statsroot, if it was changed if ($oldstatsroot ne $conf->{theme}{statsroot}) { $conf->{theme}{$url} = $urlbase; $conf->{theme}{$url} .= 'images/' unless $name eq 'images' or $name eq 'stats'; $conf->{theme}{$url} .= "$name/" unless $name eq 'stats'; } while (1) { $wiz->wraptext($lang->{"conf_$url"}) if defined $lang->{"conf_$url"}; $val = $wiz->confinput($url, "theme"); last if $val eq '' or $val !~ /[\s\\:]/; $wiz->wraptext($lang->{urlerror}); } if ($val ne '' and $val ne $conf->{theme}{$url}) { $doupload = (defined $wiz->{ftp}); $val .= "/" unless substr($val, -1) eq '/'; # add trailing slash if its not present $conf->{theme}{$url} = $val; # note: we're editing the 'real' conf hash } } # foreach $url } print "\n"; $base = $conf->{theme}{statsroot}; $conf->{theme}{imagesroot} = $OS eq 'MSWin32' ? $base .'images\\' : $base . 'images/'; $conf->{theme}{mapsroot} = $OS eq 'MSWin32' ? $base .'images\\maps\\' : $base . 'images/maps/'; $conf->{theme}{weaponsroot} = $OS eq 'MSWin32' ? $base .'images\\weapons\\' : $base . 'images/weapons/'; $base = $conf->{theme}{statsurl}; $conf->{theme}{imagesurl} = $base . 'images/'; $conf->{theme}{mapsurl} = $base . 'images/maps/'; $conf->{theme}{weaponsurl} = $base . 'images/weapons/'; # ---- save config, if we've made any changes if (scalar keys %c or $doupload) { # $wiz->wraptext($lang->{conf_updating}); # we have to loop over the hash (and not: $conf = { %$conf, %c }), otherwise subhashes will be overwritten incorrectly # since this is a config hash, we only need to worry about 1 level of subhashes foreach $k1 (keys %c) { if (ref $c{$k1} ne 'HASH') { $conf->{$k1} = $c{$k1}; } else { foreach $k2 (keys %{$c{$k1}}) { # copy all subhash values $conf->{$k1}{$k2} = $c{$k1}{$k2}; } } } confupdate($conf); } else { confupdate($conf); # $wiz->wraptext($lang->{conf_nochanges}); } } } # blah blah blah ... not used sub conf_find_base { my $base = ""; my $length = 0; while ($length < length($conf->{theme}{statsroot})) { } } 1;