diff options
Diffstat (limited to 'fs_selfservice/FS-SelfService')
-rw-r--r-- | fs_selfservice/FS-SelfService/Changes | 6 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/MANIFEST | 6 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/Makefile.PL | 15 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/SelfService.pm | 115 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/cgi/login.html | 32 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/cgi/make_payment.html | 120 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/cgi/myaccount.html | 47 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/cgi/passwd.html | 25 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/cgi/payment_results.html | 18 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 188 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/cgi/view_invoice.html | 21 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/freeside-selfservice-clientd | 226 | ||||
-rw-r--r-- | fs_selfservice/FS-SelfService/test.pl | 17 |
13 files changed, 836 insertions, 0 deletions
diff --git a/fs_selfservice/FS-SelfService/Changes b/fs_selfservice/FS-SelfService/Changes new file mode 100644 index 000000000..b9e26b7dc --- /dev/null +++ b/fs_selfservice/FS-SelfService/Changes @@ -0,0 +1,6 @@ +Revision history for Perl extension FS::SelfService. + +0.01 Tue May 28 16:49:41 2002 + - original version; created by h2xs 1.21 with options + -A -X -n FS::SelfService + diff --git a/fs_selfservice/FS-SelfService/MANIFEST b/fs_selfservice/FS-SelfService/MANIFEST new file mode 100644 index 000000000..ebd0d3b1a --- /dev/null +++ b/fs_selfservice/FS-SelfService/MANIFEST @@ -0,0 +1,6 @@ +Changes +Makefile.PL +MANIFEST +SelfService.pm +test.pl +freeside-selfservice-clientd diff --git a/fs_selfservice/FS-SelfService/Makefile.PL b/fs_selfservice/FS-SelfService/Makefile.PL new file mode 100644 index 000000000..da0a0aa24 --- /dev/null +++ b/fs_selfservice/FS-SelfService/Makefile.PL @@ -0,0 +1,15 @@ +use ExtUtils::MakeMaker; +# See lib/ExtUtils/MakeMaker.pm for details of how to influence +# the contents of the Makefile that is written. +WriteMakefile( + 'NAME' => 'FS::SelfService', + 'VERSION_FROM' => 'SelfService.pm', # finds $VERSION + 'EXE_FILES' => [ 'freeside-selfservice-clientd' ], + 'INSTALLSCRIPT' => '/usr/local/sbin', + 'INSTALLSITEBIN' => '/usr/local/sbin', + 'PERM_RWX' => '750', + 'PREREQ_PM' => {}, # e.g., Module::Name => 1.1 + ($] >= 5.005 ? ## Add these new keywords supported since 5.005 + (ABSTRACT_FROM => 'SelfService.pm', # retrieve abstract from module + AUTHOR => 'Ivan Kohler <ivan-freeside-selfservice@420.am>') : ()), +); diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm new file mode 100644 index 000000000..5849b28d1 --- /dev/null +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -0,0 +1,115 @@ +package FS::SelfService; + +use strict; +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; + +$ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin'; +$ENV{'SHELL'} = '/bin/sh'; +$ENV{'IFS'} = " \t\n"; +$ENV{'CDPATH'} = ''; +$ENV{'ENV'} = ''; +$ENV{'BASH_ENV'} = ''; + +my $freeside_uid = scalar(getpwnam('freeside')); +die "not running as the freeside user\n" if $> != $freeside_uid; + +=head1 NAME + +FS::SelfService - Freeside self-service API + +=head1 SYNOPSIS + +=head1 DESCRIPTION + +Use this API to implement your own client "self-service" module. + +If you just want to customize the look of the existing "self-service" module, +see XXXX instead. + +=head1 FUNCTIONS + +=over 4 + +=item passwd + +Returns the empty value on success, or an error message on errors. + +=cut + +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); + }'; + + eval $eval; + die $@ if $@; + +} + +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; + + #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}; + + $return; +} + +=back + +=head1 BUGS + +=head1 SEE ALSO + +L<freeside-selfservice-clientd>, L<freeside-selfservice-server> + +=cut + +1; + diff --git a/fs_selfservice/FS-SelfService/cgi/login.html b/fs_selfservice/FS-SelfService/cgi/login.html new file mode 100644 index 000000000..ca6251eb1 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/login.html @@ -0,0 +1,32 @@ +<HTML><HEAD><TITLE>Login</TITLE></HEAD> +<BODY BGCOLOR="#e8e8e8"><FONT SIZE=5>Login</FONT><BR><BR> +<FONT SIZE="+1" COLOR="#ff0000"><%= $error %></FONT> +<FORM ACTION="<%= $self_url %>" METHOD=POST> +<INPUT TYPE="hidden" NAME="session" VALUE="login"> +<TABLE BGCOLOR="#c0c0c0" BORDER=0 CELLSPACING=2 CELLPADDING=0> +<TR> + <TH ALIGN="right">Username </TH> + <TD> + <!-- <INPUT TYPE="text" NAME="username" VALUE="<%= $username %>"> --> + <INPUT TYPE="text" NAME="username" VALUE="hslink"> + </TD> +</TR> +<TR> + <TH ALIGN="right">Domain </TH> + <TD> + <!-- <INPUT TYPE="text" NAME="domain" VALUE="<%= $domain %>"> --> + <INPUT TYPE="text" NAME="domain" VALUE="pobox.com"> + </TD> +</TR> +<!--<INPUT TYPE="hidden" NAME="domain" VALUE="myisp.com">--> +<TR> + <TH ALIGN="right">Password </TH> + <TD> + <!-- <INPUT TYPE="password" NAME="password"> --> + <INPUT TYPE="password" NAME="password" VALUE="UwjM5zdb"> + </TD> +</TR> +</TABLE> +<BR><BR><INPUT TYPE="submit" VALUE="Login"> +</FORM></BODY></HTML> + diff --git a/fs_selfservice/FS-SelfService/cgi/make_payment.html b/fs_selfservice/FS-SelfService/cgi/make_payment.html new file mode 100644 index 000000000..a1cda6d49 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/make_payment.html @@ -0,0 +1,120 @@ +<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD> +<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR> +<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<TABLE BORDER=0 CELLPADDING=4><TR><TD VALIGN="top" HEIGHT=384 BGCOLOR="#dddddd"> +<A HREF="<%= $url %>myaccount">MyAccount</A><BR> +<!-- <A HREF="<%= $url %>other">SomethingElse</A><BR> --> +</TD><TD VALIGN="top"> +<FONT SIZE=4>Make a payment</FONT><BR><BR> +<FORM NAME="OneTrueForm" METHOD="POST" ACTION="<%=$selfurl%>" onSubmit="document.OneTrueForm.process.disabled=true"> +<INPUT TYPE="hidden" NAME="session" VALUE="<%=$session_id%>"> +<INPUT TYPE="hidden" NAME="action" VALUE="payment_results"> +<TABLE BGCOLOR="#cccccc"> +<TR> + <TD ALIGN="right">Amount Due</TD> + <TD> + <TABLE><TR><TD BGCOLOR="#ffffff"> + $<%=sprintf("%.2f",$balance)%> + </TD></TR></TABLE> + </TD> +</TR> +<TR> + <TD ALIGN="right">Payment amount</TD> + <TD> + <TABLE><TR><TD BGCOLOR="#ffffff"> + $<INPUT TYPE="text" NAME="amount" SIZE=8 VALUE="<%=sprintf("%.2f",$balance)%>"> + </TD></TR></TABLE> + </TD> +</TR><TR> + <TD ALIGN="right">Card type</TD> + <TD> + <SELECT NAME="card_type"><OPTION></OPTION> + <%= foreach ( keys %card_types ) { + $selected = $card_type eq $card_types{$_} ? ' SELECTED' : ''; + $OUT .= qq(<OPTION$selected VALUE="). $card_types{$_}. qq(">$_\n); + } %> + </SELECT> + </TD> +</TD><TR> + <TD ALIGN="right">Card number</TD> + <TD> + <TABLE> + <TR> + <TD> + <INPUT TYPE="text" NAME="payinfo" SIZE=20 MAXLENGTH=19 VALUE="<%=$payinfo%>"> </TD> + <TD>Exp.</TD> + <TD> + <SELECT NAME="month"> + <%= for ( ( map "0$_", 1 .. 9 ), 11, 12 ) { + $OUT .= '<OPTION'. ($_ eq $month ? ' SELECTED' : ''). ">$_\n"; + } %> + </SELECT> + </TD> + <TD> / </TD> + <TD> + <SELECT NAME="year"> + <%= for ( 2003 .. 2012 ) { + $OUT .= '<OPTION'. ($_ eq $year ? ' SELECTED' : ''). ">$_\n"; + } %> + </SELECT> + </TD> + </TR> + </TABLE> + </TD> +</TR><TR> + <TD ALIGN="right">Exact name on card</TD> + <TD><INPUT TYPE="text" SIZE=32 MAXLENGTH=80 NAME="payname" VALUE="<%=$payname%>"></TD> +</TR><TR> + <TD ALIGN="right">Card billing address</TD> + <TD> + <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address1" VALUE="<%=$address1%>"> + </TD> +</TR><TR> + <TD ALIGN="right">Address line 2</TD> + <TD> + <INPUT TYPE="text" SIZE=40 MAXLENGTH=80 NAME="address2" VALUE="<%=$address2%>"> + </TD> +</TR><TR> + <TD ALIGN="right">City</TD> + <TD> + <TABLE> + <TR> + <TD> + <INPUT TYPE="text" NAME="city" SIZE="12" MAXLENGTH=80 VALUE="<%=$city%>"> + </TD> + <TD>State</TD> + <TD> + <SELECT NAME="state"> + <%= for ( @states ) { + $OUT .= '<OPTION'. ($_ eq $state ? ' SELECTED' : '' ). ">$_\n"; + } %> + </SELECT> + </TD> + <TD>Zip</TD> + <TD> + <INPUT TYPE="text" NAME="zip" SIZE=11 MAXLENGTH=10 VALUE="<%=$zip%>"> + </TD> + </TR> + </TABLE> + </TD> +</TR><TR> + <TD COLSPAN=2> + <INPUT TYPE="checkbox" CHECKED NAME="save" VALUE="1"> + Remember this information + </TD> +</TR><TR> + <TD COLSPAN=2> + <INPUT TYPE="checkbox"<%= $payby eq 'CARD' ? ' CHECKED' : '' %> NAME="auto" VALUE="1" onClick="if (this.checked) { document.OneTrueForm.save.checked=true; }"> + Charge future payments to this card automatically + </TD> +</TR> +</TABLE> +<BR> +<INPUT TYPE="hidden" NAME="paybatch" VALUE="<%=$paybatch%>"> +<INPUT TYPE="submit" NAME="process" VALUE="Process payment"> <!-- onClick="this.disabled=true"> --> +</FORM> +</TD></TR></TABLE> +<HR> +<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT> +</BODY></HTML> + diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount.html b/fs_selfservice/FS-SelfService/cgi/myaccount.html new file mode 100644 index 000000000..f48fdedea --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/myaccount.html @@ -0,0 +1,47 @@ +<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD> +<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR> +<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<TABLE BORDER=0 CELLPADDING=4><TR><TD VALIGN="top" HEIGHT=384 BGCOLOR="#dddddd"> +<A HREF="<%= $url %>myaccount">MyAccount</A><BR> +<!-- <A HREF="<%= $url %>other">SomethingElse</A><BR> --> +</TD><TD VALIGN="top"> + +Hello <%= $name %>!<BR><BR> +<%= $small_custview %> +<BR> +<%= if ( $balance > 0 ) { + $OUT .= qq! <B><A HREF="${url}make_payment">Make a payment</A></B><BR><BR>!; +} %> +<%= + if ( @open_invoices ) { + $OUT .= '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=2 BGCOLOR="#eeeeee">'. + '<TR><TH BGCOLOR="#ff3333" COLSPAN=5>Open Invoices</TH><TD>'; + my $link = qq!<A HREF="<%= $url %>myaccount!; + my $col1 = "ffffff"; + my $col2 = "dddddd"; + my $col = $col1; + + foreach my $invoice ( @open_invoices ) { + my $td = qq!<TD BGCOLOR="#$col">!; + my $a=qq!<A HREF="${url}view_invoice;invnum=!. $invoice->{'invnum'}. '">'; + $OUT .= + "<TR>$td${a}Invoice #". $invoice->{'invnum'}. "</A></TD>$td</TD>". + "$td$a". $invoice->{'date'}. "</A></TD>$td</TD>". + qq!<TD BGCOLOR="#$col" ALIGN="right">$a\$!. $invoice->{'owed'}. + '</A></TD>'. + '</TR>'; + $col = $col eq $col1 ? $col2 : $col1; + } + $OUT .= '</TABLE>'; + } else { + $OUT .= 'You have no outstanding invoices.<BR><BR>'; + } +%> + +</TD></TR></TABLE> +<HR> +<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT> +</BODY></HTML> + + + diff --git a/fs_selfservice/FS-SelfService/cgi/passwd.html b/fs_selfservice/FS-SelfService/cgi/passwd.html new file mode 100644 index 000000000..fadc4df8b --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/passwd.html @@ -0,0 +1,25 @@ +<html> + <head> + <title>Change password</title> + </head> + <body bgcolor="#e8e8e8"> + <h3>Change password</h3> + <form action="/cgi-bin/fs_passwd.cgi" method="post"> + <table bgcolor="#cccccc" border=0 cellspacing=2> + <tr><th align="right">Username</th> + <td><input type="text" name="username" size="18"></td> + </tr> + <tr><th align="right">Current password</th> + <td><input type="password" name="old_password" size="18"></td> + </tr> + <tr><th align="right">New password</th> + <td><input type="password" name="new_password" size="18"></td> + </tr> + <tr><th align="right">Re-enter new password</th> + <td><input type="password" name="new_password2" size="18"></td> + </tr> + </table> + <br><input type="submit" value="Change password"> + </body> +</html> + diff --git a/fs_selfservice/FS-SelfService/cgi/payment_results.html b/fs_selfservice/FS-SelfService/cgi/payment_results.html new file mode 100644 index 000000000..92c8cf51b --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/payment_results.html @@ -0,0 +1,18 @@ +<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD> +<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR> +<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<TABLE BORDER=0 CELLPADDING=4><TR><TD VALIGN="top" HEIGHT=384 BGCOLOR="#dddddd"> +<A HREF="<%= $url %>myaccount">MyAccount</A><BR> +<!-- <A HREF="<%= $url %>other">SomethingElse</A><BR> --> +</TD><TD VALIGN="top"> +<FONT SIZE=4>Payment results</FONT><BR><BR> +<%= if ( $error ) { + $OUT .= qq!<FONT SIZE="+1" COLOR="#ff0000">Error processing your payment: $error</FONT>!; +} else { + $OUT .= 'Your payment was processed sucessfully. Thank you.'; +} %> +</TD></TR></TABLE> +<HR> +<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT> +</BODY></HTML> + diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi new file mode 100644 index 000000000..6d6716ddc --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -0,0 +1,188 @@ +#!/usr/bin/perl -Tw + +use strict; +use vars qw($cgi $session_id $form_max $template_dir); +use subs qw(do_template); +use CGI; +use CGI::Carp qw(fatalsToBrowser); +use Text::Template; +use FS::SelfService qw( login customer_info invoice payment_info + process_payment ); + +$template_dir = '.'; + +$form_max = 255; + +$cgi = new CGI; + +unless ( defined $cgi->param('session') ) { + do_template('login',{}); + exit; +} + +if ( $cgi->param('session') eq 'login' ) { + + $cgi->param('username') =~ /^\s*([a-z0-9_\-\.\&]{0,$form_max})\s*$/i + or die "illegal username"; + my $username = $1; + + $cgi->param('domain') =~ /^\s*([\w\-\.]{0,$form_max})\s*$/ + or die "illegal domain"; + my $domain = $1; + + $cgi->param('password') =~ /^(.{0,$form_max})$/ + or die "illegal password"; + my $password = $1; + + my $rv = login( + 'username' => $username, + 'domain' => $domain, + 'password' => $password, + ); + if ( $rv->{error} ) { + do_template('login', { + 'error' => $rv->{error}, + 'username' => $username, + 'domain' => $domain, + } ); + exit; + } else { + $cgi->param('session' => $rv->{session_id} ); + $cgi->param('action' => 'myaccount' ); + } +} + +$session_id = $cgi->param('session'); + +$cgi->param('action') =~ + /^(myaccount|view_invoice|make_payment|payment_results)$/ + or die "unknown action ". $cgi->param('action'); +my $action = $1; + +my $result = eval "&$action();"; +die $@ if $@; + +if ( $result->{error} eq "Can't resume session" ) { #ick + do_template('login',{}); + exit; +} + +#warn $result->{'open_invoices'}; +#warn scalar(@{$result->{'open_invoices'}}); + +warn "processing template $action\n"; +do_template($action, { + 'session_id' => $session_id, + %{$result} +}); + +#-- + +sub myaccount { customer_info( 'session_id' => $session_id ); } + +sub view_invoice { + + $cgi->param('invnum') =~ /^(\d+)$/ or die "illegal invnum"; + my $invnum = $1; + + invoice( 'session_id' => $session_id, + 'invnum' => $invnum, + ); + +} + +sub make_payment { + payment_info( 'session_id' => $session_id ); +} + +sub payment_results { + + use Business::CreditCard; + + $cgi->param('amount') =~ /^\s*(\d+(\.\d{2})?)\s*$/ + or die "illegal amount"; #!!! + my $amount = $1; + + my $payinfo = $cgi->param('payinfo'); + $payinfo =~ s/\D//g; + $payinfo =~ /^(\d{13,16})$/ + #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo; + or die "illegal card"; #!!! + $payinfo = $1; + validate($payinfo) + #or $error ||= $init_data->{msgcat}{invalid_card}; #. $self->payinfo; + or die "invalid card"; #!!! + cardtype($payinfo) eq $cgi->param('card_type') + #or $error ||= $init_data->{msgcat}{not_a}. $cgi->param('CARD_type'); + or die "not a ". $cgi->param('card_type'); + + $cgi->param('month') =~ /^(\d{2})$/ or die "illegal month"; + my $month = $1; + $cgi->param('year') =~ /^(\d{4})$/ or die "illegal year"; + my $year = $1; + + $cgi->param('payname') =~ /^(.{0,80})$/ or die "illegal payname"; + my $payname = $1; + + $cgi->param('address1') =~ /^(.{0,80})$/ or die "illegal address1"; + my $address1 = $1; + + $cgi->param('address2') =~ /^(.{0,80})$/ or die "illegal address2"; + my $address2 = $1; + + $cgi->param('city') =~ /^(.{0,80})$/ or die "illegal city"; + my $city = $1; + + $cgi->param('state') =~ /^(.{2})$/ or die "illegal state"; + my $state = $1; + + $cgi->param('zip') =~ /^(.{0,10})$/ or die "illegal zip"; + my $zip = $1; + + my $save = 0; + $save = 1 if $cgi->param('save'); + + my $auto = 0; + $auto = 1 if $cgi->param('auto'); + + $cgi->param('paybatch') =~ /^([\w\-\.]+)$/ or die "illegal paybatch"; + my $paybatch = $1; + + process_payment( + 'session_id' => $session_id, + 'amount' => $amount, + 'payinfo' => $payinfo, + 'month' => $month, + 'year' => $year, + 'payname' => $payname, + 'address1' => $address1, + 'address2' => $address2, + 'city' => $city, + 'state' => $state, + 'zip' => $zip, + 'save' => $save, + 'auto' => $auto, + 'paybatch' => $paybatch, + ); + +} + +#-- + +sub do_template { + my $name = shift; + my $fill_in = shift; + + $cgi->delete_all(); + $fill_in->{'selfurl'} = $cgi->self_url; + + my $template = new Text::Template( TYPE => 'FILE', + SOURCE => "$template_dir/$name.html", + DELIMITERS => [ '<%=', '%>' ], + UNTAINT => 1, ) + or die $Text::Template::ERROR; + + print $cgi->header( '-expires' => 'now' ), + $template->fill_in( HASH => $fill_in ); +} + diff --git a/fs_selfservice/FS-SelfService/cgi/view_invoice.html b/fs_selfservice/FS-SelfService/cgi/view_invoice.html new file mode 100644 index 000000000..d2b012b5d --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/view_invoice.html @@ -0,0 +1,21 @@ +<HTML><HEAD><TITLE>MyAccount</TITLE></HEAD> +<BODY BGCOLOR="#eeeeee"><FONT SIZE=5>MyAccount</FONT><BR><BR> +<%= $url = "$selfurl?session=$session_id;action="; ''; %> +<TABLE BORDER=0 CELLPADDING=4><TR><TD VALIGN="top" HEIGHT=384 BGCOLOR="#dddddd"> +<A HREF="<%= $url %>myaccount">MyAccount</A><BR> +<!-- <A HREF="<%= $url %>other">SomethingElse</A><BR> --> +</TD><TD VALIGN="top"> + +<A HREF="<%= $url %>myaccount"><-- back to MyAccount</A><BR><BR> + +<FONT SIZE="-1"><PRE> +<%= $invoice_text %> +</FONT></PRE> + +</TD></TR></TABLE> +<HR> +<FONT SIZE="-2">powered by <a href="http://www.sisd.com/freeside">freeside</a></FONT> +</BODY></HTML> + + + diff --git a/fs_selfservice/FS-SelfService/freeside-selfservice-clientd b/fs_selfservice/FS-SelfService/freeside-selfservice-clientd new file mode 100644 index 000000000..f13dd42d7 --- /dev/null +++ b/fs_selfservice/FS-SelfService/freeside-selfservice-clientd @@ -0,0 +1,226 @@ +#!/usr/bin/perl -w +# +# freeside-selfservice-clientd +# +# This is run REMOTELY over ssh by freeside-selfservice-server + +use strict; +use subs qw(spawn logmsg); +use Fcntl qw(:flock); +use POSIX qw(:sys_wait_h); +use Socket; +use Storable qw(nstore_fd fd_retrieve); +use IO::Handle qw(_IONBF); +use IO::Select; +use IO::File; + +#STDOUT->setbuf(''); + +use vars qw( $Debug ); +$Debug = 3; #2 will turn on child logging, 3 will log packet contents, + #including potentially compromising information + +my $socket = "/usr/local/freeside/selfservice_socket"; +my $pid_file = "$socket.pid"; + +my $log_file = "/usr/local/freeside/selfservice.log"; + +#my $me = '[client]'; + +$|=1; + +$SIG{__WARN__} = \&_logmsg; + +#read data to be cached or something +#warn "$me Reading init data\n" if $Debug; +#my $signup_init = + +warn "Creating $socket\n" if $Debug; +my $uaddr = sockaddr_un($socket); +my $proto = getprotobyname('tcp'); +socket(Server,PF_UNIX,SOCK_STREAM,0) or die "socket: $!"; +unlink($socket); +bind(Server, $uaddr) or die "bind: $!"; +listen(Server,SOMAXCONN) or die "listen: $!"; + +if ( -e $pid_file ) { + open(PIDFILE,"<$pid_file"); + my $old_pid = <PIDFILE>; + close PIDFILE; + $old_pid =~ /^(\d+)$/; + kill 'TERM', $1; +} +open(PIDFILE,">$pid_file"); +print PIDFILE "$$\n"; +close PIDFILE; + +#my $waitedpid; +#sub REAPER { $waitedpid = wait; $SIG{CHLD} = \&REAPER; } +#$SIG{CHLD} = \&REAPER; + +warn "entering main loop\n" if $Debug; + +my %kids; + +my $s = new IO::Select; +$s->add(\*STDIN); +$s->add(\*Server); + +#for ( $waitedpid = 0; +# accept(Client,Server) || $waitedpid; +# $waitedpid = 0, close Client) +#{ +# next if $waitedpid; + +#$SIG{PIPE} = sub { warn "SIGPIPE received" }; +#$SIG{CHLD} = sub { warn "SIGCHLD received" }; + +#sub REAPER { warn "SIGCHLD received"; my $pid = wait; $SIG{CHLD} = \&REAPER; } +#sub REAPER { my $pid = wait; $SIG{CHLD} = \&REAPER; } +#sub REAPER { my $pid = wait; delete $kids{$pid}; $SIG{CHLD} = \&REAPER; } +#$SIG{CHLD} = \&REAPER; + +my $undisp = 0; +while (1) { + + &reap_kids; + + warn "waiting for connection\n" if $Debug && !$undisp; + + #my @handles = $s->can_read(); + my @handles = $s->can_read(5); + $undisp = !scalar(@handles); + foreach my $handle ( @handles ) { + + if ( $handle == \*STDIN ) { + + warn "receiving packet from server\n" if $Debug; + + my $packet = fd_retrieve(\*STDIN); + my $token = $packet->{'_token'}; + warn "received packet from server with token $token\n". + ( $Debug > 2 + ? join('', map { " $_=>$packet->{$_}\n" } keys %$packet ) + : '' ) + if $Debug; + + if ( exists($kids{$token}) ) { + warn "sending return packet to $token via $kids{$token}\n" + if $Debug; + nstore_fd($packet, $kids{$token}); + warn "flushing to $token\n" if $Debug; + until ( $kids{$token}->flush ) { + warn "WARNING: error flushing: $!"; + sleep 1; + } + #no close or delete here - will block waiting for child + warn "done with $token\n" if $Debug; + } else { + warn "WARNING: unknown token $token, discarding message"; + } + + } elsif ( $handle == \*Server ) { + + until ( accept(Client, Server) ) { + warn "WARNING: accept failed: $!"; + next; + } + + warn "received local connection; forking\n" if $Debug; + + spawn sub { #child + warn "[child-$$] reading packet from local client" if $Debug > 1; + my $packet = fd_retrieve(\*Client); + warn "[child-$$] packet received:\n". + join('', map { " $_=>$packet->{$_}\n" } keys %$packet ) + if $Debug > 2; + my $command = $packet->{'command'}; + #handle some commands weirdly? + $packet->{_token}=$$; + + warn "[child-$$] sending packet to remote server" if $Debug > 1; + flock(STDOUT, LOCK_EX) or die "FATAL: can't lock write stream: $!"; + nstore_fd($packet, \*STDOUT) or die "FATAL: can't send response: $!"; + STDOUT->flush or die "FATAL: can't flush: $!"; + flock(STDOUT, LOCK_UN) or die "FATAL: can't release write lock: $!"; + close STDOUT or die "FATAL: can't close write stream: $!"; #??! + + warn "[child-$$] waiting for response from parent" if $Debug > 1; + my $w = new IO::Select; + $w->add(\*STDIN); + until ( $w->can_read ) { + warn "[child-$$] WARNING: interrupted select: $!\n"; + } + my $rv = fd_retrieve(\*STDIN); + + #close STDIN; + + warn "[child-$$] sending response to local client" if $Debug > 1; + nstore_fd($rv, \*Client); + Client->flush or die "FATAL: can't flush to local client: $!"; + close Client or die "FATAL: can't close connection to local client: $!"; + + warn "[child-$$] child exiting" if $Debug > 1; + exit; + + }; #eo child + + #close Client; + + } else { + die "wtf? $handle"; + } + + } + +} + +sub reap_kids { + #warn "reaping kids\n"; + foreach my $pid ( keys %kids ) { + my $kid = waitpid($pid, WNOHANG); + if ( $kid > 0 ) { + close $kids{$kid}; + delete $kids{$kid}; + } + } + #warn "done reaping\n"; +} + +sub spawn { + my $coderef = shift; + + unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') { + use Carp; + confess "usage: spawn CODEREF"; + } + + my $pid; + #if (!defined($pid = fork)) { + my $kid = new IO::Handle; + if (!defined($pid = open($kid, '|-'))) { + warn "WARNING: cannot fork: $!"; + return; + } elsif ($pid) { + warn "begat $pid" if $Debug; + $kids{$pid} = $kid; + #$kids{$pid}->autoflush; + return; # I'm the parent + } + # else I'm the child -- go spawn + +# open(STDIN, "<&Client") || die "can't dup client to stdin"; +# open(STDOUT, ">&Client") || die "can't dup client to stdout"; +# open(STDERR, ">&STDOUT") || die "can't dup stdout to stderr"; + exit &$coderef(); +} + +sub _logmsg { + chomp( my $msg = shift ); + my $log = new IO::File ">>$log_file"; + flock($log, LOCK_EX); + seek($log, 0, 2); + print $log "[client] [". scalar(localtime). "] [$$] $msg\n"; + flock($log, LOCK_UN); + close $log; +} diff --git a/fs_selfservice/FS-SelfService/test.pl b/fs_selfservice/FS-SelfService/test.pl new file mode 100644 index 000000000..7468ea471 --- /dev/null +++ b/fs_selfservice/FS-SelfService/test.pl @@ -0,0 +1,17 @@ +# Before `make install' is performed this script should be runnable with +# `make test'. After `make install' it should work as `perl test.pl' + +######################### + +# change 'tests => 1' to 'tests => last_test_to_print'; + +use Test; +BEGIN { plan tests => 1 }; +use FS::SelfService; +ok(1); # If we made it this far, we're ok. + +######################### + +# Insert your test code below, the Test module is use()ed here so read +# its man page ( perldoc Test ) for help writing this test script. + |