Parent Directory
|
Revision Log
Revision 1533 - (view) (download) (as text)
| 1 : | sh002i | 1533 | #!/usr/bin/env perl |
| 2 : | sam | 2 | |
| 3 : | |||
| 4 : | ## This file is profHousekeeping.pl | ||
| 5 : | ## It provides access to utilities deleting uneeded files, etc. | ||
| 6 : | ## | ||
| 7 : | |||
| 8 : | #################################################################### | ||
| 9 : | # Copyright @ 1995-1999 University of Rochester | ||
| 10 : | # All Rights Reserved | ||
| 11 : | #################################################################### | ||
| 12 : | |||
| 13 : | gage | 8 | use lib '.'; use webworkInit; # WeBWorKInitLine |
| 14 : | sam | 2 | use CGI qw(:standard); |
| 15 : | use Global; | ||
| 16 : | use Auth; | ||
| 17 : | use strict; | ||
| 18 : | |||
| 19 : | # begin Timing code | ||
| 20 : | use Benchmark; | ||
| 21 : | my $beginTime = new Benchmark; | ||
| 22 : | # end Timing code | ||
| 23 : | |||
| 24 : | my $cgi = new CGI; | ||
| 25 : | my %inputs = $cgi->Vars(); | ||
| 26 : | |||
| 27 : | # get information from CGI inputs (see also below for additional information) | ||
| 28 : | |||
| 29 : | my $Course = $inputs{'course'}; | ||
| 30 : | my $User = $inputs{'user'}; | ||
| 31 : | my $Session_key = $inputs{'key'}; | ||
| 32 : | |||
| 33 : | # verify that information has been received | ||
| 34 : | unless($Course && $User && $Session_key) { | ||
| 35 : | &wwerror("$0","The script did not receive the proper input data.","",""); | ||
| 36 : | die "The script profLogin.pl did not receive the proper input data."; | ||
| 37 : | } | ||
| 38 : | |||
| 39 : | # establish environment for this script | ||
| 40 : | |||
| 41 : | &Global::getCourseEnvironment($inputs{'course'}); | ||
| 42 : | |||
| 43 : | |||
| 44 : | my $cgiURL = getWebworkCgiURL; | ||
| 45 : | my $courseDirectory = $Global::coursesDirectory . $Course . $Global::dirDelim; | ||
| 46 : | my $courseScriptsDirectory = getCourseScriptsDirectory; | ||
| 47 : | my $databaseDirectory = getCourseDatabaseDirectory; | ||
| 48 : | my $htmlURL = getCourseHtmlURL; | ||
| 49 : | my $scriptDirectory = getWebworkScriptDirectory; | ||
| 50 : | sh002i | 152 | my $htmlDirectory = getCourseHtmlDirectory; |
| 51 : | sam | 2 | my $templateDirectory = getCourseTemplateDirectory; |
| 52 : | apizer | 851 | my $dat = getDat; |
| 53 : | sam | 2 | |
| 54 : | require "${scriptDirectory}$Global::DBglue_pl"; | ||
| 55 : | require "${scriptDirectory}$Global::FILE_pl"; | ||
| 56 : | require "${scriptDirectory}$Global::HTMLglue_pl"; | ||
| 57 : | |||
| 58 : | # log access | ||
| 59 : | &Global::log_info('', query_string); | ||
| 60 : | |||
| 61 : | |||
| 62 : | my $permissionsFile = &Global::getCoursePermissionsFile($Course); | ||
| 63 : | my $permissions = &get_permissions($User, $permissionsFile); | ||
| 64 : | my $keyFile = &Global::getCourseKeyFile($Course); | ||
| 65 : | |||
| 66 : | #verify session key | ||
| 67 : | &verify_key($User, $Session_key, $keyFile, $Course); | ||
| 68 : | apizer | 851 | |
| 69 : | sam | 2 | # verify permissions are correct |
| 70 : | if ($permissions != $Global::instructor_permissions ) { | ||
| 71 : | print "permissions = $permissions instructor_permissions = $Global::instructor_permissions\n"; | ||
| 72 : | print &html_NO_PERMISSION; | ||
| 73 : | exit(0); | ||
| 74 : | } | ||
| 75 : | # get the rest of the information from the submitted form | ||
| 76 : | # nothing further to get in this case | ||
| 77 : | |||
| 78 : | # print HTML text | ||
| 79 : | print &htmlTOP("Housekeeping Utilities"); | ||
| 80 : | |||
| 81 : | # print navigation button | ||
| 82 : | print $cgi->a( { -href=>"${cgiURL}login.pl?user=$User&key=$Session_key&course=$Course" }, | ||
| 83 : | |||
| 84 : | $cgi->img({ -name=>'upImg', | ||
| 85 : | -src=>"${Global::upImgUrl}", | ||
| 86 : | -align=>'right', | ||
| 87 : | -border=>'1', | ||
| 88 : | -alt=>'[Up]' | ||
| 89 : | }) | ||
| 90 : | ), | ||
| 91 : | $cgi->p; | ||
| 92 : | |||
| 93 : | print "\n", | ||
| 94 : | $cgi->hr, $cgi->br, | ||
| 95 : | "\n\n", $cgi->h3({ -align=>'left' }, "WeBWorK Housekeeping Utilities for $Course"), "\n", | ||
| 96 : | $cgi->p, | ||
| 97 : | "From this page, you can recover disk space by removing old tmp files, | ||
| 98 : | compress the gdbm database, show active users, edit the Course Environment file, etc."; | ||
| 99 : | |||
| 100 : | apizer | 851 | # remove tmp files |
| 101 : | sam | 2 | print heading('Cleanup', "1. Cleanup $Course:"), |
| 102 : | $cgi->startform(-action=>"${cgiURL}profRemoveTmpFiles.pl"), | ||
| 103 : | $cgi->submit(-value=>'Remove unnecessary tmp files'), "\n", | ||
| 104 : | hiddens('user', 'key', 'course'), | ||
| 105 : | $cgi->endform(), "\n", | ||
| 106 : | $cgi->p, "This removes unnecessary temporary fiels and may recover quite a bit of disk space."; | ||
| 107 : | |||
| 108 : | |||
| 109 : | # compress database | ||
| 110 : | print heading('Compress', "2. Compress the webworkdatabase for $Course:"), | ||
| 111 : | $cgi->startform(-action=>"${cgiURL}profCompress_GDBM_webwork-database.pl"), | ||
| 112 : | $cgi->submit(-value=>'Compress gdbm database'), "\n", | ||
| 113 : | hiddens('user', 'key', 'course'), | ||
| 114 : | $cgi->endform(), "\n", | ||
| 115 : | $cgi->p, "If $Course uses the gdbm database, this should be run monthly to significantly reduce the size of the database file. if $Course does not use the gdbm database, the operation will abort and nothing will be done."; | ||
| 116 : | |||
| 117 : | # active users | ||
| 118 : | print heading('Active', "3. Show active users in $Course:"), | ||
| 119 : | $cgi->startform(-action=>"${cgiURL}profShowActiveUsers.pl"), | ||
| 120 : | $cgi->submit(-value=>'Show Active Users'), "\n", | ||
| 121 : | hiddens('user', 'key', 'course'), | ||
| 122 : | $cgi->endform(), "\n", | ||
| 123 : | $cgi->p, "This lists all users who are currently logged into $Course."; | ||
| 124 : | apizer | 851 | |
| 125 : | apizer | 355 | # templates/motd.txt |
| 126 : | my $filename = "${templateDirectory}motd.txt"; | ||
| 127 : | my ($date, $label, @stat); | ||
| 128 : | sam | 2 | |
| 129 : | apizer | 355 | if (-e $filename) { |
| 130 : | @stat = stat($filename); | ||
| 131 : | $date = $stat[9]; | ||
| 132 : | $date = formatDateAndTime($date); | ||
| 133 : | $date =~ s|\s*at.*||; | ||
| 134 : | $label = " Last Changed $date"; | ||
| 135 : | } | ||
| 136 : | |||
| 137 : | print heading('Motd', "4. Edit Course motd.txt File (Message of The Day File) for $Course:"), | ||
| 138 : | $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"), | ||
| 139 : | $cgi->submit(-value=>'Edit Course motd.txt File'), "$label\n", | ||
| 140 : | hiddens('user', 'key', 'course'), | ||
| 141 : | $cgi->hidden(-name=>'filename', -value=>"motd.txt"), "\n", | ||
| 142 : | $cgi->hidden(-name=>'ext', -value=>'txt'), "\n", | ||
| 143 : | $cgi->endform(), "\n", | ||
| 144 : | apizer | 851 | $cgi->p, "This lets you edit the Course motd.txt File for $Course."; |
| 145 : | apizer | 355 | |
| 146 : | sam | 2 | # webworkcourse.ph |
| 147 : | apizer | 355 | $filename = "${courseDirectory}$Global::courseEnvironmentFile"; |
| 148 : | #($date, $label, @stat); | ||
| 149 : | sam | 2 | if (-e $filename) { |
| 150 : | @stat = stat($filename); | ||
| 151 : | $date = $stat[9]; | ||
| 152 : | $date = formatDateAndTime($date); | ||
| 153 : | $date =~ s|\s*at.*||; | ||
| 154 : | $label = " Last Changed $date"; | ||
| 155 : | } | ||
| 156 : | |||
| 157 : | apizer | 355 | print heading('Environment', "5. Edit Course Environment File for $Course:"), |
| 158 : | sam | 2 | $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"), |
| 159 : | $cgi->submit(-value=>'Edit Course Environment File'), "$label\n", | ||
| 160 : | hiddens('user', 'key', 'course'), | ||
| 161 : | $cgi->hidden(-name=>'filename', -value=>$Global::courseEnvironmentFile), "\n", | ||
| 162 : | $cgi->hidden(-name=>'ext', -value=>'ph'), "\n", | ||
| 163 : | $cgi->endform(), "\n", | ||
| 164 : | $cgi->p, "This lets you edit the Course Environment File for $Course."; | ||
| 165 : | |||
| 166 : | |||
| 167 : | sh002i | 152 | # html/index.html |
| 168 : | $filename = "${htmlDirectory}index.html"; | ||
| 169 : | #($date, $label, @stat); | ||
| 170 : | if (-e $filename) { | ||
| 171 : | @stat = stat($filename); | ||
| 172 : | $date = $stat[9]; | ||
| 173 : | $date = formatDateAndTime($date); | ||
| 174 : | $date =~ s|\s*at.*||; | ||
| 175 : | $label = " Last Changed $date"; | ||
| 176 : | } | ||
| 177 : | |||
| 178 : | apizer | 355 | print heading('Index', "6. Edit Course index.html File for $Course:"), |
| 179 : | sh002i | 152 | $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"), |
| 180 : | $cgi->submit(-value=>'Edit Course index.html File'), "$label\n", | ||
| 181 : | hiddens('user', 'key', 'course'), | ||
| 182 : | $cgi->hidden(-name=>'filename', -value=>"index.html"), "\n", | ||
| 183 : | $cgi->hidden(-name=>'ext', -value=>'html'), "\n", | ||
| 184 : | $cgi->endform(), "\n", | ||
| 185 : | $cgi->p, "This lets you edit the Course index.html File for $Course."; | ||
| 186 : | apizer | 851 | |
| 187 : | print heading('dataMungerPSVN', "7. Change data for a PSVN in $Course:"), | ||
| 188 : | malsyned | 734 | $cgi->startform(-action=>"${cgiURL}dataMunger.pl"), |
| 189 : | $cgi->submit(-value=>'Examine or change data for psvn:'), "\n", | ||
| 190 : | $cgi->textfield(-name=>'probSetKey', -col=>'15', -value=>'Enter PSVN'), "\n", | ||
| 191 : | $cgi->hidden(-name=>'save', -value=>'OFF'), "\n", | ||
| 192 : | $cgi->hidden(-name=>'firsttime', -value=>1), "\n", | ||
| 193 : | hiddens('user', 'key', 'course'), | ||
| 194 : | $cgi->endform(), "\n", | ||
| 195 : | "Use this to make changes for an individual student. For example, you can extend the due date for an individual student or change the status | ||
| 196 : | (correct, incorrect) or number of allowed attempts of a problem. You will also be able to download a postscript file of | ||
| 197 : | this version of the problem set."; | ||
| 198 : | sh002i | 152 | |
| 199 : | |||
| 200 : | malsyned | 734 | |
| 201 : | sam | 2 | print &htmlBOTTOM("profHousekeeping.pl", \%inputs); |
| 202 : | |||
| 203 : | # begin Timing code | ||
| 204 : | my $endTime = new Benchmark; | ||
| 205 : | &Global::logTimingInfo($beginTime,$endTime,"profHousekeeping.pl",$inputs{'course'},$inputs{'user'}); | ||
| 206 : | # end Timing code | ||
| 207 : | exit; | ||
| 208 : | |||
| 209 : | ################################################################################ | ||
| 210 : | # | ||
| 211 : | # HELPFUL METHODS | ||
| 212 : | # | ||
| 213 : | ################################################################################ | ||
| 214 : | |||
| 215 : | #returns the horizontal line, blue square, and heading for each option | ||
| 216 : | #in the list, eliminating the need to repeat this code each time it is needed | ||
| 217 : | #this does NOT PRINT the info, so that it can be incorporated into other text | ||
| 218 : | sub heading { | ||
| 219 : | my $link = shift; #name for internal link (used for shortcuts on some pages) | ||
| 220 : | my $text = shift; #text used as the main heading | ||
| 221 : | |||
| 222 : | return "\n", | ||
| 223 : | $cgi->p, "\n", | ||
| 224 : | $cgi->a({-name=>$link}), "\n", | ||
| 225 : | $cgi->hr({ -noshade=>undef }), "\n", | ||
| 226 : | $cgi->h4({ -align=>'LEFT' }, | ||
| 227 : | "\n" . $cgi->img({-src=>"$Global::bluesquareImgUrl", -border=>1, -alt=>'' }) . "\n" . | ||
| 228 : | $text ), "\n"; | ||
| 229 : | } | ||
| 230 : | |||
| 231 : | #prints hidden form fields for each of given cgi parameters | ||
| 232 : | #if a given parameter does not exist, a note is placed in the html to that affect | ||
| 233 : | #this does NOT PRINT the info, so that it can be incorporated into other text | ||
| 234 : | sub hiddens { | ||
| 235 : | my @params = @_; | ||
| 236 : | my $out; | ||
| 237 : | apizer | 851 | |
| 238 : | sam | 2 | foreach my $param (@params) { |
| 239 : | if (exists $inputs{$param}) { | ||
| 240 : | $out .= $cgi->hidden(-name=>"$param", -value=>"$inputs{$param}") . "\n"; | ||
| 241 : | } else { | ||
| 242 : | $out .= $cgi->p . "\nExpected cgi parameter $param does not exist or is empty"; | ||
| 243 : | } | ||
| 244 : | } | ||
| 245 : | apizer | 851 | |
| 246 : | sam | 2 | $out; |
| 247 : | sh002i | 152 | } |
| aubreyja at gmail dot com | ViewVC Help |
| Powered by ViewVC 1.0.9 |