Subversion Repositories php-qbpwcf

Rev

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

Rev 3 Rev 61
Line 1563... Line 1563...
1563
			
1563
			
1564
			#運行不正常 
1564
			#運行不正常 
1565
			$result["status"]="false";
1565
			$result["status"]="false";
1566
 
1566
 
1567
			#設置錯誤訊息 
1567
			#設置錯誤訊息 
1568
			$result["error"][]="缺少POST變數";	
1568
			$result["error"][]="缺少POST變數";
1569
 
1569
 
1570
			#回傳結果
1570
			#回傳結果
1571
			return $result;
1571
			return $result;
1572
						
1572
			
1573
			}#if end
1573
			}#if end
1574
 
1574
 
1575
		}#function verifyCodeAndFormData end
1575
		}#function verifyCodeAndFormData end
1576
		
1576
		
1577
	/*
1577
	/*
1578
	#函式說明:
1578
	#函式說明:
1579
	#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
1579
	#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
1580
	#回傳結果:
1580
	#回傳結果:
1581
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
1581
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
1582
	#$result["function"],當前執行的函數名稱.
1582
	#$result["function"],當前執行的函數名稱.
1583
	#$result["content"],加密後的結果.
1583
	#$result["content"],加密後的結果.
1584
	#$result["error"],錯誤訊息陣列.
1584
	#$result["error"],錯誤訊息陣列.
1585
	#$result["argu"],使用的參數.
1585
	#$result["argu"],使用的參數.
1586
	#必填參數:
1586
	#必填參數:
1587
	#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
1587
	#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
1588
	$conf["enCodeStr"]="";
1588
	$conf["enCodeStr"]="";
1589
	#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
1589
	#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
1590
	$conf["enCodeType"]="sha1";
1590
	$conf["enCodeType"]="sha1";
1591
	#可省略參數:
1591
	#可省略參數:
1592
	#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
1592
	#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
1593
	#$conf["sha1Raw"]="false";
1593
	#$conf["sha1Raw"]="false";
1594
	#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
1594
	#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
Line 1597... Line 1597...
1597
	#$conf["keyForAes256"]="";
1597
	#$conf["keyForAes256"]="";
1598
	#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
1598
	#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
1599
	#$conf["aes256Encode"]="";
1599
	#$conf["aes256Encode"]="";
1600
	#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
1600
	#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
1601
	#$conf["qbpwcfDecode"]="false";
1601
	#$conf["qbpwcfDecode"]="false";
-
 
1602
	#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
1603
	#$conf["gpgDecrypt"]="false";
-
 
1604
	#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,該參數必填.
-
 
1605
	#$conf["gpgId"]="";
1602
	#參考資料:
1606
	#參考資料:
1603
	#sha1=>http://php.net/manual/en/function.sha1.php
1607
	#sha1=>http://php.net/manual/en/function.sha1.php
1604
	#md5=>http://php.net/manual/en/function.md5.php
1608
	#md5=>http://php.net/manual/en/function.md5.php
1605
	#password_hash=>http://php.net/manual/en/function.password-hash.php
1609
	#password_hash=>http://php.net/manual/en/function.password-hash.php
1606
	#password_verify=>http://php.net/manual/en/function.password-verify.php
1610
	#password_verify=>http://php.net/manual/en/function.password-verify.php
Line 1662... Line 1666...
1662
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1666
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1663
		#可以省略的參數:
1667
		#可以省略的參數:
1664
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1668
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1665
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1669
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1666
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1670
		#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1667
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash","keyForAes256","aes256Encode","qbpwcfDecode");
1671
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sha1Raw","p_hash","keyForAes256","aes256Encode","qbpwcfDecode","gpgDecrypt","gpgId");
1668
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1672
		#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1669
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string");
1673
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string");
1670
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1674
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1671
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false");
1675
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("false",null,null,null,"false","false",null);
1672
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1676
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1673
		#$conf["arrayCountEqualCheck"][]=array();
1677
		#$conf["arrayCountEqualCheck"][]=array();
1674
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1678
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1675
		unset($conf["variableCheck::checkArguments"]);
1679
		unset($conf["variableCheck::checkArguments"]);
1676
		
1680
		
1677
		#如果檢查參數失敗
1681
		#如果檢查參數失敗
1678
		if($checkResult["status"]=="false"){
1682
		if($checkResult["status"]==="false"){
1679
			
1683
			
1680
			#設置執行失敗
1684
			#設置執行失敗
1681
			$result["status"]="false";
1685
			$result["status"]="false";
1682
			
1686
			
1683
			#設置執行錯誤
1687
			#設置執行錯誤
Line 1687... Line 1691...
1687
			return $result;
1691
			return $result;
1688
			
1692
			
1689
			}#if end
1693
			}#if end
1690
			
1694
			
1691
		#如果檢查參數不通過
1695
		#如果檢查參數不通過
1692
		if($checkResult["passed"]=="false"){
1696
		if($checkResult["passed"]==="false"){
1693
			
1697
			
1694
			#設置執行失敗
1698
			#設置執行失敗
1695
			$result["status"]="false";
1699
			$result["status"]="false";
1696
			
1700
			
1697
			#設置執行錯誤
1701
			#設置執行錯誤
Line 1962... Line 1966...
1962
				
1966
				
1963
					#取得 base64_decoed 的本文與 iv
1967
					#取得 base64_decoed 的本文與 iv
1964
					list($conf["enCodeStr"], $iv) = explode('::', base64_decode($conf["enCodeStr"]), 2);
1968
					list($conf["enCodeStr"], $iv) = explode('::', base64_decode($conf["enCodeStr"]), 2);
1965
					
1969
					
1966
					#取得 解密好的內容
1970
					#取得 解密好的內容
1967
				  	$result["content"]=openssl_decrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
1971
					$result["content"]=openssl_decrypt($conf["enCodeStr"], 'aes-256-cbc', $conf["keyForAes256"], 0, $iv);
1968
				  	
1972
					
1969
				  	#數值執行正常
1973
					#數值執行正常
1970
					$result["status"]="true";
1974
					$result["status"]="true";
1971
					
1975
					
1972
					#回傳結果
1976
					#回傳結果
1973
					return $result;
1977
					return $result;
1974
					
1978
					
Line 2031... Line 2035...
2031
					#設置解密好的內容
2035
					#設置解密好的內容
2032
					$result["content"]=$json_decode_data;
2036
					$result["content"]=$json_decode_data;
2033
				
2037
				
2034
					}#else end
2038
					}#else end
2035
			
2039
			
2036
				#跳出迴圈
2040
				#跳出 switch
2037
				break;	
2041
				break;	
2038
			
2042
			
-
 
2043
			#若是bin2hex
-
 
2044
			case "bin2hex":
-
 
2045
			
-
 
2046
				#用16進位的兩個字母來表示每個byte
-
 
2047
				$result["content"]=unpack("H*",$conf["enCodeStr"]);
-
 
2048
			
-
 
2049
				#相當於
-
 
2050
				#$result["content"]=bin2hex($conf["enCodeStr"]);
-
 
2051
				
-
 
2052
				#跳出 switch
-
 
2053
				break;
-
 
2054
				
-
 
2055
			#若是hex2bin
-
 
2056
			case "hex2bin":
-
 
2057
			
-
 
2058
				#將每個byte用兩個16進位字母來表示的字串變成 binary string
-
 
2059
 				$result["content"]=pack("H*",$conf["enCodeStr"]);
-
 
2060
			
-
 
2061
				#跳出 switch
-
 
2062
				break;
-
 
2063
			
-
 
2064
			#如果是"gpg加解密"
-
 
2065
			case "gpg":
-
 
2066
			
-
 
2067
				#如果沒有 gpgId
-
 
2068
				if(!isset($conf["gpgId"])){
-
 
2069
				
-
 
2070
					#設置執行失敗
-
 
2071
					$result["status"]="false";
-
 
2072
					
-
 
2073
					#設置執行錯誤
-
 
2074
					$result["error"]="param gpgId if required when enCodeType is ".$conf["enCodeType"];
-
 
2075
					
-
 
2076
					#回傳結果
-
 
2077
					return $result;
-
 
2078
				
-
 
2079
					}#if end
-
 
2080
			
-
 
2081
				#如果是用加密
-
 
2082
				if($conf["gpgDecrypt"]==="false"){
-
 
2083
				
-
 
2084
					#用GnuPG加密
-
 
2085
					#函式說明:
-
 
2086
					#呼叫shell執行系統命令,並取得回傳的內容.
-
 
2087
					#回傳結果:
-
 
2088
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
2089
					#$result["error"],錯誤訊息陣列.
-
 
2090
					#$result["function"],當前執行的函數名稱.
-
 
2091
					#$result["argu"],使用的參數.
-
 
2092
					#$result["cmd"],執行的指令內容.
-
 
2093
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
2094
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
2095
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
2096
					#$result["content"],為執行完後的輸出字串.
-
 
2097
					#$result["running"],是否還在執行.
-
 
2098
					#$result["pid"],pid.
-
 
2099
					#$result["statusCode"],執行結束後的代碼.
-
 
2100
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
2101
					#必填參數:
-
 
2102
					#$conf["command"],字串,要執行的指令.
-
 
2103
					$conf["external::callShell"]["command"]="base64decode.php";
-
 
2104
					#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2105
					$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
2106
					#可省略參數:
-
 
2107
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2108
					$conf["external::callShell"]["argu"]=array(base64_encode($conf["enCodeStr"]),"|","gpg","-r",$conf["gpgId"],"--trust-model","always","-v","-e");
-
 
2109
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
2110
					#$conf["arguIsAddr"]=array();
-
 
2111
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
2112
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
2113
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
2114
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
2115
					#$conf["enablePrintDescription"]="true";
-
 
2116
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
2117
					#$conf["printDescription"]="";
-
 
2118
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
2119
					$conf["external::callShell"]["escapeshellarg"]="true";
-
 
2120
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
2121
					#$conf["thereIsShellVar"]=array();
-
 
2122
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
2123
					#$conf["username"]="";
-
 
2124
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
2125
					#$conf["password"]="";
-
 
2126
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
2127
					#$conf["useScript"]="";
-
 
2128
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
2129
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
2130
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
2131
					#$conf["inBackGround"]="";
-
 
2132
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
2133
					#$conf["getErr"]="false";
-
 
2134
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
2135
					#$conf["doNotRun"]="false";
-
 
2136
					#參考資料:
-
 
2137
					#exec=>http://php.net/manual/en/function.exec.php
-
 
2138
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
2139
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
2140
					#備註:
-
 
2141
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
2142
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
2143
					$callShell=external::callShell($conf["external::callShell"]);
-
 
2144
					unset($conf["external::callShell"]);
-
 
2145
 
-
 
2146
					#如果執行失敗
-
 
2147
					if($callShell["status"]==="false"){
-
 
2148
 
-
 
2149
						#設置執行失敗
-
 
2150
						$result["status"]="false";
-
 
2151
						
-
 
2152
						#設置執行錯誤
-
 
2153
						$result["error"]=$callShell;
-
 
2154
						
-
 
2155
						#回傳結果
-
 
2156
						return $result;
-
 
2157
					
-
 
2158
						}#if end
-
 
2159
 
-
 
2160
					#取得加密後的內容
-
 
2161
					$result["content"]=$callShell["content"];
-
 
2162
				
-
 
2163
					}#if end
-
 
2164
					
-
 
2165
				#反之如果是解密
-
 
2166
				else if($conf["gpgDecrypt"]==="true"){
-
 
2167
					
-
 
2168
					#用GnuPG解密
-
 
2169
					#函式說明:
-
 
2170
					#呼叫shell執行系統命令,並取得回傳的內容.
-
 
2171
					#回傳結果:
-
 
2172
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
2173
					#$result["error"],錯誤訊息陣列.
-
 
2174
					#$result["function"],當前執行的函數名稱.
-
 
2175
					#$result["argu"],使用的參數.
-
 
2176
					#$result["cmd"],執行的指令內容.
-
 
2177
					#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
2178
					#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
2179
					#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
2180
					#$result["content"],為執行完後的輸出字串.
-
 
2181
					#$result["running"],是否還在執行.
-
 
2182
					#$result["pid"],pid.
-
 
2183
					#$result["statusCode"],執行結束後的代碼.
-
 
2184
					#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
2185
					#必填參數:
-
 
2186
					#$conf["command"],字串,要執行的指令.
-
 
2187
					$conf["external::callShell"]["command"]="base64decode.php";
-
 
2188
					#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
2189
					$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
2190
					#可省略參數:
-
 
2191
					#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
2192
					$conf["external::callShell"]["argu"]=array(base64_encode($conf["enCodeStr"]),"|","gpg","-r",$conf["gpgId"],"--trust-model","always","-v","-d");
-
 
2193
					#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
2194
					#$conf["arguIsAddr"]=array();
-
 
2195
					#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
2196
					#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
2197
					#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
2198
					#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
2199
					#$conf["enablePrintDescription"]="true";
-
 
2200
					#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
2201
					#$conf["printDescription"]="";
-
 
2202
					#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
2203
					$conf["external::callShell"]["escapeshellarg"]="true";
-
 
2204
					#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
2205
					#$conf["thereIsShellVar"]=array();
-
 
2206
					#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
2207
					#$conf["username"]="";
-
 
2208
					#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
2209
					#$conf["password"]="";
-
 
2210
					#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
2211
					#$conf["useScript"]="";
-
 
2212
					#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
2213
					#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
2214
					#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
2215
					#$conf["inBackGround"]="";
-
 
2216
					#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
2217
					#$conf["getErr"]="false";
-
 
2218
					#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
2219
					#$conf["doNotRun"]="false";
-
 
2220
					#參考資料:
-
 
2221
					#exec=>http://php.net/manual/en/function.exec.php
-
 
2222
					#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
2223
					#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
2224
					#備註:
-
 
2225
					#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
2226
					#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
2227
					$callShell=external::callShell($conf["external::callShell"]);
-
 
2228
					unset($conf["external::callShell"]);
-
 
2229
 
-
 
2230
					#如果執行失敗
-
 
2231
					if($callShell["status"]==="false"){
-
 
2232
 
-
 
2233
						#設置執行失敗
-
 
2234
						$result["status"]="false";
-
 
2235
						
-
 
2236
						#設置執行錯誤
-
 
2237
						$result["error"]=$callShell;
-
 
2238
						
-
 
2239
						#回傳結果
-
 
2240
						return $result;
-
 
2241
 
-
 
2242
						}#if end
-
 
2243
						
-
 
2244
					#取得加密後的內容
-
 
2245
					$result["content"]=$callShell["content"];
-
 
2246
					
-
 
2247
					}#else end
-
 
2248
			
-
 
2249
				#跳出 switch
-
 
2250
				break;
-
 
2251
				
2039
			#如果是其他內容
2252
			#如果是其他內容
2040
			default:
2253
			default:
2041
			
2254
			
2042
				#設置執行失敗
2255
				#設置執行失敗
2043
				$result["status"]="false";
2256
				$result["status"]="false";
Line 2054... Line 2267...
2054
		$result["status"]="true";
2267
		$result["status"]="true";
2055
		
2268
		
2056
		#回傳結果
2269
		#回傳結果
2057
		return $result;
2270
		return $result;
2058
		
2271
		
2059
		}#function enCodeStr end	
2272
		}#function enCodeStr end
2060
	
2273
	
2061
	/*
2274
	/*
2062
	#函式說明:
2275
	#函式說明:
2063
	#將字串變成2元碼或2元碼變成字串.
2276
	#將字串變成2元碼或2元碼變成字串.
2064
	#回傳結果:
2277
	#回傳結果:
Line 2187... Line 2400...
2187
			foreach($result["content"] as $key=>$bin){
2400
			foreach($result["content"] as $key=>$bin){
2188
 
2401
 
2189
				#轉換成字串
2402
				#轉換成字串
2190
				$result["content"][$key]=base_convert($result["content"][1], 16, 2);
2403
				$result["content"][$key]=base_convert($result["content"][1], 16, 2);
2191
 
2404
 
2192
				}#foreach end								
2405
				}#foreach end
2193
			
2406
			
2194
			}#if end
2407
			}#if end
2195
			
2408
			
2196
		#設置執行正常
2409
		#設置執行正常
2197
		$result["status"]="true";
2410
		$result["status"]="true";
2198
		
2411
		
2199
		#回傳結果
2412
		#回傳結果
2200
		return $result;
2413
		return $result;
2201
		
2414
		
2202
		}#function hex2bin end	
2415
		}#function str2bin end	
2203
 
2416
 
2204
	/*
2417
	/*
2205
	#函式說明:
2418
	#函式說明:
2206
	#驗證Linux使用者的密碼是否正確.
2419
	#驗證Linux使用者的密碼是否正確.
2207
	#回傳結果:
2420
	#回傳結果: