#include #include /* getenv */ #include /* vfprintf */ #include /* NULL and size_t */ #include /* str... */ #include /* is... */ #include "cgi.h" typedef long time_t; void cgiMain(void) { char *redirectUrl = cgiFormGetVal("url"); char *requestUrl = cgiFormGetVal("url"); char *volume = cgiFormGetVal("volume"); char oldLocation [100], newLocation [100], status [15], localIPcheck [12], temp [300], accessTime [100]; char urlFileName [25], logFileName [25]; int i, j, matchUrl, volumeNumber; FILE *urlFile, *logFile, *mailFile; time_t when; size_t n =10; matchUrl = 0; strcpy (urlFileName, "./urls/volume"); strcpy (logFileName, "./logs/volume"); strncpy (localIPcheck, cgiEnv.remoteAddr, n); volumeNumber = atoi (volume); if (!volumeNumber) { strcat (urlFileName, volume); strcat (logFileName, volume); strcat (urlFileName, ".txt"); strcat (logFileName, ".txt"); } else { strcpy (urlFileName, "./urls/volume2.txt"); strcpy (logFileName, "./logs/volume2.txt"); } urlFile = fopen (urlFileName, "r"); if (urlFile == NULL) { printf("Location: %s\n\n", redirectUrl); fflush(stdout); strcpy (logFileName, "./logs/fileerror.txt") ; logFile = fopen (logFileName, "a"); when = time (NULL); strftime (accessTime, 100, "%H:%M:%S on %A, %d %B %Y", localtime(&when)); fprintf (logFile, "\n\nAccessed on\t:\t%s\n", accessTime); fprintf (logFile, "Status\t\t:\t%s\n", status); fprintf (logFile, "From Document\t:\t%s\n", cgiEnv.httpReferer); fprintf (logFile, "Volume\t\t:\t%s\n", volume); fprintf (logFile, "URL Requested\t:\t%s\n", requestUrl); fprintf (logFile, "Browser Used\t:\t%s\n", cgiEnv.httpUserAgent); fprintf (logFile, "IP Address\t:\t%s(%s)\n", cgiEnv.remoteHost, cgiEnv.remoteAddr); fclose (logFile); fflush(stdout); mailFile = fopen ("./logs/temp.txt", "w"); fprintf (mailFile,"To: ngopalan@enc.org \n"); fprintf (mailFile,"From: ngopalan@enc.org \n"); fprintf (mailFile,"Subject: Redirect Script: File Opening Error\n\n"); fprintf (mailFile, "The following access to the Redirect script encountered a FILE OPENING error!\n"); fprintf (mailFile, "-----------------------------------------------------------------------------\n"); fprintf (mailFile, "Accessed on\t:\t%s\n", accessTime); fprintf (mailFile, "Status\t\t:\t%s\n", status); fprintf (mailFile, "From Document\t:\t%s\n", cgiEnv.httpReferer); fprintf (mailFile, "Volume\t\t:\t%s\n", volume); fprintf (mailFile, "URL Requested\t:\t\"%s\"\n", requestUrl); fprintf (mailFile, "Browser Used\t:\t%s\n", cgiEnv.httpUserAgent); fprintf (mailFile, "IP Address\t:\t%s(%s)\n", cgiEnv.remoteHost, cgiEnv.remoteAddr); fprintf (mailFile, "-----------------------------------------------------------------------------\n\n"); fprintf (mailFile, "Better check it out !\n\n"); fclose (mailFile); system ("/usr/lib/sendmail ngopalan@enc.org \n"); fprintf (mailFile,"From: ngopalan@enc.org \n"); fprintf (mailFile,"Subject: Redirect Script: URL Not Found\n\n"); fprintf (mailFile, "The following access to the Redirect script encountered a URL NOT FOUND error!\n"); fprintf (mailFile, "-----------------------------------------------------------------------------\n"); fprintf (mailFile, "Accessed on\t:\t%s\n", accessTime); fprintf (mailFile, "Status\t\t:\t%s\n", status); fprintf (mailFile, "From Document\t:\t%s\n", cgiEnv.httpReferer); fprintf (mailFile, "Volume\t\t:\t%s\n", volume); fprintf (mailFile, "URL Requested\t:\t\"%s\"\n", requestUrl); fprintf (mailFile, "Browser Used\t:\t%s\n", cgiEnv.httpUserAgent); fprintf (mailFile, "IP Address\t:\t%s(%s)\n", cgiEnv.remoteHost, cgiEnv.remoteAddr); fprintf (mailFile, "-----------------------------------------------------------------------------\n\n"); fprintf (mailFile, "Better check it out !\n\n"); fclose (mailFile); system ("/usr/lib/sendmail ngopalan@enc.org