From 6ff02eb18af2dd61ce2dca064414ca183fa02e6e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 16 Jul 2002 12:28:02 +0000 Subject: invoice viewing... --- fs_selfservice/FS-SelfService/SelfService.pm | 41 +++++--- fs_selfservice/FS-SelfService/cgi/login.html | 23 +++++ fs_selfservice/FS-SelfService/cgi/myaccount.html | 47 +++++++++ fs_selfservice/FS-SelfService/cgi/selfservice.cgi | 109 +++++++++++++++++++++ .../FS-SelfService/cgi/view_invoice.html | 21 ++++ .../FS-SelfService/freeside-selfservice-clientd | 2 +- 6 files changed, 230 insertions(+), 13 deletions(-) create mode 100644 fs_selfservice/FS-SelfService/cgi/login.html create mode 100644 fs_selfservice/FS-SelfService/cgi/myaccount.html create mode 100644 fs_selfservice/FS-SelfService/cgi/selfservice.cgi create mode 100644 fs_selfservice/FS-SelfService/cgi/view_invoice.html (limited to 'fs_selfservice/FS-SelfService') diff --git a/fs_selfservice/FS-SelfService/SelfService.pm b/fs_selfservice/FS-SelfService/SelfService.pm index 3cd4fd94e..9019ea4f8 100644 --- a/fs_selfservice/FS-SelfService/SelfService.pm +++ b/fs_selfservice/FS-SelfService/SelfService.pm @@ -1,7 +1,7 @@ package FS::SelfService; use strict; -use vars qw($VERSION @ISA @EXPORT_OK $socket); +use vars qw($VERSION @ISA @EXPORT_OK $socket %autoload ); use Exporter; use Socket; use FileHandle; @@ -12,10 +12,19 @@ use Storable qw(nstore_fd fd_retrieve); $VERSION = '0.03'; @ISA = qw( Exporter ); -@EXPORT_OK = qw( passwd ); $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', +); +@EXPORT_OK = keys %autoload; + $ENV{'PATH'} ='/usr/bin:/usr/ucb:/bin'; $ENV{'SHELL'} = '/bin/sh'; $ENV{'IFS'} = " \t\n"; @@ -49,17 +58,25 @@ Returns the empty value on success, or an error message on errors. =cut -sub passwd { - my $param; - if ( ref($_[0]) ) { - $param = shift; - } else { - $param = { @_ }; - } +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); + }'; - $param->{_packet} = 'passwd'; + eval $eval; + die $@ if $@; - simple_packet($param); } sub simple_packet { @@ -78,7 +95,7 @@ sub simple_packet { my $return = fd_retrieve(\*SOCK) or die "error reading result: $!"; die $return->{'_error'} if defined $return->{_error} && $return->{_error}; - $return->{'error'}; + $return; } =back diff --git a/fs_selfservice/FS-SelfService/cgi/login.html b/fs_selfservice/FS-SelfService/cgi/login.html new file mode 100644 index 000000000..dfbd0137a --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/login.html @@ -0,0 +1,23 @@ +Login +Login

+<%= $error %> +
+ + + + + + + + + + + + + + + +
Username
Domain
Password
+

+
+ diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount.html b/fs_selfservice/FS-SelfService/cgi/myaccount.html new file mode 100644 index 000000000..f8a916eea --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/myaccount.html @@ -0,0 +1,47 @@ +MyAccount +MyAccount

+<%= $url = "$selfurl?session=$session_id;action="; ''; %> +
+MyAccount
+SomethingElse
+
+ +Hello <%= $name %>!

+Your customer number is <%= $custnum %>

+Your contact information
<%= $small_custview %> +Your outstanding balance is $<%= $balance %>

+ +<%= + if ( @open_invoices ) { + $OUT .= ''. + '$td${a}Invoice #". $invoice->{'invnum'}. "$td". + "$td$a". $invoice->{'date'}. "$td". + qq!'. + ''; + $col = $col eq $col1 ? $col2 : $col1; + } + $OUT .= '
Open Invoices'; + my $link = qq!!; + my $a=qq!'; + $OUT .= + "
$a\$!. $invoice->{'owed'}. + '
'; + } else { + $OUT .= 'You have no outstanding invoices.

'; + } +%> + +
+
+small text + + + + diff --git a/fs_selfservice/FS-SelfService/cgi/selfservice.cgi b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi new file mode 100644 index 000000000..eae373931 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/selfservice.cgi @@ -0,0 +1,109 @@ +#!/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); + +$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)$/ + 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'}}); + +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 do_template { + my $name = shift; + my $fill_in = shift; + + $cgi->delete_all(); + $fill_in->{'self_url'} = $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..33388de99 --- /dev/null +++ b/fs_selfservice/FS-SelfService/cgi/view_invoice.html @@ -0,0 +1,21 @@ +MyAccount +MyAccount

+<%= $url = "$selfurl?session=$session_id;action="; ''; %> +
+MyAccount
+SomethingElse
+
+ +<-- back to MyAccount

+ +
+<%= $invoice_text %>
+
+ +
+
+small text + + + + diff --git a/fs_selfservice/FS-SelfService/freeside-selfservice-clientd b/fs_selfservice/FS-SelfService/freeside-selfservice-clientd index 319d4254f..0c25c3407 100644 --- a/fs_selfservice/FS-SelfService/freeside-selfservice-clientd +++ b/fs_selfservice/FS-SelfService/freeside-selfservice-clientd @@ -17,7 +17,7 @@ use IO::File; STDOUT->setbuf(''); use vars qw( $Debug ); -$Debug = 2; #2 will turn on child logging, 3 will log packet contents, +$Debug = 3; #2 will turn on child logging, 3 will log packet contents, #including potentially compromising information my $socket = "/usr/local/freeside/selfservice_socket"; -- cgit v1.2.1