- mysql 4.1 is available; update documentation
[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 #  my $old_domain_record = $old->domain_record; # or die ?
62 #  my $old_zone = $old_domain_record->reczone; # or die ?
63 #  unless ( $old_zone =~ /\.$/ ) {
64 #    my $old_svc_domain = $old_domain_record->svc_domain; # or die ?
65 #    $old_zone .= '.'. $old_svc_domain->domain;
66 #  }
67 #
68 #  my $old_svc_acct = $old->svc_acct; # or die ?
69 #  my $old_username = $old_svc_acct->username;
70 #  my $old_homedir = $old_svc_acct->dir; # or die ?
71 #
72 #  my $new_domain_record = $new->domain_record; # or die ?
73 #  my $new_zone = $new_domain_record->reczone; # or die ?
74 #  unless ( $new_zone =~ /\.$/ ) {
75 #    my $new_svc_domain = $new_domain_record->svc_domain; # or die ?
76 #    $new_zone .= '.'. $new_svc_domain->domain;
77 #  }
78
79 #  my $new_svc_acct = $new->svc_acct; # or die ?
80 #  my $new_username = $new_svc_acct->username;
81 #  my $new_homedir = $new_svc_acct->dir; # or die ?
82
83   #done setting variables for the command
84
85   $self->shellcommands_queue( $new->svcnum,
86     user         => $self->option('user')||'root',
87     host         => $self->machine,
88     command      => eval(qq("$command")),
89   );
90 }
91
92 #a good idea to queue anything that could fail or take any time
93 sub shellcommands_queue {
94   my( $self, $svcnum ) = (shift, shift);
95   my $queue = new FS::queue {
96     'svcnum' => $svcnum,
97     'job'    => "FS::part_export::domain_shellcommands::ssh_cmd",
98   };
99   $queue->insert( @_ );
100 }
101
102 sub ssh_cmd { #subroutine, not method
103   use Net::SSH '0.07';
104   &Net::SSH::ssh_cmd( { @_ } );
105 }
106
107 #sub shellcommands_insert { #subroutine, not method
108 #}
109 #sub shellcommands_replace { #subroutine, not method
110 #}
111 #sub shellcommands_delete { #subroutine, not method
112 #}
113