Index: ossp-pkg/tabea/tabea.cgi RCS File: /v/ossp/cvs/ossp-pkg/tabea/tabea.cgi,v rcsdiff -q -kk '-r1.21' '-r1.22' -u '/v/ossp/cvs/ossp-pkg/tabea/tabea.cgi,v' 2>/dev/null --- tabea.cgi 2002/05/16 15:54:59 1.21 +++ tabea.cgi 2002/05/17 08:09:07 1.22 @@ -91,49 +91,60 @@ my $password = $cgi->param("password") || ""; my $filename = $cgi->param("filename") || ""; -my $page = ''; +my $form = ''; -if ($cfghash{"TabeaUser"} ne '') { +for my $name (qw(mainw copyt view new copyc edit del run confr newf changer copy save)) { + my $val = $cgi->param("dialog_$name") || ""; + if ($val ne '') { + $form = $name; + } +} + +my $page = $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); -if ($dialog eq "") { +#if ($dialog eq "") { +if ($form eq '') { +# if ($form eq "mainw") { +# $page .= "Form new is login

"; +# } $page .= - $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) . - "" . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - "
Username:" . - $cgi->textfield( - -name => 'username', - -default => $username, - -size => 20, - -maxlength => 8 - ) . - "
Password:" . - $cgi->password_field( - -name => 'password', - -value => $password, - -size => 20, - -maxlength => 80 - ) . - "
" . - $cgi->reset() . - $cgi->submit(-name => 'dialog', -value => 'login') . - "
" . - $cgi->endform; + "" . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + "
Username:" . + $cgi->textfield( + -name => 'username', + -default => $username, + -size => 20, + -maxlength => 8 + ) . + "
Password:" . + $cgi->password_field( + -name => 'password', + -value => $password, + -size => 20, + -maxlength => 80 + ) . + "
" . + $cgi->reset() . + $cgi->submit(-name => 'dialog_mainw', -value => 'login') . + "
" ; } -elsif (($dialog eq 'login') || ($dialog eq 'Back')) { +#elsif (($dialog eq 'login') || ($dialog eq 'Back')) { +elsif ($form eq 'mainw') { # enter Select form - &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); @@ -145,126 +156,106 @@ my @templatesarray = split(/ /,$templatesfiles); my @configsarray = split(/ /,$configsfiles); - - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) . + + $page .= $cgi->hidden(-name => 'password', -default => $password ) . - # Begin with templates part - "" . - "
Active User: $username

\n" . - "
" . - "" . - " " . - " " . - "
Templates
" . - " " . - $cgi->scrolling_list( - -name => 'templatelist', - -value => [@templatesarray], - -size => 3 - ) . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - " " . - "
" . - "
" . - $cgi->submit(-name => 'dialog', -value => 'Copy_Temp') . - "
" . - $cgi->submit(-name => 'dialog', -value => 'View') . - "
" . - "
" . - " " . - "" . - -# Now the configuration part - "

" . - "" . - "" . - " " . - "
Configuration
" . - " " . - $cgi->scrolling_list( - -name => 'configslist', - -value => [@configsarray], - -size => 10 - ) . - " " . - " " . - - " " . - - " " . - - " " . - - " " . - - " " . - - " " . - - "
" . - $cgi->submit(-name => 'dialog', -value => 'New') . - "
" . - $cgi->submit(-name => 'dialog', -value => 'Copy_Conf') . - "
" . - $cgi->submit(-name => 'dialog', -value => 'Edit') . - "
" . - $cgi->submit(-name => 'dialog', -value => 'Del') . - "
" . - $cgi->submit(-name => 'dialog', -value => 'Run') . - "
" . - $cgi->submit(-name => 'dialog', -value => 'Config_rights') . - "
" . - "
" . - "
" ; - - - $page .= $cgi->endform; - + # Begin with templates part + "" . + "
Active User: $username

\n" . + "
" . + "" . + " " . + " " . + "
Templates
" . + " " . + $cgi->scrolling_list( + -name => 'templatelist', + -value => [@templatesarray], + -size => 3 + ) . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + "
" . + "
" . + $cgi->submit(-name => 'dialog_view', -value => 'View') . + "
" . + $cgi->submit(-name => 'dialog_copyt', -value => 'Copy') . + "
" . + "
" . + " " . + "" . + # Now the configuration part + "

" . + "" . + "" . + " " . + "
Configuration
" . + " " . + $cgi->scrolling_list( + -name => 'configslist', + -value => [@configsarray], + -size => 10 + ) . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + " " . + "
" . + $cgi->submit(-name => 'dialog_new', -value => 'New') . + "
" . + $cgi->submit(-name => 'dialog_del', -value => 'Del') . + "
" . + $cgi->submit(-name => 'dialog_edit', -value => 'Edit') . + "
" . + $cgi->submit(-name => 'dialog_copyc', -value => 'Copy') . + "
" . + $cgi->submit(-name => 'dialog_confr', -value => 'Rights') . + "
" . + $cgi->submit(-name => 'dialog_run', -value => 'Run') . + "
" . + "
" . + "
" ; } -elsif ($dialog eq 'Edit') { +elsif ($form eq 'edit') { # enter Edit form - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); $page .= &edit($cgi->param('configslist')); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; + } -elsif ($dialog eq 'Save') { +elsif ($form eq 'save') { # enter save form - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); $page .= "
" . $cgi->param('editfile') . "
" ; $page .= &save($cgi->param('editfile'), $cgi->param('editwindow')); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'View') { +elsif ($form eq 'view') { # enter View form - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); $page .= &view($cgi->param('templatelist')); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'New') { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +elsif ($form eq 'new') { $page .= &new($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'New_file') { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +#elsif ($dialog eq 'New_file') { +elsif ($form eq 'newf') { $page .= &newfile($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, $cgi->param('newfile'), $cgi->param('new_rights')); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'Config_rights') { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +#elsif ($dialog eq 'Config_rights') { +elsif ($form eq 'confr') { my $configfile; if (! defined $cgi->param('configslist') ) { $configfile = ''; @@ -273,53 +264,40 @@ } $page .= &config_rights($configfile, $username); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'Change_rights') { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +#elsif ($dialog eq 'Change_rights') { +elsif ($form eq 'changer') { $page .= &change_rights($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $cgi->param('filename'), $cgi->param('changerights') ); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'Copy_Temp') { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +#elsif ($dialog eq 'Copy_Temp') { +elsif ($form eq 'copyt') { $page .= ©_file($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" .$cgi->param('templatelist'), $username ); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'Copy_Conf') { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +#elsif ($dialog eq 'Copy_Conf') { +elsif ($form eq 'copyc') { $page .= ©_file($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" .$cgi->param('configslist'), $username ); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'Copy' ) { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +elsif ($form eq 'copy' ) { $page .= ©($cgi->param('srcfile'), $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $username . "/". $cgi->param('dstfile')); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; -$page .= $cgi->endform; } -elsif ($dialog eq 'Del' ) { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +elsif ($form eq 'del' ) { $page .= &del($cgi->param('configslist'), $username ); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } -elsif ($dialog eq 'Run' ) { - $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)); +elsif ($form eq 'run' ) { $page .= &run($cgi->param('configslist') ); $page .= $cgi->hidden(-name => 'password', -default => $password ) ; - $page .= $cgi->endform; } else { die "no correct dialog found"; } - -} else { - die "no configuration found"; -} +$page .= $cgi->endform; my $out = $MY->{TEMPLATE}; $out =~ s|%%BODY%%|$page|s; @@ -353,13 +331,13 @@ next FILE if (((stat($dirname . "/" . $subdir . "/" . $entry))[2]) & 07) != $rights; $filelist .= $subdir . "/" . $entry . " "; } - } - + } return $filelist; } ######################################################################################## + ######################################################################################## sub get_own_files { ######################################################################################## @@ -384,9 +362,6 @@ ######################################################################################## my ($editfile) = @_; my $text; - # enter Edit form - - if($editfile) { my $filename = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $editfile; @@ -394,13 +369,14 @@ $cgi->hidden(-name => 'editfile', -default => $filename ) ; } else { $text .= "Missing filename

\n" . - $cgi->submit(-name => 'dialog', -value => 'Back') ; + $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ; } return $text; } ######################################################################################## + ######################################################################################## sub save { ######################################################################################## @@ -421,12 +397,13 @@ $text .= "Cannot save file

\n" ; } - $text .= $cgi->submit(-name => 'dialog', -value => 'Back'); + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); return $text; } ######################################################################################## + ######################################################################################## sub view { ######################################################################################## @@ -438,7 +415,7 @@ $text .= &editconfig($filename, 'r', $username); } else { $text .= "Missing filename

\n" . - $cgi->submit(-name => 'dialog', -value => 'Back') ; + $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ; } return $text; } @@ -454,7 +431,6 @@ $text= "" . "New File:

\n" . "
" . - "" . " " . " " . @@ -471,12 +447,6 @@ "" . "" . " " . "" . " " . " " . "
New Filename: $dirname " . "/" . "$user" . "/" . "

" . -# $cgi->checkbox_group( -# -name => 'new_rights', -# -values => ['private', 'protected', 'public'], -# -defaults => 'private', -# -linebreak => 'true' -# ) . $cgi->scrolling_list( -name => 'new_rights', -value => ['private', 'protected', 'public'], @@ -488,8 +458,8 @@ "
" . - $cgi->submit(-name => 'dialog', -value => 'Back') . - $cgi->submit(-name => 'dialog', -value => 'New_file') . + $cgi->submit(-name => 'dialog_mainw', -value => 'Back') . + $cgi->submit(-name => 'dialog_newf', -value => 'Create') . "
"; @@ -498,6 +468,9 @@ } ######################################################################################## + + +######################################################################################## sub newfile { ######################################################################################## my ( $dirname, $user, $newfilename, $newrights ) = @_; @@ -533,14 +506,13 @@ } else { $text .= "Cannot write file. It exists

\n" ; } - $text .= $cgi->submit(-name => 'dialog', -value => 'Back'); + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); return $text; } ######################################################################################## - ######################################################################################## sub config_rights { ######################################################################################## @@ -580,16 +552,15 @@ "" . "" . "

" . - $cgi->submit(-name => 'dialog', -value => 'Back') . - $cgi->submit(-name => 'dialog', -value => 'Change_rights'); + $cgi->submit(-name => 'dialog_mainw', -value => 'Back') . + $cgi->submit(-name => 'dialog_changer', -value => 'Set_rights'); } else { $text .= "You can only change file rights in your own directory

\n" . $cgi->submit(-name => 'dialog', -value => 'Back'); } } else { - $text .= "Missing filename

\n" . - $cgi->submit(-name => 'dialog', -value => 'Back'); + $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); } return $text; @@ -607,7 +578,7 @@ $text= "" . "Changing rights of file:
" . "
" . - "
$filename to $newrights
"; + "
$filename to $newrights
"; if ($newrights eq "private" ) { $filerights = ''; } elsif ($newrights eq "protected" ) { @@ -617,10 +588,9 @@ } else { die "Unknown file rights"; } -# $text .= "Name : $filename
Rights: $filerights
" ; system("chmod o=$filerights $filename") && die "Cannot set new file rights"; $text .= "
Done.

" . - $cgi->submit(-name => 'dialog', -value => 'Back'); + $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); return $text; } @@ -665,17 +635,15 @@ "" . " " . " " . " " . "
" . " " . - $cgi->submit(-name => 'dialog', -value => 'Back'). + $cgi->submit(-name => 'dialog_mainw', -value => 'Back'). " " . - $cgi->submit(-name => 'dialog', -value => 'Copy'). + $cgi->submit(-name => 'dialog_copy', -value => 'Copy'). "
" ; - return $text; - } ######################################################################################## @@ -698,7 +666,7 @@ $text .= "You can only delete file in your own directory

\n" ; } - $text .= $cgi->submit(-name => 'dialog', -value => 'Back'); + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); return $text; } @@ -716,14 +684,18 @@ my $fileoutput; my $outputtext = ''; + if ($runfile eq '') { + $text .= "No configuration selected

\n" ; + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); + return $text; + } $rcommand =~ s|%{profile}%|$rpath|s; if (-e $output) { system("/bin/rm $output"); } - - $text= "" . + $text .= "" . "Running Configuration: $rpath

\n" . "
" . "

" . @@ -744,12 +716,14 @@ -columns => 80 }; $outputhash->{readonly}=""; - $text .= $cgi->textarea($outputhash); + $text .= $cgi->textarea($outputhash). + "
" ; } else { $text .= "Run command not working

\n" ; } + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); - $text .= $cgi->submit(-name => 'dialog', -value => 'Back'); + return $text; } ######################################################################################## @@ -768,59 +742,52 @@ system("cp $srcf $dstf") && die "Cannot copy file"; system("chmod o= $dstf") && die "Cannot change file rights"; - $text .= $cgi->submit(-name => 'dialog', -value => 'Back'); + $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back'); return $text; } ######################################################################################## - - ######################################################################################## 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 -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 + $_ =~ s|^([^#]+)#(.*)$|{$_=$1}|es; # Remove comments on the end + $_ =~ s|(.*?)\s+$|{$_=$1}|es; # Remove whitespaces at the end + ($key, $content) = /^(\w+)\s+(.*)$/; - ($key, $content) = /^(\w+)\s+(.*)$/; - - $cfghash{$key} = $content; + $cfghash{$key} = $content; + } + $cfgin->close; + } else { + die "Can't open config file"; } - $cfgin->close; -} - -return (%cfghash); + return (%cfghash); } ######################################################################################## - ######################################################################################## sub validpassword { ######################################################################################## my ($user, $password) = @_; - my $returnvalue = 0; my $uname; my $pwd; @@ -852,8 +819,6 @@ my $filestring = ""; my $direntry = ""; - - opendir(DIR, "$dir"); # Open dir for scanning foreach $direntry (readdir(DIR)) { @@ -866,8 +831,7 @@ closedir(DIR); return $filestring; } - - +######################################################################################## ######################################################################################## @@ -877,8 +841,6 @@ my $filestring = ""; my $direntry = ""; - - opendir(DIR, "$dir"); # Open dir for scanning foreach $direntry (readdir(DIR)) { @@ -909,23 +871,24 @@ ######################################################################################## - - - ######################################################################################## sub editconfig { ######################################################################################## my ($file, $mode, $user) = @_; - my $text = ''; + my $texte = ''; my $filein ; + my $editf = ''; my $readonly ; my $titletext ; $filein = IO::File->new("<$file"); - while(<$filein>) { $text .= $_; } - $filein->close(); - - + 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') { @@ -933,15 +896,14 @@ } my $textahash ={ -name => 'editwindow', - -default => $text, + -default => $editf, -rows => 40, -columns => 80 }; if ($mode eq 'r') { $textahash->{readonly}=""; } - $text .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) . - "" . + $texte .= "" . $titletext . ":

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