<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<title>Worktime Program</title>
</head>
<body>
<h1>Worktime Program</h1>
<p>
In the examples below <i>italicized</i> lines are lines of code
that changed from the previous example, <b>bold</b> lines are
lines that have been added to the example, and any time
"username" appears it should be replaced by your specific
username.
</p>
<p>
Please add this to your /etc/httpd/conf/loncapa_apache.conf file
</p>
<h3>Conf Changes</h3>
<Location /adm/username>
SetHandler perl-script
PerlHandler Apache::username
</Location>
<LocationMatch "\.username$">
SetHandler perl-script
PerlHandler Apache::username
</LocationMatch>
<h3>Example 1</h3>
<pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
sub handler {
my $r=@_[0];
$r->content_type('text/html');
$r->send_http_header;
return OK if $r->header_only;
$r->print("The username handler");
return OK;
}
1;
__END__
</pre>
<h3>Example 2</h3>
<pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
sub handler {
my $r=@_[0];
$r->content_type('text/html');
$r->send_http_header;
return OK if $r->header_only;
<i>$r->print("The username handler is in use by $ENV{'user.name'}");</i>
return OK;
}
1;
__END__
</pre>
<h3>Example 3</h3>
<pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
<b>use Apache::lonnet;</b>
sub handler {
my $r=@_[0];
$r->content_type('text/html');
$r->send_http_header;
return OK if $r->header_only;
<i>$r->print("The username handler is in use by $ENV{'user.name'} looking for "
.$r->uri."<br>");</i>
<b>my $file=&Apache::lonnet::filelocation("",$r->uri);</b>
<b>my $contents=&Apache::lonnet::getfile($file);</b>
<b>$r->print($contents);</b>
return OK;
}
1;
__END__
</pre>
<h3>Example 4</h3>
<pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
sub handler {
my $r=@_[0];
$r->content_type('text/html');
$r->send_http_header;
return OK if $r->header_only;
$r->print("The username handler is in use by $ENV{'user.name'} looking for "
.$r->uri."<br>");
my $file=&Apache::lonnet::filelocation("",$r->uri);
my $contents=&Apache::lonnet::getfile($file);
<b>$contents=~s/simple/complex/g;</b>
$r->print($contents);
return OK;
}
1;
__END__
</pre>
<h3>Example 5</h3>
<pre>
package Apache::username;
use strict;
use Apache::Constants qw(:common :http);
use Apache::lonnet;
sub handler {
my $r=@_[0];
$r->content_type('text/html');
$r->send_http_header;
return OK if $r->header_only;
$r->print("The username handler is in use by $ENV{'user.name'} looking for "
.$r->uri."<br>");
my $file=&Apache::lonnet::filelocation("",$r->uri);
my $contents=&Apache::lonnet::getfile($file);
$contents=~s/simple/complex/g;
$r->print($contents);
<b>my %hash=&Apache::lonnet::get('username',('info'));
#handle any errors
if ($hash{'info'} =~ m/^error:.*/) {
$r->print("<br>An error -$hash{'info'}- occured");
} else {
$r->print("<br>Last time you said $hash{'info'}");
}
if ($ENV{'form.info'}) {
$r->print("<br>Now you say $ENV{'form.info'}");
$hash{'info'}=$ENV{'form.info'};
&Apache::lonnet::put('username',%hash);
}</b>
return OK;
}
1;
__END__
</pre>
<h3>Example 6</h3>
<pre>
<html>
<head><title> A simple file </title></head>
<body>
This is a simple file
</body>
</html>
</pre>
<h3>Example 7</h3>
<pre>
<html>
<head><title> A simple file </title></head>
<body>
This is a simple file
<b><form method="POST" action="/~username/a.username">
<input type="text" name="info"></input>
<input type="submit" name="Submit"></input>
</form></b>
</body>
</html>
</pre>
<ol>
<li>
login
<ol>
<li>
First login to the CSE machine using the username guest__
and the password CAPA4all.
</li>
<li>
Bring up a terminal by clicnking on the monitor icon with
a foot at the bottom of the screen.
</li>
<li>
Start up a netscape by typing netscape& in the terminal.
</li>
<li>
telnet from the terminal to data.lite.msu.edu, login using
your username and the password guts
</li>
<li>
Login into LON-CAPA in netscape by pointing the browser at
http://data.lite.msu.edu and typing in your username and
guts
</li>
</ol>
</li>
<li>
Using the terminal edit the file ~/username.pm using your
favorite unix text editor and type in example 1
</li>
<li>
Point netscape at "http://data.lite.msu.edu/adm/username". You
should see a the simple message the handler prints out.
</li>
<li>
Change ~/username.pm to be what is in Example 2, the
italicized line is the only one that changed.
</li>
<li>
In netscape reload
"http://data.lite.msu.edu/adm/username". You should see the
output of the handler should now have your username, which it
got from the session enviroment.
</li>
<li>
Next in netscape goto
"http://data.lite.msu.edu/~username/a.username". You should
see the same output as before.
</li>
<li>
Using the terminal edit the file ~/public_html/a.username and
put in it example5 using your favorite unix text editor.
</li>
<li>
Change ~/username.pm to be what is in Example 3, the
italicized lines are changed and the bold lines should be
added.
</li>
<li>
In netscape reload
"http://data.lite.msu.edu/~username/a.username". You should
see the output of the handler contains the contents of the file
that you created along with the name of the file.
</li>
<li>
Change ~/username.pm to be what is in Example 4, the
bold line should be added.
</li>
<li>
In netscape reload
"http://data.lite.msu.edu/~username/a.username". You should
see the output of the handler contains the contents of the
file that you created along with the name of the file, except
that this time all instances of the word "simple" have been
replaced with the word "complex", this includes the one in the
title and the one in the body of the file.
</li>
<li>
<ol>
<li>
Change what is in ~/username.pm to be what is in Example
5. The bold section of code needs to be added.
</li>
<li>
Change what is in ~/public_html/a.username to be what is
in Example 7. The bold section needs to be added
</li>
<li>
In netscape reload
"http://data.lite.msu.edu/~username/a.username". The web
page should now contain a form, and say that an error
occured.
</li>
<li>
Type someting into the form field and click the submit button.
</li>
<li>
The handler should still report an error, but also echo
back what you typed into the error handler.
</li>
<li>
Type in the terminal
<pre>
ls -l /home/httpd/lonUsers/msu/u/s/e/username/
</pre>
Notice that there is a username.db file and a
username.hist file.
</li>
<li>
Type in the terminal
<pre>
cat /home/httpd/lonUsers/msu/u/s/e/username/username.hist
</pre>
You should see the information that you submitted.
</li>
<li>
In netscape revisit
"http://data.lite.msu.edu/~username/a.username". (Do
this by hitting return in the URL field of netscape, Don't
use the reload button.) Notice that the handler no longer
has an error. Also notice that the handler tells you what
you said last time.
</li>
<li>
Type something new into the text field and hit submit. The
handler should tell you the first submission and the last
submission.
</li>
</ol>
</li>
<li>
Extra credit: convert Example 5 to use store/restore instead
of the get/put. You will need to publish a .username file and
include it into a map. (Note that violin.sequence is the
toplevel map for you course.
</li>
<li>
Extra credit: Use Apache::lonxml::xmlparse to properly process the html file.
Use <window></window> in your example .username file.
</li>
</ol>
<h2>Helpful Notes</h2>
<ul>
<li>
If you the error handler does come up, the first bold line
will indicate what error the server process detected.
</li>
<li>
Remember that Apache::lonnet::put and Apache::lonnet::get
store data that is user wide. I use them for simplicity sake
here. Every .username file will read and write to the same
data location in the last example. Use store/restore if you
want to have data stored per unique resource instance in a
specific course. However this means that store/restore will
through errors if you attempt to use them in a context in
which a resource isn't published or isn't uniquely identified
(i.e. browsing resources.)
</li>
</ul>
<hr>
<address><a href="mailto:albertel@msu.edu">Guy Albertelli</a></address>
<!-- Created: Wed May 23 02:34:54 EDT 2001 -->
<!-- hhmts start -->
Last modified: Thu May 24 07:53:18 EDT 2001
<!-- hhmts end -->
</body>
</html>
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>