Subversion Repositories php-qbpwcf

Rev

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

Rev 146 Rev 148
Line 27454... Line 27454...
27454
	#必填參數:
27454
	#必填參數:
27455
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
27455
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
27456
	$conf["fileArgu"]=__FILE__;
27456
	$conf["fileArgu"]=__FILE__;
27457
	#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".
27457
	#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".
27458
	$conf["name"]="";
27458
	$conf["name"]="";
27459
	#$conf["cmd"],字串,要執行的指令.
27459
	#$conf["cmds"],字串陣列,每個要執行的程式.
27460
	$conf["cmd"]="";
27460
	$conf["cmds"]=array();
27461
	#可省略參數:
27461
	#可省略參數:
27462
	#$conf["params"],字串陣列,指令要使用的參數.
27462
	#$conf["params"],字串陣列,每個程式使用的參數.
27463
	#$conf["params"]=array("");
27463
	#$conf["params"]=array();
27464
	#$conf["enable"],字串,預設為"true",代表該服務為enable.
27464
	#$conf["enable"],字串,預設為"true",代表該服務為enable.
27465
	#$conf["enable"]="true";
27465
	#$conf["enable"]="true";
27466
	#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.
27466
	#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.
27467
	#$conf["startNow"]="true";
27467
	#$conf["startNow"]="true";
27468
	#$conf["keepServiceUp"],字串,是否要另外增加確保服務有保持啟動的服務,預設為"false"代表否;反之為"true"代表是.
27468
	#$conf["keepServiceUp"],字串,是否要另外增加確保服務有保持啟動的服務,預設為"false"代表否;反之為"true"代表是.
Line 27528... Line 27528...
27528
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
27528
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
27529
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
27529
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
27530
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
27530
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
27531
		#可以省略的參數:
27531
		#可以省略的參數:
27532
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
27532
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
27533
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name","cmd");
27533
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","name","cmds");
27534
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
27534
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
27535
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
27535
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","array");
27536
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
27536
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
27537
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
27537
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
27538
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
27538
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
27539
		#$conf["canNotBeEmpty"]=array();
27539
		#$conf["canNotBeEmpty"]=array();
27540
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
27540
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
Line 27611... Line 27611...
27611
		$serviceFileContent[]="Type=simple";
27611
		$serviceFileContent[]="Type=simple";
27612
		
27612
		
27613
		#用root身份執行
27613
		#用root身份執行
27614
		$serviceFileContent[]="User=root";
27614
		$serviceFileContent[]="User=root";
27615
		
27615
		
-
 
27616
		#指定要用/bin/bash來執行腳本
-
 
27617
		$fullCmd="#!/bin/bash";
-
 
27618
		
-
 
27619
		#針對每的程式
-
 
27620
		foreach($conf["cmds"] as $index => $bin){
-
 
27621
		
-
 
27622
			#函式說明:
-
 
27623
			#呼叫shell執行系統命令,並取得回傳的內容.
-
 
27624
			#回傳結果:
-
 
27625
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
27626
			#$result["error"],錯誤訊息陣列.
-
 
27627
			#$result["function"],當前執行的函數名稱.
-
 
27628
			#$result["argu"],使用的參數.
-
 
27629
			#$result["cmd"],執行的指令內容.
-
 
27630
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
27631
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
27632
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
27633
			#$result["running"],是否還在執行.
-
 
27634
			#$result["pid"],pid.
-
 
27635
			#$result["statusCode"],執行結束後的代碼.
-
 
27636
			#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
27637
			#必填參數:
-
 
27638
			#$conf["command"],字串,要執行的指令.
-
 
27639
			$conf["external::callShell"]["command"]=$bin;
-
 
27640
			#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
27641
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
-
 
27642
			#可省略參數:
-
 
27643
			
-
 
27644
			#如果有指定參數
-
 
27645
			if(isset($conf["params"])){
-
 
27646
			
-
 
27647
				#如果該程式有對應的參數陣列
-
 
27648
				if(isset($conf["params"][$index])){
-
 
27649
				
-
 
27650
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
27651
					$conf["external::callShell"]["argu"]=$conf["params"][$index];
-
 
27652
				
-
 
27653
					}#if end
-
 
27654
				
-
 
27655
				}#if end
-
 
27656
			
-
 
27657
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
27658
			#$conf["arguIsAddr"]=array();
-
 
27659
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
27660
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
27661
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
27662
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
27663
			#$conf["enablePrintDescription"]="true";
-
 
27664
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
27665
			#$conf["printDescription"]="";
-
 
27666
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
27667
			$conf["external::callShell"]["escapeshellarg"]="true";
-
 
27668
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
27669
			#$conf["thereIsShellVar"]=array();
-
 
27670
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
27671
			#$conf["username"]="";
-
 
27672
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
27673
			#$conf["password"]="";
-
 
27674
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
27675
			#$conf["useScript"]="";
-
 
27676
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
27677
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
27678
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
27679
			#$conf["inBackGround"]="";
-
 
27680
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
27681
			#$conf["getErr"]="false";
-
 
27682
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
27683
			$conf["external::callShell"]["doNotRun"]="true";
-
 
27684
			#參考資料:
-
 
27685
			#exec=>http://php.net/manual/en/function.exec.php
-
 
27686
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
27687
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
27688
			#備註:
-
 
27689
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
27690
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
27691
			$callShell=external::callShell($conf["external::callShell"]);
-
 
27692
			unset($conf["external::callShell"]);
-
 
27693
			
-
 
27694
			#如果檢查參數失敗
-
 
27695
			if($callShell["status"]==="false"){
-
 
27696
 
-
 
27697
				#設置執行失敗
-
 
27698
				$result["status"]="false";
-
 
27699
 
-
 
27700
				#設置錯誤訊息
-
 
27701
				$result["error"]=$callShell;
-
 
27702
 
-
 
27703
				#回傳結果
-
 
27704
				return $result;
-
 
27705
 
-
 
27706
				}#if end
-
 
27707
			
-
 
27708
			#組合完整指令字串
-
 
27709
			#函式說明:
-
 
27710
			#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
-
 
27711
			#回傳的結果:
-
 
27712
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
27713
			#$result["function"],當前執行的function名稱
-
 
27714
			#$result["error"],錯誤訊息陣列.
-
 
27715
			#$result["content"],處理好的字串.
-
 
27716
			#$result["argu"],使用的參數.
-
 
27717
			#必填參數:
-
 
27718
			#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
-
 
27719
			$conf["arrays::arrayToString"]["inputArray"]=$callShell["escape"]["array"];
-
 
27720
			#可省略參數:
-
 
27721
			#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
-
 
27722
			$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
-
 
27723
			#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
-
 
27724
			$conf["arrays::arrayToString"]["skipEnd"]="true";
-
 
27725
			#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
-
 
27726
			#$conf["spiltSymbolAtStart"]="";
-
 
27727
			#參考資料:
-
 
27728
			#無.
-
 
27729
			#備註:
-
 
27730
			#無.
-
 
27731
			$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
-
 
27732
			unset($conf["arrays::arrayToString"]);
-
 
27733
			
-
 
27734
			#如果轉換成字串失敗
-
 
27735
			if($arrayToString["status"]==="false"){
-
 
27736
 
-
 
27737
				#設置執行失敗
-
 
27738
				$result["status"]="false";
-
 
27739
 
-
 
27740
				#設置錯誤訊息
-
 
27741
				$result["error"]=$arrayToString;
-
 
27742
 
-
 
27743
				#回傳結果
-
 
27744
				return $result;
-
 
27745
 
-
 
27746
				}#if end
-
 
27747
			
-
 
27748
			#串接指令
-
 
27749
			$fullCmd=$fullCmd.PHP_EOL.$arrayToString["content"];
-
 
27750
		
-
 
27751
			}#foreach end
-
 
27752
		
-
 
27753
		#path of bin for systemctl 
-
 
27754
		$pathOfBinForSystemctl="/var/qbpwcf/bin_for_systemctl/";
-
 
27755
 
-
 
27756
		#bin of service path
-
 
27757
		$binOfServicePath=$pathOfBinForSystemctl.$conf["name"].".sh";
-
 
27758
		
-
 
27759
		#建立啟動該服務的腳本
27616
		#函式說明:
27760
		#函式說明:
27617
		#呼叫shell執行系統命令,並取得回傳的內容.
27761
		#將字串寫入到檔案
27618
		#回傳結果:
27762
		#回傳結果:
27619
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27763
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
27620
		#$result["error"],錯誤訊息陣列.
27764
		#$result["error"],錯誤訊息陣列.
27621
		#$result["function"],當前執行的函數名稱.
27765
		#$result["function"],當前執行的函數名稱.
-
 
27766
		#$result["fileInfo"],實際上寫入的檔案資訊陣列.
-
 
27767
		#$result["fileInfo"]["createdFileName"],建立好的檔案名稱.
-
 
27768
		#$result["fileInfo"]["createdFilePath"],檔案建立的路徑.
-
 
27769
		#$result["fileInfo"]["createdFilePathAndName"].建立好的檔案名稱與路徑.
27622
		#$result["argu"],使用的參數.
27770
		#$result["argu"],使用的參數.
27623
		#$result["cmd"],執行的指令內容.
-
 
27624
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
27625
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
27626
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
27627
		#$result["running"],是否還在執行.
-
 
27628
		#$result["pid"],pid.
-
 
27629
		#$result["statusCode"],執行結束後的代碼.
-
 
27630
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
27631
		#必填參數:
27771
		#必填參數:
27632
		#$conf["command"],字串,要執行的指令.
-
 
27633
		$conf["external::callShell"]["command"]=$conf["cmd"];
-
 
27634
		#$conf["fileArgu"],字串,變數__FILE__的內容.
27772
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
27635
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
27773
		$conf["fileAccess::writeTextIntoFile"]["fileArgu"]=__FILE__;
27636
		#可省略參數:
27774
		#可省略參數:
27637
		
-
 
27638
		#如果有參數
-
 
27639
		if(isset($conf["params"])){
-
 
27640
		
-
 
27641
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
27775
		#$conf["fileName"],字串,爲要編輯的檔案名稱,預設為隨機產生的檔案名稱.
27642
			$conf["external::callShell"]["argu"]=$conf["params"];
27776
		$conf["fileAccess::writeTextIntoFile"]["fileName"]=$binOfServicePath;
27643
		
-
 
27644
			}#if end
-
 
27645
				
-
 
27646
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
27647
		#$conf["arguIsAddr"]=array();
-
 
27648
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
27649
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
27650
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
27651
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
27777
		#$conf["inputString"],字串,爲要寫入到裏面的內容,若要每筆資料寫入後換行,則可以在字串內容後面加上 \r\n 即可,預設為"".
27652
		#$conf["enablePrintDescription"]="true";
27778
		$conf["fileAccess::writeTextIntoFile"]["inputString"]=$fullCmd;
27653
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
27779
		#$conf["writeMethod"],字串,爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入.
27654
		#$conf["printDescription"]="";
27780
		#$conf["writeMethod"]="a";
27655
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
27656
		$conf["external::callShell"]["escapeshellarg"]="true";
-
 
27657
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
27658
		#$conf["thereIsShellVar"]=array();
-
 
27659
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
27781
		#$conf["checkRepeat"],字串,"true"代表建立檔案之前要先檢查檔案是否存在,若存在則在原名稱後面加上從(1)開始的編號.
27660
		#$conf["username"]="";
27782
		#$conf["checkRepeat"]="";
27661
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
27662
		#$conf["password"]="";
-
 
27663
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
27783
		#$conf["filenameExtensionStartPoint"],字串,檔案的副檔名是從倒數第幾個小數點(dot)開始,預設為"1",最後一個小數點,必須與$conf["checkRepeat"]搭配才會生效.
27664
		#$conf["useScript"]="";
27784
		#$conf["filenameExtensionStartPoint"]="";
27665
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
27785
		#$conf["repeatNameRule"],字串,遇到相同名稱的檔案要如何加上識別的編號,編號用「\$i」表示,預設為"(\$i)",必須與$conf["checkRepeat"]搭配才會生效.
27666
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
27667
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
27668
		#$conf["inBackGround"]="";
27786
		#$conf["repeatNameRule"]="";
27669
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
27670
		#$conf["getErr"]="false";
-
 
27671
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
27787
		#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
27672
		$conf["external::callShell"]["doNotRun"]="true";
27788
		$conf["fileAccess::writeTextIntoFile"]["web"]="false";
27673
		#參考資料:
27789
		#參考資料:
27674
		#exec=>http://php.net/manual/en/function.exec.php
27790
		#無.
27675
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
27676
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
27677
		#備註:
27791
		#備註:
27678
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
27679
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
-
 
27792
		#無.
27680
		$callShell=external::callShell($conf["external::callShell"]);
27793
		$writeTextIntoFile=fileAccess::writeTextIntoFile($conf["fileAccess::writeTextIntoFile"]);
27681
		unset($conf["external::callShell"]);
27794
		unset($conf["fileAccess::writeTextIntoFile"]);
27682
		
27795
		
27683
		#如果檢查參數失敗
27796
		#如果建立腳本檔案失敗
27684
		if($callShell["status"]==="false"){
27797
		if($writeTextIntoFile["status"]==="false"){
27685
 
27798
 
27686
			#設置執行失敗
27799
			#設置執行失敗
27687
			$result["status"]="false";
27800
			$result["status"]="false";
27688
 
27801
 
27689
			#設置錯誤訊息
27802
			#設置錯誤訊息
27690
			$result["error"]=$callShell;
27803
			$result["error"]=$writeTextIntoFile;
27691
 
27804
 
27692
			#回傳結果
27805
			#回傳結果
27693
			return $result;
27806
			return $result;
27694
 
27807
 
27695
			}#if end
27808
			}#if end
27696
		
27809
			
27697
		#組合完整指令字串
27810
		#設置該腳本可以被執行
27698
		#函式說明:
27811
		#函式說明:
27699
		#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
27812
		#使用 linux 的 chmod 指令來修改目標檔案或目錄的權限.
27700
		#回傳的結果:
27813
		#回傳結果:
27701
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27814
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
27702
		#$result["function"],當前執行的function名稱
-
 
27703
		#$result["error"],錯誤訊息陣列.
27815
		#$result["error"],錯誤訊息.
27704
		#$result["content"],處理好的字串.
27816
		#$result["function"],當前執行的函式名稱.
27705
		#$result["argu"],使用的參數.
27817
		#$result["cmd"],執行的指令.
27706
		#必填參數:
27818
		#必填參數:
-
 
27819
		#$conf["mode"],字串,要變成什麼權限.
-
 
27820
		$conf["cmd::chmod"]["mode"]="700";
27707
		#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
27821
		#$conf["target"],字串,需要變更權限的目標.
27708
		$conf["arrays::arrayToString"]["inputArray"]=$callShell["escape"]["array"];
27822
		$conf["cmd::chmod"]["target"]=$binOfServicePath;
27709
		#可省略參數:
27823
		#可省略參數:
27710
		#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
27824
		#$conf["recursive"],字串,"true"代表目標目錄底下的內容都要套用,預設為"false".
27711
		$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
-
 
27712
		#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
-
 
27713
		$conf["arrays::arrayToString"]["skipEnd"]="true";
27825
		#$conf["recursive"]="true";
27714
		#$conf["spiltSymbolAtStart"],字串,是否要在開頭加上spiltSymbol,預設為"false",代表不要;反之為“true”.
27826
		#$conf["excludeSelf"],字串,預設為"false"代表不處理;若為"true"則會排除目標自己(資料夾).
27715
		#$conf["spiltSymbolAtStart"]="";
27827
		#$conf["excludeSelf"]="true";
27716
		#參考資料:
27828
		#參考資料:
27717
		#無.
27829
		#無.
27718
		#備註:
27830
		#備註:
27719
		#無.
27831
		#無.
27720
		$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
27832
		$chmod=cmd::chmod($conf["cmd::chmod"]);
27721
		unset($conf["arrays::arrayToString"]);
27833
		unset($conf["cmd::chmod"]);
27722
		
27834
		
27723
		#如果轉換成字串失敗
27835
		#如果執行異常
27724
		if($arrayToString["status"]==="false"){
27836
		if($chmod["status"]==="false"){
27725
 
27837
 
27726
			#設置執行失敗
27838
			#設置執行失敗
27727
			$result["status"]="false";
27839
			$result["status"]="false";
27728
 
27840
 
27729
			#設置錯誤訊息
27841
			#設置錯誤訊息
27730
			$result["error"]=$arrayToString;
27842
			$result["error"]=$chmod;
27731
 
27843
 
27732
			#回傳結果
27844
			#回傳結果
27733
			return $result;
27845
			return $result;
27734
 
27846
 
27735
			}#if end
27847
			}#if end
27736
		
27848
		
27737
		#完整指令
-
 
27738
		$fullCmd=$arrayToString["content"];
-
 
27739
		
-
 
27740
		#要執行的程式與參數
27849
		#要執行的程式與參數
27741
		$serviceFileContent[]="ExecStart=".$fullCmd;
27850
		$serviceFileContent[]="ExecStart=".$binOfServicePath;
27742
		
27851
		
27743
		#重新執行的程式與參數
27852
		#重新執行的程式與參數
27744
		$serviceFileContent[]="ExecReload=killall ".$conf["cmd"]."; sleep 10; ".$fullCmd;
27853
		$serviceFileContent[]="ExecReload=killall ".$binOfServicePath."; sleep 10; ".$binOfServicePath;
27745
		
27854
		
27746
		#執行失敗後,會再次嘗試執行
27855
		#執行失敗後,會再次嘗試執行
27747
		$serviceFileContent[]="Restart=on-failure";
27856
		$serviceFileContent[]="Restart=on-failure";
27748
		
27857
		
27749
		#沒有timeout
27858
		#沒有timeout
Line 27978... Line 28087...
27978
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["cmd::keepServiceUp"];
28087
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["cmd::keepServiceUp"];
27979
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
28088
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
27980
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
28089
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
27981
			#可以省略的參數:
28090
			#可以省略的參數:
27982
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
28091
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
27983
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("");
28092
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("");
27984
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
28093
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
27985
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("");
28094
			#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("");
27986
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
28095
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
27987
			$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
28096
			$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
27988
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
28097
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
27989
			#$conf["canNotBeEmpty"]=array();
28098
			#$conf["canNotBeEmpty"]=array();
27990
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
28099
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
Line 28033... Line 28142...
28033
 
28142
 
28034
				#回傳結果
28143
				#回傳結果
28035
				return $result;
28144
				return $result;
28036
 
28145
 
28037
				}#if end
28146
				}#if end
28038
		
28147
	
-
 
28148
			#取得 lib folder
-
 
28149
			exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../bin/libexec/folderOfUsrLib.php"),$output,$status);
-
 
28150
 
-
 
28151
			#如果執行失敗
-
 
28152
			if($status!==0){
-
 
28153
 
-
 
28154
				#debug
-
 
28155
				var_dump(__LINE__,$output);
-
 
28156
 
-
 
28157
				#結束執行,回傳shell 1.
-
 
28158
				exit(1);
-
 
28159
 
-
 
28160
				}#if end
-
 
28161
 
-
 
28162
			#儲存lib path
-
 
28163
			$folderOfUsrLib=$output[0];
-
 
28164
 
-
 
28165
			#以該檔案的實際位置的 lib path 為 include path 首位
-
 
28166
			$output=array();
-
 
28167
			exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
-
 
28168
 
-
 
28169
			#如果執行失敗
-
 
28170
			if($status!==0){
-
 
28171
 
-
 
28172
				#debug
-
 
28173
				var_dump(__LINE__,$output);
-
 
28174
 
-
 
28175
				#結束執行,回傳shell 1.
-
 
28176
				exit(1);
-
 
28177
 
-
 
28178
				}#if end
-
 
28179
				
-
 
28180
			#儲存base64 encode 後 lib 的 path
-
 
28181
			$base64EncodedLibIncludePath=base64_encode($output[0]);
-
 
28182
				
28039
			#要執行的php程式內容
28183
			#要執行的php程式內容
28040
			$phpScript2run=<<<'PHP'
28184
			$phpScript2run=<<<'PHP'
28041
		
28185
		
28042
#用於確保服務在線的程式 - start
28186
#用於確保服務在線的程式 - start
-
 
28187
 
-
 
28188
#宣告命名空間
-
 
28189
namespace qbpwcf;
28043
		
28190
 
-
 
28191
#設置 include path 
-
 
28192
set_include_path(base64_decode("
-
 
28193
PHP;
-
 
28194
 
-
 
28195
#串接 base64 encode 後 lib 的 path
-
 
28196
$phpScript2run=$phpScript2run.$base64EncodedLibIncludePath;
-
 
28197
 
-
 
28198
#串接後續程式
-
 
28199
$phpScript2run=$phpScript2run.<<<'PHP'
-
 
28200
").PATH_SEPARATOR.get_include_path());
-
 
28201
 
-
 
28202
#匯入外部套件
-
 
28203
include("allInOne.php");
-
 
28204
 
28044
#函式說明:
28205
#函式說明:
28045
#執行 systemd 程序來確保服務是運行中.
28206
#執行 systemd 程序來確保服務是運行中.
28046
#回傳結果:
28207
#回傳結果:
28047
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28208
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
28048
#$result["error"],錯誤訊息.
28209
#$result["error"],錯誤訊息.
28049
#$result["function"],當前執行的函式名稱.
28210
#$result["function"],當前執行的函式名稱.
28050
#$result["argu"],所使用的參數.
28211
#$result["argu"],所使用的參數.
28051
#$result["content"],執行的結果.
28212
#$result["content"],執行的結果.
28052
#必填參數:
28213
#必填參數:
28053
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
28214
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
-
 
28215
$conf["fileArgu"]=
-
 
28216
PHP;
-
 
28217
 
-
 
28218
#串接 fileArgu 參數
28054
$conf["cmd::keepServiceUp"]["fileArgu"]=$conf["fileArgu"];
28219
$phpScript2run=$phpScript2run."\"".$conf["fileArgu"]."\";\r\n";
-
 
28220
 
-
 
28221
#串接後續程式
-
 
28222
$phpScript2run=$phpScript2run.<<<'PHP'
28055
#$conf["name"],字串,服務名稱.
28223
#$conf["name"],字串,服務名稱.
-
 
28224
$conf["name"]=
-
 
28225
PHP;
-
 
28226
 
-
 
28227
#串接 name 參數
28056
$conf["cmd::keepServiceUp"]["name"]=$conf["name"];
28228
$phpScript2run=$phpScript2run."\"".$conf["name"]."\";\r\n";
-
 
28229
 
-
 
28230
#串接後續程式
-
 
28231
$phpScript2run=$phpScript2run.<<<'PHP'
28057
#可省略參數:
28232
#可省略參數:
28058
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
28233
#$conf["username"],字串,要用什麼使用者來執行,預設為root使用者
28059
#$conf["username"]="";
28234
#$conf["username"]="";
28060
#$conf["password"],字串,使用者的密碼,預設不使用.
28235
#$conf["password"],字串,使用者的密碼,預設不使用.
28061
#$conf["password"]="";
28236
#$conf["password"]="";
28062
#$conf["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port:protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱.
28237
#$conf["checkListen"],陣列,用來判斷服務是否有正確啟動的條件,一個元素代表,其中要有一個socket info符合之,若元素的key為"ip",則其數值為[ipv4/ipv6]:port:protocol(tcp/udp);若元素的key為"addr",則其數值為unix domain socket 的位置與名稱;若元素的key為"name",則其數值為程序名稱.
-
 
28238
#$conf["checkListen"]=unserialize(base64_decode("
-
 
28239
PHP;
-
 
28240
 
-
 
28241
#將參數 $conf["cmd::keepServiceUp"]["checkListen"] serialize 成字串
28063
#$conf["checkListen"]=array(array("ip"=>169.254.1.1:443/tcp,"addr"=>/usr/lib/qbpwcf/qbpwcf-usock.sock,"name"=>"addr"),"name"=>"httpd");
28242
$encodedCheckListen=base64_encode(serialize($conf["cmd::keepServiceUp"]["checkListen"]));
-
 
28243
 
-
 
28244
#串接 checkListen 參數
-
 
28245
$phpScript2run=$phpScript2run.$encodedCheckListen."\"));\r\n";
-
 
28246
 
-
 
28247
#串接後續程式
-
 
28248
$phpScript2run=$phpScript2run.<<<'PHP'
28064
#$conf["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
28249
#$conf["interval"],字串,檢查沒問題後,要多少秒後再檢查一次,預設為30秒,亦即"30".
28065
#$conf["interval"]="30";
28250
#$conf["interval"]=$conf["cmd::keepServiceUp"]["interval"];
28066
#$conf["reportOnly"],字串,"true"代表不「啟動/重新啟動」服務,只是輸出訊息表示服務有正常或需要處理;預設為"false"代表直接「啟動/重新啟動」.
28251
#$conf["reportOnly"],字串,"true"代表不「啟動/重新啟動」服務,只是輸出訊息表示服務有正常或需要處理;預設為"false"代表直接「啟動/重新啟動」.
28067
#$conf["reportOnly"]="true";
28252
#$conf["reportOnly"]="true";
28068
#$conf["verbose"],字串,預設為"false",若為"true"則會印出過程訊息.
28253
#$conf["verbose"],字串,預設為"false",若為"true"則會印出過程訊息.
28069
$conf["cmd::keepServiceUp"]["verbose"]="true";
28254
$conf["verbose"]="true";
28070
#$conf["onlyWhenEnable"],字串,預設為"true",代表若服務為enable才會將其變成運行中;反之為"false".
28255
#$conf["onlyWhenEnable"],字串,預設為"true",代表若服務為enable才會將其變成運行中;反之為"false".
28071
#$conf["onlyWhenEnable"]="false";
28256
#$conf["onlyWhenEnable"]="false";
28072
#參考資料:
28257
#參考資料:
28073
#無.
28258
#無.
28074
#備註:
28259
#備註:
28075
#無.
28260
#無.
28076
$keepServiceUp=cmd::keepServiceUp($conf["cmd::keepServiceUp"]);
28261
$keepServiceUp=cmd::keepServiceUp($conf);
28077
unset($conf["cmd::keepServiceUp"]);
28262
unset($conf);
28078
 
28263
 
28079
#如果執行異常
28264
#如果執行異常
28080
if($keepServiceUp["status"]==="false"){
28265
if($keepServiceUp["status"]==="false"){
28081
 
28266
 
28082
	#設置執行失敗
-
 
28083
	$result["status"]="false";
-
 
28084
 
-
 
28085
	#設置錯誤訊息
28267
	#debug
28086
	$result["error"]=$keepServiceUp;
28268
	var_dump($keepServiceUp);
28087
 
28269
 
28088
	#回傳結果
28270
	#異常結束執行
28089
	return $result;
28271
	exit(1);
28090
 
28272
 
28091
	}#if end
28273
	}#if end
28092
 
28274
 
28093
#用於確保服務在線的程式 - end
28275
#用於確保服務在線的程式 - end
28094
 
-
 
28095
PHP;
28276
PHP;
28096
			
28277
			
28097
			#遞迴呼叫,建立用於確保 $conf[name] 服務在線的服務
28278
			#遞迴呼叫,建立用於確保 $conf[name] 服務在線的服務
28098
			#函式說明:
28279
			#函式說明:
28099
			#將要執行的程式變成透過 systemd 來運行.
28280
			#將要執行的程式變成透過 systemd 來運行.
Line 28106... Line 28287...
28106
			#必填參數:
28287
			#必填參數:
28107
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
28288
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑.
28108
			$paramsOfRegisterService["fileArgu"]=__FILE__;
28289
			$paramsOfRegisterService["fileArgu"]=__FILE__;
28109
			#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".
28290
			#$conf["name"],字串,服務名稱,實際產生的system名稱會加上".service".
28110
			$paramsOfRegisterService["name"]=$conf["name"]."-keep";
28291
			$paramsOfRegisterService["name"]=$conf["name"]."-keep";
28111
			#$conf["cmd"],字串,要執行的指令.
28292
			#$conf["cmds"],字串陣列,每個要執行的程式.
28112
			$paramsOfRegisterService["cmd"]="php";
28293
			$paramsOfRegisterService["cmds"][]="php";
28113
			#可省略參數:
28294
			#可省略參數:
28114
			#$conf["params"],字串陣列,指令要使用的參數.
28295
			#$conf["params"],字串陣列,每個程式使用的參數.
28115
			$paramsOfRegisterService["params"]=array("-r",$phpScript2run);
28296
			$paramsOfRegisterService["params"][]=array("-r",$phpScript2run);
28116
			#$conf["enable"],字串,預設為"true",代表該服務為enable.
28297
			#$conf["enable"],字串,預設為"true",代表該服務為enable.
28117
			#$conf["enable"]="true";
28298
			#$conf["enable"]="true";
28118
			#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.
28299
			#$conf["startNow"],字串,預設為"true",代表該服務要立刻執行.
28119
			#$conf["startNow"]="true";
28300
			#$conf["startNow"]="true";
28120
			#$conf["keepServiceUp"],字串,是否要另外增加確保服務有保持啟動的服務,預設為"false"代表否;反之為"true"代表是.
28301
			#$conf["keepServiceUp"],字串,是否要另外增加確保服務有保持啟動的服務,預設為"false"代表否;反之為"true"代表是.
Line 34429... Line 34610...
34429
	*/
34610
	*/
34430
	public static function createRPMspec(&$conf){
34611
	public static function createRPMspec(&$conf){
34431
	
34612
	
34432
		}#function createRPMspec end
34613
		}#function createRPMspec end
34433
 
34614
 
-
 
34615
	/*
-
 
34616
	#函式說明:
-
 
34617
	#產生 php 程式的字串,將外部變數透過編碼的方式放進去.
-
 
34618
	#回傳結果:
-
 
34619
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
34620
	#$result["error"],錯誤訊息.
-
 
34621
	#$result["function"],當前執行的函式名稱.
-
 
34622
	#$result["content"],得到的php程式內容字串.
-
 
34623
	#必填參數:
-
 
34624
	#$conf["codes"],字串陣列,每個元素代表PHP程式片段.
-
 
34625
	$conf["codes"]=array("");
-
 
34626
	#可省略參數:
-
 
34627
	#$conf["vars"],變數陣列,每個元素代表PHP變數,會透過編碼再解碼的方式變成字串,不支援object跟resouce以及socket.
-
 
34628
	#$conf["vars"]=array();
-
 
34629
	#可省略參數:
-
 
34630
	#無.
-
 
34631
	#參考資料:
-
 
34632
	#https://www.php.net/manual/en/function.serialize.php
-
 
34633
	#https://www.php.net/manual/en/function.unserialize.php
-
 
34634
	#備註:
-
 
34635
	#無.
-
 
34636
	*/
-
 
34637
	public static function createPHPcodeString(&$conf){
-
 
34638
	
-
 
34639
		#初始化要回傳的結果
-
 
34640
		$result=array();
-
 
34641
 
-
 
34642
		#取得當前執行的函數名稱
-
 
34643
		$result["function"]=__FUNCTION__;
-
 
34644
 
-
 
34645
		#如果沒有參數
-
 
34646
		if(func_num_args()==0){
-
 
34647
 
-
 
34648
			#設置執行失敗
-
 
34649
			$result["status"]="false";
-
 
34650
 
-
 
34651
			#設置執行錯誤訊息
-
 
34652
			$result["error"]="函數".$result["function"]."需要參數";
-
 
34653
 
-
 
34654
			#回傳結果
-
 
34655
			return $result;
-
 
34656
 
-
 
34657
			}#if end
-
 
34658
 
-
 
34659
		#取得參數
-
 
34660
		$result["argu"]=$conf;
-
 
34661
 
-
 
34662
		#如果 $conf 不為陣列
-
 
34663
		if(gettype($conf)!=="array"){
-
 
34664
 
-
 
34665
			#設置執行失敗
-
 
34666
			$result["status"]="false";
-
 
34667
 
-
 
34668
			#設置執行錯誤訊息
-
 
34669
			$result["error"][]="\$conf變數須為陣列形態";
-
 
34670
 
-
 
34671
			#如果傳入的參數為 null
-
 
34672
			if(is_null($conf)){
-
 
34673
 
-
 
34674
				#設置執行錯誤訊息
-
 
34675
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
-
 
34676
 
-
 
34677
				}#if end
-
 
34678
 
-
 
34679
			#回傳結果
-
 
34680
			return $result;
-
 
34681
 
-
 
34682
			}#if end
-
 
34683
	
-
 
34684
		#函式說明:
-
 
34685
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
-
 
34686
		#回傳結果:
-
 
34687
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
34688
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
-
 
34689
		#$result["function"],當前執行的函式名稱.
-
 
34690
		#$result["argu"],設置給予的參數.
-
 
34691
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
-
 
34692
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
-
 
34693
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
-
 
34694
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
-
 
34695
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
-
 
34696
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
-
 
34697
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
-
 
34698
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
-
 
34699
		#必填參數:
-
 
34700
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
-
 
34701
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
-
 
34702
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
-
 
34703
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
-
 
34704
		#可省略參數:
-
 
34705
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
-
 
34706
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("codes");
-
 
34707
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
-
 
34708
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("array");
-
 
34709
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
-
 
34710
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
-
 
34711
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
-
 
34712
		#$conf["variableCheck::checkArguments"]["canNotBeEmpty"]=array();
-
 
34713
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
-
 
34714
		#$conf["canBeEmpty"]=array();
-
 
34715
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
-
 
34716
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("vars");
-
 
34717
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
-
 
34718
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("vars");
-
 
34719
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
-
 
34720
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array");
-
 
34721
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
-
 
34722
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
-
 
34723
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
-
 
34724
		#$conf["disallowAllSkipableVarIsEmpty"]="";
-
 
34725
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
-
 
34726
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
-
 
34727
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
-
 
34728
		#$conf["arrayCountEqualCheck"][]=array();
-
 
34729
		#參考資料:
-
 
34730
		#array_keys=>http://php.net/manual/en/function.array-keys.php
-
 
34731
		#備註:
-
 
34732
		#無.
-
 
34733
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
-
 
34734
		unset($conf["variableCheck::checkArguments"]);
-
 
34735
	
-
 
34736
		#如果執行失敗
-
 
34737
		if($checkArguments["status"]==="false"){
-
 
34738
		
-
 
34739
			#設置執行失敗
-
 
34740
			$result["status"]="false";
-
 
34741
 
-
 
34742
			#設置錯誤訊息
-
 
34743
			$result["error"]=$checkArguments;
-
 
34744
 
-
 
34745
			#回傳結果
-
 
34746
			return $result;
-
 
34747
		
-
 
34748
			}#if end
-
 
34749
			
-
 
34750
		#如果檢查不通過
-
 
34751
		if($checkArguments["passed"]==="false"){
-
 
34752
		
-
 
34753
			#設置執行失敗
-
 
34754
			$result["status"]="false";
-
 
34755
 
-
 
34756
			#設置錯誤訊息
-
 
34757
			$result["error"]=$checkArguments;
-
 
34758
 
-
 
34759
			#回傳結果
-
 
34760
			return $result;
-
 
34761
		
-
 
34762
			}#if end
-
 
34763
	
-
 
34764
		#初始化儲存結果的變數
-
 
34765
		$result["content"]="";
-
 
34766
	
-
 
34767
		#針對每段程式字串 
-
 
34768
		foreach($conf["codes"] as $index => $code){
-
 
34769
		
-
 
34770
			#串接程式 
-
 
34771
			$result["content"]=$result["content"].$code;
-
 
34772
		
-
 
34773
			#如果有設置  vars
-
 
34774
			if(isset($conf["vars"])){
-
 
34775
			
-
 
34776
				#如果有設置要接上的php變數
-
 
34777
				if(isset($conf["vars"][$index])){
-
 
34778
				
-
 
34779
					#編碼變數
-
 
34780
					$encodedVarStr=base64_encode(serialize($conf["vars"][$index]));
-
 
34781
				
-
 
34782
					#串接變數
-
 
34783
					$result["content"]=$result["content"]."unserialize(base64_decode(\"".$encodedVarStr."\"))";
-
 
34784
				
-
 
34785
					}#if end
-
 
34786
			
-
 
34787
				}#if end
-
 
34788
		
-
 
34789
			}#foreach end
-
 
34790
			
-
 
34791
		#設置執行正常
-
 
34792
		$result["status"]="true";
-
 
34793
		
-
 
34794
		#回傳結果
-
 
34795
		return $result;
-
 
34796
	
-
 
34797
		}#function createPHPcodeString end
-
 
34798
 
34434
	}#class cmd end
34799
	}#class cmd end
34435
 
34800
 
34436
?>
34801
?>
34437
34802