From 03cf178811e60606be2f2a9b4bd3f8d28784bb44 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 25 Nov 1998 19:03:09 +0000 Subject: [PATCH] completed part of the login procedure added the frameset --- webcit/auth.c | 50 +++++++++++++++++++ webcit/tcp_sockets.c | 18 ++++--- webcit/webcit.c | 115 ++++++++++++++++++++++++++++++++++++++++++- webcit/webcit.h | 7 +++ 4 files changed, 182 insertions(+), 8 deletions(-) diff --git a/webcit/auth.c b/webcit/auth.c index 0129f2d82..4da4ddd35 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -42,3 +42,53 @@ void display_login_page() { wDumpContent(); } + + + + +void output_frameset() { + printf("HTTP/1.0 200 OK\n"); + output_headers(); + + wprintf("FrameSet\n"); + wprintf("\n"); + wprintf(" \n"); + wprintf(" \n"); + wprintf("\n"); + wprintf("ooo! no frames! too bad!\n"); + wprintf("\n"); + wprintf("\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("Nope\n"); + wprintf("Your password was not accepted.\n"); + wprintf("
Try again\n"); + wprintf("\n"); + } + + wDumpContent(); + } diff --git a/webcit/tcp_sockets.c b/webcit/tcp_sockets.c index a26023555..c121c3bd4 100644 --- a/webcit/tcp_sockets.c +++ b/webcit/tcp_sockets.c @@ -121,9 +121,11 @@ int bytes; { while(len%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); } diff --git a/webcit/webcit.c b/webcit/webcit.c index a79d70dcf..946b2ab85 100644 --- a/webcit/webcit.c +++ b/webcit/webcit.c @@ -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; a0) { + + /* 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; aurl_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