Subversion Repositories HomeAutomation

Rev

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

Rev 1162 Rev 1163
1
<?php
1
<?php
2
 
2
 
3
require(dirname(__FILE__)."/config.php");
3
require(dirname(__FILE__)."/config.php");
4
 
4
 
5
if (isset($_GET["function"]))
5
if (isset($_GET["function"]))
6
{
6
{
7
    switch ($_GET["function"])
7
    switch ($_GET["function"])
8
    {
8
    {
9
        case "getMeetingsRestOfDay":
9
        case "getMeetingsRestOfDay":
10
        if (isset($_GET["shortname"]))
10
        if (isset($_GET["shortname"]))
11
        {
11
        {
12
            echo getMeetingsRestOfDay($_GET["shortname"]);
12
            echo getMeetingsRestOfDay($_GET["shortname"]);
13
        }
13
        }
14
        break;
14
        break;
15
       
15
       
16
        case "bookMeeting":
16
        case "bookMeeting":
17
        if (isset($_GET["from"]) && isset($_GET["to"]))
17
        if (isset($_GET["from"]) && isset($_GET["to"]))
18
        {
18
        {
19
           
19
           
20
        }
20
        }
21
        break;
21
        break;
22
       
22
       
23
        //case "":
23
        //case "":
24
        //
24
        //
25
        //break;
25
        //break;
26
    }
26
    }
27
}
27
}
28
 
28
 
29
function getMeetingsRestOfDay($shortname)
29
function getMeetingsRestOfDay($shortname)
30
{
30
{
31
    global $Calender;
31
    global $Calender;
32
    global $wsdl;
32
    global $wsdl;
33
    $founditem = false;
33
    $founditem = false;
34
   
34
   
35
    foreach($Calender as $item)
35
    foreach($Calender as $item)
36
    {
36
    {
37
        if ($item->Shortname == $shortname)
37
        if ($item->Shortname == $shortname)
38
        {
38
        {
39
            $founditem = $item;
39
            $founditem = $item;
40
            break;
40
            break;
41
        }
41
        }
42
    }
42
    }
43
   
43
   
44
    if ($founditem !== false)
44
    if ($founditem !== false)
45
    {
45
    {
46
        $FindItem->Traversal = "Shallow";
46
        $FindItem->Traversal = "Shallow";
47
        $FindItem->ItemShape->BaseShape = "AllProperties";
47
        $FindItem->ItemShape->BaseShape = "AllProperties";
48
        $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar";
48
        $FindItem->ParentFolderIds->DistinguishedFolderId->Id = "calendar";
49
        /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */
49
        /* Dont forget to use the proper timezone and setting for daylight saving time (php handles this fine) */
50
        $FindItem->CalendarView->StartDate = date("c");     //"2009-04-07T08:00:00Z";
50
        $FindItem->CalendarView->StartDate = date("c");     //"2009-04-07T08:00:00Z";
51
        $FindItem->CalendarView->EndDate = date("c", strtotime("+9 hour")); //"2009-04-08T00:00:00Z";
51
        $FindItem->CalendarView->EndDate = date("c", strtotime("+9 hour")); //"2009-04-08T00:00:00Z";
52
        //echo date("c")." ".date("c", strtotime("+8 hour"))." ".date("c", strtotime("18:00"))."\n";
52
        //echo date("c")." ".date("c", strtotime("+8 hour"))." ".date("c", strtotime("18:00"))."\n";
53
 
53
 
54
        stream_wrapper_unregister('https');
54
        stream_wrapper_unregister('https');
55
        stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol");
55
        stream_wrapper_register('https', 'NTLMStream') or die("Failed to register protocol");
56
         
56
         
57
        $returndata = "";
57
        $returndata = "";
58
        try
58
        try
59
        {
59
        {
60
            $client = new ExchangeNTLMSoapClient($wsdl);
60
            $client = new ExchangeNTLMSoapClient($wsdl);
61
            $client->user = $founditem->UserName;
61
            $client->user = $founditem->UserName;
62
            $client->pass = $founditem->Password;
62
            $client->pass = $founditem->Password;
63
            $result = $client->FindItem($FindItem);
63
            $result = $client->FindItem($FindItem);
64
            if ($result)
64
            if ($result)
65
            {
65
            {
66
              //print_array($result);
66
                //print_array($result);
67
              $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
67
                $calendaritems = $result->ResponseMessages->FindItemResponseMessage->RootFolder->Items->CalendarItem;
68
              //print_array($calendaritems);
68
                //print_array($calendaritems);
69
              $returndata = "";
69
                $returndata = "";
70
              for ($i = 0; $i < count($calendaritems); $i++)
70
                for ($i = 0; $i < count($calendaritems); $i++)
71
              {
71
                {
72
                if (count($calendaritems) > 1)
72
                if (count($calendaritems) > 1)
73
                {
73
                {
74
                    $item = $calendaritems[$i];
74
                    $item = $calendaritems[$i];
75
                }
75
                }
76
                else
76
                else
77
                {
77
                {
78
                    $item = $calendaritems;
78
                    $item = $calendaritems;
79
                }
79
                }
80
                $returndata .= "<meeting>\n";
80
                    $returndata .= "<meeting>\n";
81
                $returndata .= "\t<organizer>".$item->Organizer->Mailbox->Name."</organizer>\n";
81
                    $returndata .= "\t<organizer>".$item->Organizer->Mailbox->Name."</organizer>\n";
82
                $returndata .= "\t<start>".date("G:i", strtotime($item->Start))."</start>\n";
82
                    $returndata .= "\t<start>".date("G:i", strtotime($item->Start))."</start>\n";
83
                $returndata .= "\t<end>".date("G:i", strtotime($item->End))."</end>\n";
83
                    $returndata .= "\t<end>".date("G:i", strtotime($item->End))."</end>\n";
84
                $returndata .= "</meeting>\n";
84
                    $returndata .= "</meeting>\n";
85
              }
85
                }
86
            }
86
            }
87
           
87
           
88
        }
88
        }
89
        catch (SoapFault $exception)
89
        catch (SoapFault $exception)
90
        {
90
        {
91
            return "<error>".$exception."</error>";
91
            return "<error>".$exception."</error>";
92
        }
92
        }
93
 
93
 
94
        stream_wrapper_restore('https');
94
        stream_wrapper_restore('https');
95
          return $returndata;
95
            return $returndata;
96
    }
96
    }
97
    else
97
    else
98
    {
98
    {
99
        return "<error>Unknown shortname</error>";
99
        return "<error>Unknown shortname</error>";
100
    }
100
    }
101
}
101
}
102
 
102
 
103
 
103
 
104
function print_array($var)
104
function print_array($var)
105
{
105
{
106
    echo "<pre>\n";
106
    echo "<pre>\n";
107
    print_r($var);
107
    print_r($var);
108
    echo "</pre>\n";
108
    echo "</pre>\n";
109
}
109
}
110
 
110
 
111
class NTLMSoapClient extends SoapClient {
111
class NTLMSoapClient extends SoapClient {
112
  function __doRequest($request, $location, $action, $version)
112
    function __doRequest($request, $location, $action, $version)
113
  {
113
    {
114
    global $exchangeurl;
114
        global $exchangeurl;
115
    $location=$exchangeurl; //override url to exchange server
115
        $location=$exchangeurl; //override url to exchange server
116
 
116
 
117
    $headers = array( 'Method: POST',
117
        $headers = array( 'Method: POST',
118
            'Connection: Keep-Alive',
118
            'Connection: Keep-Alive',
119
            'User-Agent: PHP-SOAP-CURL',
119
            'User-Agent: PHP-SOAP-CURL',
120
            'Content-Type: text/xml; charset=utf-8',
120
            'Content-Type: text/xml; charset=utf-8',
121
            'SOAPAction: "'.$action.'"',
121
            'SOAPAction: "'.$action.'"',
122
            );
122
            );
123
    $this->__last_request_headers = $headers;
123
        $this->__last_request_headers = $headers;
124
    $ch = curl_init($location);
124
        $ch = curl_init($location);
125
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
125
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
126
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
126
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
127
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
127
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
128
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
128
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
129
    curl_setopt($ch, CURLOPT_POST, true );
129
        curl_setopt($ch, CURLOPT_POST, true );
130
    curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
130
        curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
131
    curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
131
        curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
132
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
132
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
133
    curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass);
133
        curl_setopt($ch, CURLOPT_USERPWD, $this->user.':'.$this->pass);
134
    $response = curl_exec($ch);
134
        $response = curl_exec($ch);
135
 
135
 
136
/*$myfile = "/tmp/debugex.txt";
136
/*$myfile = "/tmp/debugex.txt";
137
$fh = fopen($myfile, 'w+') or die("can't open file");
137
$fh = fopen($myfile, 'w+') or die("can't open file");
138
fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n");
138
fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n");
139
fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n");
139
fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n");
140
fwrite($fh, "reponse: ". $response."\n\n");
140
fwrite($fh, "reponse: ". $response."\n\n");
141
fclose($fh);
141
fclose($fh);
142
*/
142
*/
143
   
143
       
144
    return $response;
144
        return $response;
145
  }
145
    }
146
 
146
   
147
  function __getLastRequestHeaders()
147
    function __getLastRequestHeaders()
148
  {
148
    {
149
    return implode("\n", $this->__last_request_headers)."\n";
149
        return implode("\n", $this->__last_request_headers)."\n";
150
  }
150
    }
151
}
151
}
152
 
152
 
153
class ExchangeNTLMSoapClient extends NTLMSoapClient
153
class ExchangeNTLMSoapClient extends NTLMSoapClient
154
{
154
{
155
    public $user = '';
155
    public $user = '';
156
    public $password = '';
156
    public $password = '';
157
}
157
}
158
 
158
 
159
class NTLMStream
159
class NTLMStream
160
{
160
{
161
  private $path;
161
    private $path;
162
  private $mode;
162
    private $mode;
163
  private $options;
163
    private $options;
164
  private $opened_path;
164
    private $opened_path;
165
  private $buffer;
165
    private $buffer;
166
  private $pos;
166
    private $pos;
167
 
167
 
168
    /**
168
    /**
169
     * Open the stream
169
     * Open the stream
170
     *
170
     *
171
     * @param unknown_type $path
171
     * @param unknown_type $path
172
     * @param unknown_type $mode
172
     * @param unknown_type $mode
173
     * @param unknown_type $options
173
     * @param unknown_type $options
174
     * @param unknown_type $opened_path
174
     * @param unknown_type $opened_path
175
     * @return unknown
175
     * @return unknown
176
     */
176
     */
177
  public function stream_open($path, $mode, $options, $opened_path)
177
    public function stream_open($path, $mode, $options, $opened_path)
178
  {
178
    {
179
    echo "[NTLMStream::stream_open] $path , mode=$mode \n";
179
        echo "[NTLMStream::stream_open] $path , mode=$mode \n";
180
    $this->path = $path;
180
        $this->path = $path;
181
    $this->mode = $mode;
181
        $this->mode = $mode;
182
    $this->options = $options;
182
        $this->options = $options;
183
    $this->opened_path = $opened_path;
183
        $this->opened_path = $opened_path;
184
    $this->createBuffer($path);
184
        $this->createBuffer($path);
185
    return true;
185
        return true;
186
  }
186
    }
187
 
187
 
188
    /**
188
    /**
189
     * Close the stream
189
     * Close the stream
190
     *
190
     *
191
     */
191
     */
192
  public function stream_close()
192
    public function stream_close()
193
  {
193
    {
194
    echo "[NTLMStream::stream_close] \n";
194
        echo "[NTLMStream::stream_close] \n";
195
    curl_close($this->ch);
195
        curl_close($this->ch);
196
  }
196
    }
197
 
197
 
198
    /**
198
    /**
199
     * Read the stream
199
     * Read the stream
200
     *
200
     *
201
     * @param int $count number of bytes to read
201
     * @param int $count number of bytes to read
202
     * @return content from pos to count
202
     * @return content from pos to count
203
     */
203
     */
204
  public function stream_read($count)
204
    public function stream_read($count)
205
  {
205
    {
206
    echo "[NTLMStream::stream_read] $count \n";
206
        echo "[NTLMStream::stream_read] $count \n";
207
    if(strlen($this->buffer) == 0)
207
        if(strlen($this->buffer) == 0)
208
    {
208
        {
209
      return false;
209
            return false;
210
    }
210
        }
211
    $read = substr($this->buffer,$this->pos, $count);
211
        $read = substr($this->buffer,$this->pos, $count);
212
    $this->pos += $count;
212
        $this->pos += $count;
213
    return $read;
213
        return $read;
214
  }
214
    }
215
 
215
 
216
    /***
216
    /***
217
     * write the stream
217
     * write the stream
218
     *
218
     *
219
     * @param $data
219
     * @param $data
220
     * @return
220
     * @return
221
     */
221
     */
222
  public function stream_write($data)
222
    public function stream_write($data)
223
  {
223
    {
224
    echo "[NTLMStream::stream_write] \n";
224
        echo "[NTLMStream::stream_write] \n";
225
    if(strlen($this->buffer) == 0)
225
        if(strlen($this->buffer) == 0)
226
    {
226
        {
227
      return false;
227
            return false;
228
    }
228
        }
229
    return true;
229
        return true;
230
  }
230
    }
231
 
231
 
232
    /**
232
    /**
233
     *
233
     *
234
     * @return true if eof else false
234
     * @return true if eof else false
235
     */
235
     */
236
  public function stream_eof()
236
    public function stream_eof()
237
  {
237
    {
238
    echo "[NTLMStream::stream_eof] ";
238
        echo "[NTLMStream::stream_eof] ";
239
    if($this->pos > strlen($this->buffer))
239
        if($this->pos > strlen($this->buffer))
240
    {
240
        {
241
      echo "true \n";
241
            echo "true \n";
242
      return true;
242
            return true;
243
    }
243
        }
244
    echo "false \n";
244
        echo "false \n";
245
    return false;
245
        return false;
246
  }
246
    }
247
 
247
 
248
    /**
248
    /**
249
     * @return int the position of the current read pointer
249
     * @return int the position of the current read pointer
250
     */
250
     */
251
  public function stream_tell()
251
    public function stream_tell()
252
  {
252
    {
253
    echo "[NTLMStream::stream_tell] \n";
253
        echo "[NTLMStream::stream_tell] \n";
254
    return $this->pos;
254
        return $this->pos;
255
  }
255
    }
256
 
256
 
257
    /**
257
    /**
258
     * Flush stream data
258
     * Flush stream data
259
     */
259
     */
260
  public function stream_flush()
260
    public function stream_flush()
261
  {
261
    {
262
    echo "[NTLMStream::stream_flush] \n";
262
        echo "[NTLMStream::stream_flush] \n";
263
    $this->buffer = null;
263
        $this->buffer = null;
264
    $this->pos = null;
264
        $this->pos = null;
265
  }
265
    }
266
 
266
 
267
    /**
267
    /**
268
     * Stat the file, return only the size of the buffer
268
     * Stat the file, return only the size of the buffer
269
     *
269
     *
270
     * @return array stat information
270
     * @return array stat information
271
     */
271
     */
272
  public function stream_stat()
272
    public function stream_stat()
273
  {
273
    {
274
    echo "[NTLMStream::stream_stat] \n";
274
        echo "[NTLMStream::stream_stat] \n";
275
    $this->createBuffer($this->path);
275
        $this->createBuffer($this->path);
276
    $stat = array( 'size' => strlen($this->buffer), );
276
        $stat = array( 'size' => strlen($this->buffer), );
277
    return $stat;
277
        return $stat;
278
  }
278
    }
279
 
279
 
280
    /**
280
    /**
281
     * Stat the url, return only the size of the buffer
281
     * Stat the url, return only the size of the buffer
282
     *
282
     *
283
     * @return array stat information
283
     * @return array stat information
284
     */
284
     */
285
  public function url_stat($path, $flags)
285
    public function url_stat($path, $flags)
286
  {
286
    {
287
    echo "[NTLMStream::url_stat] \n";
287
        echo "[NTLMStream::url_stat] \n";
288
    $this->createBuffer($path);
288
        $this->createBuffer($path);
289
    $stat = array( 'size' => strlen($this->buffer), );
289
        $stat = array( 'size' => strlen($this->buffer), );
290
    return $stat;
290
        return $stat;
291
  }
291
    }
292
 
292
 
293
  /* Create the buffer by requesting the url through cURL */
293
    /* Create the buffer by requesting the url through cURL */
294
  private function createBuffer($path)
294
    private function createBuffer($path)
295
  {
295
    {
296
    global $user;
-
 
297
    global $pass;
-
 
298
    if($this->buffer)
296
        if($this->buffer)
299
    {
297
        {
300
      return;
298
            return;
301
    }
299
        }
302
    echo "[NTLMStream::createBuffer] create buffer from : $path \n";
300
        echo "[NTLMStream::createBuffer] create buffer from : $path \n";
303
    $this->ch = curl_init($path);
301
        $this->ch = curl_init($path);
304
    curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
302
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
305
    curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
303
        curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
306
    curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
304
        curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
307
    curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
305
        curl_setopt($this->ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
308
    curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
306
        curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
309
    curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass);
307
        curl_setopt($this->ch, CURLOPT_USERPWD, $user.':'.$pass);
310
    echo $this->buffer = curl_exec($this->ch);
308
        echo $this->buffer = curl_exec($this->ch);
311
   
309
       
312
    echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n";
310
        echo "[NTLMStream::createBuffer] buffer size : ".strlen($this->buffer)."bytes \n";
313
    $this->pos = 0;
311
        $this->pos = 0;
-
 
312
/*$myfile = "/tmp/debugex.txt";
-
 
313
$fh = fopen($myfile, 'w+') or die("can't open file");
-
 
314
fwrite($fh, "user: ". $this->user. " pass: ".$this->pass."\n");
-
 
315
fwrite($fh, "req: ". $request ."loc: ". $location ." act: ". $action ." ver: ". $version."\n");
-
 
316
fwrite($fh, "reponse: ". $response."\n\n");
-
 
317
fclose($fh);
-
 
318
*/
314
  }
319
    }
315
}
320
}
316
 
321
 
317
?>
322
?>
318
 
323