-
Notifications
You must be signed in to change notification settings - Fork 9
/
NTLMStream.php
136 lines (122 loc) · 3.89 KB
/
NTLMStream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php
/**
* HTTPS stream wrapper using Microsoft's NTLM Authentication
*
* Copyright (c) 2008 Invest-In-France Agency http://www.invest-in-france.org
*
* Author : Thomas Rabaix
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* @link http://rabaix.net/en/articles/2008/03/13/using-soap-php-with-ntlm-authentication
* @author Thomas Rabaix
*/
/**
* HTTPS stream wrapper using Microsoft's NTLM Authentication
*
* @link http://rabaix.net/en/articles/2008/03/13/using-soap-php-with-ntlm-authentication
* @author Thomas Rabaix
*/
class NTLMStream {
private $path;
private $mode;
private $options;
private $opened_path;
private $buffer;
private $pos;
/**
* Whether or not to validate ssl certificates
*
* @var boolean
*/
protected $validate = false;
public function stream_open($path, $mode, $options, $opened_path) {
echo "[NTLMStream::stream_open] $path , mode=$mode \n";
$this->path = $path;
$this->mode = $mode;
$this->options = $options;
$this->opened_path = $opened_path;
$this->createBuffer($path);
return true;
}
public function stream_close() {
curl_close($this->ch);
return true;
} // end function stream_close()
public function stream_read($count) {
if(strlen($this->buffer) == 0) {
return false;
}
$read = substr($this->buffer,$this->pos, $count);
$this->pos += $count;
return $read;
} // end function stream_read()
public function stream_write($data) {
if(strlen($this->buffer) == 0) {
return false;
}
return true;
} // end function stream_write()
public function stream_eof() {
if($this->pos > strlen($this->buffer)) {
return true;
}
return false;
} // end function stream_eof()
/**
* Return the position of the current read pointer
*
* @return integer
*/
public function stream_tell() {
return $this->pos;
} // end function stream_tell();
public function stream_flush() {
$this->buffer = null;
$this->pos = null;
} // end function stream_flush()
public function stream_stat() {
$this->createBuffer($this->path);
$stat = array(
'size' => strlen($this->buffer),
);
return $stat;
} // end function stream_stat()
public function url_stat($path, $flags) {
$this->createBuffer($path);
$stat = array(
'size' => strlen($this->buffer),
);
return $stat;
} // end function url_stat()
/**
* Create the buffer by requesting the url through cURL
*
* @param string $path
*/
private function createBuffer($path) {
if($this->buffer) {
return true;
}
$this->ch = curl_init($path);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, $this->validate);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, $this->validate);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
curl_setopt($this->ch, CURLOPT_USERPWD, $this->user.':'.$this->password);
$this->buffer = curl_exec($this->ch);
$this->pos = 0;
return true;
} // end function createBuffer()
} // end class NTLMStream