{
'key' => 'apacheroot',
- 'section' => 'apache',
- 'description' => 'The directory containing Apache virtual hosts',
+ 'section' => 'deprecated',
+ 'description' => '<b>DEPRECATED</b>, add a <i>www_shellcommands</i> <a href="../browse/part_export.cgi">export</a> instead. The directory containing Apache virtual hosts',
'type' => 'text',
},
{
'key' => 'apachemachine',
- 'section' => 'apache',
- 'description' => 'A machine with the apacheroot directory and user home directories. The existance of this file enables setup of virtual host directories, and, in conjunction with the `home\' configuration file, symlinks into user home directories.',
+ 'section' => 'deprecated',
+ 'description' => '<b>DEPRECATED</b>, add a <i>www_shellcommands</i> <a href="../browse/part_export.cgi">export</a> instead. A machine with the apacheroot directory and user home directories. The existance of this file enables setup of virtual host directories, and, in conjunction with the `home\' configuration file, symlinks into user home directories.',
'type' => 'text',
},
},
'useradd_stdin' => { label=>'Insert command STDIN',
type =>'textarea',
- default=>"",
+ default=>'',
},
'userdel' => { label=>'Delete command',
default=>'userdel $username',
},
'usermod_stdin' => { label=>'Modify command STDIN',
type =>'textarea',
- default=>"",
+ default=>'',
},
;
},
;
+tie my %www_shellcommands_options, 'Tie::IxHash',
+ 'user' => { lable=>'Remote username', default=>'root' },
+ 'useradd' => { label=>'Insert command',
+ default=>'mkdir /var/www/$zone; chown $username /var/www/$zone; ln -s /var/www/$zone $homedir/$zone',
+ },
+ 'userdel' => { label=>'Delete command',
+ default=>'[ -n "$zone" ] && rm -rf /var/www/$zone; rm $homedir/$zone',
+ },
+ 'usermod' => { label=>'Modify command',
+ default=>'[ -n "$old_zone" ] && rm $old_homedir/$old_zone; [ "$old_zone" != "$new_zone" -a -n "$new_zone" ] && mv /var/www/$old_zone /var/www/$new_zone; [ "$old_username" != "$new_username" ] && chown -R $new_username /var/www/$new_zone; ln -s /var/www/$new_zone $new_homedir/$new_zone',
+ },
+;
+
tie my %textradius_options, 'Tie::IxHash',
'user' => { label=>'Remote username', default=>'root' },
'users' => { label=>'users file location', default=>'/etc/raddb/users' },
'svc_www' => {
'www_shellcommands' => {
- 'desc' => 'www_shellcommands',
- 'options' => {}, # \%www_shellcommands_options,
- 'notes' => 'unfinished...',
+ 'desc' => 'Run remote commands via SSH, for virtual web sites.',
+ 'options' => \%www_shellcommands_options,
+ 'notes' => 'Run remote commands via SSH, for virtual web sites. You will need to <a href="../docs/ssh.html">setup SSH for unattended operation</a>.',
},
},
-package FS::part_export::shellcommands;
+package FS::part_export::www_shellcommands;
+use strict;
use vars qw(@ISA);
use FS::part_export;
}
sub _export_command {
- my ( $self, $action, $svc_acct) = (shift, shift, shift);
+ my ( $self, $action, $svc_www) = (shift, shift, shift);
my $command = $self->option($action);
- my $stdin = $self->option($action."_stdin");
- no strict 'refs';
- ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields;
- $self->shellcommands_queue( $svc_acct->svcnum,
+
+ #set variable for the command
+ {
+ no strict 'refs';
+ ${$_} = $svc_www->getfield($_) foreach $svc_www->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_www->svcnum,
user => $self->option('user')||'root',
host => $self->machine,
command => eval(qq("$command")),
- stdin_string => eval(qq("$stdin")),
);
}
sub _export_replace {
my($self, $new, $old ) = (shift, shift, shift);
my $command = $self->option('usermod');
- my $stdin = $self->option('usermod_stdin');
- no strict 'refs';
- ${"old_$_"} = $old->getfield($_) foreach $old->fields;
- ${"new_$_"} = $new->getfield($_) foreach $new->fields;
+
+ #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")),
- stdin_string => eval(qq("$stdin")),
);
}
my( $self, $svcnum ) = (shift, shift);
my $queue = new FS::queue {
'svcnum' => $svcnum,
- 'job' => "FS::part_export::shellcommands::ssh_cmd",
+ 'job' => "FS::part_export::www_shellcommands::ssh_cmd",
};
$queue->insert( @_ );
}
package FS::svc_www;
use strict;
-use vars qw(@ISA $conf $apacheroot $apachemachine $apacheip $nossh_hack );
+use vars qw(@ISA $conf $apacheip);
#use FS::Record qw( qsearch qsearchs );
use FS::Record qw( qsearchs dbh );
use FS::svc_Common;
use FS::domain_record;
use FS::svc_acct;
use FS::svc_domain;
-use Net::SSH qw(ssh);
@ISA = qw( FS::svc_Common );
#ask FS::UID to run this stuff for us later
$FS::UID::callback{'FS::svc_www'} = sub {
$conf = new FS::Conf;
- $apacheroot = $conf->config('apacheroot');
- $apachemachine = $conf->config('apachemachine');
$apacheip = $conf->config('apacheip');
};
The additional fields pkgnum and svcpart (see L<FS::cust_svc>) should be
defined. An FS::cust_svc record will be created and inserted.
-If the configuration values (see L<FS::Conf>) I<apachemachine>, and
-I<apacheroot> exist, the command:
-
- mkdir $apacheroot/$zone;
- chown $username $apacheroot/$zone;
- ln -s $apacheroot/$zone $homedir/$zone
-
-I<$zone> is the DNS A record pointed to by I<recnum>
-I<$username> is the username pointed to by I<usersvc>
-I<$homedir> is that user's home directory
-
-is executed on I<apachemachine> via ssh. This behaviour can be surpressed by
-setting $FS::svc_www::nossh_hack true.
-
=cut
sub insert {
return $error;
}
- my $domain_record = qsearchs('domain_record', { 'recnum' => $self->recnum } ); # or die ?
- my $zone = $domain_record->reczone;
- # or die ?
- unless ( $zone =~ /\.$/ ) {
- my $dom_svcnum = $domain_record->svcnum;
- my $svc_domain = qsearchs('svc_domain', { 'svcnum' => $dom_svcnum } );
- # or die ?
- $zone .= '.'. $svc_domain->domain;
- }
-
- my $svc_acct = qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
- # or die ?
- my $username = $svc_acct->username;
- # or die ?
- my $homedir = $svc_acct->dir;
- # or die ?
-
- if ( $apachemachine
- && $apacheroot
- && $zone
- && $username
- && $homedir
- && ! $nossh_hack
- ) {
- ssh("root\@$apachemachine",
- "mkdir $apacheroot/$zone; ".
- "chown $username $apacheroot/$zone; ".
- "ln -s $apacheroot/$zone $homedir/$zone"
- );
- }
-
$dbh->commit or die $dbh->errstr if $oldAutoCommit;
'';
}
''; #no error
}
+=item domain_record
+
+Returns the FS::domain_record record for this web virtual host's zone (see
+L<FS::domain_record>).
+
+=cut
+
+sub domain_record {
+ my $self = shift;
+ qsearchs('domain_record', { 'recnum' => $self->recnum } );
+}
+
+=item svc_acct
+
+Returns the FS::svc_acct record for this web virtual host's owner (see
+L<FS::svc_acct>).
+
+=cut
+
+sub svc_acct {
+ my $self = shift;
+ qsearchs('svc_acct', { 'svcnum' => $self->usersvc } );
+}
+
=back
=head1 BUGS