home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 13
/
amigaformatcd13.iso
/
-in_the_mag-
/
html_tutorial
/
mas_rec.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-03-07
|
3KB
|
122 lines
// Record details about who the viewer of a web page is
//
// (C) M.A.Smith University of Brighton
//
// Permission is granted to use this code
// provided this declaration and copyright notice remains intact.
//
// 26 August 1995
#include <iostream.h>
#include <fstream.h>
#include <iomanip.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
#include "parse.h"
#include "parse.cpp"
void write_log_entry( char[], char[] );
void cgi_var_output();
char* getenv_n( char [] );
void gif_output( char [] );
// Parameters to the CGI program
// passed in the QUERY_STRING environment variable
//
// file=mame - Names the file to which log information is written
// page=name - The name of the page that will be written to the log
// img=name - Names the image file which is returned
// - If no name or unreadable an image of a . is returned
// - If this parameter is omitted then a web page of CGI
// - variables is returned to help in debuging
// Remember all files name must be absolute or relative to the
// directory in which the CGI script is run
inline void html( char str[] ) { cout << str << "\n"; }
inline void html_( char str[] ) { cout << str; }
inline void html_( char c ) { cout << c; }
int main()
{
char *query_str = getenv("QUERY_STRING");
Parse list( query_str == 0 ?
"file=mas&page=test&img=" : query_str );
if ( list.get_item( "file" ) != NULL )
{
write_log_entry( list.get_item( "file", 1, true ),
list.get_item( "page" ) );
}
if ( list.get_item( "img" ) != NULL )
{
gif_output( list.get_item("img", 1, true) );
} else {
html("Content-type: text/html"); html("");
cgi_var_output(); // debug option
}
return 0;
}
void write_log_entry( char file[], char page[] )
{
ofstream inf( file, ios::app );
if ( !inf.fail() )
{
time_t t;
time( &t);
char *str = ctime( &t ); str[24] = '\0';
inf << setiosflags( ios::left );
inf << setw(24) << str << " " <<
setw(10) << (page!=NULL? page : "Unknown" ) <<
setw(20) << getenv_n("REMOTE_HOST") <<
setw(20) << getenv_n("REMOTE_ADDR") << "\n";
// setw(20) << getenv_n("REMOTE_USER") << "\n";
}
}
void gif_output( char gif[] )
{
unsigned char square [] = {
'G', 'I', 'F', '8', '9', 'a',
0002, 0000, 0002, 0000, 0263, 0000, 0000, 0000, 0000, 0000,
0277, 0000, 0000, 0000, 0277, 0000, 0277, 0277,
0000, 0000, 0000, 0277, 0277, 0000, 0277, 0000,
0277, 0277, 0300, 0300, 0300, 0200, 0200, 0200,
0377, 0000, 0000, 0000, 0377, 0000, 0377, 0377,
0000, 0000, 0000, 0377, 0377, 0000, 0377, 0000,
0377, 0377, 0377, 0377, 0377, 0054, 0000, 0000,
0000, 0000, 0002, 0000, 0002, 0000, 0100, 0004,
0003, 0020, 0200, 0010, 0000, 0073 };
html("Content-type: image/gif"); html("");
if ( gif[0] != '\0' ) // Output gif file
{
ifstream in( gif );
if ( !in.fail() ) // Can read
{
char c;
in.read( &c, 1 );
while ( !in.eof() )
{
cout.write( &c, 1 );
in.read( &c, 1 );
}
return; // Finish
}
}
cout.write( square, sizeof( square ) );
}