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