- depend on Net::SSH 0.07, for OpenSSH -T fix
[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
32 #  my $domain_record = $svc_www->domain_record; # or die ?
33 #  my $zone = $domain_record->reczone; # or die ?
34 #  unless ( $zone =~ /\.$/ ) {
35 #    my $svc_domain = $domain_record->svc_domain; # or die ?
36 #    $zone .= '.'. $svc_domain->domain;
37 #  }
38
39 #  my $svc_acct = $svc_www->svc_acct; # or die ?
40 #  my $username = $svc_acct->username;
41 #  my $homedir = $svc_acct->dir; # or die ?
42
43   #done setting variables for the command
44
45   $self->shellcommands_queue( $svc_domain->svcnum,
46     user         => $self->option('user')||'root',
47     host         => $self->machine,
48     command      => eval(qq("$command")),
49   );
50 }
51
52 sub _export_replace {
53   my($self, $new, $old ) = (shift, shift, shift);
54   my $command = $self->option('usermod');
55   
56   #set variable for the command
57   no strict 'vars';
58   {
59     no strict 'refs';
60     ${"old_$_"} = $old->getfield($_) foreach $old->fields;
61     ${"new_$_"} = $new->getfield($_) foreach $new->fields;
62   }
63 #  my $old_domain_record = $old->domain_record; # or die ?
64 #  my $old_zone = $old_domain_record->reczone; # or die ?
65 #  unless ( $old_zone =~ /\.$/ ) {
66 #    my $old_svc_domain = $old_domain_record->svc_domain; # or die ?
67 #    $old_zone .= '.'. $old_svc_domain->domain;
68 #  }
69 #
70 #  my $old_svc_acct = $old->svc_acct; # or die ?
71 #  my $old_username = $old_svc_acct->username;
72 #  my $old_homedir = $old_svc_acct->dir; # or die ?
73 #
74 #  my $new_domain_record = $new->domain_record; # or die ?
75 #  my $new_zone = $new_domain_record->reczone; # or die ?
76 #  unless ( $new_zone =~ /\.$/ ) {
77 #    my $new_svc_domain = $new_domain_record->svc_domain; # or die ?
78 #    $new_zone .= '.'. $new_svc_domain->domain;
79 #  }
80
81 #  my $new_svc_acct = $new->svc_acct; # or die ?
82 #  my $new_username = $new_svc_acct->username;
83 #  my $new_homedir = $new_svc_acct->dir; # or die ?
84
85   #done setting variables for the command
86
87   $self->shellcommands_queue( $new->svcnum,
88     user         => $self->option('user')||'root',
89     host         => $self->machine,
90     command      => eval(qq("$command")),
91   );
92 }
93
94 #a good idea to queue anything that could fail or take any time
95 sub shellcommands_queue {
96   my( $self, $svcnum ) = (shift, shift);
97   my $queue = new FS::queue {
98     'svcnum' => $svcnum,
99     'job'    => "FS::part_export::domain_shellcommands::ssh_cmd",
100   };
101   $queue->insert( @_ );
102 }
103
104 sub ssh_cmd { #subroutine, not method
105   use Net::SSH '0.07';
106   &Net::SSH::ssh_cmd( { @_ } );
107 }
108
109 #sub shellcommands_insert { #subroutine, not method
110 #}
111 #sub shellcommands_replace { #subroutine, not method
112 #}
113 #sub shellcommands_delete { #subroutine, not method
114 #}
115