예제 #1
0
		/** Converts a Word-content (or Word-file) into plain-text. */
		static function wordtext($cont, $type = null){
			require_once "knj/functions_knj_os.php";
			$catdoc_status = knj_os::checkCMD("catdoc");
			if (!$catdoc_status){
				throw new Exception("catdoc could not be found on this system.");
			}
			
			if (!$type){
				if (file_exists($cont)){
					$type = "file";
				}elseif(strlen($cont) >= 200){
					$type = "content";
				}else{
					throw new Exception("Could not register the type.");
				}
			}
			
			if ($type == "file"){
				$filename = $cont;
			}elseif($type = "content"){
				$filename = "/tmp/knj_documents_catdoc_" . time() . ".doc";
				$status = file_put_contents($filename, $cont);
				if (!$status){
					throw new Exception("Could not write temp-document to: " . $filename);
				}
			}
			
			$doc = knj_os::shellCMD($catdoc_status[filepath] . " " . $filename);
			return $doc[result];
		}
예제 #2
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;
}
 function validate()
 {
     $data = array("_GET" => $_GET, "_POST" => $_POST, "_SERVER" => $_SERVER, "_COOKIE" => $_COOKIE, "args" => $this->args);
     $send_data = base64_encode(json_encode($data, true));
     $tmp_path = "/tmp/fckeditor_mod_ruby_validate_" . microtime(true) . ".txt";
     file_put_contents($tmp_path, $send_data);
     $cmd = "ruby \"" . dirname(__FILE__) . "/validate_login.rb\" --tmp_path=\"" . $tmp_path . "\"";
     if ($this->args["knjrbfw_path"]) {
         $cmd .= " --knjrbfw_path=\"" . $this->args["knjrbfw_path"] . "\"";
     }
     $res = knj_os::shellCMD($cmd);
     unlink($tmp_path);
     return array("json" => json_decode($res["result"], true), "res" => $res);
 }
예제 #4
0
	/** Returns information about a specific networking-device. */
	function network_ifconfig($args = null){
		//Make ifconfig-command.
		if (is_string($args)){
			$command = "ifconfig " . $device;
		}else{
			$command = "ifconfig";
		}
		
		//Run command and catch result.
		if ($args["output"]){
			$ipconfig = $args["output"];
		}else{
			$os = knj_os::getOS();
			if ($os["os"] != "linux"){
				throw new Exception("This command only works with Linux.");
			}
			
			$ipconfig = knj_os::shellCMD($command);
			$ipconfig = $ipconfig["result"];
		}
		
		//Parse result.
		if (preg_match_all("/([a-z]+[0-9]{0,2})\s+Link encap([\s\S]+)(\n\n|\r\n\r\n)/U", $ipconfig, $matches)){
			foreach($matches[0] AS $key => $device_out){
				$interface = $matches[1][$key];
				
				if (preg_match_all("/(R|T)X bytes:([0-9]+)/", $device_out, $match_bytes)){
					$return[$interface]["rx_bytes"] = $match_bytes[2][0];
					$return[$interface]["tx_bytes"] = $match_bytes[2][1];
				}
				
				if (preg_match("/inet addr:([0-9.]{7,15})/", $device_out, $match_ip)){
					$return[$interface]["ip"] = $match_ip[1];
				}
				
				if (preg_match("/Mask:([0-9.]{7,15})/", $device_out, $match_ip)){
					$return[$interface]["mask"] = $match_ip[1];
				}
				
				if (preg_match("/Bcast:([0-9.]{7,15})/", $device_out, $match_ip)){
					$return[$interface]["bast"] = $match_ip[1];
				}
			}
		}
		
		return $return;
	}
예제 #5
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;
		}
 /** Stops a torrent by its hash. */
 function torrAction($id, $action)
 {
     $cmd = "transmission-remote" . $this->getLoginString() . " --torrent " . $id;
     if ($action == "stop" || $action == "start" || $action == "remove") {
         $cmd .= " --" . $action;
     } else {
         throw new Exception("Invalid action: \"" . $action . "\".");
     }
     $exec = knj_os::shellCMD($cmd);
     $this->errorCmd($exec);
     return true;
 }
예제 #8
0
		/** Sends a SMS. */
		function sendSMS($number, $msg){
			if (!$this->opts["connected"]){
				$this->connect();
			}
			
			$number = $this->checkNumber($number);
			if ($this->opts["mode"] != "bibob" && is_array($number)){
				foreach($number AS $num){
					$this->sendSMS($num, $msg);
				}
				return true;
			}
			
			if ($this->opts["mode"] == "cbb"){
				if (!$this->http){
					$this->connect();
				}
				
				$html = $this->http->post("cbb?cmd=websmssend", array(
					"newentry" => "",
					"receivers" => $number,
					"message" => $msg,
					"smssize" => strlen($msg),
					"smsprice" => "0.19",
					"sendDate" => "",
					"sendDateHour" => "",
					"sendDateMinute" => ""
				));
				
				if (strpos($html, "<td>" . $number . "</td>") !== false){
					//do nothing.
				}else{
					throw new Exception("Could not send SMS.");
				}
			}elseif($this->opts["mode"] == "happii"){
				$html = $this->http->getAddr("login/websms/");
				
				if (!preg_match("/<form name=\"WebSMSForm\" method=\"post\" action=\"\/(\S+)\">/", $html, $match)){
					throw new Exception("Could not match PID.");
				}
				$action = $match[1];
				
				$html = $this->http->post($action, array(
					"sender" => "",
					"Recipient" => substr($number, 3),
					"sMessage" => $msg,
					"sCharsLeft" => 960 - strlen($msg),
					"sSmsCount" => strlen($msg)
				));
				if (strpos($html, "This object may be found") === false){
					throw new Exception("Could not send SMS.");
				}
			}elseif($this->opts["mode"] == "bibob"){
				if (!$this->soap_client){
					$this->connect();
				}
				
				$status_ob = $this->soap_client->__soapCall("SendMessage", array("parameters" => array(
					"cellphone" => $this->opts["mobilenumber"],
					"password" => md5($this->opts["password"]),
					"smsTo" => array("string" => $number),
					"smscontents" => $msg,
					"sendDate" => date("Y-m-d"),
					"deliveryReport" => "0",
					"fromNumber" => $this->opts["mobilenumber"]
				)));
				if ($status_ob->SendMessageResult->ErrorString != "Ingen fejl."){
					throw new Exception("Could not send SMS (" . $status_ob->SendMessageResult->ErrorString . ").");
				}
			}elseif($this->opts["mode"] == "gnokii"){
				$msg = str_replace("\"", "\\\"", $msg);
				$msg = str_replace("!", "\\!", $msg);
				
				$cmd = "echo \"" . $msg . "\" | " . $this->opts["gnokiiexe"] . " --config " . $this->opts["gnokiiconf"] . " --sendsms " . $number;
				$res = knj_os::shellCMD($cmd);
				
				if (strpos($res["error"], "Send succeeded!") !== false){
					//success!
				}else{
					throw new Exception("Could not send SMS.");
				}
			}elseif($this->opts["mode"] == "knjsmsgateway"){
				fwrite($this->fp, "sendsms;" . $number . ";" . $msg . "\n");
				$status = fread($this->fp, 4096);
				
				if ($status != "sendsms;true\n"){
					throw new Exception("Error when sending SMS: \"" . $status . "\".");
				}
			}else{
				throw new Exception("Invalid mode: \"" . $this->opts["mode"] . "\".");
			}
			
			return true;
		}
예제 #9
0
파일: os.php 프로젝트: kaspernj/knjphpfw
	/** Returns the PATH-dirs for the CLI as string in an array. */
	static function getPaths(){
		$os = knj_os::getOS();
		if ($os[os] != "linux"){
			throw new Exception("This function only works on Linux.");
		}
		
		$paths = knj_os::shellCMD("echo \$PATH");
		$dirs = explode(":", $paths["result"]);
		
		return $dirs;
	}