move svc_www ssh jobs to the job queue & exports, and make them configurable
authorivan <ivan>
Sat, 6 Jul 2002 07:30:38 +0000 (07:30 +0000)
committerivan <ivan>
Sat, 6 Jul 2002 07:30:38 +0000 (07:30 +0000)
FS/FS/Conf.pm
FS/FS/part_export.pm
FS/FS/part_export/www_shellcommands.pm
FS/FS/svc_www.pm

index 25c6743..e93eaf3 100644 (file)
@@ -221,8 +221,8 @@ httemplate/docs/config.html
 
   {
     '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',
   },
 
@@ -235,8 +235,8 @@ httemplate/docs/config.html
 
   {
     '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',
   },
 
index 15b207e..3982168 100644 (file)
@@ -531,7 +531,7 @@ tie my %shellcommands_options, 'Tie::IxHash',
                },
   'useradd_stdin' => { label=>'Insert command STDIN',
                        type =>'textarea',
-                       default=>"",
+                       default=>'',
                      },
   'userdel' => { label=>'Delete command',
                  default=>'userdel $username',
@@ -552,7 +552,7 @@ tie my %shellcommands_options, 'Tie::IxHash',
                },
   'usermod_stdin' => { label=>'Modify command STDIN',
                        type =>'textarea',
-                       default=>"",
+                       default=>'',
                      },
 ;
 
@@ -581,6 +581,19 @@ tie my %shellcommands_withdomain_options, 'Tie::IxHash',
                      },
 ;
 
+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 &quot;$zone&quot; ] && rm -rf /var/www/$zone; rm $homedir/$zone',
+                },
+  'usermod'  => { label=>'Modify command',
+                  default=>'[ -n &quot;$old_zone&quot; ] && rm $old_homedir/$old_zone; [ &quot;$old_zone&quot; != &quot;$new_zone&quot; -a -n &quot;$new_zone&quot; ] && mv /var/www/$old_zone /var/www/$new_zone; [ &quot;$old_username&quot; != &quot;$new_username&quot; ] && 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' },
@@ -800,9 +813,9 @@ tie my %sqlmail_options, 'Tie::IxHash',
 
   '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>.',
     },
 
   },
index e95939b..84c1627 100644 (file)
@@ -1,5 +1,6 @@
-package FS::part_export::shellcommands;
+package FS::part_export::www_shellcommands;
 
+use strict;
 use vars qw(@ISA);
 use FS::part_export;
 
@@ -18,31 +19,72 @@ sub _export_delete {
 }
 
 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")),
   );
 }
 
@@ -51,7 +93,7 @@ sub shellcommands_queue {
   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( @_ );
 }
index 6415a30..d7a42c8 100644 (file)
@@ -1,7 +1,7 @@
 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;
@@ -9,15 +9,12 @@ use FS::cust_svc;
 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');
 };
 
@@ -85,20 +82,6 @@ otherwise returns false.
 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 {
@@ -147,37 +130,6 @@ 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;
   '';
 }
@@ -285,6 +237,30 @@ sub check {
   ''; #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