cgi_test.c File Reference

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>
#include <fcntl.h>

Include dependency graph for cgi_test.c:

Go to the source code of this file.

Defines

#define RAOSOFT_CGI_VERSION   "4.51"

Functions

int main (int argc, char **argv)

Variables

char * Variables []


Define Documentation

#define RAOSOFT_CGI_VERSION   "4.51"
 

Definition at line 8 of file cgi_test.c.


Function Documentation

int main int  argc,
char **  argv
 

Definition at line 100 of file cgi_test.c.

References NULL, RAOSOFT_CGI_VERSION, Variables, and WinsockConnect().

00101 {
00102  int i,cl;
00103  char * c;
00104  char ** v;
00105  char temp[80];
00106  int runMailTests = 0;
00107 
00108  FILE *f;
00109 
00110  if (argc > 1) if (!strcmp(argv[1],"--test")) runMailTests = 1;
00111 
00112 if (runMailTests)
00113 { /*only works from the console for security */
00114   printf("EZSurvey is testing your server configuration ...\n\n");
00115 
00116   printf("EZSurvey CGI version: %s\n\n",RAOSOFT_CGI_VERSION);
00117 
00118   #ifdef _Windows
00119   { /* init winsock lib. want v2.0 */
00120    unsigned int s;
00121    WSADATA d;
00122 
00123    printf("Testing SMTP email\n");
00124    if (WSAStartup(2, &d) != 0)
00125    {
00126      WSACleanup();
00127      printf("* Winsock 2.0 is not available.\n");
00128      printf("* This server will not be able to send mail with SMTP.\n\n");
00129    }
00130    else
00131    {
00132      s = INVALID_SOCKET;
00133      WinsockConnect("www.raosoft.com", 80, &s);
00134      if (s != INVALID_SOCKET) /* shutdown and close the socket if needed */
00135      {
00136        shutdown(s, 2);   /* shutdown both channels (read+write) */
00137        closesocket(s);
00138        printf("Winsock OK\n");
00139      }
00140      else
00141      {
00142        printf("* This computer does not allow outbound network traffic.\n");
00143        printf("* This server will not be able to send mail with SMTP.\n\n");
00144      }
00145      WSACleanup();
00146    }
00147   }
00148   {/* init mapi32 lib.*/
00149     char LibName[1024];
00150     HANDLE library;
00151 
00152     printf("Testing MAPI email\n");
00153     GetProfileString("Mail", "CMCDLLNAME32", "MAPI32.DLL", LibName, 1024);
00154     library = LoadLibrary(LibName);
00155     if ((UINT) library < 32)
00156     {
00157      printf("* The MAPI DLL (%s) is not available.\n",LibName);
00158      printf("* This server will not be able to send mail to Exchange.\n\n");
00159     }
00160     else
00161     {
00162      int err=0;
00163      if (!GetProcAddress(library,"cmc_logoff"))
00164        err += printf("* The MAPI DLL (%s) is missing the cmc_logoff function.\n",LibName);
00165      if (!GetProcAddress(library,"cmc_logon"))
00166        err += printf("* The MAPI DLL (%s) is missing the cmc_logon function.\n",LibName);
00167      if (!GetProcAddress(library,"cmc_send"))
00168        err += printf("* The MAPI DLL (%s) is missing the cmc_send function.\n",LibName);
00169      if (!GetProcAddress(library,"cmc_look_up"))
00170        err += printf("* The MAPI DLL (%s) is missing the cmc_look_up function.\n",LibName);
00171      if (!GetProcAddress(library,"cmc_free"))
00172        err += printf("* The MAPI DLL (%s) is missing the cmc_free function.\n",LibName);
00173      if (!err) printf("MAPI OK\n");
00174      else
00175      printf("* This server will not be able to send mail to Exchange.\n\n");
00176 
00177     }
00178   }
00179   #else
00180   printf("Testing sendmail\n");
00181   f = popen("sendmail -t","w");
00182   if (!f) {
00183   printf("Tring /usr/local/sbin/sendmail instead\n");
00184   f = popen("/usr/local/sbin/sendmail -t","w");
00185   }
00186   if (!f) {
00187   printf("Tring /usr/lib/sendmail instead\n");
00188   f = popen("/usr/lib/sendmail -t","w");
00189   }
00190   if (f)
00191   {
00192    pclose(f);
00193    printf("sendmail OK\n");
00194   }
00195   else
00196   {
00197    printf("* The sendmail program is not in any of the obvious places.\n");
00198    printf("* This will prevent you from receiving security notices or\n");
00199    printf("* from having data returned to your email.\n\n");
00200    printf("* Please edit the file 'src/cgi_mail.c' and set the SENDMAIL\n");
00201    printf("* definition at the top to the correct path. You may use the UNIX\n");
00202    printf("* command 'locate sendmail' to search the server hard drives.\n");
00203    printf("* You will need to recompile the EZSurvey CGI programs for the\n");
00204    printf("* change to take effect.\n\n");
00205   }
00206 #endif
00207 
00208  printf("Done testing the server!\n");
00209 }
00210 else
00211 {
00212  printf("Content-type: text/plain\n\n<pre>","");
00213  printf("Server configuration information\n");
00214  printf("--------------------------------\n\n");
00215 
00216  printf("EZSurvey CGI version: %s\n",RAOSOFT_CGI_VERSION);
00217 
00218  if (argc) printf("Program name: %s\n",argv[0]);
00219  if (argc > 1)
00220  {
00221   printf("Arguments:\n","");
00222   for (i=1;i<argc; i++) {printf("  %d ",i); printf("%s\n",argv[i]);}
00223  }
00224 
00225 #ifdef _Windows
00226  getcwd(temp,80);
00227  printf("Current working directory: %s\n",temp);
00228 
00229  printf("Environment variables:\n",0);
00230   for (i=0;_environ[i]; i++)
00231   {
00232    printf("%d ",i);
00233    printf("%s\n",_environ[i]);
00234   }
00235 #else
00236  c = getenv("user");  if (c) printf("User name: %s\n",c);
00237  c = getenv("home");  if (c) printf("Home directory: %s\n",c);
00238  c = getenv("shell"); if (c) printf("Shell: %s\n",c);
00239  c = getenv("cwd");   if (c) printf("Current working directory: %s\n",c);
00240  v = Variables;
00241  for (v = Variables; *v; v++)
00242   {c = getenv(*v); if (c) printf("%s: %s\n",*v,c);}
00243 
00244 #endif
00245 
00246  c = getenv("CONTENT_LENGTH");
00247  cl = c == NULL ? 0 : atoi(c);
00248  if (cl)
00249  {
00250   printf("\n\nTesting POST data\n");
00251   printf("-----------------\n\n");
00252   printf("Content length: %d\n",cl);
00253   printf("Form data:\n",0);
00254   while ((i = fread(temp,1,cl < 80 ? cl : 80,stdin))!= 0)
00255   {
00256    fwrite(temp,1,i,stdout);
00257    fwrite("\n",1,1,stdout);
00258    cl -= i;
00259   }
00260  }
00261 
00262  printf("\n\nTesting file system access\n");
00263  printf("--------------------------\n\n");
00264 
00265  f = fopen("logtest.txt","at");
00266  if (f)
00267  {
00268   printf("logtest.txt: APPEND OK\n",0);
00269   fclose(f);
00270  }
00271  else
00272  {
00273   printf("logtest.txt: ERROR unable to open the file for writing\n",0);
00274  }
00275 
00276  f = fopen("readme.txt","r");
00277  if (f)
00278   {
00279    printf("readme.txt: READ OK\n",0);
00280    while (fread(temp,1,1,f)) fwrite(temp,1,1,stdout);
00281    fclose(f);
00282   }
00283  else printf("readme.txt: ERROR unable to open the file for reading\n",0);
00284 
00285  printf("\n\nAbout this program\n");
00286  printf("------------------\n\n");
00287  #ifdef _Windows
00288  printf("Run 'testcgi --test' from the command line to inspect mail configuration.\n");
00289  printf("Use 'testcgi' as the handler for any form to test your browser and server.\n");
00290  #else
00291  printf("Run './testcgi.cgi --test' from the command line to inspect mail configuration.\n");
00292  printf("Use './testcgi.cgi' as the handler for any form to test your browser and server.\n");
00293  #endif
00294 }
00295 
00296  return 0;
00297 }


Variable Documentation

char* Variables[]
 

Definition at line 63 of file cgi_test.c.

Referenced by main().



Raosoft, Inc.
Raosoft EZReport, EZSurvey, InterForm, RapidReport, Raosoft, and SurveyWin are registered trademarks of Raosoft, Inc. Page contents © 1996-2007 by Raosoft, Inc. You may use and modify this file for your own use, but may not distribute it or derivative works without the prior written consent of Raosoft, Inc. This software is provided "as is," and Raosoft makes no warranty, express or implied, of fitness for a particular application. Every measure has been taken to anticipate risks inherent to computer networks, but we cannot guarantee safety or reliability of this program in every situation.
Tel: 206-525-4025 (US) Email: raosoft@raosoft.com
http://www.raosoft.com/