This repository was archived by the owner on Aug 27, 2022. It is now read-only.
forked from andreknieriem/photobooth
-
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathadmin.php
More file actions
138 lines (119 loc) · 3.96 KB
/
admin.php
File metadata and controls
138 lines (119 loc) · 3.96 KB
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
<?php
header('Content-Type: application/json');
require_once('../lib/config.php');
require_once('../lib/db.php');
$data = $_POST;
if (!isset($data['type'])) {
echo json_encode('error');
}
if ($data['type'] == 'reset') {
if($config['reset_remove_images']) {
// empty folders
foreach ($config['foldersAbs'] as $folder) {
if (is_dir($folder)) {
$files = glob($folder.'/*.jpg');
foreach ($files as $file) { // iterate files
if (is_file($file)) {
unlink($file); // delete file
}
}
}
}
}
if($config['reset_remove_mailtxt']) {
if (is_file(MAIL_FILE)) {
unlink(MAIL_FILE); // delete file
}
}
if($config['reset_remove_config']) {
// delete personal config
if(is_file('../config/my.config.inc.php')){
unlink('../config/my.config.inc.php');
}
}
// delete db.txt
if (is_file(DB_FILE)) {
unlink(DB_FILE); // delete file
}
die(json_encode('success'));
}
if ($data['type'] == 'config') {
$newConfig = [];
foreach ($config as $k=>$conf) {
if (is_array($conf)) {
if (!empty($data[$k]) && is_array($data[$k])) {
$newConfig[$k] = $data[$k];
continue;
}
foreach ($conf as $sk => $sc) {
if (isset($data[$k][$sk]) && !empty($data[$k][$sk])) {
if ($data[$k][$sk] == 'true') {
$newConfig[$k][$sk] = true;
} else {
$newConfig[$k][$sk] = $data[$k][$sk];
}
}
}
} else {
if (isset($data[$k]) && !empty($data[$k])) {
if ($data[$k] == 'true') {
$newConfig[$k] = true;
} else {
$newConfig[$k] = $data[$k];
}
} else {
$newConfig[$k] = false;
}
}
}
if ($newConfig['login_enabled']) {
if (isset($newConfig['login_password']) && !empty($newConfig['login_password'])) {
if (!($newConfig['login_password'] === $config['login_password'])) {
$hashing = password_hash($newConfig['login_password'], PASSWORD_DEFAULT);
$newConfig['login_password'] = $hashing;
}
} else {
$newConfig['login_enabled'] = false;
}
} else {
$newConfig['login_password'] = NULL;
}
if (!$newConfig['previewFromCam']) {
$newConfig['previewCamTakesPic'] = false;
}
$content = "<?php\n\$config = ". var_export(arrayRecursiveDiff($newConfig, $defaultConfig), true) . ";";
if (file_put_contents($my_config_file, $content)) {
clearCache($my_config_file);
echo json_encode('success');
} else {
echo json_encode('error');
}
}
function arrayRecursiveDiff($aArray1, $aArray2)
{
$aReturn = array();
foreach ($aArray1 as $mKey => $mValue) {
if (array_key_exists($mKey, $aArray2)) {
if (is_array($mValue)) {
$aRecursiveDiff = arrayRecursiveDiff($mValue, $aArray2[$mKey]);
if (count($aRecursiveDiff)) {
$aReturn[$mKey] = $aRecursiveDiff;
}
} else {
if ($mValue != $aArray2[$mKey]) {
$aReturn[$mKey] = $mValue;
}
}
} else {
$aReturn[$mKey] = $mValue;
}
}
return $aReturn;
}
function clearCache($file) {
if (function_exists('opcache_invalidate') && strlen(ini_get("opcache.restrict_api")) < 1) {
opcache_invalidate($file, true);
} elseif (function_exists('apc_compile_file')) {
apc_compile_file($file);
}
}