add email address to shellcommands
[freeside.git] / fs_selfservice / FS-SelfService / SelfService.pm
1 package FS::SelfService;
2
3 use strict;
4 use vars qw($VERSION @ISA @EXPORT_OK $socket %autoload );
5 use Exporter;
6 use Socket;
7 use FileHandle;
8 #use IO::Handle;
9 use IO::Select;
10 use Storable qw(nstore_fd fd_retrieve);
11
12 $VERSION = '0.03';
13
14 @ISA = qw( Exporter );
15
16 $socket =  "/usr/local/freeside/selfservice_socket";
17
18 %autoload = (
19   'passwd'        => 'passwd/passwd',
20   'chfn'          => 'passwd/passwd',
21   'chsh'          => 'passwd/passwd',
22   'login'         => 'MyAccount/login',
23   'customer_info' => 'MyAccount/customer_info',
24   'invoice'       => 'MyAccount/invoice',
25   'start'         => 'MyAccount/start',
26   'update'        => 'MyAccount/update',
27   'collect'       => 'MyAccount/collect',
28   'cancel'        => 'MyAccount/cancel',
29   'uncancel'      => 'MyAccount/uncancel',
30   'getinfo'       => 'MyAccount/getinfo',
31   'charge'        => 'MyAccount/charge',
32   'new_customer'  => 'MyAccount/new_customer',
33 );
34
35 @EXPORT_OK = keys %autoload;
36
37 $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin';
38 $ENV{'SHELL'} = '/bin/sh';
39 $ENV{'IFS'} = " \t\n";
40 $ENV{'CDPATH'} = '';
41 $ENV{'ENV'} = '';
42 $ENV{'BASH_ENV'} = '';
43
44 my $freeside_uid = scalar(getpwnam('freeside'));
45 die "not running as the freeside user\n" if $> != $freeside_uid;
46
47 =head1 NAME
48
49 FS::SelfService - Freeside self-service API
50
51 =head1 SYNOPSIS
52
53 =head1 DESCRIPTION
54
55 Use this API to implement your own client "self-service" module.
56
57 If you just want to customize the look of the existing "self-service" module,
58 see XXXX instead.
59
60 =head1 FUNCTIONS
61
62 =over 4
63
64 =item passwd
65
66 Returns the empty value on success, or an error message on errors.
67
68 =cut
69
70 foreach my $autoload ( keys %autoload ) {
71
72   my $eval =
73   "sub $autoload { ". '
74                    my $param;
75                    if ( ref($_[0]) ) {
76                      $param = shift;
77                    } else {
78                      $param = { @_ };
79                    }
80
81                    $param->{_packet} = \''. $autoload{$autoload}. '\';
82
83                    simple_packet($param);
84                  }';
85
86   eval $eval;
87   die $@ if $@;
88
89 }
90
91 sub simple_packet {
92   my $packet = shift;
93   socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!";
94   connect(SOCK, sockaddr_un($socket)) or die "connect: $!";
95   nstore_fd($packet, \*SOCK) or die "can't send packet: $!";
96   SOCK->flush;
97
98   #shoudl trap: Magic number checking on storable file failed at blib/lib/Storable.pm (autosplit into blib/lib/auto/Storable/fd_retrieve.al) line 337, at /usr/local/share/perl/5.6.1/FS/SelfService.pm line 71
99
100   #block until there is a message on socket
101 #  my $w = new IO::Select;
102 #  $w->add(\*SOCK);
103 #  my @wait = $w->can_read;
104   my $return = fd_retrieve(\*SOCK) or die "error reading result: $!";
105   die $return->{'_error'} if defined $return->{_error} && $return->{_error};
106
107   $return;
108 }
109
110 =back
111
112 =head1 BUGS
113
114 =head1 SEE ALSO
115
116 L<freeside-selfservice-clientd>, L<freeside-selfservice-server>
117
118 =cut
119
120 1;
121