www-thermferm/getprofiles.php

changeset 134
f05601490415
parent 133
345307762220
child 135
0882292322b3
equal deleted inserted replaced
133:345307762220 134:f05601490415
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
28 if (isset($_GET['update'])) {
29 /*
30 * Build the update command
31 */
32 $update_cmd = "PROFILE ".$_GET['UUID'].",".$_GET['Name'];
33
34 $sock = open_socket();
35 if ($sock != false) {
36 /*
37 * Send command and absorb the result.
38 */
39 socket_write($sock, $update_cmd, 4096);
40 while (1) {
41 $line = socket_read($sock, 4096);
42 if ($line === '')
43 break;
44 }
45 socket_close($sock);
46 }
47 }
48
49
50
51 /*
52 * Get current profiles
53 */
54 $sock = open_socket();
55 if ($sock == false) {
56 echo "";
57 return;
58 }
59
60 socket_write($sock, "LIST PROFILES", 4096);
61 $answer = "";
62 while (1) {
63 $line = socket_read($sock, 4096);
64 if ($line === '')
65 break;
66 $answer .= $line;
67 }
68 socket_close($sock);
69 $arr = explode("\r\n", $answer);
70 $row = '[';
71
72
73 /* We don't use json_encode because it doesn't work for our purpose */
74 if (startsWith($arr[0], "212")) {
75 $j = 1;
76 while (1) {
77 if (strcmp($arr[$j], ".") == 0)
78 break;
79 if ($j > 1)
80 $row .= ',';
81 $f = explode(",", $arr[$j]);
82 $row .= '{"UUID":"'.$f[0].'","Name":"'.$f[1].'","Steps":"'.$f[2].'"}';
83 $j++;
84 }
85 }
86
87 $row .= ']';
88 echo $row;
89
90 ?>

mercurial