-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig-import.php
50 lines (38 loc) · 1.11 KB
/
config-import.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
<?php
//print_r($_FILES);
$filename = $_GET['file'];
switch ($filename) {
case 'cosmostreamer.conf':
break;
case 'config.txt':
break;
default: die('forbidden');
}
$tempFilename = '/tmp/' . $filename . '.tmp';
$fullFilename = '/boot/' . $filename;
/// Upload file into temp dir
if (move_uploaded_file($_FILES['file']['tmp_name'], $tempFilename)) {
} else {
die('Filed to save file');
}
/// Check file content
$fileContent = file_get_contents($tempFilename);
switch ($filename) {
case 'cosmostreamer.conf':
if (strpos($fileContent, 'Cosmostreamer NG config file') === false) die('Not a Cosmostreamer config file!');
break;
case 'config.txt':
if (strpos($fileContent, '# For more options and information see') === false) die('Not a Raspberry Pi config file!');
break;
}
system('mount -o rw,remount /boot');
/// Backup existing file
@copy($fullFilename, $fullFilename . '.save');
if (rename($tempFilename, $fullFilename)) {
echo 'ok';
} else {
echo 'fail';
}
system('sync');
system('mount -o ro,remount /boot > /dev/null 2>&1');
?>