Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_VALID_MOS not being defined

Status
Not open for further replies.

cjelec

Programmer
Jan 5, 2007
491
GB
Hi,

Using a Joomla module that is for making purchases online. It has a callback page for WorldPay to send back saying that it has accepted the payment.

The problem I'm having is that the code starts with the usual:

define('_VALID_MOS', 1);

Then it imports the database.php file:

require_once($mambo_path.'includes/database.php');

But this line returns 'Restricted access' on the page. I looked in the database.php file and it checks the _VALID_MOS:

defined( '_VALID_MOS' ) or die( 'Restricted access' );

So I'm thinking that its not setting or picking up the _VALID_MOS properly.

Can someone help me?

Thanks
 
can you post the code of your module? i suspect there is something wrong in the logic.
 
Hi, thanks for looking at my question.

The module is called Virtuemart and the file is called worldpay_notify.php

Code:
<?php
/*
* @version $Id: worldpay_notify.php 617 2007-01-04 19:43:08Z soeren_nb $
* @package VirtueMart
* @subpackage Payment
*
* @copyright (C) 2004 Soeren Eberhardt
* @license [URL unfurl="true"]http://www.gnu.org/copyleft/gpl.html[/URL] GNU/GPL
* VirtueMart is Free Software.
* VirtueMart comes with absolute no warranty.
*
* [URL unfurl="true"]www.virtuemart.net[/URL]
*/

if ($_POST) {

	WriteFile("Start of file");

    define('_VALID_MOS', '1');

    global $mosConfig_absolute_path, $mosConfig_live_site, $mosConfig_lang;

	WriteFile("Mambo config");
    /*** access Mambo's configuration file ***/
    $my_path = dirname($_SERVER['SCRIPT_FILENAME']);
	WriteFile("Script_Filename=" . $my_path);
	WriteFile("Mambo config 1");
    $mambo_path = str_replace("administrator/components/com_virtuemart", "", $my_path);
	WriteFile("Mambo_path=" . $mambo_path);
	WriteFile("Mambo config 2");
    require_once($mambo_path.'configuration.php');
	WriteFile("Mambo config 3");

// ######### ERROR HAPPENS ON LINE BELOW ############
    require_once($mambo_path.'includes/database.php');

	WriteFile("Mambo config 4");

    global $database;
WriteFile("Mambo config 5");
    $database = new database( $mosConfig_host, $mosConfig_user, $mosConfig_password, $mosConfig_db, $mosConfig_dbprefix );
WriteFile("Mambo language");
    // load Mambo Language File
    if (file_exists( $mosConfig_absolute_path. '/language/'.$mosConfig_lang.'.php' )){
      require_once( $mosConfig_absolute_path. '/language/'.$mosConfig_lang.'.php' );
    }
    else{
      require_once( $mosConfig_absolute_path. '/language/english.php' );
    }

    /*** END of Mambo config ***/

    /*** VirtueMart part ***/
WriteFile("Virtuemart part");
    define('PHPSHOPPATH', $mosConfig_absolute_path.'/administrator/components/com_virtuemart/');

    require_once(PHPSHOPPATH."virtuemart.cfg.php");

	
	require_once( CLASSPATH. "language.class.php" );
	
    //Set up the mailer to infor Warehouse of validated order
    //require_once( $mosConfig_absolute_path . '/includes/phpmailer/class.phpmailer.php');
    //$mail = new mosPHPMailer();
    //$mail->PluginDir = $mosConfig_absolute_path . '/includes/phpmailer/';
    //$mail->SetLanguage("en", $mosConfig_absolute_path . '/includes/phpmailer/language/');
  
WriteFile("Virtuemart language");
    /* load the VirtueMart Language File */
    if (file_exists( ADMINPATH. 'languages/'.$mosConfig_lang.'.php' ))
      require_once( ADMINPATH. 'languages/'.$mosConfig_lang.'.php' );
    else
      require_once( ADMINPATH. 'languages/english.php' );


    /* 
    Moded
    Gotta replace this...perhaps
    Load the PayPal Configuration File 
    */ 
    require_once( CLASSPATH. 'payment/ps_worldpay.cfg.php' );



    /* Load the VirtueMart database class */
    require_once( CLASSPATH. 'ps_database.php' );

    /*** END VirtueMart part ***/

    /**
    Read in the post from worldpay.
    Email was used in PayPal version

    **/
	WriteFile("Start of foreach");
    $workstring = 'cmd=_notify-validate'; // Notify validate
    $i = 1;
    foreach ($_POST as $ipnkey => $ipnval) {
        if (get_magic_quotes_gpc())
            // Fix issue with magic quotes
            $ipnval = stripslashes ($ipnval);
            
       if (!eregi("^[_0-9a-z-]{1,30}$",$ipnkey)  || !strcasecmp ($ipnkey, 'cmd'))  { 
            // ^ Antidote to potential variable injection and poisoning
            unset ($ipnkey); 
            unset ($ipnval); 
        } 
       // Eliminate the above
        // Remove empty keys (not values)
        if (@$ipnkey != '') { 
          //unset ($_POST); // Destroy the original ipn post array, sniff...
          $workstring.='&'.@$ipnkey.'='.urlencode(@$ipnval); 
        }
       echo "key ".$i++.": $ipnkey, value: $ipnval<br />";
    } // Notify string
WriteFile("Payment Status");
    $payment_status  = trim(stripslashes($_POST['transStatus'])); //if $payment_status == 'Y'?
    $order_id =  trim(stripslashes($_POST['cartId']));
    
    $d['order_id'] = $order_id;    //this identifies the order record

    if( $payment_status == 'Y' ){
        $d['order_status'] = 'C';  //this is the new value for the database field I think X for cancelled, C for confirmed
    }
    else if( $payment_status == 'C' ){
        $d['order_status'] = 'X';  //this is the new value for the database field I think X for cancelled, C for confirmed
    }
//Write $_POST to file
    WriteFile("ps_order.php");
    require_once ( CLASSPATH . 'ps_order.php' );

    $ps_order= new ps_order;

    $ps_order->order_status_update($d);
	WriteFile("EOF");
}

function WriteFile($msg)
{
	$d = date('d.m.y H.i.s');
	$fh = fopen("mylog.txt", 'a');
	fwrite($fh, $d . $msg . "\n");
	fclose($fh);
}
?>

I added the WriteFile function so that i could diagnose the error and find out that the vars were correct. I have maked where the code stops, I know this because the log file only goes upto "Mambo config 3" and the page output says "Restricted access"...

Thanks again
 
that seems very strange.

some debugging. just before the require_once line can you add this

Code:
writeFile('.........');
writeFile('just before the require');
writeFile(print_r(get_defined_constants(true), true));
writeFile('.........');

this should tell us what the constants state is at the time of the include.

try also adding this debug snip just before the defined() line in database.php.

please post back the relevant snips of the output.
 
Hi,

I'll have to do that on Monday as I don't have access to the server till then.

When I get the response from the line of code I'll post it for you to have a look at it.

Whilst waiting till Monday, A few thoughts that I have had:

1) Are Constants stored in the session file?
2) Are Constants restricted to scope?
3) If this file (WorldPay_notify) is located in
/administrator/components/com_virtuemart and its
referencing a file using full paths
(Win based: c:\wamp\ would that create a new session?

Thanks again
 
1. no
2. constants have global scope
3. cookies are based on the http url, not the file uri's. so the change in directory should not create a new session.
 
Hi,

I finally got around to testing the site again. I added your code to the file and ran it. Found that it does set the _VALID_MOS and that there are a lot of constants named with something for mysql and database...

So I'm none the wiser...

Thanks again
 
ok. did you test for the constants in the db file too? (not that they can be unset, i'm just interested in what is being called at that moment).

you could also try increasing the level of debugging in the database file by changing this line

Code:
defined( '_VALID_MOS' ) or die( 'Restricted access' );

to

Code:
writefile('about to test db file');
if (defined('_VALID_MOS')){
 writeFile('VM is defined');
} else {
 writeFile('VM is not defined');
 exit();
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top