/** 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;
}
示例#3
0
	/** Loads a PHP-extension. */
	function knj_dl($extension){
		if (is_array($extension)){
			foreach($extension AS $ext){
				knj_dl($ext);
			}
			
			return true;
		}
		
		require_once "knj/functions_knj_os.php";
		$pre = "";
		$os = knj_os::getOS();
		
		if (extension_loaded($extension)){
			return true;
		}
		
		if ($extension == "sqlite" && !extension_loaded("php_pdo")){
			knj_dl("pdo");
		}
		
		if ($os["os"] == "windows"){
			$pre = "php_";
			$app = ".dll";
			
			if ($extension == "glade" || $extension == "libglade"){
				$extension = "gtk_libglade2";
			}elseif($extension == "gd"){
				$extension = "gd2";
			}
		}else{
			$app = ".so";
			
			if ($extension == "gtk2"){
				$pre = "php_";
			}
		}
		
		if ($extension == "gtk2" && extension_loaded("php-gtk")){
			return true;
		}
		
		if (!ini_get("enable_dl")){
			throw new Exception("The option \"enable_dl\" is not enabled in \"php.ini\" - cant load extension.");
		}
		
		if (!dl($pre . $extension . $app)){
			throw new Exception("Could not load the extension: " . $extension . ".");
		}
		
		return true;
	}
 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);
 }
	/** 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;
	}
示例#6
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;
 }
示例#9
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;
		}
示例#10
0
					$renames[$file] = $file_new;
				}
			}
			
			foreach($renames AS $key => $value){
				if (rename($folder . "/" . $key, $folder . "/" . $value)){
					$this->tv_files->get_model()->append(array($value));
				}else{
					$this->tv_files->get_model()->append(array($key));
				}
			}
		}
	}
	
	//Start program.
	require_once("knjphpframework/functions_knj_extensions.php");
	require_once("knjphpframework/functions_knj_os.php");
	require_once("knjphpframework/functions_treeview.php");
	
	if (!knj_dl("gtk2")){
		die("Could not load PHP-GTK2-module.\n");
	}
	
	if (knj_os::getOS() == "windows"){
		//Set Windows-skin if running Windows.
		Gtk::rc_parse("gtkrc");
	}
	
	$win_main = new WinMain();
	Gtk::main();
?>
示例#11
0
文件: os.php 项目: kaspernj/knjphpfw
	/** Returns the path to the PHP-executable, which you need if you want to start new processes. */
	static function getPHPExec($version = 5){
		$os = knj_os::getOS();
		
		if ($os["os"] == "linux"){
			$test_paths = array(
				"/usr/bin/php" . $version,
				"/usr/local/bin/php" . $version,
				"/usr/bin/php",
				"/usr/local/bin/php"
			);
			foreach($test_paths AS $path){
				if (file_exists($path)){
					return $path;
				}
			}
			
			if ($_SERVER["_"] && file_exists($_SERVER["_"])){
				return $_SERVER["_"];
			}
		}elseif($os["os"] == "windows"){
			//A hack to make this function work with packages created with knjPackageCreater.
			if (file_exists("../php5gtk2/php.exe")){
				return realpath("../php5gtk2/php.exe");
			}
		}else{
			throw new Exception("Unsupported OS: \"" . $os["os"] . "\".");
		}
		
		throw new Exception("Could not find the PHP-executable.");
	}
示例#12
0
/** Parse a string so it will be a valid filename. */
function knj_string_filename($string, $os = null){
	if (!$os){
		require_once("knj/os.php");
		$os = knj_os::getOS();
		$os = $os["os"];
	}
	
	if ($os == "windows"){
		//parse windows-filename here.
	}elseif($os == "linux"){
		$string = strtr($string, array(
			"å" => "aa",
			"ø" => "oe",
			"æ" => "ae",
			utf8_decode("å") => "aa",
			utf8_decode("æ") => "ae",
			utf8_decode("ø") => "oe",
			"|" => "",
			"&" => "",
			"/" => "",
			"\\" => ""
		));
	}else{
		throw new Exception("Unsupported OS.");
	}
	
	return $string;
}