114 lines
4.0 KiB
PHP
114 lines
4.0 KiB
PHP
<?php
|
|
|
|
class Note extends PhpObject
|
|
{
|
|
private $sNote;
|
|
private $sUrl;
|
|
private $sCookie;
|
|
|
|
function __construct($sNote)
|
|
{
|
|
parent::__construct(__CLASS__, Settings::DEBUG);
|
|
$this->sNote = $sNote;
|
|
$this->sUrl = '';
|
|
$this->sCookie = '';
|
|
}
|
|
|
|
public function getNote()
|
|
{
|
|
$sContent = '';
|
|
if($this->sNote!='')
|
|
{
|
|
$this->sUrl = 'http://service.sap.com/sap/support/notes/'.$this->sNote;
|
|
$this->getPageRecursive();
|
|
$sSapPath = substr($this->sUrl, 0, strpos($this->sUrl, '/bc/bsp/sno/ui_entry/entry.htm'));
|
|
$sFirstDir = substr($sSapPath, strpos($sSapPath, 'sap('));
|
|
$this->sUrl = $sSapPath.'/bc/bsp/sno/ui/main.do'.strstr($this->sUrl, '?param=');
|
|
|
|
$sDomain = self::getDomain($this->sUrl);
|
|
$sDomain = $sDomain.(substr($sDomain, -1)=='/'?'':'/');
|
|
|
|
$sContent = $this->getPage();
|
|
$sContent = preg_replace('`(src|href|action|popup_emptydoc|emptyhoverurl|mimepath|stylepath)(\=|\:)\"(.*)\"`mUi', '$1$2"'.$sDomain.'$3"', $sContent);
|
|
$sContent = preg_replace('`(src|href|action|popup_emptydoc|emptyhoverurl|mimepath|stylepath)(\=|\:)\\\'(.*)\\\'`mUi', '$1$2"'.$sDomain.'$3"', $sContent);
|
|
$sContent = preg_replace('`url\((.*)\)`mUi', 'url('.$sDomain.'$1)"', $sContent);
|
|
$sContent = str_replace('.sap-ag.de//', '.sap-ag.de/', $sContent);
|
|
$sContent = str_replace('.sap-ag.de/1x1', '.sap-ag.de/'.$sFirstDir.'/bc/bsp/sno/ui/1x1', $sContent);
|
|
$sContent = str_replace("url = '/sap/support/notes/'", "url = '".$sDomain."sap/support/notes/'", $sContent);
|
|
|
|
//$sContent = str_replace('domainrelaxing:sapUrDomainRelaxing.NONE', 'domainrelaxing:sapUrDomainRelaxing.MAXIMAL', $sContent);
|
|
|
|
//Add customized javascript function
|
|
$sPre = '<script>window.onresize = setHeight;';
|
|
$sPost = '</script>';
|
|
$sInsert = ' parent.onEndOfProcess();';
|
|
$sContent = str_replace($sPre.$sPost, $sPre.$sInsert.$sPost, $sContent);
|
|
|
|
//Deleting auto resize
|
|
//$sContent = str_replace('lv_diff = 210','lv_diff = 0', $sContent);
|
|
$sContent = str_replace(array('setHeight();', 'window.onresize = setHeight; '), '', $sContent);
|
|
|
|
}
|
|
else $this->addError('Empty note number');
|
|
|
|
return $sContent;
|
|
}
|
|
|
|
private function getPage($bHeader=false)
|
|
{
|
|
$oCurl = curl_init();
|
|
curl_setopt($oCurl, CURLOPT_URL, $this->sUrl);
|
|
curl_setopt($oCurl, CURLOPT_HEADER, $bHeader);
|
|
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($oCurl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
|
//if($bHeader) curl_setopt($oCurl, CURLOPT_FOLLOWLOCATION, true);
|
|
if($this->sCookie!='') curl_setopt($oCurl, CURLOPT_COOKIE, $this->sCookie);
|
|
curl_setopt($oCurl, CURLOPT_USERPWD, $this->getCredentials());
|
|
$sContent = curl_exec($oCurl);
|
|
curl_close($oCurl);
|
|
return $sContent;
|
|
}
|
|
|
|
private function getPageRecursive()
|
|
{
|
|
$sheader = $this->getPage(true);
|
|
$asLines = explode("\n", $sheader);
|
|
foreach($asLines as $sLine) $asInfo[strtolower(strstr($sLine, ':', true))] = trim(substr(strstr($sLine, ':'), 1));
|
|
|
|
if(array_key_exists('set-cookie', $asInfo)) $this->parseSetCookie($asInfo['set-cookie']);
|
|
|
|
$bToBeContinued = array_key_exists('location', $asInfo);
|
|
if($bToBeContinued)
|
|
{
|
|
$this->sUrl = ((substr($asInfo['location'], 0, 4)!='http')?self::getDomain($this->sUrl):'').$asInfo['location'];
|
|
return $this->getPageRecursive();
|
|
}
|
|
else return substr($sheader, strpos($sheader, '<html>'));
|
|
}
|
|
|
|
private function parseSetCookie($sCookie)
|
|
{
|
|
//Store current cookie
|
|
$this->sCookie .= $sCookie;
|
|
|
|
//Parse FIXME
|
|
$asCookieInfo = explode('; ', $sCookie);
|
|
foreach($asCookieInfo as $sCookieInfo) $asCookie[strstr($sCookieInfo, '=', true)] = substr(strstr($sCookieInfo, '='), 1);
|
|
setcookie('sap-appcontext', $asCookie['sap-appcontext'], time()+3600, $asCookie['path']);
|
|
}
|
|
|
|
private function getCredentials()
|
|
{
|
|
$asLogins = array_keys(Settings::$OSS_ACCOUNTS);
|
|
$iIndex = rand(0, count($asLogins)-1);
|
|
return $asLogins[$iIndex].':'.Settings::$OSS_ACCOUNTS[$asLogins[$iIndex]];
|
|
}
|
|
|
|
private static function getDomain($sUrl)
|
|
{
|
|
$asUrl = parse_url($sUrl);
|
|
return $asUrl['scheme'].'://'.$asUrl['host'];
|
|
}
|
|
}
|
|
|
|
?>
|