"These men know why they are on this New Jersey hilltop." intrigued?

Netbounce project with Apache2

by: burt rosenberg
at: february 2024

Overview

The project is to get the netbounce code working for you. I wanted that your output actually apear on a project webpage. I just thought at would be fun. There are a few ways to do this. Well let's try this last way.

First activity: get netbounce working

The assignment as accepted has an empty directory. Step one is the copy the netbounce code from the class example repository to the assignment directory and push. Then get netbounce working between EC2 instances.
  1. The Makefile has a macro for the IP addresses. In particular the IP address of the server needs to be in the Makefile of the client.
  2. The UPD port 3333 must be opened on EC2, by editing the security list.

Second activity: add logging

I would like to see the output on the terminal also on a webpage. To do this add statements in the client and server code to open a file for append, and to append into that file a copy of what you are writing to stdout. We could have also done this with redirection, but this might be more fun.
  1. Add some new variables at the top of your code,
    	#include<time.h> // in the include section
    	
    	// in the variable declaration section
    	char * out_file_name = NULL ;
    	FILE * out_fn = NULL ;
    	time_t the_time ;
    
  2. Add a -f option to getopt. This requires two changes, f: added to the string that configures getopt and an new switch case,
    	while ((ch = getopt(argc, argv, "vp:lf:")) != -1) {  // change
    	
    	// add somewhere in the switch body
    		case 'f':
    			out_file_name = strdup(optarg) ;
    			break ;
    
  3. Opening the file for append, if the command option -f appeared, and using some calls to get the time printed out,
    	if (out_file_name) {
    		out_fn = fopen(out_file_name, "a");
    		if (!out_fn) {
    			perror("fopen") ;
    			exit(1) ;
    		}
    	}
    
  4. Decorate your code with outputs to the opened file. For instance, the time.
    	// see https://en.cppreference.com/w/c/chrono/ctime
    
    	if (out_fn) {
    		time(&the_time) ;
    		fprintf(out_fn,"%sserver starting ...", ctime(&the_time)) ;
    		
    		fflush(out_fn) ;
    	}
    
    or data writes,
    	if (out_fn) {
    		fprintf(out_fn,"packet sent, %d bytes\n", bytes_sent) ;
    		fflush(out_fn) ;
    	}
    
Test and commit. A new Makefile macro gives the name of the logfile and the option to apply for the targets run-server and run-client.

Third activity: enable shtml

shtml is server-side includes. The html file first goes to a small macro processor that constructs the page. For instance you can run a shell command or include another file this way,
<!--#echo var="DATE_LOCAL" -->
<!--#include file=netbounce-log.txt -->
see howto/ssi.html for more information.

  1. The ability to include files is in an apache module, code that is optional. Enable the module using,
    sudo a2enmod  include
    
    see howto apache modules for more information. Note that this command is ubuntu, not apache.
  2. Then onfigure the include module in the apache configuration files. In the file /etc/apache2/site-available/000-default.conf add
    <Directory /var/www/>
            Options +Includes
            AddType text/html .shtml
            AddOutputFilter INCLUDES .shtml
            DirectoryIndex index.html index.shtml
    </Directory>
    
  3. Restart the webserver,
    sudo systemctl restart apache2
    
  4. Rename index.html to index.shtml. And some shtml line in it and reload the browser

Fourth activity: the project website

Create the file /var/www/ubuntu/project2/index.shtml to your liking and include the include-directive that was presented above. Make sure the makefile pathnames are correct. Your output should be on the web at __ipaddress_/project2.
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

author: burton rosenberg
created: 8 feb 2024
update:8 jan 2024