]> code.citadel.org Git - citadel.git/blob - webcit/useredit.c
* More edit user stuff
[citadel.git] / webcit / useredit.c
1 /*
2  * Administrative screen to add/change/delete user accounts
3  *
4  */
5
6
7 #include <ctype.h>
8 #include <stdlib.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <fcntl.h>
12 #include <signal.h>
13 #include <sys/types.h>
14 #include <sys/wait.h>
15 #include <sys/socket.h>
16 #include <sys/time.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include "webcit.h"
27
28
29
30
31
32 void select_user_to_edit(char *message)
33 {
34         char buf[SIZ];
35         char username[SIZ];
36
37         output_headers(3);      /* No room banner on this screen */
38
39         if (message != NULL) wprintf(message);
40
41         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
42         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
43                 "Add/change/delete user accounts"
44                 "</B></FONT></TD></TR></TABLE>\n");
45
46         wprintf("<TABLE border=0 CELLSPACING=10><TR VALIGN=TOP>"
47                 "<TD>To edit an existing user account, select the user "
48                 "name from the list and click 'Edit'.<BR><BR>");
49         
50         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/display_edituser\">\n");
51         wprintf("<SELECT NAME=\"username\" SIZE=10>\n");
52         serv_puts("LIST");
53         serv_gets(buf);
54         if (buf[0] == '1') {
55                 while (serv_gets(buf), strcmp(buf, "000")) {
56                         extract(username, buf, 0);
57                         wprintf("<OPTION>");
58                         escputs(username);
59                         wprintf("\n");
60                 }
61         }
62         wprintf("</SELECT><BR>\n");
63
64         wprintf("<input type=submit name=sc value=\"Edit\">");
65         wprintf("</FORM></CENTER>\n");
66
67         wprintf("</TD><TD>"
68                 "To create a new user account, enter the desired "
69                 "user name in the box below and click 'Create'.<BR><BR>");
70
71         wprintf("<CENTER><FORM METHOD=\"POST\" ACTION=\"/create_user\">\n");
72         wprintf("New user: ");
73         wprintf("<input type=text name=username><BR>\n"
74                 "<input type=submit value=\"Create\">"
75                 "</FORM></CENTER>\n");
76
77         wprintf("</TD></TR></TABLE>\n");
78
79         wDumpContent(1);
80 }
81
82
83
84 /*
85  * Edit a user.  If supplied_username is null, look in the "username"
86  * web variable for the name of the user to edit.
87  */
88 void display_edituser(char *supplied_username) {
89         char username[SIZ];
90         char buf[SIZ];
91         char error_message[SIZ];
92
93         if (supplied_username != NULL) {
94                 strcpy(username, supplied_username);
95         }
96         else {
97                 strcpy(username, bstr("username") );
98         }
99
100         serv_printf("AGUP %s", username);
101         serv_gets(buf);
102         if (buf[0] != '2') {
103                 sprintf(error_message,
104                         "<IMG SRC=\"static/error.gif\" VALIGN=CENTER>"
105                         "%s<BR><BR>\n", &buf[4]);
106                 select_user_to_edit(error_message);
107                 return;
108         }
109
110         output_headers(3);      /* No room banner on this screen */
111
112         wprintf("this is %s", username);
113
114         wDumpContent(1);
115
116 }
117
118
119
120 void create_user(void) {
121         char buf[SIZ];
122         char username[SIZ];
123         char error_message[SIZ];
124
125         strcpy(username, bstr("username"));
126
127         serv_printf("CREU %s", username);
128         serv_gets(buf);
129
130         if (buf[0] == '2') {
131                 display_edituser(username);
132         }
133         else {
134                 sprintf(error_message,
135                         "<IMG SRC=\"static/error.gif\" VALIGN=CENTER>"
136                         "%s<BR><BR>\n", &buf[4]);
137                 select_user_to_edit(error_message);
138                 return;
139         }
140
141         output_headers(3);
142
143         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
144         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"<B>"
145                 "Edit user account: ");
146         escputs(username);
147         wprintf("</B></FONT></TD></TR></TABLE>\n");
148
149         wDumpContent(1);
150
151 }