invoice viewing...
authorivan <ivan>
Tue, 16 Jul 2002 12:28:02 +0000 (12:28 +0000)
committerivan <ivan>
Tue, 16 Jul 2002 12:28:02 +0000 (12:28 +0000)
fs_selfservice/DEPLOY
fs_selfservice/FS-SelfService/SelfService.pm
fs_selfservice/FS-SelfService/cgi/login.html [new file with mode: 0644]
fs_selfservice/FS-SelfService/cgi/myaccount.html [new file with mode: 0644]
fs_selfservice/FS-SelfService/cgi/selfservice.cgi [new file with mode: 0644]
fs_selfservice/FS-SelfService/cgi/view_invoice.html [new file with mode: 0644]
fs_selfservice/FS-SelfService/freeside-selfservice-clientd
fs_selfservice/freeside-selfservice-server
fs_selfservice/fs_passwd_test

index 9b03bf2..7c68e78 100755 (executable)
@@ -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
index 3cd4fd9..9019ea4 100644 (file)
@@ -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 (file)
index 0000000..dfbd013
--- /dev/null
@@ -0,0 +1,23 @@
+<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 %>"></TD>
+</TR>
+<TR>
+  <TH ALIGN="right">Domain </TH>
+  <TD><INPUT TYPE="text" NAME="domain" VALUE="<%= $domain %>"></TD>
+</TR>
+<!--<INPUT TYPE="hidden" NAME="domain" VALUE="myisp.com">-->
+<TR>
+  <TH ALIGN="right">Password </TH>
+  <TD><INPUT TYPE="password" NAME="password"></TD>
+</TR>
+</TABLE>
+<BR><BR><INPUT TYPE="submit" VALUE="Login">
+</FORM></BODY></HTML>
+
diff --git a/fs_selfservice/FS-SelfService/cgi/myaccount.html b/fs_selfservice/FS-SelfService/cgi/myaccount.html
new file mode 100644 (file)
index 0000000..f8a916e
--- /dev/null
@@ -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>
+Your customer number is <%= $custnum %><BR><BR>
+Your contact information<BR><%= $small_custview %>
+Your outstanding balance is $<%= $balance %><BR><BR>
+<!--<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=2 BORDERCOLOR="#999999">
+<TR><TH>Invoice</TH><TH>Date</TH><TH>Owed</TH></TR>-->
+<%=
+  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="<%= $selfurl %>?session=<%= $session_id %>;action=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">small text</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 (file)
index 0000000..eae3739
--- /dev/null
@@ -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 (file)
index 0000000..33388de
--- /dev/null
@@ -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">small text</FONT>
+</BODY></HTML>
+
+
+
index 319d425..0c25c34 100644 (file)
@@ -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";
index 0e1c75e..e55ca49 100644 (file)
@@ -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
 ###
 
index c6a2979..4f8b8a8 100755 (executable)
@@ -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;