Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Printer module from web interface

by ksublondie (Pilgrim)
on Mar 07, 2011 at 23:02 UTC ( #891923=perlquestion: print w/ replies, xml ) Need Help??
ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks!

I'm needing to use the Printer module on a linux web server. If I try to print from a script run from the command line it works like a charm. However, if I try that same code (actually the same file, not just a copied portion of the script somewhere else),

my $prn= new Printer('linux' => 'lp'); $prn->print($text);
I get the following error:
Internal exception error - Insecure $ENV{PATH} while running with -T s +witch
I'm not a linux expert. I only know enough to be dangerous. I've tracked it down to failing at the following line:
open PRINTER, $pr_cmd or Carp::croak "Can't open printer connection to $self->{'printer'}{$OSNAME} +: $!";
in the print sub inside Printer::Unix. Any ideas on how I can get this to work?

Yes, I need to be using a specific printer from the server, not the locally installed printers on the workstation.

Comment on Printer module from web interface
Select or Download Code
Re: Printer module from web interface
by GrandFather (Cardinal) on Mar 07, 2011 at 23:39 UTC

    You've hit a Taint issue. How is $pr_cmd formed? You should be able to untaint $pr_cmd by running it through a regex match and using a matched string as the value for $pr_cmd.

    True laziness is hard work
      $pr_cmd is set in the Printer::Unix module:
      my $pr_cmd = "| lpr -P $self->{'printer'}{$OSNAME}";
      I've added:
      $pr_cmd=~/^(.*)$/; $pr_cmd=$1;
      and I've even tried hard-coding $pr_cmd="| lpr -P lp" but I'm still getting the same error. Interesting observation:
      open PRINTER, $pr_cmd or warn "Can't open printer connection to lp: $!";
      Doesn't show my warning text. Is that to be expected?

        Oh!. Maybe you need to untaint $ENV{PATH}. If it's used by open, which is likely, then you'd get that error and your script would die horribly before hitting the warning.

        True laziness is hard work
Re: Printer module from web interface
by wind (Priest) on Mar 08, 2011 at 00:17 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://891923]
Approved by Perlbotics
Front-paged by MidLifeXis
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2014-10-01 22:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (40 votes), past polls