Subversion Repositories php-qbpwcf

Rev

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

Rev 61 Rev 66
Line 2042... Line 2042...
2042
			
2042
			
2043
			#若是bin2hex
2043
			#若是bin2hex
2044
			case "bin2hex":
2044
			case "bin2hex":
2045
			
2045
			
2046
				#用16進位的兩個字母來表示每個byte
2046
				#用16進位的兩個字母來表示每個byte
2047
				$result["content"]=unpack("H*",$conf["enCodeStr"]);
2047
				$unpack=unpack("H*",$conf["enCodeStr"]);
-
 
2048
			
-
 
2049
				#如果沒有結果
-
 
2050
				if(!isset($unpack[1])){
-
 
2051
				
-
 
2052
					#設置執行失敗
-
 
2053
					$result["status"]="false";
-
 
2054
					
-
 
2055
					#設置執行錯誤
-
 
2056
					$result["error"][]="bin2hex failed";
-
 
2057
					
-
 
2058
					#設置執行錯誤
-
 
2059
					$result["error"][]=$unpack;
-
 
2060
					
-
 
2061
					#回傳結果
-
 
2062
					return $result;
-
 
2063
				
-
 
2064
					}#if end
-
 
2065
					
-
 
2066
				#取得結果
-
 
2067
				$result["content"]=$unpack[1];
2048
			
2068
			
2049
				#相當於
2069
				#相當於
2050
				#$result["content"]=bin2hex($conf["enCodeStr"]);
2070
				#$result["content"]=bin2hex($conf["enCodeStr"]);
2051
				
2071
				
2052
				#跳出 switch
2072
				#跳出 switch
Line 2054... Line 2074...
2054
				
2074
				
2055
			#若是hex2bin
2075
			#若是hex2bin
2056
			case "hex2bin":
2076
			case "hex2bin":
2057
			
2077
			
2058
				#將每個byte用兩個16進位字母來表示的字串變成 binary string
2078
				#將每個byte用兩個16進位字母來表示的字串變成 binary string
2059
 				$result["content"]=pack("H*",$conf["enCodeStr"]);
2079
 				$pack=pack("H*",$conf["enCodeStr"]);
-
 
2080
				
-
 
2081
				$result["content"]=$pack;
2060
			
2082
			
2061
				#跳出 switch
2083
				#跳出 switch
2062
				break;
2084
				break;
2063
			
2085
			
2064
			#如果是"gpg加解密"
2086
			#如果是"gpg加解密"
Line 2414... Line 2436...
2414
		
2436
		
2415
		}#function str2bin end	
2437
		}#function str2bin end	
2416
 
2438
 
2417
	/*
2439
	/*
2418
	#函式說明:
2440
	#函式說明:
2419
	#驗證Linux使用者的密碼是否正確.
2441
	#驗證Linux使用者的密碼或ssh private key是否正確.
2420
	#回傳結果:
2442
	#回傳結果:
2421
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
2443
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
2422
	#$result["function"],當前執行的函數名稱.
2444
	#$result["function"],當前執行的函數名稱.
2423
	#$result["error"],錯誤訊息陣列.
2445
	#$result["error"],錯誤訊息陣列.
2424
	#$result["warninig"],警告訊息陣列.
2446
	#$result["warninig"],警告訊息陣列.
Line 2429... Line 2451...
2429
	#$conf["password"],字串,用於驗證使用者的密碼.
2451
	#$conf["password"],字串,用於驗證使用者的密碼.
2430
	$conf["password"]="";
2452
	$conf["password"]="";
2431
	#$conf["fileArgu"],字串,變數__FILE__的內容.
2453
	#$conf["fileArgu"],字串,變數__FILE__的內容.
2432
	$conf["fileArgu"]=__FILE__;
2454
	$conf["fileArgu"]=__FILE__;
2433
	#可省略參數:
2455
	#可省略參數:
-
 
2456
	#$conf["sshPrivateKey"],字串,"true"代表password為ssh private key的內容;反之預設為密碼,設置為"false".
2434
	#無.
2457
	#$conf["sshPrivateKey"]="false";
2435
	#參考資料:
2458
	#參考資料:
2436
	#無.
2459
	#無.
2437
	#備註:
2460
	#備註:
2438
	#僅能在命令列環境下運行.
2461
	#僅能在命令列環境下運.
-
 
2462
	#目前僅支援驗證執行php端的使用者.
2439
	*/
2463
	*/
2440
	public static function validUser(&$conf){
2464
	public static function validUser(&$conf){
2441
		
2465
		
2442
		#初始化要回傳的結果
2466
		#初始化要回傳的結果
2443
		$result=array();
2467
		$result=array();
Line 2535... Line 2559...
2535
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列
2559
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列
2536
		$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");
2560
		$conf["variableCheck::checkArguments"]["canBeEmpty"]=array("password");
2537
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
2561
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
2538
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2562
		#$conf["skipableVariableCanNotBeEmpty"]=array();
2539
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2563
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2540
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("fileArgu","conf","commentsArray","forceRewrite");
2564
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sshPrivateKey");
2541
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2565
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2542
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","string");
2566
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2543
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2567
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2544
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(__FILE__,".qbpwcf_tmp/cmd/getFromConf/conf.xml",array("請輸入變數 ".$conf["readVarName"]." 的內容"),"false");
2568
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false");
2545
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2569
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2546
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
2570
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conName","conVal");
2547
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
2571
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("target","styleAttr","styleVal");
2548
		#參考資料來源:
2572
		#參考資料來源:
2549
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2573
		#array_keys=>http://php.net/manual/en/function.array-keys.php
Line 2618... Line 2642...
2618
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2642
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2619
		$callShell=external::callShell($conf["external::callShell"]);
2643
		$callShell=external::callShell($conf["external::callShell"]);
2620
		unset($conf["external::callShell"]);
2644
		unset($conf["external::callShell"]);
2621
		
2645
		
2622
		#如果執行shell失敗
2646
		#如果執行shell失敗
2623
		if($callShell["status"]=="false"){
2647
		if($callShell["status"]==="false"){
2624
			
2648
			
2625
			#設置執行不正常
2649
			#設置執行不正常
2626
			$result["status"]="false";
2650
			$result["status"]="false";
2627
			
2651
			
2628
			#設置執行錯誤
2652
			#設置執行錯誤
Line 2632... Line 2656...
2632
			return $result;
2656
			return $result;
2633
			
2657
			
2634
			}#if end
2658
			}#if end
2635
			
2659
			
2636
		#如果使用者 $conf["username"] 不存在
2660
		#如果使用者 $conf["username"] 不存在
2637
		if($callShell["output"][0]=="id: ".$conf["username"].": no such user"){
2661
		if($callShell["output"][0]==="id: ".$conf["username"].": no such user"){
2638
			
2662
			
2639
			#設置執行不正常
2663
			#設置執行不正常
2640
			$result["status"]="true";
2664
			$result["status"]="true";
2641
			
2665
			
2642
			#設置使用者驗證失敗
2666
			#設置使用者驗證失敗
Line 2647... Line 2671...
2647
			
2671
			
2648
			#回傳結果
2672
			#回傳結果
2649
			return $result;
2673
			return $result;
2650
			
2674
			
2651
			}#if end
2675
			}#if end
-
 
2676
		
-
 
2677
		#如果要用ssh private key進行認證
-
 
2678
		if($conf["sshPrivateKey"]==="true"){
-
 
2679
		
-
 
2680
			#可以用 echo "env | grep SSH_CONNECTION=" | ssh username@127.0.0.1 來驗證使用者的ssh連線是否成功
-
 
2681
		
-
 
2682
			#預設用來測試ssh private key 與 username 是否可成功登入的賬戶
-
 
2683
			$sshAgentAcct="qbpwcf";
-
 
2684
		
-
 
2685
			#確認用來測試登入ssh的使用者qbpwcf存在
-
 
2686
			#檢查使用者是否存在
-
 
2687
			#函式說明:
-
 
2688
			#呼叫shell執行系統命令,並取得回傳的內容.
-
 
2689
			#回傳的結果:
-
 
2690
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
2691
			#$result["error"],錯誤訊息陣列.
-
 
2692
			#$result["function"],當前執行的函數名稱.
-
 
2693
			#$result["cmd"],執行的指令內容.
-
 
2694
			#$result["output"],爲執行完二元碼後的輸出陣列.
-
 
2695
			#必填的參數
-
 
2696
			#$conf["command"],字串,要執行的指令與.
-
 
2697
			$conf["external::callShell"]["command"]="id";
-
 
2698
			#可省略參數:
-
 
2699
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2700
			$conf["external::callShell"]["argu"]=array($sshAgentAcct);
-
 
2701
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
2702
			#$conf["enablePrintDescription"]="true";
-
 
2703
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
-
 
2704
			#$conf["printDescription"]="";
-
 
2705
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
-
 
2706
			#$conf["escapeshellarg"]="false";
-
 
2707
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
-
 
2708
			#$conf["external::callShell"]["username"]="";
-
 
2709
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
-
 
2710
			#$conf["external::callShell"]["password"]="";
-
 
2711
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
-
 
2712
			$conf["external::callShell"]["useScript"]="true";
-
 
2713
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
-
 
2714
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
2715
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
-
 
2716
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2717
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
2718
			#備註:
-
 
2719
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
-
 
2720
			#參考資料:
-
 
2721
			#exec=>http://php.net/manual/en/function.exec.php
-
 
2722
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
2723
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
2724
			$callShell=external::callShell($conf["external::callShell"]);
-
 
2725
			unset($conf["external::callShell"]);
-
 
2726
			
-
 
2727
			#如果執行shell失敗
-
 
2728
			if($callShell["status"]==="false"){
-
 
2729
				
-
 
2730
				#設置執行不正常
-
 
2731
				$result["status"]="false";
-
 
2732
				
-
 
2733
				#設置執行錯誤
-
 
2734
				$result["error"]=$callShell;
-
 
2735
				
-
 
2736
				#回傳結果
-
 
2737
				return $result;
-
 
2738
				
-
 
2739
				}#if end
-
 
2740
			
-
 
2741
			#另外儲存存放ssh使用者設定的目錄
-
 
2742
			$dotsshFolderOfsshAgent="/home/".$sshAgentAcct."/.ssh";
-
 
2743
			
-
 
2744
			#如果使用者 $sshAgentAcct 不存在
-
 
2745
			if($callShell["output"][0]==="id: ".$sshAgentAcct.": no such user"){
-
 
2746
				
-
 
2747
				#透過 qbpwcf-usock.service 服務建立對應的使用者
-
 
2748
				#函式說明:
-
 
2749
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
2750
				#回傳結果:
-
 
2751
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
2752
				#$result["error"],錯誤訊息陣列.
-
 
2753
				#$result["function"],當前執行的函式名稱.
-
 
2754
				#$result["argu"],使用的參數.
-
 
2755
				#$result["content"],執行完指令的結果.
-
 
2756
				#必填參數:
-
 
2757
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2758
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
2759
				#$conf["command"],字串,要執行的指令名稱.
-
 
2760
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="useradd";
-
 
2761
				#可省略參數:
-
 
2762
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
2763
				#$conf["sock"]=qbpwcf_usock_path;
-
 
2764
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2765
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct);
-
 
2766
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
2767
				#$conf["commandIncludeArgu"]="false";
-
 
2768
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
2769
				#$conf["commandInBg"]="false";
-
 
2770
				#參考資料:
-
 
2771
				#無.
-
 
2772
				#備註:
-
 
2773
				#無.
-
 
2774
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2775
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2776
				
-
 
2777
				#如果執行shell失敗
-
 
2778
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
2652
					
2779
					
2653
		#可以用 echo 'password' | su username -c 'echo valid' 來檢查使用者密碼是否正確
-
 
2654
		#檢查使用者是否存在
2780
					#設置執行不正常
2655
		#函式說明:
-
 
2656
		#呼叫shell執行系統命令,並取得回傳的內容.
-
 
2657
		#回傳的結果:
-
 
2658
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
2659
		#$result["error"],錯誤訊息陣列.
-
 
2660
		#$result["function"],當前執行的函數名稱.
-
 
2661
		#$result["cmd"],執行的指令內容.
-
 
2662
		#$result["output"],爲執行完二元碼後的輸出陣列.
-
 
2663
		#必填的參數
-
 
2664
		#$conf["command"],字串,要執行的指令與.
-
 
2665
		$conf["external::callShell"]["command"]="echo";
-
 
2666
		#可省略參數:
-
 
2667
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2668
		$conf["external::callShell"]["argu"]=array($conf["password"],"|","su",$conf["username"],"-c","echo valid");
-
 
2669
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
2670
		#$conf["enablePrintDescription"]="true";
-
 
2671
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
-
 
2672
		#$conf["printDescription"]="";
-
 
2673
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
-
 
2674
		#$conf["escapeshellarg"]="false";
2781
					$result["status"]="false";
2675
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
-
 
2676
		#$conf["external::callShell"]["username"]="";
-
 
2677
		#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
-
 
2678
		#$conf["external::callShell"]["password"]="";
-
 
2679
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
-
 
2680
		$conf["external::callShell"]["useScript"]="true";
-
 
2681
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
-
 
2682
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
2683
		#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
-
 
2684
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
2685
		#備註:
-
 
2686
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
-
 
2687
		#參考資料:
-
 
2688
		#exec=>http://php.net/manual/en/function.exec.php
-
 
2689
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
2690
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
2691
		$callShell=external::callShell($conf["external::callShell"]);
-
 
2692
		unset($conf["external::callShell"]);
-
 
2693
					
2782
					
-
 
2783
					#設置執行錯誤
-
 
2784
					$result["error"]=$execAnyCmdByQBPWCFunixSocket;
-
 
2785
					
-
 
2786
					#回傳結果
-
 
2787
					return $result;
-
 
2788
					
-
 
2789
					}#if end
-
 
2790
					
-
 
2791
				#透過 qbpwcf-usock.service 服務建立設置對應使用者的 .ssh 目錄 
-
 
2792
				#函式說明:
-
 
2793
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
2794
				#回傳結果:
-
 
2795
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
2796
				#$result["error"],錯誤訊息陣列.
-
 
2797
				#$result["function"],當前執行的函式名稱.
-
 
2798
				#$result["argu"],使用的參數.
-
 
2799
				#$result["content"],執行完指令的結果.
-
 
2800
				#必填參數:
-
 
2801
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2802
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
2803
				#$conf["command"],字串,要執行的指令名稱.
-
 
2804
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
-
 
2805
				#可省略參數:
-
 
2806
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
2807
				#$conf["sock"]=qbpwcf_usock_path;
-
 
2808
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2809
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($dotsshFolderOfsshAgent);
-
 
2810
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
2811
				#$conf["commandIncludeArgu"]="false";
-
 
2812
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
2813
				#$conf["commandInBg"]="false";
-
 
2814
				#參考資料:
-
 
2815
				#無.
-
 
2816
				#備註:
-
 
2817
				#無.
-
 
2818
				$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2819
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2820
				
2694
		#如果執行shell失敗
2821
				#如果執行shell失敗
-
 
2822
				if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
-
 
2823
					
-
 
2824
					#設置執行不正常
2695
		if($callShell["status"]=="false"){
2825
					$result["status"]="false";
-
 
2826
					
-
 
2827
					#設置執行錯誤
-
 
2828
					$result["error"]=$execAnyCmdByQBPWCFunixSocket;
-
 
2829
					
-
 
2830
					#回傳結果
-
 
2831
					return $result;
-
 
2832
					
-
 
2833
					}#if end
-
 
2834
				
-
 
2835
				}#if end
2696
			
2836
			
-
 
2837
			#確認 ssh 使用者設定的目錄 $dotsshFolderOfsshAgent 是否存在
-
 
2838
			#函式說明:
-
 
2839
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
2840
			#回傳結果:
-
 
2841
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
2842
			#$result["error"],錯誤訊息陣列.
-
 
2843
			#$result["function"],當前執行的函式名稱.
-
 
2844
			#$result["argu"],使用的參數.
-
 
2845
			#$result["content"],執行完指令的結果.
-
 
2846
			#必填參數:
-
 
2847
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2848
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
2849
			#$conf["command"],字串,要執行的指令名稱.
-
 
2850
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="checkNodeExist.php";
2697
			#設置執行不正常
2851
			#可省略參數:
-
 
2852
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
2853
			#$conf["sock"]=qbpwcf_usock_path;
-
 
2854
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2855
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($dotsshFolderOfsshAgent);
-
 
2856
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
2857
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
2858
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
2698
			$result["status"]="false";
2859
			#$conf["commandInBg"]="false";
-
 
2860
			#參考資料:
-
 
2861
			#無.
-
 
2862
			#備註:
-
 
2863
			#無.
-
 
2864
			$execAnyCmdByQBPWCFunixSocket=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2865
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
2699
			
2866
			
-
 
2867
			#如果執行shell失敗
-
 
2868
			if($execAnyCmdByQBPWCFunixSocket["status"]==="false"){
-
 
2869
				
-
 
2870
				#設置執行不正常
-
 
2871
				$result["status"]="false";
-
 
2872
				
2700
			#設置執行錯誤
2873
				#設置執行錯誤
2701
			$result["error"]=$callShell;
2874
				$result["error"]=$execAnyCmdByQBPWCFunixSocket;
-
 
2875
				
-
 
2876
				#回傳結果
-
 
2877
				return $result;
-
 
2878
				
-
 
2879
				}#if end
2702
			
2880
			
2703
			#回傳結果
2881
			#如果得到的結果不為 json
2704
			return $result;
2882
			if(!json_validate($execAnyCmdByQBPWCFunixSocket["content"])){
2705
			
2883
			
-
 
2884
				#設置執行不正常
-
 
2885
				$result["status"]="false";
-
 
2886
				
-
 
2887
				#設置執行錯誤
-
 
2888
				$result["error"]=$execAnyCmdByQBPWCFunixSocket;
-
 
2889
				
2706
			}#if end
2890
				#回傳結果
-
 
2891
				return $result;
2707
			
2892
			
2708
		#範例輸出:
-
 
2709
		#Script started on Sat 05 Nov 2016 06:08:31 PM CST
-
 
2710
		#Password: valid
-
 
2711
							
2893
				}#if end
2712
		#如果輸出 "valid"
-
 
2713
		if($callShell["output"][1]=="Password: valid"){
-
 
2714
			
2894
			
2715
			#代表使用者密碼正確
2895
			#解析 json 並轉換成 array
-
 
2896
			$execAnyCmdByQBPWCFunixSocket["content"]=(array)(json_decode($execAnyCmdByQBPWCFunixSocket["content"]));
2716
			
2897
			
2717
			#設置執行正常
2898
			#如果沒有找到要存在的 $dotsshFolderOfsshAgent 目錄
2718
			$result["status"]="true";
2899
			if(count($execAnyCmdByQBPWCFunixSocket["content"])===0){
2719
			
2900
			
-
 
2901
				#建立之
-
 
2902
				#函式說明:
-
 
2903
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
2904
				#回傳結果:
-
 
2905
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
2906
				#$result["error"],錯誤訊息陣列.
-
 
2907
				#$result["function"],當前執行的函式名稱.
-
 
2908
				#$result["argu"],使用的參數.
-
 
2909
				#$result["content"],執行完指令的結果.
-
 
2910
				#必填參數:
-
 
2911
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2912
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
2913
				#$conf["command"],字串,要執行的指令名稱.
-
 
2914
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
-
 
2915
				#可省略參數:
-
 
2916
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
2917
				#$conf["sock"]=qbpwcf_usock_path;
-
 
2918
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2919
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("-p",$dotsshFolderOfsshAgent);
-
 
2920
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
2921
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
2922
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
2923
				#$conf["commandInBg"]="false";
-
 
2924
				#參考資料:
-
 
2925
				#無.
-
 
2926
				#備註:
-
 
2927
				#無.
-
 
2928
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2929
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2930
				
-
 
2931
				#如果執行shell失敗
-
 
2932
				if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
2933
					
2720
			#設置使用者驗證失敗
2934
					#設置執行不正常
2721
			$result["valid"]="true";
2935
					$result["status"]="false";
-
 
2936
					
-
 
2937
					#設置執行錯誤
-
 
2938
					$result["error"]=$createDotsshFolderOfsshAgent;
-
 
2939
					
-
 
2940
					#回傳結果
-
 
2941
					return $result;
-
 
2942
					
-
 
2943
					}#if end
2722
			
2944
			
2723
			#回傳結果
-
 
2724
			return $result;
2945
				}#if end
2725
			
2946
			
-
 
2947
			#如果沒有找到要存在的 $dotsshFolderOfsshAgent 目錄
-
 
2948
			else if($execAnyCmdByQBPWCFunixSocket[0]!==$dotsshFolderOfsshAgent){
-
 
2949
			
-
 
2950
				#建立之
-
 
2951
				#函式說明:
-
 
2952
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
2953
				#回傳結果:
-
 
2954
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
2955
				#$result["error"],錯誤訊息陣列.
-
 
2956
				#$result["function"],當前執行的函式名稱.
-
 
2957
				#$result["argu"],使用的參數.
-
 
2958
				#$result["content"],執行完指令的結果.
-
 
2959
				#必填參數:
-
 
2960
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2961
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
2962
				#$conf["command"],字串,要執行的指令名稱.
-
 
2963
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="mkdir";
-
 
2964
				#可省略參數:
-
 
2965
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
2966
				#$conf["sock"]=qbpwcf_usock_path;
-
 
2967
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2968
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("-p",$dotsshFolderOfsshAgent);
-
 
2969
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
2970
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
2971
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
2972
				#$conf["commandInBg"]="false";
-
 
2973
				#參考資料:
-
 
2974
				#無.
-
 
2975
				#備註:
-
 
2976
				#無.
-
 
2977
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2978
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
2979
				
-
 
2980
				#如果執行shell失敗
-
 
2981
				if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
2982
					
-
 
2983
					#設置執行不正常
-
 
2984
					$result["status"]="false";
-
 
2985
					
-
 
2986
					#設置執行錯誤
-
 
2987
					$result["error"]=$createDotsshFolderOfsshAgent;
-
 
2988
					
-
 
2989
					#回傳結果
-
 
2990
					return $result;
-
 
2991
					
-
 
2992
					}#if end
-
 
2993
			
-
 
2994
				}#if end
-
 
2995
			
-
 
2996
			#取得 $dotsshFolderOfsshAgent 的權限與擁有着
-
 
2997
			#函式說明:
-
 
2998
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
2999
			#回傳結果:
-
 
3000
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3001
			#$result["error"],錯誤訊息陣列.
-
 
3002
			#$result["function"],當前執行的函式名稱.
-
 
3003
			#$result["argu"],使用的參數.
-
 
3004
			#$result["content"],執行完指令的結果.
-
 
3005
			#必填參數:
-
 
3006
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3007
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3008
			#$conf["command"],字串,要執行的指令名稱.
-
 
3009
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="getNodeInfo.php";
-
 
3010
			#可省略參數:
-
 
3011
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3012
			#$conf["sock"]=qbpwcf_usock_path;
-
 
3013
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3014
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("--node",$dotsshFolderOfsshAgent);
-
 
3015
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3016
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3017
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3018
			#$conf["commandInBg"]="false";
-
 
3019
			#參考資料:
-
 
3020
			#無.
-
 
3021
			#備註:
-
 
3022
			#無.
-
 
3023
			$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3024
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3025
			
-
 
3026
			#如果執行shell失敗
-
 
3027
			if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3028
				
-
 
3029
				#設置執行不正常
-
 
3030
				$result["status"]="false";
-
 
3031
				
-
 
3032
				#設置執行錯誤
-
 
3033
				$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3034
				
-
 
3035
				#回傳結果
-
 
3036
				return $result;
-
 
3037
				
-
 
3038
				}#if end
-
 
3039
			
-
 
3040
			#如果執行異常
-
 
3041
			if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3042
			
-
 
3043
				#設置執行不正常
-
 
3044
				$result["status"]="false";
-
 
3045
				
-
 
3046
				#設置執行錯誤
-
 
3047
				$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3048
				
-
 
3049
				#回傳結果
-
 
3050
				return $result;
-
 
3051
			
-
 
3052
				}#if end
-
 
3053
				
-
 
3054
			#如果沒有得到輸出
-
 
3055
			if(!isset($createDotsshFolderOfsshAgent["content"][0])){
-
 
3056
			
-
 
3057
				#設置執行不正常
-
 
3058
				$result["status"]="false";
-
 
3059
				
-
 
3060
				#設置執行錯誤
-
 
3061
				$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3062
				
-
 
3063
				#回傳結果
-
 
3064
				return $result;
-
 
3065
			
-
 
3066
				}#if end
-
 
3067
				
-
 
3068
			#如果輸出結果不是json
-
 
3069
			if(!json_validate($createDotsshFolderOfsshAgent["content"][0])){
-
 
3070
			
-
 
3071
				#設置執行不正常
-
 
3072
				$result["status"]="false";
-
 
3073
				
-
 
3074
				#設置執行錯誤
-
 
3075
				$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3076
				
-
 
3077
				#回傳結果
-
 
3078
				return $result;
-
 
3079
			
2726
			}#if end
3080
				}#if end
-
 
3081
			
-
 
3082
			#解析json
-
 
3083
			$node_info=json_decode($createDotsshFolderOfsshAgent["content"][0]);
-
 
3084
			
-
 
3085
			#若 $dotsshFolderOfsshAgent 的權限,不為 "rwx------"
-
 
3086
			if($node_info->ownerPerm!=="rwx" || $node_info->groupPerm!=="---" || $node_info->otherPerm!=="---"){
-
 
3087
			
-
 
3088
				#更新其權限設置
-
 
3089
				#函式說明:
-
 
3090
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3091
				#回傳結果:
-
 
3092
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3093
				#$result["error"],錯誤訊息陣列.
-
 
3094
				#$result["function"],當前執行的函式名稱.
-
 
3095
				#$result["argu"],使用的參數.
-
 
3096
				#$result["content"],執行完指令的結果.
-
 
3097
				#必填參數:
-
 
3098
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3099
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3100
				#$conf["command"],字串,要執行的指令名稱.
-
 
3101
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chmod";
-
 
3102
				#可省略參數:
-
 
3103
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3104
				#$conf["sock"]=qbpwcf_usock_path;
-
 
3105
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3106
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("700",$dotsshFolderOfsshAgent);
-
 
3107
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3108
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3109
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3110
				#$conf["commandInBg"]="false";
-
 
3111
				#參考資料:
-
 
3112
				#無.
-
 
3113
				#備註:
-
 
3114
				#無.
-
 
3115
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3116
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3117
				
-
 
3118
				#如果執行shell失敗
-
 
3119
				if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3120
					
-
 
3121
					#設置執行不正常
-
 
3122
					$result["status"]="false";
-
 
3123
					
-
 
3124
					#設置執行錯誤
-
 
3125
					$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3126
					
-
 
3127
					#回傳結果
-
 
3128
					return $result;
-
 
3129
					
-
 
3130
					}#if end
-
 
3131
				
-
 
3132
				}#if end
-
 
3133
			
-
 
3134
			#若 $dotsshFolderOfsshAgent 的擁有着不為 $sshAgentAcct:$sshAgentAcct
-
 
3135
			if($node_info->ownerName!==$sshAgentAcct || $node_info->groupName!==$sshAgentAcct){
-
 
3136
			
-
 
3137
				#更新其擁有着設置
-
 
3138
				#函式說明:
-
 
3139
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3140
				#回傳結果:
-
 
3141
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3142
				#$result["error"],錯誤訊息陣列.
-
 
3143
				#$result["function"],當前執行的函式名稱.
-
 
3144
				#$result["argu"],使用的參數.
-
 
3145
				#$result["content"],執行完指令的結果.
-
 
3146
				#必填參數:
-
 
3147
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3148
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3149
				#$conf["command"],字串,要執行的指令名稱.
-
 
3150
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chown";
-
 
3151
				#可省略參數:
-
 
3152
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3153
				#$conf["sock"]=qbpwcf_usock_path;
-
 
3154
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3155
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct.":".$sshAgentAcct,$dotsshFolderOfsshAgent);
-
 
3156
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3157
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3158
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3159
				#$conf["commandInBg"]="false";
-
 
3160
				#參考資料:
-
 
3161
				#無.
-
 
3162
				#備註:
-
 
3163
				#無.
-
 
3164
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3165
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3166
				
-
 
3167
				#如果執行shell失敗
-
 
3168
				if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3169
					
-
 
3170
					#設置執行不正常
-
 
3171
					$result["status"]="false";
-
 
3172
					
-
 
3173
					#設置執行錯誤
-
 
3174
					$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3175
					
-
 
3176
					#回傳結果
-
 
3177
					return $result;
-
 
3178
					
-
 
3179
					}#if end
-
 
3180
			
-
 
3181
				}#if end
-
 
3182
			
-
 
3183
			#設置要使用的ssh private key
-
 
3184
			#函式說明:
-
 
3185
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3186
			#回傳結果:
-
 
3187
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3188
			#$result["error"],錯誤訊息陣列.
-
 
3189
			#$result["function"],當前執行的函式名稱.
-
 
3190
			#$result["argu"],使用的參數.
-
 
3191
			#$result["content"],執行完指令的結果.
-
 
3192
			#必填參數:
-
 
3193
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3194
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3195
			#$conf["command"],字串,要執行的指令名稱.
-
 
3196
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="echo";
-
 
3197
			#可省略參數:
-
 
3198
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3199
			#$conf["sock"]=qbpwcf_usock_path;
-
 
3200
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3201
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshPrivateKeyContent,">",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
-
 
3202
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3203
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3204
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3205
			#$conf["commandInBg"]="false";
-
 
3206
			#參考資料:
-
 
3207
			#無.
-
 
3208
			#備註:
-
 
3209
			#無.
-
 
3210
			$createSshPrivateKey=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3211
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3212
			
-
 
3213
			#如果執行shell失敗
-
 
3214
			if($createSshPrivateKey["status"]==="false"){
-
 
3215
				
-
 
3216
				#設置執行不正常
-
 
3217
				$result["status"]="false";
-
 
3218
				
-
 
3219
				#設置執行錯誤
-
 
3220
				$result["error"]=$createSshPrivateKey;
-
 
3221
				
-
 
3222
				#回傳結果
-
 
3223
				return $result;
-
 
3224
				
-
 
3225
				}#if end
-
 
3226
			
-
 
3227
			#取得 ssh privacy key 檔案的權限與擁有着
-
 
3228
			#函式說明:
-
 
3229
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3230
			#回傳結果:
-
 
3231
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3232
			#$result["error"],錯誤訊息陣列.
-
 
3233
			#$result["function"],當前執行的函式名稱.
-
 
3234
			#$result["argu"],使用的參數.
-
 
3235
			#$result["content"],執行完指令的結果.
-
 
3236
			#必填參數:
-
 
3237
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3238
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3239
			#$conf["command"],字串,要執行的指令名稱.
-
 
3240
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="getNodeInfo.php";
-
 
3241
			#可省略參數:
-
 
3242
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3243
			#$conf["sock"]=qbpwcf_usock_path;
-
 
3244
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3245
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("--node",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
-
 
3246
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3247
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3248
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3249
			#$conf["commandInBg"]="false";
-
 
3250
			#參考資料:
-
 
3251
			#無.
-
 
3252
			#備註:
-
 
3253
			#無.
-
 
3254
			$getSshPrivateKeyFileInfo=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3255
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3256
			
-
 
3257
			#如果執行shell失敗
-
 
3258
			if($getSshPrivateKeyFileInfo["status"]==="false"){
-
 
3259
				
-
 
3260
				#設置執行不正常
-
 
3261
				$result["status"]="false";
-
 
3262
				
-
 
3263
				#設置執行錯誤
-
 
3264
				$result["error"]=$getSshPrivateKeyFileInfo;
-
 
3265
				
-
 
3266
				#回傳結果
-
 
3267
				return $result;
-
 
3268
				
-
 
3269
				}#if end
-
 
3270
			
-
 
3271
			#如果執行異常
-
 
3272
			if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3273
			
-
 
3274
				#設置執行不正常
-
 
3275
				$result["status"]="false";
-
 
3276
				
-
 
3277
				#設置執行錯誤
-
 
3278
				$result["error"]=$getSshPrivateKeyFileInfo;
-
 
3279
				
-
 
3280
				#回傳結果
-
 
3281
				return $result;
-
 
3282
			
-
 
3283
				}#if end
-
 
3284
				
-
 
3285
			#如果沒有得到輸出
-
 
3286
			if(!isset($createDotsshFolderOfsshAgent["content"][0])){
-
 
3287
			
-
 
3288
				#設置執行不正常
-
 
3289
				$result["status"]="false";
-
 
3290
				
-
 
3291
				#設置執行錯誤
-
 
3292
				$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3293
				
-
 
3294
				#回傳結果
-
 
3295
				return $result;
-
 
3296
			
-
 
3297
				}#if end
-
 
3298
				
-
 
3299
			#如果輸出結果不是json
-
 
3300
			if(!json_validate($createDotsshFolderOfsshAgent["content"][0])){
-
 
3301
			
-
 
3302
				#設置執行不正常
-
 
3303
				$result["status"]="false";
-
 
3304
				
-
 
3305
				#設置執行錯誤
-
 
3306
				$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3307
				
-
 
3308
				#回傳結果
-
 
3309
				return $result;
-
 
3310
			
-
 
3311
				}#if end
-
 
3312
			
-
 
3313
			#解析json
-
 
3314
			$node_info=json_decode($createDotsshFolderOfsshAgent["content"][0]);
-
 
3315
			
-
 
3316
			#若 ssh privacy key 檔案的擁有着不為 $sshAgentAcct:$sshAgentAcct
-
 
3317
			if($node_info->ownerName!==$sshAgentAcct || $node_info->groupName!==$sshAgentAcct){
-
 
3318
			
-
 
3319
				#更新 ssh privacy key 的檔案擁有者
-
 
3320
				#函式說明:
-
 
3321
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3322
				#回傳結果:
-
 
3323
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3324
				#$result["error"],錯誤訊息陣列.
-
 
3325
				#$result["function"],當前執行的函式名稱.
-
 
3326
				#$result["argu"],使用的參數.
-
 
3327
				#$result["content"],執行完指令的結果.
-
 
3328
				#必填參數:
-
 
3329
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3330
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3331
				#$conf["command"],字串,要執行的指令名稱.
-
 
3332
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chmod";
-
 
3333
				#可省略參數:
-
 
3334
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3335
				#$conf["sock"]=qbpwcf_usock_path;
-
 
3336
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3337
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("700",$dotsshFolderOfsshAgent);
-
 
3338
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3339
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3340
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3341
				#$conf["commandInBg"]="false";
-
 
3342
				#參考資料:
-
 
3343
				#無.
-
 
3344
				#備註:
-
 
3345
				#無.
-
 
3346
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3347
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3348
				
-
 
3349
				#如果執行shell失敗
-
 
3350
				if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3351
					
-
 
3352
					#設置執行不正常
-
 
3353
					$result["status"]="false";
-
 
3354
					
-
 
3355
					#設置執行錯誤
-
 
3356
					$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3357
					
-
 
3358
					#回傳結果
-
 
3359
					return $result;
-
 
3360
					
-
 
3361
					}#if end
-
 
3362
			
-
 
3363
				}#if end
-
 
3364
			
-
 
3365
			#若 ssh privacy key 檔案的權限不為 "rw-------"
-
 
3366
			if($node_info->ownerPerm!=="rw-" || $node_info->groupPerm!=="---" || $node_info->otherPerm!=="---"){
-
 
3367
				
-
 
3368
				#更新 ssh privacy key 的檔案擁有者
-
 
3369
				#函式說明:
-
 
3370
				#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3371
				#回傳結果:
-
 
3372
				#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3373
				#$result["error"],錯誤訊息陣列.
-
 
3374
				#$result["function"],當前執行的函式名稱.
-
 
3375
				#$result["argu"],使用的參數.
-
 
3376
				#$result["content"],執行完指令的結果.
-
 
3377
				#必填參數:
-
 
3378
				#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3379
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3380
				#$conf["command"],字串,要執行的指令名稱.
-
 
3381
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="chown";
-
 
3382
				#可省略參數:
-
 
3383
				#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3384
				#$conf["sock"]=qbpwcf_usock_path;
-
 
3385
				#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3386
				$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array($sshAgentAcct.":".$sshAgentAcct,$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName);
-
 
3387
				#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3388
				#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3389
				#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3390
				#$conf["commandInBg"]="false";
-
 
3391
				#參考資料:
-
 
3392
				#無.
-
 
3393
				#備註:
-
 
3394
				#無.
-
 
3395
				$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3396
				unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3397
				
-
 
3398
				#如果執行shell失敗
-
 
3399
				if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3400
					
-
 
3401
					#設置執行不正常
-
 
3402
					$result["status"]="false";
-
 
3403
					
-
 
3404
					#設置執行錯誤
-
 
3405
					$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3406
					
-
 
3407
					#回傳結果
-
 
3408
					return $result;
-
 
3409
					
-
 
3410
					}#if end
-
 
3411
			
-
 
3412
				}#if end
-
 
3413
			
-
 
3414
			#嘗試進行連線,並確認是否成功
-
 
3415
			#函式說明:
-
 
3416
			#連線到 usr/bin/qbpwcf-usock.php 產生的  unix domain socket,運行指定的指令.
-
 
3417
			#回傳結果:
-
 
3418
			#$result["status"],"true"代表執行正常;"false"代表執行不正常.
-
 
3419
			#$result["error"],錯誤訊息陣列.
-
 
3420
			#$result["function"],當前執行的函式名稱.
-
 
3421
			#$result["argu"],使用的參數.
-
 
3422
			#$result["content"],執行完指令的結果.
-
 
3423
			#必填參數:
-
 
3424
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
3425
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["fileArgu"]=__FILE__;
-
 
3426
			#$conf["command"],字串,要執行的指令名稱.
-
 
3427
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["command"]="echo";
-
 
3428
			#可省略參數:
-
 
3429
			#$conf["sock"],字串,要連線的 usr/bin/qbpwcf-sock.php(sock::unixDomainSockServer) 所產生的 unix domain socket 路徑與名稱,預設為 qbpwcf_usock_path.
-
 
3430
			#$conf["sock"]=qbpwcf_usock_path;
-
 
3431
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3432
			$conf["sock::execAnyCmdByQBPWCFunixSocket"]["argu"]=array("env","|","ssh",$sshAgentAcct."@"."127.0.0.1","-i",$dotsshFolderOfsshAgent."/".$sshPrivateKeyFileName,"|","grep","SSH_CLIENT=127.0.0.1","|","wc","-l");
-
 
3433
			#$conf["commandIncludeArgu"],字串,是否command含有參數,預設為"false"代表沒有;反之為"true".
-
 
3434
			#$conf["sock::execAnyCmdByQBPWCFunixSocket"]["commandIncludeArgu"]="true";
-
 
3435
			#$conf["commandInBg"],字串,是否要將程序放在背景執行,再取得相關資訊,預設為"false"代表不要;反之為"true".
-
 
3436
			#$conf["commandInBg"]="false";
-
 
3437
			#參考資料:
-
 
3438
			#無.
-
 
3439
			#備註:
-
 
3440
			#無.
-
 
3441
			$createDotsshFolderOfsshAgent=sock::execAnyCmdByQBPWCFunixSocket($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3442
			unset($conf["sock::execAnyCmdByQBPWCFunixSocket"]);
-
 
3443
			
-
 
3444
			#如果執行shell失敗
-
 
3445
			if($createDotsshFolderOfsshAgent["status"]==="false"){
-
 
3446
				
-
 
3447
				#設置執行不正常
-
 
3448
				$result["status"]="false";
-
 
3449
				
-
 
3450
				#設置執行錯誤
-
 
3451
				$result["error"]=$createDotsshFolderOfsshAgent;
-
 
3452
				
-
 
3453
				#回傳結果
-
 
3454
				return $result;
-
 
3455
				
-
 
3456
				}#if end
2727
		
3457
		
2728
		#反之如果是
3458
			#若得到的輸出未含有ssh登入的資訊(SSH_CLIENT=127.0.0.1 ...)
2729
		else if($callShell["output"][1]="Password: su: Authentication failure"){
3459
			if($createDotsshFolderOfsshAgent["content"]!=="1"){
2730
			
3460
			
2731
			#代表使用者密碼不正確
3461
				#設置執行正常
2732
			$result["status"]="true";
3462
				$result["status"]="true";
-
 
3463
				
-
 
3464
				#設置使用者驗證失敗
-
 
3465
				$result["valid"]="false";
-
 
3466
				
-
 
3467
				#設置使用者不存在的警告
-
 
3468
				$result["warning"][]="使用者 \"".$conf["username"]."\"可能不存在或無法被ssh登入!";
-
 
3469
				
-
 
3470
				#回傳結果
-
 
3471
				return $result;
2733
			
3472
			
2734
			#設置使用者驗證失敗
-
 
2735
			$result["valid"]="false";
3473
				}#if end
2736
			
3474
			
-
 
3475
			#設置執行正常
-
 
3476
			$result["status"]="true";
-
 
3477
			
2737
			#設置使用者不存在的警告
3478
			#設置使用者驗證正常
2738
			$result["warning"][]="使用者 \"".$conf["username"]."\" 的密碼不為 \"".$conf["password"]."\" !";
3479
			$result["valid"]="true";
2739
			
3480
			
2740
			#回傳結果
3481
			#回傳結果
2741
			return $result;
3482
			return $result;
2742
			
3483
		
2743
			}#if end
3484
			}#if end
2744
			
3485
			
2745
		#反之
3486
		#反之
2746
		else{				
3487
		else{
2747
			
3488
			
-
 
3489
			#可以用 echo 'password' | su username -c 'echo valid' 來檢查使用者密碼是否正確
-
 
3490
			#檢查使用者是否存在
-
 
3491
			#函式說明:
-
 
3492
			#呼叫shell執行系統命令,並取得回傳的內容.
-
 
3493
			#回傳的結果:
-
 
3494
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
3495
			#$result["error"],錯誤訊息陣列.
-
 
3496
			#$result["function"],當前執行的函數名稱.
-
 
3497
			#$result["cmd"],執行的指令內容.
-
 
3498
			#$result["output"],爲執行完二元碼後的輸出陣列.
-
 
3499
			#必填的參數
-
 
3500
			#$conf["command"],字串,要執行的指令與.
-
 
3501
			$conf["external::callShell"]["command"]="echo";
2748
			#設置執行不正常
3502
			#可省略參數:
-
 
3503
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
3504
			$conf["external::callShell"]["argu"]=array($conf["password"],"|","su",$conf["username"],"-c","echo valid");
-
 
3505
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
3506
			#$conf["enablePrintDescription"]="true";
-
 
3507
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
-
 
3508
			#$conf["printDescription"]="";
-
 
3509
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2749
			$result["status"]="false";
3510
			#$conf["escapeshellarg"]="false";
-
 
3511
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行apache的使用者.
-
 
3512
			#$conf["external::callShell"]["username"]="";
-
 
3513
			#$conf["password"],字串,與$conf["username"]搭配的使用者密碼,預設不使用密碼.
-
 
3514
			#$conf["external::callShell"]["password"]="";
-
 
3515
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要;"false"代表不要,預設為"false".
-
 
3516
			$conf["external::callShell"]["useScript"]="true";
-
 
3517
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 ".qbpwcf_tmp/external/callShell/".
-
 
3518
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
3519
			#$conf["fileArgu"],字串,變數__FILE__的內容,預設為當前檔案的路徑與名稱.
-
 
3520
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
3521
			#備註:
-
 
3522
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.使用root身份可能會被selinux阻擋.
-
 
3523
			#參考資料:
-
 
3524
			#exec=>http://php.net/manual/en/function.exec.php
-
 
3525
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
3526
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
3527
			$callShell=external::callShell($conf["external::callShell"]);
-
 
3528
			unset($conf["external::callShell"]);
2750
			
3529
			
-
 
3530
			#如果執行shell失敗
-
 
3531
			if($callShell["status"]==="false"){
-
 
3532
				
-
 
3533
				#設置執行不正常
-
 
3534
				$result["status"]="false";
-
 
3535
				
2751
			#設置錯誤訊息
3536
				#設置執行錯誤
2752
			$result["error"]=$callShell;
3537
				$result["error"]=$callShell;
-
 
3538
				
-
 
3539
				#回傳結果
-
 
3540
				return $result;
-
 
3541
				
-
 
3542
				}#if end
-
 
3543
				
-
 
3544
			#範例輸出:
2753
			$result["error"][]="非預期的輸出結果!";				
3545
			#Script started on Sat 05 Nov 2016 06:08:31 PM CST
-
 
3546
			#Password: valid
2754
			
3547
			
-
 
3548
			#如果輸出 "valid"
-
 
3549
			if($callShell["output"][1]=="Password: valid"){
-
 
3550
				
-
 
3551
				#代表使用者密碼正確
-
 
3552
				
-
 
3553
				#設置執行正常
-
 
3554
				$result["status"]="true";
-
 
3555
				
-
 
3556
				#設置使用者驗證失敗
-
 
3557
				$result["valid"]="true";
-
 
3558
				
2755
			#回傳結果
3559
				#回傳結果
2756
			return $result;
3560
				return $result;
-
 
3561
				
-
 
3562
				}#if end
2757
			
3563
			
-
 
3564
			#反之如果是
-
 
3565
			else if($callShell["output"][1]==="Password: su: Authentication failure"){
-
 
3566
				
-
 
3567
				#代表使用者密碼不正確
-
 
3568
				$result["status"]="true";
-
 
3569
				
-
 
3570
				#設置使用者驗證失敗
-
 
3571
				$result["valid"]="false";
-
 
3572
				
-
 
3573
				#設置使用者不存在的警告
-
 
3574
				$result["warning"][]="使用者 \"".$conf["username"]."\" 的密碼不為 \"".$conf["password"]."\" !";
-
 
3575
				
-
 
3576
				#回傳結果
-
 
3577
				return $result;
-
 
3578
				
-
 
3579
				}#if end
-
 
3580
				
-
 
3581
			#反之
-
 
3582
			else{
-
 
3583
				
-
 
3584
				#設置執行不正常
-
 
3585
				$result["status"]="false";
-
 
3586
				
-
 
3587
				#設置錯誤訊息
-
 
3588
				$result["error"][]="非預期的輸出結果!";
-
 
3589
				
-
 
3590
				#設置錯誤訊息
-
 
3591
				$result["error"][]=$callShell;
-
 
3592
				
-
 
3593
				#回傳結果
-
 
3594
				return $result;
-
 
3595
				
-
 
3596
				}#else end
-
 
3597
		
2758
			}#else end
3598
			}#else end
2759
			
3599
			
2760
		#設置執行不正常
3600
		#設置執行不正常
2761
		$result["status"]="false";
3601
		$result["status"]="false";
2762
		
3602
		
2763
		#設置錯誤訊息
3603
		#設置錯誤訊息
2764
		$result["error"][]="非預期的結果!";				
3604
		$result["error"][]="非預期的結果!";
2765
		
3605
		
2766
		#回傳結果
3606
		#回傳結果
2767
		return $result;
3607
		return $result;
2768
		
3608
		
2769
		}#function validUser end
3609
		}#function validUser end
Line 3090... Line 3930...
3090
		#回傳結果
3930
		#回傳結果
3091
		return $result;
3931
		return $result;
3092
		
3932
		
3093
		}#function validPassword end
3933
		}#function validPassword end
3094
 
3934
 
-
 
3935
	/*
-
 
3936
	#函式說明:
-
 
3937
	#id指令來取得目標賬號的群組資訊
-
 
3938
	#回傳結果:
-
 
3939
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
3940
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
3941
	#$result["function"],當前執行的函式名稱.
-
 
3942
	#$result["content"],呼叫完WebService所得回傳結果.
-
 
3943
	#$result["content"]["groupId"],群組的id.
-
 
3944
	#$result["content"]["belongGroupName"],陣列,隸屬的群組名稱陣列.
-
 
3945
	#$result["content"]["belongGroupId"],陣列,隸屬的群組id.
-
 
3946
	#必填參數:
-
 
3947
	#$conf["user"],字串,要取得群組資訊的目標使用者名稱.
-
 
3948
	$conf["user"]="";
-
 
3949
	#可省略參數:
-
 
3950
	#無.
-
 
3951
	#參考資料:
-
 
3952
	#無.
-
 
3953
	#備註:
-
 
3954
	#無.
-
 
3955
	*/
-
 
3956
	public static function getUserGroup(&$conf){
-
 
3957
	
-
 
3958
		#初始化要回傳的結果
-
 
3959
		$result=array();
-
 
3960
 
-
 
3961
		#取得當前執行的函數名稱
-
 
3962
		$result["function"]=__FUNCTION__;
-
 
3963
 
-
 
3964
		#如果沒有參數
-
 
3965
		if(func_num_args()==0){
-
 
3966
			
-
 
3967
			#設置執行失敗
-
 
3968
			$result["status"]="false";
-
 
3969
			
-
 
3970
			#設置執行錯誤訊息
-
 
3971
			$result["error"]="函數".$result["function"]."需要參數";
-
 
3972
			
-
 
3973
			#回傳結果
-
 
3974
			return $result;
-
 
3975
			
-
 
3976
			}#if end
-
 
3977
		
-
 
3978
		#取得參數
-
 
3979
		$result["argu"]=$conf;
-
 
3980
 
-
 
3981
		#如果 $conf 不為陣列
-
 
3982
		if(gettype($conf)!=="array"){
-
 
3983
			
-
 
3984
			#設置執行失敗
-
 
3985
			$result["status"]="false";
-
 
3986
			
-
 
3987
			#設置執行錯誤訊息
-
 
3988
			$result["error"][]="\$conf變數須為陣列形態";
-
 
3989
			
-
 
3990
			#如果傳入的參數為 null
-
 
3991
			if($conf===null){
-
 
3992
				
-
 
3993
				#設置執行錯誤訊息
-
 
3994
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
3995
				
-
 
3996
				}#if end
-
 
3997
 
-
 
3998
			#回傳結果
-
 
3999
			return $result;
-
 
4000
			
-
 
4001
			}#if end
-
 
4002
		
-
 
4003
		#函式說明:
-
 
4004
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
-
 
4005
		#回傳結果:
-
 
4006
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4007
		#$result["error"],執行不正常結束的錯訊息陣列.
-
 
4008
		#$result["simpleError"],簡單表示的錯誤訊息.
-
 
4009
		#$result["function"],當前執行的函式名稱.
-
 
4010
		#$result["argu"],設置給予的參數.
-
 
4011
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
4012
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
4013
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
4014
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
4015
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
4016
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
4017
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
4018
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
4019
		#必填參數:
-
 
4020
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
4021
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
4022
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
4023
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
4024
		#可省略參數:
-
 
4025
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
4026
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("user");
-
 
4027
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
-
 
4028
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
-
 
4029
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
4030
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
4031
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
-
 
4032
		#$conf["canNotBeEmpty"]=array();
-
 
4033
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
-
 
4034
		#$conf["canBeEmpty"]=array();
-
 
4035
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
-
 
4036
		#$conf["skipableVariableCanNotBeEmpty"]=array();
-
 
4037
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
4038
		#$conf["skipableVariableName"]=array();
-
 
4039
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
4040
		#$conf["skipableVariableType"]=array();
-
 
4041
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
4042
		#$conf["skipableVarDefaultValue"]=array("");
-
 
4043
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
-
 
4044
		#$conf["disallowAllSkipableVarIsEmpty"]="";
-
 
4045
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
-
 
4046
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
-
 
4047
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
-
 
4048
		#$conf["disallowAllSkipableVarNotExist"]="";
-
 
4049
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
4050
		#$conf["arrayCountEqualCheck"][]=array();
-
 
4051
		#參考資料:
-
 
4052
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
4053
		#備註:
-
 
4054
		#無.
-
 
4055
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
4056
		unset($conf["variableCheck::checkArguments"]);
-
 
4057
		
-
 
4058
		#如果驗證失敗
-
 
4059
		if($checkArguments["status"]==="false"){
-
 
4060
			
-
 
4061
			#設置執行失敗
-
 
4062
			$result["status"]="false";
-
 
4063
			
-
 
4064
			#設置錯誤訊息
-
 
4065
			$result["error"]=$checkArguments;
-
 
4066
			
-
 
4067
			#回傳結果
-
 
4068
			return $result;
-
 
4069
			
-
 
4070
			}#if end
-
 
4071
			
-
 
4072
		#如果驗證不成功
-
 
4073
		if($checkArguments["passed"]==="false"){
-
 
4074
			
-
 
4075
			#設置執行失敗
-
 
4076
			$result["status"]="false";
-
 
4077
			
-
 
4078
			#設置錯誤訊息
-
 
4079
			$result["error"]=$checkArguments;
-
 
4080
			
-
 
4081
			#回傳結果
-
 
4082
			return $result;
-
 
4083
			
-
 
4084
			}#if end
-
 
4085
	
-
 
4086
		#函式說明:
-
 
4087
		#呼叫shell執行系統命令,並取得回傳的內容.
-
 
4088
		#回傳結果:
-
 
4089
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4090
		#$result["error"],錯誤訊息陣列.
-
 
4091
		#$result["function"],當前執行的函數名稱.
-
 
4092
		#$result["argu"],使用的參數.
-
 
4093
		#$result["cmd"],執行的指令內容.
-
 
4094
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
4095
		#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
4096
		#$result["content"],為執行完後的輸出字串.
-
 
4097
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
4098
		#$result["running"],是否還在執行.
-
 
4099
		#$result["pid"],pid.
-
 
4100
		#$result["statusCode"],執行結束後的代碼.
-
 
4101
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
4102
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
4103
		#必填參數:
-
 
4104
		#$conf["command"],字串,要執行的指令.
-
 
4105
		$conf["external::callShell"]["command"]="id";
-
 
4106
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
4107
		$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
4108
		#可省略參數:
-
 
4109
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
4110
		$conf["external::callShell"]["argu"]=array($user);
-
 
4111
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
4112
		#$conf["arguIsAddr"]=array();
-
 
4113
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
4114
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
4115
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
4116
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
4117
		#$conf["enablePrintDescription"]="true";
-
 
4118
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
4119
		#$conf["printDescription"]="";
-
 
4120
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
4121
		$conf["external::callShell"]["escapeshellarg"]="true";
-
 
4122
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
4123
		#$conf["thereIsShellVar"]=array();
-
 
4124
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
4125
		#$conf["username"]="";
-
 
4126
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
4127
		#$conf["password"]="";
-
 
4128
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
4129
		#$conf["useScript"]="";
-
 
4130
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
4131
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
4132
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
4133
		#$conf["inBackGround"]="";
-
 
4134
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
4135
		#$conf["getErr"]="false";
-
 
4136
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
4137
		#$conf["doNotRun"]="false";
-
 
4138
		#參考資料:
-
 
4139
		#exec=>http://php.net/manual/en/function.exec.php
-
 
4140
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
4141
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
4142
		#備註:
-
 
4143
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
4144
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
4145
		$callShell=external::callShell($conf["external::callShell"]);
-
 
4146
		unset($conf["external::callShell"]);
-
 
4147
	
-
 
4148
		#如果執行異常
-
 
4149
		if($callShell["status"]==="false"){
-
 
4150
		
-
 
4151
			#設置執行失敗
-
 
4152
			$result["status"]="false";
-
 
4153
			
-
 
4154
			#設置錯誤訊息
-
 
4155
			$result["error"]=$callShell;
-
 
4156
			
-
 
4157
			#回傳結果
-
 
4158
			return $result;
-
 
4159
		
-
 
4160
			}#if end
-
 
4161
			
-
 
4162
		#若輸出不對
-
 
4163
		if(count($callShell["content"])===0){
-
 
4164
		
-
 
4165
			#設置執行失敗
-
 
4166
			$result["status"]="false";
-
 
4167
			
-
 
4168
			#設置錯誤訊息
-
 
4169
			$result["error"]=$callShell;
-
 
4170
			
-
 
4171
			#回傳結果
-
 
4172
			return $result;
-
 
4173
		
-
 
4174
			}#if end
-
 
4175
			
-
 
4176
		#解析輸出資訊
-
 
4177
		#範例輸出:
-
 
4178
		#uid=1000(liveuser) gid=1000(liveuser) groups=1000(liveuser),10(wheel),1002(web)
-
 
4179
		
-
 
4180
		#函式說明:
-
 
4181
		#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
-
 
4182
		#回傳結果:
-
 
4183
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4184
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
4185
		#$result["function"],當前執行的函式名稱.
-
 
4186
		#$result["argu"],所使用的參數.
-
 
4187
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
-
 
4188
		#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
4189
		#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
4190
		#必填參數:
-
 
4191
		#$conf["input"],字串,要檢查的字串.
-
 
4192
		$conf["search::findSpecifyStrFormat"]["input"]=$callShell["content"][0];
-
 
4193
		#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
4194
		$conf["search::findSpecifyStrFormat"]["format"]="uid=\${userId}(\${userName}) gid=\${groupId}(\${groupName}) groups=\${repeatedGroupId}(\${repeatedGroupName})\${otherGroupStr}";
-
 
4195
		#可省略參數:
-
 
4196
		#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
-
 
4197
		#$conf["varEqual"]=array(null,"found");
-
 
4198
		#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
-
 
4199
		#$conf["varCon"]=array("no_tail"=>" not");
-
 
4200
		#參考資料:
-
 
4201
		#無.
-
 
4202
		#備註:
-
 
4203
		#無.
-
 
4204
		$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
4205
		unset($conf["search::findSpecifyStrFormat"]);
-
 
4206
	
-
 
4207
		#如果執行異常
-
 
4208
		if($findSpecifyStrFormat["status"]==="false"){
-
 
4209
		
-
 
4210
			#設置執行失敗
-
 
4211
			$result["status"]="false";
-
 
4212
			
-
 
4213
			#設置錯誤訊息
-
 
4214
			$result["error"]=$findSpecifyStrFormat;
-
 
4215
			
-
 
4216
			#回傳結果
-
 
4217
			return $result;
-
 
4218
		
-
 
4219
			}#if end
-
 
4220
			
-
 
4221
		#如果沒有符合格式的內容
-
 
4222
		if($findSpecifyStrFormat["found"]==="false"){
-
 
4223
		
-
 
4224
			#設置執行失敗
-
 
4225
			$result["status"]="false";
-
 
4226
			
-
 
4227
			#設置錯誤訊息
-
 
4228
			$result["error"]=$findSpecifyStrFormat;
-
 
4229
			
-
 
4230
			#回傳結果
-
 
4231
			return $result;
-
 
4232
		
-
 
4233
			}#if end
-
 
4234
			
-
 
4235
		#另存使用者id
-
 
4236
		$userId=$findSpecifyStrFormat["parsedVar"]["userId"][0];
-
 
4237
		
-
 
4238
		#另存群組的id
-
 
4239
		$groupId=$findSpecifyStrFormat["parsedVar"]["groupId"][0];
-
 
4240
		
-
 
4241
		#另存隸屬其他群組的資訊
-
 
4242
		$othergGroupStr=$findSpecifyStrFormat["parsedVar"]["othergGroupStr"][0];
-
 
4243
		
-
 
4244
		#如果有其他群組資訊
-
 
4245
		if(!empty($othergGroupStr)){
-
 
4246
		
-
 
4247
			#用逗號切割結果出來
-
 
4248
			#函式說明:
-
 
4249
			#將固定格式的字串分開,並回傳分開的結果.
-
 
4250
			#回傳結果:
-
 
4251
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4252
			#$result["error"],錯誤訊息陣列
-
 
4253
			#$result["function"],當前執行的函數名稱.
-
 
4254
			#$result["argu"],使用的參數.
-
 
4255
			#$result["oriStr"],要分割的原始字串內容
-
 
4256
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
-
 
4257
			#$result["dataCounts"],爲總共分成幾段
-
 
4258
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
-
 
4259
			#必填參數:
-
 
4260
			#$conf["stringIn"],字串,要處理的字串.
-
 
4261
			$conf["stringProcess::spiltString"]["stringIn"]=$othergGroupStr;
-
 
4262
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
-
 
4263
			$conf["stringProcess::spiltString"]["spiltSymbol"]=",";
-
 
4264
			#可省略參數:
-
 
4265
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
-
 
4266
			#$conf["allowEmptyStr"]="false";
-
 
4267
			#參考資料:
-
 
4268
			#無.
-
 
4269
			#備註:
-
 
4270
			#無.
-
 
4271
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
-
 
4272
			unset($conf["stringProcess::spiltString"]);
-
 
4273
		
-
 
4274
			#如果執行異常
-
 
4275
			if($spiltString["status"]==="false"){
-
 
4276
			
-
 
4277
				#設置執行失敗
-
 
4278
				$result["status"]="false";
-
 
4279
				
-
 
4280
				#設置錯誤訊息
-
 
4281
				$result["error"]=$spiltString;
-
 
4282
				
-
 
4283
				#回傳結果
-
 
4284
				return $result;
-
 
4285
			
-
 
4286
				}#if end
-
 
4287
				
-
 
4288
			#如果沒有符合格式的內容
-
 
4289
			if($spiltString["found"]==="false"){
-
 
4290
			
-
 
4291
				#設置執行失敗
-
 
4292
				$result["status"]="false";
-
 
4293
				
-
 
4294
				#設置錯誤訊息
-
 
4295
				$result["error"]=$spiltString;
-
 
4296
				
-
 
4297
				#回傳結果
-
 
4298
				return $result;
-
 
4299
			
-
 
4300
				}#if end
-
 
4301
				
-
 
4302
			#依照分隔成的段數
-
 
4303
			foreach($spiltString["dataArray"] as $oginfo){
-
 
4304
			
-
 
4305
				#解析groudId跟groupName
-
 
4306
				
-
 
4307
				#範例輸出:
-
 
4308
				#10(wheel)
-
 
4309
				
-
 
4310
				#函式說明:
-
 
4311
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
-
 
4312
				#回傳結果:
-
 
4313
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
4314
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
4315
				#$result["function"],當前執行的函式名稱.
-
 
4316
				#$result["argu"],所使用的參數.
-
 
4317
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
-
 
4318
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
-
 
4319
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
-
 
4320
				#必填參數:
-
 
4321
				#$conf["input"],字串,要檢查的字串.
-
 
4322
				$conf["search::findSpecifyStrFormat"]["input"]=$oginfo;
-
 
4323
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
-
 
4324
				$conf["search::findSpecifyStrFormat"]["format"]="gid=\${groupId}(\${groupName})";
-
 
4325
				#可省略參數:
-
 
4326
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
-
 
4327
				#$conf["varEqual"]=array(null,"found");
-
 
4328
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
-
 
4329
				#$conf["varCon"]=array("no_tail"=>" not");
-
 
4330
				#參考資料:
-
 
4331
				#無.
-
 
4332
				#備註:
-
 
4333
				#無.
-
 
4334
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
-
 
4335
				unset($conf["search::findSpecifyStrFormat"]);
-
 
4336
			
-
 
4337
				#如果執行異常
-
 
4338
				if($findSpecifyStrFormat["status"]==="false"){
-
 
4339
				
-
 
4340
					#設置執行失敗
-
 
4341
					$result["status"]="false";
-
 
4342
					
-
 
4343
					#設置錯誤訊息
-
 
4344
					$result["error"]=$findSpecifyStrFormat;
-
 
4345
					
-
 
4346
					#回傳結果
-
 
4347
					return $result;
-
 
4348
				
-
 
4349
					}#if end
-
 
4350
					
-
 
4351
				#如果格式異常
-
 
4352
				if($findSpecifyStrFormat["found"]==="false"){
-
 
4353
				
-
 
4354
					#設置執行失敗
-
 
4355
					$result["status"]="false";
-
 
4356
					
-
 
4357
					#設置錯誤訊息
-
 
4358
					$result["error"]=$findSpecifyStrFormat;
-
 
4359
					
-
 
4360
					#回傳結果
-
 
4361
					return $result;
-
 
4362
				
-
 
4363
					}#if end
-
 
4364
					
-
 
4365
				#如果是 user 自己的群組
-
 
4366
				if($findSpecifyStrFormat["parsedVar"]["groupName"][0]===$user){
-
 
4367
				
-
 
4368
					#跳過該群組資訊
-
 
4369
					continue;
-
 
4370
				
-
 
4371
					}#if end	
-
 
4372
					
-
 
4373
				#儲存其他 group id
-
 
4374
				$otherGroupId[]=$findSpecifyStrFormat["parsedVar"]["groupId"][0];
-
 
4375
			
-
 
4376
				#儲存其他 group name
-
 
4377
				$otherGroupName[]=$findSpecifyStrFormat["parsedVar"]["groupName"][0];
-
 
4378
			
-
 
4379
				}#foreach end
-
 
4380
		
-
 
4381
			}#if end
-
 
4382
			
-
 
4383
		#設置 group id 結果
-
 
4384
		$result["content"]["groupId"]=$groupId;
-
 
4385
		
-
 
4386
		#設置隸屬的 group 名稱
-
 
4387
		$result["content"]["belongGroupName"]=$otherGroupName;
-
 
4388
	
-
 
4389
		#設置隸屬的 group id
-
 
4390
		$result["content"]["belongGroupId"]=$otherGroupId;
-
 
4391
		
-
 
4392
		#設置執行正常
-
 
4393
		$result["status"]="true";
-
 
4394
		
-
 
4395
		#回傳結果 
-
 
4396
		return $result;
-
 
4397
	
-
 
4398
		}#function getUserGroup end 
-
 
4399
 
3095
	}#class authenticate end
4400
	}#class authenticate end
3096
	
4401
	
3097
?>
4402
?>