Worktime Program

In the examples below italicized lines are lines of code that changed from the previous example, bold lines are lines that have been added to the example, and any time "username" appears it should be replaced by your specific username.

Please add this to your /etc/httpd/conf/loncapa_apache.conf file

Conf Changes

<Location /adm/username> SetHandler perl-script PerlHandler Apache::username </Location> <LocationMatch "\.username$"> SetHandler perl-script PerlHandler Apache::username </LocationMatch>

Example 1

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__
    

Example 2

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 is in use by $ENV{'user.name'}");
	return OK;
}
1;
__END__
    

Example 3

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);
	$r->print($contents);
	return OK;
}
1;
__END__
    

Example 4

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);
	return OK;
}
1;
__END__
    

Example 5

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);
        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);
        }
        return OK;
}
1;
__END__
    

Example 6

<html>
	<head><title> A simple file </title></head>
	<body>
		This is a simple file
	</body>
</html>
    

Example 7

<html>
	<head><title> A simple file </title></head>
	<body>
		This is a simple file
	        <form method="POST" action="/~username/a.username">
		       <input type="text" name="info"></input>
		       <input type="submit" name="Submit"></input>
                </form>
	</body>
</html>

    
  1. login
    1. First login to the CSE machine using the username guest__ and the password CAPA4all.
    2. Bring up a terminal by clicnking on the monitor icon with a foot at the bottom of the screen.
    3. Start up a netscape by typing netscape& in the terminal.
    4. telnet from the terminal to data.lite.msu.edu, login using your username and the password guts
    5. Login into LON-CAPA in netscape by pointing the browser at http://data.lite.msu.edu and typing in your username and guts
  2. Using the terminal edit the file ~/username.pm using your favorite unix text editor and type in example 1
  3. Point netscape at "http://data.lite.msu.edu/adm/username". You should see a the simple message the handler prints out.
  4. Change ~/username.pm to be what is in Example 2, the italicized line is the only one that changed.
  5. 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.
  6. Next in netscape goto "http://data.lite.msu.edu/~username/a.username". You should see the same output as before.
  7. Using the terminal edit the file ~/public_html/a.username and put in it example5 using your favorite unix text editor.
  8. Change ~/username.pm to be what is in Example 3, the italicized lines are changed and the bold lines should be added.
  9. 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.
  10. Change ~/username.pm to be what is in Example 4, the bold line should be added.
  11. 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.
    1. Change what is in ~/username.pm to be what is in Example 5. The bold section of code needs to be added.
    2. Change what is in ~/public_html/a.username to be what is in Example 7. The bold section needs to be added
    3. 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.
    4. Type someting into the form field and click the submit button.
    5. The handler should still report an error, but also echo back what you typed into the error handler.
    6. Type in the terminal
      ls -l /home/httpd/lonUsers/msu/u/s/e/username/
      	    
      Notice that there is a username.db file and a username.hist file.
    7. Type in the terminal
      cat /home/httpd/lonUsers/msu/u/s/e/username/username.hist
      	    
      You should see the information that you submitted.
    8. 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.
    9. Type something new into the text field and hit submit. The handler should tell you the first submission and the last submission.
  12. 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.
  13. Extra credit: Use Apache::lonxml::xmlparse to properly process the html file. Use <window></window> in your example .username file.

Helpful Notes


Guy Albertelli
Last modified: Thu May 24 07:53:18 EDT 2001