]> code.citadel.org Git - citadel.git/blob - webcit/auth.c
added new "action" variable to make main loop simpler
[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  * $Id$
7  */
8
9 #include <stdlib.h>
10 #ifdef HAVE_UNISTD_H
11 #include <unistd.h>
12 #endif
13 #include <stdio.h>
14 #include <ctype.h>
15 #include <string.h>
16 #include <errno.h>
17 #include "webcit.h"
18 #include "child.h"
19
20
21
22 /*
23  * Display the login screen
24  */
25 void display_login(void) {
26         char buf[256];
27
28         printf("HTTP/1.0 200 OK\n");
29         output_headers();
30
31         wprintf("<HTML><BODY>\n");
32         wprintf("<CENTER><TABLE border=0><TR><TD>\n");
33
34         /* FIX replace with the correct image */
35         wprintf("<IMG SRC=\"/static/velma.gif\">");
36         wprintf("</TD><TD><CENTER>\n");
37
38         serv_puts("MESG hello");
39         serv_gets(buf);
40         if (buf[0]=='1') fmout(NULL);
41
42         wprintf("</CENTER></TD></TR></TABLE></CENTER>\n");
43
44         wprintf("<HR>\n");
45         /* FIX add instructions here */
46         wprintf("<CENTER><FORM ACTION=\"/login\" METHOD=\"POST\">\n");
47         wprintf("<TABLE border><TR>\n");
48         wprintf("<TD>User Name:</TD>\n");
49         wprintf("<TD><INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"25\">\n");
50         wprintf("</TD></TR><TR>\n");
51         wprintf("<TD>Password:</TD>\n");
52         wprintf("<TD><INPUT TYPE=\"password\" NAME=\"pass\" MAXLENGTH=\"20\"></TD>\n");
53         wprintf("</TR></TABLE>\n");
54         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Login\">\n");
55         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"New User\">\n");
56         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Exit\">\n");
57         wprintf("</FORM></CENTER>\n");
58         wprintf("</BODY></HTML>\n");
59         wDumpContent();
60         }
61
62
63
64
65 /*
66  * This function needs to get called whenever a PASS or NEWU succeeds
67  */
68 void become_logged_in(char *user, char *pass, char *serv_response) {
69         logged_in = 1;
70         extract(wc_username, &serv_response[4], 0);
71         strcpy(wc_password, pass);
72         axlevel = extract_int(&serv_response[4], 1);
73         if (axlevel >=6) is_aide = 1;
74         }
75
76
77 void do_login(void) {
78         char buf[256];
79
80         fprintf(stderr, "do_login() called\n");
81         if (!strcasecmp(bstr("action"), "Login")) {
82                 serv_printf("USER %s", bstr("name"));
83                 serv_gets(buf);
84                 if (buf[0]=='3') {
85                         serv_printf("PASS %s", bstr("pass"));
86                         serv_gets(buf);
87                         if (buf[0]=='2') {
88                                 become_logged_in(bstr("name"),
89                                         bstr("pass"), buf);
90                                 }
91                         }
92                 }
93
94         fprintf(stderr, "logged_in==%d\n", logged_in);
95
96         if (logged_in) {
97                 output_static("frameset.html");
98                 }
99         else {
100                 printf("HTTP/1.0 200 OK\n");
101                 output_headers();
102                 wprintf("<HTML><HEAD><TITLE>Nope</TITLE></HEAD><BODY>\n");
103                 wprintf("Your password was not accepted.\n");
104                 wprintf("<HR><A HREF=\"/\">Try again</A>\n");
105                 wprintf("</BODY></HTML>\n");
106                 wDumpContent();
107                 }
108
109         }
110
111 void do_welcome(void) {
112         printf("HTTP/1.0 200 OK\n");
113         output_headers();
114         wprintf("<HTML><BODY>\n");
115         wprintf("<CENTER><H1>");
116         escputs(wc_username);
117         wprintf("</H1>\n");
118         /* other stuff here */
119         wprintf("</BODY></HTML>\n");
120         wDumpContent();
121         }
122
123
124 void do_logout(void) {
125         char buf[256];
126
127         strcpy(wc_username, "");
128         strcpy(wc_password, "");
129         strcpy(wc_roomname, "");
130         strcpy(wc_host, "");
131         strcpy(wc_port, "");
132
133         printf("HTTP/1.0 200 OK\n");
134         output_headers();
135         printf("X-WebCit-Session: close\n");
136         
137         wprintf("<HTML><HEAD><TITLE>Goodbye</TITLE></HEAD><BODY><CENTER>\n");
138
139         serv_puts("MESG goodbye");
140         serv_gets(buf);
141
142         if (buf[0]=='1') fmout(NULL);
143         else wprintf("Goodbye\n");
144
145         wprintf("</CENTER></BODY></HTML>\n");
146         wDumpContent();
147         serv_puts("QUIT");
148         exit(0);
149         }