From: ivan Date: Fri, 23 Aug 2002 23:43:51 +0000 (+0000) Subject: add domain_shellcommands export X-Git-Tag: freeside_1_4_1beta1~50 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=eb6cb474f653dc738b26c9f8ca9b43e9b6f1e546 add domain_shellcommands export --- diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm index 4f45fbeec..67b3cade5 100644 --- a/FS/FS/part_export.pm +++ b/FS/FS/part_export.pm @@ -594,6 +594,19 @@ tie my %www_shellcommands_options, 'Tie::IxHash', }, ; +tie my %domain_shellcommands_options, 'Tie::IxHash', + 'user' => { lable=>'Remote username', default=>'root' }, + 'useradd' => { label=>'Insert command', + default=>'', + }, + 'userdel' => { label=>'Delete command', + default=>'', + }, + 'usermod' => { label=>'Modify command', + default=>'', + }, +; + tie my %textradius_options, 'Tie::IxHash', 'user' => { label=>'Remote username', default=>'root' }, 'users' => { label=>'users file location', default=>'/etc/raddb/users' }, @@ -797,6 +810,12 @@ tie my %sqlmail_options, 'Tie::IxHash', 'notes' => 'Database schema can be made to work with Courier IMAP and Exim. Others could work but are untested. (...extended description from pc-intouch?...)', }, + 'domain_shellcommands' => { + 'desc' => 'Run remote commands via SSH, for domains.', + 'options' => \%domain_shellcommands_options, + 'notes' => 'Run remote commands via SSH, for domains. You will need to setup SSH for unattended operation.', + }, + }, diff --git a/FS/FS/part_export/domain_shellcommands.pm b/FS/FS/part_export/domain_shellcommands.pm new file mode 100644 index 000000000..d2f55e5ad --- /dev/null +++ b/FS/FS/part_export/domain_shellcommands.pm @@ -0,0 +1,113 @@ +package FS::part_export::domain_shellcommands; + +use strict; +use vars qw(@ISA); +use FS::part_export; + +@ISA = qw(FS::part_export); + +sub rebless { shift; } + +sub _export_insert { + my($self) = shift; + $self->_export_command('useradd', @_); +} + +sub _export_delete { + my($self) = shift; + $self->_export_command('userdel', @_); +} + +sub _export_command { + my ( $self, $action, $svc_domain) = (shift, shift, shift); + my $command = $self->option($action); + + #set variable for the command + { + no strict 'refs'; + ${$_} = $svc_domain->getfield($_) foreach $svc_domain->fields; + } + +# my $domain_record = $svc_www->domain_record; # or die ? +# my $zone = $domain_record->reczone; # or die ? +# unless ( $zone =~ /\.$/ ) { +# my $svc_domain = $domain_record->svc_domain; # or die ? +# $zone .= '.'. $svc_domain->domain; +# } + +# my $svc_acct = $svc_www->svc_acct; # or die ? +# my $username = $svc_acct->username; +# my $homedir = $svc_acct->dir; # or die ? + + #done setting variables for the command + + $self->shellcommands_queue( $svc_domain->svcnum, + user => $self->option('user')||'root', + host => $self->machine, + command => eval(qq("$command")), + ); +} + +sub _export_replace { + my($self, $new, $old ) = (shift, shift, shift); + my $command = $self->option('usermod'); + + #set variable for the command + { + no strict 'refs'; + ${"old_$_"} = $old->getfield($_) foreach $old->fields; + ${"new_$_"} = $new->getfield($_) foreach $new->fields; + } +# my $old_domain_record = $old->domain_record; # or die ? +# my $old_zone = $old_domain_record->reczone; # or die ? +# unless ( $old_zone =~ /\.$/ ) { +# my $old_svc_domain = $old_domain_record->svc_domain; # or die ? +# $old_zone .= '.'. $old_svc_domain->domain; +# } +# +# my $old_svc_acct = $old->svc_acct; # or die ? +# my $old_username = $old_svc_acct->username; +# my $old_homedir = $old_svc_acct->dir; # or die ? +# +# my $new_domain_record = $new->domain_record; # or die ? +# my $new_zone = $new_domain_record->reczone; # or die ? +# unless ( $new_zone =~ /\.$/ ) { +# my $new_svc_domain = $new_domain_record->svc_domain; # or die ? +# $new_zone .= '.'. $new_svc_domain->domain; +# } + +# my $new_svc_acct = $new->svc_acct; # or die ? +# my $new_username = $new_svc_acct->username; +# my $new_homedir = $new_svc_acct->dir; # or die ? + + #done setting variables for the command + + $self->shellcommands_queue( $new->svcnum, + user => $self->option('user')||'root', + host => $self->machine, + command => eval(qq("$command")), + ); +} + +#a good idea to queue anything that could fail or take any time +sub shellcommands_queue { + my( $self, $svcnum ) = (shift, shift); + my $queue = new FS::queue { + 'svcnum' => $svcnum, + 'job' => "FS::part_export::domain_shellcommands::ssh_cmd", + }; + $queue->insert( @_ ); +} + +sub ssh_cmd { #subroutine, not method + use Net::SSH '0.06'; + &Net::SSH::ssh_cmd( { @_ } ); +} + +#sub shellcommands_insert { #subroutine, not method +#} +#sub shellcommands_replace { #subroutine, not method +#} +#sub shellcommands_delete { #subroutine, not method +#} + diff --git a/FS/MANIFEST b/FS/MANIFEST index 8355e40fb..5737d620f 100644 --- a/FS/MANIFEST +++ b/FS/MANIFEST @@ -59,6 +59,7 @@ FS/part_export/bind_slave.pm FS/part_export/bsdshell.pm FS/part_export/cp.pm FS/part_export/cyrus.pm +FS/part_export/domain_shellcommands.pm FS/part_export/http.pm FS/part_export/infostreet.pm FS/part_export/null.pm @@ -132,6 +133,7 @@ t/part_export-bind_slave.t t/part_export-bsdshell.t t/part_export-cp.t t/part_export-cyrus.t +t/part_export-domain_shellcommands.t t/part_export-http.t t/part_export-infostreet.t t/part_export-null.t diff --git a/FS/t/part_export-domain_shellcommands.t b/FS/t/part_export-domain_shellcommands.t new file mode 100644 index 000000000..a2a44fbfb --- /dev/null +++ b/FS/t/part_export-domain_shellcommands.t @@ -0,0 +1,5 @@ +BEGIN { $| = 1; print "1..1\n" } +END {print "not ok 1\n" unless $loaded;} +use FS::part_export::domain_shellcommands; +$loaded=1; +print "ok 1\n";