/** * Returns the user and group that a specified file belongs to. It also returns the mods for the file. * * @param string $file The file which should be read. */ function fs_getFileInfo($file){ if (!file_exists($file)){ throw new Exception("fs_getMods(): The file does not exist (" . $file . ")."); } require_once "knj/strings.php"; require_once "knj/os.php"; $stat = knj_os::systemCMD("ls -l " . knj_string_unix_safe($file)); $return["mods"]["user"]["mod"] = substr($stat, 1, 3); $return["mods"]["group"]["mod"] = substr($stat, 4, 3); $return["mods"]["all"]["mod"] = substr($stat, 7, 3); foreach($return["mods"] AS $key => $value){ if (substr($value["mod"], 0, 1) == "r"){ $return["mods"][$key]["read"] = true; }else{ $return["mods"][$key]["read"] = false; } if (substr($value["mod"], 1, 1) == "w"){ $return["mods"][$key]["write"] = true; }else{ $return["mods"][$key]["write"] = false; } if (substr($value["mod"], 2, 1) == "x"){ $return["mods"][$key]["exe"] = true; }else{ $return["mods"][$key]["exe"] = false; } } $groups = preg_split("/\s+/", $stat); $return["user"] = $groups[2]; $return["group"] = $groups[3]; return $return; }
/** Returns the user, which is running the script. */ static function whoAmI(){ global $knj_whoami; if ($knj_whoami){ return $knj_whoami; } $os = knj_os::getOS(); if ($os["os"] == "linux"){ $knj_whoami = trim(knj_os::systemCMD("whoami")); }else{ throw new Exception("Unsupported OS: " . $os["os"]); } return $knj_whoami; }