1 <?php |
|
2 /***************************************************************************** |
|
3 * Copyright (C) 2014 |
|
4 * |
|
5 * Michiel Broek <mbroek at mbse dot eu> |
|
6 * |
|
7 * This file is part of ThermFerm |
|
8 * |
|
9 * This is free software; you can redistribute it and/or modify it |
|
10 * under the terms of the GNU General Public License as published by the |
|
11 * Free Software Foundation; either version 2, or (at your option) any |
|
12 * later version. |
|
13 * |
|
14 * ThermFerm is distributed in the hope that it will be useful, but |
|
15 * WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
17 * General Public License for more details. |
|
18 * |
|
19 * You should have received a copy of the GNU General Public License |
|
20 * along with ThermFerm; see the file COPYING. If not, write to the Free |
|
21 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
22 *****************************************************************************/ |
|
23 |
|
24 require_once('utilities.php'); |
|
25 |
|
26 |
|
27 $sock = open_socket(); |
|
28 if ($sock == false) { |
|
29 echo ""; |
|
30 return; |
|
31 } |
|
32 |
|
33 socket_write($sock, "LIST", 4096); |
|
34 $answer = ""; |
|
35 while (1) { |
|
36 $line = socket_read($sock, 4096); |
|
37 if ($line === '') |
|
38 break; |
|
39 $answer .= $line; |
|
40 } |
|
41 socket_close($sock); |
|
42 $arr = explode("\r\n", $answer); |
|
43 |
|
44 |
|
45 $row = '['; |
|
46 |
|
47 /* We don't use json_encode because it doesn't work for our purpose */ |
|
48 if (startsWith($arr[0], "212")) { |
|
49 $j = 1; |
|
50 while (1) { |
|
51 if (strcmp($arr[$j], ".") == 0) |
|
52 break; |
|
53 if ($j > 1) |
|
54 $row .= ','; |
|
55 $f = explode(",", $arr[$j]); |
|
56 $row .= '{"UUID":"'.$f[0].'","Name":"'.$f[1].'","Mode":"'.$f[2].'"}'; |
|
57 $j++; |
|
58 } |
|
59 } |
|
60 |
|
61 $row .= ']'; |
|
62 echo $row; |
|
63 |
|
64 ?> |
|