Index: ossp-pkg/tabea/tabea.cgi RCS File: /v/ossp/cvs/ossp-pkg/tabea/tabea.cgi,v rcsdiff -q -kk '-r1.23' '-r1.24' -u '/v/ossp/cvs/ossp-pkg/tabea/tabea.cgi,v' 2>/dev/null --- tabea.cgi 2002/05/17 13:00:04 1.23 +++ tabea.cgi 2002/05/17 18:28:01 1.24 @@ -27,7 +27,6 @@ ## ## tabea.cgi: Tabea CGI (syntax: Perl) ## -## require 5.000; use strict; @@ -36,7 +35,6 @@ $|++; - my $cfgfile = "./tabea.cfg"; my $pwdfile = "./tabea.pw"; my $configsdir = "./tabea.d"; @@ -65,7 +63,6 @@ exit(0); }; - # update cookies my $cookies = []; foreach my $param (qw(username)) { # FIXME! @@ -79,7 +76,7 @@ )); } if ($cgi->param($param) eq '' and $cgi->cookie($param) ne '') { - $cgi->param(-name => $param, -value => [$cgi->cookie($param)]); + $cgi->param(-name => $param, -value => [$cgi->cookie($param)]); } } @@ -101,18 +98,18 @@ } } -NEXTFORM: +NEXTFORM: my $page = $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); if ($form eq '') { $page .= &login(); } elsif ($form eq 'mainw') { - $page .= mainw(); + $page .= mainw(); } elsif ($form eq 'edit') { $page .= &edit($cgi->param('configslist')); -} +} elsif ($form eq 'save') { $page .= &save($cgi->param('editfile'), $cgi->param('editwindow')); } @@ -123,15 +120,15 @@ $page .= &new($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username); } elsif ($form eq 'newf') { - $page .= &newfile($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, $cgi->param('newfile'), - $cgi->param('new_rights')); + $page .= &newfile($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, + $username, $cgi->param('newfile'), $cgi->param('new_rights')); } elsif ($form eq 'confr') { $page .= &config_rights($cgi->param('configslist')); } elsif ($form eq 'changer') { - $page .= &change_rights($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $cgi->param('filename'), - $cgi->param('changerights') ); + $page .= &change_rights($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" + . $cgi->param('filename'), $cgi->param('changerights') ); } elsif ($form eq 'copyt') { $page .= ©_file($cgi->param('templatelist') ); @@ -140,7 +137,7 @@ $page .= ©_file($cgi->param('configslist')); } elsif ($form eq 'copy' ) { - $page .= ©($cgi->param('srcfile'), $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . + $page .= ©($cgi->param('srcfile'), $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $username . "/". $cgi->param('dstfile')); } elsif ($form eq 'del' ) { @@ -153,7 +150,7 @@ die "no correct dialog found"; } -$page .= $cgi->hidden(-name => 'password', -default => $password ) ; +$page .= $cgi->hidden(-name => 'password', -default => $password); $page .= $cgi->endform; my $out = $MY->{TEMPLATE}; @@ -162,7 +159,8 @@ print $cgi->header(-cookie => $cookies, -expires => '+1s') . $out; -exit (0); +exit(0); + ############### End of main part ####################################################### ######################################################################################## @@ -170,7 +168,7 @@ ######################################################################################## my $text = ''; - $text .= + $text .= "
Username: | " . @@ -212,8 +210,8 @@ ######################################################################################## my $text = ''; - &validpassword($username, $password, $cfghash{'BaseDir'}.$cfghash{'PasswdFile'}) - || 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 = &get_name_files($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, 4); my $configsfiles = &get_name_files($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, 6); @@ -222,17 +220,17 @@ $templatesfiles = &strsort($templatesfiles); $configsfiles = &strsort($configsfiles); - + my @templatesarray = split(/ /,$templatesfiles); my @configsarray = split(/ /,$configsfiles); - - $text .= - # Begin with templates part + + $text .= + # Begin with templates part "" . "
" . + " | " . " | " . $cgi->scrolling_list( -name => 'templatelist', @@ -259,7 +257,7 @@ " |
" . @@ -293,10 +291,10 @@ " |
" . + " | " .
"$namefile " . " | " .
- " " . + " | " .
$cgi->scrolling_list(
-name => 'changerights',
-value => ['private', 'protected', 'public'],
@@ -553,17 +552,19 @@
$cgi->submit(-name => 'dialog_mainw', -value => 'Back') .
$cgi->submit(-name => 'dialog_changer', -value => 'Set_rights');
$confname = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $namefile;
- $text .= $cgi->hidden(-name => 'filename', -default => $namefile ) ;
- } else {
+ $text .= $cgi->hidden(-name => 'filename', -default => $namefile ) ;
+ }
+ else {
$text .= "You can only change file rights in your own directory \n" . - $cgi->submit(-name => 'dialog', -value => 'Back'); + $cgi->submit(-name => 'dialog', -value => 'Back'); } - } else { + } + else { $text .= "Missing filename \n" . - $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); + $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); } - return $text; + return $text; } ######################################################################################## @@ -571,22 +572,25 @@ ######################################################################################## sub change_rights { ######################################################################################## - my ( $filename, $newrights ) = @_; + my ($filename, $newrights) = @_; my $text = ''; my $filerights = ''; - $text= "" . - "Changing rights of file: " . - "" . - " $filename to $newrights "; - if ($newrights eq "private" ) { - $filerights = ''; - } elsif ($newrights eq "protected" ) { - $filerights = "r"; - } elsif ($newrights eq "public" ) { - $filerights = "rw"; - } else { - die "Unknown file rights"; + $text = "" . + "Changing rights of file: " . + "" . + " $filename to $newrights "; + if ($newrights eq "private") { + $filerights = ''; + } + elsif ($newrights eq "protected") { + $filerights = "r"; + } + elsif ($newrights eq "public") { + $filerights = "rw"; + } + else { + die "Unknown file rights"; } system("chmod o=$filerights $filename") && die "Cannot set new file rights"; $form = 'mainw'; @@ -600,13 +604,11 @@ ######################################################################################## sub copy_file { ######################################################################################## - my ( $filename ) = @_; + my ($filename) = @_; my $text = ''; - - if ($filename) { - my $srcfile = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $filename; + my $srcfile = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $filename; $text .= $cgi->hidden(-name => 'srcfile', -default => $srcfile ) . "" . "Copying File: " . @@ -620,7 +622,7 @@ " | Destinationfile | " . "||||||||
$srcfile | " . + "$srcfile | " . "" .
"
\n" . - $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ; + $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ; } - return $text; + return $text; } ######################################################################################## @@ -662,31 +665,31 @@ ######################################################################################## sub del { ######################################################################################## - my ( $delfile ) = @_; + my ($delfile) = @_; my $text = ''; if ($delfile) { my $fpath = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $delfile; - - $text= "" . - "Delete File: $fpath \n" . - "" . - " " ; + $text = "" . + "Delete File: $fpath \n" . + "" . + " "; $delfile =~ m{^([a-zA-Z0-9!" \n" ; } - } else { - $text .= "Missing filename \n" ; + else { + $text .= "You can only delete file in your own directory \n"; + } + } + else { + $text .= "Missing filename \n"; } - - $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ; - + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); + return $text; } ######################################################################################## @@ -695,7 +698,7 @@ ######################################################################################## sub run { ######################################################################################## - my ( $runfile ) = @_; + my ($runfile) = @_; my $text = ''; my $rpath = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $runfile; my $rcommand = $cfghash{'ExecuteCommand'}; @@ -704,7 +707,7 @@ my $outputtext = ''; if ($runfile eq '') { - $text .= "No configuration selected \n" ; + $text .= "No configuration selected \n" ; $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); return $text; } @@ -715,34 +718,35 @@ } $text .= "" . - "Running Configuration: $rpath \n" . - "" . - " " . - "Run command: " . $rcommand . " " ; + "Running Configuration: $rpath \n" . + "" . + " " . + "Run command: " . $rcommand . " "; system("$rcommand > $output 2>&1"); $fileoutput = IO::File->new("<$output"); - if(defined $fileoutput) { + if (defined $fileoutput) { while (<$fileoutput>) { $outputtext .= $_; } $fileoutput->close(); - my $outputhash ={ -name => 'outputwindow', - -default => $outputtext, - -rows => 40, - -columns => 80 + my $outputhash = { + -name => 'outputwindow', + -default => $outputtext, + -rows => 40, + -columns => 80 }; - $outputhash->{readonly}=""; - $text .= $cgi->textarea($outputhash). - " " ; - } else { - $text .= "Run command not working \n" ; - } - $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); + $outputhash->{readonly} = ""; + $text .= $cgi->textarea($outputhash) . " "; + } + else { + $text .= "Run command not working \n"; + } + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); - return $text; + return $text; } ######################################################################################## @@ -750,20 +754,20 @@ ######################################################################################## sub copy { ######################################################################################## - my ( $srcf, $dstf ) = @_; + my ($srcf, $dstf) = @_; my $text = ''; $text .= "" . - "Copying File: " . - " " . - "Copying from $srcf to $dstf " ; + "Copying File: " . + " " . + "Copying from $srcf to $dstf "; system("cp $srcf $dstf") && die "Cannot copy file"; system("chmod o= $dstf") && die "Cannot change file rights"; $form = 'mainw'; - goto NEXTFORM; - + goto NEXTFORM; + return $text; } ######################################################################################## @@ -772,31 +776,32 @@ ######################################################################################## sub read_config { ######################################################################################## - my ($cfgfile) = @_; + my ($cfgfile) = @_; my %cfghash ; my $cfgin ; my $key; my $content; - print "Lese file: $cfgfile\n"; + print "Reading 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 + 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 + $_ =~ 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; - } else { + } + else { die "Can't open config file"; } return (%cfghash); @@ -812,10 +817,10 @@ my $uname; my $pwd; my $pwdin; - + $pwdin = IO::File->new("<$pwdfile"); if(defined $pwdin) { - while(<$pwdin>) { + while (<$pwdin>) { $_ =~ s|^(\w+):(.+)$|{$uname=$1; $pwd=$2}|eg; ( $uname =~ $user ) && do { # check the password if (crypt($password, $pwd) eq $pwd){ @@ -824,9 +829,7 @@ } } } - $pwdin->close(); - return $returnvalue; } ######################################################################################## @@ -835,17 +838,16 @@ ######################################################################################## sub readsubdir { ######################################################################################## - my ( $dir ) = @_; + my ($dir) = @_; my $filestring = ""; my $direntry = ""; - opendir(DIR, "$dir"); # Open dir for scanning - + opendir(DIR, "$dir"); foreach $direntry (readdir(DIR)) { next if $direntry eq "."; next if $direntry eq ".."; if (-d "$dir/$direntry") { - $filestring .= $direntry. " "; + $filestring .= $direntry . " "; } } closedir(DIR); @@ -857,17 +859,16 @@ ######################################################################################## sub readdir { ######################################################################################## - my ( $dir ) = @_; + my ($dir) = @_; my $filestring = ""; my $direntry = ""; - opendir(DIR, "$dir"); # Open dir for scanning - + opendir(DIR, "$dir"); foreach $direntry (readdir(DIR)) { next if $direntry eq "."; next if $direntry eq ".."; if (-f "$dir/$direntry") { - $filestring .= $direntry. " "; + $filestring .= $direntry . " "; } } closedir(DIR); @@ -879,10 +880,10 @@ ######################################################################################## sub strsort { ######################################################################################## - my ( $sortstr ) = @_; + my ($sortstr) = @_; + + my @sortarray = split(/ /, $sortstr); - my @sortarray = split (/ /, $sortstr); - @sortarray = reverse sort {$b cmp $a} @sortarray; $sortstr = join(" ", @sortarray); @@ -902,49 +903,52 @@ my $titletext ; $filein = IO::File->new("<$file"); - if(defined $filein) { - while(<$filein>) { $editf .= $_; } - $filein->close(); - } else { + if (defined $filein) { + while(<$filein>) { + $editf .= $_; + } + $filein->close(); + } + else { die "Can't open $file"; } - + if ($mode eq 'w') { $titletext = "Edit window"; } elsif ($mode eq 'r') { - $titletext = "View window"; + $titletext = "View window"; } - my $textahash ={ -name => 'editwindow', - -default => $editf, - -rows => 40, - -columns => 80 + my $textahash = { + -name => 'editwindow', + -default => $editf, + -rows => 40, + -columns => 80 }; if ($mode eq 'r') { $textahash->{readonly}=""; } $texte .= "" . - $titletext . ": \n" . - "" . - "" . - "File: $file \n" . - "" . - $cgi->textarea($textahash). - " \n" . - "
|