[system] / trunk / webwork / system / cgi / cgi-scripts / profHousekeeping.pl Repository:
ViewVC logotype

Annotation of /trunk/webwork/system/cgi/cgi-scripts/profHousekeeping.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 152 - (view) (download) (as text)

1 : sam 11 #!/usr/local/bin/webwork-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 :     my $dat = getDat;
53 :    
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 :    
69 :     # 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 :     # remove tmp files
101 :     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 :    
125 :     # webworkcourse.ph
126 :     my $filename = "${courseDirectory}$Global::courseEnvironmentFile";
127 :     my ($date, $label, @stat);
128 :     if (-e $filename) {
129 :     @stat = stat($filename);
130 :     $date = $stat[9];
131 :     $date = formatDateAndTime($date);
132 :     $date =~ s|\s*at.*||;
133 :     $label = " Last Changed $date";
134 :     }
135 :    
136 :     print heading('Environment', "4. Edit Course Environment File for $Course:"),
137 :     $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"),
138 :     $cgi->submit(-value=>'Edit Course Environment File'), "$label\n",
139 :     hiddens('user', 'key', 'course'),
140 :     $cgi->hidden(-name=>'filename', -value=>$Global::courseEnvironmentFile), "\n",
141 :     $cgi->hidden(-name=>'ext', -value=>'ph'), "\n",
142 :     $cgi->endform(), "\n",
143 :     $cgi->p, "This lets you edit the Course Environment File for $Course.";
144 :    
145 :    
146 : sh002i 152 # html/index.html
147 :     $filename = "${htmlDirectory}index.html";
148 :     #($date, $label, @stat);
149 :     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 :     print heading('Index', "5. Edit Course index.html File for $Course:"),
158 :     $cgi->startform(-action=>"${cgiURL}profEditCourseFiles.pl"),
159 :     $cgi->submit(-value=>'Edit Course index.html File'), "$label\n",
160 :     hiddens('user', 'key', 'course'),
161 :     $cgi->hidden(-name=>'filename', -value=>"index.html"), "\n",
162 :     $cgi->hidden(-name=>'ext', -value=>'html'), "\n",
163 :     $cgi->endform(), "\n",
164 :     $cgi->p, "This lets you edit the Course index.html File for $Course.";
165 :    
166 :    
167 : sam 2 print &htmlBOTTOM("profHousekeeping.pl", \%inputs);
168 :    
169 :     # begin Timing code
170 :     my $endTime = new Benchmark;
171 :     &Global::logTimingInfo($beginTime,$endTime,"profHousekeeping.pl",$inputs{'course'},$inputs{'user'});
172 :     # end Timing code
173 :     exit;
174 :    
175 :     ################################################################################
176 :     #
177 :     # HELPFUL METHODS
178 :     #
179 :     ################################################################################
180 :    
181 :     #returns the horizontal line, blue square, and heading for each option
182 :     #in the list, eliminating the need to repeat this code each time it is needed
183 :     #this does NOT PRINT the info, so that it can be incorporated into other text
184 :     sub heading {
185 :     my $link = shift; #name for internal link (used for shortcuts on some pages)
186 :     my $text = shift; #text used as the main heading
187 :    
188 :     return "\n",
189 :     $cgi->p, "\n",
190 :     $cgi->a({-name=>$link}), "\n",
191 :     $cgi->hr({ -noshade=>undef }), "\n",
192 :     $cgi->h4({ -align=>'LEFT' },
193 :     "\n" . $cgi->img({-src=>"$Global::bluesquareImgUrl", -border=>1, -alt=>'' }) . "\n" .
194 :     $text ), "\n";
195 :     }
196 :    
197 :     #prints hidden form fields for each of given cgi parameters
198 :     #if a given parameter does not exist, a note is placed in the html to that affect
199 :     #this does NOT PRINT the info, so that it can be incorporated into other text
200 :     sub hiddens {
201 :     my @params = @_;
202 :     my $out;
203 :    
204 :     foreach my $param (@params) {
205 :     if (exists $inputs{$param}) {
206 :     $out .= $cgi->hidden(-name=>"$param", -value=>"$inputs{$param}") . "\n";
207 :     } else {
208 :     $out .= $cgi->p . "\nExpected cgi parameter $param does not exist or is empty";
209 :     }
210 :     }
211 :    
212 :     $out;
213 : sh002i 152 }

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9