4.x+ self-service API: list and remove cards on file, RT#38919
[freeside.git] / FS / FS / part_export / cardfortress.pm
1 package FS::part_export::cardfortress;
2
3 use strict;
4 use base 'FS::part_export';
5 use vars qw( %info );
6 use String::ShellQuote;
7
8 #tie my %options, 'Tie::IxHash';
9 #;
10
11 %info = (
12   'svc'      => 'svc_acct',
13   'desc'     => 'CardFortress',
14   'options'  => {}, #\%options,
15   'nodomain' => 'Y',
16   'notes'    => '',
17 );
18
19 sub rebless { shift; }
20
21 sub _export_insert {
22   my($self, $svc_acct) = (shift, shift);
23
24   eval "use Net::OpenSSH;";
25   return $@ if $@;
26
27   open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
28   my $ssh = Net::OpenSSH->new( $self->machine,
29                                default_stdin_fh => $def_in );
30
31   #capture2 and return STDERR, its probably useful if there's a problem
32   my $private_key = $ssh->capture(
33     { 'stdin_data' => $svc_acct->_password. "\n" },
34     '/usr/local/bin/merchant_create', map $svc_acct->$_, qw( username finger )
35   );
36   return $ssh->error if $ssh->error;
37
38   $svc_acct->cf_privatekey($private_key);
39
40   $svc_acct->replace;
41
42 }
43
44 sub _export_replace {
45   my( $self, $new, $old ) = (shift, shift, shift);
46
47   return 'username changes not yet supported'
48     if $old->username ne $new->username;
49
50   return 'password changes not yet supported'
51     if $old->_password ne $new->_password;
52
53   return 'Real name changes not yet supported'
54     if $old->finger ne $new->finger;
55
56   '';
57 }
58
59 sub _export_delete {
60   my( $self, $svc_acct ) = (shift, shift);
61
62   #well, we're just going to disable them for now, but there you go
63
64   eval "use Net::OpenSSH;";
65   return $@ if $@;
66
67   open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
68   my $ssh = Net::OpenSSH->new( $self->machine,
69                                default_stdin_fh => $def_in );
70
71   #capture2 and return STDERR, its probably useful if there's a problem
72   my $unused_output = $ssh->capture(
73     '/usr/local/bin/merchant_disable', map $svc_acct->$_, qw( username )
74   );
75   return $ssh->error if $ssh->error;
76
77   '';
78
79 }
80
81 1;