X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;ds=sidebyside;f=fs_selfservice%2FFS-SelfService%2FSelfService.pm;h=5849b28d10e87e9690a6ef85c24c2bd343ba191e;hb=e354694764fb1442b6bc74a63189f094c51f1a89;hp=75e550a2df4b8c964410583462ad10da991d2767;hpb=b4d172efa2225ef5070c1a6f168eb98fce8c5c62;p=freeside.git diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 75e550a2d..5849b28d1 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -1,66 +1,115 @@ package FS::SelfService; -use 5.006; use strict; -use warnings; +use vars qw($VERSION @ISA @EXPORT_OK $socket %autoload ); +use Exporter; +use Socket; +use FileHandle; +#use IO::Handle; +use IO::Select; +use Storable qw(nstore_fd fd_retrieve); + +$VERSION = '0.03'; + +@ISA = qw( Exporter ); + +$socket = "/usr/local/freeside/selfservice_socket"; + +%autoload = ( + 'passwd' => 'passwd/passwd', + 'chfn' => 'passwd/passwd', + 'chsh' => 'passwd/passwd', + 'login' => 'MyAccount/login', + 'customer_info' => 'MyAccount/customer_info', + 'invoice' => 'MyAccount/invoice', + 'cancel' => 'MyAccount/cancel', + 'payment_info' => 'MyAccount/payment_info', + 'process_payment' => 'MyAccount/process_payment', +); +@EXPORT_OK = keys %autoload; -require Exporter; +$ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin'; +$ENV{'SHELL'} = '/bin/sh'; +$ENV{'IFS'} = " \t\n"; +$ENV{'CDPATH'} = ''; +$ENV{'ENV'} = ''; +$ENV{'BASH_ENV'} = ''; -our @ISA = qw(Exporter); +my $freeside_uid = scalar(getpwnam('freeside')); +die "not running as the freeside user\n" if $> != $freeside_uid; -# Items to export into callers namespace by default. Note: do not export -# names by default without a very good reason. Use EXPORT_OK instead. -# Do not simply export all your public functions/methods/constants. +=head1 NAME -# This allows declaration use FS::SelfService ':all'; -# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK -# will save memory. -our %EXPORT_TAGS = ( 'all' => [ qw( - -) ] ); +FS::SelfService - Freeside self-service API -our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); +=head1 SYNOPSIS -our @EXPORT = qw( - -); -our $VERSION = '0.01'; +=head1 DESCRIPTION +Use this API to implement your own client "self-service" module. -# Preloaded methods go here. +If you just want to customize the look of the existing "self-service" module, +see XXXX instead. -1; -__END__ -# Below is stub documentation for your module. You better edit it! +=head1 FUNCTIONS -=head1 NAME +=over 4 -FS::SelfService - Perl extension for blah blah blah +=item passwd -=head1 SYNOPSIS +Returns the empty value on success, or an error message on errors. - use FS::SelfService; - blah blah blah +=cut -=head1 DESCRIPTION +foreach my $autoload ( keys %autoload ) { + + my $eval = + "sub $autoload { ". ' + my $param; + if ( ref($_[0]) ) { + $param = shift; + } else { + $param = { @_ }; + } + + $param->{_packet} = \''. $autoload{$autoload}. '\'; + + simple_packet($param); + }'; -Stub documentation for FS::SelfService, created by h2xs. It looks like the -author of the extension was negligent enough to leave the stub -unedited. + eval $eval; + die $@ if $@; -Blah blah blah. +} -=head2 EXPORT +sub simple_packet { + my $packet = shift; + socket(SOCK, PF_UNIX, SOCK_STREAM, 0) or die "socket: $!"; + connect(SOCK, sockaddr_un($socket)) or die "connect: $!"; + nstore_fd($packet, \*SOCK) or die "can't send packet: $!"; + SOCK->flush; -None by default. + #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 + #block until there is a message on socket +# my $w = new IO::Select; +# $w->add(\*SOCK); +# my @wait = $w->can_read; + my $return = fd_retrieve(\*SOCK) or die "error reading result: $!"; + die $return->{'_error'} if defined $return->{_error} && $return->{_error}; -=head1 AUTHOR + $return; +} -A. U. Thor, Ea.u.thor@a.galaxy.far.far.awayE +=back + +=head1 BUGS =head1 SEE ALSO -L. +L, L =cut + +1; +