summaryrefslogtreecommitdiff
path: root/FS/FS/part_export/cardfortress.pm
blob: ae8e2966f44dcfd8ff783d5b4f04374217c5c8bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package FS::part_export::cardfortress;

use strict;
use base 'FS::part_export';
use vars qw( %info );
use String::ShellQuote;
use Net::OpenSSH;

#tie my %options, 'Tie::IxHash';
#;

%info = (
  'svc'      => 'svc_acct',
  'desc'     => 'CardFortress',
  'options'  => {}, #\%options,
  'nodomain' => 'Y',
  'notes'    => '',
);

sub rebless { shift; }

sub _export_insert {
  my($self, $svc_acct) = (shift, shift);


  open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
  my $ssh = Net::OpenSSH->new( $self->machine,
                               default_stdin_fh => $def_in );

  #capture2 and return STDERR, its probably useful if there's a problem
  my $private_key = $ssh->capture(
    { 'stdin_data' => $svc_acct->_password. "\n" },
    '/usr/local/bin/merchant_create', map $svc_acct->$_, qw( username finger )
  );
  return $ssh->error if $ssh->error;

  $svc_acct->cf_privatekey($private_key);

  $svc_acct->replace;

}

sub _export_replace {
  my( $self, $new, $old ) = (shift, shift, shift);

  return 'username changes not yet supported'
    if $old->username ne $new->username;

  return 'password changes not yet supported'
    if $old->_password ne $new->_password;

  return 'Real name changes not yet supported'
    if $old->finger ne $new->finger;

  '';
}

#well, we're just going to disable them for now, but there you go
sub _export_delete    { shift->merchant_disable(@_) }

sub _export_suspend   { shift->merchant_disable(@_) }

sub _export_unsuspend { shift->merchant_enable(@_) }

sub merchant_disable {
  my( $self, $svc_acct ) = (shift, shift);

  open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
  my $ssh = Net::OpenSSH->new( $self->machine,
                               default_stdin_fh => $def_in );

  #capture2 and return STDERR, its probably useful if there's a problem
  my $unused_output = $ssh->capture(
    '/usr/local/bin/merchant_disable', map $svc_acct->$_, qw( username )
  );
  return $ssh->error if $ssh->error;

  '';

}

sub merchant_enable {
  my( $self, $svc_acct ) = (shift, shift);

  open my $def_in, '<', '/dev/null' or die "unable to open /dev/null";
  my $ssh = Net::OpenSSH->new( $self->machine,
                               default_stdin_fh => $def_in );

  #capture2 and return STDERR, its probably useful if there's a problem
  my $unused_output = $ssh->capture(
    '/usr/local/bin/merchant_enable', map $svc_acct->$_, qw( username )
  );
  return $ssh->error if $ssh->error;

  '';

}

1;