示例#1
0
function fileinfo($file)
{
    require_once "knj/os.php";
    require_once "knj/strings.php";
    $res = knj_os::shellCMD("file " . knj_string_unix_safe($file));
    if (strlen($res["error"]) > 0) {
        throw new Exception(trim($res["error"]));
    }
    $res = substr($res["result"], strlen($file) + 2, -1);
    return $res;
}
 /** Sets the limit of download and upload. */
 function setLimit($mode, $limit = null)
 {
     $cmd = "transmission-remote" . $this->getLoginString();
     if ($mode == "down" || $mode == "up") {
         $cmd .= " --" . $mode . "limit " . knj_string_unix_safe($limit);
     } elseif ($mode == "nodown") {
         $cmd .= " --no-downlimit";
     } elseif ($mode == "noup") {
         $cmd .= " --no-uplimit";
     } else {
         throw new Exception("Invalid mode: \"" . $mode . "\".");
     }
     $exec = knj_os::shellCMD($cmd);
     $this->errorCmd($exec);
     return true;
 }
示例#3
0
文件: os.php 项目: kaspernj/knjphpfw
	/** Returns runnning processes. */
	static function getProcs($args = null){
		if (is_array($args) && $args["grep"]){
			$grep = $args["grep"];
			$command = "ps aux | " . $grep;
		}elseif(is_string($args) && strlen($args) > 0){
			require_once "knj/functions_knj_strings.php";
			$grep = "grep " . knj_string_unix_safe($args);
			$command = "ps aux | " . $grep;
		}else{
			$command = "ps aux";
		}
		$command .= " | grep -vir grep";
		
		$psaux = knj_os::shellCMD($command);
		$procs = explode("\n", $psaux["result"]);
		$return = array();
		
		foreach($procs AS $proc){
			$proc = trim($proc);
			
			if (strlen($proc) > 0 && substr($proc, 0, 4) != "USER"){
				if (preg_match("/^(\S+)\s+([0-9]+)\s+([0-9.]+)\s+([0-9.]+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+ ([\s\S]+)$/", $proc, $match)){
					$cmd = $match[5];
					
					if ($cmd != $command && $cmd != $grep && $cmd != "sh -c " . $command){
						$user = $match[1];
						$pid = $match[2];
						$cpu = $match[3];
						$ram = $match[4];
						
						$return[] = array(
							"user" => $user,
							"pid" => $pid,
							"cpu" => $cpu,
							"ram" => $ram,
							"cmd" => $cmd
						);
					}
				}else{
					echo "One of the processes wasnt not read: \"" . $proc . "\".\n";
				}
			}
		}
		
		return $return;
	}
示例#4
0
	/** This function handels the locales-command on Linux-systems in an easy way. */
	function knj_locate($string){
		require_once("knj/functions_knj_os.php");
		require_once("knj/functions_knj_strings.php");
		
		
		//Error handeling.
		$os = knj_os::getOS();
		if ($os["os"] != "linux"){
			throw new Exception("This function only works on Linux.");
		}
		
		
		//Make shell-command.
		$cmd = "locate";
		if (is_array($string)){
			foreach($string AS $str){
				$cmd .= " " . knj_string_unix_safe($str);
			}
		}else{
			$cmd .= " " . knj_string_unix_safe($string);
		}
		
		
		//Execute shell-command.
		$result = knj_os::shellCMD($cmd);
		if (strlen(trim($result["error"]))){
			throw new Exception($result["error"]);
		}
		
		
		//Make array of files found and unset the last one (because it will be empty).
		$files = explode("\n", $result["result"]);
		unset($files[count($files) - 1]);
		
		
		//Return the array.
		return $files;
	}
		/** Returns information about a specific file by running the Linux "file"-command on a file. */
		static function fileInfo($file){
			if (!file_exists($file)){
				throw new Exception("The file does not exist (" . $file . ").");
			}
			
			require_once("knj/os.php");
			require_once("knj/strings.php");
			
			$result = knj_os::shellCMD("file " . knj_string_unix_safe($file));
			$result = substr($result["result"], strlen($file) + 2, -1);
			
			return $result;
		}
示例#6
0
		/** Saves a file on the server. */
		function putFile($path, $content){
			require_once("knj/functions_knj_strings.php");
			
			$lines = explode("\n", $content);
			$first = true;
			foreach($lines AS $line){
				if ($first){
					$first = false;
					$this->shellCMD("echo " . knj_string_unix_safe($line) . " > " . $path) . "\n";
				}else{
					$this->shellCMD("echo " . knj_string_unix_safe($line) . " >> " . $path) . "\n";
				}
			}
		}