1 package FS::MailAdminClient;
4 use vars qw($VERSION @ISA @EXPORT_OK $fs_mailadmind_socket);
12 @ISA = qw( Exporter );
13 @EXPORT_OK = qw( signup_info authenticate list_packages list_mailboxes delete_mailbox password_mailbox add_mailbox list_forwards list_pkg_forwards delete_forward add_forward new_customer );
15 $fs_mailadmind_socket = "/usr/local/freeside/fs_mailadmind_socket";
17 $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin';
18 $ENV{'SHELL'} = '/bin/sh';
19 $ENV{'IFS'} = " \t\n";
22 $ENV{'BASH_ENV'} = '';
24 my $freeside_uid = scalar(getpwnam('freeside'));
25 die "not running as the freeside user\n" if $> != $freeside_uid;
29 FS::MailAdminClient - Freeside mail administration client API
33 use FS::MailAdminClient qw( signup_info list_mailboxes new_customer );
35 ( $locales, $packages, $pops ) = signup_info;
37 ( $accounts ) = list_mailboxes;
39 $error = new_customer ( {
43 'comapny' => $company,
44 'address1' => $address1,
45 'address2' => $address2,
50 'country' => $country,
51 'daytime' => $daytime,
55 'payinfo' => $payinfo,
56 'paydate' => $paydate,
57 'payname' => $payname,
58 'invoicing_list' => $invoicing_list,
59 'pkgpart' => $pkgpart,
60 'username' => $username,
61 '_password' => $password,
67 This module provides an API for a remote mail administration server.
69 It needs to be run as the freeside user. Because of this, the program which
70 calls these subroutines should be written very carefully.
78 Returns three array references of hash references.
80 The first set of hash references is of allowable locales. Each hash reference
81 has the following keys:
87 The second set of hash references is of allowable packages. Each hash
88 reference has the following keys:
92 The third set of hash references is of allowable POPs (Points Of Presence).
93 Each hash reference has the following keys:
103 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
104 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
105 print SOCK "signup_info\n";
108 chop ( my $n_cust_main_county = <SOCK> );
109 my @cust_main_county = map {
110 chop ( my $taxnum = <SOCK> );
111 chop ( my $state = <SOCK> );
112 chop ( my $county = <SOCK> );
113 chop ( my $country = <SOCK> );
118 'country' => $country,
120 } 1 .. $n_cust_main_county;
122 chop ( my $n_part_pkg = <SOCK> );
124 chop ( my $pkgpart = <SOCK> );
125 chop ( my $pkg = <SOCK> );
127 'pkgpart' => $pkgpart,
132 chop ( my $n_svc_acct_pop = <SOCK> );
133 my @svc_acct_pop = map {
134 chop ( my $popnum = <SOCK> );
135 chop ( my $city = <SOCK> );
136 chop ( my $state = <SOCK> );
137 chop ( my $ac = <SOCK> );
138 chop ( my $exch = <SOCK> );
139 chop ( my $loc = <SOCK> );
148 } 1 .. $n_svc_acct_pop;
152 \@cust_main_county, \@part_pkg, \@svc_acct_pop;
157 Authentictes against a service on the remote Freeside system. Requires a hash
158 reference as a parameter with the following keys:
162 Returns a scalar error message of the form "authuser OK|FAILED" or an error
169 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
170 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
171 print SOCK "authenticate", "\n";
174 print SOCK join("\n", map { $hashref->{$_} } qw(
179 chop( my $error = <SOCK> );
187 Returns one array reference of hash references.
189 The set of hash references is of existing packages. Each hash reference
190 has the following keys:
199 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
200 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
201 print SOCK "list_packages\n", $user, "\n";
204 chop ( my $n_packages = <SOCK> );
206 chop ( my $pkgnum = <SOCK> );
207 chop ( my $domain = <SOCK> );
208 chop ( my $account = <SOCK> );
212 'account' => $account,
223 Returns one array references of hash references.
225 The set of hash references is of existing accounts. Each hash reference
226 has the following keys:
234 my ($user, $package) = @_;
235 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
236 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
237 print SOCK "list_mailboxes\n", $user, "\n", $package, "\n";
240 chop ( my $n_svc_acct = <SOCK> );
242 chop ( my $svcnum = <SOCK> );
243 chop ( my $username = <SOCK> );
244 chop ( my $_password = <SOCK> );
247 'username' => $username,
248 '_password' => $_password,
259 Deletes a mailbox service from the remote Freeside system. Requires a hash
260 reference as a paramater with the following keys:
264 Returns a scalar error message, or the empty string for success.
270 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
271 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
272 print SOCK "delete_mailbox", "\n";
275 print SOCK join("\n", map { $hashref->{$_} } qw(
280 chop( my $error = <SOCK> );
286 =item password_mailbox
288 Changes the password for a mailbox service on the remote Freeside system.
289 Requires a hash reference as a paramater with the following keys:
294 Returns a scalar error message, or the empty string for success.
298 sub password_mailbox {
300 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
301 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
302 print SOCK "password_mailbox", "\n";
305 print SOCK join("\n", map { $hashref->{$_} } qw(
306 authuser account _password
310 chop( my $error = <SOCK> );
318 Creates a mailbox service on the remote Freeside system. Requires a hash
319 reference as a parameter with the following keys:
325 Returns a scalar error message, or the empty string for success.
331 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
332 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
333 print SOCK "add_mailbox", "\n";
336 print SOCK join("\n", map { $hashref->{$_} } qw(
337 authuser package account _password
341 chop( my $error = <SOCK> );
349 Returns one array references of hash references.
351 The set of hash references is of existing forwards. Each hash reference
352 has the following keys:
359 my ($user, $service) = @_;
360 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
361 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
362 print SOCK "list_forwards\n", $user, "\n", $service, "\n";
365 chop ( my $n_svc_forward = <SOCK> );
366 my @svc_forward = map {
367 chop ( my $svcnum = <SOCK> );
368 chop ( my $dest = <SOCK> );
373 } 1 .. $n_svc_forward;
380 =item list_pkg_forwards
382 Returns one array references of hash references.
384 The set of hash references is of existing forwards. Each hash reference
385 has the following keys:
392 sub list_pkg_forwards {
393 my ($user, $package) = @_;
394 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
395 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
396 print SOCK "list_pkg_forwards\n", $user, "\n", $package, "\n";
399 chop ( my $n_svc_forward = <SOCK> );
400 my @svc_forward = map {
401 chop ( my $svcnum = <SOCK> );
402 chop ( my $srcsvc = <SOCK> );
403 chop ( my $dest = <SOCK> );
409 } 1 .. $n_svc_forward;
418 Deletes a forward service from the remote Freeside system. Requires a hash
419 reference as a paramater with the following keys:
423 Returns a scalar error message, or the empty string for success.
429 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
430 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
431 print SOCK "delete_forward", "\n";
434 print SOCK join("\n", map { $hashref->{$_} } qw(
439 chop( my $error = <SOCK> );
447 Creates a forward service on the remote Freeside system. Requires a hash
448 reference as a parameter with the following keys:
454 Returns a scalar error message, or the empty string for success.
460 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
461 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
462 print SOCK "add_forward", "\n";
465 print SOCK join("\n", map { $hashref->{$_} } qw(
466 authuser package source dest
470 chop( my $error = <SOCK> );
476 =item new_customer HASHREF
478 Adds a customer to the remote Freeside system. Requires a hash reference as
479 a paramater with the following keys:
504 Returns a scalar error message, or the empty string for success.
511 socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
512 connect(SOCK, sockaddr_un($fs_mailadmind_socket)) or die "connect: $!";
513 print SOCK "new_customer\n";
515 print SOCK join("\n", map { $hashref->{$_} } qw(
516 first last ss company address1 address2 city county state zip country
517 daytime night fax payby payinfo paydate payname invoicing_list
518 pkgpart username _password popnum
522 chop( my $error = <SOCK> );
530 $Id: MailAdminClient.pm,v 1.1 2001-10-18 15:04:54 jeff Exp $
536 L<fs_signupd>, L<FS::SignupServer>, L<FS::cust_main>