save($newconf); if (!$res) { $err = 'failed to save to file ' . $path; return false; } return true; } $err = 'failed to create file ' . $path; } return false; } public static function createDir($path, $mode, &$err) { if (file_exists($path)) { if (is_dir($path)) { return true; } $err = "$path is not a directory"; return false; } $parent = substr($path, 0, (strrpos($path, '/'))); if (strlen($parent) <= 1) { $err = "invalid path: $path"; return false; } if (!file_exists($parent) && !PathTool::createDir($parent, $mode, $err)) { return false; } if (mkdir($path, $mode)) { return true; } $err = "fail to create directory $path"; return false; } public static function isDenied($path) { $absname = realpath($path); if (strncmp($absname, '/etc/', 5) == 0) { return true; } return false; } }