xref: /plugin/siteexport/inc/httpproxy.php (revision ec70cd20236f33554fc4b65a6d3af8f9fd8ff6fd)
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.
137d101cc1SGerry 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');
217d101cc1SGerry Weißbachrequire_once( DOKU_INC . 'inc/HTTPClient.php');
227d101cc1SGerry Weißbach
237d101cc1SGerry Weißbachclass HTTPProxy extends DokuHTTPClient {
247d101cc1SGerry Weißbach
257d101cc1SGerry Weißbach    var $debugClass = null;
26cb1f35bbSGerry Weißbach    var $setttings = null;
277d101cc1SGerry Weißbach
287d101cc1SGerry Weißbach    /**
297d101cc1SGerry Weißbach     * Constructor.
307d101cc1SGerry Weißbach     */
31cb1f35bbSGerry Weißbach    function __construct($debug, $settings){
327d101cc1SGerry Weißbach        global $conf;
337d101cc1SGerry Weißbach
347d101cc1SGerry Weißbach        // call parent constructor
357d101cc1SGerry Weißbach        $this->debugClass = $debug;
36cb1f35bbSGerry Weißbach        $this->settings = $settings;
377d101cc1SGerry Weißbach        parent::__construct();
387d101cc1SGerry Weißbach
397d101cc1SGerry Weißbach        $this->timeout = 60; //max. 25 sec
407d101cc1SGerry Weißbach        $this->headers['If-Modified-Since'] = substr(gmdate('r', 0), 0, -5).'GMT';
417d101cc1SGerry Weißbach        $this->status = -1;
427d101cc1SGerry Weißbach        $this->debug = true;
43cb1f35bbSGerry Weißbach
44cb1f35bbSGerry Weißbach		if ( $this->settings->cookie == null ) {
45cb1f35bbSGerry Weißbach			$this->_debug("Has to re-authenticate request.");
46cb1f35bbSGerry Weißbach			if ( !$this->authenticate() ) {
47cb1f35bbSGerry Weißbach				$this->_debug("Trying other Authentication (auth.php):", auth_setup() && $this->authenticate(true) ? 'authenticated' : 'not authenticated'); // Try again.
487d101cc1SGerry Weißbach			}
497d101cc1SGerry Weißbach
504c005702SGerry Weißbach			$this->_debug("Using Authentication:", array('user' => $this->user, 'password' => '*****'));
51cb1f35bbSGerry Weißbach
52cb1f35bbSGerry Weißbach		} else {
53cb1f35bbSGerry Weißbach			$this->cookies = $this->settings->cookie;
54cb1f35bbSGerry Weißbach		}
55cb1f35bbSGerry Weißbach
56cb1f35bbSGerry Weißbach		$this->headers['X-Real-Ip'] = clientIP(true);
57cb1f35bbSGerry Weißbach		$this->headers['Accept-Encoding'] = $_SERVER['HTTP_ACCEPT_ENCODING'];
58cb1f35bbSGerry Weißbach		$this->headers['Accept-Charset'] = $_SERVER['HTTP_ACCEPT_CHARSET'];
59cb1f35bbSGerry Weißbach		$this->agent = $_SERVER['HTTP_USER_AGENT'];
60cb1f35bbSGerry Weißbach	}
61cb1f35bbSGerry Weißbach
62cb1f35bbSGerry Weißbach	/**
63cb1f35bbSGerry Weißbach	 * Authenticate using currently logged in user
64cb1f35bbSGerry Weißbach	 */
65cb1f35bbSGerry Weißbach	private function authenticate($secondAttempt=false) {
66cb1f35bbSGerry Weißbach
67cb1f35bbSGerry Weißbach		global $auth, $INPUT;
68cb1f35bbSGerry Weißbach
69cb1f35bbSGerry Weißbach		// Ok, this is evil. We read the login information of the current user and forward it to the HTTPClient
70cb1f35bbSGerry Weißbach		list($this->user, $sticky, $this->pass) = auth_getCookie();
71cb1f35bbSGerry Weißbach
72cb1f35bbSGerry Weißbach		// Logged in in second attempt is now in Session.
73cb1f35bbSGerry Weißbach		if ( $secondAttempt && !isset($this->user) && $INPUT->str('u') && $INPUT->str('p') ) {
74cb1f35bbSGerry Weißbach
75cb1f35bbSGerry Weißbach			// We hacked directly into the login mechanism which provides the login information without encryption via $INPUT
76cb1f35bbSGerry Weißbach			$this->user = $INPUT->str('u');
77cb1f35bbSGerry Weißbach			$this->pass = $INPUT->str('p');
78cb1f35bbSGerry Weißbach			$sticky = $INPUT->str('r');
79cb1f35bbSGerry Weißbach		} else {
80cb1f35bbSGerry Weißbach			$secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session
81*ec70cd20SGerry Weißbach			$this->pass = $this->auth_decrypt($this->pass, $secret);
82cb1f35bbSGerry Weißbach		}
83cb1f35bbSGerry Weißbach
84cb1f35bbSGerry Weißbach		return isset($this->user);
85cb1f35bbSGerry Weißbach	}
86cb1f35bbSGerry Weißbach
87cb1f35bbSGerry Weißbach	/**
88*ec70cd20SGerry Weißbach	 * Auth Decryption has changed from Weatherwax to Binky
89*ec70cd20SGerry Weißbach	 */
90*ec70cd20SGerry Weißbach	private function auth_decrypt($pass, $secret) {
91*ec70cd20SGerry Weißbach
92*ec70cd20SGerry Weißbach		if ( function_exists('auth_decrypt') ) {
93*ec70cd20SGerry Weißbach			// Binky
94*ec70cd20SGerry Weißbach			return auth_decrypt($pass, $secret);
95*ec70cd20SGerry Weißbach		} else if ( function_exists('PMA_blowfish_decrypt') ) {
96*ec70cd20SGerry Weißbach			// Weatherwax
97*ec70cd20SGerry Weißbach			return PMA_blowfish_decrypt($pass, $secret);
98*ec70cd20SGerry Weißbach		} else {
99*ec70cd20SGerry Weißbach			$this->debugClass->runtimeException("No decryption method found");
100*ec70cd20SGerry Weißbach		}
101*ec70cd20SGerry Weißbach	}
102*ec70cd20SGerry Weißbach
103*ec70cd20SGerry Weißbach	/**
104cb1f35bbSGerry Weißbach	 * Remeber HTTPClient Cookie after successfull authentication
105cb1f35bbSGerry Weißbach	 */
106cb1f35bbSGerry Weißbach	function sendRequest($url,$data='',$method='GET') {
107cb1f35bbSGerry Weißbach
108cb1f35bbSGerry Weißbach		$returnCode = parent::sendRequest($url,$data,$method);
109cb1f35bbSGerry Weißbach		if ( $this->settings->cookie == null ) {
110cb1f35bbSGerry Weißbach			$this->settings->cookie = $this->cookies;
111cb1f35bbSGerry Weißbach		}
112cb1f35bbSGerry Weißbach
113cb1f35bbSGerry Weißbach		return $returnCode;
114cb1f35bbSGerry Weißbach	}
1157d101cc1SGerry Weißbach
1167d101cc1SGerry Weißbach	 /**
1177d101cc1SGerry Weißbach	 * print debug info to file if exists
1187d101cc1SGerry Weißbach	 */
1197d101cc1SGerry Weißbach	public function _debug($info,$var=null){
1207d101cc1SGerry Weißbach
1217d101cc1SGerry Weißbach		if ( !$this->debugClass ) {
1227d101cc1SGerry Weißbach			return;
1237d101cc1SGerry Weißbach		}
1247d101cc1SGerry Weißbach
125cb1f35bbSGerry Weißbach		$this->debugClass->message("[HTTPClient] " . $info, $var, 1);
1267d101cc1SGerry Weißbach	}
1277d101cc1SGerry Weißbach}
1287d101cc1SGerry Weißbach
1297d101cc1SGerry Weißbach//Setup VIM: ex: et ts=4 enc=utf-8 :