17d101cc1SGerry Weißbach<?php 27d101cc1SGerry Weißbach 37d101cc1SGerry Weißbach/** 47d101cc1SGerry Weißbach * i-net software provides programming examples for illustration only, 57d101cc1SGerry Weißbach * without warranty either expressed or implied, including, but not 67d101cc1SGerry Weißbach * limited to, the implied warranties of merchantability and/or fitness 77d101cc1SGerry Weißbach * for a particular purpose. This programming example assumes that you 87d101cc1SGerry Weißbach * are familiar with the programming language being demonstrated and the 97d101cc1SGerry Weißbach * tools used to create and debug procedures. i-net software support 107d101cc1SGerry Weißbach * professionals can help explain the functionality of a particular 117d101cc1SGerry Weißbach * procedure, but they will not modify these examples to provide added 127d101cc1SGerry Weißbach * functionality or construct procedures to meet your specific needs. 136792d0cfSGerry Weißbach * Copyright © i-net software 1998-2010 147d101cc1SGerry Weißbach */ 157d101cc1SGerry Weißbach 167d101cc1SGerry Weißbach/** ******************************************************************** 177d101cc1SGerry Weißbach * THIS FILE SHOULD NOT BE MODIFIED 187d101cc1SGerry Weißbach ******************************************************************** */ 197d101cc1SGerry Weißbach 207d101cc1SGerry Weißbachif (!defined('DOKU_INC')) die('meh'); 21598b862fSGerry Weißbachif ( file_exists(DOKU_INC . 'inc/HTTPClient.php') ) { 227d101cc1SGerry Weißbach require_once(DOKU_INC . 'inc/HTTPClient.php'); 23598b862fSGerry Weißbach class _HTTPProxy extends DokuHTTPClient {} 24598b862fSGerry Weißbach} else if ( class_exists( "\dokuwiki\HTTP\DokuHTTPClient", true ) ) { 25598b862fSGerry Weißbach class _HTTPProxy extends \dokuwiki\HTTP\DokuHTTPClient {} 26598b862fSGerry Weißbach} 277d101cc1SGerry Weißbach 28598b862fSGerry Weißbachclass HTTPProxy extends _HTTPProxy { 297d101cc1SGerry Weißbach 30d98cce67SGerry Weißbach public $debugClass = null; 31a8c17ab5Si-net /// software public $settings = null; 327d101cc1SGerry Weißbach 337d101cc1SGerry Weißbach /** 347d101cc1SGerry Weißbach * Constructor. 350571ece2SScrutinizer Auto-Fixer * @param siteexport_functions $functions 367d101cc1SGerry Weißbach */ 37a8c17ab5Si-net /// software public function __construct($functions) { 387d101cc1SGerry Weißbach global $conf; 398035b959SGerry Weißbach 408f1c46d4SGerry Weißbach // The proxy should only be used if configured. 418f1c46d4SGerry Weißbach // Usually the proxy will allow connections away from the current server. 428f1c46d4SGerry Weißbach // This is what we do not want in most cases. 438035b959SGerry Weißbach if ($functions->getConf('useProxy')) { 448035b959SGerry Weißbach unset($conf['proxy']); 458035b959SGerry Weißbach } 467d101cc1SGerry Weißbach 477d101cc1SGerry Weißbach // call parent constructor 481e0bea35SGerry Weissbach $this->debugClass = $functions->debug; 491e0bea35SGerry Weissbach $this->settings = $functions->settings; 507d101cc1SGerry Weißbach parent::__construct(); 517d101cc1SGerry Weißbach 527d101cc1SGerry Weißbach $this->timeout = 60; //max. 25 sec 532ab96209SGerry Weißbach $this->headers['If-Modified-Since'] = gmdate('r', 0); 547d101cc1SGerry Weißbach $this->status = -1; 557d101cc1SGerry Weißbach $this->debug = true; 56cb1f35bbSGerry Weißbach 57cb1f35bbSGerry Weißbach if ($this->settings->cookie == null) { 58cb1f35bbSGerry Weißbach $this->_debug("Has to re-authenticate request."); 59cb1f35bbSGerry Weißbach if (!$this->authenticate()) { 601e0bea35SGerry Weissbach 611e0bea35SGerry Weissbach $this->_debug("Trying other Authentication (auth.php):"); // Try again. 621e0bea35SGerry Weissbach if (!(auth_setup() && $this->authenticate(true))) { 631e0bea35SGerry Weissbach $this->_debug("Trying other Authentication (config):", $functions->authenticate() && $this->authenticate(true) ? 'authenticated' : 'not authenticated'); // Try again. 641e0bea35SGerry Weissbach } else { 651e0bea35SGerry Weissbach $this->_debug("Ok, using default auth.php"); // Try again. 661e0bea35SGerry Weissbach } 677d101cc1SGerry Weißbach } 687d101cc1SGerry Weißbach 694c005702SGerry Weißbach $this->_debug("Using Authentication:", array('user' => $this->user, 'password' => '*****')); 70cb1f35bbSGerry Weißbach 71cb1f35bbSGerry Weißbach } else { 72cb1f35bbSGerry Weißbach $this->cookies = $this->settings->cookie; 73cb1f35bbSGerry Weißbach } 74cb1f35bbSGerry Weißbach 75cb1f35bbSGerry Weißbach $this->headers['X-Real-Ip'] = clientIP(true); 76a0417606SGerry Weißbach $this->headers['X-Site-Exporter'] = $functions->getSecurityToken(); 77cb1f35bbSGerry Weißbach $this->headers['Accept-Encoding'] = $_SERVER['HTTP_ACCEPT_ENCODING']; 78cb1f35bbSGerry Weißbach $this->headers['Accept-Charset'] = $_SERVER['HTTP_ACCEPT_CHARSET']; 796a4ce600SGerry Weißbach $this->agent = $_SERVER['HTTP_USER_AGENT'] . ' DokuWiki/SiteExport'; 80cb1f35bbSGerry Weißbach } 81cb1f35bbSGerry Weißbach 82cb1f35bbSGerry Weißbach /** 83cb1f35bbSGerry Weißbach * Authenticate using currently logged in user 84cb1f35bbSGerry Weißbach */ 85cb1f35bbSGerry Weißbach private function authenticate($secondAttempt = false) { 86cb1f35bbSGerry Weißbach 87cb1f35bbSGerry Weißbach global $auth, $INPUT; 88cb1f35bbSGerry Weißbach 89cb1f35bbSGerry Weißbach // Ok, this is evil. We read the login information of the current user and forward it to the HTTPClient 90cb1f35bbSGerry Weißbach list($this->user, $sticky, $this->pass) = auth_getCookie(); 91cb1f35bbSGerry Weißbach 92cb1f35bbSGerry Weißbach // Logged in in second attempt is now in Session. 93cb1f35bbSGerry Weißbach if ($secondAttempt && !isset($this->user) && $INPUT->str('u') && $INPUT->str('p')) { 94cb1f35bbSGerry Weißbach 95cb1f35bbSGerry Weißbach // We hacked directly into the login mechanism which provides the login information without encryption via $INPUT 96cb1f35bbSGerry Weißbach $this->user = $INPUT->str('u'); 97cb1f35bbSGerry Weißbach $this->pass = $INPUT->str('p'); 98cb1f35bbSGerry Weißbach } else { 99cb1f35bbSGerry Weißbach $secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session 1003de90976SGerry Weißbach $this->pass = !empty($this->pass) ? $this->auth_decrypt($this->pass, $secret) : ''; 101cb1f35bbSGerry Weißbach } 102cb1f35bbSGerry Weißbach 103cb1f35bbSGerry Weißbach return isset($this->user); 104cb1f35bbSGerry Weißbach } 105cb1f35bbSGerry Weißbach 106cb1f35bbSGerry Weißbach /** 107ec70cd20SGerry Weißbach * Auth Decryption has changed from Weatherwax to Binky 108ec70cd20SGerry Weißbach */ 109ec70cd20SGerry Weißbach private function auth_decrypt($pass, $secret) { 110ec70cd20SGerry Weißbach 111ec70cd20SGerry Weißbach if (function_exists('auth_decrypt')) { 112ec70cd20SGerry Weißbach // Binky 113ec70cd20SGerry Weißbach return auth_decrypt($pass, $secret); 114ec70cd20SGerry Weißbach } else if (function_exists('PMA_blowfish_decrypt')) { 115ec70cd20SGerry Weißbach // Weatherwax 116ec70cd20SGerry Weißbach return PMA_blowfish_decrypt($pass, $secret); 117ec70cd20SGerry Weißbach } else { 118ec70cd20SGerry Weißbach $this->debugClass->runtimeException("No decryption method found"); 119ec70cd20SGerry Weißbach } 120ec70cd20SGerry Weißbach } 121ec70cd20SGerry Weißbach 122ec70cd20SGerry Weißbach /** 123cb1f35bbSGerry Weißbach * Remeber HTTPClient Cookie after successfull authentication 124cb1f35bbSGerry Weißbach */ 125a8c17ab5Si-net /// software public function sendRequest($url, $data = '', $method = 'GET') { 126cb1f35bbSGerry Weißbach 127cb1f35bbSGerry Weißbach $returnCode = parent::sendRequest($url, $data, $method); 128cb1f35bbSGerry Weißbach if ($this->settings->cookie == null) { 129cb1f35bbSGerry Weißbach $this->settings->cookie = $this->cookies; 130cb1f35bbSGerry Weißbach } 131cb1f35bbSGerry Weißbach 132cb1f35bbSGerry Weißbach return $returnCode; 133cb1f35bbSGerry Weißbach } 1347d101cc1SGerry Weißbach 1357d101cc1SGerry Weißbach /** 1367d101cc1SGerry Weißbach * print debug info to file if exists 1370571ece2SScrutinizer Auto-Fixer * @param string $info 13864269406SGerry Weißbach * @param mixed $var 1397d101cc1SGerry Weißbach */ 140*cac1d6daSGerry Weißbach public function _debug($info, $var = null) { 1417d101cc1SGerry Weißbach 1427d101cc1SGerry Weißbach if (!$this->debugClass) { 1437d101cc1SGerry Weißbach return; 1447d101cc1SGerry Weißbach } 1457d101cc1SGerry Weißbach 146cb1f35bbSGerry Weißbach $this->debugClass->message("[HTTPClient] " . $info, $var, 1); 1477d101cc1SGerry Weißbach } 14864269406SGerry Weißbach 14964269406SGerry Weißbach /** 15064269406SGerry Weißbach * print debug info to file if exists 15164269406SGerry Weißbach * @param string $info 15264269406SGerry Weißbach * @param mixed $var 15364269406SGerry Weißbach */ 15464269406SGerry Weißbach protected function debug($info, $var = null) { 15564269406SGerry Weißbach $this->_debug( $info, $var ); 15664269406SGerry Weißbach } 1577d101cc1SGerry Weißbach} 1587d101cc1SGerry Weißbach 1597d101cc1SGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 : 160