Index: ossp-pkg/tabea/tabea.cgi RCS File: /v/ossp/cvs/ossp-pkg/tabea/tabea.cgi,v rcsdiff -q -kk '-r1.12' '-r1.13' -u '/v/ossp/cvs/ossp-pkg/tabea/tabea.cgi,v' 2>/dev/null --- tabea.cgi 2002/05/10 15:41:18 1.12 +++ tabea.cgi 2002/05/13 13:05:56 1.13 @@ -35,9 +35,12 @@ $|++; + +my $cfgfile = "./tabea.cfg"; # Name of configuration file + my $pwdfile = "./tabea.pw"; my $configsdir = "./tabea.d"; -my $tabeauser = "tabea"; +#my $tabeauser = "tabea"; # establish my configuration my $MY = {}; @@ -82,7 +85,10 @@ } } +# Read the configuration +my %cfghash = read_config($cfgfile); +#print "Test: $cfghash{'TabeaUser'}\n"; # fetch parameters my $dialog = $cgi->param("dialog") || ""; @@ -91,6 +97,8 @@ my $page = ''; +if ($cfghash{"TabeaUser"} ne '') { + if ($dialog eq "") { $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) . # $cgi->hidden(-name => 'form', -default => ['login']) . @@ -130,10 +138,10 @@ # enter Select form - &validpassword($username, $password, $pwdfile) || print STDOUT $cgi->redirect(-uri => $cgi->url(-full => 1), -type => "text/html"); + &validpassword($username, $password, $cfghash{'BaseDir'}.$cfghash{'PasswdFile'}) || print STDOUT $cgi->redirect(-uri => $cgi->url(-full => 1), -type => "text/html"); - my $templatesfiles = &readdir($configsdir."/".$tabeauser); - my $configsfiles = &readdir($configsdir."/".$username); + my $templatesfiles = &readdir($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} ."/".$cfghash{'TabeaUser'}); + my $configsfiles = &readdir($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} ."/".$username); my @templatesarray = split(/ /,$templatesfiles); my @configsarray = split(/ /,$configsfiles); @@ -225,7 +233,7 @@ # enter Edit form # &validpassword($username, $password, $pwdfile) || print STDOUT $cgi->redirect(-uri => $cgi->url(-full => 1), -type => "text/html"); if ($cgi->param('configslist')) { - my $filename = $configsdir . "/" . $username . "/" . $cgi->param('configslist'); + my $filename = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $username . "/" . $cgi->param('configslist'); &editconfig($filename, 'w', $username); } else { $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) . @@ -239,7 +247,7 @@ # enter View form # &validpassword($username, $password, $pwdfile) || print STDOUT $cgi->redirect(-uri => $cgi->url(-full => 1), -type => "text/html"); if ($cgi->param('templatelist')) { - my $filename = $configsdir . "/" . $tabeauser . "/" . $cgi->param('templatelist'); + my $filename = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $cfghash{'TabeaUser'} . "/" . $cgi->param('templatelist'); &editconfig($filename, 'r', $username); } else { $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) . @@ -252,6 +260,10 @@ die "invalid dialog \"$dialog\""; } +} else { + die "no configuration found"; +} + my $out = $MY->{TEMPLATE}; $out =~ s|%%BODY%%|$page|s; $out =~ s|%%TITLE%%|Test|s; @@ -260,6 +272,42 @@ exit (0); +######################################################################################## +sub read_config { +######################################################################################## + +my ($cfgfile) = @_; +my %cfghash ; +my $cfgin ; +my $key; +my $content; + +print "Lese file: $cfgfile\n"; +$cfgin = IO::File->new("<$cfgfile"); + +if (defined $cfgin) { + LOOP: while(<$cfgin>) { + + + $_ =~ s|^\s+(.*?)|{$_=$1}|es; # Remove whitespaces at the beginning + next LOOP if $_ =~ /^\n/; # Remove the first empty require + next LOOP if $_ eq ""; # Remove empty line + next LOOP if $_ =~/^#/; # Remove comment lines + + $_ =~ s|^([^#]+)#(.*)$|{$_=$1}|es; # Remove comments on the end + $_ =~ s|(.*?)\s+$|{$_=$1}|es; # Remove whitespaces at the end + + + ($key, $content) = /^(\w+)\s+(.*)$/; + + $cfghash{$key} = $content; + } + $cfgin->close; +} + +return (%cfghash); +} +######################################################################################## @@ -320,6 +368,7 @@ my ($file, $mode, $user) = @_; my $text = ''; my $filein ; + $filein = IO::File->new("<$file"); while(<$filein>) { $text .= $_; }