wf.c

Go to the documentation of this file.
00001 /******************************************************************************/
00002 /* cgi_wf.c © Copyright 2003 by Raosoft Inc. All Rights Reserved.             */
00003 /*                                                                            */
00004 /* You may use and modify this file for your own use, but may not distribute  */
00005 /* it or derivative works without the prior written consent of Raosoft, Inc.  */
00006 /*                                                                            */
00007 /* This software is provided "as is," and Raosoft makes no warranty, express  */
00008 /* or implied, of fitness for a articular application. Every measure has been */
00009 /* taken to anticipate risks inherent to computer networks, but we cannot     */
00010 /* guarantee safety or reliability of this program in every situation.        */
00011 /*                                                                            */
00012 /******************************************************************************/
00013 
00014 #include "cgi.h"
00015 
00016 char* JSShowPage(ScriptEnvironment* Env, char* cmd, int argc, char** argv, CGINameValue* Params)
00017 {/* prepend the next page to the _PAGENEXT list */
00018  char* pageskip;
00019  if (argc < 1) return 0;
00020  pageskip = GetFieldValue(Params,"_PAGESKIP");
00021  if (*pageskip)
00022   {
00023    if (!HasToken(pageskip,argv[0],0))
00024     {
00025      char*x = strdup3(pageskip,",",argv[0]);
00026      SetFieldValue(Params,"_PAGESKIP",x);
00027      CGIFREE(x);
00028     }
00029   }
00030  else
00031   {
00032    SetFieldValue(Params,"_PAGESKIP",argv[0]);
00033   }
00034  return 0;
00035 }
00036 
00037 char* JSTimeStamp(ScriptEnvironment* Env, char* cmd, int argc, char** argv, CGINameValue* Params)
00038 {
00039     char datetime[32];
00040     GetTime(datetime,datetime+8,0);
00041     return strdup(datetime);
00042 }
00043 
00044 /* recipient, subject, message */
00045 char* JSSendMail(ScriptEnvironment* Env, char* cmd, int argc, char** argv, CGINameValue* Params)
00046 {
00047  if (!Env->config) return 0;
00048  if (argc < 3) return 0;
00049  {
00050    char* server   = GetSetting(Env->config,"EMAILSERVER","");
00051    char* profile  = GetSetting(Env->config,"EMAILPROFILE","Windows Messaging Settings");
00052    char* name     = GetSetting(Env->config,"EMAILNAME","");
00053    char* password = GetSetting(Env->config,"EMAILPWD","");
00054    SendMail(argv[0],argv[1],argv[2], server, profile, name, password);
00055  }
00056  return 0;
00057 }
00058 
00059 #ifdef VPWSCGI
00060 int CGImainWF(char * argv0,char* url,CGINameValue* Params,STREAM htmlout)
00061 {
00062 #else
00063 int CGImain(char * argv0,CGINameValue* Params,STREAM htmlout)
00064 {
00065     char* url = GetEnvironment(htmlout,"PATH_INFO");
00066     if (!url) url = GetFieldValue(Params,"_page");
00067  return WFmain(argv0,url,Params,htmlout);
00068 }
00069 int WFmain(char * argv0,char* url,CGINameValue* Params,STREAM htmlout)
00070 {
00071 #endif
00072  ScriptFunction Functions[] =
00073  {
00074   {"print",10,(ScriptFunctionCall)*JSPrint},
00075   {"write",10,(ScriptFunctionCall)*JSPrint},
00076   {"eval",1,(ScriptFunctionCall)*JSEval},
00077   {"timestamp",0,(ScriptFunctionCall)*JSTimeStamp},
00078   {"toFixed",2,(ScriptFunctionCall)*JStoFixed},
00079   {"sendMail",3,(ScriptFunctionCall)*JSSendMail},
00080   {"escape",1,(ScriptFunctionCall)*JSHTMLEscape},
00081   {"hasRecord",1,(ScriptFunctionCall)*JSHasRecord},
00082   {"runReport",8,(ScriptFunctionCall)*JSReport},
00083   {"number",1,(ScriptFunctionCall)*JSToNumber},
00084   {"toNumber",1,(ScriptFunctionCall)*JSToNumber},
00085   {"random",1,(ScriptFunctionCall)*JSRandom},
00086         {"subStr",3,(ScriptFunctionCall)*JSsubstr},
00087       {"indexOf",4,(ScriptFunctionCall)*JSIndexOf},
00088       {"length",1,(ScriptFunctionCall)*JSstrlen},
00089 {0,0,0}};
00090 
00091  CGINameValue* config = NULL;
00092 
00093  FILE* f = NULL;
00094 
00095  if (url)
00096  {
00097   if (!url[0]) url = "index.html";
00098   if (strstr(url,"..")) return 101;
00099   if (url[0] == '/') return 101;
00100   if (strchr(url,'|')) return 101;
00101   if (strchr(url,'\\')) return 101;
00102   if (strchr(url,'>')) return 101;
00103   if (strchr(url,'<')) return 101;
00104   f = FileOpen(argv0,url,0);
00105  }
00106 
00107  if (f)
00108     {
00109         if (stristr(url,".html") || stristr(url,".jsp"))
00110         {
00111             SendCGIHeader(htmlout,NULL);
00112             RunReport(argv0,htmlout,f,Params,NULL,NULL,0,0);
00113             CGIFCLOSE(f);
00114             return 0;
00115         }
00116         if (stristr(url,".js"))
00117         {
00118          ScriptEnvironment Global;
00119          char fn[MAXPATH];
00120           ExpandLocalPath(argv0,fn,"cgi",".ini");
00121          config = ReadINIFileSection(fn,"server",0);
00122 
00123          memset(&Global,0,sizeof(Global));
00124          Global.htmlout   = htmlout;
00125          Global.Functions = Functions;
00126          Global.argv0     = argv0;
00127          Global.config    = config;
00128 
00129             SendCGIHeader(htmlout,NULL);
00130             RunScript(&Global,f,Params);
00131          if (config) DeleteNVP(config);
00132             CGIFCLOSE(f);
00133             return 0;
00134         }
00135         if (stristr(url,".gif"))
00136         {
00137             SendCGIHeader(htmlout,"Content-type: image/gif\n\n");
00138         }
00139         else if (stristr(url,".jpg"))
00140         {
00141             SendCGIHeader(htmlout,"Content-type: image/jpeg\n\n");
00142         }
00143         else if (stristr(url,".pdf"))
00144         {
00145             SendCGIHeader(htmlout,"Content-type: application/pdf\n\n");
00146         }
00147         HTMLWriteFileF(htmlout,f);
00148         CGIFCLOSE(f);
00149       return 0;
00150     }
00151 
00152  HTMLWrite(htmlout,"<P>usage: wf.cgi?_page=index.html\n"
00153    "<HR>Workflow automation &copy; 2003 by Raosoft, Inc. All Rights Reserved.");
00154 
00155  return 0;
00156 }


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/