View Single Post
Old 17th August 2010, 13:32   #294
Jkey
Forum King
 
Join Date: Jul 2004
Location: E*arth
Posts: 3,031
I don't know if its what you want but here is a basic php proxy for sc_trans
that I use for testing to eliminate the browser security issues related to
sc_trans instances running remotely.
It should work with post/get requests from the test ui out of the box
you just need adjust the testui code to point at this php file on your webserver
Security is not accounted for due to this being a "local" test code.

PHP Code:
<?PHP
//$url = $_GET['url'];
  
$url "http://your_IP:8000/api";
  
$username "admin";
  
$password "1234";
  
$dt_string"";
  
$ch curl_init$url );

  if( !
function_exists('apache_request_headers') ) {
///
function apache_request_headers() {
  
$arh = array();
  
$rx_http '/\AHTTP_/';
  foreach(
$_SERVER as $key => $val) {
    if( 
preg_match($rx_http$key) ) {
      
$arh_key preg_replace($rx_http''$key);
      
$rx_matches = array();
      
// do some nasty string manipulations to restore the original letter case
      // this should work in most cases
      
$rx_matches explode('_'$arh_key);
      if( 
count($rx_matches) > and strlen($arh_key) > ) {
        foreach(
$rx_matches as $ak_key => $ak_val$rx_matches[$ak_key] = ucfirst($ak_val);
        
$arh_key implode('-'$rx_matches);
      }
      
$arh[$arh_key] = $val;
    }
  }
  return( 
$arh );
}
///
}
///

  
$rs apache_request_headers();
  foreach(
$rs as $key => $value){
   if(
$key== "ACCEPT"){
  
$rs[$key] = "application/xml";
   }
  }

  
$rs_string "";
  foreach(
$rs as $key => $value){
  
$rs_string .=  $key."=".$value.'&';
  }
  
rtrim($rs_string,'&');

$dt $_REQUEST;
foreach(
$dt as $key => $value) {
 
$dt_string .= $key.'='.urlencode($value).'&';
}
rtrim($dt_string,'&');


  
curl_setopt($chCURLOPT_HTTPAUTHCURLAUTH_BASIC);
 
// curl_setopt($ch,CURLOPT_USERPWD,((!$_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER']:$username).":".((!$_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW']:$password));
  
curl_setopt($ch,CURLOPT_USERPWD,$username.":".$password);
  
curl_setopt$chCURLOPT_POST,true);
  
curl_setopt$chCURLOPT_POSTFIELDS$dt_string );
  
curl_setopt$chCURLOPT_FOLLOWLOCATIONtrue );
  
curl_setopt$chCURLOPT_HEADERfalse );
  
curl_setopt($chCURLOPT_HTTPHEADER,$rs_string); 
  
curl_setopt$chCURLOPT_RETURNTRANSFERtrue );
  
//curl_setopt( $ch, CURLOPT_USERAGENT,"ui");
  
$contents =  curl_exec$ch );
  
$status curl_getinfo$ch );
  
curl_close$ch );
header('Content-Type: application/xml');
print 
$contents;


?

So Long, and Thanks for All the Fish.
Jkey is offline