OSSP CVS Repository

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

Check-in Number: 2135
Date: 2002-May-15 15:04:20 (local)
2002-May-15 13:04:20 (UTC)
User:ps
Branch:
Comment: Varios cleanups
Tickets:
Inspections:
Files:
ossp-pkg/tabea/tabea.cgi      1.17 -> 1.18     185 inserted, 185 deleted

ossp-pkg/tabea/tabea.cgi 1.17 -> 1.18

--- tabea.cgi    2002/05/15 11:47:41     1.17
+++ tabea.cgi    2002/05/15 13:04:20     1.18
@@ -56,7 +56,7 @@
 
 #   activate a general error handler
 $SIG{__DIE__} = sub {
-    my ($err) = @@_;
+    my ($err) = @_;
 
     #$err =~ s|at\s+\S+\s+line\s+(\d+)|(line $1)|s;
     $err =~ s|\n|<br>\n|sg;
@@ -71,16 +71,22 @@
 #   update cookies
 my $cookies = [];
 foreach my $param (qw(username)) { # FIXME!
-    if ($cgi->param($param) ne '' and ($cgi->param($param) ne $cgi->cookie($param))) {
-        push(@@{$cookies}, $cgi->cookie(
+    my $cookieparam;
+    if (defined $cgi->param($param)) {
+        $cookieparam = $cgi->param($param);
+    } else {
+        $cookieparam = '';
+    }
+    if ($cookieparam ne '' and ($cookieparam ne $cgi->cookie($param))) {
+        push(@{$cookies}, $cgi->cookie(
              -name    => $param,
-             -value   => $cgi->param($param),
+             -value   => $cookieparam,
              -expires => '+1d',
              -path    => $cgi->url(-absolute => 1),
              -secure  => 0
         ));
     }
-    if ($cgi->param($param) eq '' and $cgi->cookie($param) ne '') {
+    if ($cookieparam eq '' and $cookieparam ne '') {
          $cgi->param(-name => $param, -value => [$cgi->cookie($param)]);
     }
 }
@@ -88,8 +94,6 @@
 # Read the configuration
 my %cfghash = read_config($cfgfile);
 
-#print "Test: $cfghash{'TabeaUser'}\n";
-
 
 #   fetch parameters
 my $dialog   = $cgi->param("dialog")   || "";
@@ -103,38 +107,37 @@
 
 if ($dialog eq "") {
     $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
-#        $cgi->hidden(-name => 'form', -default => ['login']) .
-        "<table cellspacing=0 cellpadding=0>" .
-        "  <tr>" .
-        "    <td>Username:</td>" .
-        "    <td>" .
-        $cgi->textfield(
-            -name => 'username',
-            -default => $username,
-            -size => 20,
-            -maxlength => 8
-        ) .
-        "    </td>" .
-        "  </tr>" .
-        "  <tr>" .
-        "    <td>Password:</td>" .
-        "    <td>" .
-        $cgi->password_field(
-            -name => 'password',
-            -value => $password,
-            -size => 20,
-            -maxlength => 80
-        ) .
-        "    </td>" .
-        "  </tr>" .
-        "  <tr>" .
-        "    <td colspan=2 align=right>" .
-        $cgi->reset() .
-        $cgi->submit(-name => 'dialog', -value => 'login') .
-        "    </td>" .
-        "  </tr>" .
-        "</table>" .
-        $cgi->endform;
+    "<table cellspacing=0 cellpadding=0>" .
+    "  <tr>" .
+    "    <td>Username:</td>" .
+    "    <td>" .
+    $cgi->textfield(
+        -name => 'username',
+        -default => $username,
+        -size => 20,
+        -maxlength => 8
+    ) .
+    "    </td>" .
+    "  </tr>" .
+    "  <tr>" .
+    "    <td>Password:</td>" .
+    "    <td>" .
+    $cgi->password_field(
+        -name => 'password',
+        -value => $password,
+        -size => 20,
+        -maxlength => 80
+    ) .
+    "    </td>" .
+    "  </tr>" .
+    "  <tr>" .
+    "    <td colspan=2 align=right>" .
+    $cgi->reset() .
+    $cgi->submit(-name => 'dialog', -value => 'login') .
+    "    </td>" .
+    "  </tr>" .
+    "</table>" .
+    $cgi->endform;
 }
 elsif (($dialog eq 'login') || ($dialog eq 'Back')) {
     #   enter Select form
@@ -143,9 +146,6 @@
     &validpassword($username, $password, $cfghash{'BaseDir'}.$cfghash{'PasswdFile'}) || print STDOUT $cgi->redirect(-uri => $cgi->url(-full => 1), -type => "text/html");
 
      
-#    my $templatesfiles = &readdir($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} ."/".$cfghash{'TabeaUser'});
-#    my $configsfiles = &readdir($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} ."/".$username);
-
     my $templatesfiles = &get_name_files($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, 4);
     my $configsfiles = &get_name_files($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, 6);
 
@@ -154,113 +154,112 @@
     $templatesfiles = &strsort($templatesfiles);
     $configsfiles = &strsort($configsfiles);
     
-    my @@templatesarray = split(/ /,$templatesfiles);
-    my @@configsarray = split(/ /,$configsfiles);
+    my @templatesarray = split(/ /,$templatesfiles);
+    my @configsarray = split(/ /,$configsfiles);
     
     
-#
      $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
-        $cgi->hidden(-name => 'form', -default => ['']) .
+     $cgi->hidden(-name => 'password', -default => $password ) .
 # Begin with templates part         
-        "<font size=+1>" .
-        "<br> Active User: $username<br><br>\n" .
-        "</font>" .
-        "<table> <caption>Templates</caption>" .
-        "  <td>" . 
-        "    <td>" .
-        $cgi->scrolling_list(
-            -name => 'templatelist',
-            -value => [@@templatesarray],
-            -size => 3
-        ) .
-        "   </td>" .
-        "  <td>" .
-        "    <table>" .
-        "   <td>" .
-        "   <tr>" .
-        "     <td>" .
-        $cgi->submit(-name => 'dialog', -value => 'Copy_Temp') .
-        "     </td>" .
-        "   </tr>" .
-        "   <tr>" .
-        "     <td>" .
-        $cgi->submit(-name => 'dialog', -value => 'View') .
-        "     </td>" .
-        "   </tr>" .
-        "   </td>" .
-        "   </table>" .
-        "   </td>" .
-        "   </table>" .
-        " </td>" .
-        "</table>" .
+     "<font size=+1>" .
+     "<br> Active User: $username<br><br>\n" .
+     "</font>" .
+     "<table> <caption>Templates</caption>" .
+     "  <td>" . 
+     "    <td>" .
+     $cgi->scrolling_list(
+        -name => 'templatelist',
+        -value => [@templatesarray],
+        -size => 3
+     ) .
+     "   </td>" .
+     "  <td>" .
+     "    <table>" .
+     "   <td>" .
+     "   <tr>" .
+     "     <td>" .
+     $cgi->submit(-name => 'dialog', -value => 'Copy_Temp') .
+     "     </td>" .
+     "   </tr>" .
+     "   <tr>" .
+     "     <td>" .
+     $cgi->submit(-name => 'dialog', -value => 'View') .
+     "     </td>" .
+     "   </tr>" .
+     "   </td>" .
+     "   </table>" .
+     "   </td>" .
+     "   </table>" .
+     " </td>" .
+     "</table>" .
 
 # Now the configuration part         
-        "<br><br>" .
-        "<table> <caption>Configuration</caption>" .
-        "<td>" .
-        "    <td>" .
-        $cgi->scrolling_list(
-            -name => 'configslist',
-            -value => [@@configsarray],
-            -size => 10
-        ) .
-        "   </td>" .
-        "   <td>" .
-        "     <table>" .
-
-        "      <tr><td>" .
-        $cgi->submit(-name => 'dialog', -value => 'New') .
-        "      </td></tr>" .
-
-        "      <tr><td>" .
-        $cgi->submit(-name => 'dialog', -value => 'Copy_Conf') .
-        "      </td></tr>" .
-
-        "      <tr><td>" .
-        $cgi->submit(-name => 'dialog', -value => 'Edit') .
-        "      </td></tr>" .
-
-        "      <tr><td>" .
-        $cgi->submit(-name => 'dialog', -value => 'Del') .
-        "      </td></tr>" .
-
-        "      <tr><td>" .
-        $cgi->submit(-name => 'dialog', -value => 'Run') .
-        "      </td></tr>" .
-
-        "      <tr><td>" .
-        $cgi->submit(-name => 'dialog', -value => 'Config_rights') .
-        "      </td></tr>" .
-
-        "    </table>" .
-        "  </td>" .
-        "<td>" .
-        "</table>" ;
-
-
-        $page .= $cgi->endform;  
+     "<br><br>" .
+     "<table> <caption>Configuration</caption>" .
+     "<td>" .
+     "    <td>" .
+     $cgi->scrolling_list(
+        -name => 'configslist',
+        -value => [@configsarray],
+        -size => 10
+      ) .
+      "   </td>" .
+      "   <td>" .
+      "     <table>" .
+      "      <tr><td>" .
+      $cgi->submit(-name => 'dialog', -value => 'New') .
+      "      </td></tr>" .
+      "      <tr><td>" .
+      $cgi->submit(-name => 'dialog', -value => 'Copy_Conf') .
+      "      </td></tr>" .
+      "      <tr><td>" .
+      $cgi->submit(-name => 'dialog', -value => 'Edit') .
+      "      </td></tr>" .
+      "      <tr><td>" .
+      $cgi->submit(-name => 'dialog', -value => 'Del') .
+      "      </td></tr>" .
+      "      <tr><td>" .
+      $cgi->submit(-name => 'dialog', -value => 'Run') .
+      "      </td></tr>" .
+      "      <tr><td>" .
+      $cgi->submit(-name => 'dialog', -value => 'Config_rights') .
+      "      </td></tr>" .
+      "    </table>" .
+      "  </td>" .
+      "<td>" .
+      "</table>" .
+      $cgi->endform;  
 
 }
 elsif ($dialog eq 'Edit') {
     #   enter Edit form
-        $page .= &edit($cgi->param('configslist'));
+    $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 '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));
+    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
     $page .= &new($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username);
     $page .= $cgi->endform;
 }
 elsif ($dialog eq 'New_file') {
     $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1));
+    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
     $page .= &newfile($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, $cgi->param('newfile'), $cgi->param('new_rights'));
     $page .= $cgi->endform;
 }
 elsif ($dialog eq 'Config_rights') {
     $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1));
+    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
     my $configfile;        
     if (! defined $cgi->param('configslist') ) {
         $configfile = '';
@@ -273,6 +272,7 @@
 }
 elsif ($dialog eq 'Change_rights') {
     $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1));
+    $page .= $cgi->hidden(-name => 'password', -default => $password ) ;
     $page .= &change_rights($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" .  $cgi->param('filename'), $cgi->param('changerights') );
     $page .= $cgi->endform;
 }
@@ -292,22 +292,22 @@
 ########################################################################################
 sub get_name_files {
 ########################################################################################
-    my ($dirname, $user, $rights) = @@_;
+    my ($dirname, $user, $rights) = @_;
     my $filel = '';
-    my @@filelarray;
+    my @filelarray;
     my $filelist = '';
     my $subdir = '';
     my $filemode = '';
     my $entry = '';
 
     my $dirlist = &readsubdir($dirname . "/" );    
-    my @@dirarray =  split (/ /, $dirlist);
+    my @dirarray =  split (/ /, $dirlist);
 
-    DIR: foreach $subdir (@@dirarray)  {
+    DIR: foreach $subdir (@dirarray)  {
         next DIR if $subdir eq $user;
         $filel = &readdir($dirname . "/" . $subdir . "/") ;
-        @@filelarray = split (/ /, $filel);
-        FILE: foreach $entry (@@filelarray) {
+        @filelarray = split (/ /, $filel);
+        FILE: foreach $entry (@filelarray) {
             my $path = $dirname . "/" . $subdir . "/" . $entry;
             next FILE if  (((stat($dirname . "/" . $subdir . "/" . $entry))[2]) & 07)  !=  $rights;
             $filelist .= $subdir . "/" . $entry . " ";
@@ -322,14 +322,14 @@
 ########################################################################################
 sub get_own_files {
 ########################################################################################
-    my ($dirname, $user) = @@_;
+    my ($dirname, $user) = @_;
     my $filelist = '';
     my $entry = '';
 
     my $flist = &readdir($dirname . "/" . $user . "/");
-    my @@flistarray = split (/ /,$flist);
+    my @flistarray = split (/ /,$flist);
 
-    foreach $entry (@@flistarray) {
+    foreach $entry (@flistarray) {
         $filelist .= $user . "/" . $entry . " ";
     }
 
@@ -341,7 +341,7 @@
 ########################################################################################
 sub edit {
 ########################################################################################
-    my ($file) = @@_;
+    my ($file) = @_;
     my $text;
     #   enter Edit form
     if($file) {
@@ -350,8 +350,7 @@
     } else {
         $text = $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
         "<font color=red>Missing iilename<br><br>\n" .
-        $cgi->submit(-name => 'dialog', -value => 'Back') .
-        $cgi->endform;
+        $cgi->submit(-name => 'dialog', -value => 'Back') ;
     }
     return $text;
 }
@@ -361,17 +360,15 @@
 ########################################################################################
 sub view {
 ########################################################################################
-    my ($file) = @@_; 
+    my ($file) = @_; 
     my $text;
     
     if ($file) {
         my $filename = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $cgi->param('templatelist');
         &editconfig($filename, 'r', $username);
     } else {
-        $text .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
-        "<font color=red>Missing filename<br><br>\n" .
-        $cgi->submit(-name => 'dialog', -value => 'Back') .
-        $cgi->endform;
+        $text .= "<font color=red>Missing filename<br><br>\n" .
+        $cgi->submit(-name => 'dialog', -value => 'Back') ;
     }
     return $text;
 }
@@ -381,7 +378,7 @@
 #########################################################################################
 sub new {
 ########################################################################################
-    my ( $dirname, $user ) = @@_;
+    my ( $dirname, $user ) = @_;
     my $text = '';
 
     $text= "<font size=+2>" .
@@ -433,32 +430,43 @@
 ########################################################################################
 sub newfile {
 ########################################################################################
-    my ( $dirname, $user, $newfilename, $newrights ) = @@_;
+    my ( $dirname, $user, $newfilename, $newrights ) = @_;
     my $text = '';
     my $newpath = $dirname . "/" . $user . "/" . $newfilename;
+    my $filesinpath = &readdir($dirname . "/" . $user . "/");
+    my @filesinpatharray = split(/ /,$filesinpath);
+    my $canwrite = 1;   # true
     my $filerights = '';
 
     $text= "<font size=+2>" .
-    "Creating New File:<br><br>" .
+    "Creating New File: $newfilename <br><br>" .
     "</font><br><br><br>" ;
-    system("touch $newpath") && die "Cannot create new file";
-    if ($newrights eq "private" ) {
-        $filerights = '';
-    } elsif ($newrights eq "protected" ) {
-        $filerights = "r";
-    } elsif ($newrights eq "public" ) {
-        $filerights = "rw";
+    foreach (@filesinpatharray) {
+        if ( $_ eq $newfilename) { $canwrite = 0; };
+    } 
+    $text .= "$canwrite<br><br>"; 
+    if ( $canwrite ) { 
+        system("touch $newpath") && die "Cannot create new file";
+        if ($newrights eq "private" ) {
+            $filerights = '';
+        } elsif ($newrights eq "protected" ) {
+            $filerights = "r";
+        } elsif ($newrights eq "public" ) {
+            $filerights = "rw";
+        } else {
+            die "Unknown file rights";   
+        }
+        $text .= "Creating the new file $newpath<br><br>";
+        system("touch $newpath") && die "Cannot create new file";
+        $text .= "Setting new file rights for $newpath<br><br>";
+        system("chmod u=rw $newpath") && die "Cannot set new file rights";
+        system("chmod o=$filerights $newpath") && die "Cannot set new file rights";
+        # Checking that file dont exist: TODO
+        $text .= "<br><br><br>" ;
     } else {
-        die "Unknown file rights";   
+        $text .= "<font color=red>Cannot write file. It exists<br><br>\n" ;
     }
-    $text .= "Creating the new file $newpath<br><br>";
-    system("touch $newpath") && die "Cannot create new file";
-    $text .= "Setting new file rights for $newpath<br><br>";
-    system("chmod u=rw $newpath") && die "Cannot set new file rights";
-    system("chmod o=$filerights $newpath") && die "Cannot set new file rights";
-    # Checking that file dont exist: TODO
-    $text .= "<br><br><br>" .
-    $cgi->submit(-name => 'dialog', -value => 'Back');
+    $text .= $cgi->submit(-name => 'dialog', -value => 'Back');
 
     return $text;
 }
@@ -469,18 +477,12 @@
 ########################################################################################
 sub config_rights {
 ########################################################################################
-    my ( $namefile, $user ) = @@_; 
+    my ( $namefile, $user ) = @_; 
     my $text = '';
     my $defaultright = '';
-    my $filerights = stat( (($namefile)[2]) & 07 );
-    my $fnamehash ={ -name => 'filename',
-          -default => $namefile,
-          -size => 20,
-          -maxlength => 30
-    };
-    $fnamehash->{readonly}="";
+    my $filerights = (stat($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $namefile))[2] & 07;
     
-#    $text .= $cgi->hidden(-name => 'filename', -default => ['xxx', 'xxx2'] ) ;
+    $text .= $cgi->hidden(-name => 'filename', -default => $namefile ) ;
     if ( $filerights == 6 ) {
         $defaultright = "public" ;     
     } elsif ( $filerights == 4 ) {
@@ -489,7 +491,7 @@
         $defaultright = "private" ;
     }
 
-    $text= "<font size=+2>" .
+    $text .= "<font size=+2>" .
     "Changing rights of file:<br><br>" ;
     
     if ($namefile ne '') {
@@ -498,7 +500,7 @@
             $text .= "<table>" .
             "<tr>" .
             " <td>" . 
-            $cgi->textfield($fnamehash). 
+            "$namefile<br>" .
             " </td>" .
             " <td>" . 
             $cgi->scrolling_list(
@@ -514,15 +516,14 @@
             $cgi->submit(-name => 'dialog', -value => 'Back') .
             $cgi->submit(-name => 'dialog', -value => 'Change_rights');
         } else {
-            $text .= "<font color=red>You can only change file rights in your directory<br><br>\n" .
-            $cgi->submit(-name => 'dialog', -value => 'Back');
+            $text .= "<font color=red>You can only change file rights in your directory<br><br>\n";
         }
     } else {
-
-        $text .= "<font color=red>Missing filename<br><br>\n" .
-        $cgi->submit(-name => 'dialog', -value => 'Back');
+        $text .= "<font color=red>Missing filename<br><br>\n" ;
     }
 
+    $text .= $cgi->submit(-name => 'dialog', -value => 'Back');
+
    return $text;
 }
 ########################################################################################
@@ -531,7 +532,7 @@
 ########################################################################################
 sub change_rights {
 ########################################################################################
-    my ( $filename, $newrights ) = @@_;
+    my ( $filename, $newrights ) = @_;
     my $text = '';
     my $filerights = '';
 
@@ -548,7 +549,6 @@
     } else {
            die "Unknown file rights";
     }
-#    $text .= "Name : $filename<br>Rights: $filerights<br>" ;
     system("chmod o=$filerights $filename") && die "Cannot set new file rights";
     $text .= "<br>Done.<br><br>" .
     $cgi->submit(-name => 'dialog', -value => 'Back');
@@ -563,7 +563,7 @@
 sub read_config {
 ########################################################################################
 
-my ($cfgfile) = @@_;   
+my ($cfgfile) = @_;   
 my %cfghash ;
 my $cfgin ;
 my $key;
@@ -601,7 +601,7 @@
 ########################################################################################
 sub validpassword {
 ########################################################################################
-    my ($user, $password) = @@_;
+    my ($user, $password) = @_;
 
     my $returnvalue = 0;
     my $uname;
@@ -630,7 +630,7 @@
 ########################################################################################
 sub readsubdir {
 ########################################################################################
-    my ( $dir ) = @@_;
+    my ( $dir ) = @_;
     my $filestring = "";
     my $direntry = "";
 
@@ -655,7 +655,7 @@
 ########################################################################################
 sub readdir {
 ########################################################################################
-    my ( $dir ) = @@_;
+    my ( $dir ) = @_;
     my $filestring = "";
     my $direntry = "";
 
@@ -679,12 +679,12 @@
 ########################################################################################
 sub strsort {
 ########################################################################################
-    my ( $sortstr ) = @@_;
+    my ( $sortstr ) = @_;
 
-    my @@sortarray = split (/ /, $sortstr);
+    my @sortarray = split (/ /, $sortstr);
      
-    @@sortarray = reverse sort {$b cmp $a} @@sortarray;
-    $sortstr = join(" ", @@sortarray);
+    @sortarray = reverse sort {$b cmp $a} @sortarray;
+    $sortstr = join(" ", @sortarray);
 
     return $sortstr;
 }
@@ -697,7 +697,7 @@
 ########################################################################################
 sub editconfig {
 ########################################################################################
-    my ($file, $mode, $user) = @@_;
+    my ($file, $mode, $user) = @_;
     my $text = '';
     my $filein ;
     my $readonly ;

CVSTrac 2.0.1