Subversion Repositories HomeAutomation

Rev

Rev 1194 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1194 Rev 1215
1
<?php
1
<?php
2
 
2
 
3
require(dirname(__FILE__)."/config.php");
3
require(dirname(__FILE__)."/config.php");
4
 
4
 
5
/*
5
/*
6
 
6
 
7
  http://www.howtoforge.com/talking-soap-with-exchange
7
  http://www.howtoforge.com/talking-soap-with-exchange
8
 
8
 
9
*/
9
*/
10
 
10
 
11
if (isset($_GET["function"]))
11
if (isset($_GET["function"]))
12
{
12
{
13
    switch ($_GET["function"])
13
    switch ($_GET["function"])
14
    {
14
    {
15
        case "getMeetingsRestOfDay":
15
        case "getMeetingsRestOfDay":
16
        if (isset($_GET["shortname"]))
16
        if (isset($_GET["shortname"]))
17
        {
17
        {
18
            echo getMeetingsRestOfDay($_GET["shortname"]);
18
            echo getMeetingsRestOfDay($_GET["shortname"]);
19
        }
19
        }
20
        break;
20
        break;
21
       
21
       
22
        case "bookMeeting":
22
        case "bookMeeting":
23
        if (isset($_GET["from"]) && isset($_GET["to"]))
23
        if (isset($_GET["from"]) && isset($_GET["to"]) && isset($_GET["shortname"]))
24
        {
24
        {
-
 
25
            if (preg_match("/^\d\d:\d\d$/", $_GET["from"]) && preg_match("/^\d\d:\d\d$/", $_GET["to"]))
25
           
26
            {
-
 
27
                echo bookMeeting($_GET["shortname"], $_GET["from"], $_GET["to"]);
-
 
28
            }
26
        }
29
        }
27
        break;
30
        break;
28
       
31
       
29
        //case "":
32
        //case "":
30
        //
33
        //
31
        //break;
34
        //break;
32
    }
35
    }
33
}
36
}
-
 
37
 
34
 
38
 
35
/*
39
/*
-
 
40
  Book meeting
-
 
41
  Return a JSON formed string with the result
-
 
42
*/
-
 
43
function bookMeeting($shortname, $bookFrom, $bookTo)
-
 
44
{
-
 
45
    global $Calender;
-
 
46
    global $wsdl;
-
 
47
    $founditem = false;
-
 
48
   
-
 
49
    foreach($Calender as $item)
-
 
50
    {
-
 
51
        if ($item->Shortname == $shortname)
-
 
52
        {
-
 
53
            $founditem = $item;
-
 
54
            break;
-
 
55
        }
-
 
56
    }
-
 
57
   
-
 
58
    if ($founditem !== false)
-
 
59
    {
36
    $CreateItem->SendMeetingInvitations = "SendToNone";
60
        $CreateItem->SendMeetingInvitations = "SendToNone";
37
    $CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = "calendar";
61
        $CreateItem->SavedItemFolderId->DistinguishedFolderId->Id = "calendar";
38
    $CreateItem->Items->CalendarItem = array();
62
        $CreateItem->Items->CalendarItem = array();
39
    $CreateItem->Items->CalendarItem[0]->Subject = "Hello from PHP";
63
        $CreateItem->Items->CalendarItem[0]->Subject = "Booking from panel";
-
 
64
        /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */
40
    $CreateItem->Items->CalendarItem[0]->Start = "2010-01-01T16:00:00Z"; # ISO date format. Z denotes UTC time
65
        $CreateItem->Items->CalendarItem[0]->Start = date("c",strtotime($bookFrom)); // "2009-05-22T17:00:00Z" ISO date format. Z denotes UTC time
41
    $CreateItem->Items->CalendarItem[0]->End = "2010-01-01T17:00:00Z";
66
        $CreateItem->Items->CalendarItem[0]->End = date("c",strtotime($bookTo));
42
    $CreateItem->Items->CalendarItem[0]->IsAllDayEvent = false;
67
        $CreateItem->Items->CalendarItem[0]->IsAllDayEvent = false;
43
    $CreateItem->Items->CalendarItem[0]->LegacyFreeBusyStatus = "Busy";
68
        $CreateItem->Items->CalendarItem[0]->LegacyFreeBusyStatus = "Busy";
44
    $CreateItem->Items->CalendarItem[0]->Location = "Bahamas";
69
        $CreateItem->Items->CalendarItem[0]->Location = $founditem->Shortname;
45
    $CreateItem->Items->CalendarItem[0]->Categories->String = "MyCategory";
70
        $CreateItem->Items->CalendarItem[0]->Categories->String = "Meeting";
-
 
71
 
-
 
72
        stream_wrapper_unregister('https');
-
 
73
        stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol");
-
 
74
         
-
 
75
        try
-
 
76
        {
-
 
77
            $client = new ExchangeNTLMSoapClient($wsdl);
-
 
78
            $client->user = $founditem->UserName;
-
 
79
            $client->pass = $founditem->Password;
46
    $result = $client->CreateItem($CreateItem);
80
            $result = $client->CreateItem($CreateItem);
-
 
81
            if ($result)
-
 
82
            {
47
    print_array($result);
83
                //print_array($result);
-
 
84
                if ($result->ResponseMessages->CreateItemResponseMessage->ResponseClass == "Success")
-
 
85
                {
-
 
86
                    $returndata = "{ result:'success',\nshortname:'".$shortname."'}\n";
-
 
87
                }
-
 
88
                else
-
 
89
                {
-
 
90
                    $errorcode=$result->ResponseMessages->CreateItemResponseMessage->MessageText;
-
 
91
                    $returndata = "{ result:'error',\nerror:'".$errorcode."',\nshortname:'".$shortname."'}\n";
-
 
92
                }
-
 
93
            }
-
 
94
            else
-
 
95
            {
-
 
96
                $returdata = "{ error:'No result',\nshortname:'".$shortname."'}\n";
-
 
97
            }
-
 
98
           
-
 
99
        }
-
 
100
        catch (SoapFault $exception)
-
 
101
        {
-
 
102
            $returdata = "{ error:'".$exception."',\nshortname:'".$shortname."'}\n";
-
 
103
        }
-
 
104
 
-
 
105
        stream_wrapper_restore('https');
-
 
106
        return $returndata;
-
 
107
    }
-
 
108
    else
-
 
109
    {
-
 
110
        return "{ error:'Unknown shortname',\nshortname:'".$shortname."'}\n";
-
 
111
    }
-
 
112
}
-
 
113
 
-
 
114
 
-
 
115
/*
-
 
116
 
-
 
117
stdClass Object
-
 
118
(
-
 
119
    [ResponseMessages] => stdClass Object
-
 
120
        (
-
 
121
            [CreateItemResponseMessage] => stdClass Object
-
 
122
                (
-
 
123
                    [ResponseCode] => NoError
-
 
124
                    [ResponseClass] => Success
-
 
125
                    [Items] => stdClass Object
-
 
126
                        (
-
 
127
                            [CalendarItem] => stdClass Object
-
 
128
                                (
-
 
129
                                    [ItemId] => stdClass Object
-
 
130
                                        (
-
 
131
                                            [Id] =>
-
 
132
AAAcAEVudGVyLktvbmZlcmVuc3J1bUBxcnRlY2guc2UARgAAAAAAWx3xkPMlnUyMluTTqIdb4AcAdM/rfM3YaEeMsdYGn8jOeAAAAClWOAAAK68xOGjBUkCXHxa/+2eMqAAah/ErtAAA
-
 
133
                                            [ChangeKey] => DwAAABYAAAArrzE4aMFSQJcfFr/7Z4yoABqH8Tu3
-
 
134
                                        )
-
 
135
                                )
-
 
136
                        )
-
 
137
                )
-
 
138
        )
-
 
139
)
-
 
140
 
-
 
141
stdClass Object
-
 
142
(
-
 
143
    [ResponseMessages] => stdClass Object
-
 
144
        (
-
 
145
            [CreateItemResponseMessage] => stdClass Object
-
 
146
                (
-
 
147
                    [MessageText] => EndDate is earlier than StartDate
-
 
148
                    [ResponseCode] => ErrorCalendarEndDateIsEarlierThanStartDate
-
 
149
                    [DescriptiveLinkKey] => 0
-
 
150
                    [ResponseClass] => Error
-
 
151
                    [Items] => stdClass Object
-
 
152
                        (
-
 
153
                        )
-
 
154
                )
-
 
155
        )
-
 
156
)
48
*/
157
*/
-
 
158
 
-
 
159
 
49
 
160
 
50
/*
161
/*
51
  Get all meetings from now and 9 hours later
162
  Get all meetings from now and 9 hours later
52
  Return a JSON formed string
163
  Return a JSON formed string
53
*/
164
*/
54
function getMeetingsRestOfDay($shortname)
165
function getMeetingsRestOfDay($shortname)
55
{
166
{
56
    global $Calender;
167
    global $Calender;
57
    global $wsdl;
168
    global $wsdl;
58
    $founditem = false;
169
    $founditem = false;
59
   
170
   
60
    foreach($Calender as $item)
171
    foreach($Calender as $item)
61
    {
172
    {
62
        if ($item->Shortname == $shortname)
173
        if ($item->Shortname == $shortname)
63
        {
174
        {
64
            $founditem = $item;
175
            $founditem = $item;
65
            break;
176
            break;
66
        }
177
        }
67
    }
178
    }
68
   
179
   
69
    if ($founditem !== false)
180
    if ($founditem !== false)
70
    {
181
    {
71
        $FindItem->Traversal = "Shallow";
182
        $FindItem->Traversal = "Shallow";
72
        $FindItem->ItemShape->BaseShape = "AllProperties";
183
        $FindItem->ItemShape->BaseShape = "AllProperties";
73
        $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar";
184
        $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar";
74
        /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */
185
        /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */
75
        $FindItem->CalendarView->StartDate = date("c");                     //"2009-04-07T08:00:00Z";
186
        $FindItem->CalendarView->StartDate = date("c");                     //"2009-04-07T08:00:00Z";
76
        $FindItem->CalendarView->EndDate = date("c", strtotime("+9 hour")); //"2009-04-08T00:00:00Z";
187
        $FindItem->CalendarView->EndDate = date("c", strtotime("+9 hour")); //"2009-04-08T00:00:00Z";
77
        //echo date("c")." ".date("c", strtotime("+8 hour"))." ".date("c", strtotime("18:00"))."\n";
188
        //echo date("c")." ".date("c", strtotime("+8 hour"))." ".date("c", strtotime("18:00"))."\n";
78
 
189
 
79
        stream_wrapper_unregister('https');
190
        stream_wrapper_unregister('https');
80
        stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol");
191
        stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol");
81
         
192
         
82
        $returndata = "{ \n\tshortname:'".$shortname."',\n\tmeetings:[\n";
193
        $returndata = "{ \n\tshortname:'".$shortname."',\n\tmeetings:[\n";
83
        try
194
        try
84
        {
195
        {
85
            $client = new ExchangeNTLMSoapClient($wsdl);
196
            $client = new ExchangeNTLMSoapClient($wsdl);
86
            $client->user = $founditem->UserName;
197
            $client->user = $founditem->UserName;
87
            $client->pass = $founditem->Password;
198
            $client->pass = $founditem->Password;
88
            $result = $client->FindItem($FindItem);
199
            $result = $client->FindItem($FindItem);
89
            if ($result)
200
            if ($result)
90
            {
201
            {
91
                //print_array($result);
202
                //print_array($result);
92
                $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
203
                $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
93
                //print_array($calendaritems);
204
                //print_array($calendaritems);
94
                for ($i = 0; $i < count($calendaritems); $i++)
205
                for ($i = 0; $i < count($calendaritems); $i++)
95
                {
206
                {
96
                    if (count($calendaritems) > 1)
207
                    if (count($calendaritems) > 1)
97
                    {
208
                    {
98
                        $item = $calendaritems[$i];
209
                        $item = $calendaritems[$i];
99
                    }
210
                    }
100
                    else
211
                    else
101
                    {
212
                    {
102
                        $item = $calendaritems;
213
                        $item = $calendaritems;
103
                    }
214
                    }
104
                    $returndata .= "\t\t{\n";
215
                    $returndata .= "\t\t{\n";
105
                    $returndata .= "\t\torganizer:'".$item->Organizer->Mailbox->Name."',\n";
216
                    $returndata .= "\t\torganizer:'".$item->Organizer->Mailbox->Name."',\n";
-
 
217
                    $returndata .= "\t\tsubject:'".$item->Subject."',\n";
106
                    $returndata .= "\t\tstart:'".date("G:i", strtotime($item->Start))."',\n";
218
                    $returndata .= "\t\tstart:'".date("G:i", strtotime($item->Start))."',\n";
107
                    $returndata .= "\t\tend:'".date("G:i", strtotime($item->End))."'\n";
219
                    $returndata .= "\t\tend:'".date("G:i", strtotime($item->End))."'\n";
108
                    $returndata .= "\t\t}";
220
                    $returndata .= "\t\t}";
109
                    if ($i+1 < count($calendaritems))
221
                    if ($i+1 < count($calendaritems))
110
                    {
222
                    {
111
                        $returndata .= ",\n";
223
                        $returndata .= ",\n";
112
                    }
224
                    }
113
                }
225
                }
114
            }
226
            }
-
 
227
            else
115
           
228
            {
-
 
229
                return "{ error:'No result',\nshortname:'".$shortname."'}\n";
-
 
230
            }
116
        }
231
        }
117
        catch (SoapFault $exception)
232
        catch (SoapFault $exception)
118
        {
233
        {
119
            return "{ error:'".$exception."',\nshortname:'".$shortname."'}\n";
234
            return "{ error:'".$exception."',\nshortname:'".$shortname."'}\n";
120
        }
235
        }
121
 
236
 
122
        stream_wrapper_restore('https');
237
        stream_wrapper_restore('https');
123
        $returndata .= "\n\t]\n}\n";
238
        $returndata .= "\n\t]\n}\n";
124
        return $returndata;
239
        return $returndata;
125
    }
240
    }
126
    else
241
    else
127
    {
242
    {
128
        return "{ error:'Unknown shortname',\nshortname:'".$shortname."'}\n";
243
        return "{ error:'Unknown shortname',\nshortname:'".$shortname."'}\n";
129
    }
244
    }
130
}
245
}
131
 
246
 
132
 
247
 
133
function print_array($var)
248
function print_array($var)
134
{
249
{
135
    echo "<pre>\n";
250
    echo "<pre>\n";
136
    print_r($var);
251
    print_r($var);
137
    echo "</pre>\n";
252
    echo "</pre>\n";
138
}
253
}
139
 
254
 
140
class NTLMSoapClient extends SoapClient {
255
class NTLMSoapClient extends SoapClient {
141
    function __doRequest($request, $location, $action, $version)
256
    function __doRequest($request, $location, $action, $version)
142
    {
257
    {
143
        global $exchangeurl;
258
        global $exchangeurl;
144
        $location=$exchangeurl; //override url to exchange server
259
        $location=$exchangeurl; //override url to exchange server
145
 
260
 
146
        $headers = array( 'Method: POST',
261
        $headers = array( 'Method: POST',
147
            'Connection: Keep-Alive',
262
            'Connection: Keep-Alive',
148
            'User-Agent: PHP-SOAP-CURL',
263
            'User-Agent: PHP-SOAP-CURL',
149
            'Content-Type: text/xml; charset=utf-8',
264
            'Content-Type: text/xml; charset=utf-8',
150
            'SOAPAction: "'.$action.'"',
265
            'SOAPAction: "'.$action.'"',
151
            );
266
            );
152
        $this->__last_request_headers = $headers;
267
        $this->__last_request_headers = $headers;
153
        $ch = curl_init($location);
268
        $ch = curl_init($location);
154
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
269
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
155
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
270
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
156
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
271
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
157
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
272
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
158
        curl_setopt($ch, CURLOPT_POST, true );
273
        curl_setopt($ch, CURLOPT_POST, true );
159
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
274
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
160
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
275
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
161
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
276
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
162
        curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass);
277
        curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass);
163
        $response = curl_exec($ch);
278
        $response = curl_exec($ch);
164
 
279
 
165
/*$myfile = "/tmp/debugex.txt";
280
/*$myfile = "/tmp/debugex.txt";
166
$fh = fopen($myfile, 'w+') or die("can't open file");
281
$fh = fopen($myfile, 'w+') or die("can't open file");
167
fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n");
282
fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n");
168
fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n");
283
fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n");
169
fwrite($fh, "reponse: ". $response."\n\n");
284
fwrite($fh, "reponse: ". $response."\n\n");
170
fclose($fh);
285
fclose($fh);
171
*/
286
*/
172
       
287
       
173
        return $response;
288
        return $response;
174
    }
289
    }
175
   
290
   
176
    function __getLastRequestHeaders()
291
    function __getLastRequestHeaders()
177
    {
292
    {
178
        return implode("\n", $this->__last_request_headers)."\n";
293
        return implode("\n", $this->__last_request_headers)."\n";
179
    }
294
    }
180
}
295
}
181
 
296
 
182
class ExchangeNTLMSoapClient extends NTLMSoapClient
297
class ExchangeNTLMSoapClient extends NTLMSoapClient
183
{
298
{
184
    public $user = '';
299
    public $user = '';
185
    public $password = '';
300
    public $password = '';
186
}
301
}
187
 
302
 
188
class NTLMStream
303
class NTLMStream
189
{
304
{
190
    private $path;
305
    private $path;
191
    private $mode;
306
    private $mode;
192
    private $options;
307
    private $options;
193
    private $opened_path;
308
    private $opened_path;
194
    private $buffer;
309
    private $buffer;
195
    private $pos;
310
    private $pos;
196
 
311
 
197
    /**
312
    /**
198
     * Open the stream
313
     * Open the stream
199
     *
314
     *
200
     * @param unknown_type $path
315
     * @param unknown_type $path
201
     * @param unknown_type $mode
316
     * @param unknown_type $mode
202
     * @param unknown_type $options
317
     * @param unknown_type $options
203
     * @param unknown_type $opened_path
318
     * @param unknown_type $opened_path
204
     * @return unknown
319
     * @return unknown
205
     */
320
     */
206
    public function stream_open($path, $mode, $options, $opened_path)
321
    public function stream_open($path, $mode, $options, $opened_path)
207
    {
322
    {
208
        echo "[NTLMStream::stream_open] $path , mode=$mode \n";
323
        echo "[NTLMStream::stream_open] $path , mode=$mode \n";
209
        $this->path = $path;
324
        $this->path = $path;
210
        $this->mode = $mode;
325
        $this->mode = $mode;
211
        $this->options = $options;
326
        $this->options = $options;
212
        $this->opened_path = $opened_path;
327
        $this->opened_path = $opened_path;
213
        $this->createBuffer($path);
328
        $this->createBuffer($path);
214
        return true;
329
        return true;
215
    }
330
    }
216
 
331
 
217
    /**
332
    /**
218
     * Close the stream
333
     * Close the stream
219
     *
334
     *
220
     */
335
     */
221
    public function stream_close()
336
    public function stream_close()
222
    {
337
    {
223
        echo "[NTLMStream::stream_close] \n";
338
        echo "[NTLMStream::stream_close] \n";
224
        curl_close($this->ch);
339
        curl_close($this->ch);
225
    }
340
    }
226
 
341
 
227
    /**
342
    /**
228
     * Read the stream
343
     * Read the stream
229
     *
344
     *
230
     * @param int $count number of bytes to read
345
     * @param int $count number of bytes to read
231
     * @return content from pos to count
346
     * @return content from pos to count
232
     */
347
     */
233
    public function stream_read($count)
348
    public function stream_read($count)
234
    {
349
    {
235
        echo "[NTLMStream::stream_read] $count \n";
350
        echo "[NTLMStream::stream_read] $count \n";
236
        if(strlen($this->buffer) == 0)
351
        if(strlen($this->buffer) == 0)
237
        {
352
        {
238
            return false;
353
            return false;
239
        }
354
        }
240
        $read = substr($this->buffer,$this->pos, $count);
355
        $read = substr($this->buffer,$this->pos, $count);
241
        $this->pos += $count;
356
        $this->pos += $count;
242
        return $read;
357
        return $read;
243
    }
358
    }
244
 
359
 
245
    /***
360
    /***
246
     * write the stream
361
     * write the stream
247
     *
362
     *
248
     * @param $data
363
     * @param $data
249
     * @return
364
     * @return
250
     */
365
     */
251
    public function stream_write($data)
366
    public function stream_write($data)
252
    {
367
    {
253
        echo "[NTLMStream::stream_write] \n";
368
        echo "[NTLMStream::stream_write] \n";
254
        if(strlen($this->buffer) == 0)
369
        if(strlen($this->buffer) == 0)
255
        {
370
        {
256
            return false;
371
            return false;
257
        }
372
        }
258
        return true;
373
        return true;
259
    }
374
    }
260
 
375
 
261
    /**
376
    /**
262
     *
377
     *
263
     * @return true if eof else false
378
     * @return true if eof else false
264
     */
379
     */
265
    public function stream_eof()
380
    public function stream_eof()
266
    {
381
    {
267
        echo "[NTLMStream::stream_eof] ";
382
        echo "[NTLMStream::stream_eof] ";
268
        if($this->pos > strlen($this->buffer))
383
        if($this->pos > strlen($this->buffer))
269
        {
384
        {
270
            echo "true \n";
385
            echo "true \n";
271
            return true;
386
            return true;
272
        }
387
        }
273
        echo "false \n";
388
        echo "false \n";
274
        return false;
389
        return false;
275
    }
390
    }
276
 
391
 
277
    /**
392
    /**
278
     * @return int the position of the current read pointer
393
     * @return int the position of the current read pointer
279
     */
394
     */
280
    public function stream_tell()
395
    public function stream_tell()
281
    {
396
    {
282
        echo "[NTLMStream::stream_tell] \n";
397
        echo "[NTLMStream::stream_tell] \n";
283
        return $this->pos;
398
        return $this->pos;
284
    }
399
    }
285
 
400
 
286
    /**
401
    /**
287
     * Flush stream data
402
     * Flush stream data
288
     */
403
     */
289
    public function stream_flush()
404
    public function stream_flush()
290
    {
405
    {
291
        echo "[NTLMStream::stream_flush] \n";
406
        echo "[NTLMStream::stream_flush] \n";
292
        $this->buffer = null;
407
        $this->buffer = null;
293
        $this->pos = null;
408
        $this->pos = null;
294
    }
409
    }
295
 
410
 
296
    /**
411
    /**
297
     * Stat the file, return only the size of the buffer
412
     * Stat the file, return only the size of the buffer
298
     *
413
     *
299
     * @return array stat information
414
     * @return array stat information
300
     */
415
     */
301
    public function stream_stat()
416
    public function stream_stat()
302
    {
417
    {
303
        echo "[NTLMStream::stream_stat] \n";
418
        echo "[NTLMStream::stream_stat] \n";
304
        $this->createBuffer($this->path);
419
        $this->createBuffer($this->path);
305
        $stat = array( 'size' => strlen($this->buffer), );
420
        $stat = array( 'size' => strlen($this->buffer), );
306
        return $stat;
421
        return $stat;
307
    }
422
    }
308
 
423
 
309
    /**
424
    /**
310
     * Stat the url, return only the size of the buffer
425
     * Stat the url, return only the size of the buffer
311
     *
426
     *
312
     * @return array stat information
427
     * @return array stat information
313
     */
428
     */
314
    public function url_stat($path, $flags)
429
    public function url_stat($path, $flags)
315
    {
430
    {
316
        echo "[NTLMStream::url_stat] \n";
431
        echo "[NTLMStream::url_stat] \n";
317
        $this->createBuffer($path);
432
        $this->createBuffer($path);
318
        $stat = array( 'size' => strlen($this->buffer), );
433
        $stat = array( 'size' => strlen($this->buffer), );
319
        return $stat;
434
        return $stat;
320
    }
435
    }
321
 
436
 
322
    /* Create the buffer by requesting the url through cURL */
437
    /* Create the buffer by requesting the url through cURL */
323
    private function createBuffer($path)
438
    private function createBuffer($path)
324
    {
439
    {
325
        if($this->buffer)
440
        if($this->buffer)
326
        {
441
        {
327
            return;
442
            return;
328
        }
443
        }
329
        echo "[NTLMStream::createBuffer] create buffer from : $path \n";
444
        echo "[NTLMStream::createBuffer] create buffer from : $path \n";
330
        $this->ch = curl_init($path);
445
        $this->ch = curl_init($path);
331
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
446
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
332
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
447
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
333
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
448
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
334
        curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
449
        curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
335
        curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
450
        curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
336
        curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass);
451
        curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass);
337
        echo $this->buffer = curl_exec($this->ch);
452
        echo $this->buffer = curl_exec($this->ch);
338
       
453
       
339
        echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n";
454
        echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n";
340
        $this->pos = 0;
455
        $this->pos = 0;
341
/*$myfile = "/tmp/debugex.txt";
456
/*$myfile = "/tmp/debugex.txt";
342
$fh = fopen($myfile, 'w+') or die("can't open file");
457
$fh = fopen($myfile, 'w+') or die("can't open file");
343
fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n");
458
fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n");
344
fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n");
459
fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n");
345
fwrite($fh, "reponse: ". $response."\n\n");
460
fwrite($fh, "reponse: ". $response."\n\n");
346
fclose($fh);
461
fclose($fh);
347
*/
462
*/
348
    }
463
    }
349
}
464
}
350
 
465
 
351
?>
466
?>
352
 
467