Sat, 09 Aug 2014 11:29:02 +0200
Code cleanup
100 | 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 | ||
25 | function open_socket() | |
26 | { | |
27 | $sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); | |
28 | ||
29 | if (!($sock === false)) { | |
30 | if (socket_connect($sock, "localhost", 6554)) { | |
31 | socket_set_option($sock, SOL_SOCKET, SO_RCVTIMEO, array('sec' => 15, 'usec' => 0)); | |
32 | } else { | |
33 | socket_close($sock); | |
34 | } | |
35 | } | |
36 | return $sock; | |
37 | } | |
38 | ||
39 | ||
40 | ||
196 | 41 | /* |
42 | * @param string $command to send to the server. | |
43 | * Return: string with the complete reply from the | |
44 | * server. This can be a multiline reply. | |
45 | */ | |
46 | function send_cmd($command) | |
47 | { | |
48 | $sock = open_socket(); | |
49 | if ($sock == false) { | |
50 | return ""; | |
51 | } | |
52 | socket_write($sock, $command, 4096); | |
53 | ||
54 | $answer = ""; | |
55 | while (1) { | |
56 | $line = socket_read($sock, 4096); | |
57 | if ($line === '') | |
58 | break; | |
59 | $answer .= $line; | |
60 | } | |
61 | socket_close($sock); | |
62 | ||
63 | return $answer; | |
64 | } | |
65 | ||
66 | ||
67 | ||
68 | /* | |
69 | * @param string $command to send to the server. | |
70 | * Return: 0 = Ok. | |
71 | * 1 = Server responden with an error. | |
72 | */ | |
73 | function send_cmd_check($command) | |
74 | { | |
75 | $answer = send_cmd($command); | |
76 | ||
77 | if (strlen($answer) && (($answer[0] == '1') || ($answer[0] == '2'))) | |
78 | return 0; | |
79 | ||
80 | return 1; | |
81 | } | |
82 | ||
83 | ||
84 | ||
100 | 85 | function startsWith($haystack, $needle) |
86 | { | |
87 | return !strncmp($haystack, $needle, strlen($needle)); | |
88 | } | |
89 | ||
90 | ||
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
91 | |
137
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
92 | function build_header($heading) |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
93 | { |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
94 | $outstr = '<!DOCTYPE html>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
95 | $outstr .= '<html>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
96 | $outstr .= ' <head>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
97 | $outstr .= ' <meta http-equiv="content-type" content="text/html; charset=utf-8" />'.PHP_EOL; |
137
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
98 | $outstr .= ' <title>'.$heading.'</title>'.PHP_EOL; |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
99 | $outstr .= ' <link type="text/css" href="css/style.css" rel="stylesheet" media="all" />'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
100 | $outstr .= ' </head>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
101 | $outstr .= ' <body class="default">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
102 | $outstr .= ' <div id="jqxWidget">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
103 | $outstr .= ' <div id="header">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
104 | $outstr .= ' <form action="maintenance.php" style="margin:30px; float:right">'.PHP_EOL; |
173 | 105 | $outstr .= ' <input type="submit" style="width: 150px; height: 25px;" value="Maintenance Panel" />'.PHP_EOL; |
134
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
106 | $outstr .= ' </form>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
107 | $outstr .= ' </div> <!-- header -->'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
108 | $outstr .= ' <div id="content">'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
109 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
110 | return $outstr; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
111 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
112 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
113 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
114 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
115 | function build_footer() |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
116 | { |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
117 | $outstr = ' </div> <!-- content -->'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
118 | $outstr .= ' </div> <!-- jqxWidget -->'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
119 | $outstr .= ' </body>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
120 | $outstr .= '</html>'.PHP_EOL; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
121 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
122 | return $outstr; |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
123 | } |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
124 | |
f05601490415
Redesigned the web interface, one single app is too slow. The main dashboard will be a shiny ajax driven page, the setup pages will be simple and php only. Keep It Simple, Stupid.
Michiel Broek <mbroek@mbse.eu>
parents:
127
diff
changeset
|
125 | |
137
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
126 | |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
127 | /* |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
128 | * Goto URL. Works also after headers have been sent. |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
129 | */ |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
130 | function load($url) { |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
131 | echo' |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
132 | <script> |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
133 | if (top.location != self.location) { |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
134 | top.location = "'.$url.'" |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
135 | } |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
136 | {location.href="'.$url.'";} |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
137 | </script>'; |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
138 | } |
e4518fd9b626
Profiles can be managed via the web interface
Michiel Broek <mbroek@mbse.eu>
parents:
134
diff
changeset
|
139 | |
155
0d86f3c0a07b
Unit mode can switch between OFF and NONE.
Michiel Broek <mbroek@mbse.eu>
parents:
137
diff
changeset
|
140 |