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