", $string); $string = str_replace('"', "\\\"", trim($string)); echo ""; @flush(); } // unRAID update control readfile('update.htm'); flush(); $docroot = $_SERVER['DOCUMENT_ROOT']; if (isset($_POST['#file'])) { $file = $_POST['#file']; // prepend with boot (flash) if path is relative if ($file && $file[0]!='/') $file = "/boot/config/plugins/$file"; $section = $_POST['#section'] ?? false; $cleanup = isset($_POST['#cleanup']); $default = ($file && isset($_POST['#default'])) ? @parse_ini_file("$docroot/plugins/".basename(dirname($file))."/default.cfg", $section) : []; $keys = is_file($file) ? (parse_ini_file($file, $section) ?: []) : []; // the 'save' switch can be reset by the include file to disallow settings saving $save = true; if (isset($_POST['#include'])) { $include = realpath($docroot.'/'.$_POST['#include']); if (strpos($include, $docroot) === 0) include $include; else { syslog(LOG_INFO, "Include file not allowed: $include. Settings not saved!"); $save = false; } } if ($save) { $text = ""; if ($section) { foreach ($_POST as $key => $value) if ($key[0]!='#') $keys[$section][$key] = $default[$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 ($key[0]!='#') $keys[$key] = $default[$key] ?? $value; foreach ($keys as $key => $value) if (strlen($value) || !$cleanup) $text .= "$key=\"$value\"\n"; } @mkdir(dirname($file)); file_put_contents($file, $text); } } if (isset($_POST['#command'])) { if (isset($_POST['#env'])) { foreach ($_POST['#env'] as $env) putenv($env); } $command = $_POST['#command']; if (strpos($command, $docroot) !== 0) $command = "$docroot/$command"; $command = realpath($command); if ($command === false) syslog(LOG_INFO, "Invalid #command: {$_POST['#command']}"); else { $command = escapeshellcmd($command); if (isset($_POST['#arg'])) { $args = $_POST['#arg']; ksort($args); $command .= " ".implode(" ", array_map("escapeshellarg", $args)); } syslog(LOG_INFO, $command); $proc = popen($command, 'r'); while (!feof($proc)) { write_log(fgets($proc)); } } } ?>