1 /*
2 * $Id: command.c,v 1.2.2.11 2010/01/10 00:18:10 tomcollins Exp $
3 * Copyright (C) 1999-2004 Inter7 Internet Technologies, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
18 */
19
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <unistd.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26 #include <pwd.h>
27 #include <dirent.h>
28
29 #include <vpopmail_config.h>
30 #include <vpopmail.h>
31 #include <vauth.h>
32
33 #include "config.h"
34 #include "alias.h"
35 #include "autorespond.h"
36 #include "cgi.h"
37 #include "command.h"
38 #include "forward.h"
39 #include "mailinglist.h"
40 #include "printh.h"
41 #include "qmailadmin.h"
42 #include "qmailadminx.h"
43 #include "show.h"
44 #include "user.h"
45 #include "util.h"
46
process_commands()47 void process_commands()
48 {
49 if (strcmp(TmpBuf2, "showmenu") == 0 ) {
50 show_menu(Username, Domain, Mytime);
51
52 } else if (strcmp(TmpBuf2, "quick") == 0) {
53 /* This feature sponsored by PinkRoccade Public Sector, Sept 2004 */
54
55 char moddel[20];
56 /* we use global ActionUser here because the functions that
57 * quickAction calls expect the username in that global.
58 */
59 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
60 lowerit (ActionUser); /* convert username to lower case */
61 GetValue(TmpCGI, moddel, "MODIFY=", sizeof(moddel));
62 if (*moddel) {
63 quickAction (ActionUser, ACTION_MODIFY);
64 } else {
65 GetValue(TmpCGI, moddel, "DELETE=", sizeof(moddel));
66 if (*moddel) {
67 quickAction (ActionUser, ACTION_DELETE);
68 } else {
69 /* malformed request -- missing fields */
70 show_menu(Username, Domain, Mytime);
71 vclose();
72 exit(0);
73 }
74 }
75
76 } else if (strcmp(TmpBuf2, "showusers") == 0) {
77 GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber));
78 GetValue(TmpCGI, SearchUser, "searchuser=", sizeof(SearchUser));
79 show_users(Username, Domain, Mytime);
80
81 } else if (strcmp(TmpBuf2, "showaliases") == 0) {
82 GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber));
83 show_aliases();
84
85 } else if (strcmp(TmpBuf2, "showforwards") == 0) {
86 GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber));
87 GetValue(TmpCGI, SearchUser, "searchuser=", sizeof(SearchUser));
88 show_forwards(Username, Domain, Mytime);
89
90 } else if (strcmp(TmpBuf2, "showmailinglists") == 0) {
91 show_mailing_lists(Username, Domain, Mytime);
92
93 } else if (strcmp(TmpBuf2, "showautoresponders") == 0) {
94 show_autoresponders(Username, Domain, Mytime);
95
96 } else if (strcmp(TmpBuf2, "adduser") == 0 ) {
97 adduser();
98
99 } else if (strcmp(TmpBuf2, "addusernow") == 0 ) {
100 addusernow();
101
102 #ifdef CATCHALL_ENABLED
103 } else if (strcmp(TmpBuf2, "setdefault") == 0 ) {
104 GetValue(TmpCGI, ActionUser, "deluser=", sizeof(ActionUser));
105 GetValue(TmpCGI, Pagenumber, "page=", sizeof(Pagenumber));
106 setdefaultaccount();
107
108 } else if (strcmp(TmpBuf2, "bounceall") == 0 ) {
109 bounceall();
110
111 } else if (strcmp(TmpBuf2, "deleteall") == 0 ) {
112 deleteall();
113
114 } else if (strcmp(TmpBuf2, "setremotecatchall") == 0 ) {
115 setremotecatchall();
116
117 } else if (strcmp(TmpBuf2, "setremotecatchallnow") == 0 ) {
118 setremotecatchallnow();
119 #endif
120
121 } else if (strcmp(TmpBuf2, "addlistmodnow") == 0 ) {
122 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
123 GetValue(TmpCGI, Newu, "newu=", sizeof(Newu));
124 addlistgroupnow(1);
125
126 } else if (strcmp(TmpBuf2, "dellistmod") == 0 ) {
127 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
128 dellistgroup("del_listmod.html");
129
130 } else if (strcmp(TmpBuf2, "dellistmodnow") == 0 ) {
131 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
132 GetValue(TmpCGI, Newu, "newu=", sizeof(Newu));
133 dellistgroupnow(1);
134
135 } else if (strcmp(TmpBuf2, "addlistmod") == 0 ) {
136 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
137 addlistgroup("add_listmod.html");
138
139 } else if (strcmp(TmpBuf2, "showlistmod") == 0 ) {
140 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
141 show_list_group("show_moderators.html");
142
143 } else if (strcmp(TmpBuf2, "addlistdig") == 0 ) {
144 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
145 addlistgroup("add_listdig.html");
146
147 } else if (strcmp(TmpBuf2, "addlistdignow") == 0 ) {
148 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
149 GetValue(TmpCGI, Newu, "newu=", sizeof(Newu));
150 addlistgroupnow(2);
151
152 } else if (strcmp(TmpBuf2, "dellistdig") == 0 ) {
153 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
154 dellistgroup("del_listdig.html");
155
156 } else if (strcmp(TmpBuf2, "dellistdignow") == 0 ) {
157 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
158 GetValue(TmpCGI, Newu, "newu=", sizeof(Newu));
159 dellistgroupnow(2);
160
161 } else if (strcmp(TmpBuf2, "showlistdig") == 0 ) {
162 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
163 show_list_group("show_digest_subscribers.html");
164
165 } else if (strcmp(TmpBuf2, "moduser") == 0 ) {
166 GetValue(TmpCGI, ActionUser, "moduser=", sizeof(ActionUser));
167 moduser();
168
169 } else if (strcmp(TmpBuf2, "modusernow") == 0 ) {
170 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
171 GetValue(TmpCGI, Password1, "password1=", sizeof(Password1));
172 GetValue(TmpCGI, Password2, "password2=", sizeof(Password2));
173 GetValue(TmpCGI, Gecos, "gecos=", sizeof(Gecos));
174 modusergo();
175
176 } else if (strcmp(TmpBuf2, "deluser") == 0 ) {
177 GetValue(TmpCGI, ActionUser, "deluser=", sizeof(ActionUser));
178 deluser();
179
180 } else if (strcmp(TmpBuf2, "delusernow") == 0 ) {
181 GetValue(TmpCGI, ActionUser, "deluser=", sizeof(ActionUser));
182 delusergo();
183
184 } else if (strcmp(TmpBuf2, "moddotqmail") == 0 ) {
185 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
186 moddotqmail();
187
188 } else if (strcmp(TmpBuf2, "moddotqmailnow") == 0 ) {
189 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
190 GetValue(TmpCGI, Newu, "newu=", sizeof(Newu));
191 GetValue(TmpCGI, LineData, "linedata=", sizeof(LineData));
192 GetValue(TmpCGI, Action, "action=", sizeof(Action));
193 moddotqmailnow();
194
195 } else if (strcmp(TmpBuf2, "deldotqmail") == 0 ) {
196 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
197 deldotqmail();
198
199 } else if (strcmp(TmpBuf2, "deldotqmailnow") == 0 ) {
200 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
201 deldotqmailnow();
202
203 } else if (strcmp(TmpBuf2, "adddotqmail") == 0 ) {
204 adddotqmail();
205
206 } else if (strcmp(TmpBuf2, "adddotqmailnow") == 0 ) {
207 GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser));
208 GetValue(TmpCGI, Alias, "alias=", sizeof(Alias));
209 adddotqmailnow();
210
211 } else if (strcmp(TmpBuf2, "addmailinglist") == 0 ) {
212 addmailinglist();
213
214 } else if (strcmp(TmpBuf2, "delmailinglist") == 0 ) {
215 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
216 delmailinglist();
217
218 } else if (strcmp(TmpBuf2, "delmailinglistnow") == 0 ) {
219 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
220 delmailinglistnow();
221
222 } else if (strcmp(TmpBuf2, "addlistusernow") == 0 ) {
223 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
224 GetValue(TmpCGI, Newu, "newu=", sizeof(Newu));
225 addlistgroupnow(0);
226
227 } else if (strcmp(TmpBuf2, "dellistuser") == 0 ) {
228 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
229 dellistgroup("del_listuser.html");
230
231 } else if (strcmp(TmpBuf2, "dellistusernow") == 0 ) {
232 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
233 GetValue(TmpCGI, Newu, "newu=", sizeof(Newu));
234 dellistgroupnow(0);
235
236 } else if (strcmp(TmpBuf2, "addlistuser") == 0 ) {
237 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
238 addlistgroup("add_listuser.html");
239
240 } else if (strcmp(TmpBuf2, "addmailinglistnow") == 0 ) {
241 GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser));
242 addmailinglistnow();
243
244 } else if (strcmp(TmpBuf2, "modmailinglist") == 0 ) {
245 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
246 modmailinglist();
247
248 } else if (strcmp(TmpBuf2, "modmailinglistnow") == 0 ) {
249 GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser));
250 modmailinglistnow();
251
252 } else if (strcmp(TmpBuf2, "modautorespond") == 0 ) {
253 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
254 modautorespond();
255
256 } else if (strcmp(TmpBuf2, "addautorespond") == 0 ) {
257 addautorespond();
258
259 } else if (strcmp(TmpBuf2, "addautorespondnow") == 0 ) {
260 GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser));
261 GetValue(TmpCGI, Alias, "alias=", sizeof(Alias));
262 GetValue(TmpCGI, Message, "message=", sizeof(Message));
263 GetValue(TmpCGI, Newu, "owner=", sizeof(Newu));
264 addautorespondnow();
265
266 } else if (strcmp(TmpBuf2, "modautorespondnow") == 0 ) {
267 GetValue(TmpCGI, ActionUser, "newu=", sizeof(ActionUser));
268 GetValue(TmpCGI, Alias, "alias=", sizeof(Alias));
269 GetValue(TmpCGI, Message, "message=", sizeof(Message));
270 GetValue(TmpCGI, Newu, "owner=", sizeof(Newu));
271 modautorespondnow();
272
273 } else if (strcmp(TmpBuf2, "showlistusers") == 0 ) {
274 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
275 show_list_group("show_subscribers.html");
276
277 } else if (strcmp(TmpBuf2, "delautorespond") == 0 ) {
278 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
279 delautorespond();
280
281 } else if (strcmp(TmpBuf2, "delautorespondnow") == 0 ) {
282 GetValue(TmpCGI, ActionUser, "modu=", sizeof(ActionUser));
283 delautorespondnow();
284
285 } else if (strcmp(TmpBuf2, "logout") == 0 ) {
286 sprintf(TmpBuf, "%s/%s/" MAILDIR, RealDir, Username );
287 del_id_files(TmpBuf);
288 show_login();
289
290 } else if (strcmp(TmpBuf2, "showcounts") == 0 ) {
291 show_counts();
292 }
293
294 vclose();
295 exit(0);
296 }
297
setdefaultaccount()298 void setdefaultaccount()
299 {
300 struct vqpasswd *pw;
301 FILE *fs;
302
303 if ((pw = vauth_getpw( ActionUser, Domain )) == NULL) {
304 snprinth (StatusMessage, sizeof(StatusMessage), "%s %H@%H",
305 html_text[223], ActionUser, Domain);
306 } else {
307 if ( (fs = fopen(".qmail-default", "w")) == NULL ) {
308 snprintf (StatusMessage, sizeof(StatusMessage), "%s", html_text[82]);
309 } else {
310 fprintf(fs, "| %s/bin/vdelivermail '' %s@%s\n", VPOPMAILDIR, ActionUser, Domain);
311 fclose(fs);
312 #ifdef ONCHANGE_SCRIPT
313 snprintf ( onchange_buf , MAX_BUFF , "%s@%s" , ActionUser , Domain ) ;
314 call_onchange ( "setdefault" ) ;
315 #endif
316 }
317 }
318 show_users(Username, Domain, Mytime);
319 vclose();
320 exit(0);
321 }
322