]> code.citadel.org Git - citadel.git/blob - webcit/auth.c
Set up an option in output_headers() to optionally print the most
[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         fprintf(stderr, "become_logged_in(%s,%s)\n", user, pass);
92         }
93
94
95 void do_login(void) {
96         char buf[256];
97
98         if (!strcasecmp(bstr("action"), "Exit")) {
99                 do_logout();
100                 }
101
102         if (!strcasecmp(bstr("action"), "Login")) {
103                 serv_printf("USER %s", bstr("name"));
104                 serv_gets(buf);
105                 if (buf[0]=='3') {
106                         serv_printf("PASS %s", bstr("pass"));
107                         serv_gets(buf);
108                         if (buf[0]=='2') {
109                                 become_logged_in(bstr("name"),
110                                         bstr("pass"), buf);
111                                 }
112                         else {
113                                 display_login(&buf[4]);
114                                 return;
115                                 }
116                         }
117                 else {
118                         display_login(&buf[4]);
119                         return;
120                         }
121                 }
122
123         if (!strcasecmp(bstr("action"), "New User")) {
124                 serv_printf("NEWU %s", bstr("name"));
125                 serv_gets(buf);
126                 if (buf[0]=='2') {
127                         become_logged_in(bstr("name"), bstr("pass"), buf);
128                         serv_printf("SETP %s", bstr("pass"));
129                         serv_gets(buf);
130                         }
131                 else {
132                         display_login(&buf[4]);
133                         return;
134                         }
135                 }
136
137         if (logged_in) {
138                 output_static("frameset.html");
139                 }
140         else {
141                 display_login("Your password was not accepted.");
142                 }
143
144         }
145
146 void do_welcome(void) {
147         printf("HTTP/1.0 200 OK\n");
148         output_headers(1);
149         wprintf("<CENTER><H1>");
150         escputs(wc_username);
151         wprintf("</H1>\n");
152         /* FIX add user stats here */
153
154         wprintf("<HR>");
155         /* FIX  ---  what should we put here?  the main menu,
156          * or new messages in the lobby?
157          */
158         embed_main_menu();
159
160         wprintf("</BODY></HTML>\n");
161         wDumpContent();
162         }
163
164
165 void do_logout(void) {
166         char buf[256];
167
168         strcpy(wc_username, "");
169         strcpy(wc_password, "");
170         strcpy(wc_roomname, "");
171         strcpy(wc_host, "");
172         strcpy(wc_port, "");
173
174         printf("HTTP/1.0 200 OK\n");
175         printf("X-WebCit-Session: close\n");
176         output_headers(1);
177
178         wprintf("<CENTER>");    
179         serv_puts("MESG goodbye");
180         serv_gets(buf);
181
182         if (buf[0]=='1') fmout(NULL);
183         else wprintf("Goodbye\n");
184
185         wprintf("<HR><A HREF=\"/\">Log in again</A>\n");
186
187         wprintf("</CENTER></BODY></HTML>\n");
188         wDumpContent();
189         serv_puts("QUIT");
190         exit(0);
191         }