-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_cfg.php
More file actions
47 lines (44 loc) · 1.79 KB
/
update_cfg.php
File metadata and controls
47 lines (44 loc) · 1.79 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
<?PHP
// update_cfg() is used to update selected name=value variables in a cfg file. Note that calling
// this function will write the cfg file on the flash.
// The $_POST variable contains a list of key/value parameters to be updated in the file. There are a
// number of special parameters prefixed with a hash '#' character:
// $file - the path of the cfg file to be updated. It does not need to previously exist.
// #section - If present, then the ini file consists of a set of named sections, and all of the $cfg
// parameters apply to this one particular section. If omitted, then it's just a flat ini file without
// sections.
// #include - specifies name of an include file to read in before saving the file contents
// #cleanup - if present then parameters with empty strings are omitted from being written to the file
//
include("/usr/local/emhttp/update.php");
//
$file = $_POST['#file'];
if ($file) {
$section = isset($_POST['#section']) ? $_POST['#section'] : FALSE;
$cleanup = isset($_POST['#cleanup']);
$keys = @parse_ini_file($file, $section);
if (isset($_POST['#include'])) include "/usr/local/emhttp/{$_POST['#include']}";
$text = "# Generated settings:\n";
if ($section) {
foreach ($_POST as $key => $value) if (substr($key,0,1)!='#') $keys[$section][$key] = $value;
foreach ($keys as $section => $block) {
$text .= "[$section]\n";
foreach ($block as $key => $value) {
if (strlen($value) || !$cleanup) {
$text .= "$key=\"$value\"\n";
}
}
}
}
else {
foreach ($_POST as $key => $value) if (substr($key,0,1)!='#') $keys[$key] = $value;
foreach ($keys as $key => $value) {
if (strlen($value) || !$cleanup) {
$text .= "$key=\"$value\"\n";
}
}
}
@mkdir(dirname($file));
file_put_contents($file, $text);
}
?>