1 package FS::part_export::domain_shellcommands;
4 use vars qw(@ISA %info);
8 @ISA = qw(FS::part_export);
10 tie my %options, 'Tie::IxHash',
11 'user' => { label=>'Remote username', default=>'root' },
12 'useradd' => { label=>'Insert command',
15 'userdel' => { label=>'Delete command',
18 'usermod' => { label=>'Modify command',
24 'svc' => 'svc_domain',
25 'desc' => 'Run remote commands via SSH, for domains (qmail, ISPMan).',
26 'options' => \%options,
28 Run remote commands via SSH, for domains. You will need to
29 <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.9:Documentation:Administration:SSH_Keys">setup SSH for unattended operation</a>.
30 <BR><BR>Use these buttons for some useful presets:
33 <INPUT TYPE="button" VALUE="qmail catchall .qmail-domain-default maintenance" onClick='
34 this.form.useradd.value = "[ \"$uid\" -a \"$gid\" -a \"$dir\" -a \"$qdomain\" ] && [ -e $dir/.qmail-$qdomain-default ] || { touch $dir/.qmail-$qdomain-default; chown $uid:$gid $dir/.qmail-$qdomain-default; }";
35 this.form.userdel.value = "";
36 this.form.usermod.value = "";
39 <INPUT TYPE="button" VALUE="ISPMan CLI" onClick='
40 this.form.useradd.value = "/usr/local/ispman/bin/ispman.addDomain -d $domain changeme";
41 this.form.userdel.value = "/usr/local/ispman/bin/ispman.deleteDomain -d $domain";
42 this.form.usermod.value = "";
45 The following variables are available for interpolation (prefixed with <code>new_</code> or <code>old_</code> for replace operations):
47 <LI><code>$domain</code>
48 <LI><code>$qdomain</code> - domain with periods replaced by colons
49 <LI><code>$uid</code> - of catchall account
50 <LI><code>$gid</code> - of catchall account
51 <LI><code>$dir</code> - home directory of catchall account
52 <LI>All other fields in
53 <a href="../docs/schema.html#svc_domain">svc_domain</a> are also available.
58 sub rebless { shift; }
62 $self->_export_command('useradd', @_);
67 $self->_export_command('userdel', @_);
71 my ( $self, $action, $svc_domain) = (shift, shift, shift);
72 my $command = $self->option($action);
73 return '' if $command =~ /^\s*$/;
75 #set variable for the command
79 ${$_} = $svc_domain->getfield($_) foreach $svc_domain->fields;
81 ( $qdomain = $domain ) =~ s/\./:/g; #see dot-qmail(5): EXTENSION ADDRESSES
83 if ( $svc_domain->catchall ) {
85 my $svc_acct = $svc_domain->catchall_svc_acct;
86 ${$_} = $svc_acct->getfield($_) foreach qw(uid gid dir);
89 ${$_} = '' foreach qw(uid gid dir);
92 #done setting variables for the command
94 $self->shellcommands_queue( $svc_domain->svcnum,
95 user => $self->option('user')||'root',
96 host => $self->machine,
97 command => eval(qq("$command")),
101 sub _export_replace {
102 my($self, $new, $old ) = (shift, shift, shift);
103 my $command = $self->option('usermod');
105 #set variable for the command
109 ${"old_$_"} = $old->getfield($_) foreach $old->fields;
110 ${"new_$_"} = $new->getfield($_) foreach $new->fields;
112 ( $old_qdomain = $old_domain ) =~ s/\./:/g; #see dot-qmail(5): EXTENSION ADDRESSES
113 ( $new_qdomain = $new_domain ) =~ s/\./:/g; #see dot-qmail(5): EXTENSION ADDRESSES
118 if ( $old->catchall ) {
119 my $svc_acct = $old->catchall_svc_acct;
120 ${"old_$_"} = $svc_acct->getfield($_) foreach qw(uid gid dir);
122 ${"old_$_"} = '' foreach qw(uid gid dir);
124 if ( $new->catchall ) {
125 my $svc_acct = $new->catchall_svc_acct;
126 ${"new_$_"} = $svc_acct->getfield($_) foreach qw(uid gid dir);
128 ${"new_$_"} = '' foreach qw(uid gid dir);
133 #done setting variables for the command
135 $self->shellcommands_queue( $new->svcnum,
136 user => $self->option('user')||'root',
137 host => $self->machine,
138 command => eval(qq("$command")),
142 #a good idea to queue anything that could fail or take any time
143 sub shellcommands_queue {
144 my( $self, $svcnum ) = (shift, shift);
145 my $queue = new FS::queue {
147 'job' => "FS::part_export::domain_shellcommands::ssh_cmd",
149 $queue->insert( @_ );
152 sub ssh_cmd { #subroutine, not method
154 &Net::SSH::ssh_cmd( { @_ } );
157 #sub shellcommands_insert { #subroutine, not method
159 #sub shellcommands_replace { #subroutine, not method
161 #sub shellcommands_delete { #subroutine, not method