Subversion Repositories php-qbpwcf

Rev

Rev 130 | Rev 218 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 130 Rev 183
Line 550... Line 550...
550
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
550
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
551
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
551
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
552
	#備註:
552
	#備註:
553
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
553
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
554
	#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
554
	#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
555
	#疑似檢查要執行的指令是否存在的shell script會有異常報錯,目前抓不到原因,但不影響執行結果.
555
	*/		
556
	*/
556
	public static function callShell(&$conf){
557
	public static function callShell(&$conf){
557
		
558
		
558
		#初始化要回傳的結果
559
		#初始化要回傳的結果
559
		$result=array();
560
		$result=array();
560
		
561
		
Line 803... Line 804...
803
			
804
			
804
			#輸出文字
805
			#輸出文字
805
			echo "執行「".$conf["printDescription"]."」命令\n";
806
			echo "執行「".$conf["printDescription"]."」命令\n";
806
			
807
			
807
			}#if end
808
			}#if end
808
					
809
		
809
		#初始化執行的指令
810
		#初始化執行的指令
810
		$result["cmd"]=$conf["command"];
811
		$result["cmd"]=$conf["command"];
811
		
812
		
812
		#初始化輸出
813
		#初始化輸出
813
		$output=array();
814
		$output=array();
Line 873... Line 874...
873
			}#if end
874
			}#if end
874
			
875
			
875
		#取得PATH字串陣列
876
		#取得PATH字串陣列
876
		$PATHS=$spiltString["dataArray"];
877
		$PATHS=$spiltString["dataArray"];
877
		
878
		
878
		#var_dump($PATHS);exit;
-
 
879
		
-
 
880
		#預設沒有找到程式
879
		#預設沒有找到程式
881
		$cmdFound=false;
880
		$cmdFound=false;
882
		
881
		
883
		#如果要執行的程式有指定位置
882
		#如果要執行的程式有指定位置
884
		if(strpos($result["cmd"],"/")!==false){
883
		if(strpos($result["cmd"],"/")!==false){
Line 890... Line 889...
890
			$output=array();
889
			$output=array();
891
			
890
			
892
			#執行指令
891
			#執行指令
893
			exec($cmd,$output,$status);
892
			exec($cmd,$output,$status);
894
		
893
		
-
 
894
			/*
-
 
895
			#debug
-
 
896
			$fh=fopen("/tmp/external::callShell.log","a");
-
 
897
			fwrite($fh,PHP_EOL."start".PHP_EOL);
-
 
898
			fwrite($fh,$result["cmd"].PHP_EOL);
-
 
899
			fwrite($fh,$cmd.PHP_EOL);
-
 
900
			fwrite($fh,print_r($ouput,true).PHP_EOL);
-
 
901
			fwrite($fh,$status.PHP_EOL);
-
 
902
			fwrite($fh,PHP_EOL."end".PHP_EOL);
-
 
903
			fclose($fh);
-
 
904
			*/
-
 
905
		
895
			#如果有找到
906
			#如果有找到
896
			if($status===0){
907
			if($status===0){
897
			
908
			
898
				#設置有找到
909
				#設置有找到
899
				$cmdFound=true;
910
				$cmdFound=true;
Line 915... Line 926...
915
				$output=array();
926
				$output=array();
916
				
927
				
917
				#執行指令
928
				#執行指令
918
				exec($cmd,$output,$status);
929
				exec($cmd,$output,$status);
919
			
930
			
-
 
931
				/*
-
 
932
				#debug
-
 
933
				$fh=fopen("/tmp/external::callShell.log","a");
-
 
934
				fwrite($fh,PHP_EOL."start".PHP_EOL);
-
 
935
				fwrite($fh,$result["cmd"].PHP_EOL);
-
 
936
				fwrite($fh,$cmd.PHP_EOL);
-
 
937
				fwrite($fh,print_r($ouput,true).PHP_EOL);
-
 
938
				fwrite($fh,$status.PHP_EOL);
-
 
939
				fwrite($fh,PHP_EOL."end".PHP_EOL);
-
 
940
				fclose($fh);
-
 
941
				*/
-
 
942
			
920
				#如果執行正常
943
				#如果執行正常
921
				if($status===0){
944
				if($status===0){
922
				
945
				
923
					#代表有找到程式
946
					#代表有找到程式
924
					$cmdFound=true;
947
					$cmdFound=true;
Line 929... Line 952...
929
					}#if end
952
					}#if end
930
			
953
			
931
				}#foreach end
954
				}#foreach end
932
		
955
		
933
			}#else end
956
			}#else end
934
					
957
		
935
		#如果找不到要執行的程式
958
		#如果找不到要執行的程式
936
		if($cmdFound===false){
959
		if($cmdFound===false){
937
		
960
		
938
			$equalPosition=strpos($result["cmd"],"=");
961
			$equalPosition=strpos($result["cmd"],"=");
939
		
962