]> code.citadel.org Git - citadel.git/blob - webcit/auth.c
* Fixed a bug in the room banner display code
[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(char *mesg) {
26         char buf[256];
27
28         printf("HTTP/1.0 200 OK\n");
29         output_headers(1);
30
31         /* Da banner */
32         wprintf("<CENTER><TABLE border=0 width=100%><TR><TD>\n");
33         wprintf("<IMG SRC=\"/image&name=hello\">");
34         wprintf("</TD><TD><CENTER>\n");
35
36         if (mesg != NULL) {
37                 wprintf("<font size=+1><b>%s</b></font>", mesg);
38                 }
39         else {
40                 serv_puts("MESG hello");
41                 serv_gets(buf);
42                 if (buf[0]=='1') fmout(NULL);
43                 }
44
45         wprintf("</CENTER></TD></TR></TABLE></CENTER>\n");
46         wprintf("<HR>\n");
47
48         /* Da login box */
49         wprintf("<CENTER><FORM ACTION=\"/login\" METHOD=\"POST\">\n");
50         wprintf("<TABLE border><TR>\n");
51         wprintf("<TD>User Name:</TD>\n");
52         wprintf("<TD><INPUT TYPE=\"text\" NAME=\"name\" MAXLENGTH=\"25\">\n");
53         wprintf("</TD></TR><TR>\n");
54         wprintf("<TD>Password:</TD>\n");
55         wprintf("<TD><INPUT TYPE=\"password\" NAME=\"pass\" MAXLENGTH=\"20\"></TD>\n");
56         wprintf("</TR></TABLE>\n");
57         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Login\">\n");
58         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"New User\">\n");
59         wprintf("<INPUT type=\"submit\" NAME=\"action\" VALUE=\"Exit\">\n");
60         wprintf("</FORM></CENTER>\n");
61
62         /* Da instructions */
63         wprintf("<LI><EM>If you already have an account on %s,",
64                 serv_info.serv_humannode);
65         wprintf("</EM> enter your user name\n");
66         wprintf("and password and click \"<TT>Login</TT>.\"<BR>\n");
67         wprintf("<LI><EM>If you are a new user,</EM>\n");
68         wprintf("enter the name and password you wish to use, and click\n");
69         wprintf("\"New User.\"<BR><LI>");
70         wprintf("<EM>Please log off properly when finished.</EM>");
71         wprintf("<LI>You must use a browser that supports <i>frames</i> ");
72         wprintf("and <i>cookies</i>.\n");
73         wprintf("</EM></UL>\n");
74
75         wprintf("</BODY></HTML>\n");
76         wDumpContent();
77         }
78
79
80
81
82 /*
83  * This function needs to get called whenever a PASS or NEWU succeeds
84  */
85 void become_logged_in(char *user, char *pass, char *serv_response) {
86         logged_in = 1;
87         extract(wc_username, &serv_response[4], 0);
88         strcpy(wc_password, pass);
89         axlevel = extract_int(&serv_response[4], 1);
90         if (axlevel >=6) is_aide = 1;
91         }
92
93
94 void do_login(void) {
95         char buf[256];
96
97         if (!strcasecmp(bstr("action"), "Exit")) {
98                 do_logout();
99                 }
100
101         if (!strcasecmp(bstr("action"), "Login")) {
102                 serv_printf("USER %s", bstr("name"));
103                 serv_gets(buf);
104                 if (buf[0]=='3') {
105                         serv_printf("PASS %s", bstr("pass"));
106                         serv_gets(buf);
107                         if (buf[0]=='2') {
108                                 become_logged_in(bstr("name"),
109                                         bstr("pass"), buf);
110                                 }
111                         else {
112                                 display_login(&buf[4]);
113                                 return;
114                                 }
115                         }
116                 else {
117                         display_login(&buf[4]);
118                         return;
119                         }
120                 }
121
122         if (!strcasecmp(bstr("action"), "New User")) {
123                 serv_printf("NEWU %s", bstr("name"));
124                 serv_gets(buf);
125                 if (buf[0]=='2') {
126                         become_logged_in(bstr("name"), bstr("pass"), buf);
127                         serv_printf("SETP %s", bstr("pass"));
128                         serv_gets(buf);
129                         }
130                 else {
131                         display_login(&buf[4]);
132                         return;
133                         }
134                 }
135
136         if (logged_in) {
137                 output_static("frameset.html");
138                 }
139         else {
140                 display_login("Your password was not accepted.");
141                 }
142
143         }
144
145 void do_welcome(void) {
146         printf("HTTP/1.0 200 OK\n");
147         output_headers(1);
148         wprintf("<CENTER><H1>");
149         escputs(wc_username);
150         wprintf("</H1>\n");
151         /* FIX add user stats here */
152
153         wprintf("<HR>");
154         /* FIX  ---  what should we put here?  the main menu,
155          * or new messages in the lobby?
156          */
157         embed_main_menu();
158
159         wprintf("</BODY></HTML>\n");
160         wDumpContent();
161         }
162
163
164 void do_logout(void) {
165         char buf[256];
166
167         strcpy(wc_username, "");
168         strcpy(wc_password, "");
169         strcpy(wc_roomname, "");
170         strcpy(wc_host, "");
171         strcpy(wc_port, "");
172
173         printf("HTTP/1.0 200 OK\n");
174         printf("X-WebCit-Session: close\n");
175         output_headers(1);
176
177         wprintf("<CENTER>");    
178         serv_puts("MESG goodbye");
179         serv_gets(buf);
180
181         if (buf[0]=='1') fmout(NULL);
182         else wprintf("Goodbye\n");
183
184         wprintf("<HR><A HREF=\"/\">Log in again</A>\n");
185
186         wprintf("</CENTER></BODY></HTML>\n");
187         wDumpContent();
188         serv_puts("QUIT");
189         exit(0);
190         }