This commit was generated by cvs2svn to compensate for changes in r2523,
[freeside.git] / FS / FS / part_export / www_shellcommands.pm
1 package FS::part_export::www_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_www) = (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_www->getfield($_) foreach $svc_www->fields;
30   }
31   my $domain_record = $svc_www->domain_record; # or die ?
32   my $zone = $domain_record->zone; # or die ?
33   my $svc_acct = $svc_www->svc_acct; # or die ?
34   my $username = $svc_acct->username;
35   my $homedir = $svc_acct->dir; # or die ?
36
37   #done setting variables for the command
38
39   $self->shellcommands_queue( $svc_www->svcnum,
40     user         => $self->option('user')||'root',
41     host         => $self->machine,
42     command      => eval(qq("$command")),
43   );
44 }
45
46 sub _export_replace {
47   my($self, $new, $old ) = (shift, shift, shift);
48   my $command = $self->option('usermod');
49   
50   #set variable for the command
51   no strict 'vars';
52   {
53     no strict 'refs';
54     ${"old_$_"} = $old->getfield($_) foreach $old->fields;
55     ${"new_$_"} = $new->getfield($_) foreach $new->fields;
56   }
57   my $old_domain_record = $old->domain_record; # or die ?
58   my $old_zone = $old_domain_record->reczone; # or die ?
59   unless ( $old_zone =~ /\.$/ ) {
60     my $old_svc_domain = $old_domain_record->svc_domain; # or die ?
61     $old_zone .= '.'. $old_svc_domain->domain;
62   }
63
64   my $old_svc_acct = $old->svc_acct; # or die ?
65   my $old_username = $old_svc_acct->username;
66   my $old_homedir = $old_svc_acct->dir; # or die ?
67
68   my $new_domain_record = $new->domain_record; # or die ?
69   my $new_zone = $new_domain_record->reczone; # or die ?
70   unless ( $new_zone =~ /\.$/ ) {
71     my $new_svc_domain = $new_domain_record->svc_domain; # or die ?
72     $new_zone .= '.'. $new_svc_domain->domain;
73   }
74
75   my $new_svc_acct = $new->svc_acct; # or die ?
76   my $new_username = $new_svc_acct->username;
77   my $new_homedir = $new_svc_acct->dir; # or die ?
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::www_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