Add vmail command for changing password when you know the current password
[hcoop/domtool2.git] / src / main-portal.sml
1 (* HCoop Domtool (http://hcoop.sourceforge.net/)
2 * Copyright (c) 2014, Clinton Ebadi <clinton@unknownlamer.org>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *)
18
19 (* Portal helper utility. *)
20
21 (* Duplicated from main-config.sml, should be put into a common module
22 and all domtool commands should return proper exit codes instead of
23 always succeeding *)
24
25 fun println x = (print x; print "\n")
26 fun printerr x = (TextIO.output (TextIO.stdErr, x); TextIO.flushOut TextIO.stdErr)
27 fun die reason = (printerr reason; printerr "\n"; OS.Process.exit OS.Process.failure)
28
29 val _ =
30 case CommandLine.arguments () of
31 ["vmailpasswd", domain, user] =>
32 (case Client.getpass () of
33 Client.Passwd oldpasswd =>
34 (case Client.getpass () of
35 Client.Passwd newpasswd =>
36 Main.requestPortalPasswdMailbox {domain = domain,
37 user = user,
38 oldpasswd = oldpasswd,
39 newpasswd = newpasswd}
40 | Client.Aborted => die "Aborted"
41 | Client.Error => die "New passwords did not match")
42 | _ => die "Error entering old password")
43 | _ => die "Invalid command-line arguments"
44