Topic: using punbb cookies in perl scripts

I've integrated punbb with my site and if users are logged in, they can also post photos and videos to a weblog. Those scripts are written in perl and I wonder how I can use cookies produced by punbb in these scripts. any idea?

Re: using punbb cookies in perl scripts

<?php
    passthru("perl ./script.cgi");
?>

That will execute the script.cgi file, using perl. I believe cookie data is stored as an environment variable, and passthru should keep the same environment. Then all you have to do is figure out which cookie data means which database entry. Alternatively you can just do all the cookie handling in php, and then run your cgi script, with passthru("perl ./script.cgi -confimed"); and in script.cgi near the top

if ($ARGV[1] != '-confirmed') exit();
echo "deadram"; echo; fortune;

3 (edited by erinther 2007-02-18 14:19)

Re: using punbb cookies in perl scripts

Hi. thank for your answer. I tired it but my perl scripts are located in plugins. I mean passthru does not work for it, at least I could not figure it out.You mentioned "cookie handling". well, that is the point I need help. I don't know how to manipulate or call cookie's data in my php or perl script. I tried in my perl script to print the cookie created by punbb and i got something like that:

a:2:{i:0;s:1:"2";i:1;s:32:"3f3410c241f5ef458e47c2293e279a0c";}

I need  to get some data from cookie and then put it inside a form and send it to perl script to evalute it .

4 (edited by deadram 2007-02-18 07:03)

Re: using punbb cookies in perl scripts

Ok... AMP_PassData2CgiAndPrintCgiResult.cgi

<?php
/***********************************************************************

  Copyright (C) 2002-2007  Punbb Community (deadram at gmail dot com)

  This file is part of PunBB.

  PunBB is free software; you can redistribute it and/or modify it
  under the terms of the GNU General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  PunBB is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  MA  02111-1307  USA

************************************************************************/

// Make sure no one attempts to run this script "directly"
if (!defined('PUN'))
    exit;

// Tell admin_loader.php that this is indeed a plugin and that it is loaded
define('PUN_PLUGIN_LOADED', 1);

//
// The rest is up to you!
//

// Display the admin navigation menu
generate_admin_menu($plugin);

?>
    <div class="blockform">
        <h2><span>A test plugin</span></h2>
        <div class="box">
            <form method="post" action="<?php echo $_SERVER['REQUEST_URI'] ?>">
                <p class="submittop"><input type="submit" name="run_cgi" value="Run" /></p>
                <div class="infldset">
                    <fieldset>
                        <legend>Options</legend>
                        <div class="infldset">
                            <table class="aligntop" cellspacing="0">
                                <tr>
                                    <th scope="row">Run cgi</th>
                                    <td>
                                        <input type="text" name="cgi_path" value="./plugins/cgi/SomeCgiScript.cgi">
                                        <p>Type the relative path from the forum root directory to a cgi script above</p>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </fieldset>
                </div>
                <p class="submittop"><input type="submit" name="run_cgi" value="Run" /></p>
            </form>
        </div>
    </div>
    <div class="blockform">
        <h2><span>Output</span></h2>
        <div class="box">
            <p><?php if (isset($_POST['run_cgi'])) { passthru($_POST['cgi_path'].' ARGVARS FROM PHP IE: data from the user table, ect...'); } ?></p>
        </div>
    </div>

SomeCgiScript.cgi

#!/usr/bin/perl

$numArgs = $#ARGV + 1;
print 'Thanks, you gave me '.$numArgs.' command-line arguments.'."\n\n";
foreach $argnum (0 .. $#ARGV) {
    print "$ARGV[$argnum]\n";
}

print "\n\n".'Here\'s your environment variables:'."\n\n";
foreach $key (sort keys(%ENV)) {
    print "$key = $ENV{$key}\n";
}

In the php script get whatever data you need. Stuff for the database, etc... in perl parse the argvars.
The cookie set by punbb is just a number that references a row in the punbb database, that has I think uid, ip, cookie "id", and accesstime. I forget exactly though. You don't need to fumble around with the cookie though. in the php script get the vars you want to change and/or alter. in perl do the work, and in php parse the output and change any values.

The php's official docs on passthru list a few alternative ways to call external applications.

If you wanted to use the example above and then access the database in the perl script, you will need to write your own database access code ($db->Function isn't official php, it's punbb's own db layer). Give me a few and I'll edit to include some info on the database records tongue

EDIT --

Looks like I was wrong. Guess the cookie doesn't work like I expected it too. Anyways, you don't need the cookie, if you already have the uid tongue

echo "deadram"; echo; fortune;

Re: using punbb cookies in perl scripts

erinther wrote:

Hi. thank for your answer. I tired it but my perl scripts are located in plugins. I mean passthru does not work for it, at least I could not figure it out.You mentioned "cookie handling". well, that is the point I need help. I don't know how to manipulate or call cookie's data in my php or perl script. I tried in my perl script to print the cookie created by punbb and i got something like that:

a:2:{i:0;s:1:"2";i:1;s:32:"3f3410c241f5ef458e47c2293e279a0c";}

I need  to get some data from cookie and then put it inside a froum and send it to perl script to evalute it .

you do realize thats how an ARRAY of some variable looks when you insert it within a db?

~thegleek

Re: using punbb cookies in perl scripts

just pass variables you need in the argvs to the perl script.
Humm, you probably could use a tmp file or two, or three for input/output/errors between the php script and the perl script tongue

echo "deadram"; echo; fortune;