#include <stdio.h>
#include <stdlib.h>

#include "captive.h"


int main() {

	char buffer[500];
	char username[USERNAME_LEN];
	FILE *f;
	

	strncpy( username, getenv("QUERY_STRING"), USERNAME_LEN );


	printf( "Content-type: text/html\n\n" );


	printf( "<html><head><title>Captive Portal - SmoothWall Express</title></head><body bgcolor=\"#ffffff\" text=\"#000000\" link=\"#0000ff\" vlink=\"#ff0000\"><font face=\"courier new\" size=\"-2\">\n" );
	printf( "<br><br><font face=\"arial, sans-serif\" size=\"-1\"><a href=\"javascript:history.back()\">Back</a></font><br><br>" );

	snprintf( buffer, 500, "/var/smoothwall/mods/captive/squid/%s", username );
	f = fopen( buffer, "r" );
	if( !f ) { printf( "No log file for %s.", buffer ); exit(0); }

	fgets( buffer, 500, f );
	while( !feof(f) ) {
		printf( "<br>%s", buffer );
		fgets( buffer, 500, f );
	}
	fclose( f );

	printf( "<br><br><font face=\"arial, sans-serif\" size=\"-1\"><a href=\"javascript:history.back()\">Back</a></font><br><br>" );

	return 0;
}
