From 6ff02eb18af2dd61ce2dca064414ca183fa02e6e Mon Sep 17 00:00:00 2001 From: ivan Date: Tue, 16 Jul 2002 12:28:02 +0000 Subject: [PATCH] invoice viewing... --- fs_selfservice/DEPLOY | 7 ++ 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 +- fs_selfservice/freeside-selfservice-server | 74 ++------------ fs_selfservice/fs_passwd_test | 3 +- 9 files changed, 246 insertions(+), 81 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 diff --git a/fs_selfservice/DEPLOY b/fs_selfservice/DEPLOY index 9b03bf259..7c68e78ec 100755 --- a/fs_selfservice/DEPLOY +++ b/fs_selfservice/DEPLOY @@ -1,8 +1,15 @@ #!/bin/sh +( cd ..; make deploy; cd fs_selfservice ) + cd FS-SelfService perl Makefile.PL && make && make install cd .. kill `cat /var/run/freeside-selfservice-server.ivan.pid`; sleep 3 ./freeside-selfservice-server ivan localhost + +cp /home/ivan/freeside_current/fs_selfservice/FS-SelfService/cgi/* /var/www/MyAccount +chown freeside /var/www/MyAccount/selfservice.cgi +chmod 4755 /var/www/MyAccount/selfservice.cgi +ln -s /var/www/MyAccount/selfservice.cgi /var/www/MyAccount/index.cgi 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"; diff --git a/fs_selfservice/freeside-selfservice-server b/fs_selfservice/freeside-selfservice-server index 0e1c75e43..e55ca4984 100644 --- a/fs_selfservice/freeside-selfservice-server +++ b/fs_selfservice/freeside-selfservice-server @@ -16,17 +16,10 @@ use IO::Select; use IO::File; use Storable qw(nstore_fd fd_retrieve); use Net::SSH qw(sshopen2); - use FS::UID qw(adminsuidsetup forksuidsetup); +use FS::ClientAPI; -#use Tie::RefHash; -#use FS::Conf; -#use FS::Record qw( qsearch qsearchs ); -#use FS::cust_main_county; -#use FS::cust_main; -#use FS::Msgcat qw(gettext); - -$Debug = 1; # >= 2 will log packet contents, including potentially compromising +$Debug = 2; # >= 2 will log packet contents, including potentially compromising # information $shutdown = 0; @@ -42,13 +35,6 @@ my $pid_file = "/var/run/freeside-selfservice-server.$user.pid"; my $clientd = "/usr/local/sbin/freeside-selfservice-clientd"; #better name? -my %dispatch = ( - 'signup' => \&signup, - #'signup_init' => 'signup_init', - 'passwd' => \&passwd, - -); - my $warnkids=0; while (1) { my($writer,$reader,$error) = (new IO::Handle, new IO::Handle, new IO::Handle); @@ -102,13 +88,11 @@ while (1) { $FS::UID::dbh->{InactiveDestroy} = 1; forksuidsetup($user); - my $sub = $dispatch{$packet->{_packet}}; - my $rv; - if ( $sub ) { - warn "calling $sub handler\n" if $Debug; - $rv = &{$sub}($packet); - } else { - warn my $error = "WARNING: unknown packet type ". $packet->{_packet}; + my $type = $packet->{_packet}; + warn "calling $type handler\n" if $Debug; + my $rv = eval { FS::ClientAPI->dispatch($type, $packet); }; + if ( $@ ) { + warn my $error = "WARNING: error dispatching $type: $@"; $rv = { _error => $error }; } $rv->{_token} = $packet->{_token}; #identifier @@ -128,50 +112,6 @@ while (1) { } ### -# dispatch subroutines (should live elsewhere eventually) -### - -sub passwd { - #sleep 3; - use FS::Record qw(qsearchs); - use FS::svc_acct; - #use FS::svc_domain; - - my $packet = shift; - - #my $domain = qsearchs('svc_domain', { 'domain' => $packet->{'domain'} } ) - # or return { error => "Domain $domain not found" }; - - my $old_password = $packet->{'old_password'}; - my $new_password = $packet->{'new_password'}; - my $new_gecos = $packet->{'new_gecos'}; - my $new_shell = $packet->{'new_shell'}; - - my $svc_acct = - ( length($old_password) < 13 - && qsearchs( 'svc_acct', { 'username' => $packet->{'username'}, - #'domsvc' => $svc_domain->domsvc, - '_password' => $old_password } ) - ) - || qsearchs( 'svc_acct', { 'username' => $packet->{'username'}, - #'domsvc' => $svc_domain->domsvc, - '_password' => $old_password } ); - - unless ( $svc_acct ) { return { error => 'Incorrect password.' } } - - my %hash = $svc_acct->hash; - my $new_svc_acct = new FS::svc_acct ( \%hash ); - $new_svc_acct->setfield('_password', $new_password ) - if $new_password && $new_password ne $old_password; - $new_svc_acct->setfield('finger',$new_gecos) if $new_gecos; - $new_svc_acct->setfield('shell',$new_shell) if $new_shell; - my $error = $new_svc_acct->replace($svc_acct); - - return { error => $error }; - -} - -### # utility subroutines ### diff --git a/fs_selfservice/fs_passwd_test b/fs_selfservice/fs_passwd_test index c6a297968..4f8b8a888 100755 --- a/fs_selfservice/fs_passwd_test +++ b/fs_selfservice/fs_passwd_test @@ -3,11 +3,12 @@ use strict; use FS::SelfService qw(passwd); -my $error = passwd( +my $rv = passwd( 'username' => 'ivan', 'old_password' => 'heyhoo', 'new_password' => 'haloo', ); +my $error = $rv->{error}; if ( $error eq 'Incorrect password.' ) { exit; -- 2.11.0