we still have a problem
[citadel.git] / webcit / auth.c
1 /*
2  * auth.c
3  *
4  * This file contains code which relates to authentication of users to Citadel.
5  *
6  */
7
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <ctype.h>
12 #include <string.h>
13 #include <errno.h>
14 #include "webcit.h"
15
16 void display_login_page() {
17         
18         printf("HTTP/1.0 200 OK\n");
19         output_headers();
20
21         wprintf("<HTML><HEAD><TITLE>Please log in</TITLE></HEAD><BODY>\n");
22         wprintf("<TABLE border=0><TR><TD>\n");
23         wprintf("<IMG SRC=\"/static/velma.gif\">\n");   
24         wprintf("</TD><TD>");
25         wprintf("<H1>&quot;Velma&quot;</H1><H2>(next generation WebCit)</H2>");
26         wprintf("Please log in...<BR>\n");
27
28
29         wprintf("<FORM ACTION=\"/login\" METHOD=\"POST\">\n");
30         wprintf("<TABLE border><TR><TD>");
31         wprintf("User Name:</TD><TD><INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"25\"   >\n");
32         wprintf("</TD></TR><TD>");
33         wprintf("Password:</TD><TD><INPUT TYPE=\"password\" NAME=\"pass\" MAXLENGTH=\"20\">");
34         wprintf("</TD></TR></TABLE>\n");
35         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Login\">\n");
36         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"New User\">\n");
37         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Exit\">\n");
38         wprintf("</FORM>\n");
39
40         wprintf("</TD></TR></TABLE>\n");
41         wprintf("</BODY></HTML>\n");
42
43         wDumpContent();
44         }
45
46
47
48
49 void output_frameset() {
50         printf("HTTP/1.0 200 OK\n");
51         output_headers();
52
53         wprintf("<HTML><HEAD><TITLE>FrameSet</TITLE></HEAD>\n");
54         wprintf("<FRAMESET cols=\"15%, 80%\">\n");
55         wprintf("  <FRAME name=\"left\" src=\"/static/velma.gif\">\n");
56         wprintf("  <FRAME name=\"right\" src=\"/display_main_menu\">\n");
57         wprintf("<NOFRAMES>\n");
58         wprintf("Your browser doesn't support frames.<BR>\n");
59         wprintf("This site uses frames.<BR>\n");
60         wprintf("Therefore, you cannot view this site.<BR>\n");
61         wprintf("Perhaps you should telnet instead?<BR>\n");
62         wprintf("</NOFRAMES>\n");
63         wprintf("</FRAMESET></HTML>\n");
64         wDumpContent();
65         }
66
67
68 /*
69  * This function needs to get called whenever a PASS or NEWU succeeds
70  */
71 void become_logged_in(char *user, char *pass, char *serv_response) {
72
73         logged_in = 1;
74         strcpy(wc_username, user);
75         strcpy(wc_password, pass);
76         
77         }
78
79
80 void do_login() {
81         char buf[256];
82
83         if (!strcasecmp(bstr("action"), "Login")) {
84                 serv_printf("USER %s", bstr("name"));
85                 serv_gets(buf);
86                 if (buf[0]=='3') {
87                         serv_printf("PASS %s", bstr("pass"));
88                         serv_gets(buf);
89                         if (buf[0]=='2') {
90                                 become_logged_in(bstr("name"), bstr("pass"), buf);
91                                 }
92                         }
93                 }
94
95         if (logged_in) {
96                 output_frameset();
97                 }
98         else {
99                 printf("HTTP/1.0 200 OK\n");
100                 output_headers();
101                 wprintf("<HTML><HEAD><TITLE>Nope</TITLE></HEAD><BODY>\n");
102                 wprintf("Your password was not accepted.\n");
103                 wprintf("<HR><A HREF=\"/\">Try again</A>\n");
104                 wprintf("</BODY></HTML>\n");
105                 wDumpContent();
106                 }
107
108         }