useful shellcommands presets
[freeside.git] / FS / FS / part_export.pm
index 94b819d..072074b 100644 (file)
@@ -141,7 +141,7 @@ sub insert {
 
   '';
 
-};
+}
 
 =item delete
 
@@ -361,7 +361,8 @@ sub option {
 
 Reblesses the object into the FS::part_export::EXPORTTYPE class, where
 EXPORTTYPE is the object's I<exporttype> field.  There should be better docs
-on how to create new exports, but until then, see L</NEW EXPORT CLASSES>.
+on how to create new exports (and they should live in their own files and be
+autoloaded-on-demand), but until then, see L</NEW EXPORT CLASSES>.
 
 =cut
 
@@ -369,7 +370,8 @@ sub rebless {
   my $self = shift;
   my $exporttype = $self->exporttype;
   my $class = ref($self). "::$exporttype";
-  eval "use $class;" or die $@;
+  eval "use $class;";
+  die $@ if $@;
   bless($self, $class);
 }
 
@@ -412,6 +414,26 @@ sub export_delete {
   $self->_export_delete(@_);
 }
 
+=item export_suspend
+
+=cut
+
+sub export_suspend {
+  my $self = shift;
+  $self->rebless;
+  $self->_export_suspend(@_);
+}
+
+=item export_unsuspend
+
+=cut
+
+sub export_unsuspend {
+  my $self = shift;
+  $self->rebless;
+  $self->_export_unsuspend(@_);
+}
+
 #fallbacks providing useful error messages intead of infinite loops
 sub _export_insert {
   my $self = shift;
@@ -428,6 +450,20 @@ sub _export_delete {
   return "_export_delete: unknown export type ". $self->exporttype;
 }
 
+#fallbacks providing null operations
+
+sub _export_suspend {
+  my $self = shift;
+  #warn "warning: _export_suspened unimplemented for". ref($self);
+  '';
+}
+
+sub _export_unsuspend {
+  my $self = shift;
+  #warn "warning: _export_unsuspend unimplemented for ". ref($self);
+  '';
+}
+
 =back
 
 =head1 SUBROUTINES
@@ -458,33 +494,55 @@ sub export_info {
   my $r = { map { %{$exports{$_}} } keys %exports };
 }
 
-=item exporttype2svcdb EXPORTTYPE
-
-Returns the applicable I<svcdb> for an I<exporttype>.
+#=item exporttype2svcdb EXPORTTYPE
+#
+#Returns the applicable I<svcdb> for an I<exporttype>.
+#
+#=cut
+#
+#sub exporttype2svcdb {
+#  my $exporttype = $_[0];
+#  foreach my $svcdb ( keys %exports ) {
+#    return $svcdb if grep { $exporttype eq $_ } keys %{$exports{$svcdb}};
+#  }
+#  '';
+#}
 
-=cut
+tie my %sysvshell_options, 'Tie::IxHash',
+  'crypt' => { label=>'Password encryption',
+               type=>'select', options=>[qw(crypt md5)],
+               default=>'crypt',
+             },
+;
 
-sub exporttype2svcdb {
-  my $exporttype = $_[0];
-  foreach my $svcdb ( keys %exports ) {
-    return $svcdb if grep { $exporttype eq $_ } keys %{$exports{$svcdb}};
-  }
-  '';
-}
+tie my %bsdshell_options, 'Tie::IxHash', 
+  'crypt' => { label=>'Password encryption',
+               type=>'select', options=>[qw(crypt md5)],
+               default=>'crypt',
+             },
+;
 
 tie my %shellcommands_options, 'Tie::IxHash',
   #'machine' => { label=>'Remote machine' },
   'user' => { label=>'Remote username', default=>'root' },
   'useradd' => { label=>'Insert command',
-                 default=>'useradd -d $dir -m -s $shell -u $uid $username'
+                 default=>'useradd -d $dir -m -s $shell -u $uid $username; passwd $username'
                 #default=>'cp -pr /etc/skel $dir; chown -R $uid.$gid $dir'
                },
+  'useradd_stdin' => { label=>'Insert command STDIN',
+                       type =>'textarea',
+                       default=>"\$_password\n\$_password\n",
+                     },
   'userdel' => { label=>'Delete command',
                  default=>'userdel $username',
                  #default=>'rm -rf $dir',
                },
+  'userdel_stdin' => { label=>'Delete command STDIN',
+                       type =>'textarea',
+                       default=>'',
+                     },
   'usermod' => { label=>'Modify command',
-                 default=>'usermod -d $new_dir -l $new_username -s $new_shell -u $new_uid $old_username',
+                 default=>'usermod -d $new_dir -l $new_username -s $new_shell -u $new_uid $old_username; passwd $new_username',
                 #default=>'[ -d $old_dir ] && mv $old_dir $new_dir || ( '.
                  #  'chmod u+t $old_dir; mkdir $new_dir; cd $old_dir; '.
                  #  'find . -depth -print | cpio -pdm $new_dir; '.
@@ -492,10 +550,44 @@ tie my %shellcommands_options, 'Tie::IxHash',
                  #  'rm -rf $old_dir'.
                  #')'
                },
+  'usermod_stdin' => { label=>'Modify command STDIN',
+                       type =>'textarea',
+                       default=>"\$_password\n\$_password\n",
+                     },
+;
+
+tie my %shellcommands_withdomain_options, 'Tie::IxHash',
+  'user' => { label=>'Remote username', default=>'root' },
+  'useradd' => { label=>'Insert command',
+                 #default=>''
+               },
+  'useradd_stdin' => { label=>'Insert command STDIN',
+                       type =>'textarea',
+                       #default=>"$_password\n$_password\n",
+                     },
+  'userdel' => { label=>'Delete command',
+                 #default=>'',
+               },
+  'userdel_stdin' => { label=>'Delete command STDIN',
+                       type =>'textarea',
+                       #default=>'',
+                     },
+  'usermod' => { label=>'Modify command',
+                 default=>'',
+               },
+  'usermod_stdin' => { label=>'Modify command STDIN',
+                       type =>'textarea',
+                       #default=>"$_password\n$_password\n",
+                     },
+;
+
+tie my %textradius_options, 'Tie::IxHash',
+  'user' => { label=>'Remote username', default=>'root' },
+  'users' => { label=>'users file location', default=>'/etc/raddb/users' },
 ;
 
 tie my %sqlradius_options, 'Tie::IxHash',
-  'datasrc'  => { label=>'DBI data source' },
+  'datasrc'  => { label=>'DBI data source ' },
   'username' => { label=>'Database username' },
   'password' => { label=>'Database password' },
 ;
@@ -544,6 +636,11 @@ tie my %bind_slave_options, 'Tie::IxHash',
                      default => '/etc/bind/named.conf' },
 ;
 
+tie my %sqlmail_options, 'Tie::IxHash',
+  'datasrc'  => { label=>'DBI data source' },
+  'username' => { label=>'Database username' },
+  'password' => { label=>'Database password' },
+;
 
 
 #export names cannot have dashes...
@@ -551,13 +648,17 @@ tie my %bind_slave_options, 'Tie::IxHash',
   'svc_acct' => {
     'sysvshell' => {
       'desc' =>
-        'Batch export of /etc/passwd and /etc/shadow files (Linux/SysV)',
-      'options' => {},
+        'Batch export of /etc/passwd and /etc/shadow files (Linux/SysV).',
+      'options' => \%sysvshell_options,
+      'nodomain' => 'Y',
+      'notes' => 'MD5 crypt requires installation of <a href="http://search.cpan.org/search?dist=Crypt-PasswdMD5">Crypt::PasswdMD5</a> from CPAN.    Run bin/sysvshell.export to export the files.',
     },
     'bsdshell' => {
       'desc' =>
-        'Batch export of /etc/passwd and /etc/master.passwd files (BSD)',
-      'options' => {},
+        'Batch export of /etc/passwd and /etc/master.passwd files (BSD).',
+      'options' => \%bsdshell_options,
+      'nodomain' => 'Y',
+      'notes' => 'MD5 crypt requires installation of <a href="http://search.cpan.org/search?dist=Crypt-PasswdMD5">Crypt::PasswdMD5</a> from CPAN.  Run bin/bsdshell.export to export the files.',
     },
 #    'nis' => {
 #      'desc' =>
@@ -565,22 +666,36 @@ tie my %bind_slave_options, 'Tie::IxHash',
 #      'options' => {},
 #    },
     'textradius' => {
-      'desc' => 'Batch export of a text /etc/raddb/users file (Livingston, Cistron)',
-      'options' => {},
+      'desc' => 'Real-time export to a text /etc/raddb/users file (Livingston, Cistron)',
+      'options' => \%textradius_options,
+      'notes' => 'This will edit a text RADIUS users file in place on a remote server.  Requires installation of <a href="http://search.cpan.org/search?dist=RADIUS-UserFile">RADIUS::UserFile</a> from CPAN.  If using RADIUS::UserFile 1.01, make sure to apply <a href="http://rt.cpan.org/NoAuth/Bug.html?id=1210">this patch</a>.  Also make sure <a href="http://rsync.samba.org/">rsync</a> is installed on the remote machine, and <a href="../docs/ssh.html">SSH is setup for unattended operation</a>.',
     },
 
     'shellcommands' => {
       'desc' => 'Real-time export via remote SSH (i.e. useradd, userdel, etc.)',
       'options' => \%shellcommands_options,
       'nodomain' => 'Y',
-      'notes' => 'shellcommandsnotes... (this one is the nodomain one)',
+      'notes' => 'Run remote commands via SSH.  Usernames are considered unique (also see shellcommands_withdomain).  You probably want this if the commands you are running will not accept a domain as a parameter.  You will need to <a href="../docs/ssh.html">setup SSH for unattended operation</a>.<BR><BR>Use these buttons for some useful presets:<UL><LI><INPUT TYPE="button" VALUE="Linux/NetBSD" onClick=\'this.form.useradd.value = "useradd -d $dir -m -s $shell -u $uid $username; passwd $username"; this.form.useradd_stdin.value = "$_password\n$_password\n"; this.form.userdel.value = "userdel $username"; this.form.userdel_stdin.value=""; this.form.usermod.value = "usermod -d $new_dir -l $new_username -s $new_shell -u $new_uid $old_username; passwd $new_username"; this.form.usermod_stdin.value = "$_password\n$_password\n";\'><LI><INPUT TYPE="button" VALUE="FreeBSD" onClick=\'this.form.useradd.value = "pw useradd $username -d $dir -m -s $shell -u $uid; passwd $username"; this.form.useradd_stdin.value = "$_password\n$_password\n"; this.form.userdel.value = "userdel $username"; this.form.userdel_stdin.value=""; this.form.usermod.value = "pw usermod $old_username -d $new_dir -l $new_username -s $new_shell -u $new_uid; passwd $new_username"; this.form.usermod_stdin.value = "$_password\n$_password\n";\'><LI><INPUT TYPE="button" VALUE="Just maintain directories (use with sysvshell or bsdshell)" onClick=\'this.form.useradd.value = "cp -pr /etc/skel $dir; chown -R $uid.$gid $dir"; this.form.useradd_stdin.value = ""; this.form.usermod.value = "[ -d $old_dir ] && mv $old_dir $new_dir || ( chmod u+t $old_dir; mkdir $new_dir; cd $old_dir; find . -depth -print | cpio -pdm $new_dir; chmod u-t $new_dir; chown -R $uid.$gid $new_dir; rm -rf $old_dir )"; this.form.usermod_stdin.value = ""; this.form.userdel.value = "rm -rf $dir"; this.form.userdel_stdin.value="";\'></UL>',
+    },
+
+    'shellcommands_withdomain' => {
+      'desc' => 'Real-time export via remote SSH.',
+      'options' => \%shellcommands_withdomain_options,
+      'notes' => 'Run remote commands via SSH.  username@domain (rather than just usernames) are considered unique (also see shellcommands).  You probably want this if the commands you are running will accept a domain as a parameter, and will allow the same username with different domains.  You will need to <a href="../docs/ssh.html">setup SSH for unattended operation</a>.',
     },
 
     'sqlradius' => {
       'desc' => 'Real-time export to SQL-backed RADIUS (ICRADIUS, FreeRADIUS)',
       'options' => \%sqlradius_options,
       'nodomain' => 'Y',
-      'notes' => 'Real-time export of radcheck, radreply and usergroup tables to any SQL database for <a href="http://www.freeradius.org/">FreeRADIUS</a> or <a href="http://radius.innercite.com/">ICRADIUS</a>.  Use <a href="../docs/man/bin/freeside-sqlradius-reset">freeside-sqlradius-reset</a> to delete and repopulate the tables from the Freeside database.',
+      'notes' => 'Real-time export of radcheck, radreply and usergroup tables to any SQL database for <a href="http://www.freeradius.org/">FreeRADIUS</a> or <a href="http://radius.innercite.com/">ICRADIUS</a>.  An existing RADIUS database will be updated in realtime, but you can use <a href="../docs/man/bin/freeside-sqlradius-reset">freeside-sqlradius-reset</a> to delete the entire RADIUS database and repopulate the tables from the Freeside database.  See the <a href="http://search.cpan.org/doc/TIMB/DBI-1.23/DBI.pm">DBI documentation</a> and the <a href="http://search.cpan.org/search?mode=module&query=DBD%3A%3A">documentation for your DBD</a> for the exact syntax of a DBI data source.  If using <a href="http://www.freeradius.org/">FreeRADIUS</a> 0.5 or above, make sure your <b>op</b> fields are set to allow NULL values.',
+    },
+
+    'sqlmail' => {
+      'desc' => 'Real-time export to SQL-backed mail server',
+      'options' => \%sqlmail_options,
+      'nodomain' => 'Y',
+      'notes' => 'Database schema can be made to work with Courier IMAP and Exim.  Others could work but are untested. (...extended description from pc-intouch?...)',
     },
 
     'cyrus' => {
@@ -606,7 +721,6 @@ tie my %bind_slave_options, 'Tie::IxHash',
     'vpopmail' => {
       'desc' => 'Real-time export to vpopmail text files',
       'options' => \%vpopmail_options,
-
       'notes' => 'Real time export to <a href="http://inter7.com/vpopmail/">vpopmail</a> text files (...extended description from jeff?...)',
     },
 
@@ -617,13 +731,20 @@ tie my %bind_slave_options, 'Tie::IxHash',
     'bind' => {
       'desc' =>'Batch export to BIND named',
       'options' => \%bind_options,
-      'notes' => 'bind export notes',
+      'notes' => 'Batch export of BIND zone and configuration files to primary nameserver.  <a href="http://search.cpan.org/search?dist=File-Rsync">File::Rsync</a> must be installed.  Run bin/bind.export to export the files.',
     },
 
     'bind_slave' => {
       'desc' =>'Batch export to slave BIND named',
       'options' => \%bind_slave_options,
-      'notes' => 'bind export notes (secondary munge)',
+      'notes' => 'Batch export of BIND configuration file to a secondary nameserver.  Zones are slaved from the listed masters.  <a href="http://search.cpan.org/search?dist=File-Rsync">File::Rsync</a> must be installed.  Run bin/bind.export to export the files.',
+    },
+
+    'sqlmail' => {
+      'desc' => 'Real-time export to SQL-backed mail server',
+      'options' => \%sqlmail_options,
+      #'nodomain' => 'Y',
+      'notes' => 'Database schema can be made to work with Courier IMAP and Exim.  Others could work but are untested. (...extended description from pc-intouch?...)',
     },
 
 
@@ -631,9 +752,23 @@ tie my %bind_slave_options, 'Tie::IxHash',
 
   'svc_acct_sm' => {},
 
-  'svc_forward' => {},
+  'svc_forward' => {
+    'sqlmail' => {
+      'desc' => 'Real-time export to SQL-backed mail server',
+      'options' => \%sqlmail_options,
+      #'nodomain' => 'Y',
+      'notes' => 'Database schema can be made to work with Courier IMAP and Exim.  Others could work but are untested. (...extended description from pc-intouch?...)',
+    },
+  },
+
+  'svc_www' => {
+    'www_shellcommands' => {
+      'desc'    => 'www_shellcommands',
+      'options' => {}, # \%www_shellcommands_options,
+      'notes'   => 'unfinished...',
+    },
 
-  'svc_www' => {},
+  },
 
 );
 
@@ -646,7 +781,8 @@ FS/FS/part_export/ (an example may be found in eg/export_template.pm)
 
 =head1 BUGS
 
-Probably.
+All the stuff in the %exports hash should be generated from the specific
+export modules.
 
 Hmm... cust_export class (not necessarily a database table...) ... ?