Worktime Install, Changes Intro, Handler Creation

Install

To familiarise you with the system, first we will update these systems from the current STABLE release to the latest release

CVS

First you will need to check out LON-CAPA from CVS

Login

cvs -d :pserver:username@zaphod.lite.msu.edu:/home/cvs login

Checkout the LON-CAPA source code

cvs -d :pserver:username@zaphod.lite.msu.edu:/home/cvs checkout LON-CAPA

Add you current hosts.tab file to the CVS checkout

cp /home/httpd/lonTabs/hosts.tab ~/loncapa/loncom/hosts.tab

Build and Install the newest version of LON-CAPA

cd ~/loncapa/loncom/build

su

make build

make install

Restart the necessary services

/etc/init.d/httpd restart

/etc/init.d/loncontrol restart


Using CVS

CVS is a code versioning system, that tracks changes in code and supports multiple features to make multiple developers able to coexist with the same central repository of code. It has many options and commands. I highly suggest reading the CVS man page man cvs at some time.

The most useful commands you will have access to are

Common options to cvs commands

Some commands to try (in the loncom directory)

cvs diff -u -r 1.40 -r 1.43 lond | less
cvs diff -u -r STABLE -r HEAD loncron | less
cvs log loncron | less
cvs update -r STABLE loncron
cvs update -D 'last week'
cvs update -A loncron
cvs annotate loncron | less
    

Changing Code and detecting errors

We will change the lonhomework handler to act differently, and we will cause it to throw errors

Making a new Handler

In the examples below italicised 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.

Example 1

package Apache::workshop;
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 workshop handler");
	return OK;
}
1;
__END__
    

Example 2

<Location /adm/workshop>
PerlAccessHandler       Apache::lonacc
SetHandler perl-script
PerlHandler Apache::workshop
ErrorDocument     403 /adm/login
ErrorDocument     500 /adm/errorhandler
</Location>

<LocationMatch "^/(res|\~).*\.workshop$">
SetHandler perl-script
PerlHandler Apache::workshop
</LocationMatch>
    

Example 3

package Apache::workshop;
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 workshop handler is in use by $env{'user.name'}");
	return OK;
}
1;
__END__
    

Example 4

package Apache::workshop;
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 workshop 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 5

package Apache::workshop;
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 workshop 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 6

package Apache::workshop;
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 workshop handler is in use by $env{'user.name'} looking for "
                   .$r->uri."<br>");
        my $file=&amp;Apache::lonnet::filelocation("",$r->uri);
        my $contents=&amp;Apache::lonnet::getfile($file);
        $contents=~s/simple/complex/g;
        $r->print($contents);
        my %hash=&Apache::lonnet::get('workshop',['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('workshop',\%hash);
        }
        return OK;
}
1;
__END__
    

Example 7

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

Example 8

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

    
  1. You will need to add the author role to the domcc user, use the CUSR button on the remote, type in the username 'domcc' and then add the author role. Logout, and log back in. (You will also need to let the webserver have permission to enter domcc's home directory, do this by having domcc dochmod a+x /home/domcc
  2. Create the file loncapa/loncom/workshop.pm using your favourite unix text editor and type in example 1
  3. Add example 2 to the file /etc/httpd/conf/loncapa_apache.conf
  4. Copy the workshop.pm file to /home/httpd/lib/perl/Apache, and restart the webserver. You will need to do this after every change of the workshop.pm file.
  5. Point netscape at "http://cc313-pc-XX.cl.msu.edu/adm/workshop". You should see the simple message the handler prints out.
  6. Change workshop.pm to be what is in Example 3, the italicised line is the only one that changed.
  7. In netscape reload "http://cc313-pc-XX.cl.msu.edu/adm/workshop". You should see the output of the handler should now have your lon-capa name, which it got from the session environment.
  8. Next in netscape goto "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should see the same output as before.
  9. Using the terminal edit the file ~/public_html/a.workshop and put in it Example 7 using your favourite unix text editor.
  10. Change ~/workshop.pm to be what is in Example 4, the italicised lines are changed and the bold lines should be added.
  11. In netscape reload "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". You should see the output of the handler contains the contents of the file that you created along with the name of the file.
  12. Change ~/workshop.pm to be what is in Example 5, the bold line should be added.
  13. In netscape reload "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". 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 ~/workshop.pm to be what is in Example 6. The bold section of code needs to be added.
    2. Change what is in ~/public_html/a.workshop to be what is in Example 8. The bold section needs to be added
    3. In netscape reload "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". The web page should now contain a form, and say that an error occurred.
    4. Type something 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/pcXX/d/o/m/domcc
      	    
      Notice that there is a workshop.db file and a workshop.hist file.
    7. Type in the terminal
      cat /home/httpd/lonUsers/pcXX/d/o/m/workshop.hist
      	    
      You should see the information that you submitted.
    8. In netscape revisit "http://cc313-pc-XX.cl.msu.edu/~domcc/a.workshop". (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.

Helpful Notes


Guy Albertelli
Last modified: Tue Jun 11 14:18:30 EDT 2002