From: Mike G. v. a. <we...@ma...> - 2009-02-04 03:25:44
|
Log Message: ----------- Added code to check the directory structure of the courses (make sure all standard directories are present and have rwx privileges available to the webserver. No automatic repair of the directory structure is performed. (We'll see how annoying that is.) Modified Files: -------------- webwork2/lib/WeBWorK/ContentGenerator: CourseAdmin.pm webwork2/lib/WeBWorK/Utils: CourseIntegrityCheck.pm Revision Data ------------- Index: CourseAdmin.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm,v retrieving revision 1.81 retrieving revision 1.82 diff -Llib/WeBWorK/ContentGenerator/CourseAdmin.pm -Llib/WeBWorK/ContentGenerator/CourseAdmin.pm -u -r1.81 -r1.82 --- lib/WeBWorK/ContentGenerator/CourseAdmin.pm +++ lib/WeBWorK/ContentGenerator/CourseAdmin.pm @@ -383,13 +383,14 @@ }); my $CIchecker = new WeBWorK::Utils::CourseIntegrityCheck(ce=>$tempCE); - my ($tables_ok,$dbStatus) = $CIchecker->checkCourseTables($courseID); + my ($tables_ok,$dbStatus) = $CIchecker->checkCourseTables($courseID); + my ($directories_ok, $str2) = $CIchecker->checkCourseDirectories(); print CGI::li(CGI::a({href=>$self->systemLink($urlpath, authen => 0)}, $courseID), CGI::code( $tempCE->{dbLayoutName}, ), - (-r $tempCE->{courseFiles}->{environment}) ? "" : CGI::i(", missing course.conf"), - ($courseID eq "modelCourse" or $tables_ok ) ? CGI::span({style=>"color:green"},"Database tables ok") : CGI::span({style=>"color:red"},"Database tables need updating"), + ($courseID eq "modelCourse" or $directories_ok) ? "" : CGI::span({style=>"color:red"},"Directory structure or permissions need to be repaired. "), + ($courseID eq "modelCourse" or $tables_ok ) ? CGI::span({style=>"color:green"},"Database tables ok") : CGI::span({style=>"color:red"},"Database tables need updating."), ); @@ -908,9 +909,11 @@ %WeBWorK::SeedCE, courseName => $rename_oldCourseID, }); +############################################################################# +# Check database +############################################################################# my ($tables_ok,$dbStatus); - my %missing_fields; if ($ce2->{dbLayoutName} ) { my $CIchecker = new WeBWorK::Utils::CourseIntegrityCheck(ce=>$ce2); ($tables_ok,$dbStatus) = $CIchecker->checkCourseTables($rename_oldCourseID); @@ -981,6 +984,10 @@ $str.=CGI::br(); } +############################################################################# +# Report on databases +############################################################################# + print CGI::p($str); if ($extra_database_tables) { print CGI::p({-style=>'color:red; font-weight:bold'},"There are extra database tables which are not defined in the schema. @@ -989,12 +996,31 @@ if ($extra_database_fields) { print CGI::p({-style=>'color:red; font-weight:bold'},"There are extra database fields which are not defined in the schema for at least one table. They can only be removed manually from the database."); - } + } if ($all_tables_ok) { print CGI::p({-style=>'color:green; font-weight:bold'},"Course $rename_oldCourseID database is in order"); } else { print CGI::p({-style=>'color:red; font-weight:bold'}, "Course $rename_oldCourseID databases must be updated before renaming this course."); - } + } + +############################################################################# +# Check directories +############################################################################# + + + my ($directories_ok, $str2) = $CIchecker->checkCourseDirectories($ce2); + my $style = ($directories_ok)?"color:green" : "color:red"; + print CGI::h2("Directory structure"), CGI::p($str2), + ($directories_ok)? CGI::p({style=>$style},"Directory structure is ok") : + CGI::p({style=>$style},"Directory structure is missing directories + or the webserver lacks sufficient privileges."); + +############################################################################# +# Print form for choosing next action. +############################################################################# + + + print CGI::start_form(-method=>"POST", -action=>$r->uri); print $self->hidden_authen_fields; print $self->hidden_fields("subDisplay"); @@ -1004,18 +1030,23 @@ - if ($all_tables_ok ) { # no missing tables or missing fields + if ($all_tables_ok && $directories_ok ) { # no missing tables or missing fields or directories print CGI::p({style=>"text-align: center"}, CGI::submit(-name=>"decline_rename_course", -value=>"Don't rename"), " ", CGI::submit(-name=>"confirm_rename_course", -value=>"Rename") , ); - } else { + } elsif( $directories_ok ) { print CGI::p({style=>"text-align: center"}, CGI::submit(-name => "decline_rename_course", -value => "Don't rename"), " ", CGI::submit(-name=>"upgrade_course_tables", -value=>"upgrade course tables"), ); + } else { + print CGI::p({style=>"text-align: center"}, + CGI::submit(-name => "decline_rename_course", -value => "Don't rename"), + CGI::br(),"Directory structure needs to be repaired manually before renaming." + ); } } } @@ -1798,7 +1829,9 @@ my ($tables_ok,$dbStatus); - +############################################################################# +# Check database +############################################################################# my %missing_fields; if ($ce2->{dbLayoutName} ) { my $CIchecker = new WeBWorK::Utils::CourseIntegrityCheck(ce=>$ce2); @@ -1870,6 +1903,10 @@ $str.=CGI::br(); } +############################################################################# +# Report on databases +############################################################################# + print CGI::p($str); if ($extra_database_tables) { print CGI::p({-style=>'color:red; font-weight:bold'},"There are extra database tables which are not defined in the schema. @@ -1889,6 +1926,25 @@ must be upgraded before archiving this course." ); } +############################################################################# +# Check directories +############################################################################# + + + my ($directories_ok, $str2) = $CIchecker->checkCourseDirectories(); + my $style = ($directories_ok)?"color:green" : "color:red"; + print CGI::h2("Directory structure"), CGI::p($str2), + ($directories_ok)? CGI::p({style=>$style},"Directory structure is ok") : + CGI::p({style=>$style},"Directory structure is missing directories + or the webserver lacks sufficient privileges."); + + + + +############################################################################# +# Print form for choosing next action. +############################################################################# + print CGI::start_form(-method=>"POST", -action=>$r->uri); print $self->hidden_authen_fields; print $self->hidden_fields("subDisplay"); @@ -1901,7 +1957,7 @@ print CGI::p( "$archive_courseID: The directory for the course not found."); } - if ($all_tables_ok ) { # no missing fields + if ($all_tables_ok && $directories_ok ) { # no missing fields # Warn about overwriting an existing archive if (-e $archive_path and -w $archive_path) { print CGI::p({-style=>'color:red; font-weight:bold'},"The course '$archive_courseID' has already been archived at '$archive_path'. @@ -1913,13 +1969,19 @@ " ", CGI::submit(-name=>"confirm_archive_course", -value=>"archive") , ); - } else { + } elsif( $directories_ok) { print CGI::p({style=>"text-align: center"}, CGI::submit(-name => "decline_archive_course", -value => "Don't archive"), " ", CGI::submit(-name=>"upgrade_course_tables", -value=>"upgrade course tables"), ); - } + } else { + print CGI::p({style=>"text-align: center"}, + CGI::submit(-name => "decline_archive_course", -value => "Don't archive"),CGI::br(), + "Directory structure needs to be repaired manually before archiving." + ); + + } print CGI::end_form(); } else { print CGI::p({-style=>'color:red; font-weight:bold'},"Unable to find database layout for $archive_courseID"); Index: CourseIntegrityCheck.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/Utils/CourseIntegrityCheck.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -Llib/WeBWorK/Utils/CourseIntegrityCheck.pm -Llib/WeBWorK/Utils/CourseIntegrityCheck.pm -u -r1.2 -r1.3 --- lib/WeBWorK/Utils/CourseIntegrityCheck.pm +++ lib/WeBWorK/Utils/CourseIntegrityCheck.pm @@ -264,6 +264,48 @@ } + + + + +=item $CIchecker->checkCourseDirectories($courseName); + +Checks the course directories to make sure they exist and have the correct +permissions. + + +=cut + +sub checkCourseDirectories { + my ($self) = @_; + my $ce = $self->{ce}; + my @webworkDirectories = keys %{$ce->{webworkDirs}}; + my @courseDirectories = keys %{$ce->{courseDirs}}; + my $str = ''; + my @results; + my $directories_ok =1; + foreach my $dir (sort @courseDirectories) { + my $path = $ce->{courseDirs}->{$dir}; + my $status = (-e $path) ? + ((-r $path)?'r':'-') . + ((-w _ )?'w':'-' ) . + ((-x _ )?'x':'-' ) : "missing"; + + #all directories should be readable, writable and executable + my $style; + if ($status eq 'rwx') { + $style = "color:green"; + } else { + $directories_ok = 0; + $style = "color:red"; + } + + push @results, CGI::span({style=>$style},"$dir => $path $status <br/>\n"); + } + $str = join(" ",@results); + return ( $directories_ok, $str); +} + ############################################################################## # Database utilities -- borrowed from DBUpgrade.pm ??use or modify??? --MEG ############################################################################## |