This commit was generated by cvs2svn to compensate for changes in r2523,
[freeside.git] / FS / FS / part_export / domain_shellcommands.pm
1 package FS::part_export::domain_shellcommands;
2
3 use strict;
4 use vars qw(@ISA);
5 use FS::part_export;
6
7 @ISA = qw(FS::part_export);
8
9 sub rebless { shift; }
10
11 sub _export_insert {
12   my($self) = shift;
13   $self->_export_command('useradd', @_);
14 }
15
16 sub _export_delete {
17   my($self) = shift;
18   $self->_export_command('userdel', @_);
19 }
20
21 sub _export_command {
22   my ( $self, $action, $svc_domain) = (shift, shift, shift);
23   my $command = $self->option($action);
24
25   #set variable for the command
26   no strict 'vars';
27   {
28     no strict 'refs';
29     ${$_} = $svc_domain->getfield($_) foreach $svc_domain->fields;
30   }
31   ( $qdomain = $domain ) =~ s/\./:/g; #see dot-qmail(5): EXTENSION ADDRESSES
32
33   if ( $svc_domain->catchall ) {
34     no strict 'refs';
35     my $svc_acct = $svc_domain->catchall_svc_acct;
36     ${$_} = $svc_acct->getfield($_) foreach qw(uid gid dir);
37   } else {
38     ${$_} = '' foreach qw(uid gid dir);
39   }
40
41   #done setting variables for the command
42
43   $self->shellcommands_queue( $svc_domain->svcnum,
44     user         => $self->option('user')||'root',
45     host         => $self->machine,
46     command      => eval(qq("$command")),
47   );
48 }
49
50 sub _export_replace {
51   my($self, $new, $old ) = (shift, shift, shift);
52   my $command = $self->option('usermod');
53   
54   #set variable for the command
55   no strict 'vars';
56   {
57     no strict 'refs';
58     ${"old_$_"} = $old->getfield($_) foreach $old->fields;
59     ${"new_$_"} = $new->getfield($_) foreach $new->fields;
60   }
61   ( $old_qdomain = $old_domain ) =~ s/\./:/g; #see dot-qmail(5): EXTENSION ADDRESSES
62   ( $new_qdomain = $new_domain ) =~ s/\./:/g; #see dot-qmail(5): EXTENSION ADDRESSES
63
64   if ( $old->catchall ) {
65     no strict 'refs';
66     my $svc_acct = $old->catchall_svc_acct;
67     ${"old_$_"} = $svc_acct->getfield($_) foreach qw(uid gid dir);
68   } else {
69     ${"old_$_"} = '' foreach qw(uid gid dir);
70   }
71   if ( $new->catchall ) {
72     no strict 'refs';
73     my $svc_acct = $new->catchall_svc_acct;
74     ${"new_$_"} = $svc_acct->getfield($_) foreach qw(uid gid dir);
75   } else {
76     ${"new_$_"} = '' foreach qw(uid gid dir);
77   }
78
79   #done setting variables for the command
80
81   $self->shellcommands_queue( $new->svcnum,
82     user         => $self->option('user')||'root',
83     host         => $self->machine,
84     command      => eval(qq("$command")),
85   );
86 }
87
88 #a good idea to queue anything that could fail or take any time
89 sub shellcommands_queue {
90   my( $self, $svcnum ) = (shift, shift);
91   my $queue = new FS::queue {
92     'svcnum' => $svcnum,
93     'job'    => "FS::part_export::domain_shellcommands::ssh_cmd",
94   };
95   $queue->insert( @_ );
96 }
97
98 sub ssh_cmd { #subroutine, not method
99   use Net::SSH '0.07';
100   &Net::SSH::ssh_cmd( { @_ } );
101 }
102
103 #sub shellcommands_insert { #subroutine, not method
104 #}
105 #sub shellcommands_replace { #subroutine, not method
106 #}
107 #sub shellcommands_delete { #subroutine, not method
108 #}
109