home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Connectivity / PPP / Docs / NeXTPPP_HTML / websale / member.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-09-18  |  6.2 KB  |  224 lines

  1. /*
  2.  * member.c
  3.  * Handle membership forms.
  4.  *
  5.  * Copyright 1995 First Virtual Holdings Inc. All Rights Reserved.
  6.  */
  7.  
  8. /*
  9. Copyright (c) 1994 FIRST VIRTUAL HOLDINGS INCORPORATED
  10. FIRST VIRTUAL (TM) and the FIRST VIRTUAL logo are service marks
  11. of First Virtual Holdings Incorporated.
  12.  
  13. Permission to use, copy, modify, and distribute this material 
  14. for any purpose and without fee is hereby granted, provided 
  15. that the above copyright notice and this permission notice 
  16. appear in all copies, and that the name of First Virtual not be 
  17. used in advertising or publicity pertaining to this 
  18. material without the specific, prior written permission 
  19. of First Virtual Holdings Incorporated.  FIRST VIRTUAL
  20. MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  21. OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  22. WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  23.  
  24. */
  25.  
  26. /* SEE config.h for installation configuration */
  27.  
  28. #include <stdlib.h>
  29. #include <stdio.h>
  30. #include <ctype.h>    /* for isalpha and isdigit */
  31. #include <string.h>    /* for strstr() and the usual */
  32. #include <time.h>    /* for time() */
  33. #include <unistd.h>    /* for getpid() */
  34.  
  35. #include "config.h"    /* for configuring this program */
  36.  
  37. extern char *membershipContents, *badacctContents, *blewitContents, *noaccessContents, *thankyouContents;
  38.  
  39. int goodfinger(s) char * s;
  40. {
  41.     /* This return 1 if the PIN described by the finger in s is
  42.        active, else zero */
  43.     int ret;
  44.     char * p;
  45.     char * q;
  46.     char * r;
  47.     
  48.     ret = 0;
  49.     p = strstr(s, "Account-Status:");
  50.     if (p) {
  51.     q = strstr(p, "active");
  52.     if (q) {
  53.         ret = 1;
  54.         for (r = p; r < q; r++) {
  55.         if (*r=='\n') ret = 0;
  56.         }
  57.         }
  58.     }
  59.     return ret;
  60.     }
  61.  
  62. void main()
  63. {
  64.     char * qs;    /* Query string */
  65.     char * as;    /* Action string */
  66.     char FVPIN[50];    /* First Virtual ID */
  67.     char price[40];    /* The price to charge */
  68.     char * * fnp;    /* Field name pointer */
  69.     char fc[2000];    /* Field contents */
  70.     char * fcp;    /* Field contents pointer */
  71.     char xferid[40];/* Transfer ID */
  72.     FILE * pf;    /* pipe file */
  73.     char junkbuf[2000];
  74.     char inbuf[4000];    /* Input buffer for POST method */
  75.     char * cl;        /* content length */
  76.     int cli;        /* content length as an integer */
  77.     int i;            /* temp int */
  78.  
  79.     as = getenv("SCRIPT_NAME");
  80.     if (as == NULL) as = "?NONE?";
  81.     cl = getenv("CONTENT_LENGTH");
  82.     if (cl && *cl && 0 != (cli = atoi(cl))) {
  83.     if (sizeof(inbuf) < cli + 5) {
  84.         printf("Content-type: text/plain\n\nServer error one?\n");
  85.         exit(0);
  86.         }    
  87.     qs = inbuf;
  88.     while (0 < cli) {
  89.         i = read(0, qs, cli);
  90.         if (i < 1) {
  91.         printf("Content-type: text/plain\n\nServer error two?\n");
  92.         exit(0);    /* Eh? */
  93.         }
  94.         qs += i; cli -= i;
  95.         }
  96.     *qs = 0;
  97.     qs = inbuf;
  98.     }
  99.     else {
  100.     qs = getenv("QUERY_STRING");
  101.     }
  102.     if (!qs || !*qs) {
  103.     int i = 0;
  104.     printf("Content-type: text/html\n\n");
  105.     fflush(stdout);
  106.     while (0 != strncmp("ACTIONPROGURL", membershipContents+i,
  107.                 strlen("ACTIONPROGURL"))) {
  108.         putchar(membershipContents[i]);
  109.         i++;    
  110.         }    
  111.     fputs(as, stdout); i += strlen("ACTIONPROGURL");
  112.     puts(membershipContents + i);
  113.     exit(0);
  114.     }
  115.     /* Here he has filled out the form */
  116.     /* See if he gave us a FVPIN and check it if so. */
  117.     FVPIN[0] = 0; xferid[0] = 0;
  118.     parseurl(qs, "FVPIN", FVPIN, sizeof(FVPIN));
  119.     strcpy(price, amount);
  120.     if (!price[0]) parseurl(qs, "price", price, sizeof(price));
  121.     for (i = 0; price[i]; i++) {
  122.     if (!isdigit(price[i]) && price[i] != '.')
  123.         price[i] = ' ';
  124.     }
  125.     if (atof(price) <= 0.0) price[0] = 0; /* not a valid price */
  126.     else sprintf(price, "%0.2f", atof(price));
  127.     if (FVPIN[0] && price[0]) {
  128.     /* He gave us an ID and an amount -- check and charge */
  129.     char fingerout[2000];
  130.     char fingerin[200];
  131.     int i;
  132.     strcpy(fingerin, fingerpath);
  133.     strcat(fingerin, " ");
  134.     for (i=0; FVPIN[i]; i++) {
  135.         if (isalpha(FVPIN[i])||isdigit(FVPIN[i])) {
  136.         fingerin[strlen(fingerin)+1]=0;
  137.         fingerin[strlen(fingerin)]=FVPIN[i];
  138.         }
  139.         }
  140.     strcat(fingerin, fingeraddr);
  141.     pf = popen(fingerin, "r");
  142.     if (!pf) {
  143.         /* What to do if you can't finger? */
  144.         puts(noaccessContents);
  145.         exit(1);
  146.         }
  147.     i = fread(fingerout, 1, sizeof(fingerout)-2, pf);
  148.     if (i < 1) {
  149.         /* Again, can't finger */
  150.         puts(noaccessContents);
  151.         exit(1);
  152.         }
  153.     fingerout[i] = 0;
  154.     if (goodfinger(fingerout)) {
  155.         /* Bill them */
  156.         /* First, a transfer ID */
  157.         sprintf(xferid, "<%d.%d@%s>", 
  158.             time(NULL), getpid(), mymach);
  159.         sprintf(junkbuf, "%s %s %s", mailpath, xferaddr, handleraddr);
  160.         pf = popen(junkbuf, "w");
  161.         if (!pf) {
  162.         puts(noaccessContents);
  163.         exit(1);
  164.         }
  165.         fprintf(pf, "Content-type: application/green-commerce; transaction=transfer-request\n");
  166.         fprintf(pf, "Subject: %s (TRANSFER)\n", desc);
  167.         fprintf(pf, "From: %s\n", handleraddr);
  168.         fprintf(pf, "To: %s\nCC: %s\n\n", xferaddr, handleraddr);
  169.         fprintf(pf, "Seller: %s\nBuyer: %s\n",
  170.             mysellid, FVPIN);
  171.         fprintf(pf, "Amount: %s\nCurrency: %s\n",
  172.             price, currency);
  173.         fprintf(pf, "Payment-expected: no\n");
  174.         fprintf(pf, "Description: %s\nTransfer-id: %s\n",
  175.             desc, xferid);
  176.         fprintf(pf, "\n\n");
  177.         /* Add more descriptive text here if you want. */
  178.         pclose(pf);
  179.         }
  180.     else {
  181.         /* The account is not active */
  182.         puts(badacctContents);
  183.         printf("%s\n</pre>\n", fingerout);
  184.         exit(0);
  185.         }
  186.     }
  187.     else {
  188.     /* Here, they didn't give us a FVPIN */
  189.     /* Do nothing except set the form properly below */
  190.     }
  191.     /* If we got this far, we submitted a bill if we had their ID. */
  192.     /* Here, we collect the other info. */
  193.     sprintf(junkbuf, "%s %s", mailpath, handleraddr);
  194.     pf = popen(junkbuf, "w");
  195.     if (!pf) {
  196.     puts(blewitContents);
  197.     exit(0);
  198.     }
  199.     fprintf(pf, "Subject: %s (FIELDS)\n", desc);
  200.     fprintf(pf, "From: %s\n", handleraddr);
  201.     fprintf(pf, "To: %s\n\n", handleraddr);
  202.     for (fnp=fields; *fnp; fnp++) {
  203.     fc[0] = 0;
  204.     parseurl(qs, *fnp, fc, sizeof(fc));
  205.     if (fc[0]) {
  206.         /* We got a field. Add it to the output */
  207.         fprintf(pf, "%s: ", *fnp);
  208.         for (fcp=fc; *fcp; fcp++) {
  209.         if ('\r'!=*fcp)
  210.             fputc(*fcp, pf);
  211.         if ('\n'==*fcp)
  212.             fputc(' ', pf);
  213.         }
  214.         fputc('\n', pf);
  215.         }
  216.     }
  217.     fprintf(pf, "Script: %s\n", as);
  218.     fprintf(pf, "Transfer-id: %s\n", xferid);
  219.     fprintf(pf, "Price: %s\n", price);
  220.     pclose(pf);
  221.     puts(thankyouContents);
  222.     exit(0);
  223.     }
  224.