-
Notifications
You must be signed in to change notification settings - Fork 61
/
dev.php
495 lines (459 loc) · 16.6 KB
/
dev.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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
<?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: dev.php
* version: 1.0
*
*/
// 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 'phprestart':
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_queue'] = "phprestart";
$_SESSION['w_active'] = 1;
// unlock session file
playerSession('unlock');
} else {
echo "background worker busy";
}
// set UI notify
$_SESSION['notify']['title'] = 'PHP RESTART';
$_SESSION['notify']['msg'] = 'restarting php backend...';
// unlock session file
playerSession('unlock');
break;
case 'syschmod':
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_queue'] = "syschmod";
$_SESSION['w_active'] = 1;
$_SESSION['notify']['title'] = 'Setup filesystem';
$_SESSION['notify']['msg'] = 'Permission reconstruced.';
// unlock session file
playerSession('unlock');
} else {
$_SESSION['notify']['msg'] = 'Background worker busy....';
}
// unlock session file
playerSession('unlock');
break;
case 'blankplayerid':
session_start();
playerSession('write',$db,'playerid','');
playerSession('write',$db,'hwplatform','');
playerSession('write',$db,'hwplatformid','');
playerSession('unlock');
break;
case 'phpclearcache':
sleep(2);
apc_clear_cache();
apc_clear_cache('opcode');
session_start();
$_SESSION['notify']['title'] = '';
$_SESSION['notify']['msg'] = 'PHP APC Cache cleared';
playerSession('unlock');
break;
case 'workerrestart':
// reset worker status
session_start();
$_SESSION['w_queue'] = '';
$_SESSION['w_queueargs'] = '';
$_SESSION['w_active'] = 0;
$_SESSION['w_lock'] = 0;
$_SESSION['w_jobID'] = '';
// queue worker job
$_SESSION['w_queue'] = "workerrestart";
$_SESSION['w_active'] = 1;
$_SESSION['notify']['title'] = 'Worker reset';
$_SESSION['notify']['msg'] = 'player_wrk.php restarted...';
// unlock session file
playerSession('unlock');
break;
case 'workersessionreset':
session_start();
$_SESSION['w_queue'] = '';
$_SESSION['w_queueargs'] = '';
$_SESSION['w_lock'] = '';
$_SESSION['w_active'] = '';
$_SESSION['w_jobID'] = '';
$_SESSION['notify']['title'] = '';
$_SESSION['notify']['msg'] = 'PHP worker Session DATA cleared';
playerSession('unlock');
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 'totalbackup':
break;
case 'restore':
break;
}
}
if (isset($_POST['save'])){
session_start();
// commit debug levels and settings
if ($_POST['dev'] != $_SESSION['dev']) {
playerSession('write',$db,'dev',$_POST['dev']);
}
if ($_POST['debug'] != $_SESSION['debug']) {
playerSession('write',$db,'debug',$_POST['debug']);
}
if ($_POST['hiddendebug'] != $_SESSION['hiddendebug']) {
playerSession('write',$db,'hiddendebug',$_POST['hiddendebug']);
}
// set UI notify
$_SESSION['notify']['title'] = 'Debug settings changed';
$_SESSION['notify']['msg'] = '';
// unlock session file
playerSession('unlock');
}
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');
}
if (isset($_POST['enableapc']) && $_POST['enableapc'] != $_SESSION['enableapc']) {
if ($_SESSION['w_lock'] != 1 && $_SESSION['w_queue'] == '') {
// start / respawn session
session_start();
$_SESSION['w_queue'] = "enableapc";
$_SESSION['w_queueargs'] = $_POST['enableapc'];
$_SESSION['w_active'] = 1;
// unlock session file
playerSession('unlock');
$_SESSION['notify']['msg'] = 'persistent cache enabled.';
} else {
$_SESSION['notify']['msg'] = 'background worker busy...retry later...';
}
// set UI notify
$_SESSION['notify']['title'] = 'PHP APC';
// unlock session file
playerSession('unlock');
}
// wait for worker output if $_SESSION['w_active'] = 1
waitWorker(1);
?>
<?php
$sezione = basename(__FILE__, '.php');
include('_header.php');
?>
<div class="container">
<h1>Development settings</h1>
<form class="form-horizontal" method="post">
<fieldset>
<legend>Debug level</legend>
<p>
We provide different debug levels:<br><br>
<span class="help-block">defcon[0]: no debug output (default) </span>
<span class="help-block">defcon[1]: output system stats and some informations about Audio backend</span>
<span class="help-block">defcon[2]: output same as defcon[1] and UI PHP SESSION status</span>
<span class="help-block">defcon[3]: output ALL debug info (add SQLite datastore content)</span>
</p>
<div class="control-group">
<label class="control-label">Debug level</label>
<div class="controls">
<select class="input-large" name="debug">
<option value="0" <?php if ($_SESSION['debug'] == '0') echo "selected"; ?>>defcon [0] (default)</option>
<option value="1" <?php if ($_SESSION['debug'] == '1') echo "selected"; ?>>defcon [1] (sys+MPD)</option>
<option value="2" <?php if ($_SESSION['debug'] == '2') echo "selected"; ?>>defcon [2] (sys+MPD+PHP)</option>
<option value="3" <?php if ($_SESSION['debug'] == '3') echo "selected"; ?>>defcon [3] (sys+MPD+PHP+SQL)</option>
</select>
</div>
</div>
<div class="control-group">
<label class="control-label">Hide debug informations</label>
<div class="controls">
<div class="toggle">
<label class="toggle-radio" for="toggleOption4" >ON</label>
<input type="radio" name="hiddendebug" id="toggleOption3" value="1" <?php if ($_SESSION['hiddendebug'] == 1) echo "checked=\"checked\""; ?>>
<label class="toggle-radio" for="toggleOption3">OFF</label>
<input type="radio" name="hiddendebug" id="toggleOption4" value="0" <?php if ($_SESSION['hiddendebug'] == 0) echo "checked=\"checked\""; ?>>
</div>
<span class="help-block">Enable this setting if you want hide debug information (use "show page source" Browser function to view debug data)</span>
</div>
</div>
<div class="form-actions">
<button class="btn btn-primary btn-large" value="save" name="save" type="submit">Save settings</button>
</div>
</fieldset>
</form>
<form class="form-horizontal" method="post">
<fieldset>
<legend>System commands</legend>
<p>Just some handy system commands, without the hassle of logging into SSH.</p>
<div class="control-group">
<label class="control-label">System reboot</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="reboot" id="syscmd-reboot">
</div>
</div>
<div class="control-group">
<label class="control-label">System poweroff</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="poweroff" id="syscmd-poweroff">
</div>
</div>
<div class="control-group">
<label class="control-label">Setup FS permissions</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="syschmod" id="syscmd-syschmod">
</div>
</div>
<div class="control-group">
<label class="control-label">Restart MPD service</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="mpdrestart" id="syscmd-mpdrestart">
</div>
</div>
<div class="control-group">
<label class="control-label">reset NET config</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="netconfreset" id="syscmd-netconfreset">
</div>
</div>
<div class="control-group">
<label class="control-label">reset MPD config</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="mpdconfreset" id="syscmd-mpdconfreset">
</div>
</div>
<div class="control-group">
<label class="control-label">blank playerID</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="blankplayerid" id="syscmd-blankplayerid">
<span class="help-block">actual playerID: <?php echo $_SESSION['playerid'];?></span>
<span class="help-block">REMEMBER to use this function prior to public a Player IMG.</span>
</div>
</div>
</fieldset>
</form>
<form class="form-horizontal" method="post">
<fieldset>
<legend>PHP backend control</legend>
<p>Just some handy "tools" for PHP backend management.</p>
<div class="control-group">
<label class="control-label">Restart PHP service</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="phprestart" id="syscmd-phprestart">
</div>
</div>
<div class="control-group">
<label class="control-label">Clear PHP APC cache</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="phpclearcache" id="syscmd-phpclearcache">
</div>
</div>
<div class="control-group">
<label class="control-label">View PHP APC status</label>
<div class="controls">
<a class="btn" type="submit" href="command/apc.php" name="syscmd" id="syscmd-viewphpcache" target="_blank">php cache status</a>
</div>
</div>
<div class="control-group">
<label class="control-label">PHP APC persistent cache</label>
<div class="controls">
<div class="toggle">
<label class="toggle-radio" for="toggleOption5" >ON</label>
<input type="radio" name="enableapc" id="toggleOption6" value="0" <?php if ($_SESSION['enableapc'] == 0) echo "checked=\"checked\""; ?>>
<label class="toggle-radio" for="toggleOption6">OFF</label>
<input type="radio" name="enableapc" id="toggleOption5" value="1" <?php if ($_SESSION['enableapc'] == 1) echo "checked=\"checked\""; ?>>
</div>
<span class="help-block">Enable PHP APC persistence (apc.stat = 0). This drastically speed-up page render, but you must manually clear cache (use above button) at any source code change. This is enabled by default in production environment.</span>
</div>
</div>
<div class="form-actions">
<button class="btn btn-primary btn-large" value="apply" name="apply" type="submit">Save settings</button>
</div>
</fieldset>
</form>
<form class="form-horizontal" method="post">
<fieldset>
<legend>Background WORKER control</legend>
<p>Just some handy "tools" for Background WORKER management.</p>
<div class="control-group">
<label class="control-label">restart WORKER</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="workerrestart" id="syscmd-workerrestart">
</div>
</div>
<div class="control-group">
<label class="control-label">reset WORKER session</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="workersessionreset" id="syscmd-workersessionreset">
</div>
</div>
</fieldset>
</form>
<form class="form-horizontal" method="post">
<fieldset>
<legend>Compatibility fixes</legend>
<p>For people suffering problems with some receivers and DACs.</p>
<div class="control-group">
<label class="control-label">CMedia fix</label>
<div class="controls">
<div class="toggle">
<label class="toggle-radio" for="toggleOption7" >ON</label>
<input type="radio" name="cmediafix" id="toggleOption8" value="1" <?php if ($_SESSION['cmediafix'] == 1) echo "checked=\"checked\""; ?>>
<label class="toggle-radio" for="toggleOption8">OFF</label>
<input type="radio" name="cmediafix" id="toggleOption7" value="0" <?php if ($_SESSION['cmediafix'] == 0) echo "checked=\"checked\""; ?>>
</div>
<span class="help-block">For those who have a CM6631 receiver and experiment issues (noise, crackling) between tracks with different sample rates and/or bit depth.<br>
A "dirty" fix that should avoid the problem, do NOT use if everything works normally.</span>
</div>
</div>
<div class="form-actions">
<button class="btn btn-primary btn-large" value="apply" name="apply" type="submit">Apply fixes</button>
</div>
</fieldset>
</form>
<form class="form-horizontal" method="post">
<fieldset>
<legend>Backup / Restore configuration</legend>
<p> </p>
<div class="control-group">
<label class="control-label">Backup player config</label>
<div class="controls">
<input class="btn" type="submit" name="syscmd" value="backup" id="syscmd-backup">
</div>
</div>
</fieldset>
</form>
<form class="form-horizontal" method="post">
<fieldset>
<div class="control-group" >
<label class="control-label" for="port">Configuration file</label>
<div class="controls">
<!-- per ACX da fixare -->
<div class="fileupload fileupload-new" data-provides="fileupload">
<span class="btn btn-file"><span class="fileupload-new">restore</span><span class="fileupload-exists">Change</span><input type="file" /></span>
<span class="fileupload-preview"></span>
<a href="#" class="close fileupload-exists" data-dismiss="fileupload" style="float: none">×</a>
</div>
<!-- per ACX da fixare -->
</div>
</div>
<div class="form-actions">
<button class="btn btn-primary btn-large" value="restore" name="syscmd" type="submit">Restore config</button>
</div>
</fieldset>
</form>
</div>
<?php include('_footer.php'); ?>