completed part of the login procedure
authorArt Cancro <ajc@citadel.org>
Wed, 25 Nov 1998 19:03:09 +0000 (19:03 +0000)
committerArt Cancro <ajc@citadel.org>
Wed, 25 Nov 1998 19:03:09 +0000 (19:03 +0000)
added the frameset

webcit/auth.c
webcit/tcp_sockets.c
webcit/webcit.c
webcit/webcit.h

index 0129f2d82964e702b09bb997ed193b118f4f85bd..4da4ddd353c7774d111b9d96269ea271856c8bca 100644 (file)
@@ -42,3 +42,53 @@ void display_login_page() {
 
        wDumpContent();
        }
+
+
+
+
+void output_frameset() {
+       printf("HTTP/1.0 200 OK\n");
+       output_headers();
+
+       wprintf("<HTML><HEAD><TITLE>FrameSet</TITLE></HEAD>\n");
+       wprintf("<FRAMESET cols=\"20%, 80%\">\n");
+       wprintf("    <FRAME src=\"/static/velma.gif\">\n");
+       wprintf("    <FRAME src=\"/thepage\">\n");
+       wprintf("<NOFRAMES>\n");
+       wprintf("ooo!  no frames!  too bad!\n");
+       wprintf("</NOFRAMES>\n");
+       wprintf("</FRAMESET></HTML>\n");
+       wDumpContent();
+       }
+
+
+
+void do_login() {
+       char buf[256];
+
+       if (!strcasecmp(bstr("action"), "Login")) {
+               serv_printf("USER %s", bstr("name"));
+               serv_gets(buf);
+               if (buf[0]=='3') {
+                       serv_printf("PASS %s", bstr("pass"));
+                       serv_gets(buf);
+                       if (buf[0]=='2') {
+                               logged_in = 1;
+                               }
+                       }
+               }
+
+       if (logged_in) {
+               output_frameset();
+               }
+       else {
+               printf("HTTP/1.0 200 OK\n");
+               output_headers();
+               wprintf("<HTML><HEAD><TITLE>Nope</TITLE></HEAD><BODY>\n");
+               wprintf("Your password was not accepted.\n");
+               wprintf("<HR><A HREF=\"/\">Try again</A>\n");
+               wprintf("</BODY></HTML>\n");
+               }
+
+       wDumpContent();
+       }
index a26023555bcd26b51ca5f11bbd9dab0fcab8871c..c121c3bd42c1e82bff3bafa53e2f987228f4202a 100644 (file)
@@ -121,9 +121,11 @@ int bytes; {
         while(len<bytes) {
                 rlen = read(serv_sock,&buf[len],bytes-len);
                 if (rlen<1) {
-                        printf("Network error - connection terminated.\n");
-                        printf("%s\n", strerror(errno));
-                        exit(3);
+                        fprintf(stderr, "Server connection broken: %s\n",
+                               strerror(errno));
+                        connected = 0;
+                       logged_in = 0;
+                       return;
                         }
                 len = len + rlen;
                 }
@@ -146,6 +148,7 @@ char strbuf[]; {
                strbuf[len++] = ch;
                } while((ch!=10)&&(ch!=13)&&(ch!=0)&&(len<255));
        strbuf[len-1] = 0;
+       fprintf(stderr, ">%s\n", strbuf);
        }
 
 
@@ -183,9 +186,11 @@ int nbytes; {
                 retval = write(serv_sock, &buf[bytes_written],
                         nbytes - bytes_written);
                 if (retval < 1) {
-                        printf("Network error - connection terminated.\n");
-                        printf("%s\n", strerror(errno));
-                        exit(3);
+                        fprintf(stderr, "Server connection broken: %s\n",
+                               strerror(errno));
+                        connected = 0;
+                       logged_in = 0;
+                       return;
                         }
                 bytes_written = bytes_written + retval;
                 }
@@ -217,6 +222,7 @@ void serv_printf(const char *format, ...) {
 
        strcat(buf, "\n");
        serv_write(buf, strlen(buf));
+       fprintf(stderr, "<%s", buf);
        }
 
 
index a79d70dcfe6ca0fd7c0a5b3ffbd26cdd88a5bcfa..946b2ab857480db2b9dfcc117353e9d494acf41c 100644 (file)
@@ -29,6 +29,102 @@ int logged_in = 0;
 struct webcontent *wlist = NULL;
 struct webcontent *wlast = NULL;
 
+struct urlcontent *urlstrings = NULL;
+
+
+void unescape_input(buf)
+char buf[]; {
+       int a,b;
+       char hex[3];
+
+       while ((isspace(buf[strlen(buf)-1]))&&(strlen(buf)>0))
+               buf[strlen(buf)-1] = 0;
+
+       for (a=0; a<strlen(buf); ++a) {
+               if (buf[a]=='+') buf[a]=' ';    
+               if (buf[a]=='%') {
+                       hex[0]=buf[a+1];
+                       hex[1]=buf[a+2];
+                       hex[2]=0;
+                       sscanf(hex,"%02x",&b);
+                       buf[a] = (char) b;
+                       strcpy(&buf[a+1],&buf[a+3]);
+                       }
+               }
+
+       }
+
+
+void addurls(char *url) {
+       char *up, *ptr;
+       char buf[256];
+       int a,b;
+       struct urlcontent *u;
+
+       up = url;
+       while (strlen(up)>0) {
+               
+               /* locate the = sign */
+               strncpy(buf,up,255);
+               b = (-1);
+               for (a=255; a>=0; --a) if (buf[a]=='=') b=a;
+               if (b<0) goto DONE;
+               buf[b]=0;
+       
+               u = (struct urlcontent *)malloc(sizeof(struct urlcontent));
+               u->next = urlstrings;
+               urlstrings = u;
+               strcpy(u->url_key, buf);
+       
+               /* now chop that part off */
+               for (a=0; a<=b; ++a) ++up;
+       
+               /* locate the & sign */
+               ptr = up;
+               b = strlen(up);
+               for (a=0; a<strlen(up); ++a) {
+                       if (!strncmp(ptr,"&",1)) {
+                               b=a;
+                               goto FOUNDIT;
+                               }
+                       ++ptr;
+                       }
+FOUNDIT:       ptr = up;
+               for (a=0; a<b; ++a) ++ptr;
+               strcpy(ptr,"");
+               
+               u->url_data = malloc(strlen(up));
+               strcpy(u->url_data, up);
+               unescape_input(u->url_data);
+
+               up = ptr;
+               ++up;
+
+               fprintf(stderr, "%s=%s\n", u->url_key, u->url_data);
+               }
+DONE:
+       }
+
+void free_urls() {
+       struct urlcontent *u;
+
+       while (urlstrings != NULL) {
+               free(urlstrings->url_data);
+               u = urlstrings->next;
+               free(urlstrings);
+               urlstrings = u;
+               }
+       }
+
+char *bstr(char *key) {
+       struct urlcontent *u;
+
+       for (u = urlstrings; u != NULL; u = u->next) {
+               if (!strcasecmp(u->url_key, key)) return(u->url_data);
+               }
+       return("");
+       }
+
 
 void wprintf(const char *format, ...) {   
         va_list arg_ptr;   
@@ -144,7 +240,7 @@ void output_static(char *what) {
 void session_loop() {
        char cmd[256];
        char buf[256];
-       int a;
+       int a, b;
        int ContentLength = 0;
        char *content;
 
@@ -196,6 +292,7 @@ void session_loop() {
                fread(content, ContentLength, 1, stdin);
                content[ContentLength] = 0;
                fprintf(stderr, "CONTENT:\n%s\n", content);
+               addurls(content);
                }
        else {
                content = NULL;
@@ -209,6 +306,7 @@ void session_loop() {
        if (!connected) {
                serv_sock = connectsock(c_host, c_port, "tcp");
                connected = 1;
+               serv_gets(buf); /* get the server welcome message */
                strcpy(wc_host, c_host);
                strcpy(wc_port, c_port);
                serv_printf("IDEN %d|%d|%d|%s|%s",
@@ -218,7 +316,8 @@ void session_loop() {
                        SERVER,
                        ""
                        );
-               serv_gets(buf); /* FIX find out where the user is */
+               serv_gets(buf);
+               /* FIX find out where the user is */
                }
 
 
@@ -252,12 +351,23 @@ void session_loop() {
                        }
                }
 
+       /* If there are variables in the URL, we must grab them now */  
+       for (a=0; a<strlen(cmd); ++a) if (cmd[a]=='?') {
+               for (b=a; b<strlen(cmd); ++b) if (isspace(cmd[b])) cmd[b]=0;
+               addurls(&cmd[a+1]);
+               cmd[a] = 0;
+               }
+
        if (!strncasecmp(cmd, "GET /static/", 12)) {
                strcpy(buf, &cmd[12]);
                for (a=0; a<strlen(buf); ++a) if (isspace(buf[a])) buf[a]=0;
                output_static(buf);
                }
 
+       else if ((!logged_in)&&(!strncasecmp(cmd, "POST /login", 11))) {
+               do_login();
+               }
+
        else if (!logged_in) {
                display_login_page();
                }
@@ -278,6 +388,7 @@ void session_loop() {
                free(content);
                content = NULL;
                }
+       free_urls();
        }
 
 
index a140e50586ae1bf9308932fe115c67e4f26544ca..0402eed737dc4c31e87f68c512b779dbbe5f5145 100644 (file)
@@ -21,4 +21,11 @@ struct webcontent {
        char w_data[256];
        };
 
+struct urlcontent {
+       struct urlcontent *next;
+       char url_key[32];
+       char *url_data;
+       };
+
 void serv_printf(const char *format, ...);
+char *bstr();