Subversion Repositories HomeAutomation

Rev

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

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