add -s and -n flags to freeside-daily to specify the kinds of jobs to be run, RT...
authorivan <ivan>
Fri, 26 Jun 2009 23:12:45 +0000 (23:12 +0000)
committerivan <ivan>
Fri, 26 Jun 2009 23:12:45 +0000 (23:12 +0000)
FS/bin/freeside-queued

index 22fd7bb..008616f 100644 (file)
@@ -4,6 +4,7 @@ use strict;
 use vars qw( $DEBUG $kids $max_kids %kids );
 use POSIX qw(:sys_wait_h);
 use IO::File;
+use Getopt::Std;
 use FS::UID qw(adminsuidsetup forksuidsetup driver_name dbh myconnect);
 use FS::Daemon qw(daemonize1 drop_root logfile daemonize2 sigint sigterm);
 use FS::Conf;
@@ -18,6 +19,10 @@ $DEBUG = 0;
 
 $kids = 0;
 
+&untaint_argv;  #what it sounds like  (eww)
+use vars qw(%opt);
+getopts('sn', \%opt );
+
 my $user = shift or die &usage;
 
 warn "starting daemonization (forking)\n" if $DEBUG;
@@ -95,9 +100,16 @@ while (1) {
                    ? " LIMIT $limit FOR UPDATE "
                    : " FOR UPDATE LIMIT $limit " );
 
+  my $hashref = { 'status' => 'new' };
+  if ( $opt{'s'} ) {
+    $hashref->{'status'} = 'Y';
+  } elsif ( $opt{'n'} ) {
+    $hashref->{'status'} = '';
+  }
+
   my @jobs = qsearch({
     'table'     => 'queue',
-    'hashref'   => { 'status' => 'new' },
+    'hashref'   => $hashref,
     'extra_sql' => $nodepend,
     'order_by'  => $order_by,
   });
@@ -217,6 +229,15 @@ while (1) {
   }
 }
 
+sub untaint_argv {
+  foreach $_ ( $[ .. $#ARGV ) { #untaint @ARGV
+    #$ARGV[$_] =~ /^([\w\-\/]*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
+    # Date::Parse
+    $ARGV[$_] =~ /^(.*)$/ || die "Illegal arguement \"$ARGV[$_]\"";
+    $ARGV[$_]=$1;
+  }
+}
+
 sub usage {
   die "Usage:\n\n  freeside-queued user\n";
 }
@@ -237,12 +258,16 @@ freeside-queued - Job queue daemon
 
 =head1 SYNOPSIS
 
-  freeside-queued user
+  freeside-queued [ -s | -n ] user
 
 =head1 DESCRIPTION
 
 Job queue daemon.  Should be running at all times.
 
+-s: "secure" jobs only (queued billing jobs)
+
+-n: non-"secure" jobs only (other jobs)
+
 user: from the mapsecrets file - see config.html from the base documentation
 
 =head1 VERSION