export pkg_change hook, RT#22596
[freeside.git] / FS / FS / part_export / shellcommands.pm
1 package FS::part_export::shellcommands;
2
3 use vars qw(@ISA %info);
4 use Tie::IxHash;
5 use Date::Format;
6 use String::ShellQuote;
7 use FS::part_export;
8 use FS::Record qw( qsearch qsearchs );
9
10 @ISA = qw(FS::part_export);
11
12 tie my %options, 'Tie::IxHash',
13
14   'user' => { label=>'Remote username', default=>'root' },
15
16   'useradd' => { label=>'Insert command',
17                  default=>'useradd -c $finger -d $dir -m -s $shell -u $uid -p $crypt_password $username'
18                 #default=>'cp -pr /etc/skel $dir; chown -R $uid.$gid $dir'
19                },
20   'useradd_no_queue' => { label=>'Run immediately',
21                           type => 'checkbox',
22                         },
23   'useradd_stdin' => { label=>'Insert command STDIN',
24                        type =>'textarea',
25                        default=>'',
26                      },
27
28   'userdel' => { label=>'Delete command',
29                  default=>'userdel -r $username',
30                  #default=>'rm -rf $dir',
31                },
32   'userdel_no_queue' => { label=>'Run immediately',
33                           type =>'checkbox',
34                         },
35   'userdel_stdin' => { label=>'Delete command STDIN',
36                        type =>'textarea',
37                        default=>'',
38                      },
39
40   'usermod' => { label=>'Modify command',
41                  default=>'usermod -c $new_finger -d $new_dir -m -l $new_username -s $new_shell -u $new_uid -g $new_gid -p $new_crypt_password $old_username',
42                 #default=>'[ -d $old_dir ] && mv $old_dir $new_dir || ( '.
43                  #  'chmod u+t $old_dir; mkdir $new_dir; cd $old_dir; '.
44                  #  'find . -depth -print | cpio -pdm $new_dir; '.
45                  #  'chmod u-t $new_dir; chown -R $uid.$gid $new_dir; '.
46                  #  'rm -rf $old_dir'.
47                  #')'
48                },
49   'usermod_no_queue' => { label=>'Run immediately',
50                           type =>'checkbox',
51                         },
52   'usermod_stdin' => { label=>'Modify command STDIN',
53                        type =>'textarea',
54                        default=>'',
55                      },
56   'usermod_pwonly' => { label=>'Disallow username, domain, uid, gid, and dir changes', #and RADIUS group changes',
57                         type =>'checkbox',
58                       },
59   'usermod_nousername' => { label=>'Disallow just username changes',
60                             type =>'checkbox',
61                           },
62
63   'suspend' => { label=>'Suspension command',
64                  default=>'usermod -L $username',
65                },
66   'suspend_no_queue' => { label=>'Run immediately',
67                           type =>'checkbox',
68                         },
69   'suspend_stdin' => { label=>'Suspension command STDIN',
70                        default=>'',
71                      },
72
73   'unsuspend' => { label=>'Unsuspension command',
74                    default=>'usermod -U $username',
75                  },
76   'unsuspend_no_queue' => { label=>'Run immediately',
77                             type =>'checkbox',
78                           },
79   'unsuspend_stdin' => { label=>'Unsuspension command STDIN',
80                          default=>'',
81                        },
82
83   'pkg_change' => { label=>'Package changed command',
84                     default=>'',
85                   },
86
87   # run commands on package change for multiple services and roll back the
88   #  package change transaciton if one fails?  yuck. no.
89   #  if this was really needed, would need to restrict to a single service with
90   #  this kind of export configured.
91   #'pkg_change_no_queue' => { label=>'Run immediately',
92   #                           type =>'checkbox',
93   #                         },
94   'pkg_change_stdin' => { label=>'Package changed command STDIN',
95                           default=>'',
96                         },
97
98   'crypt' => { label   => 'Default password encryption',
99                type=>'select', options=>[qw(crypt md5)],
100                default => 'crypt',
101              },
102   'groups_susp_reason' => { label =>
103                              'Radius group mapping to reason (via template user)',
104                              type  => 'textarea',
105                           },
106   'fail_on_output' => {
107       label => 'Treat any output from the command as an error',
108       type  => 'checkbox',
109   },
110   'ignore_all_errors' => {
111       label => 'Ignore all errors from the command',
112       type  => 'checkbox',
113   },
114   'ignored_errors' => { label   => 'Regexes of specific errors to ignore, separated by newlines',
115                         type    => 'textarea'
116                       },
117 #  'no_queue' => { label => 'Run command immediately',
118 #                   type  => 'checkbox',
119 #                },
120 ;
121
122 %info = (
123   'svc'         => 'svc_acct',
124   'desc'        => 'Real-time export via remote SSH (i.e. useradd, userdel, etc.)',
125   'options'     => \%options,
126   'nodomain'    => 'Y',
127   'svc_machine' => 1,
128   'notes'       => <<'END'
129 Run remote commands via SSH.  Usernames are considered unique (also see
130 shellcommands_withdomain).  You probably want this if the commands you are
131 running will not accept a domain as a parameter.  You will need to
132 <a href="http://www.freeside.biz/mediawiki/index.php/Freeside:1.9:Documentation:Administration:SSH_Keys">setup SSH for unattended operation</a>.
133
134 <BR><BR>Use these buttons for some useful presets:
135 <UL>
136   <LI>
137     <INPUT TYPE="button" VALUE="Linux" onClick='
138       this.form.useradd.value = "useradd -c $finger -d $dir -m -s $shell -u $uid -p $crypt_password $username";
139       this.form.useradd_stdin.value = "";
140       this.form.userdel.value = "userdel -r $username";
141       this.form.userdel_stdin.value="";
142       this.form.usermod.value = "usermod -c $new_finger -d $new_dir -m -l $new_username -s $new_shell -u $new_uid -g $new_gid -p $new_crypt_password $old_username";
143       this.form.usermod_stdin.value = "";
144       this.form.suspend.value = "usermod -L $username";
145       this.form.suspend_stdin.value="";
146       this.form.unsuspend.value = "usermod -U $username";
147       this.form.unsuspend_stdin.value="";
148     '>
149   <LI>
150     <INPUT TYPE="button" VALUE="FreeBSD" onClick='
151       this.form.useradd.value = "pw useradd $username -d $dir -m -s $shell -u $uid -g $gid -c $finger -h 0";
152       this.form.useradd_stdin.value = "$_password\n";
153       this.form.userdel.value = "pw userdel $username -r";
154       this.form.userdel_stdin.value="";
155       this.form.usermod.value = "pw usermod $old_username -d $new_dir -m -l $new_username -s $new_shell -u $new_uid -g $new_gid -c $new_finger -h 0";
156       this.form.usermod_stdin.value = "$new__password\n";
157       this.form.suspend.value = "pw lock $username";
158       this.form.suspend_stdin.value="";
159       this.form.unsuspend.value = "pw unlock $username";
160       this.form.unsuspend_stdin.value="";
161     '>
162   <LI>
163     <INPUT TYPE="button" VALUE="NetBSD/OpenBSD" onClick='
164       this.form.useradd.value = "useradd -c $finger -d $dir -m -s $shell -u $uid -p $crypt_password $username";
165       this.form.useradd_stdin.value = "";
166       this.form.userdel.value = "userdel -r $username";
167       this.form.userdel_stdin.value="";
168       this.form.usermod.value = "usermod -c $new_finger -d $new_dir -m -l $new_username -s $new_shell -u $new_uid -g $new_gid -p $new_crypt_password $old_username";
169       this.form.usermod_stdin.value = "";
170       this.form.suspend.value = "";
171       this.form.suspend_stdin.value="";
172       this.form.unsuspend.value = "";
173       this.form.unsuspend_stdin.value="";
174     '>
175   <LI>
176     <INPUT TYPE="button" VALUE="Just maintain directories (use with sysvshell or bsdshell)" onClick='
177       this.form.useradd.value = "cp -pr /etc/skel $dir; chown -R $uid.$gid $dir"; this.form.useradd_stdin.value = "";
178       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 $new_uid.$new_gid $new_dir; rm -rf $old_dir )";
179       this.form.usermod_stdin.value = "";
180       this.form.userdel.value = "rm -rf $dir";
181       this.form.userdel_stdin.value="";
182       this.form.suspend.value = "";
183       this.form.suspend_stdin.value="";
184       this.form.unsuspend.value = "";
185       this.form.unsuspend_stdin.value="";
186     '>
187 </UL>
188
189 The following variables are available for interpolation (prefixed with new_ or
190 old_ for replace operations):
191 <UL>
192   <LI><code>$username</code>
193   <LI><code>$_password</code>
194   <LI><code>$quoted_password</code> - unencrypted password, already quoted for the shell (do not add additional quotes).
195   <LI><code>$crypt_password</code> - encrypted password.  When used on the command line (rather than STDIN), it will be quoted for the shell already (do not add additional quotes).
196   <LI><code>$ldap_password</code> - Password in LDAP/RFC2307 format (for example, "{PLAIN}himom", "{CRYPT}94pAVyK/4oIBk" or "{MD5}5426824942db4253f87a1009fd5d2d4").  When used on the command line (rather than STDIN), it will be quoted for the shell already (do not add additional quotes).
197   <LI><code>$uid</code>
198   <LI><code>$gid</code>
199   <LI><code>$finger</code> - GECOS.  When used on the command line (rather than STDIN), it will be quoted for the shell already (do not add additional quotes).
200   <LI><code>$first</code> - First name of GECOS.  When used on the command line (rather than STDIN), it will be quoted for the shell already (do not add additional quotes).
201   <LI><code>$last</code> - Last name of GECOS.  When used on the command line (rather than STDIN), it will be quoted for the shell already (do not add additional quotes).
202   <LI><code>$dir</code> - home directory
203   <LI><code>$shell</code>
204   <LI><code>$quota</code>
205   <LI><code>@radius_groups</code>
206   <LI><code>$reasonnum (when suspending)</code>
207   <LI><code>$reasontext (when suspending)</code>
208   <LI><code>$reasontypenum (when suspending)</code>
209   <LI><code>$reasontypetext (when suspending)</code>
210   <LI><code>$pkgnum</code>
211   <LI><code>$custnum</code>
212   <LI>All other fields in <b>svc_acct</b> are also available.
213   <LI>The following fields from <b>cust_main</b> are also available (except during replace): company, address1, address2, city, state, zip, county, daytime, night, fax, otaker, agent_custid, locale.  When used on the command line (rather than STDIN), they will be quoted for the shell already (do not add additional quotes).
214 </UL>
215 For the package changed command only, the following fields are also available:
216 <UL>
217   <LI>$old_pkgnum and $new_pkgnum
218   <LI>$old_pkgpart and $new_pkgpart
219   <LI>$old_agent_pkgid and $new_agent_pkgid
220   <LI>$old_order_date and $new_order_date
221   <LI>$old_start_date and $new_start_date
222   <LI>$old_setup and $new_setup
223   <LI>$old_bill and $new_bill
224   <LI>$old_last_bill and $new_last_bill
225   <LI>$old_susp and $new_susp
226   <LI>$old_adjourn and $new_adjourn
227   <LI>$old_resume and $new_resume
228   <LI>$old_cancel and $new_cancel
229   <LI>$old_unancel and $new_unancel
230   <LI>$old_expire and $new_expire
231   <LI>$old_contract_end and $new_contract_end
232 </UL>
233 END
234 );
235
236 sub _groups_susp_reason_map { shift->_map('groups_susp_reason'); }
237
238 sub _map {
239   my $self = shift;
240   map { reverse(/^\s*(\S+)\s*(.*)\s*$/) } split("\n", $self->option(shift) );
241 }
242
243 sub rebless { shift; }
244
245 sub _export_insert {
246   my $self = shift;
247   $self->_export_command('useradd', @_);
248 }
249
250 sub _export_delete {
251   my $self = shift;
252   $self->_export_command('userdel', @_);
253 }
254
255 sub _export_suspend {
256   my $self = shift;
257   $self->_export_command_or_super('suspend', @_);
258 }
259
260 sub _export_unsuspend {
261   my $self = shift;
262   $self->_export_command_or_super('unsuspend', @_);
263 }
264
265 sub export_pkg_change {
266   my( $self, $svc_acct, $new_cust_pkg, $old_cust_pkg ) = @_;
267
268   my @fields = qw( pkgnum pkgpart agent_pkgid ); #others?
269   my @date_fields = qw( order_date start_date setup bill last_bill susp adjourn
270                         resume cancel uncancel expore contract_end );
271
272   no strict 'vars';
273   {
274     no strict 'refs';
275     foreach (@fields) {
276       ${"old_$_"} = $old_cust_pkg->getfield($_);
277       ${"new_$_"} = $new_cust_pkg->getfield($_);
278     }
279     foreach (@date_fields) {
280       ${"old_$_"} = time2str('%Y-%m-%d', $old_cust_pkg->getfield($_));
281       ${"new_$_"} = time2str('%Y-%m-%d', $new_cust_pkg->getfield($_));
282     }
283   }
284
285   $self->_export_command('pkg_change', $svc_acct);
286 }
287
288 sub _export_command_or_super {
289   my($self, $action) = (shift, shift);
290   if ( $self->option($action) =~ /^\s*$/ ) {
291     my $method = "SUPER::_export_$action";
292     $self->$method(@_);
293   } else {
294     $self->_export_command($action, @_);
295   }
296 };
297
298 sub _export_command {
299   my ( $self, $action, $svc_acct) = (shift, shift, shift);
300   my $command = $self->option($action);
301
302   return '' if $command =~ /^\s*$/;
303   my $stdin = $self->option($action."_stdin");
304
305   no strict 'vars';
306   {
307     no strict 'refs';
308     ${$_} = $svc_acct->getfield($_) foreach $svc_acct->fields;
309
310     # snarfs are unused at this point?
311     # my $count = 1;
312     # foreach my $acct_snarf ( $svc_acct->acct_snarf ) {
313     #   ${"snarf_$_$count"} = shell_quote( $acct_snarf->get($_) )
314     #     foreach qw( machine username _password );
315     #   $count++;
316     # }
317   }
318
319   my $cust_pkg = $svc_acct->cust_svc->cust_pkg;
320   if ( $cust_pkg ) {
321     no strict 'vars';
322     {
323       no strict 'refs';
324       foreach my $custf (qw( company address1 address2 city state zip country
325                              daytime night fax otaker agent_custid locale
326                         ))
327       {
328         ${$custf} = $cust_pkg->cust_main->$custf();
329       }
330     }
331     $email = ( grep { $_ !~ /^(POST|FAX)$/ } $cust_pkg->cust_main->invoicing_list )[0];
332   } else {
333     $email = '';
334   }
335
336   $finger =~ /^(.*)\s+(\S+)$/ or $finger =~ /^((.*))$/;
337   ($first, $last ) = ( $1, $2 );
338   $domain = $svc_acct->domain;
339
340   $quoted_password = shell_quote $_password;
341
342   $crypt_password = $svc_acct->crypt_password( $self->option('crypt') );
343   $ldap_password  = $svc_acct->ldap_password(  $self->option('crypt') );
344
345   @radius_groups = $svc_acct->radius_groups;
346
347   my ($reasonnum, $reasontext, $reasontypenum, $reasontypetext);
348   if ( $cust_pkg && $action eq 'suspend' &&
349        (my $r = $cust_pkg->last_reason('susp')) )
350   {
351     $reasonnum = $r->reasonnum;
352     $reasontext = $r->reason;
353     $reasontypenum = $r->reason_type;
354     $reasontypetext = $r->reasontype->type;
355
356     my %reasonmap = $self->_groups_susp_reason_map;
357     my $userspec = '';
358     $userspec = $reasonmap{$reasonnum}
359       if exists($reasonmap{$reasonnum});
360     $userspec = $reasonmap{$reasontext}
361       if (!$userspec && exists($reasonmap{$reasontext}));
362
363     my $suspend_user;
364     if ( $userspec =~ /^\d+$/ ) {
365       $suspend_user = qsearchs( 'svc_acct', { 'svcnum' => $userspec } );
366     } elsif ( $userspec =~ /^\S+\@\S+$/ ) {
367       my ($username,$domain) = split(/\@/, $userspec);
368       for my $user (qsearch( 'svc_acct', { 'username' => $username } )){
369         $suspend_user = $user if $userspec eq $user->email;
370       }
371     } elsif ($userspec) {
372       $suspend_user = qsearchs( 'svc_acct', { 'username' => $userspec } );
373     }
374
375     @radius_groups = $suspend_user->radius_groups
376       if $suspend_user;  
377
378   } else {
379     $reasonnum = $reasontext = $reasontypenum = $reasontypetext = '';
380   }
381
382   $pkgnum = $cust_pkg ? $cust_pkg->pkgnum : '';
383   $custnum = $cust_pkg ? $cust_pkg->custnum : '';
384
385   my $stdin_string = eval(qq("$stdin"));
386   return "error filling in STDIN: $@" if $@;
387
388   $first = shell_quote $first;
389   $last = shell_quote $last;
390   $finger = shell_quote $finger;
391   $crypt_password = shell_quote $crypt_password;
392   $ldap_password  = shell_quote $ldap_password;
393
394   $company = shell_quote $company;
395   $address1 = shell_quote $address1;
396   $address2 = shell_quote $address2;
397   $city = shell_quote $city;
398   $state = shell_quote $state;
399   $zip = shell_quote $zip;
400   $country = shell_quote $country;
401   $daytime = shell_quote $daytime;
402   $night = shell_quote $night;
403   $fax = shell_quote $fax;
404   $otaker = shell_quote $otaker; 
405   $agent_custid = shell_quote $agent_custid;
406   $locale = shell_quote $locale;
407
408   my $command_string = eval(qq("$command"));
409   return "error filling in command: $@" if $@;
410
411   my @ssh_cmd_args = (
412     user          => $self->option('user') || 'root',
413     host          => $self->svc_machine($svc_acct),
414     command       => $command_string,
415     stdin_string  => $stdin_string,
416     ignored_errors    => $self->option('ignored_errors') || '',
417     ignore_all_errors => $self->option('ignore_all_errors'),
418     fail_on_output    => $self->option('fail_on_output'),
419  );
420
421   if ( $self->option($action. '_no_queue') ) {
422     # discard return value just like freeside-queued.
423     eval { ssh_cmd(@ssh_cmd_args) };
424     $error = $@;
425     $error = $error->full_message if ref $error; # Exception::Class::Base
426     return $error.
427              ' ('. $self->exporttype. ' to '. $self->svc_machine($svc_acct). ')'
428       if $error;
429   } else {
430     $self->shellcommands_queue( $svc_acct->svcnum, @ssh_cmd_args );
431   }
432 }
433
434 sub _export_replace {
435   my($self, $new, $old ) = (shift, shift, shift);
436   my $command = $self->option('usermod');
437   return '' if $command =~ /^\s*$/;
438   my $stdin = $self->option('usermod_stdin');
439   no strict 'vars';
440   {
441     no strict 'refs';
442     ${"old_$_"} = $old->getfield($_) foreach $old->fields;
443     ${"new_$_"} = $new->getfield($_) foreach $new->fields;
444   }
445   my $old_cust_pkg = $old->cust_svc->cust_pkg;
446   my $new_cust_pkg = $new->cust_svc->cust_pkg;
447   my $new_cust_main = $new_cust_pkg ? $new_cust_pkg->cust_main : '';
448
449   $new_finger =~ /^(.*)\s+(\S+)$/ or $new_finger =~ /^((.*))$/;
450   ($new_first, $new_last ) = ( $1, $2 );
451   $quoted_new__password = shell_quote $new__password; #old, wrong?
452   $new_quoted_password = shell_quote $new__password; #new, better?
453   $old_domain = $old->domain;
454   $new_domain = $new->domain;
455
456   $new_crypt_password = $new->crypt_password( $self->option('crypt') );
457   $new_ldap_password  = $new->ldap_password(  $self->option('crypt') );
458
459   @old_radius_groups = $old->radius_groups;
460   @new_radius_groups = $new->radius_groups;
461
462   my $error = '';
463   if ( $self->option('usermod_pwonly') || $self->option('usermod_nousername') ){
464     if ( $old_username ne $new_username ) {
465       $error ||= "can't change username";
466     }
467   }
468   if ( $self->option('usermod_pwonly') ) {
469     if ( $old_domain ne $new_domain ) {
470       $error ||= "can't change domain";
471     }
472     if ( $old_uid != $new_uid ) {
473       $error ||= "can't change uid";
474     }
475     if ( $old_gid != $new_gid ) {
476       $error ||= "can't change gid";
477     }
478     if ( $old_dir ne $new_dir ) {
479       $error ||= "can't change dir";
480     }
481     #if ( join("\n", sort @old_radius_groups) ne
482     #     join("\n", sort @new_radius_groups)    ) {
483     #  $error ||= "can't change RADIUS groups";
484     #}
485   }
486   return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($new). ')'
487     if $error;
488
489   $new_agent_custid = $new_cust_main ? $new_cust_main->agent_custid : '';
490   $new_locale = $new_cust_main ? $new_cust_main->locale : '';
491   $old_pkgnum = $old_cust_pkg ? $old_cust_pkg->pkgnum : '';
492   $old_custnum = $old_cust_pkg ? $old_cust_pkg->custnum : '';
493   $new_pkgnum = $new_cust_pkg ? $new_cust_pkg->pkgnum : '';
494   $new_custnum = $new_cust_pkg ? $new_cust_pkg->custnum : '';
495
496   my $stdin_string = eval(qq("$stdin"));
497
498   $new_first = shell_quote $new_first;
499   $new_last = shell_quote $new_last;
500   $new_finger = shell_quote $new_finger;
501   $new_crypt_password = shell_quote $new_crypt_password;
502   $new_ldap_password  = shell_quote $new_ldap_password;
503   $new_agent_custid = shell_quote $new_agent_custid;
504   $new_locale = shell_quote $new_locale;
505
506   my $command_string = eval(qq("$command"));
507
508   my @ssh_cmd_args = (
509     user          => $self->option('user') || 'root',
510     host          => $self->svc_machine($new),
511     command       => $command_string,
512     stdin_string  => $stdin_string,
513     ignored_errors    => $self->option('ignored_errors') || '',
514     ignore_all_errors => $self->option('ignore_all_errors'),
515     fail_on_output    => $self->option('fail_on_output'),
516   );
517
518   if($self->option('usermod_no_queue')) {
519     # discard return value just like freeside-queued.
520     eval { ssh_cmd(@ssh_cmd_args) };
521     $error = $@;
522     $error = $error->full_message if ref $error; # Exception::Class::Base
523     return $error. ' ('. $self->exporttype. ' to '. $self->svc_machine($new). ')'
524       if $error;
525   }
526   else {
527     $self->shellcommands_queue( $new->svcnum, @ssh_cmd_args );
528   }
529 }
530
531 #a good idea to queue anything that could fail or take any time
532 sub shellcommands_queue {
533   my( $self, $svcnum ) = (shift, shift);
534   my $queue = new FS::queue {
535     'svcnum' => $svcnum,
536     'job'    => "FS::part_export::shellcommands::ssh_cmd",
537   };
538   $queue->insert( @_ );
539 }
540
541 sub ssh_cmd { #subroutine, not method
542   use Net::OpenSSH;
543   my $opt = { @_ };
544   open my $def_in, '<', '/dev/null' or die "unable to open /dev/null\n";
545   my $ssh = Net::OpenSSH->new(
546     $opt->{'user'}.'@'.$opt->{'host'},
547     'default_stdin_fh' => $def_in
548   );
549   # ignore_all_errors doesn't override SSH connection/auth errors--
550   # probably correct
551   die "Couldn't establish SSH connection: ". $ssh->error if $ssh->error;
552
553   my $ssh_opt = {};
554   $ssh_opt->{'stdin_data'} = $opt->{'stdin_string'}
555     if exists($opt->{'stdin_string'}) and length($opt->{'stdin_string'});
556
557   my ($output, $errput) = $ssh->capture2($ssh_opt, $opt->{'command'});
558
559   return if $opt->{'ignore_all_errors'};
560   #die "Error running SSH command: ". $ssh->error if $ssh->error;
561
562   if ( ($output || $errput)
563        && $opt->{'ignored_errors'} && length($opt->{'ignored_errors'})
564   ) {
565     my @ignored_errors = split('\n',$opt->{'ignored_errors'});
566     foreach my $ignored_error ( @ignored_errors ) {
567         $output =~ s/$ignored_error//g;
568         $errput =~ s/$ignored_error//g;
569     }
570     $output =~ s/[\s\n]//g;
571     $errput =~ s/[\s\n]//g;
572   }
573
574   die (($errput || $ssh->error). "\n") if $errput || $ssh->error; 
575   #die "$errput\n" if $errput;
576
577   die "$output\n" if $output and $opt->{'fail_on_output'};
578   '';
579 }
580
581 #sub shellcommands_insert { #subroutine, not method
582 #}
583 #sub shellcommands_replace { #subroutine, not method
584 #}
585 #sub shellcommands_delete { #subroutine, not method
586 #}
587
588 sub _upgrade_exporttype {
589   my $class = shift;
590   $class =~ /^FS::part_export::(\w+)$/;
591   foreach my $self ( qsearch('part_export', { 'exporttype' => $1 }) ) {
592     my %options = $self->options;
593     my $changed = 0;
594     # 2011-12-13 - 2012-02-16: ignore_all_output option
595     if ( $options{'ignore_all_output'} ) {
596       # ignoring STDOUT is now the default
597       $options{'ignore_all_errors'} = 1;
598       delete $options{'ignore_all_output'};
599       $changed++;
600     }
601     my $error = $self->replace(%options) if $changed;
602     die $error if $error;
603   }
604 }
605
606 1;
607