Subversion Repositories HomeAutomation

Rev

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

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