RT# 83450 - fixed rateplan export
[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 #well, we're just going to disable them for now, but there you go
59 sub _export_delete    { shift->merchant_disable(@_) }
60
61 sub _export_suspend   { shift->merchant_disable(@_) }
62
63 sub _export_unsuspend { shift->merchant_enable(@_) }
64
65 sub merchant_disable {
66   my( $self, $svc_acct ) = (shift, shift);
67
68   open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
69   my $ssh = Net::OpenSSH->new( $self->machine,
70                                default_stdin_fh => $def_in );
71
72   #capture2 and return STDERR, its probably useful if there's a problem
73   my $unused_output = $ssh->capture(
74     '/usr/local/bin/merchant_disable', map $svc_acct->$_, qw( username )
75   );
76   return $ssh->error if $ssh->error;
77
78   '';
79
80 }
81
82 sub merchant_enable {
83   my( $self, $svc_acct ) = (shift, shift);
84
85   open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
86   my $ssh = Net::OpenSSH->new( $self->machine,
87                                default_stdin_fh => $def_in );
88
89   #capture2 and return STDERR, its probably useful if there's a problem
90   my $unused_output = $ssh->capture(
91     '/usr/local/bin/merchant_enable', map $svc_acct->$_, qw( username )
92   );
93   return $ssh->error if $ssh->error;
94
95   '';
96
97 }
98
99 1;