Subversion Repositories oidplus

Rev

Rev 277 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 277 Rev 386
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 * http.php
4
 * This file includes:
-
 
5
 *
-
 
6
 * 1. PHP HTTP protocol client: HTTP client to access Web site pages
5
 *    by Manuel Lemos
7
 *    by Manuel Lemos
6
 *    http://www.phpclasses.org/httpclient
8
 *    http://www.phpclasses.org/httpclient
7
 *    License: BSD License
9
 *    License: BSD License
8
 *
10
 *
-
 
11
 *    http.php
-
 
12
 *        @(#) $Header: /opt2/ena/metal/http/http.php,v 1.94 2016/05/03 02:07:04 mlemos Exp $
-
 
13
 *        Modified by Daniel Marschall, ViaThinkSoft, Revision 2020-09-12
-
 
14
 *
-
 
15
 *
-
 
16
 * 2. Simple Authentication and Security Layer client
-
 
17
 *    (Included because of dependency)
-
 
18
 *    by Manuel Lemos
-
 
19
 *    http://www.phpclasses.org/sasl
-
 
20
 *    License: BSD License
-
 
21
 *
-
 
22
 *    sasl.php
-
 
23
 *        @(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $
-
 
24
 *    basic_sasl_client.php
-
 
25
 *        @(#) $Id: basic_sasl_client.php,v 1.1 2004/11/17 08:01:23 mlemos Exp $
-
 
26
 *    cram_md5_sasl_client.php
-
 
27
 *        @(#) $Id: cram_md5_sasl_client.php,v 1.3 2004/11/17 08:00:37 mlemos Exp $
-
 
28
 *    digest_sasl_client.php
-
 
29
 *        @(#) $Id: digest_sasl_client.php,v 1.1 2005/10/27 05:24:15 mlemos Exp $
-
 
30
 *    login_sasl_client.php
-
 
31
 *        @(#) $Id: login_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
-
 
32
 *    ntlm_sasl_client.php
-
 
33
 *        @(#) $Id: ntlm_sasl_client.php,v 1.3 2004/11/17 08:00:37 mlemos Exp $
-
 
34
 *    plain_sasl_client.php
-
 
35
 *        @(#) $Id: plain_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
-
 
36
 */
-
 
37
 
-
 
38
// =============================================================================
-
 
39
 
-
 
40
/*
-
 
41
 * basic_sasl_client.php
-
 
42
 *
-
 
43
 * @(#) $Id: basic_sasl_client.php,v 1.1 2004/11/17 08:01:23 mlemos Exp $
-
 
44
 *
-
 
45
 */
-
 
46
 
-
 
47
define("SASL_BASIC_STATE_START",    0);
-
 
48
define("SASL_BASIC_STATE_DONE",     1);
-
 
49
 
-
 
50
class basic_sasl_client_class
-
 
51
{
-
 
52
        var $credentials=array();
-
 
53
        var $state=SASL_BASIC_STATE_START;
-
 
54
 
-
 
55
        Function Initialize(&$client)
-
 
56
        {
-
 
57
                return(1);
-
 
58
        }
-
 
59
 
-
 
60
        Function Start(&$client, &$message, &$interactions)
-
 
61
        {
-
 
62
                if($this->state!=SASL_BASIC_STATE_START)
-
 
63
                {
-
 
64
                        $client->error="Basic authentication state is not at the start";
-
 
65
                        return(SASL_FAIL);
-
 
66
                }
-
 
67
                $this->credentials=array(
-
 
68
                        "user"=>"",
-
 
69
                        "password"=>""
-
 
70
                );
-
 
71
                $defaults=array(
-
 
72
                );
-
 
73
                $status=$client->GetCredentials($this->credentials,$defaults,$interactions);
-
 
74
                if($status==SASL_CONTINUE)
-
 
75
                {
-
 
76
                        $message=$this->credentials["user"].":".$this->credentials["password"];
-
 
77
                        $this->state=SASL_BASIC_STATE_DONE;
-
 
78
                }
-
 
79
                else
-
 
80
                        Unset($message);
-
 
81
                return($status);
-
 
82
        }
-
 
83
 
-
 
84
        Function Step(&$client, $response, &$message, &$interactions)
-
 
85
        {
-
 
86
                switch($this->state)
-
 
87
                {
-
 
88
                        case SASL_BASIC_STATE_DONE:
-
 
89
                                $client->error="Basic authentication was finished without success";
-
 
90
                                return(SASL_FAIL);
-
 
91
                        default:
-
 
92
                                $client->error="invalid Basic authentication step state";
-
 
93
                                return(SASL_FAIL);
-
 
94
                }
-
 
95
                return(SASL_CONTINUE);
-
 
96
        }
-
 
97
};
-
 
98
 
-
 
99
// =============================================================================
-
 
100
 
-
 
101
/*
-
 
102
 * cram_md5_sasl_client.php
-
 
103
 *
-
 
104
 * @(#) $Id: cram_md5_sasl_client.php,v 1.3 2004/11/17 08:00:37 mlemos Exp $
-
 
105
 *
-
 
106
 */
-
 
107
 
-
 
108
define("SASL_CRAM_MD5_STATE_START",             0);
-
 
109
define("SASL_CRAM_MD5_STATE_RESPOND_CHALLENGE", 1);
-
 
110
define("SASL_CRAM_MD5_STATE_DONE",              2);
-
 
111
 
-
 
112
class cram_md5_sasl_client_class
-
 
113
{
-
 
114
        var $credentials=array();
-
 
115
        var $state=SASL_CRAM_MD5_STATE_START;
-
 
116
 
-
 
117
        Function Initialize(&$client)
-
 
118
        {
-
 
119
                return(1);
-
 
120
        }
-
 
121
 
-
 
122
        Function HMACMD5($key,$text)
-
 
123
        {
-
 
124
                $key=(strlen($key)<64 ? str_pad($key,64,"\0") : substr($key,0,64));
-
 
125
                return(md5((str_repeat("\x5c", 64)^$key).pack("H32", md5((str_repeat("\x36", 64)^$key).$text))));
-
 
126
        }
-
 
127
 
-
 
128
        Function Start(&$client, &$message, &$interactions)
-
 
129
        {
-
 
130
                if($this->state!=SASL_CRAM_MD5_STATE_START)
-
 
131
                {
-
 
132
                        $client->error="CRAM-MD5 authentication state is not at the start";
-
 
133
                        return(SASL_FAIL);
-
 
134
                }
-
 
135
                $this->credentials=array(
-
 
136
                        "user"=>"",
-
 
137
                        "password"=>""
-
 
138
                );
-
 
139
                $defaults=array();
-
 
140
                $status=$client->GetCredentials($this->credentials,$defaults,$interactions);
-
 
141
                if($status==SASL_CONTINUE)
-
 
142
                        $this->state=SASL_CRAM_MD5_STATE_RESPOND_CHALLENGE;
-
 
143
                Unset($message);
-
 
144
                return($status);
-
 
145
        }
-
 
146
 
-
 
147
        Function Step(&$client, $response, &$message, &$interactions)
-
 
148
        {
-
 
149
                switch($this->state)
-
 
150
                {
-
 
151
                        case SASL_CRAM_MD5_STATE_RESPOND_CHALLENGE:
-
 
152
                                $message=$this->credentials["user"]." ".$this->HMACMD5($this->credentials["password"], $response);
-
 
153
                                $this->state=SASL_CRAM_MD5_STATE_DONE;
-
 
154
                                break;
-
 
155
                        case SASL_CRAM_MD5_STATE_DONE:
-
 
156
                                $client->error="CRAM-MD5 authentication was finished without success";
-
 
157
                                return(SASL_FAIL);
-
 
158
                        default:
-
 
159
                                $client->error="invalid CRAM-MD5 authentication step state";
-
 
160
                                return(SASL_FAIL);
-
 
161
                }
-
 
162
                return(SASL_CONTINUE);
-
 
163
        }
-
 
164
};
-
 
165
 
-
 
166
// =============================================================================
-
 
167
 
-
 
168
/*
-
 
169
 * digest_sasl_client.php
-
 
170
 *
-
 
171
 * @(#) $Id: digest_sasl_client.php,v 1.1 2005/10/27 05:24:15 mlemos Exp $
-
 
172
 *
-
 
173
 */
-
 
174
 
-
 
175
define('SASL_DIGEST_STATE_START',             0);
-
 
176
define('SASL_DIGEST_STATE_RESPOND_CHALLENGE', 1);
-
 
177
define('SASL_DIGEST_STATE_DONE',              2);
-
 
178
 
-
 
179
class digest_sasl_client_class
-
 
180
{
-
 
181
        var $credentials=array();
-
 
182
        var $state=SASL_DIGEST_STATE_START;
-
 
183
 
-
 
184
        Function unq($string)
-
 
185
        {
-
 
186
                return(($string[0]=='"' && $string[strlen($string)-1]=='"') ? substr($string, 1, strlen($string)-2) : $string);
-
 
187
        }
-
 
188
 
-
 
189
        Function H($data)
-
 
190
        {
-
 
191
                return md5($data);
-
 
192
        }
-
 
193
 
-
 
194
        Function KD($secret, $data)
-
 
195
        {
-
 
196
                return $this->H($secret.':'.$data);
-
 
197
        }
-
 
198
 
-
 
199
        Function Initialize(&$client)
-
 
200
        {
-
 
201
                return(1);
-
 
202
        }
-
 
203
 
-
 
204
        Function Start(&$client, &$message, &$interactions)
-
 
205
        {
-
 
206
                if($this->state!=SASL_DIGEST_STATE_START)
-
 
207
                {
-
 
208
                        $client->error='Digest authentication state is not at the start';
-
 
209
                        return(SASL_FAIL);
-
 
210
                }
-
 
211
                $this->credentials=array(
-
 
212
                        'user'=>'',
-
 
213
                        'password'=>'',
-
 
214
                        'uri'=>'',
-
 
215
                        'method'=>'',
-
 
216
                        'session'=>''
-
 
217
                );
-
 
218
                $defaults=array();
-
 
219
                $status=$client->GetCredentials($this->credentials,$defaults,$interactions);
-
 
220
                if($status==SASL_CONTINUE)
-
 
221
                        $this->state=SASL_DIGEST_STATE_RESPOND_CHALLENGE;
-
 
222
                Unset($message);
-
 
223
                return($status);
-
 
224
        }
-
 
225
 
-
 
226
        Function Step(&$client, $response, &$message, &$interactions)
-
 
227
        {
-
 
228
                switch($this->state)
-
 
229
                {
-
 
230
                        case SASL_DIGEST_STATE_RESPOND_CHALLENGE:
-
 
231
                                $values=explode(',',$response);
-
 
232
                                $parameters=array();
-
 
233
                                for($v=0; $v<count($values); $v++)
-
 
234
                                        $parameters[strtok(trim($values[$v]), '=')]=strtok('');
-
 
235
 
-
 
236
                                $message='username="'.$this->credentials['user'].'"';
-
 
237
                                if(!IsSet($parameters[$p='realm'])
-
 
238
                                && !IsSet($parameters[$p='nonce']))
-
 
239
                                {
-
 
240
                                        $client->error='Digest authentication parameter '.$p.' is missing from the server response';
-
 
241
                                        return(SASL_FAIL);
-
 
242
                                }
-
 
243
                                $message.=', realm='.$parameters['realm'];
-
 
244
                                $message.=', nonce='.$parameters['nonce'];
-
 
245
                                $message.=', uri="'.$this->credentials['uri'].'"';
-
 
246
                                if(IsSet($parameters['algorithm']))
-
 
247
                                {
-
 
248
                                        $algorithm=$this->unq($parameters['algorithm']);
-
 
249
                                        $message.=', algorithm='.$parameters['algorithm'];
-
 
250
                                }
-
 
251
                                else
-
 
252
                                        $algorithm='';
-
 
253
 
-
 
254
                                $realm=$this->unq($parameters['realm']);
-
 
255
                                $nonce=$this->unq($parameters['nonce']);
-
 
256
                                if(IsSet($parameters['qop']))
-
 
257
                                {
-
 
258
                                        switch($qop=$this->unq($parameters['qop']))
-
 
259
                                        {
-
 
260
                                                case "auth":
-
 
261
                                                        $cnonce=$this->credentials['session'];
-
 
262
                                                        break;
-
 
263
                                                default:
-
 
264
                                                        $client->error='Digest authentication quality of protection '.$qop.' is not yet supported';
-
 
265
                                                        return(SASL_FAIL);
-
 
266
                                        }
-
 
267
                                }
-
 
268
                                $nc_value='00000001';
-
 
269
                                if(IsSet($parameters['qop'])
-
 
270
                                && !strcmp($algorithm, 'MD5-sess'))
-
 
271
                                        $A1=$this->H($this->credentials['user'].':'. $realm.':'. $this->credentials['password']).':'.$nonce.':'.$cnonce;
-
 
272
                                else
-
 
273
                                        $A1=$this->credentials['user'].':'. $realm.':'. $this->credentials['password'];
-
 
274
                                $A2=$this->credentials['method'].':'.$this->credentials['uri'];
-
 
275
                                if(IsSet($parameters['qop']))
-
 
276
                                        $response=$this->KD($this->H($A1), $nonce.':'. $nc_value.':'. $cnonce.':'. $qop.':'. $this->H($A2));
-
 
277
                                else
-
 
278
                                        $response=$this->KD($this->H($A1), $nonce.':'. $this->H($A2));
-
 
279
                                $message.=', response="'.$response.'"';
-
 
280
                                if(IsSet($parameters['opaque']))
-
 
281
                                        $message.=', opaque='.$parameters['opaque'];
-
 
282
                                if(IsSet($parameters['qop']))
-
 
283
                                        $message.=', qop="'.$qop.'"';
-
 
284
                                $message.=', nc='.$nc_value;
-
 
285
                                if(IsSet($parameters['qop']))
-
 
286
                                        $message.=', cnonce="'.$cnonce.'"';
-
 
287
                                $client->encode_response=0;
-
 
288
                                $this->state=SASL_DIGEST_STATE_DONE;
-
 
289
                                break;
-
 
290
                        case SASL_DIGEST_STATE_DONE:
-
 
291
                                $client->error='Digest authentication was finished without success';
-
 
292
                                return(SASL_FAIL);
-
 
293
                        default:
-
 
294
                                $client->error='invalid Digest authentication step state';
-
 
295
                                return(SASL_FAIL);
-
 
296
                }
-
 
297
                return(SASL_CONTINUE);
-
 
298
        }
-
 
299
};
-
 
300
 
-
 
301
// =============================================================================
-
 
302
 
-
 
303
/*
-
 
304
 * login_sasl_client.php
-
 
305
 *
-
 
306
 * @(#) $Id: login_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
-
 
307
 *
-
 
308
 */
-
 
309
 
-
 
310
define("SASL_LOGIN_STATE_START",             0);
-
 
311
define("SASL_LOGIN_STATE_IDENTIFY_USER",     1);
-
 
312
define("SASL_LOGIN_STATE_IDENTIFY_PASSWORD", 2);
-
 
313
define("SASL_LOGIN_STATE_DONE",              3);
-
 
314
 
-
 
315
class login_sasl_client_class
-
 
316
{
-
 
317
        var $credentials=array();
-
 
318
        var $state=SASL_LOGIN_STATE_START;
-
 
319
 
-
 
320
        Function Initialize(&$client)
-
 
321
        {
-
 
322
                return(1);
-
 
323
        }
-
 
324
 
-
 
325
        Function Start(&$client, &$message, &$interactions)
-
 
326
        {
-
 
327
                if($this->state!=SASL_LOGIN_STATE_START)
-
 
328
                {
-
 
329
                        $client->error="LOGIN authentication state is not at the start";
-
 
330
                        return(SASL_FAIL);
-
 
331
                }
-
 
332
                $this->credentials=array(
-
 
333
                        "user"=>"",
-
 
334
                        "password"=>"",
-
 
335
                        "realm"=>""
-
 
336
                );
-
 
337
                $defaults=array(
-
 
338
                        "realm"=>""
-
 
339
                );
-
 
340
                $status=$client->GetCredentials($this->credentials,$defaults,$interactions);
-
 
341
                if($status==SASL_CONTINUE)
-
 
342
                        $this->state=SASL_LOGIN_STATE_IDENTIFY_USER;
-
 
343
                Unset($message);
-
 
344
                return($status);
-
 
345
        }
-
 
346
 
-
 
347
        Function Step(&$client, $response, &$message, &$interactions)
-
 
348
        {
-
 
349
                switch($this->state)
-
 
350
                {
-
 
351
                        case SASL_LOGIN_STATE_IDENTIFY_USER:
-
 
352
                                $message=$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "");
-
 
353
                                $this->state=SASL_LOGIN_STATE_IDENTIFY_PASSWORD;
-
 
354
                                break;
-
 
355
                        case SASL_LOGIN_STATE_IDENTIFY_PASSWORD:
-
 
356
                                $message=$this->credentials["password"];
-
 
357
                                $this->state=SASL_LOGIN_STATE_DONE;
-
 
358
                                break;
-
 
359
                        case SASL_LOGIN_STATE_DONE:
-
 
360
                                $client->error="LOGIN authentication was finished without success";
-
 
361
                                break;
-
 
362
                        default:
-
 
363
                                $client->error="invalid LOGIN authentication step state";
-
 
364
                                return(SASL_FAIL);
-
 
365
                }
-
 
366
                return(SASL_CONTINUE);
-
 
367
        }
-
 
368
};
-
 
369
 
-
 
370
// =============================================================================
-
 
371
 
-
 
372
/*
-
 
373
 * ntlm_sasl_client.php
-
 
374
 *
-
 
375
 * @(#) $Id: ntlm_sasl_client.php,v 1.3 2004/11/17 08:00:37 mlemos Exp $
-
 
376
 *
-
 
377
 */
-
 
378
 
-
 
379
define("SASL_NTLM_STATE_START",             0);
-
 
380
define("SASL_NTLM_STATE_IDENTIFY_DOMAIN",   1);
-
 
381
define("SASL_NTLM_STATE_RESPOND_CHALLENGE", 2);
-
 
382
define("SASL_NTLM_STATE_DONE",              3);
-
 
383
 
-
 
384
class ntlm_sasl_client_class
-
 
385
{
-
 
386
        var $credentials=array();
-
 
387
        var $state=SASL_NTLM_STATE_START;
-
 
388
 
-
 
389
        Function Initialize(&$client)
-
 
390
        {
-
 
391
                if(!function_exists($function="mcrypt_encrypt")
-
 
392
                || !function_exists($function="mhash"))
-
 
393
                {
-
 
394
                        $extensions=array(
-
 
395
                                "mcrypt_encrypt"=>"mcrypt",
-
 
396
                                "mhash"=>"mhash"
-
 
397
                        );
-
 
398
                        $client->error="the extension ".$extensions[$function]." required by the NTLM SASL client class is not available in this PHP configuration";
-
 
399
                        return(0);
-
 
400
                }
-
 
401
                return(1);
-
 
402
        }
-
 
403
 
-
 
404
        Function ASCIIToUnicode($ascii)
-
 
405
        {
-
 
406
                for($unicode="",$a=0;$a<strlen($ascii);$a++)
-
 
407
                        $unicode.=substr($ascii,$a,1).chr(0);
-
 
408
                return($unicode);
-
 
409
        }
-
 
410
 
-
 
411
        Function TypeMsg1($domain,$workstation)
-
 
412
        {
-
 
413
                $domain_length=strlen($domain);
-
 
414
                $workstation_length=strlen($workstation);
-
 
415
                $workstation_offset=32;
-
 
416
                $domain_offset=$workstation_offset+$workstation_length;
-
 
417
                return(
-
 
418
                        "NTLMSSP\0".
-
 
419
                        "\x01\x00\x00\x00".
-
 
420
                        "\x07\x32\x00\x00".
-
 
421
                        pack("v",$domain_length).
-
 
422
                        pack("v",$domain_length).
-
 
423
                        pack("V",$domain_offset).
-
 
424
                        pack("v",$workstation_length).
-
 
425
                        pack("v",$workstation_length).
-
 
426
                        pack("V",$workstation_offset).
-
 
427
                        $workstation.
-
 
428
                        $domain
-
 
429
                );
-
 
430
        }
-
 
431
 
-
 
432
        Function NTLMResponse($challenge,$password)
-
 
433
        {
-
 
434
                $unicode=$this->ASCIIToUnicode($password);
-
 
435
                $md4=mhash(MHASH_MD4,$unicode);
-
 
436
                $padded=$md4.str_repeat(chr(0),21-strlen($md4));
-
 
437
                $iv_size=mcrypt_get_iv_size(MCRYPT_DES,MCRYPT_MODE_ECB);
-
 
438
                $iv=mcrypt_create_iv($iv_size,MCRYPT_RAND);
-
 
439
                for($response="",$third=0;$third<21;$third+=7)
-
 
440
                {
-
 
441
                        for($packed="",$p=$third;$p<$third+7;$p++)
-
 
442
                                $packed.=str_pad(decbin(ord(substr($padded,$p,1))),8,"0",STR_PAD_LEFT);
-
 
443
                        for($key="",$p=0;$p<strlen($packed);$p+=7)
-
 
444
                        {
-
 
445
                                $s=substr($packed,$p,7);
-
 
446
                                $b=$s.((substr_count($s,"1") % 2) ? "0" : "1");
-
 
447
                                $key.=chr(bindec($b));
-
 
448
                        }
-
 
449
                        $ciphertext=mcrypt_encrypt(MCRYPT_DES,$key,$challenge,MCRYPT_MODE_ECB,$iv);
-
 
450
                        $response.=$ciphertext;
-
 
451
                }
-
 
452
                return $response;
-
 
453
        }
-
 
454
 
-
 
455
        Function TypeMsg3($ntlm_response,$user,$domain,$workstation)
-
 
456
        {
-
 
457
                $domain_unicode=$this->ASCIIToUnicode($domain);
-
 
458
                $domain_length=strlen($domain_unicode);
-
 
459
                $domain_offset=64;
-
 
460
                $user_unicode=$this->ASCIIToUnicode($user);
-
 
461
                $user_length=strlen($user_unicode);
-
 
462
                $user_offset=$domain_offset+$domain_length;
-
 
463
                $workstation_unicode=$this->ASCIIToUnicode($workstation);
-
 
464
                $workstation_length=strlen($workstation_unicode);
-
 
465
                $workstation_offset=$user_offset+$user_length;
-
 
466
                $lm="";
-
 
467
                $lm_length=strlen($lm);
-
 
468
                $lm_offset=$workstation_offset+$workstation_length;
-
 
469
                $ntlm=$ntlm_response;
-
 
470
                $ntlm_length=strlen($ntlm);
-
 
471
                $ntlm_offset=$lm_offset+$lm_length;
-
 
472
                $session="";
-
 
473
                $session_length=strlen($session);
-
 
474
                $session_offset=$ntlm_offset+$ntlm_length;
-
 
475
                return(
-
 
476
                        "NTLMSSP\0".
-
 
477
                        "\x03\x00\x00\x00".
-
 
478
                        pack("v",$lm_length).
-
 
479
                        pack("v",$lm_length).
-
 
480
                        pack("V",$lm_offset).
-
 
481
                        pack("v",$ntlm_length).
-
 
482
                        pack("v",$ntlm_length).
-
 
483
                        pack("V",$ntlm_offset).
-
 
484
                        pack("v",$domain_length).
-
 
485
                        pack("v",$domain_length).
-
 
486
                        pack("V",$domain_offset).
-
 
487
                        pack("v",$user_length).
-
 
488
                        pack("v",$user_length).
-
 
489
                        pack("V",$user_offset).
-
 
490
                        pack("v",$workstation_length).
-
 
491
                        pack("v",$workstation_length).
-
 
492
                        pack("V",$workstation_offset).
-
 
493
                        pack("v",$session_length).
-
 
494
                        pack("v",$session_length).
-
 
495
                        pack("V",$session_offset).
-
 
496
                        "\x01\x02\x00\x00".
-
 
497
                        $domain_unicode.
-
 
498
                        $user_unicode.
-
 
499
                        $workstation_unicode.
-
 
500
                        $lm.
-
 
501
                        $ntlm
-
 
502
                );
-
 
503
        }
-
 
504
 
-
 
505
        Function Start(&$client, &$message, &$interactions)
-
 
506
        {
-
 
507
                if($this->state!=SASL_NTLM_STATE_START)
-
 
508
                {
-
 
509
                        $client->error="NTLM authentication state is not at the start";
-
 
510
                        return(SASL_FAIL);
-
 
511
                }
-
 
512
                $this->credentials=array(
-
 
513
                        "user"=>"",
-
 
514
                        "password"=>"",
-
 
515
                        "realm"=>"",
-
 
516
                        "workstation"=>""
-
 
517
                );
-
 
518
                $defaults=array();
-
 
519
                $status=$client->GetCredentials($this->credentials,$defaults,$interactions);
-
 
520
                if($status==SASL_CONTINUE)
-
 
521
                        $this->state=SASL_NTLM_STATE_IDENTIFY_DOMAIN;
-
 
522
                Unset($message);
-
 
523
                return($status);
-
 
524
        }
-
 
525
 
-
 
526
        Function Step(&$client, $response, &$message, &$interactions)
-
 
527
        {
-
 
528
                switch($this->state)
-
 
529
                {
-
 
530
                        case SASL_NTLM_STATE_IDENTIFY_DOMAIN:
-
 
531
                                $message=$this->TypeMsg1($this->credentials["realm"],$this->credentials["workstation"]);
-
 
532
                                $this->state=SASL_NTLM_STATE_RESPOND_CHALLENGE;
-
 
533
                                break;
-
 
534
                        case SASL_NTLM_STATE_RESPOND_CHALLENGE:
-
 
535
                                $ntlm_response=$this->NTLMResponse(substr($response,24,8),$this->credentials["password"]);
-
 
536
                                $message=$this->TypeMsg3($ntlm_response,$this->credentials["user"],$this->credentials["realm"],$this->credentials["workstation"]);
-
 
537
                                $this->state=SASL_NTLM_STATE_DONE;
-
 
538
                                break;
-
 
539
                        case SASL_NTLM_STATE_DONE:
-
 
540
                                $client->error="NTLM authentication was finished without success";
-
 
541
                                return(SASL_FAIL);
-
 
542
                        default:
-
 
543
                                $client->error="invalid NTLM authentication step state";
-
 
544
                                return(SASL_FAIL);
-
 
545
                }
-
 
546
                return(SASL_CONTINUE);
-
 
547
        }
-
 
548
};
-
 
549
 
-
 
550
// =============================================================================
-
 
551
 
-
 
552
/*
-
 
553
 * plain_sasl_client.php
-
 
554
 *
-
 
555
 * @(#) $Id: plain_sasl_client.php,v 1.2 2004/11/17 08:00:37 mlemos Exp $
-
 
556
 *
-
 
557
 */
-
 
558
 
-
 
559
define("SASL_PLAIN_STATE_START",    0);
-
 
560
define("SASL_PLAIN_STATE_IDENTIFY", 1);
-
 
561
define("SASL_PLAIN_STATE_DONE",     2);
-
 
562
 
-
 
563
define("SASL_PLAIN_DEFAULT_MODE",            0);
-
 
564
define("SASL_PLAIN_EXIM_MODE",               1);
-
 
565
define("SASL_PLAIN_EXIM_DOCUMENTATION_MODE", 2);
-
 
566
 
-
 
567
class plain_sasl_client_class
-
 
568
{
-
 
569
        var $credentials=array();
-
 
570
        var $state=SASL_PLAIN_STATE_START;
-
 
571
 
-
 
572
        Function Initialize(&$client)
-
 
573
        {
-
 
574
                return(1);
-
 
575
        }
-
 
576
 
-
 
577
        Function Start(&$client, &$message, &$interactions)
-
 
578
        {
-
 
579
                if($this->state!=SASL_PLAIN_STATE_START)
-
 
580
                {
-
 
581
                        $client->error="PLAIN authentication state is not at the start";
-
 
582
                        return(SASL_FAIL);
-
 
583
                }
-
 
584
                $this->credentials=array(
-
 
585
                        "user"=>"",
-
 
586
                        "password"=>"",
-
 
587
                        "realm"=>"",
-
 
588
                        "mode"=>""
-
 
589
                );
-
 
590
                $defaults=array(
-
 
591
                        "realm"=>"",
-
 
592
                        "mode"=>""
-
 
593
                );
-
 
594
                $status=$client->GetCredentials($this->credentials,$defaults,$interactions);
-
 
595
                if($status==SASL_CONTINUE)
-
 
596
                {
-
 
597
                        switch($this->credentials["mode"])
-
 
598
                        {
-
 
599
                                case SASL_PLAIN_EXIM_MODE:
-
 
600
                                        $message=$this->credentials["user"]."\0".$this->credentials["password"]."\0";
-
 
601
                                        break;
-
 
602
                                case SASL_PLAIN_EXIM_DOCUMENTATION_MODE:
-
 
603
                                        $message="\0".$this->credentials["user"]."\0".$this->credentials["password"];
-
 
604
                                        break;
-
 
605
                                default:
-
 
606
                                        $message=$this->credentials["user"]."\0".$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "")."\0".$this->credentials["password"];
-
 
607
                                        break;
-
 
608
                        }
-
 
609
                        $this->state=SASL_PLAIN_STATE_DONE;
-
 
610
                }
-
 
611
                else
-
 
612
                        Unset($message);
-
 
613
                return($status);
-
 
614
        }
-
 
615
 
-
 
616
        Function Step(&$client, $response, &$message, &$interactions)
-
 
617
        {
-
 
618
                switch($this->state)
-
 
619
                {
-
 
620
/*
-
 
621
                        case SASL_PLAIN_STATE_IDENTIFY:
-
 
622
                                switch($this->credentials["mode"])
-
 
623
                                {
-
 
624
                                        case SASL_PLAIN_EXIM_MODE:
-
 
625
                                                $message=$this->credentials["user"]."\0".$this->credentials["password"]."\0";
-
 
626
                                                break;
-
 
627
                                        case SASL_PLAIN_EXIM_DOCUMENTATION_MODE:
-
 
628
                                                $message="\0".$this->credentials["user"]."\0".$this->credentials["password"];
-
 
629
                                                break;
-
 
630
                                        default:
-
 
631
                                                $message=$this->credentials["user"]."\0".$this->credentials["user"].(strlen($this->credentials["realm"]) ? "@".$this->credentials["realm"] : "")."\0".$this->credentials["password"];
-
 
632
                                                break;
-
 
633
                                }
-
 
634
                                var_dump($message);
-
 
635
                                $this->state=SASL_PLAIN_STATE_DONE;
-
 
636
                                break;
-
 
637
*/
-
 
638
                        case SASL_PLAIN_STATE_DONE:
-
 
639
                                $client->error="PLAIN authentication was finished without success";
-
 
640
                                return(SASL_FAIL);
-
 
641
                        default:
-
 
642
                                $client->error="invalid PLAIN authentication step state";
-
 
643
                                return(SASL_FAIL);
-
 
644
                }
-
 
645
                return(SASL_CONTINUE);
-
 
646
        }
-
 
647
};
-
 
648
 
-
 
649
// =============================================================================
-
 
650
 
-
 
651
/*
-
 
652
 * sasl.php
-
 
653
 *
-
 
654
 * @(#) $Id: sasl.php,v 1.11 2005/10/31 18:43:27 mlemos Exp $
-
 
655
 *
-
 
656
 */
-
 
657
 
-
 
658
define("SASL_INTERACT", 2);
-
 
659
define("SASL_CONTINUE", 1);
-
 
660
define("SASL_OK",       0);
-
 
661
define("SASL_FAIL",    -1);
-
 
662
define("SASL_NOMECH",  -4);
-
 
663
 
-
 
664
class sasl_interact_class
-
 
665
{
-
 
666
    var $id;
-
 
667
    var $challenge;
-
 
668
    var $prompt;
-
 
669
    var $default_result;
-
 
670
    var $result;
-
 
671
};
-
 
672
 
-
 
673
class sasl_client_class
-
 
674
{
-
 
675
    /* Public variables */
-
 
676
 
-
 
677
    var $error='';
-
 
678
 
-
 
679
    var $mechanism='';
-
 
680
 
-
 
681
    var $encode_response=1;
-
 
682
 
-
 
683
    /* Private variables */
-
 
684
 
-
 
685
    var $driver;
-
 
686
    var $drivers=array(
-
 
687
        "Digest"   => array("digest_sasl_client_class"/*,   "digest_sasl_client.php"   */),
-
 
688
        "CRAM-MD5" => array("cram_md5_sasl_client_class"/*, "cram_md5_sasl_client.php" */),
-
 
689
        "LOGIN"    => array("login_sasl_client_class"/*,    "login_sasl_client.php"    */),
-
 
690
        "NTLM"     => array("ntlm_sasl_client_class"/*,     "ntlm_sasl_client.php"     */),
-
 
691
        "PLAIN"    => array("plain_sasl_client_class"/*,    "plain_sasl_client.php"    */),
-
 
692
        "Basic"    => array("basic_sasl_client_class"/*,    "basic_sasl_client.php"    */)
-
 
693
    );
-
 
694
    var $credentials=array();
-
 
695
 
-
 
696
    /* Public functions */
-
 
697
 
-
 
698
    Function SetCredential($key,$value)
-
 
699
    {
-
 
700
        $this->credentials[$key]=$value;
-
 
701
    }
-
 
702
 
-
 
703
    Function GetCredentials(&$credentials,$defaults,&$interactions)
-
 
704
    {
-
 
705
        Reset($credentials);
-
 
706
        $end=(GetType($key=Key($credentials))!="string");
-
 
707
        for(;!$end;)
-
 
708
        {
-
 
709
            if(!IsSet($this->credentials[$key]))
-
 
710
            {
-
 
711
                if(IsSet($defaults[$key]))
-
 
712
                    $credentials[$key]=$defaults[$key];
-
 
713
                    else
-
 
714
                    {
-
 
715
                        $this->error="the requested credential ".$key." is not defined";
-
 
716
                        return(SASL_NOMECH);
-
 
717
                    }
-
 
718
            }
-
 
719
            else
-
 
720
                $credentials[$key]=$this->credentials[$key];
-
 
721
                Next($credentials);
-
 
722
                $end=(GetType($key=Key($credentials))!="string");
-
 
723
        }
-
 
724
        return(SASL_CONTINUE);
-
 
725
    }
-
 
726
 
-
 
727
    Function Start($mechanisms, &$message, &$interactions)
-
 
728
    {
-
 
729
        if(strlen($this->error))
-
 
730
            return(SASL_FAIL);
-
 
731
        if(IsSet($this->driver))
-
 
732
            return($this->driver->Start($this,$message,$interactions));
-
 
733
        $no_mechanism_error="";
-
 
734
        for($m=0;$m<count($mechanisms);$m++)
-
 
735
        {
-
 
736
            $mechanism=$mechanisms[$m];
-
 
737
            if(IsSet($this->drivers[$mechanism]))
-
 
738
            {
-
 
739
                /*
-
 
740
                 * if(!class_exists($this->drivers[$mechanism][0]))
-
 
741
                 *      require(dirname(__FILE__)."/".$this->drivers[$mechanism][1]);
-
 
742
                 */
-
 
743
                $this->driver=new $this->drivers[$mechanism][0];
-
 
744
                if($this->driver->Initialize($this))
-
 
745
                {
-
 
746
                    $this->encode_response=1;
-
 
747
                    $status=$this->driver->Start($this,$message,$interactions);
-
 
748
                    switch($status)
-
 
749
                    {
-
 
750
                        case SASL_NOMECH:
-
 
751
                            Unset($this->driver);
-
 
752
                            if(strlen($no_mechanism_error)==0)
-
 
753
                                $no_mechanism_error=$this->error;
-
 
754
                                $this->error="";
-
 
755
                                break;
-
 
756
                        case SASL_CONTINUE:
-
 
757
                            $this->mechanism=$mechanism;
-
 
758
                            return($status);
-
 
759
                        default:
-
 
760
                            Unset($this->driver);
-
 
761
                            $this->error="";
-
 
762
                            return($status);
-
 
763
                    }
-
 
764
                }
-
 
765
                else
-
 
766
                {
-
 
767
                    Unset($this->driver);
-
 
768
                    if(strlen($no_mechanism_error)==0)
-
 
769
                        $no_mechanism_error=$this->error;
-
 
770
                        $this->error="";
-
 
771
                }
-
 
772
            }
-
 
773
        }
-
 
774
        $this->error=(strlen($no_mechanism_error) ? $no_mechanism_error : "it was not requested any of the authentication mechanisms that are supported");
-
 
775
        return(SASL_NOMECH);
-
 
776
    }
-
 
777
 
-
 
778
    Function Step($response, &$message, &$interactions)
-
 
779
    {
-
 
780
        if(strlen($this->error))
-
 
781
            return(SASL_FAIL);
-
 
782
            return($this->driver->Step($this,$response,$message,$interactions));
-
 
783
    }
-
 
784
 
-
 
785
};
-
 
786
 
-
 
787
// =============================================================================
-
 
788
 
-
 
789
 
-
 
790
/*
-
 
791
 * http.php
-
 
792
 *
9
 * @(#) $Header: /opt2/ena/metal/http/http.php,v 1.94 2016/05/03 02:07:04 mlemos Exp $
793
 * @(#) $Header: /opt2/ena/metal/http/http.php,v 1.94 2016/05/03 02:07:04 mlemos Exp $
10
 *
794
 *
11
 */
795
 */
12
 
796
 
13
class http_class {
797
class http_class {
Line 122... Line 906...
122
                        $separator=$string;
906
                        $separator=$string;
123
                        $string=$this->next_token;
907
                        $string=$this->next_token;
124
                }
908
                }
125
                for($character=0;$character<strlen($separator);$character++)
909
                for($character=0;$character<strlen($separator);$character++)
126
                {
910
                {
-
 
911
                        $found = null;
127
                        if(GetType($position=strpos($string,$separator[$character]))=="integer")
912
                        if(GetType($position=strpos($string,$separator[$character]))=="integer")
128
                                $found=(IsSet($found) ? min($found,$position) : $position);
913
                                $found=(!is_null($found) ? min($found,$position) : $position);
129
                }
914
                }
130
                if(IsSet($found))
915
                if(IsSet($found))
131
                {
916
                {
132
                        $this->next_token=substr($string,$found+1);
917
                        $this->next_token=substr($string,$found+1);
133
                        return(substr($string,0,$found));
918
                        return(substr($string,0,$found));
Line 396... Line 1181...
396
 
1181
 
397
        Function Connect($host_name, $host_port, $ssl, $server_type = 'HTTP')
1182
        Function Connect($host_name, $host_port, $ssl, $server_type = 'HTTP')
398
        {
1183
        {
399
                $domain=$host_name;
1184
                $domain=$host_name;
400
                $port = $host_port;
1185
                $port = $host_port;
-
 
1186
                $ip = '';
401
                if(strlen($error = $this->Resolve($domain, $ip, $server_type)))
1187
                if(strlen($error = $this->Resolve($domain, $ip, $server_type)))
402
                        return($error);
1188
                        return($error);
403
                if(strlen($this->socks_host_name))
1189
                if(strlen($this->socks_host_name))
404
                {
1190
                {
405
                        switch($this->socks_version)
1191
                        switch($this->socks_version)
Line 423... Line 1209...
423
                }
1209
                }
424
                if($this->debug)
1210
                if($this->debug)
425
                        $this->OutputDebug('Connecting to '.$server_type.' server IP '.$ip.' port '.$port.'...');
1211
                        $this->OutputDebug('Connecting to '.$server_type.' server IP '.$ip.' port '.$port.'...');
426
                if($ssl)
1212
                if($ssl)
427
                        $ip="ssl://".$host_name;
1213
                        $ip="ssl://".$host_name;
-
 
1214
                $errno = -1;
428
                if(($this->connection=($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno)))==0)
1215
                if(($this->connection=($this->timeout ? @fsockopen($ip, $port, $errno, $error, $this->timeout) : @fsockopen($ip, $port, $errno)))==0)
429
                {
1216
                {
430
                        $error_code = self::HTTP_CLIENT_ERROR_CANNOT_CONNECT;
1217
                        $error_code = self::HTTP_CLIENT_ERROR_CANNOT_CONNECT;
431
                        switch($errno)
1218
                        switch($errno)
432
                        {
1219
                        {
Line 439... Line 1226...
439
                                case -6:
1226
                                case -6:
440
                                        return($this->SetError("fdopen() call failed", $error_code));
1227
                                        return($this->SetError("fdopen() call failed", $error_code));
441
                                case -7:
1228
                                case -7:
442
                                        return($this->SetError("setvbuf() call failed", $error_code));
1229
                                        return($this->SetError("setvbuf() call failed", $error_code));
443
                                default:
1230
                                default:
-
 
1231
                                        $php_errormsg = '';
444
                                        return($this->SetPHPError($errno." could not connect to the host \"".$host_name."\"",$php_errormsg, $error_code));
1232
                                        return($this->SetPHPError($errno." could not connect to the host \"".$host_name."\"",$php_errormsg, $error_code));
445
                        }
1233
                        }
446
                }
1234
                }
447
                else
1235
                else
448
                {
1236
                {
Line 999... Line 1787...
999
                if(IsSet($file["FileName"]))
1787
                if(IsSet($file["FileName"]))
1000
                {
1788
                {
1001
                        if(GetType($length=@filesize($file["FileName"]))!="integer")
1789
                        if(GetType($length=@filesize($file["FileName"]))!="integer")
1002
                        {
1790
                        {
1003
                                $error="it was not possible to determine the length of the file ".$file["FileName"];
1791
                                $error="it was not possible to determine the length of the file ".$file["FileName"];
-
 
1792
                                /*
1004
                                if(IsSet($php_errormsg)
1793
                                if(IsSet($php_errormsg)
1005
                                && strlen($php_errormsg))
1794
                                && strlen($php_errormsg))
1006
                                        $error.=": ".$php_errormsg;
1795
                                        $error.=": ".$php_errormsg;
-
 
1796
                                */
1007
                                if(!file_exists($file["FileName"]))
1797
                                if(!file_exists($file["FileName"]))
1008
                                        $error="it was not possible to access the file ".$file["FileName"];
1798
                                        $error="it was not possible to access the file ".$file["FileName"];
1009
                                return($error);
1799
                                return($error);
1010
                        }
1800
                        }
1011
                        $definition["FILENAME"]=$file["FileName"];
1801
                        $definition["FILENAME"]=$file["FileName"];
Line 1049... Line 1839...
1049
                        case "200":
1839
                        case "200":
1050
                                $this->OutputDebug('Establishing the cryptography layer with host '.$host);
1840
                                $this->OutputDebug('Establishing the cryptography layer with host '.$host);
1051
                                if(!stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT))
1841
                                if(!stream_socket_enable_crypto($this->connection, 1, STREAM_CRYPTO_METHOD_SSLv23_CLIENT))
1052
                                {
1842
                                {
1053
                                        $this->OutputDebug('Failed establishing the cryptography layer with host '.$host);
1843
                                        $this->OutputDebug('Failed establishing the cryptography layer with host '.$host);
-
 
1844
                                        $php_errormsg = '';
1054
                                        $this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg, self::HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE);
1845
                                        $this->SetPHPError('it was not possible to start a SSL encrypted connection via this proxy', $php_errormsg, self::HTTP_CLIENT_ERROR_COMMUNICATION_FAILURE);
1055
                                        $this->Disconnect();
1846
                                        $this->Disconnect();
1056
                                        return($this->error);
1847
                                        return($this->error);
1057
                                }
1848
                                }
1058
                                $this->OutputDebug('Succeeded establishing the cryptography layer with host '.$host);
1849
                                $this->OutputDebug('Succeeded establishing the cryptography layer with host '.$host);
Line 1094... Line 1885...
1094
                                return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1885
                                return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1095
                        case "Connected":
1886
                        case "Connected":
1096
                                $connect = 0;
1887
                                $connect = 0;
1097
                                break;
1888
                                break;
1098
                        case "ConnectedToProxy":
1889
                        case "ConnectedToProxy":
-
 
1890
                                $headers = array();
1099
                                if(strlen($error = $this->ConnectFromProxy($arguments, $headers)))
1891
                                if(strlen($error = $this->ConnectFromProxy($arguments, $headers)))
1100
                                        return($error);
1892
                                        return($error);
1101
                                $connect = 1;
1893
                                $connect = 1;
1102
                                break;
1894
                                break;
1103
                        default:
1895
                        default:
Line 1165... Line 1957...
1165
                                $files=(IsSet($arguments["PostFiles"]) ? $arguments["PostFiles"] : array());
1957
                                $files=(IsSet($arguments["PostFiles"]) ? $arguments["PostFiles"] : array());
1166
                                Reset($files);
1958
                                Reset($files);
1167
                                $end=(GetType($input=Key($files))!="string");
1959
                                $end=(GetType($input=Key($files))!="string");
1168
                                for(;!$end;)
1960
                                for(;!$end;)
1169
                                {
1961
                                {
-
 
1962
                                        $definition = array();
1170
                                        if(strlen($error=$this->GetFileDefinition($files[$input],$definition)))
1963
                                        if(strlen($error=$this->GetFileDefinition($files[$input],$definition)))
1171
                                                return("3 ".$error);
1964
                                                return("3 ".$error);
1172
                                        $headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"; filename=\"".$definition["NAME"]."\"\r\nContent-Type: ".$definition["Content-Type"]."\r\n\r\n";
1965
                                        $headers="--".$boundary."\r\nContent-Disposition: form-data; name=\"".$input."\"; filename=\"".$definition["NAME"]."\"\r\nContent-Type: ".$definition["Content-Type"]."\r\n\r\n";
1173
                                        $part=count($post_parts);
1966
                                        $part=count($post_parts);
1174
                                        $post_parts[$part]=array("HEADERS"=>$headers);
1967
                                        $post_parts[$part]=array("HEADERS"=>$headers);
Line 1228... Line 2021...
1228
                                {
2021
                                {
1229
                                        if(IsSet($stream[$part]["Data"]))
2022
                                        if(IsSet($stream[$part]["Data"]))
1230
                                                $this->request_body.=$stream[$part]["Data"];
2023
                                                $this->request_body.=$stream[$part]["Data"];
1231
                                        elseif(IsSet($stream[$part]["File"]))
2024
                                        elseif(IsSet($stream[$part]["File"]))
1232
                                        {
2025
                                        {
1233
                                                if(!($file=@fopen($stream[$part]["File"],"rb")))
2026
                                                if(!($file=@fopen($stream[$part]["File"],"rb"))) {
-
 
2027
                                                        $php_errormsg = '';
1234
                                                        return($this->SetPHPError("could not open upload file ".$stream[$part]["File"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE));
2028
                                                        return($this->SetPHPError("could not open upload file ".$stream[$part]["File"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE));
-
 
2029
                                                }
1235
                                                while(!feof($file))
2030
                                                while(!feof($file))
1236
                                                {
2031
                                                {
1237
                                                        if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
2032
                                                        if(GetType($block=@fread($file,$this->file_buffer_length))!="string")
1238
                                                        {
2033
                                                        {
1239
                                                                $error=$this->SetPHPError("could not read body stream file ".$stream[$part]["File"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
2034
                                                                $error=$this->SetPHPError("could not read body stream file ".$stream[$part]["File"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
Line 1283... Line 2078...
1283
                        }
2078
                        }
1284
                        $request_uri=strtolower($this->protocol)."://".$this->host_name.(($this->host_port==0 || $this->host_port==$default_port) ? "" : ":".$this->host_port).$this->request_uri;
2079
                        $request_uri=strtolower($this->protocol)."://".$this->host_name.(($this->host_port==0 || $this->host_port==$default_port) ? "" : ":".$this->host_port).$this->request_uri;
1285
                }
2080
                }
1286
                if($this->use_curl)
2081
                if($this->use_curl)
1287
                {
2082
                {
-
 
2083
                        $m = array();
1288
                        $version=(GetType($v=curl_version())=="array" ? (IsSet($v["version"]) ? $v["version"] : "0.0.0") : (preg_match("/^libcurl\\/([0-9]+\\.[0-9]+\\.[0-9]+)/",$v,$m) ? $m[1] : "0.0.0"));
2084
                        $version=(GetType($v=curl_version())=="array" ? (IsSet($v["version"]) ? $v["version"] : "0.0.0") : (preg_match("/^libcurl\\/([0-9]+\\.[0-9]+\\.[0-9]+)/",$v,$m) ? $m[1] : "0.0.0"));
1289
                        $curl_version=100000*intval($this->Tokenize($version,"."))+1000*intval($this->Tokenize("."))+intval($this->Tokenize(""));
2085
                        $curl_version=100000*intval($this->Tokenize($version,"."))+1000*intval($this->Tokenize("."))+intval($this->Tokenize(""));
1290
                        $protocol_version=($curl_version<713002 ? "1.0" : $this->protocol_version);
2086
                        $protocol_version=($curl_version<713002 ? "1.0" : $this->protocol_version);
1291
                }
2087
                }
1292
                else
2088
                else
Line 1348... Line 2144...
1348
                                        $request_body.=$post_parts[$part]["HEADERS"].$post_parts[$part]["DATA"];
2144
                                        $request_body.=$post_parts[$part]["HEADERS"].$post_parts[$part]["DATA"];
1349
                                        if(IsSet($post_parts[$part]["FILENAME"]))
2145
                                        if(IsSet($post_parts[$part]["FILENAME"]))
1350
                                        {
2146
                                        {
1351
                                                if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
2147
                                                if(!($file=@fopen($post_parts[$part]["FILENAME"],"rb")))
1352
                                                {
2148
                                                {
-
 
2149
                                                        $php_errormsg = '';
1353
                                                        $this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
2150
                                                        $this->SetPHPError("could not open upload file ".$post_parts[$part]["FILENAME"], $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
1354
                                                        $success=0;
2151
                                                        $success=0;
1355
                                                        break;
2152
                                                        break;
1356
                                                }
2153
                                                }
1357
                                                while(!feof($file))
2154
                                                while(!feof($file))
Line 1556... Line 2353...
1556
                        $line=$this->GetLine();
2353
                        $line=$this->GetLine();
1557
                        if(GetType($line)!="string")
2354
                        if(GetType($line)!="string")
1558
                                return($this->SetError("could not read request reply: ".$this->error, $this->error_code));
2355
                                return($this->SetError("could not read request reply: ".$this->error, $this->error_code));
1559
                        if(strlen($this->response_status)==0)
2356
                        if(strlen($this->response_status)==0)
1560
                        {
2357
                        {
-
 
2358
                                $matches = array();
1561
                                if(!preg_match($match="/^http\\/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$/i",$line,$matches))
2359
                                if(!preg_match($match="/^http\\/[0-9]+\\.[0-9]+[ \t]+([0-9]+)[ \t]*(.*)\$/i",$line,$matches))
1562
                                        return($this->SetError("it was received an unexpected HTTP response status", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
2360
                                        return($this->SetError("it was received an unexpected HTTP response status", self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1563
                                $this->response_status=$matches[1];
2361
                                $this->response_status=$matches[1];
1564
                                $this->response_message=$matches[2];
2362
                                $this->response_message=$matches[2];
1565
                                if($this->response_status == 204)
2363
                                if($this->response_status == 204)
Line 1673... Line 2471...
1673
                                if(!IsSet($location_arguments["scheme"]))
2471
                                if(!IsSet($location_arguments["scheme"]))
1674
                                        $location=((GetType($end=strrpos($this->request_uri,"/"))=="integer" && $end>1) ? substr($this->request_uri,0,$end) : "")."/".$location;
2472
                                        $location=((GetType($end=strrpos($this->request_uri,"/"))=="integer" && $end>1) ? substr($this->request_uri,0,$end) : "")."/".$location;
1675
                        }
2473
                        }
1676
                        if(!strcmp($location[0],"/"))
2474
                        if(!strcmp($location[0],"/"))
1677
                                $location=$this->protocol."://".$this->host_name.($this->host_port ? ":".$this->host_port : "").$location;
2475
                                $location=$this->protocol."://".$this->host_name.($this->host_port ? ":".$this->host_port : "").$location;
-
 
2476
                        $arguments = array();
1678
                        $error=$this->GetRequestArguments($location,$arguments);
2477
                        $error=$this->GetRequestArguments($location,$arguments);
1679
                        if(strlen($error))
2478
                        if(strlen($error))
1680
                                return($this->SetError("could not process redirect url: ".$error, self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
2479
                                return($this->SetError("could not process redirect url: ".$error, self::HTTP_CLIENT_ERROR_PROTOCOL_FAILURE));
1681
                        $arguments["RequestMethod"]="GET";
2480
                        $arguments["RequestMethod"]="GET";
1682
                        if(strlen($error=$this->Close())==0
2481
                        if(strlen($error=$this->Close())==0
Line 1752... Line 2551...
1752
                        $sasl->SetCredential("uri",$this->request_uri);
2551
                        $sasl->SetCredential("uri",$this->request_uri);
1753
                        $sasl->SetCredential("method",$this->request_method);
2552
                        $sasl->SetCredential("method",$this->request_method);
1754
                        $sasl->SetCredential("session",$this->session);
2553
                        $sasl->SetCredential("session",$this->session);
1755
                        do
2554
                        do
1756
                        {
2555
                        {
-
 
2556
                                $message = null;
-
 
2557
                                $interactions = null;
1757
                                $status=$sasl->Start($mechanisms,$message,$interactions);
2558
                                $status=$sasl->Start($mechanisms,$message,$interactions);
1758
                        }
2559
                        }
1759
                        while($status==SASL_INTERACT);
2560
                        while($status==SASL_INTERACT);
1760
                        switch($status)
2561
                        switch($status)
1761
                        {
2562
                        {
Line 1768... Line 2569...
1768
                        }
2569
                        }
1769
                        if($proxy >= 0)
2570
                        if($proxy >= 0)
1770
                        {
2571
                        {
1771
                                for(;;)
2572
                                for(;;)
1772
                                {
2573
                                {
-
 
2574
                                        $body = '';
1773
                                        if(strlen($error=$this->ReadReplyBody($body,$this->file_buffer_length)))
2575
                                        if(strlen($error=$this->ReadReplyBody($body,$this->file_buffer_length)))
1774
                                                return($error);
2576
                                                return($error);
1775
                                        if(strlen($body)==0)
2577
                                        if(strlen($body)==0)
1776
                                                break;
2578
                                                break;
1777
                                }
2579
                                }
Line 1970... Line 2772...
1970
                                return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
2772
                                return($this->SetError("connection was not yet established", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1971
                        case "Connected":
2773
                        case "Connected":
1972
                        case "ConnectedToProxy":
2774
                        case "ConnectedToProxy":
1973
                                return($this->SetError("request was not sent", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
2775
                                return($this->SetError("request was not sent", self::HTTP_CLIENT_ERROR_INVALID_PARAMETERS));
1974
                        case "RequestSent":
2776
                        case "RequestSent":
-
 
2777
                                $headers = array();
1975
                                if(($error=$this->ReadReplyHeaders($headers))!="")
2778
                                if(($error=$this->ReadReplyHeaders($headers))!="")
1976
                                        return($error);
2779
                                        return($error);
1977
                                break;
2780
                                break;
1978
                        case "GotReplyHeaders":
2781
                        case "GotReplyHeaders":
1979
                                break;
2782
                                break;
Line 2004... Line 2807...
2004
        Function ReadWholeReplyBody(&$body)
2807
        Function ReadWholeReplyBody(&$body)
2005
        {
2808
        {
2006
                $body = '';
2809
                $body = '';
2007
                for(;;)
2810
                for(;;)
2008
                {
2811
                {
-
 
2812
                        $body = '';
-
 
2813
                        $block = '';
2009
                        if(strlen($error = $this->ReadReplyBody($block, $this->file_buffer_length)))
2814
                        if(strlen($error = $this->ReadReplyBody($block, $this->file_buffer_length)))
2010
                                return($error);
2815
                                return($error);
2011
                        if(strlen($block) == 0)
2816
                        if(strlen($block) == 0)
2012
                                return('');
2817
                                return('');
2013
                        $body .= $block;
2818
                        $body .= $block;
2014
                }
2819
                }
2015
        }
2820
        }
2016
 
2821
 
2017
        Function ReadWholeReplyIntoTemporaryFile(&$file)
2822
        Function ReadWholeReplyIntoTemporaryFile(&$file)
2018
        {
2823
        {
2019
                if(!($file = tmpfile()))
2824
                if(!($file = tmpfile())) {
-
 
2825
                        $php_errormsg = '';
2020
                        return $this->SetPHPError('could not create the temporary file to save the response', $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
2826
                        return $this->SetPHPError('could not create the temporary file to save the response', $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
-
 
2827
                }
2021
                for(;;)
2828
                for(;;)
2022
                {
2829
                {
-
 
2830
                        $block = '';
2023
                        if(strlen($error = $this->ReadReplyBody($block, $this->file_buffer_length)))
2831
                        if(strlen($error = $this->ReadReplyBody($block, $this->file_buffer_length)))
2024
                        {
2832
                        {
2025
                                fclose($file);
2833
                                fclose($file);
2026
                                return($error);
2834
                                return($error);
2027
                        }
2835
                        }
Line 2035... Line 2843...
2035
                                }
2843
                                }
2036
                                return('');
2844
                                return('');
2037
                        }
2845
                        }
2038
                        if(!@fwrite($file, $block))
2846
                        if(!@fwrite($file, $block))
2039
                        {
2847
                        {
-
 
2848
                                $php_errormsg = '';
2040
                                $error = $this->SetPHPError('could not write to the temporary file to save the response', $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
2849
                                $error = $this->SetPHPError('could not write to the temporary file to save the response', $php_errormsg, self::HTTP_CLIENT_ERROR_CANNOT_ACCESS_LOCAL_FILE);
2041
                                fclose($file);
2850
                                fclose($file);
2042
                                return $error;
2851
                                return $error;
2043
                        }
2852
                        }
2044
                }
2853
                }