From: Rob H. <for...@us...> - 2001-12-20 02:30:39
|
Update of /cvsroot/sandweb/sandweb/bin In directory usw-pr-cvs1:/tmp/cvs-serv8819 Modified Files: sandweb.cgi Log Message: started adding debugging, when I realized that instead of doing tons of error checking and debugging statements all over the place, this stuff should really be encapsulated and handled by the File class. Index: sandweb.cgi =================================================================== RCS file: /cvsroot/sandweb/sandweb/bin/sandweb.cgi,v retrieving revision 1.98 retrieving revision 1.99 diff -U2 -r1.98 -r1.99 --- sandweb.cgi 2001/12/18 09:47:14 1.98 +++ sandweb.cgi 2001/12/20 02:30:37 1.99 @@ -75,5 +75,5 @@ # unable to load user with cookie, or cookie expired set_error("unable to get cookie"); - $log->debug("unable to get valid cookie: '$cookie'"); + $log->debug("unable to get valid cookie: '$cookie'\n"); login_menu(); exit 0; @@ -93,4 +93,5 @@ # User is logged in; load prefs load_prefs(1); + $log->debug("loading prefs\n"); my $username = $auth->get_userinfo('username'); @@ -172,5 +173,5 @@ my $page = param('action'); my $msg = "Invalid page - $page!"; - $log->error("$msg"); + $log->error("$msg\n"); set_error("$msg"); debug_menu( cookie => $cookie ); @@ -180,5 +181,5 @@ else { # no cookie, default login_menu - $log->debug("no cookie found: '$cookie'"); + $log->debug("no cookie found: '$cookie'\n"); login_menu(); } @@ -197,4 +198,6 @@ my %args = @_; + $log->debug("entering login menu\n"); + my $content = $ui->get_menu( MENU => 'login', @@ -217,4 +220,7 @@ sub main_menu { my %args = @_; + + $log->debug("entering main menu\n"); + my $cookie = $args{'cookie'}; unless ($cookie) { @@ -227,5 +233,5 @@ } - $log->debug("cookie: '$cookie'"); + $log->debug("cookie: '$cookie'\n"); print header( -cookie => $cookie ); @@ -244,4 +250,7 @@ sub debug_menu { my %args = @_; + + $log->debug("entering debug menu\n"); + my $cookie = $args{'cookie'}; unless ($cookie) { @@ -269,4 +278,7 @@ sub browse_menu { my %args = @_; + + $log->debug("entering browse menu"); + my $cookie = $args{'cookie'}; unless ($cookie) { @@ -290,4 +302,5 @@ if ( $repo_type eq 'CVS' ) { + $log->debug("repo type is CVS, setting up CVSROOT\n"); if ( $connection eq 'local' ) { $vcsroot = "$root"; @@ -297,4 +310,5 @@ } + $log->debug("creating Repository object\n"); my $repository = SandWeb::Repository->new( root => "$vcsroot", @@ -303,4 +317,5 @@ ); + $log->debug("creating Browse object\n"); my $browse = SandWeb::Browse->new( username => $username, @@ -309,5 +324,8 @@ ); - my $file = SandWeb::File->new(); + $log->debug("creating File object\n"); + my $file = SandWeb::File->new( + 'log_obj' => $log, + ); my $username = $auth->get_userinfo('username'); @@ -340,4 +358,6 @@ my %args = @_; + $log->debug("entering file handling routine\n"); + my $cookie = $args{'cookie'}; unless ($cookie) { @@ -352,5 +372,7 @@ my $file_command = $args{'file_command'}; + $log->debug("file command is : $file_command\n"); my $location = $args{'location'}; + $log->debug("location is : $location\n"); my @filename = (); my $count = 0; @@ -360,4 +382,5 @@ } my $filename = "@filename"; + $log->debug("filename(s) : $filename"); my $save = param('save'); my $username = $auth->get_userinfo('username'); @@ -374,4 +397,5 @@ if ( $file_command eq 'remove' ) { unless (@filename) { + $log->debug("no files selected for removal\n"); set_error("Please select file(s) or folder(s) to remove."); browse_menu( @@ -382,10 +406,13 @@ foreach my $entry (@filename) { - + + $log->debug("creating File object"); my $file = SandWeb::File->new( + 'log_obj' => $log, 'filename' => $entry, 'location' => "$users_dir/$username$location", ); + $log->debug("removing file"); if ($file) { if ( $file->get_file_type() eq 'Directory' ) { @@ -404,4 +431,5 @@ if ( $repo_type eq 'CVS' ) { + $log->debug("repo type is CVS, setting up CVSROOT"); if ( $connection eq 'local' ) { $vcsroot = "$root"; @@ -411,4 +439,5 @@ } + $log->debug("creating Repository object"); my $repository = SandWeb::Repository->new( root => $vcsroot, @@ -423,5 +452,7 @@ if ($filename) { + $log->debug("creating file object"); $file = SandWeb::File->new( + 'log_obj' => $log, 'filename' => $filename, 'location' => "$users_dir/$username$location", @@ -430,4 +461,5 @@ if ( $file_command eq 'info' ) { + $log->debug("calling file info routine"); # can't give the leading / to the VCS $filename =~ s/\///; @@ -455,5 +487,7 @@ } elsif ( $file_command eq 'view' ) { + $log->debug("viewing file : $filename\n"); if ( $file->get_file_type() ne "Text" ) { + $log->debug("User wants to view non-text file.\n"); set_error("This does not appear to be a text file."); browse_menu( @@ -461,10 +495,8 @@ path => $location, ); - } - my @tmp; - open (FILE, "$users_dir/$username/$location/$filename"); - foreach my $line (<FILE>) { - push @tmp, $line; } + + my @tmp = $file->file_read(); + my $content = $ui->get_menu( MENU => 'view_file', @@ -485,11 +517,28 @@ } elsif ( $file_command eq 'edit' ) { + $log->debug("editing file : $filename \n"); if ($save) { my $data = param('data'), my $filename = $file->get_filename(); + $log->debug("saving edited file : $filename \n"); - open ( FILE, "> $users_dir/$username$location/$filename" ); + $log->debug("opening $users_dir/$username$location/$filename\n"); + unless (open ( FILE, "> $users_dir/$username$location/$filename" )) { + $log->error("could not open $users_dir/$username$location/$filename for writing : $!\n"); + browse_menu( + cookie => $cookie, + path => $location, + ); + } print FILE "$data"; - close FILE; + unless (close FILE) { + my $error = "could not save $users_dir/$username$location/$filename : $!"; + $log->error("$error\n"); + set_error("$error\n"); + browse_menu( + cookie => $cookie, + path => $location, + ); + } browse_menu( @@ -499,4 +548,5 @@ } if ( $file->get_file_type() ne "Text" ) { + $log->debug("User wants to edit non-text file : $filename\n"); set_error("This does not appear to be a text file."); browse_menu( @@ -506,8 +556,27 @@ } my @tmp; - open (FILE, "$users_dir/$username/$location/$filename"); + $log->debug("opening $users_dir/$username/$location/$filename\n"); + unless (open (FILE, "< $users_dir/$username/$location/$filename") ) { + my $error = "could not open $users_dir/$username/$location/$filename for reading : $!"; + $log->error("$error\n"); + set_error("$error"); + browse_menu( + cookie => $cookie, + path => $location, + ); + } foreach my $line (<FILE>) { push @tmp, $line; } + unless (close FILE) { + my $error = "could not close $users_dir/$username/$location/$filename : $!"; + $log->error("$error\n"); + set_error("$error"); + browse_menu( + cookie => $cookie, + path => $location, + ); + } + $log->debug("closing $users_dir/$username/$location/$filename\n"); my $content = $ui->get_menu( MENU => 'edit_file', @@ -618,4 +687,33 @@ ERROR => $error, ); + exit 0; + } + elsif ( $file_command eq 'download' ) { + open FILE,"< $users_dir/$username/$location/$filename"; + my @file = <FILE>; + close FILE; + my @file_split = split(/\./, $filename); + my $file_extension = $file_split[$#file_split]; + my $content_type; + open FILE,"< /usr/local/apache/conf/mime.types"; + my @mimes = <FILE>; + close FILE; + foreach my $mime_type (@mimes) { + unless ( $mime_type =~ /^#/) { + my @mime_string = split(/\s+/, $mime_type); + if ($mime_string[1]) { + if ( $file_extension eq $mime_string[1] ){ + $content_type = $mime_string[0]; + } + } + } + } + unless ($content_type) { + $content_type = "binary/unknown"; + } + print "content-type:$content_type\n\n"; + foreach my $line (@file) { + print "$line"; + } exit 0; } |