21,886
社区成员
发帖
与我相关
我的任务
分享
$g = array(
"varrun_path" => "/var/run",
"varetc_path" => "/var/etc",
"vardb_path" => "/var/db",
"varlog_path" => "/var/log",
"etc_path" => "/etc",
"tmp_path" => "/tmp",
"conf_path" => "/conf",
"ftmp_path" => "/ftmp",
"conf_default_path" => "/conf.default",
"cf_path" => "/cf",
"cf_conf_path" => "/cf/conf",
"www_path" => "/usr/local/www",
"xml_rootobj" => "freenas",
"debug" => false,
"latest_config" => "5.7",
"nopccard_platforms" => array("wrap", "net48xx"),
"wireless_regex" => "/^(ndis|wi|ath|an|ral|ural|wai|iwi|awi|wlan|ipw)/",
"default_passwd" => "freenas",
"default_ip" => "192.168.1.250"
);
function mwexec($command, $logerr = false) {
global $g;
// Set PATH
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
if ($g['debug']) {
if (!$_SERVER['REMOTE_ADDR'])
echo "mwexec(): $command\n";
passthru($command, $retval);
} else {
$redirect = ">/dev/null 2>&1";
if (true === $logerr)
$redirect = "2>&1 >/dev/null";
exec("{$command} {$redirect}", $output, $retval);
if ((true === $logerr) && (is_array($output))) {
write_log(implode($output));
}
}
return $retval;
}
function mwexec2($command, &$output = NULL, &$return_var = NULL) {
// Set PATH
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
return exec($command, $output, $return_var);
}
/* wrapper for exec() in background */
function mwexec_bg($command) {
global $g;
// Set PATH
putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
if ($g['debug']) {
if (!$_SERVER['REMOTE_ADDR'])
echo "mwexec(): $command\n";
}
exec("nohup $command > /dev/null 2>&1 &");
}
/* unlink a file, if it exists */
function unlink_if_exists($fn) {
if (file_exists($fn))
unlink($fn);
}