point people at DBI/DBD documentation for information on data sources. *sigh*
[freeside.git] / FS / FS / part_export / shellcommands.pm
1 package FS::part_export::shellcommands;
2
3 use vars qw(@ISA);
4 use FS::part_export;
5
6 @ISA = qw(FS::part_export);
7
8 sub rebless { shift; }
9
10 sub _export_insert {
11   my($self) = shift;
12   $self->_export_command('useradd', @_);
13 }
14
15 sub _export_delete {
16   my($self) = shift;
17   $self->_export_command('userdel', @_);
18 }
19
20 sub _export_command {
21   my ( $self, $action, $svc_acct) = (shift, shift, shift);
22   my $command = $self->option($action);
23   no strict 'refs';
24   ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields;
25   $self->shellcommands_queue( $svc_acct->svcnum,
26     $self->options('user')||'root'. "\@". $self->options('machine'),
27     eval(qq("$command"))
28   );
29 }
30
31 sub _export_replace {
32   my($self, $new, $old ) = (shift, shift, shift);
33   my $command = $self->option('usermod');
34   no strict 'refs';
35   ${"old_$_"} = $old->getfield($_) foreach $old->fields;
36   ${"new_$_"} = $new->getfield($_) foreach $new->fields;
37   $self->shellcommands_queue( $new->svcnum,
38     $self->options('user')||'root'. "\@". $self->options('machine'),
39     eval(qq("$command"))
40   );
41 }
42
43 #a good idea to queue anything that could fail or take any time
44 sub shellcommands_queue {
45   my( $self, $svcnum ) = (shift, shift);
46   my $queue = new FS::queue {
47     'svcnum' => $svcnum,
48     'job'    => "Net::SSH::ssh_cmd", #freeside-queued pre-uses...
49   };
50   $queue->insert( @_ );
51 }
52
53 #sub shellcommands_insert { #subroutine, not method
54 #}
55 #sub shellcommands_replace { #subroutine, not method
56 #}
57 #sub shellcommands_delete { #subroutine, not method
58 #}
59