Page 1 of 1

please explain this typical coding

Posted: Thu Dec 30, 2010 10:45 am
by chandana27
<?php

// function to obtain WAPI cred
function getCred($cUserName,$cPassWord){
$credXml = '<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://soap.webapp.webex.com">
<soapenv:Body>
<login>
<userName>'.$cUserName.'</userName>
<password>'.$cPassWord.'</password>
<isp>WBX</isp>
</login>
</soapenv:Body>
</soapenv:Envelope>';
$fromCmd = "getCred";
$credRequest = postIt($credXml, "login", $fromCmd);

// Set up the parser object
$parser = new XMLParser($credRequest);

// activate the parsing ...
$parser->Parse();
$credStatus = $parser->document->responseresult[0]->tagData;

// if the login fails
if ($credStatus == "FAILURE") {
// display the error
$credResult = $parser->document->resultstring[0]->tagData;
echo '<div align="center" style="width:100%; text-align:center; color:#FF0000; background-color:#FFFFFF"\>
<h3>There was a problem with the info you provided.<br/>The error returned by the system: </h3>
<h3 style="color:#000000; font-family:Courier New; font-size:11pt;">'.$credResult.'</h3></div>'; }
else {
// store the cred
$cred = $parser->document->soapenv_body[0]->wbxapi[0]->securitycontext[0]->cred[0]->tagData;
return $cred; }
}

// function to obtain the middleware's login token
function getToken($connectID,$eURL,$env,$admin_acct,$admin_pw){
$timeStamp = date('Y-m-d\TH:m:s');
$requestID = "ID_".$timeStamp;
// create the XML to send
$tokenXml = '<listWorkspaces xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.webex.org/wbxcommunity/1.0" xsi:schemaLocation="http://www.webex.org/wbxcommunity/1.0 listWorkspaces.xsd">
<signature>
<partnerID>'.$admin_acct.'</partnerID>
<partnerPassword>'.$admin_pw.'</partnerPassword>
<requestID>'.$requestID.'</requestID>
<timestamp>'.$timeStamp.'</timestamp>
</signature>
<numberOfActivities>1</numberOfActivities>
<connectID>'.$connectID.'</connectID>
</listWorkspaces>';
$fromCmd = "listWorkspaces";
// post the XML and receive response
$cred = postIt($tokenXml,$eURL,$fromCmd);

// Set up the parser object
$parser = new XMLParser($cred);

// Work the magic...
$parser->Parse();
$tokenStatus = $parser->document->responseresult[0]->tagData;

if ($tokenStatus == "FAILURE") {
$tokenResult = $parser->document->resultstring[0]->tagData;
echo '<div align="center" style="width:100%; text-align:center; color:#FF0000; background-color:#FFFFFF"\>
<h3>There was a problem with the info you provided.<br/>The error returned by the system: </h3>
<h3 style="color:#000000; font-family:Courier New; font-size:11pt;">'.$tokenResult.'</h3></div>'; }
else {
$tokenParse = $parser->document->logintoken[0]->tagData;
return $tokenParse; }
}

// function to do XML processing
function postIt1($requestXml,$eURL,$fromCmd){
// set to 1 to view in debug mode
$Debug_Mode = 0;

// Set up the parser object
$parser = new XMLParser($requestXML);

// Work the magic...
$parser->Parse();
$xmlResponse = $parser->document->responseresult[0]->tagData;

// VZ Proxy
$ProxyServer = "banfproxy.verizon.com";
$fp = fsockopen($ProxyServer, 80, $errno, $errstr);
if (!$fp){
echo "Failed to open ProxyServer: $ProxyServer Error number $errno, $errstr.<br>";
return 0;
}
/**/
// $fp = fsockopen($proxy, $errno, $errstr);
// if the request is a WAPI request
if (($eURL == "login") || ($eURL == "get")){
$action = $eURL;
$eURL = "swapi.webexconnect.com";
// $fp = fsockopen("ssl://".$URL, 443, $errno, $errstr);
$hdr = "POST /wbxconnect/services/WBXConnect HTTP/1.1\n";
$hdr .= "Host: ".$eURL."\n";
$hdr .= "SOAPAction: ".$action."\n";
$hdr .= "Content-Type: application/x-www-form-urlencoded\n";
$hdr .= "Content-Length: ".strlen($requestXml)."\n\n";
}
// else it's a middleware request
else {
// $fp = fsockopen("ssl://".$eURL, 443, $errno, $errstr);
$hdr = "POST /voffice/rapi/".$fromCmd." HTTP/1.1\r\n";
$hdr .= "Content-type: text/xml\r\n";
$hdr .= "Host: ".$eURL."\r\n";
$hdr .= "Connection: Keep-Alive\r\n";
$hdr .= "Content-length: ".strlen($requestXml)."\r\n\r\n";
}
$hdr .= $requestXml;

/* $fp = fsockopen($eURL,80,$errno,$errstr,90);
if (!$fp) {
die ( "Could not connect to server. The error returned the server: $errno, $errstr\n" ); }
*/
if($Debug_Mode){
echo "XML sent to server: <br>";
echo "<textarea cols=\"100\" rows=\"30\">".htmlspecialchars($requestXml)."</textarea><br><br>";
}
if($fp){
fwrite($fp,$hdr);
$response = "";
while (!feof($fp)) {
$response .= fgets($fp); }

//remove header info from response
$response = strstr($response,'<?xml');
if($Debug_Mode){
echo "Received from the server:<br>";
echo "<textarea cols=\"100\" rows=\"30\">".htmlspecialchars($response)."</textarea><br><br>";
}
return $response;
fclose($fp);
}
else {
return false; }
}


function postIt($requestXml,$eURL,$fromCmd)
{
if (($eURL == "login") || ($eURL == "get"))
{
$action = $eURL;
$eURL = "https://swapi.webexconnect.com";

$header = "POST ".$eURL."/wbxconnect/services/WBXConnect HTTP/1.1\n";
$header .= "Host: ".$eURL."\r\n";
$header .= "SOAPAction: ".$action."\n";
$header .= "User-Agent: My Agent\r\n";
$header .= "Content-type: application/xml\r\n";
$header .= "Content-length: ".strlen($requestXml)." \r\n\r\n";
} else {
$eURL = "https://".$eURL;

$header = "POST ".$eURL."/voffice/rapi/".$fromCmd." HTTP/1.1\r\n";
$header .= "Host: ".$eURL."\r\n";
$header .= "User-Agent: My Agent\r\n";
$header .= "Content-type: application/xml\r\n";
$header .= "Content-length: ".strlen($requestXml)." \r\n\r\n";
}

$header .= $requestXml;
$header .= "\r\n";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $eURL);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $header);
curl_setopt($ch, CURLOPT_PROXY, "banproxy.verizon.com:80");

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);

$data = curl_exec($ch);

if (curl_errno($ch)) {
print curl_error($ch);
} else {
curl_close($ch);
//echo "<textarea cols=\"100\" rows=\"30\">".$data."</textarea><br><br>";
return $data;
}
}

?>



can someone please explain me this coding, If you are unable to explain the entire coding, at least help me to some extent.

Thanks in advance

Re: please explain this typical coding

Posted: Thu Dec 30, 2010 2:23 pm
by dorthea
Sorry Chandana, i have gone through your coding, but was unable to understand. Even i am looking forwrd 4 sum 1 who will elaborate that coding.

Re: please explain this typical coding

Posted: Thu Dec 30, 2010 2:37 pm
by greyhoundcode
To be honest it gives me a headache just looking at it, in its current form at least. Can you edit it and wrap the code in syntax tags? (Use the PHP Code button)