/* For more information, please visit http://www.blackcat.net/redir */ /* or email scripts@blackcat.net for support. All code, comments, and */ /* binary programs relating to Redirect are copyright 1997 Black Cat */ /* Communications. You may modify the it as long as this comment block */ /* remains intact. Redirect is a trademark of Black Cat Communications */ #include #include #include #include main(int argc, char *argv[]) { /* Pointer for fopen, used to reference the file */ FILE *fp; /* The location variable used at the end */ /* Variables that log REMOTE_ADDR, HTTP_REFERER, and */ /* HTTP_USER_AGENT, respectively */ char *user_ip; char *refer_url; char *browser; /* Variables used to store the time */ time_t now; char *c; struct tm *current_time; /* Gets the time from and saves it */ /* Then convert it to readable format */ time(&now); current_time = localtime(&now); c = asctime(current_time); /* Snag the environment variables and store them in the */ /* respective variables */ user_ip = getenv("REMOTE_ADDR"); refer_url = getenv("HTTP_REFERER"); browser = getenv("HTTP_USER_AGENT"); /* Opens a text mode file for reading and appending at the start */ fp = fopen( "redirlog", "a" ); if (fp == NULL) { printf("Content-type: text/html\n\n"); printf("Script Error!

Attempting to open the log file with read/write options failed. This is might mean that the log file hasn't been created at all or it doesn't have the correct permissions. It should be chmod 666, which gives all users read/write access. The CGI program itself should be chmod 755. For more infomation, please visit http://www.blackcat.net/redir or email scripts@blackcat.net.

"); } /* Write the incremented counter value to the file */ fprintf(fp, "%s%s\n%s\n%s\n%s\n\n",c, argv[1], user_ip, browser, refer_url); /* Close the file */ fclose(fp); /* Redirects the user to the specified URL */ printf("Location:%s\n\n",argv[1]); }