Subversion Repositories php-qbpwcf

Rev

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

Rev 3 Rev 48
Line 1797... Line 1797...
1797
			$result["username"]=$conf["accountVar"];
1797
			$result["username"]=$conf["accountVar"];
1798
 
1798
 
1799
			}#else end
1799
			}#else end
1800
 
1800
 
1801
		#預設使用該php程式的使用者帳號
1801
		#預設使用該php程式的使用者帳號
1802
		#$result["phpUser"]="apache";
1802
		$result["phpUser"]="apache";
-
 
1803
		
-
 
1804
		#嘗試從系統變數取得使用者名稱
-
 
1805
		#函式說明:
-
 
1806
		#呼叫shell執行系統命令,並取得回傳的內容.
-
 
1807
		#回傳結果:
-
 
1808
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
1809
		#$result["error"],錯誤訊息陣列.
-
 
1810
		#$result["function"],當前執行的函數名稱.
-
 
1811
		#$result["argu"],使用的參數.
-
 
1812
		#$result["cmd"],執行的指令內容.
-
 
1813
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
1814
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
-
 
1815
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
-
 
1816
		#$result["running"],是否還在執行.
-
 
1817
		#$result["pid"],pid.
-
 
1818
		#$result["statusCode"],執行結束後的代碼.
-
 
1819
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
1820
		#必填參數:
-
 
1821
		#$conf["command"],字串,要執行的指令.
-
 
1822
		$conf["external::callShell"]["command"]="env";
-
 
1823
		#$conf["fileArgu"],字串,變數__FILE__的內容.
-
 
1824
		$conf["external::callShell"]["fileArgu"]=__FILE__;
-
 
1825
		#可省略參數:
-
 
1826
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
-
 
1827
		#$conf["external::callShell"]["argu"]=array();
-
 
1828
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
-
 
1829
		#$conf["arguIsAddr"]=array();
-
 
1830
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
-
 
1831
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
-
 
1832
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
-
 
1833
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
-
 
1834
		#$conf["enablePrintDescription"]="true";
-
 
1835
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
-
 
1836
		#$conf["printDescription"]="";
-
 
1837
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
-
 
1838
		$conf["external::callShell"]["escapeshellarg"]="true";
-
 
1839
		#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
-
 
1840
		#$conf["thereIsShellVar"]=array();
-
 
1841
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
-
 
1842
		#$conf["username"]="";
-
 
1843
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
-
 
1844
		#$conf["password"]="";
-
 
1845
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
-
 
1846
		#$conf["useScript"]="";
-
 
1847
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
-
 
1848
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
-
 
1849
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
-
 
1850
		#$conf["inBackGround"]="";
-
 
1851
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
-
 
1852
		#$conf["getErr"]="false";
-
 
1853
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
1854
		#$conf["doNotRun"]="false";
-
 
1855
		#參考資料:
-
 
1856
		#exec=>http://php.net/manual/en/function.exec.php
-
 
1857
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
-
 
1858
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
-
 
1859
		#備註:
-
 
1860
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
-
 
1861
		#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
-
 
1862
		$callShell=external::callShell($conf["external::callShell"]);
-
 
1863
		unset($conf["external::callShell"]);
-
 
1864
	
-
 
1865
		#如果執行失敗
-
 
1866
		if($callShell["status"]==="false"){
-
 
1867
		
-
 
1868
			#設置執行失敗
-
 
1869
			$result["status"]="false";
1803
 
1870
 
-
 
1871
			#設置執行錯誤訊息
-
 
1872
			$result["error"]=$callShell;
-
 
1873
 
-
 
1874
			#回傳結果
-
 
1875
			return $result;
-
 
1876
		
-
 
1877
			}#if end
-
 
1878
			
-
 
1879
		#函式說明:
-
 
1880
		#檢查多個字串中的每個字串是否有多個關鍵字
-
 
1881
		#回傳結果:
-
 
1882
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
-
 
1883
		#$result["function"],當前執行的函數名稱.
-
 
1884
		#$result["error"],錯誤訊息.
-
 
1885
		#$result["argu"],使用的參數.
-
 
1886
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
-
 
1887
		#$result["foundedKeyWords"],找到的關鍵字陣列.
-
 
1888
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
-
 
1889
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
-
 
1890
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
-
 
1891
		#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
-
 
1892
		#必填參數:
-
 
1893
		#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
-
 
1894
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("LOGNAME=","USERNAME=","USER=","HOME=");
-
 
1895
		#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
-
 
1896
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
-
 
1897
		#可省略參數:
-
 
1898
		#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
-
 
1899
		#$conf["completeEqual"]="true";
-
 
1900
		#參考資料:
-
 
1901
		#無.
-
 
1902
		#備註:
-
 
1903
		#無.
-
 
1904
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
-
 
1905
		unset($conf["search::findManyKeyWordsFromManyString"]);
-
 
1906
	
-
 
1907
		#debug
-
 
1908
		#var_dump(__LINE__,$findManyKeyWordsFromManyString);
-
 
1909
	
-
 
1910
		#如果執行不正常
-
 
1911
		if($findManyKeyWordsFromManyString["status"]==="false"){
-
 
1912
		
-
 
1913
			#設置執行失敗
-
 
1914
			$result["status"]="false";
-
 
1915
 
-
 
1916
			#設置執行錯誤訊息
-
 
1917
			$result["error"]=$findManyKeyWordsFromManyString;
-
 
1918
 
-
 
1919
			#回傳結果
-
 
1920
			return $result;
-
 
1921
			
-
 
1922
			}#if end
-
 
1923
			
-
 
1924
		#針對每個有找到關鍵字的來源字串
-
 
1925
		foreach($findManyKeyWordsFromManyString["keyWordsIncludeStr"] as $keyWordsIncludeStr){
-
 
1926
		
-
 
1927
			#如果有多個關鍵字
-
 
1928
			if(count($keyWordsIncludeStr["keyWords"])>1){
-
 
1929
			
-
 
1930
				#跳過
-
 
1931
				continue;
-
 
1932
			
-
 
1933
				}#if end
-
 
1934
		
-
 
1935
			#解析使用者名稱
-
 
1936
			#函式說明:
-
 
1937
			#將字串特定關鍵字與其前面的內容剔除
-
 
1938
			#回傳結果:
-
 
1939
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
-
 
1940
			#$result["error"],錯誤訊息陣列.
-
 
1941
			#$result["warning"],警告訊息鎮列.
-
 
1942
			#$result["founded"],有無找到定字串"true"代表有,"false"代表沒有.
-
 
1943
			#$result["function"],當前執行的函數名稱.
-
 
1944
			#$result["argu"],使用的參數.
-
 
1945
			#$result["oriStr"],要處理的原始字串內容.
-
 
1946
			#$result["content"],處理好的的字串內容.	
-
 
1947
			#必填參數:
-
 
1948
			#$conf["stringIn"],字串,要處理的字串.
-
 
1949
			$conf["stringProcess::delStrBeforeKeyWord"]["stringIn"]=$keyWordsIncludeStr["sourceVal"];
-
 
1950
			#$conf["keyWord"],字串,特定字串.
-
 
1951
			$conf["stringProcess::delStrBeforeKeyWord"]["keyWord"]=$keyWordsIncludeStr["keyWords"][0];
-
 
1952
			#可省略參數:
-
 
1953
			#$conf["recursive"],字串,預設為"false"代表找到一個關鍵字就會停止;"true"代表會即重複執行,知道沒有關鍵字為止.
-
 
1954
			$conf["stringProcess::delStrBeforeKeyWord"]["recursive"]="true";
-
 
1955
			#$conf["lastResult"],陣列,本函式前次執行的結果,若沒有找到關鍵字,則會改回傳該內容.
-
 
1956
			#$conf["lastResult"]=$delStrBeforeKeyWord;
-
 
1957
			#參考資料:
-
 
1958
			#無.
-
 
1959
			#備註:
-
 
1960
			#無.
-
 
1961
			$delStrBeforeKeyWord=stringProcess::delStrBeforeKeyWord($conf["stringProcess::delStrBeforeKeyWord"]);
-
 
1962
			unset($conf["stringProcess::delStrBeforeKeyWord"]);
-
 
1963
		
-
 
1964
			#debug
-
 
1965
			#var_dump(__LINE__,$delStrBeforeKeyWord);
-
 
1966
		
-
 
1967
			#如果執行不正常
-
 
1968
			if($delStrBeforeKeyWord["status"]==="false"){
-
 
1969
			
-
 
1970
				#設置執行失敗
-
 
1971
				$result["status"]="false";
-
 
1972
 
-
 
1973
				#設置執行錯誤訊息
-
 
1974
				$result["error"]=$delStrBeforeKeyWord;
-
 
1975
 
-
 
1976
				#回傳結果
-
 
1977
				return $result;
-
 
1978
			
-
 
1979
				}#if end
-
 
1980
				
-
 
1981
			#如果沒有關鍵字
-
 
1982
			if($delStrBeforeKeyWord["founded"]==="false"){
-
 
1983
			
-
 
1984
				#設置執行失敗
-
 
1985
				$result["status"]="false";
-
 
1986
 
-
 
1987
				#設置執行錯誤訊息
-
 
1988
				$result["error"]=$delStrBeforeKeyWord;
-
 
1989
 
-
 
1990
				#回傳結果
-
 
1991
				return $result;
-
 
1992
			
-
 
1993
				}#if end
-
 
1994
				
-
 
1995
			#如果不是空字串
-
 
1996
			if(!empty($delStrBeforeKeyWord["content"])){
-
 
1997
			
-
 
1998
				#取得使用者名稱
-
 
1999
				$result["phpUser"]=basename($delStrBeforeKeyWord["content"]);
-
 
2000
			
-
 
2001
				#結束 foreach
-
 
2002
				break;
-
 
2003
			
-
 
2004
				}#if end
-
 
2005
		
-
 
2006
			}#foreach end
-
 
2007
		
1804
		#如果 $_SERVER['HTTP_USER_AGENT'] 存在
2008
		#如果 $_SERVER['HTTP_USER_AGENT'] 存在
1805
		if(isset($_SERVER['HTTP_USER_AGENT'])){
2009
		if(isset($_SERVER['HTTP_USER_AGENT'])){
1806
 
2010
 
1807
			#var_dump($_SERVER["DOCUMENT_ROOT"]);
2011
			#var_dump($_SERVER["DOCUMENT_ROOT"]);
1808
 
2012