]> code.citadel.org Git - citadel.git/blob - webcit/auth.c
portability enhancements
[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         if (!strcasecmp(bstr("action"), "Login")) {
81                 serv_printf("USER %s", bstr("name"));
82                 serv_gets(buf);
83                 if (buf[0]=='3') {
84                         serv_printf("PASS %s", bstr("pass"));
85                         serv_gets(buf);
86                         if (buf[0]=='2') {
87                                 become_logged_in(bstr("name"),
88                                         bstr("pass"), buf);
89                                 }
90                         }
91                 }
92
93         if (logged_in) {
94                 output_static("frameset.html");
95                 }
96         else {
97                 printf("HTTP/1.0 200 OK\n");
98                 output_headers();
99                 wprintf("<HTML><HEAD><TITLE>Nope</TITLE></HEAD><BODY>\n");
100                 wprintf("Your password was not accepted.\n");
101                 wprintf("<HR><A HREF=\"/\">Try again</A>\n");
102                 wprintf("</BODY></HTML>\n");
103                 wDumpContent();
104                 }
105
106         }
107
108 void do_welcome(void) {
109         printf("HTTP/1.0 200 OK\n");
110         output_headers();
111         wprintf("<HTML><BODY>\n");
112         wprintf("<CENTER><H1>");
113         escputs(wc_username);
114         wprintf("</H1>\n");
115         /* other stuff here */
116         wprintf("</BODY></HTML>\n");
117         wDumpContent();
118         }
119
120
121 void do_logout(void) {
122         char buf[256];
123
124         strcpy(wc_username, "");
125         strcpy(wc_password, "");
126         strcpy(wc_roomname, "");
127         strcpy(wc_host, "");
128         strcpy(wc_port, "");
129
130         printf("HTTP/1.0 200 OK\n");
131         output_headers();
132         printf("X-WebCit-Session: close\n");
133         
134         wprintf("<HTML><HEAD><TITLE>Goodbye</TITLE></HEAD><BODY><CENTER>\n");
135
136         serv_puts("MESG goodbye");
137         serv_gets(buf);
138
139         if (buf[0]=='1') fmout(NULL);
140         else wprintf("Goodbye\n");
141
142         wprintf("</CENTER></BODY></HTML>\n");
143         wDumpContent();
144         serv_puts("QUIT");
145         exit(0);
146         }