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 .= "" . " " . " " . @@ -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 "" . "
Active User: $username

\n" . "
" . "
Username:
" . - "
Templates
" . + " " . " " . $cgi->scrolling_list( -name => 'templatelist', @@ -259,7 +257,7 @@ "
" . " " . "" . - # Now the configuration part + # Now the configuration part "

" . "" . "
Configuration
" . @@ -293,10 +291,10 @@ "
" . " " . "" . - "" ; + ""; return $text; -} +} ######################################################################################## @@ -311,12 +309,12 @@ my $filemode = ''; my $entry = ''; - my $dirlist = &readsubdir($dirname . "/" ); - my @dirarray = split (/ /, $dirlist); + my $dirlist = &readsubdir($dirname . "/"); + my @dirarray = split (/ /, $dirlist); - DIR: foreach $subdir (@dirarray) { + DIR: foreach $subdir (@dirarray) { next DIR if $subdir eq $user; - $filel = &readdir($dirname . "/" . $subdir . "/") ; + $filel = &readdir($dirname . "/" . $subdir . "/"); @filelarray = split (/ /, $filel); FILE: foreach $entry (@filelarray) { my $path = $dirname . "/" . $subdir . "/" . $entry; @@ -324,7 +322,7 @@ $filelist .= $subdir . "/" . $entry . " "; } } - + return $filelist; } ######################################################################################## @@ -355,15 +353,15 @@ my ($editfile) = @_; my $text; - if($editfile) { + if ($editfile) { my $filename = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $editfile; - $text .=&editconfig($filename, 'w', $username). - $cgi->hidden(-name => 'editfile', -default => $filename ) ; + $text .= &editconfig($filename, 'w', $username) . + $cgi->hidden(-name => 'editfile', -default => $filename ); } else { $text .= "Missing filename

\n" . - $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ; + $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); } - + return $text; } ######################################################################################## @@ -372,14 +370,14 @@ ######################################################################################## sub save { ######################################################################################## - my ( $file, $edittext) = @_; + my ($file, $edittext) = @_; my $text = ''; - my $fileout; + my $fileout; $text= "" . - "Save File: $file

\n" . - "
" . - "

" ; + "Save File: $file

\n" . + "
" . + "

"; $fileout = IO::File->new(">$file"); if (defined $fileout) { @@ -388,11 +386,11 @@ $form = 'mainw'; goto NEXTFORM; } else { - $text .= "Cannot save file

\n" ; + $text .= "Cannot save file

\n"; } $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); - + return $text; } ######################################################################################## @@ -401,15 +399,15 @@ ######################################################################################## sub view { ######################################################################################## - my ($file) = @_; + my ($file) = @_; my $text; - + if ($file) { my $filename = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $cgi->param('templatelist'); $text .= &editconfig($filename, 'r', $username); } else { $text .= "Missing filename

\n" . - $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ; + $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); } return $text; } @@ -419,7 +417,7 @@ ######################################################################################### sub new { ######################################################################################## - my ( $dirname, $user ) = @_; + my ($dirname, $user) = @_; my $text = ''; $text= "" . @@ -449,14 +447,14 @@ " " . " " . "
" . - " " . + " " . "" . " " . $cgi->submit(-name => 'dialog_mainw', -value => 'Back') . $cgi->submit(-name => 'dialog_newf', -value => 'Create') . " " . - " " . - ""; + " " . + ""; return $text; } @@ -467,7 +465,7 @@ ######################################################################################## sub newfile { ######################################################################################## - my ( $dirname, $user, $newfilename, $newrights ) = @_; + my ($dirname, $user, $newfilename, $newrights) = @_; my $text = ''; my $newpath = $dirname . "/" . $user . "/" . $newfilename; my $filesinpath = &readdir($dirname . "/" . $user . "/"); @@ -476,31 +474,33 @@ my $filerights = ''; $text= "" . - "Creating New File: $newfilename

" . - "



" ; + "Creating New File: $newfilename

" . + "



"; foreach (@filesinpatharray) { - if ( $_ eq $newfilename) { $canwrite = 0; }; + if ($_ eq $newfilename) { + $canwrite = 0; + }; } - if ( $canwrite ) { - if ($newrights eq "private" ) { + if ($canwrite) { + if ($newrights eq "private") { $filerights = ''; - } elsif ($newrights eq "protected" ) { + } elsif ($newrights eq "protected") { $filerights = "r"; - } elsif ($newrights eq "public" ) { + } elsif ($newrights eq "public") { $filerights = "rw"; } else { - die "Unknown file rights"; + die "Unknown file rights"; } $text .= "Creating the new file $newpath

"; system("touch $newpath") && die "Cannot create new file"; $text .= "Setting new file rights for $newpath

"; system("chmod u=rw $newpath") && die "Cannot set new file rights"; system("chmod o=$filerights $newpath") && die "Cannot set new file rights"; - $text .= "


" ; + $text .= "


"; $form = 'mainw'; goto NEXTFORM; } else { - $text .= "Cannot write file. File exists

\n" ; + $text .= "Cannot write file. File exists

\n"; } $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); @@ -512,34 +512,33 @@ ######################################################################################## sub config_rights { ######################################################################################## - my ( $namefile ) = @_; + my ($namefile) = @_; my $text = ''; my $defaultright = ''; my $confname = ''; - + my $filerights = (stat($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $namefile))[2] & 07; - - + if ($namefile ne '') { - if ( $filerights == 6 ) { - $defaultright = "public" ; - } elsif ( $filerights == 4 ) { - $defaultright = "protected" ; + if ($filerights == 6) { + $defaultright = "public" ; + } elsif ($filerights == 4) { + $defaultright = "protected"; } else { - $defaultright = "private" ; + $defaultright = "private"; } $text .= "" . - "Changing rights of file:

" ; - + "Changing rights of file:

"; + $namefile =~ m{^([a-zA-Z0-9!"£$%^&*()-_=+#~]+)/(.+)}sg; if ($1 eq $username) { $text .= "" . "" . - " " . - " " . " " . " " . - " " . + " " . " " . + "
" . + " " . "$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" . " " . " " . @@ -643,18 +645,19 @@ " " . + " " . " " . - " " . + " " . + " " . "
" . " " . $cgi->submit(-name => 'dialog_mainw', -value => 'Back'). - " " . $cgi->submit(-name => 'dialog_copy', -value => 'Copy'). - "
" ; - } else { + } + else { $text .= "Missing filename

\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!"$%^&*()-_=+#~]+)/(.+)}sg; - if ( $1 eq $username ) { + if ($1 eq $username) { system("rm $fpath") && die "Cannot delete file"; $form = 'mainw'; goto NEXTFORM; - } else { - $text .= "You can only delete file in your own directory

\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" . - "" . - " "; + $titletext . ":

\n" . + "" . + "" . + "File: $file

\n" . + "
" . + $cgi->textarea($textahash). + "

\n" . + "
" . - " " . - $cgi->submit(-name => 'dialog_mainw', -value => 'Back') . - "
" . + " "; if ($mode eq 'w') { - $texte .= " "; + $texte .= " "; } $texte .= " " . - "
" . + " " . + $cgi->submit(-name => 'dialog_mainw', -value => 'Back') . + " " . - $cgi->submit(-name => 'dialog_save', -value => 'Save') . - " " . + $cgi->submit(-name => 'dialog_save', -value => 'Save') . + " " . - "
" ; - + "
"; return $texte; } ########################################################################################