00001 #include <string.h>
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <ctype.h>
00005 #include <time.h>
00006 #include <fcntl.h>
00007
00008 #define RAOSOFT_CGI_VERSION "4.51"
00009
00010 #if defined(_Windows) || defined(_WIN32)
00011 #include <winsock2.h>
00012
00013 #define CMC_USE_MSWIN_NT
00014
00015 #ifdef __BORLANDC__
00016 #include <win32/xcmc.h>
00017 #include <win32/xcmcext.h>
00018 #include <win32/xcmcmsxt.h>
00019 #else
00020 #include "xcmc.h"
00021 #include "xcmcext.h"
00022 #include "xcmcmsxt.h"
00023 #endif
00024 #endif
00025
00026 #ifdef _Windows
00027
00028 int WinsockConnect(char* host, int port, unsigned int*s)
00029 {
00030 long int hostaddr = 0;
00031 unsigned long *p;
00032 struct sockaddr_in svraddr;
00033 struct hostent *he;
00034 *s = INVALID_SOCKET;
00035
00036 if (isdigit(host[0]))
00037 {
00038 hostaddr = inet_addr(host);
00039 }
00040 else
00041 {
00042 he = gethostbyname(host);
00043 if (!he) {return 62;}
00044 p = (unsigned long*)he->h_addr_list[0];
00045 hostaddr = *p;
00046 }
00047
00048 *s = socket(AF_INET, SOCK_STREAM, 0);
00049
00050 if (*s == INVALID_SOCKET) return 63;
00051
00052 svraddr.sin_family = AF_INET;
00053 svraddr.sin_port = (short)htons(port);
00054 memcpy(&svraddr.sin_addr.s_addr, &hostaddr, sizeof(IN_ADDR));
00055 memset(svraddr.sin_zero,0,sizeof(svraddr.sin_zero));
00056
00057 if (connect(*s, (SOCKADDR*)&svraddr, sizeof(svraddr)) != 0)
00058 return 64;
00059
00060 return 0;
00061 }
00062 #else
00063 char* Variables [] =
00064 {
00065 "DOCUMENT_ROOT",
00066 "GATEWAY_INTERFACE",
00067 "HTTP_ACCEPT",
00068 "HTTP_ACCEPT_CHARSET",
00069 "HTTP_ACCEPT_ENCODING",
00070 "HTTP_ACCEPT_LANGUAGE",
00071 "HTTP_CONNECTION",
00072 "HTTP_HOST",
00073 "HTTP_KEEP_ALIVE",
00074 "HTTP_REFERER",
00075 "HTTP_USER_AGENT",
00076 "PATH",
00077 "Path",
00078 "QUERY_STRING",
00079 "REMOTE_ADDR",
00080 "REMOTE_HOST",
00081 "REMOTE_PORT",
00082 "REQUEST_METHOD",
00083 "REQUEST_URI",
00084 "SCRIPT_FILENAME",
00085 "SCRIPT_NAME",
00086 "SERVER_ADDR",
00087 "SERVER_ADMIN",
00088 "SERVER_NAME",
00089 "SERVER_PORT",
00090 "SERVER_PROTOCOL",
00091 "SERVER_SIGNATURE",
00092 "SERVER_SOFTWARE",
00093 "TZ",
00094 "CONTENT_TYPE",
00095 "CONTENT_LENGTH",
00096 0
00097 };
00098 #endif
00099
00100 int main(int argc,char** argv)
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 {
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 {
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)
00135 {
00136 shutdown(s, 2);
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 {
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 }
00298