Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

shell script from plugin?

Quote Reply
shell script from plugin?
I'm trying to execute a shell script from within my plugin -- but it's not working.

The script works when executed manually, or from a normal cgi script but things choke when I try to do it from a LinksSQL plugin. Can anybody think of why this wouldn't work? Most of the script below is working, no errors or thrown back. Just the shell script call is failing....

Any help/opinions are greatly appreciated.
Thanks,
Mike



Here's the code...

# ==================================================================
# Plugins::Class_Detailed - Auto Generated Program Module
#
# Plugins::Class_Detailed
# Author : Michael Paler
# Version : 1
# Updated : Wed Jan 5 17:34:06 2005
#
# ==================================================================
#

package Plugins::Class_Detailed;
# ==================================================================

use strict;
use GT::Base;
use GT::Plugins qw/STOP CONTINUE/;
use Links qw/$CFG $IN $DB/;
use File::Temp qw(tempfile);
use GT::Dumper;


# Inherit from base class for debug and error methods
@Plugins::Class_Detailed::ISA = qw(GT::Base);

# Your code begins here! Good Luck!


# PLUGIN HOOKS
# ===================================================================


sub build_detailed {
# -----------------------------------------------------------------------------
# This subroutine will be called whenever the hook 'build_detailed' is run. You
# should call GT::Plugins->action(STOP) if you don't want the regular
# 'build_detailed' code to run, otherwise the code will continue as normal.
#
my (@args) = @_;

# block of variables that we are encoding
my %vars = (
"cmd" => "_xclick",
"quantity" => "4",
"business" => "foo\@bar.com",
"item_name" => "Stuff I'm selling",
"amount" => "9.00",
"cancel_return" => "http://foo.com",
"currency_code" => "USD",
"rm" => "2",
"cert_id"=> "DPPL2XXXXXXXX"
);

# now use it to encrypt some text
my $str;
foreach my $var (keys(%vars)) {
$str .= "$var=$vars{$var}\n";
}

my $dir = "/private/classifieds/encrypt/";
my ($fh,$filename) = tempfile(DIR => $dir, SUFFIX => ".txt");

open($fh, "> $filename" )
or die "Can't create temp file: $1\n";

print $fh $str; # <-- this step is working because I can see $str in the temp file
my $encrypt = `/private/classifieds/encrypt/encrypt.sh $filename`; # <-- this step returns nothing...

#close($fh);
#unlink($filename);

# push the encryption into the $args hash
$args[0]{encrypt} = $encrypt;

# Do something useful here
print $IN->header;
print $str;
print $encrypt;
print Dumper(\@args);

GT::Plugins->action(STOP);
return @args;

}

# Always end with a 1.
1;


The shell script...

#!/bin/bash
MY_CERT=my-pubcert.pem
MY_KEY=my-prvkey.pem
MY_TEMP=$1

#while read line
#do
#echo $line
#done < $1
#echo $MY_TEMP

openssl smime -sign -in $MY_TEMP -signer $MY_CERT -inkey $MY_KEY -outform der -nodetach -binary | \
openssl smime -encrypt -des3 -binary -outform pem paypal_sandbox_cert.pem
Quote Reply
Re: [Swaylock] shell script from plugin? In reply to
Hi,

You will probably need to put it into a seperate .cgi script. Example header;

Code:
#!/usr/bin/perl

use strict;

use lib './';
use Links qw/$IN $DB $CFG/;
Links::init('./');
use CGI::Carp qw(fatalsToBrowser);

.. rest of your code here

Hope that helps :)

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] shell script from plugin? In reply to
Andy,

Thanks for the suggestion -- that was going to be my next course of action.

Couple of questions...is this a security issue within LinkSQL? Could there be a way to locally disable this security restriction?

So how do I execute the cgi script from the plugin?

Thanks for your help!!
Quote Reply
Re: [Swaylock] shell script from plugin? In reply to
Perhaps I should rephrase the question...

Can you execute a shell script from within a plugin? If no, why not?

Thanks,
Mike
Quote Reply
Re: [Swaylock] shell script from plugin? In reply to
I seem to have solved the first problem by using the following package:

IPC::Open2;

But now I'm having a problem getting a large encrypted blob to my for template parsing.

In my plugin:

my (@args) = @_;

# execute some code to get my large blob

# push the encrypted blob into @args
$args[0]{encrypted_blob} = $encrypted;

print $IN->header;
print Dumper(\@args);

return @args;

end of plugin.

The blob makes it into @args because it's visible in the first dump.

But it doesn't make it over to the template.
Anybody have any ideas why? (I it has to do with the carriage returns in the value -- but I'm not sure.)

Thanks,
Mike

Here's the first dump with the blob in there:

$VAR = [ { 'Ad_Duration' => '30', 'Ad_ExpiryDate' => '2005-01-04', 'Ad_Last_Renewal' => '2004-12-05', 'Ad_Num_Renewals' => '0', 'Ad_Status' => 'New', 'Add_Date' => '2004-12-05', 'Address' => '', 'Buy_It_Now' => 'Yes', 'City' => 'Los Angeles', 'Contact_Email' => 'foo@bar.com', 'Contact_Name' => 'Michael Jones', 'Country' => 'United States', 'Date_Checked' => '0000-00-00 00:00:00', 'Description' => 'fds ', 'Display_Phone' => 'No', 'ExpiryCounted' => '0', 'ExpiryDate' => '2147483647', 'ExpiryNotify' => '0', 'Hits' => '0', 'ID' => '165', 'Image' => undef, 'Image_thumbnail' => undef, 'LinkOwner' => 'jones', 'Mod_Date' => '2004-12-31', 'Phone' => '', 'Price' => '3.00', 'Price_Note' => '', 'Quantity' => '4', 'Rating' => '0.00', 'Shipping' => '1.00', 'Shipping2' => 'No', 'SlideShowCache' => '{}', 'State' => 'CA', 'Status' => '0', 'Timestmp' => '20041231150840', 'Title' => 'for sale test 2', 'URL' => undef, 'Votes' => '0', 'Zip_Code' => '', 'email_method' => 'pm', 'encrypted_blob' => '-----BEGIN PKCS7----- MIIHdQYJKoZIhvcNAQcDoIIHZjCCB2ICAQAxggE6MIIBNgIBADCBnjCBmDELMAkG A1UEBhMCVVMxEzARBgNVBAgTCkNhbGlmb3JuaWExETAPBgNVBAcTCFNhbiBKb3Nl MRUwEwYDVQQKEwxQYXlQYWwsIEluYy4xFjAUBgNVBAsUDXNhbmRib3hfY2VydHMx FDASBgNVBAMUC3NhbmRib3hfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYXlwYWwu Y29tAgEAMA0GCSqGSIb3DQEBAQUABIGASe2m38XEekAz45Ma7Kz7qhmsUoQ/KcIa q319ZnX7Vy961sYrAKH2sOBIf0OOO7VA9/typwCLJ4vqSIoZQ/LwNbK40IneeG3C xrR95o/CKcGVvvIoQRwLqTuIGodcAuxpf5f1i9edGOCDKDaCWEFVE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anged' => 'Yes', 'isNew' => 'No', 'isPopular' => 'No', 'isValidated' => 'Yes' } ];
Quote Reply
Re: [Swaylock] shell script from plugin? In reply to
Uugh. Answered my own question again. I was using the wrong plugin hook. was using build_detailed -- needed to be using site_html_detailed