|
0
|
1 |
// Copyright (C) 1999,2000 Bruce Guenter <bruceg@em.ca>
|
|
|
2 |
//
|
|
|
3 |
// This program is free software; you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation; either version 2 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// This program is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with this program; if not, write to the Free Software
|
|
|
15 |
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
16 |
|
|
|
17 |
#include <config.h>
|
|
|
18 |
#include "cgi/cgi-base.h"
|
|
|
19 |
#include "misc/server.h"
|
|
|
20 |
#include "vdomain/vdomain.h"
|
|
|
21 |
#include "misc/itoa.h"
|
|
|
22 |
|
|
|
23 |
CGI_MAIN
|
|
|
24 |
{
|
|
|
25 |
CGI_INPUT(username);
|
|
|
26 |
CGI_INPUT(destination);
|
|
|
27 |
CGI_OPTINPUT(enable);
|
|
|
28 |
|
|
|
29 |
bool do_disable = (!!enable) && enable == "0";
|
|
|
30 |
bool do_enable = (!!enable) && enable != "0";
|
|
|
31 |
|
|
|
32 |
username = username.lower();
|
|
|
33 |
|
|
|
34 |
// Enable the account *BEFORE* changing the destination
|
|
|
35 |
if(do_enable) {
|
|
|
36 |
response resp = server_call("chattr", vdomain, username, password,
|
|
|
37 |
itoa(vdomain::ATTR_MAILBOX_ENABLED),
|
|
|
38 |
enable).call();
|
|
|
39 |
if(!resp)
|
|
|
40 |
error(resp.msg);
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
unsigned dests = destination.count(',') + 1;
|
|
|
44 |
|
|
|
45 |
server_call call("chattr", dests + 4);
|
|
|
46 |
call.operand(0, vdomain);
|
|
|
47 |
call.operand(1, username);
|
|
|
48 |
call.operand(2, password);
|
|
|
49 |
call.operand(3, itoa(vdomain::ATTR_DEST));
|
|
|
50 |
|
|
|
51 |
unsigned i = 4;
|
|
|
52 |
for(mystring_iter iter(destination, ','); iter; ++iter, ++i)
|
|
|
53 |
call.operand(i, *iter);
|
|
|
54 |
|
|
|
55 |
response resp = call.call();
|
|
|
56 |
if(!resp)
|
|
|
57 |
error(resp.msg);
|
|
|
58 |
|
|
|
59 |
// Disable the account *AFTER* changing the destination.
|
|
|
60 |
if(do_disable) {
|
|
|
61 |
response resp = server_call("chattr", vdomain, username, password,
|
|
|
62 |
itoa(vdomain::ATTR_MAILBOX_ENABLED),
|
|
|
63 |
enable).call();
|
|
|
64 |
if(!resp)
|
|
|
65 |
error(resp.msg);
|
|
|
66 |
}
|
|
|
67 |
success("The alias was succesfully changed.");
|
|
|
68 |
}
|