3 eval 'exec /usr/bin/perl -Tw -S $0 ${1+"$@"}'
4 if 0; # not running under some shell
8 # This is run REMOTELY over ssh by fs_mailadmin_server.
14 use vars qw( $Debug );
18 my($fs_mailadmind_socket)="/usr/local/freeside/fs_mailadmind_socket";
20 $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
21 $ENV{'SHELL'} = '/bin/sh';
22 $ENV{'IFS'} = " \t\n";
25 $ENV{'BASH_ENV'} = '';
29 warn "[fs_mailadmind] Reading locales...\n" if $Debug;
30 chomp( my $n_cust_main_county = <STDIN> );
31 my @cust_main_county = map {
32 chomp( my $taxnum = <STDIN> );
33 chomp( my $state = <STDIN> );
34 chomp( my $county = <STDIN> );
35 chomp( my $country = <STDIN> );
40 'country' => $country,
42 } ( 1 .. $n_cust_main_county );
44 warn "[fs_mailadmind] Reading package definitions...\n" if $Debug;
45 chomp( my $n_part_pkg = <STDIN> );
47 chomp( my $pkgpart = <STDIN> );
48 chomp( my $pkg = <STDIN> );
50 'pkgpart' => $pkgpart,
53 } ( 1 .. $n_part_pkg );
55 warn "[fs_mailadmind] Reading POPs...\n" if $Debug;
56 chomp( my $n_svc_acct_pop = <STDIN> );
57 my @svc_acct_pop = map {
58 chomp( my $popnum = <STDIN> );
59 chomp( my $city = <STDIN> );
60 chomp( my $state = <STDIN> );
61 chomp( my $ac = <STDIN> );
62 chomp( my $exch = <STDIN> );
63 chomp( my $loc = <STDIN> );
72 } ( 1 .. $n_svc_acct_pop );
74 warn "[fs_mailadmind] Creating $fs_mailadmind_socket\n" if $Debug;
75 my $uaddr = sockaddr_un($fs_mailadmind_socket);
76 my $proto = getprotobyname('tcp');
77 socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!";
78 unlink($fs_mailadmind_socket);
79 bind(Server, $uaddr) or die "bind: $!";
80 listen(Server,SOMAXCONN) or die "listen: $!";
82 warn "[fs_mailadmind] Entering main loop...\n" if $Debug;
84 for ( ; $paddr = accept(Client,Server); close Client) {
86 chop( my $command = <Client> );
88 if ( $command eq "signup_info" ) {
89 warn "[fs_mailadmind] sending signup info...\n" if $Debug;
90 print Client join("\n", $n_cust_main_county,
99 print Client join("\n", $n_part_pkg,
106 print Client join("\n", $n_svc_acct_pop,
117 } elsif ( $command eq "new_customer" ) {
118 warn "[fs_mailadmind] reading customer signup...\n" if $Debug;
120 $first, $last, $ss, $company, $address1, $address2, $city, $county,
121 $state, $zip, $country, $daytime, $night, $fax, $payby, $payinfo,
122 $paydate, $payname, $invoicing_list, $pkgpart, $username, $password,
124 ) = map { scalar(<Client>) } ( 1 .. 23 );
126 warn "[fs_mailadmind] sending customer data to remote server...\n" if $Debug;
128 $first, $last, $ss, $company, $address1, $address2, $city, $county,
129 $state, $zip, $country, $daytime, $night, $fax, $payby, $payinfo,
130 $paydate, $payname, $invoicing_list, $pkgpart, $username, $password,
134 warn "[fs_mailadmind] reading error from remote server...\n" if $Debug;
137 warn "[fs_mailadmind] sending error to local client...\n" if $Debug;
140 } elsif ( $command eq "authenticate" ) {
141 warn "[fs_mailadmind] reading user information to auth...\n" if $Debug;
142 chop( my $user = <Client> );
143 warn "[fs_mailadmind] reading authentication material...\n" if $Debug;
144 chop( my $password = <Client> );
145 warn "[fs_mailadmind] sending information to remote server...\n" if $Debug;
146 print "authenticate\n", $user, "\n", $password, "\n";
148 warn "[fs_mailadmind] reading error from remote server...\n" if $Debug;
151 warn "[fs_mailadmind] sending error to local client...\n" if $Debug;
154 } elsif ( $command eq "list_packages" ) {
155 warn "[fs_mailadmind] reading user information to list_packages...\n" if $Debug;
156 chop( my $user = <Client> );
157 warn "[fs_mailadmind] sending user information to remote server...\n" if $Debug;
158 print "list_packages\n", $user, "\n";
160 warn "[fs_mailadmind] reading data from remote server...\n" if $Debug;
161 chomp( my $n_packages = <STDIN> );
163 chomp( my $pkgnum = <STDIN> );
164 chomp( my $domain = <STDIN> );
165 chomp( my $account = <STDIN> );
169 'account' => $account,
171 } ( 1 .. $n_packages );
173 warn "[fs_mailadmind] sending data to local client...\n" if $Debug;
175 print Client join("\n", $n_packages,
183 } elsif ( $command eq "list_mailboxes" ) {
184 warn "[fs_mailadmind] reading user information to list_mailboxes...\n" if $Debug;
185 chop( my $user = <Client> );
186 warn "[fs_mailadmind] reading package number to list_mailboxes...\n" if $Debug;
187 chop( my $package = <Client> );
188 warn "[fs_mailadmind] sending user information to remote server...\n" if $Debug;
189 print "list_mailboxes\n", $user, "\n", $package, "\n";
191 warn "[fs_mailadmind] reading data from remote server...\n" if $Debug;
192 chomp( my $n_svc_acct = <STDIN> );
194 chomp( my $svcnum = <STDIN> );
195 chomp( my $username = <STDIN> );
196 chomp( my $_password = <STDIN> );
199 'username' => $username,
200 '_password' => $_password,
202 } ( 1 .. $n_svc_acct );
204 warn "[fs_mailadmind] sending data to local client...\n" if $Debug;
206 print Client join("\n", $n_svc_acct,
214 } elsif ( $command eq "delete_mailbox" ) {
215 warn "[fs_mailadmind] reading user information to auth...\n" if $Debug;
216 chop( my $user = <Client> );
217 warn "[fs_mailadmind] reading account information to delete...\n" if $Debug;
218 chop( my $account = <Client> );
219 warn "[fs_mailadmind] sending information to remote server...\n" if $Debug;
220 print "delete_mailbox\n", $user, "\n", $account, "\n";
222 warn "[fs_mailadmind] reading error from remote server...\n" if $Debug;
225 warn "[fs_mailadmind] sending error to local client...\n" if $Debug;
228 } elsif ( $command eq "password_mailbox" ) {
229 warn "[fs_mailadmind] reading user information to auth...\n" if $Debug;
230 chop( my $user = <Client> );
231 warn "[fs_mailadmind] reading account information to password...\n" if $Debug;
233 $account, $_password,
234 ) = map { scalar(<Client>) } ( 1 .. 2 );
236 warn "[fs_mailadmind] sending password data to remote server...\n" if $Debug;
237 print "password_mailbox", "\n";
239 $user, "\n", $account, $_password,
242 warn "[fs_mailadmind] reading error from remote server...\n" if $Debug;
245 warn "[fs_mailadmind] sending error to local client...\n" if $Debug;
248 } elsif ( $command eq "add_mailbox" ) {
249 warn "[fs_mailadmind] reading user information to auth...\n" if $Debug;
250 chop( my $user = <Client> );
251 warn "[fs_mailadmind] reading account information to create...\n" if $Debug;
253 $package, $account, $_password,
254 ) = map { scalar(<Client>) } ( 1 .. 3 );
256 warn "[fs_mailadmind] sending service data to remote server...\n" if $Debug;
257 print "add_mailbox", "\n";
259 $user, "\n", $package, $account, $_password,
262 warn "[fs_mailadmind] reading error from remote server...\n" if $Debug;
265 warn "[fs_mailadmind] sending error to local client...\n" if $Debug;
268 } elsif ( $command eq "add_forward" ) {
269 warn "[fs_mailadmind] reading user information to auth...\n" if $Debug;
270 chop( my $user = <Client> );
271 warn "[fs_mailadmind] reading forward information to create...\n" if $Debug;
273 $package, $source, $dest,
274 ) = map { scalar(<Client>) } ( 1 .. 3 );
276 warn "[fs_mailadmind] sending service data to remote server...\n" if $Debug;
277 print "add_forward", "\n";
279 $user, "\n", $package, $source, $dest,
282 warn "[fs_mailadmind] reading error from remote server...\n" if $Debug;
285 warn "[fs_mailadmind] sending error to local client...\n" if $Debug;
288 } elsif ( $command eq "delete_forward" ) {
289 warn "[fs_mailadmind] reading user information to auth...\n" if $Debug;
290 chop( my $user = <Client> );
291 warn "[fs_mailadmind] reading forward information to delete...\n" if $Debug;
292 chop( my $service = <Client> );
293 warn "[fs_mailadmind] sending information to remote server...\n" if $Debug;
294 print "delete_forward\n", $user, "\n", $service, "\n";
296 warn "[fs_mailadmind] reading error from remote server...\n" if $Debug;
299 warn "[fs_mailadmind] sending error to local client...\n" if $Debug;
302 } elsif ( $command eq "list_forwards" ) {
303 warn "[fs_mailadmind] reading user information to list_forwards...\n" if $Debug;
304 chop( my $user = <Client> );
305 warn "[fs_mailadmind] reading service number to list_forwards...\n" if $Debug;
306 chop( my $service = <Client> );
307 warn "[fs_mailadmind] sending user information to remote server...\n" if $Debug;
308 print "list_forwards\n", $user, "\n", $service, "\n";
310 warn "[fs_mailadmind] reading data from remote server...\n" if $Debug;
311 chomp( my $n_svc_forward = <STDIN> );
312 my @svc_forward = map {
313 chomp( my $svcnum = <STDIN> );
314 chomp( my $dest = <STDIN> );
319 } ( 1 .. $n_svc_forward );
321 warn "[fs_mailadmind] sending data to local client...\n" if $Debug;
323 print Client join("\n", $n_svc_forward,
330 } elsif ( $command eq "list_pkg_forwards" ) {
331 warn "[fs_mailadmind] reading user information to list_pkg_forwards...\n" if $Debug;
332 chop( my $user = <Client> );
333 warn "[fs_mailadmind] reading service number to list_forwards...\n" if $Debug;
334 chop( my $package = <Client> );
335 warn "[fs_mailadmind] sending user information to remote server...\n" if $Debug;
336 print "list_pkg_forwards\n", $user, "\n", $package, "\n";
338 warn "[fs_mailadmind] reading data from remote server...\n" if $Debug;
339 chomp( my $n_svc_forward = <STDIN> );
340 my @svc_forward = map {
341 chomp( my $svcnum = <STDIN> );
342 chomp( my $srcsvc = <STDIN> );
343 chomp( my $dest = <STDIN> );
349 } ( 1 .. $n_svc_forward );
351 warn "[fs_mailadmind] sending data to local client...\n" if $Debug;
353 print Client join("\n", $n_svc_forward,
362 die "unexpected command from client: $command";