1<?php 2 3/** 4 * i-net software provides programming examples for illustration only, 5 * without warranty either expressed or implied, including, but not 6 * limited to, the implied warranties of merchantability and/or fitness 7 * for a particular purpose. This programming example assumes that you 8 * are familiar with the programming language being demonstrated and the 9 * tools used to create and debug procedures. i-net software support 10 * professionals can help explain the functionality of a particular 11 * procedure, but they will not modify these examples to provide added 12 * functionality or construct procedures to meet your specific needs. 13 * Copyright © i-net software 1998-2010 14 */ 15 16/** ******************************************************************** 17 * THIS FILE SHOULD NOT BE MODIFIED 18 ******************************************************************** */ 19 20if (!defined('DOKU_INC')) die('meh'); 21require_once(DOKU_INC . 'inc/HTTPClient.php'); 22 23class HTTPProxy extends DokuHTTPClient { 24 25 public $debugClass = null; 26 public $settings = null; 27 28 /** 29 * Constructor. 30 * @param siteexport_functions $functions 31 */ 32 public function __construct($functions) { 33 global $conf; 34 35 // The proxy should only be used if configured. 36 // Usually the proxy will allow connections away from the current server. 37 // This is what we do not want in most cases. 38 if ($functions->getConf('useProxy')) { 39 unset($conf['proxy']); 40 } 41 42 // call parent constructor 43 $this->debugClass = $functions->debug; 44 $this->settings = $functions->settings; 45 parent::__construct(); 46 47 $this->timeout = 60; //max. 25 sec 48 $this->headers['If-Modified-Since'] = gmdate('r', 0); 49 $this->status = -1; 50 $this->debug = true; 51 52 if ($this->settings->cookie == null) { 53 $this->_debug("Has to re-authenticate request."); 54 if (!$this->authenticate()) { 55 56 $this->_debug("Trying other Authentication (auth.php):"); // Try again. 57 if (!(auth_setup() && $this->authenticate(true))) { 58 $this->_debug("Trying other Authentication (config):", $functions->authenticate() && $this->authenticate(true) ? 'authenticated' : 'not authenticated'); // Try again. 59 } else { 60 $this->_debug("Ok, using default auth.php"); // Try again. 61 } 62 } 63 64 $this->_debug("Using Authentication:", array('user' => $this->user, 'password' => '*****')); 65 66 } else { 67 $this->cookies = $this->settings->cookie; 68 } 69 70 $this->headers['X-Real-Ip'] = clientIP(true); 71 $this->headers['X-Site-Exporter'] = $functions->getSecurityToken(); 72 $this->headers['Accept-Encoding'] = $_SERVER['HTTP_ACCEPT_ENCODING']; 73 $this->headers['Accept-Charset'] = $_SERVER['HTTP_ACCEPT_CHARSET']; 74 $this->agent = $_SERVER['HTTP_USER_AGENT'] . ' DokuWiki/SiteExport'; 75 } 76 77 /** 78 * Authenticate using currently logged in user 79 */ 80 private function authenticate($secondAttempt = false) { 81 82 global $auth, $INPUT; 83 84 // Ok, this is evil. We read the login information of the current user and forward it to the HTTPClient 85 list($this->user, $sticky, $this->pass) = auth_getCookie(); 86 87 // Logged in in second attempt is now in Session. 88 if ($secondAttempt && !isset($this->user) && $INPUT->str('u') && $INPUT->str('p')) { 89 90 // We hacked directly into the login mechanism which provides the login information without encryption via $INPUT 91 $this->user = $INPUT->str('u'); 92 $this->pass = $INPUT->str('p'); 93 } else { 94 $secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session 95 $this->pass = !empty($this->pass) ? $this->auth_decrypt($this->pass, $secret) : ''; 96 } 97 98 return isset($this->user); 99 } 100 101 /** 102 * Auth Decryption has changed from Weatherwax to Binky 103 */ 104 private function auth_decrypt($pass, $secret) { 105 106 if (function_exists('auth_decrypt')) { 107 // Binky 108 return auth_decrypt($pass, $secret); 109 } else if (function_exists('PMA_blowfish_decrypt')) { 110 // Weatherwax 111 return PMA_blowfish_decrypt($pass, $secret); 112 } else { 113 $this->debugClass->runtimeException("No decryption method found"); 114 } 115 } 116 117 /** 118 * Remeber HTTPClient Cookie after successfull authentication 119 */ 120 public function sendRequest($url, $data = '', $method = 'GET') { 121 122 $returnCode = parent::sendRequest($url, $data, $method); 123 if ($this->settings->cookie == null) { 124 $this->settings->cookie = $this->cookies; 125 } 126 127 return $returnCode; 128 } 129 130 /** 131 * print debug info to file if exists 132 * @param string $info 133 */ 134 public function _debug($info, $var = null) { 135 136 if (!$this->debugClass) { 137 return; 138 } 139 140 $this->debugClass->message("[HTTPClient] " . $info, $var, 1); 141 } 142} 143 144//Setup VIM: ex: et ts=4 enc=utf-8 : 145