--- tabea.cgi 2002/05/15 15:34:06 1.19
+++ tabea.cgi 2002/05/16 12:22:05 1.20
@@ -27,6 +27,7 @@
##
## tabea.cgi: Tabea CGI (syntax: Perl)
##
+##
require 5.000;
use strict;
@@ -35,13 +36,10 @@
$|++;
-
-my $cfgfile = "./tabea.cfg"; # Name of configuration file
-
-my $pwdfile = "./tabea.pw";
+my $cfgfile = "./tabea.cfg";
+my $pwdfile = "./tabea.pw";
my $configsdir = "./tabea.d";
-
# establish my configuration
my $MY = {};
$MY->{PROGNAME} = ($0 =~ m|^.*?([^/]+?)(?:\.[^/.]+)?$|)[0];
@@ -70,22 +68,16 @@
# update cookies
my $cookies = [];
foreach my $param (qw(username)) { # FIXME!
- my $cookieparam;
- if (defined $cgi->param($param)) {
- $cookieparam = $cgi->param($param);
- } else {
- $cookieparam = '';
- }
- if ($cookieparam ne '' and ($cookieparam ne $cgi->cookie($param))) {
+ if ($cgi->param($param) ne '' and ($cgi->param($param) ne $cgi->cookie($param))) {
push(@{$cookies}, $cgi->cookie(
-name => $param,
- -value => $cookieparam,
+ -value => $cgi->param($param),
-expires => '+1d',
-path => $cgi->url(-absolute => 1),
-secure => 0
));
}
- if ($cookieparam eq '' and $cookieparam ne '') {
+ if ($cgi->param($param) eq '' and $cgi->cookie($param) ne '') {
$cgi->param(-name => $param, -value => [$cgi->cookie($param)]);
}
}
@@ -93,7 +85,6 @@
# Read the configuration
my %cfghash = read_config($cfgfile);
-
# fetch parameters
my $dialog = $cgi->param("dialog") || "";
my $username = $cgi->param("username") || "";
@@ -105,46 +96,45 @@
if ($cfghash{"TabeaUser"} ne '') {
if ($dialog eq "") {
- $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
- "<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;
+ $page .=
+ $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
+ "<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
-
&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);
@@ -156,78 +146,86 @@
my @templatesarray = split(/ /,$templatesfiles);
my @configsarray = split(/ /,$configsfiles);
-
- $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
- $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>" .
+ $page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
+ $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>" .
# 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>" .
- $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>" ;
+
+
+ $page .= $cgi->endform;
}
elsif ($dialog eq 'Edit') {
@@ -237,6 +235,9 @@
$page .= $cgi->hidden(-name => 'password', -default => $password ) ;
$page .= $cgi->endform;
}
+elsif ($dialog eq 'Save') {
+ ## FIXME
+}
elsif ($dialog eq 'View') {
# enter View form
$page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1));
@@ -246,19 +247,19 @@
}
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->hidden(-name => 'password', -default => $password ) ;
$page .= $cgi->endform;
}
elsif ($dialog eq 'New_file') {
$page .= $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1));
+ $page .= &newfile($cfghash{'BaseDir'} . $cfghash{'ConfigDir'}, $username, $cgi->param('newfile'),
+ $cgi->param('new_rights'));
$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 = '';
@@ -266,15 +267,41 @@
$configfile = $cgi->param('configslist');
}
$page .= &config_rights($configfile, $username);
- # $page .= "Returnvalue: " . $cgi->param('filename') . "<br>";
+ $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));
+ $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));
+ $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));
+ $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));
+ $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));
+ $page .= &del($cgi->param('configslist'), $username );
$page .= $cgi->hidden(-name => 'password', -default => $password ) ;
- $page .= &change_rights($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $cgi->param('filename'), $cgi->param('changerights') );
$page .= $cgi->endform;
}
+
} else {
die "no configuration found";
}
@@ -347,8 +374,7 @@
my $filename = $cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $file;
&editconfig($filename, 'w', $username);
} else {
- $text = $cgi->startform( -method => "POST", -action => $cgi->url(-full => 1)) .
- "<font color=red>Missing iilename<br><br>\n" .
+ $text .= "<font color=red>Missing filename<br><br>\n" .
$cgi->submit(-name => 'dialog', -value => 'Back') ;
}
return $text;
@@ -442,10 +468,8 @@
"</font><br><br><br>" ;
foreach (@filesinpatharray) {
if ( $_ eq $newfilename) { $canwrite = 0; };
- }
- $text .= "$canwrite<br><br>";
- if ( $canwrite ) {
- system("touch $newpath") && die "Cannot create new file";
+ }
+ if ( $canwrite ) {
if ($newrights eq "private" ) {
$filerights = '';
} elsif ($newrights eq "protected" ) {
@@ -460,7 +484,6 @@
$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 {
$text .= "<font color=red>Cannot write file. It exists<br><br>\n" ;
@@ -480,8 +503,8 @@
my $text = '';
my $defaultright = '';
my $filerights = (stat($cfghash{'BaseDir'} . $cfghash{'ConfigDir'} . "/" . $namefile))[2] & 07;
-
- $text .= $cgi->hidden(-name => 'filename', -default => $namefile ) ;
+
+ $text .= $cgi->hidden(-name => 'filename', -default => $namefile ) ;
if ( $filerights == 6 ) {
$defaultright = "public" ;
} elsif ( $filerights == 4 ) {
@@ -515,13 +538,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";
+ $text .= "<font color=red>You can only change file rights in your own directory<br><br>\n" .
+ $cgi->submit(-name => 'dialog', -value => 'Back');
}
} else {
- $text .= "<font color=red>Missing filename<br><br>\n" ;
- }
- $text .= $cgi->submit(-name => 'dialog', -value => 'Back');
+ $text .= "<font color=red>Missing filename<br><br>\n" .
+ $cgi->submit(-name => 'dialog', -value => 'Back');
+ }
return $text;
}
@@ -548,6 +572,7 @@
} 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');
@@ -557,6 +582,107 @@
########################################################################################
+########################################################################################
+sub copy_file {
+########################################################################################
+ my ( $srcfile, $user ) = @_;
+ 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', -value => 'Back').
+ " </td>" .
+ " <td>" .
+ $cgi->submit(-name => 'dialog', -value => 'Copy').
+ " </td>" .
+ " </td>" .
+ "</table>" ;
+
+
+ return $text;
+
+}
+########################################################################################
+
+
+########################################################################################
+sub del {
+########################################################################################
+ my ( $delfile, $user ) = @_;
+ 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 ) {
+ system("rm $fpath") && die "Cannot delete file";
+ } else {
+ $text .= "<font color=red>You can only delete file in your own directory<br><br>\n" ;
+ }
+
+ $text .= $cgi->submit(-name => 'dialog', -value => 'Back');
+
+ return $text;
+}
+########################################################################################
+
+
+
+########################################################################################
+sub copy {
+########################################################################################
+ my ( $srcf, $dstf ) = @_;
+ my $text = '';
+
+ $text .= "<font size=+1>" .
+ "Copying File:<br>" .
+ "</font><br><br>" .
+ "Copying from <font size=+1>$srcf</font> to <font size=+1>$dstf</font><br><br>" ;
+
+ system("cp $srcf $dstf") && die "Cannot copy file";
+ system("chmod o= $dstf") && die "Cannot change file rights";
+
+ $text .= $cgi->submit(-name => 'dialog', -value => 'Back');
+
+ return $text;
+}
+########################################################################################
+
+
+
########################################################################################
sub read_config {
@@ -742,9 +868,7 @@
}
$page .= " <td>" .
" </td>" .
- "</table>" .
-
+ "</table>" ;
- $cgi->endform;
}
########################################################################################
|