OSSP CVS Repository

ossp - Check-in [2140]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 2140
Date: 2002-May-17 15:00:04 (local)
2002-May-17 13:00:04 (UTC)
User:ps
Branch:
Comment: Cleanups and error correcting
Tickets:
Inspections:
Files:
ossp-pkg/tabea/tabea.cgi      1.22 -> 1.23     182 inserted, 162 deleted

ossp-pkg/tabea/tabea.cgi 1.22 -> 1.23

--- tabea.cgi    2002/05/17 08:09:07     1.22
+++ tabea.cgi    2002/05/17 13:00:04     1.23
@@ -36,6 +36,7 @@
 
 $|++;
 
+
 my $cfgfile    = "./tabea.cfg";
 my $pwdfile    = "./tabea.pw";
 my $configsdir = "./tabea.d";
@@ -99,15 +100,77 @@
         $form = $name;
     }
 }
-    
+
+NEXTFORM:    
 my $page = $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1));
 
-#if ($dialog eq "") {
 if ($form eq '') {
-#    if ($form eq "mainw") {
-#        $page .= "Form new is login<br><br>";
-#    }
-    $page .= 
+    $page .= &login();
+}
+elsif ($form eq 'mainw') {
+    $page .= mainw(); 
+}
+elsif ($form eq 'edit') {
+    $page .= &edit($cgi->param('configslist'));
+} 
+elsif ($form eq 'save') {
+    $page .= &save($cgi->param('editfile'), $cgi->param('editwindow'));
+}
+elsif ($form eq 'view') {
+    $page .= &view($cgi->param('templatelist'));
+}
+elsif ($form eq 'new') {
+    $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'));
+}
+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') );
+}
+elsif ($form eq 'copyt') {
+    $page .= &copy_file($cgi->param('templatelist') );
+}
+elsif ($form eq 'copyc') {
+    $page .= &copy_file($cgi->param('configslist'));
+}
+elsif ($form eq 'copy' ) {
+    $page .= &copy($cgi->param('srcfile'), $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" .  
+                   $username . "/". $cgi->param('dstfile'));
+}
+elsif ($form eq 'del' ) {
+    $page .= &del($cgi->param('configslist'));
+}
+elsif ($form eq 'run' ) {
+    $page .= &run($cgi->param('configslist') );
+}
+else {
+    die "no correct dialog found";
+}
+
+$page .= $cgi->hidden(-name => 'password', -default => $password ) ;
+$page .= $cgi->endform;
+
+my $out = $MY->{TEMPLATE};
+$out =~ s|%%BODY%%|$page|s;
+$out =~ s|%%TITLE%%|Test|s;
+
+print $cgi->header(-cookie => $cookies, -expires => '+1s') . $out;
+
+exit (0);
+############### End of main part #######################################################
+
+########################################################################################
+sub login{
+########################################################################################
+    my $text = '';
+
+    $text .= 
     "<table cellspacing=0 cellpadding=0>" .
     "  <tr>" .
     "    <td>Username:</td>" .
@@ -138,11 +201,17 @@
     "    </td>" .
     "  </tr>" .
     "</table>" ;
+
+    return $text;
 }
-#elsif (($dialog eq 'login') || ($dialog eq 'Back')) {
-elsif ($form eq 'mainw') {
-    #   enter Select form
-    
+########################################################################################
+
+
+########################################################################################
+sub mainw {
+########################################################################################
+    my $text = '';
+
     &validpassword($username, $password, $cfghash{'BaseDir'}.$cfghash{'PasswdFile'}) 
                 || print STDOUT $cgi->redirect(-uri => $cgi->url(-full => 1), -type => "text/html");
 
@@ -157,8 +226,7 @@
     my @templatesarray = split(/ /,$templatesfiles);
     my @configsarray = split(/ /,$configsfiles);
            
-    $page .= 
-    $cgi->hidden(-name => 'password', -default => $password ) .
+    $text .= 
     # Begin with templates part         
     "<font size=+1>" .
     "<br> Active User: $username<br><br>\n" .
@@ -226,86 +294,10 @@
     "  </td>" .
     "<td>" .
     "</table>" ;
-}
-elsif ($form eq 'edit') {
-    #   enter Edit form
-    $page .= &edit($cgi->param('configslist'));
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-    
-} 
-elsif ($form eq 'save') {
-    #  enter save form
-    $page .= "<br>" . $cgi->param('editfile') . "<br>" ;
-    $page .= &save($cgi->param('editfile'), $cgi->param('editwindow'));
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-elsif ($form eq 'view') {
-    #   enter View form
-    $page .= &view($cgi->param('templatelist'));
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-elsif ($form eq 'new') {
-    $page .= &new($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username);
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-#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 ) ;
-}
-#elsif ($dialog eq 'Config_rights') {
-elsif ($form eq 'confr') {
-    my $configfile;        
-    if (! defined $cgi->param('configslist') ) {
-        $configfile = '';
-    } else {
-        $configfile = $cgi->param('configslist');
-    }
-    $page .= &config_rights($configfile, $username);
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-#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 ) ;
-}
-#elsif ($dialog eq 'Copy_Temp') {
-elsif ($form eq 'copyt') {
-    $page .= &copy_file($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" .$cgi->param('templatelist'), $username );
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-#elsif ($dialog eq 'Copy_Conf') {
-elsif ($form eq 'copyc') {
-    $page .= &copy_file($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" .$cgi->param('configslist'), $username );
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-elsif ($form eq 'copy' ) {
-    $page .= &copy($cgi->param('srcfile'), $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" .  $username . "/". $cgi->param('dstfile'));
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-elsif ($form eq 'del' ) {
-    $page .= &del($cgi->param('configslist'), $username );
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-elsif ($form eq 'run' ) {
-    $page .= &run($cgi->param('configslist') );
-    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
-}
-else {
-    die "no correct dialog found";
-}
-
-$page .= $cgi->endform;
-
-my $out = $MY->{TEMPLATE};
-$out =~ s|%%BODY%%|$page|s;
-$out =~ s|%%TITLE%%|Test|s;
-
-print $cgi->header(-cookie => $cookies, -expires => '+1s') . $out;
 
-exit (0);
+    return $text;
+}    
+########################################################################################
 
 
 ########################################################################################
@@ -393,6 +385,8 @@
     if (defined $fileout) {
         print $fileout $edittext;
         $fileout->close;
+        $form = 'mainw';
+        goto NEXTFORM;
     } else {
         $text .= "<font color=red>Cannot save file<br><br>\n" ;
     }
@@ -503,8 +497,10 @@
         system("chmod u=rw $newpath") && die "Cannot set new file rights";
         system("chmod o=$filerights $newpath") && die "Cannot set new file rights";
         $text .= "<br><br><br>" ;
+        $form = 'mainw';
+        goto NEXTFORM;
     } else {
-        $text .= "<font color=red>Cannot write file. It exists<br><br>\n" ;
+        $text .= "<font color=red>Cannot write file. File exists<br><br>\n" ;
     }
     $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back');
 
@@ -516,26 +512,28 @@
 ########################################################################################
 sub config_rights {
 ########################################################################################
-    my ( $namefile, $user ) = @_; 
+    my ( $namefile ) = @_; 
     my $text = '';
     my $defaultright = '';
-    my $filerights = (stat($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $namefile))[2] & 07;
-   
-    $text .= $cgi->hidden(-name => 'filename', -default => $namefile ) ; 
-    if ( $filerights == 6 ) {
-        $defaultright = "public" ;     
-    } elsif ( $filerights == 4 ) {
-        $defaultright = "protected" ;
-    } else {
-        $defaultright = "private" ;
-    }
-
-    $text .= "<font size=+2>" .
-    "Changing rights of file:<br><br>" ;
+    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" ;
+        } else {
+            $defaultright = "private" ;
+        }
+
+        $text .= "<font size=+2>" .
+        "Changing rights of file:<br><br>" ;
+   
         $namefile =~ m{^([a-zA-Z0-9!"£$%^&*()-_=+#~]+)/(.+)}sg;
-        if ($1 eq $user) {
+        if ($1 eq $username) {
             $text .= "<table>" .
             "<tr>" .
             " <td>" . 
@@ -554,6 +552,8 @@
             "<br><br>" .
             $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 .= "<font color=red>You can only change file rights in your own directory<br><br>\n" .
             $cgi->submit(-name => 'dialog', -value => 'Back');
@@ -589,8 +589,8 @@
            die "Unknown file rights";
     }
     system("chmod o=$filerights $filename") && die "Cannot set new file rights";
-    $text .= "<br>Done.<br><br>" .
-    $cgi->submit(-name => 'dialog_mainw', -value => 'Back');
+    $form = 'mainw';
+    goto NEXTFORM;
 
     return $text;
 }
@@ -600,48 +600,59 @@
 ########################################################################################
 sub copy_file {
 ########################################################################################
-    my ( $srcfile, $user ) = @_;
+    my ( $filename ) = @_;
     my $text = '';
     
-    $text .= $cgi->hidden(-name => 'srcfile', -default => $srcfile ) .
-    "<font size=+1>" .
-    "Copying File:<br>" .
-    "</font>" .
-    "<br><br>" .
-    "Active user: $user<br>" .
-    "<table border=1 width=50%>" .
-    " <tr>" .
-    "  <td>Sourcefile :</td>" .
-    "  <td>Destinationfile</td>" .
-    " </tr>" .
-    " <tr>" .
-    "  <td>$srcfile</td>" . 
-    "  <td>" .
-    "   <table>" .
-    "   <tr>" .
-    "    <td>" . $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $user . "/</td>" .
-    "    <td>" .
-    $cgi->textfield(-name=>'dstfile',
-                    -default=>'',
-                    -size=>30,
-                    -maxlength=>80) .
-    "   </td>" .
-    "   </tr>" .
-    "   </table>" .
-    "  </td>" .
-    " </tr>" .
-    "</table>" .
-    "<br><br>" .
-    "<table>" .
-    " <td>" .
-    " <td>" .
-    $cgi->submit(-name => 'dialog_mainw', -value => 'Back').
-    " </td>" .    
-    " <td>" .
-    $cgi->submit(-name => 'dialog_copy', -value => 'Copy').
-    " </td>" .    
-    " </td>" .    
-    "</table>" ;
+
+
+    if ($filename) {
+        my $srcfile = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $filename; 
+        $text .= $cgi->hidden(-name => 'srcfile', -default => $srcfile ) .
+        "<font size=+1>" .
+        "Copying File:<br>" .
+        "</font>" .
+        "<br><br>" .
+        "Active user: $username<br>" .
+        "<br>" .
+        "<table border=1 width=50%>" .
+        " <tr>" .
+        "  <td>Sourcefile :</td>" .
+        "  <td>Destinationfile</td>" .
+        " </tr>" .
+        " <tr>" .
+        "  <td>$srcfile</td>" . 
+        "  <td>" .
+        "   <table>" .
+        "   <tr>" .
+        "    <td>" . $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $username . "/</td>" .
+        "    <td>" .
+        $cgi->textfield(
+            -name=>'dstfile',
+            -default=>'',
+            -size=>30,
+            -maxlength=>80
+        ) .
+        "   </td>" .
+        "   </tr>" .
+        "   </table>" .
+        "  </td>" .
+        " </tr>" .
+        "</table>" .
+        "<br><br>" .
+        "<table>" .
+        " <td>" .
+        " <td>" .
+        $cgi->submit(-name => 'dialog_mainw', -value => 'Back').
+        " </td>" .    
+        " <td>" .
+        $cgi->submit(-name => 'dialog_copy', -value => 'Copy').
+        " </td>" .    
+        " </td>" .    
+        "</table>" ;
+    } else {
+        $text .= "<font color=red>Missing filename<br><br>\n" .
+        $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ;
+    }
 
     return $text; 
 }
@@ -651,23 +662,31 @@
 ########################################################################################
 sub del {
 ########################################################################################
-    my ( $delfile, $user ) = @_;
+    my ( $delfile ) = @_;
     my $text = '';
-    my $fpath = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $delfile;
 
-    $text= "<font size=+2>" .
-    "Delete File: $fpath<br><br>\n" .
-    "</font>" .
-    "<br><br>" ;
-    $delfile =~ m{^([a-zA-Z0-9!"<A3>$%^&*()-_=+#~]+)/(.+)}sg;
-    if ( $1 eq $user ) {
+    if ($delfile) {
+        my $fpath = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $delfile;
+
+        $text= "<font size=+2>" .
+        "Delete File: $fpath<br><br>\n" .
+        "</font>" .
+        "<br><br>" ;
+        $delfile =~ m{^([a-zA-Z0-9!"<A3>$%^&*()-_=+#~]+)/(.+)}sg;
+        if ( $1 eq $username ) {
             system("rm $fpath") && die "Cannot delete file";
+            $form = 'mainw';
+            goto NEXTFORM;
+        } else {
+            $text .= "<font color=red>You can only delete file in your own directory<br><br>\n" ;
+        }
     } else {
-        $text .= "<font color=red>You can only delete file in your own directory<br><br>\n" ;
+        $text .= "<font color=red>Missing filename<br><br>\n" ;
     }
-    
-    $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back');
 
+    
+    $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back') ;
+    
     return $text;
 }
 ########################################################################################
@@ -742,8 +761,9 @@
     system("cp $srcf $dstf") && die "Cannot copy file";
     system("chmod o= $dstf") && die "Cannot change file rights";
 
-    $text .= $cgi->submit(-name => 'dialog_mainw', -value => 'Back');
-
+    $form = 'mainw';
+    goto NEXTFORM; 
+    
     return $text;
 }
 ########################################################################################

CVSTrac 2.0.1