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