-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsettings.php
233 lines (204 loc) · 6.72 KB
/
settings.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
<?php
/*
* PlayerUI Copyright (C) 2013 Andrea Coiutti & Simone De Gregori
* Tsunamp Team
* http://www.tsunamp.com
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RaspyFi; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*
* UI-design/JS code by: Andrea Coiutti (aka ACX)
* PHP/JS code by: Simone De Gregori (aka Orion)
*
* file: settings.php
* version: 1.1
*
*/
// common include
include('inc/connection.php');
playerSession('open',$db,'','');
playerSession('unlock',$db,'','');
?>
<?php
if (isset($_POST['syscmd'])){
switch ($_POST['syscmd']) {
case 'reboot':
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_queue'] = "reboot";
$_SESSION['w_active'] = 1;
// set UI notify
$_SESSION['notify']['title'] = 'REBOOT';
$_SESSION['notify']['msg'] = 'reboot player initiated...';
// unlock session file
playerSession('unlock');
} else {
echo "background worker busy";
}
// unlock session file
playerSession('unlock');
break;
case 'poweroff':
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_queue'] = "poweroff";
$_SESSION['w_active'] = 1;
// set UI notify
$_SESSION['notify']['title'] = 'SHUTDOWN';
$_SESSION['notify']['msg'] = 'shutdown player initiated...';
// unlock session file
playerSession('unlock');
} else {
echo "background worker busy";
}
break;
case 'mpdrestart':
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_queue'] = "mpdrestart";
$_SESSION['w_active'] = 1;
// set UI notify
$_SESSION['notify']['title'] = 'MPD RESTART';
$_SESSION['notify']['msg'] = 'restarting MPD daemon...';
// unlock session file
playerSession('unlock');
} else {
echo "background worker busy";
}
break;
case 'backup':
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_jobID'] = wrk_jobID();
$_SESSION['w_queue'] = 'backup';
$_SESSION['w_active'] = 1;
playerSession('unlock');
// wait worker response loop
while (1) {
sleep(2);
session_start();
if ( isset($_SESSION[$_SESSION['w_jobID']]) ) {
// set UI notify
$_SESSION['notify']['title'] = 'BACKUP';
$_SESSION['notify']['msg'] = 'backup complete.';
pushFile($_SESSION[$_SESSION['w_jobID']]);
unset($_SESSION[$_SESSION['w_jobID']]);
break;
}
session_write_close();
}
} else {
session_start();
$_SESSION['notify']['title'] = 'Job Failed';
$_SESSION['notify']['msg'] = 'background worker is busy.';
}
// unlock session file
playerSession('unlock');
break;
case 'updatempdDB':
if ( !$mpd) {
session_start();
$_SESSION['notify']['title'] = 'Error';
$_SESSION['notify']['msg'] = 'Cannot connect to MPD Daemon';
} else {
sendMpdCommand($mpd,'update');
session_start();
$_SESSION['notify']['title'] = 'MPD Update';
$_SESSION['notify']['msg'] = 'database update started...';
}
break;
case 'totalbackup':
break;
case 'restore':
break;
}
}
if (isset($_POST['orionprofile']) && $_POST['orionprofile'] != $_SESSION['orionprofile']){
// load worker queue
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_queue'] = 'orionprofile';
$_SESSION['w_queueargs'] = $_POST['orionprofile'];
// set UI notify
$_SESSION['notify']['title'] = 'KERNEL PROFILE';
$_SESSION['notify']['msg'] = 'orionprofile changed <br> current profile: <strong>'.$_POST['orionprofile']."</strong>";
// unlock session file
playerSession('unlock');
} else {
echo "background worker busy";
}
// activate worker job
if ($_SESSION['w_lock'] != 1) {
// start / respawn session
session_start();
$_SESSION['w_active'] = 1;
// save new value on SQLite datastore
playerSession('write',$db,'orionprofile',$_POST['orionprofile']);
// unlock session file
playerSession('unlock');
} else {
return "background worker busy";
}
}
if (isset($_POST['cmediafix']) && $_POST['cmediafix'] != $_SESSION['cmediafix']){
// load worker queue
// start / respawn session
session_start();
// save new value on SQLite datastore
if ($_POST['cmediafix'] == 1 OR $_POST['cmediafix'] == 0) {
playerSession('write',$db,'cmediafix',$_POST['cmediafix']);
}
// set UI notify
if ($_POST['cmediafix'] == 1) {
$_SESSION['notify']['title'] = '';
$_SESSION['notify']['msg'] = 'CMediaFix enabled';
} else {
$_SESSION['notify']['title'] = '';
$_SESSION['notify']['msg'] = 'CMediaFix disabled';
}
// unlock session file
playerSession('unlock');
}
// configure html select elements
$_system_select['orionprofile'] .= "<option value=\"default\" ".(($_SESSION['orionprofile'] == 'default') ? "selected" : "").">default</option>\n";
$_system_select['orionprofile'] .= "<option value=\"ACX\" ".(($_SESSION['orionprofile'] == 'ACX') ? "selected" : "").">ACX</option>\n";
$_system_select['orionprofile'] .= "<option value=\"Buscia\" ".(($_SESSION['orionprofile'] == 'Buscia') ? "selected" : "").">Buscia</option>\n";
$_system_select['orionprofile'] .= "<option value=\"Mike\" ".(($_SESSION['orionprofile'] == 'Mike') ? "selected" : "").">Mike</option>\n";
$_system_select['orionprofile'] .= "<option value=\"Orion\" ".(($_SESSION['orionprofile'] == 'Orion') ? "selected" : "").">Orion</option>\n";
$_system_select['cmediafix1'] .= "<input type=\"radio\" name=\"cmediafix\" id=\"toggleOption1\" value=\"1\" ".(($_SESSION['cmediafix'] == 1) ? "checked=\"checked\"" : "").">\n";
$_system_select['cmediafix0'] .= "<input type=\"radio\" name=\"cmediafix\" id=\"toggleOption2\" value=\"0\" ".(($_SESSION['cmediafix'] == 0) ? "checked=\"checked\"" : "").">\n";
// set template
$tpl = "settings.html";
?>
<?php
$sezione = basename(__FILE__, '.php');
include('_header.php');
?>
<!-- content --!>
<?php
// wait for worker output if $_SESSION['w_active'] = 1
waitWorker(1);
eval("echoTemplate(\"".getTemplate("templates/$tpl")."\");");
?>
<!-- content -->
<?php
debug($_POST);
?>
<?php include('_footer.php'); ?>