If this is your first visit, check our documentation. To post, register or login.
Forums / Community Contributed Add-Ons / Contribution-Writing Guidelines / 3rd party software access using XML-RPC for PHP

3rd party software access using XML-RPC for PHP

Started by torvista on 30 Sep 2012, 9:33 AM · Views: 4,575

Results 1 to 8 of 8
30 Sep 2012, 9:33 AM
#1
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,880
Plugin Contributions:
7

Post #1 by torvista

(http://phpxmlrpc.sourceforge.net/)

This particular connector I am "overseeing" the fine-tuning of, is working mostly correctly.

  1. The connector was written for oscommerce and although it does not have any calls to osc functions, it is all direct db queries like
    mysql_query("insert etc..

which for some reason makes me uneasy.
Is there any case (security/safety) to use the standard zen functions instead?

  1. I would like the admin activity log to note when the connector does something.
    Is there a function I could call to do that, or a dummy page it could load to trigger a log entry, or just easier to directly insert a record in the log?

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

30 Sep 2012, 5:16 PM
#2
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #2 by drbyte

If it were to call application_top properly then it would trigger the proper logging too.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

24 Oct 2012, 9:30 AM
#3
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,880
Plugin Contributions:
7

Post #3 by torvista

call application_top properly

Hmm... the "properly" bit is escaping me. Just including it crashes the application thats using it. The usual php error log is empty.

The structure of the file is like this

 include("xmlrpcutils/xmlrpc.inc");
	include("xmlrpcutils/xmlrpcs.inc");
	include("../../includes/configure.php");
	//include("../../includes/application_top.php");//crashes application
define('RESPONSE_ENCODING', 'UTF-8'); //It must be your DDBB encoding
define('DEBUG_FILE', 'debug.xmlrpc.txt'); //Absolute path to debug and warning file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	$con = mysql_pconnect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD);
	mysql_select_db(DB_DATABASE);

followed by a list of the various functions, for example

	function get_taxes() {
		debug('fn '.__FUNCTION__ . ' ('. __LINE__.', '.date('d/m/Y,H:i:s').')');//steve
		
		$taxes = array();

		$result = mysql_query("select tax_class_id, tax_class_title from tax_class;");
		if ($result) while ($row = mysql_fetch_row($result)) {
			$taxes[] = new xmlrpcval(array(new xmlrpcval($row[0], "int"), new xmlrpcval($row[1], "string")), "array");
		}
		return new xmlrpcresp( new xmlrpcval($taxes, "array"));
	}

(Since this file is in a known location, I assume its vulnerable to cross-site scripting with the query as is?)

and at the end the creation of the new server object

$server = new xmlrpc_server( array(	"get_taxes" => array(		"function" => "get_taxes",
																	"signature" => array(	array($xmlrpcArray)
																						)
																	),
etc...

This issue is now more than a desire than just wanting access to be logged...the function that gets the payment methods chokes on paypalwpp as that payment method class references the base class and calls zen_functions which this file can't find, so I assume getting application_top called properly would solve that issue...

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

24 Oct 2012, 3:03 PM
#4
drbyte avatar

drbyte

Sensei

Join Date:
Jan 2004
Posts:
63,512
Plugin Contributions:
176

Post #4 by drbyte

A couple things that stand out:

  1. application_top should normally be loaded before configure.php ... because it will load configure.php automatically. So you won't need to call configure.php afterward either.
  2. application_top expects that the file calling it is in a folder just ONE directory-level above it. Not two like you're doing. Use PHP's chdir() function to change directory into your ZC store's main folder before calling application_top.

.
Zen Cart - putting the dream of business ownership within reach of anyone!
Donate to: DrByte directly or to the Zen Cart team as a whole

Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

24 Oct 2012, 8:57 PM
#5
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,880
Plugin Contributions:
7

Post #5 by torvista

Well, I could not get it to work with application_top.

I've done too many tests to detail it:
absolute paths,
chdir and reducing the path to configure.php (for testing that path combination that was ok),
moving the files to root
moving the files to includes.
But whatever I tried the best I could get was application_top not found irrespective of the path used (all combinations from absolute downwards), even when it could find configure.php with the same path.

While I can work round the actual problem that has instigated the desire to do this, its annoying to leave it at this.

FYI original path info, if that contradicts your previous post.
Shop
/home/xxxxx/public_html/tienda/includes/configure.php
Connector/calling file
/home/xxxxx/public_html/tienda/xyz/connector/connector_file.php

Wouldn't work at all with the file in the shop root...issue with the host code I think.

thanks anyway.

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

24 Oct 2012, 9:20 PM
#6
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #6 by wilt

k,

so the file that remote services will call on your server is

connector_file.php

This should go in the root of the ADMIN directory,

then
in connector_file.php you have

include('includes/application_top.php');
include(DIR_FS_ADMIN . 'somepath' . "xmlrpcutils/xmlrpc.inc");
include(DIR_FS_ADMIN . 'somepath' . "xmlrpcutils/xmlrpcs.inc");
define('RESPONSE_ENCODING', 'UTF-8'); //It must be your DDBB encoding
define('DEBUG_FILE', 'debug.xmlrpc.txt'); //Absolute path to debug and warning file
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    $con = mysql_pconnect(DB_SERVER, DB_SERVER_USERNAME, DB_SERVER_PASSWORD);
    mysql_select_db(DB_DATABASE);

note the 'somepath' bit will have to be adjusted to suit the location you have placed theses files.

e.g.

include(DIR_FS_ADMIN . 'includes/functions/' . "xmlrpcutils/xmlrpc.inc");

24 Oct 2012, 9:25 PM
#7
wilt avatar

wilt

Oji-san

Join Date:
Jun 2003
Location:
Newcastle UK
Posts:
1,950
Plugin Contributions:
3

Post #7 by wilt

Hi,

I guess it should also be mentioned that by including the admin application_top.php you will also be restricted in that
it will attempt to 'authorise' any call to that file based on the existence (or not) of a valid admin_id in the current session

So in this sense it may not be suitable for you to include application_top.php

24 Oct 2012, 9:39 PM
#8
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,880
Plugin Contributions:
7

Post #8 by torvista

Thanks for the input.

I agree, that seemed the obvious way it should have been from the start...and one of the things I tried to begin with even before starting this thread but the host application wont connect with it in the shop root. I'm sure its a path discrepancy in the host code which I am trying to avoid fiddling with, my knowledge of Python is limited to dead parrots.

This is my problem with this issue, although I contracted a consultancy to deal with the host application and fix the (originally osc) connector, once I started testing I found all sorts of holes in it so have ended up revising the connector myself as its evident I can't trust anyone else to spend the hours required to test properly/be safe with poking about in my perfectly-functioning shop database.

So, back to vim...

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...