forked from LightsOnHudson/FPP-Plugin-Weather
-
Notifications
You must be signed in to change notification settings - Fork 4
/
plugin_setup.php
executable file
·317 lines (221 loc) · 9.99 KB
/
plugin_setup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
<?php
//$DEBUG=true;
include_once "/opt/fpp/www/common.php";
include_once 'functions.inc.php';
include_once 'commonFunctions.inc.php';
//$pluginName = "Weather";
$pluginName = basename(dirname(__FILE__)); //pjd 7-14-2019 added per dkulp
$gitURL = "https://github.com/FalconChristmas/FPP-Plugin-Weather.git";
$pluginUpdateFile = $settings['pluginDirectory']."/".$pluginName."/"."pluginUpdate.inc";
$ScriptPath= "/home/fpp/media/scripts/";
$PluginPath= $settings['pluginDirectory']."/".$pluginName."/";
$logFile = $settings['logDirectory']."/".$pluginName.".log";
logEntry("$pluginUpdateFile = ".$pluginUpdateFile);
clearstatcache();
if (!(file_exists($ScriptPath."getLocalWeather.sh"))){
logEntry("GetLocalWeather.sh does not exist, copying scripts");
copy ($PluginPath."getLocalWeather.sh", "/home/fpp/media/scripts/getLocalWeather.sh");
}
if (!(file_exists($ScriptPath."RUN-MATRIX.sh"))){
logEntry("RUN-MATRIX.sh does not exist, copying scripts");
copy ($PluginPath."RUN-MATRIX.sh", "/home/fpp/media/scripts/RUN-MATRIX.sh");
}
if(isset($_POST['updatePlugin']))
{
$updateResult = updatePluginFromGitHub($gitURL, $branch="master", $pluginName);
echo $updateResult."<br/> \n";
}
if(isset($_POST['submit']))
{
// "Writing config file
WriteSettingToFile("SEPARATOR",urlencode($_POST["SEPARATOR"]),$pluginName);
WriteSettingToFile("CITY",trim(urlencode($_POST["CITY"])),$pluginName);
WriteSettingToFile("STATE",trim(urlencode($_POST["STATE"])),$pluginName);
WriteSettingToFile("LAST_READ",urlencode($_POST["LAST_READ"]),$pluginName);
WriteSettingToFile("API_KEY",urlencode($_POST["API_KEY"]),$pluginName);
WriteSettingToFile("PRE_TEXT",urlencode($_POST["PRE_TEXT"]),$pluginName);
WriteSettingToFile("POST_TEXT",urlencode($_POST["POST_TEXT"]),$pluginName);
WriteSettingToFile("TEMP_TYPE",urlencode($_POST["TEMP_TYPE"]),$pluginName);
WriteSettingToFile("COUNTRY",urlencode($_POST["country"]),$pluginName);
$pluginConfigFile = $settings['configDirectory'] . "/plugin." . $pluginName;
if (file_exists($pluginConfigFile)) {
$pluginSettings = parse_ini_file($pluginConfigFile);
}
}
$ENABLED = urldecode($pluginSettings['ENABLED']);
$SEPARATOR = urldecode($pluginSettings['SEPARATOR']);
$CITY= trim(urldecode($pluginSettings['CITY']));
$STATE= trim(urldecode($pluginSettings['STATE']));
$API_KEY = urldecode($pluginSettings['API_KEY']);
$INCLUDE_WIND = urldecode($pluginSettings['INCLUDE_WIND']);
$INCLUDE_TEMP = urldecode($pluginSettings['INCLUDE_TEMP']);
$INCLUDE_HUMIDITY = urldecode($pluginSettings['INCLUDE_HUMIDITY']);
$INCLUDE_LOCALE = urldecode($pluginSettings['INCLUDE_LOCALE']);
$PRE_TEXT = urldecode($pluginSettings['PRE_TEXT']);
$POST_TEXT = urldecode($pluginSettings['POST_TEXT']);
$TEMP_TYPE = urldecode($pluginSettings['TEMP_TYPE']);
$INCLUDE_DEGREE_SYMBOL = urldecode($pluginSettings['INCLUDE_DEGREE_SYMBOL']);
$COUNTRY= urldecode($pluginSettings['COUNTRY']);
if (strlen($COUNTRY)<1){ //empty setting, setting default
$COUNTRY="US";
}
$IMMEDIATE_OUTPUT= urldecode($pluginSettings['IMMEDIATE_OUTPUT']);//this doesn't work..for another day
if (strlen($IMMEDIATE_OUTPUT)<1){ //empty setting, setting default
$IMMEDIATE_OUTPUT="ON";
}
$LATITUDE= GetSettingValue("Latitude");
$LONGITUDE= GetSettingValue("Longitude");
$LAST_READ = urldecode($pluginSettings['LAST_READ']);//("LAST_READ",$pluginName));
//set hide/unhide value for country <div>
if ($COUNTRY == "US") {
$USDIV = "display:block";
$OTHDIV = "display:none";
} else {
$USDIV = "display:none";
$OTHDIV = "display:block";
}
if(strlen($SEPARATOR)>1) { //change to allow for no separator
$SEPARATOR="|";
}
if((int)$LAST_READ == 0 || $LAST_READ == "") {
$LAST_READ=0;
}
?>
<!DOCTYPE html>
<head>
</head>
<body>
<div id="<?echo $pluginName;?>" class="settings">
<fieldset>
<legend><?php echo $pluginName;?> Support Instructions</legend>
<p>Known Issues:
<ul>
<li>None</li>
</ul>
<p>Configuration:
<ul>
<li>Configure your City & 2 Character State & Separator Character to display</li>
<li>Not all City and State combinations are supported. If not, you can select the Other Country option</br>
and use your Latitude and Longitude settings to get your local weather.<p>
<p>Link to settings: <a href=settings.php?tab=10> System tab</a></p>
<li>Visit <a href="http://home.openweathermap.org/" target="_blank">http://home.openweathermap.org/</a> to sign up for an API KEY</li>
</ul>
<ul>
</ul>
<form method="post" action="http://<? echo $_SERVER['SERVER_ADDR']?>/plugin.php?plugin=<?echo $pluginName;?>&page=plugin_setup.php">
<?
echo "<input type=\"hidden\" name=\"LAST_READ\" value=\"".$LAST_READ."\"> \n";
echo "<p/>\n";
$restart=0;
$reboot=0;
echo "ENABLE PLUGIN: ";
//if($ENABLED== 1 || $ENABLED == "on") {
// echo "<input type=\"checkbox\" checked name=\"ENABLED\"> \n";
//just use the name of the plugin. Because it will pop up with 'enabled / disabled ' suffix
PrintSettingCheckbox($pluginName." Plugin", "ENABLED", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName = $pluginName, $callbackName = "");
//} else {
//echo "<input type=\"checkbox\" name=\"ENABLED\"> \n";
//}
echo "<p/> \n";
if($DEBUG) {
echo "RESET LAST READ INDEX: ";
echo "<br/> \n";
echo "Last read: ".$LAST_READ. ": ";
echo "<input type=\"checkbox\" name=\"RESET_LAST_READ\"> \n";
//PrintSettingCheckbox("Radio Station", "ENABLED", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
}
echo "<p/> \n";
echo "Pre Text (Text to display ahead of Weather data): \n";
?>
<input type="text" name="PRE_TEXT" size="16" value="<? echo $PRE_TEXT; ?>"> <p>
Post Text (Text to display after weather data):
<input type="text" name="POST_TEXT" size="16" value="<? echo $POST_TEXT; ?>"> <p>
Select your country
<input type="radio" id="us" name="country" value="US" onclick="setRadioUS()" <? if ($COUNTRY=="US") echo "checked"; ?>>
<label for="us">US</label>
<input type="radio" id="other" name="country" value="Other" onclick="setRadioOther()"<? if ($COUNTRY=="Other") echo "checked"; ?>>
<label for="other">Other</label><p/>
<div id="ifUS" style="<? echo "$USDIV"; ?>">
City: <input type="text" name="CITY" size="16" value="<? echo $CITY; ?>"> <p>
State: <input type="text" name="STATE" size="2" value="<? echo $STATE; ?>"> <p>
</div>
<div id="ifOther" style="<? echo "$OTHDIV"; ?>">
<h4>Make sure your Latitude and Longitude settings are correct. To change them, go to the FPP Settings page on the <a href=settings.php?tab=9> System tab</a></h4> <p>
Latitude: <input type="text" name="LATITUDE" size="16" value="<? echo $LATITUDE; ?>" disabled> <p>
Longitude: <input type="text" name="LONGITUDE" size="16" value="<? echo $LONGITUDE; ?>" disabled> <p>
</div>
<?
echo "Temperature type: \n";
echo "<select name=\"TEMP_TYPE\"> \n";
switch ($TEMP_TYPE)
{
case "F":
echo "<option selected value=\"".$TEMP_TYPE."\">Fahrenheit</option> \n";
echo "<option value=\"C\">Celcius</option> \n";
break;
case "C":
echo "<option selected value=\"".$TEMP_TYPE."\">Celcius</option> \n";
echo "<option value=\"F\">Fahrenheit</option> \n";
break;
default:
echo "<option value=\"C\">Celcius</option> \n";
echo "<option value=\"F\">Fahrenheit</option> \n";
break;
}
echo "</select> \n";
echo "<p/> \n";
echo "Include Locale in output: \n";
PrintSettingCheckbox("Include Locale", "INCLUDE_LOCALE", $restart = 0, $reboot = 0, "1", "0", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
echo "Separator: \n";
echo "<input type=\"text\" name=\"SEPARATOR\" size=\"2\" value=\"".$SEPARATOR."\"> \n";
echo "<p/> \n";
echo "Include Temp: ";
PrintSettingCheckbox("Include Temp", "INCLUDE_TEMP", $restart = 0, $reboot = 0, "1", "0", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
echo "Include Wind: ";
PrintSettingCheckbox("Include Wind", "INCLUDE_WIND", $restart = 0, $reboot = 0, "1", "0", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
echo "Include Humidity: ";
PrintSettingCheckbox("Include Humidity", "INCLUDE_HUMIDITY", $restart = 0, $reboot = 0, "1", "0", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
echo "Include Degree Symbol (°): ";
PrintSettingCheckbox("Include Degree Symbol", "INCLUDE_DEGREE_SYMBOL", $restart = 0, $reboot = 0, "1", "0", $pluginName = $pluginName, $callbackName = "");
echo "<p/> \n";
echo "API KEY: \n";
echo "<input type=\"text\" name=\"API_KEY\" size=\"64\" value=\"".$API_KEY."\"> \n";
echo "<p/> \n";
echo "Immediately output to Matrix (Run MATRIX plugin): ";
PrintSettingCheckbox("Immediate output to Matrix", "IMMEDIATE_OUTPUT", $restart = 0, $reboot = 0, "ON", "OFF", $pluginName = $pluginName, $callbackName = "");
echo "<p><h3>If you want your message to display immediately when the command to run the Weather </br>
is activated then enable the Immediate Output. Otherwise the message will be stored in the </br>
Matrix Message Queue until you give the Matrix Message Queue the command to run and your data won't be current</h3></p>";
echo "<p/> \n";
?>
<p/>
<input id="submit_button" name="submit" type="submit" class="buttons" value="Save Config">
<?
if(file_exists($pluginUpdateFile))
{
//echo "updating plugin included";
include $pluginUpdateFile;
}
?>
</form>
<p>To report a bug, please file it against the project on Git: https://github.com/FalconChristmas/FPP-Plugin-Weather
</fieldset>
</div>
<br />
<script>
function setRadioUS() {
document.getElementById('ifUS').style.display = "block";
document.getElementById('ifOther').style.display = "none";
}
function setRadioOther() {
document.getElementById('ifUS').style.display = "none";
document.getElementById('ifOther').style.display = "block";
}
</script>
</body>
</html>