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'); 21if ( file_exists(DOKU_INC . 'inc/HTTPClient.php') ) { 22 require_once(DOKU_INC . 'inc/HTTPClient.php'); 23 class _HTTPProxy extends DokuHTTPClient {} 24} else if ( class_exists( "\dokuwiki\HTTP\DokuHTTPClient", true ) ) { 25 class _HTTPProxy extends \dokuwiki\HTTP\DokuHTTPClient {} 26} 27 28class HTTPProxy extends _HTTPProxy { 29 30 public $debugClass = null; 31 public $settings = null; 32 33 /** 34 * Constructor. 35 * @param siteexport_functions $functions 36 */ 37 public function __construct($functions) { 38 global $conf; 39 40 // The proxy should only be used if configured. 41 // Usually the proxy will allow connections away from the current server. 42 // This is what we do not want in most cases. 43 if ($functions->getConf('useProxy')) { 44 unset($conf['proxy']); 45 } 46 47 // call parent constructor 48 $this->debugClass = $functions->debug; 49 $this->settings = $functions->settings; 50 parent::__construct(); 51 52 $this->timeout = 60; //max. 25 sec 53 $this->headers['If-Modified-Since'] = gmdate('r', 0); 54 $this->status = -1; 55 $this->debug = true; 56 57 if ($this->settings->cookie == null) { 58 $this->_debug("Has to re-authenticate request."); 59 if (!$this->authenticate()) { 60 61 $this->_debug("Trying other Authentication (auth.php):"); // Try again. 62 if (!(auth_setup() && $this->authenticate(true))) { 63 $this->_debug("Trying other Authentication (config):", $functions->authenticate() && $this->authenticate(true) ? 'authenticated' : 'not authenticated'); // Try again. 64 } else { 65 $this->_debug("Ok, using default auth.php"); // Try again. 66 } 67 } 68 69 $this->_debug("Using Authentication:", array('user' => $this->user, 'password' => '*****')); 70 71 } else { 72 $this->cookies = $this->settings->cookie; 73 } 74 75 $this->headers['X-Real-Ip'] = clientIP(true); 76 $this->headers['X-Site-Exporter'] = $functions->getSecurityToken(); 77 $this->headers['Accept-Encoding'] = $_SERVER['HTTP_ACCEPT_ENCODING'] ?? ''; 78 $this->headers['Accept-Charset'] = $_SERVER['HTTP_ACCEPT_CHARSET'] ?? ''; 79 $this->agent = $_SERVER['HTTP_USER_AGENT'] . ' DokuWiki/SiteExport'; 80 } 81 82 /** 83 * Authenticate using currently logged in user 84 */ 85 private function authenticate($secondAttempt = false) { 86 87 global $auth, $INPUT; 88 89 // Ok, this is evil. We read the login information of the current user and forward it to the HTTPClient 90 list($this->user, $sticky, $this->pass) = auth_getCookie(); 91 92 // Logged in in second attempt is now in Session. 93 if ($secondAttempt && !isset($this->user) && $INPUT->str('u') && $INPUT->str('p')) { 94 95 // We hacked directly into the login mechanism which provides the login information without encryption via $INPUT 96 $this->user = $INPUT->str('u'); 97 $this->pass = $INPUT->str('p'); 98 } else { 99 $secret = auth_cookiesalt(!$sticky, true); //bind non-sticky to session 100 $this->pass = !empty($this->pass) ? $this->auth_decrypt($this->pass, $secret) : ''; 101 } 102 103 return isset($this->user); 104 } 105 106 /** 107 * Auth Decryption has changed from Weatherwax to Binky 108 */ 109 private function auth_decrypt($pass, $secret) { 110 111 if (function_exists('auth_decrypt')) { 112 // Binky 113 return auth_decrypt($pass, $secret); 114 } else if (function_exists('PMA_blowfish_decrypt')) { 115 // Weatherwax 116 return PMA_blowfish_decrypt($pass, $secret); 117 } else { 118 $this->debugClass->runtimeException("No decryption method found"); 119 } 120 } 121 122 /** 123 * Remeber HTTPClient Cookie after successfull authentication 124 */ 125 public function sendRequest($url, $data = '', $method = 'GET') { 126 127 $returnCode = parent::sendRequest($url, $data, $method); 128 if ($this->settings->cookie == null) { 129 $this->settings->cookie = $this->cookies; 130 } 131 132 return $returnCode; 133 } 134 135 /** 136 * print debug info to file if exists 137 * @param string $info 138 * @param mixed $var 139 */ 140 public function _debug($info, $var = null) { 141 142 if (!$this->debugClass) { 143 return; 144 } 145 146 $this->debugClass->message("[HTTPClient] " . $info, $var, 1); 147 } 148 149 /** 150 * print debug info to file if exists 151 * @param string $info 152 * @param mixed $var 153 */ 154 protected function debug($info, $var = null) { 155 $this->_debug( $info, $var ); 156 } 157} 158 159//Setup VIM: ex: et ts=4 enc=utf-8 : 160