Subversion Repositories php-qbpwcf

Rev

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

Rev 3 Rev 226
Line 1... Line 1...
1
<?php
1
<?php
2
 
2
 
3
/*
3
/*
4
 
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2025 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
11
    it under the terms of the GNU General Public License as published by
Line 981... Line 981...
981
 
981
 
982
			}#if end
982
			}#if end
983
 
983
 
984
		#組合 wget 指令
984
		#組合 wget 指令
985
		$paramsArray=array("--no-check-certificate","-O",$conf["saveLocation"].".html",$conf["type"]."://".$conf["webHostAddressOrDNS"].":".$conf["port"]."/".$conf["webPageLocation"]);
985
		$paramsArray=array("--no-check-certificate","-O",$conf["saveLocation"].".html",$conf["type"]."://".$conf["webHostAddressOrDNS"].":".$conf["port"]."/".$conf["webPageLocation"]);
986
		
986
 
987
		#函式說明:
987
		#函式說明:
988
		#呼叫shell執行系統命令,並取得回傳的內容.
988
		#呼叫shell執行系統命令,並取得回傳的內容.
989
		#回傳結果:
989
		#回傳結果:
990
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
990
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
991
		#$result["error"],錯誤訊息陣列.
991
		#$result["error"],錯誤訊息陣列.
Line 1549... Line 1549...
1549
			#設置 --ssl-reqd 參數,代表強制為https
1549
			#設置 --ssl-reqd 參數,代表強制為https
1550
			$arguments[]="--ssl-reqd";
1550
			$arguments[]="--ssl-reqd";
1551
 
1551
 
1552
			#要包住參數
1552
			#要包住參數
1553
			$plainArgu[]="false";
1553
			$plainArgu[]="false";
1554
			
1554
 
1555
			#不要改用「'」包住參數
1555
			#不要改用「'」包住參數
1556
			$useApostrophe[]="false";
1556
			$useApostrophe[]="false";
1557
	
1557
 
1558
			#如果允許不被信任的憑證
1558
			#如果允許不被信任的憑證
1559
			if($conf["allowAnySSLcertificate"]==="true"){
1559
			if($conf["allowAnySSLcertificate"]==="true"){
1560
 
1560
 
1561
				#設置 -k 參數
1561
				#設置 -k 參數
1562
				$arguments[]="-k";
1562
				$arguments[]="-k";
1563
 
1563
 
1564
				#要包住參數
1564
				#要包住參數
1565
				$plainArgu[]="false";
1565
				$plainArgu[]="false";
1566
				
1566
 
1567
				#不要改用「'」包住參數
1567
				#不要改用「'」包住參數
1568
				$useApostrophe[]="false";
1568
				$useApostrophe[]="false";
1569
 
1569
 
1570
				}#if end
1570
				}#if end
1571
 
1571
 
Line 1586... Line 1586...
1586
			#設置post變數
1586
			#設置post變數
1587
			$arguments[]=$header;
1587
			$arguments[]=$header;
1588
 
1588
 
1589
			#要包住參數
1589
			#要包住參數
1590
			$plainArgu[]="false";
1590
			$plainArgu[]="false";
1591
			
1591
 
1592
			#不要改用「'」包住參數
1592
			#不要改用「'」包住參數
1593
			$useApostrophe[]="false";
1593
			$useApostrophe[]="false";
1594
 
1594
 
1595
			}#foreach end
1595
			}#foreach end
1596
 
1596
 
Line 1628... Line 1628...
1628
			#設置post變數
1628
			#設置post變數
1629
			$arguments[]=$name."=".$value;
1629
			$arguments[]=$name."=".$value;
1630
 
1630
 
1631
			#要包住參數
1631
			#要包住參數
1632
			$plainArgu[]="false";
1632
			$plainArgu[]="false";
1633
			
1633
 
1634
			#不要改用「'」包住參數
1634
			#不要改用「'」包住參數
1635
			$useApostrophe[]="false";
1635
			$useApostrophe[]="false";
1636
 
1636
 
1637
			}#foreach end
1637
			}#foreach end
1638
			
1638
 
1639
		#如果有設置 $conf["rawPost"]
1639
		#如果有設置 $conf["rawPost"]
1640
		if(isset($conf["rawPost"])){
1640
		if(isset($conf["rawPost"])){
1641
		
1641
 
1642
			#如果沒有要url encode
1642
			#如果沒有要url encode
1643
			if($conf["urlEncode"]==="false"){
1643
			if($conf["urlEncode"]==="false"){
1644
 
1644
 
1645
				#設置post參數
1645
				#設置post參數
1646
				$arguments[]="-d";
1646
				$arguments[]="-d";
1647
				
1647
 
1648
				#要包住參數
1648
				#要包住參數
1649
				$plainArgu[]="false";
1649
				$plainArgu[]="false";
1650
				
1650
 
1651
				#不要改用「'」包住參數
1651
				#不要改用「'」包住參數
1652
				$useApostrophe[]="false";
1652
				$useApostrophe[]="false";
1653
				
1653
 
1654
				#數值post vlaue
1654
				#數值post vlaue
1655
				$arguments[]=$conf["rawPost"];
1655
				$arguments[]=$conf["rawPost"];
1656
 
1656
 
1657
				#要包住參數
1657
				#要包住參數
1658
				$plainArgu[]="false";
1658
				$plainArgu[]="false";
1659
				
1659
 
1660
				#改用「'」包住參數
1660
				#改用「'」包住參數
1661
				$useApostrophe[]="true";
1661
				$useApostrophe[]="true";
1662
 
1662
 
1663
				}#if end
1663
				}#if end
1664
 
1664
 
1665
			#反之要 url encode
1665
			#反之要 url encode
1666
			else{
1666
			else{
1667
 
1667
 
1668
				#設置post參數
1668
				#設置post參數
1669
				$arguments[]="--data-urlencode";
1669
				$arguments[]="--data-urlencode";
1670
				
1670
 
1671
				#要包住參數
1671
				#要包住參數
1672
				$plainArgu[]="false";
1672
				$plainArgu[]="false";
1673
				
1673
 
1674
				#不要改用「'」包住參數
1674
				#不要改用「'」包住參數
1675
				$useApostrophe[]="false";
1675
				$useApostrophe[]="false";
1676
				
1676
 
1677
				#數值post vlaue
1677
				#數值post vlaue
1678
				$arguments[]=$conf["rawPost"];
1678
				$arguments[]=$conf["rawPost"];
1679
 
1679
 
1680
				#要包住參數
1680
				#要包住參數
1681
				$plainArgu[]="false";
1681
				$plainArgu[]="false";
1682
				
1682
 
1683
				#改用「'」包住參數
1683
				#改用「'」包住參數
1684
				$useApostrophe[]="true";
1684
				$useApostrophe[]="true";
1685
 
1685
 
1686
				}#else end
1686
				}#else end
1687
		
1687
 
1688
			}#if end
1688
			}#if end
1689
 
1689
 
1690
		#如果有設置 agent
1690
		#如果有設置 agent
1691
		if(isset($conf["agent"])){
1691
		if(isset($conf["agent"])){
1692
 
1692
 
Line 1702... Line 1702...
1702
			#設置agent參數值
1702
			#設置agent參數值
1703
			$arguments[]=$conf["agent"];
1703
			$arguments[]=$conf["agent"];
1704
 
1704
 
1705
			#要包住參數
1705
			#要包住參數
1706
			$plainArgu[]="false";
1706
			$plainArgu[]="false";
1707
			
1707
 
1708
			#不要改用「'」包住參數
1708
			#不要改用「'」包住參數
1709
			$useApostrophe[]="false";
1709
			$useApostrophe[]="false";
1710
	
1710
 
1711
			}#if end
1711
			}#if end
1712
		
1712
 
1713
		#遇到大於 400 的 http 回應要回傳異常
1713
		#遇到大於 400 的 http 回應要回傳異常
1714
		$arguments[]="--fail";
1714
		$arguments[]="--fail";
1715
 
1715
 
1716
		#要求的網址用 " " 包起來
1716
		#要求的網址用 " " 包起來
1717
		$arguments[]=$conf["url"];
1717
		$arguments[]=$conf["url"];
Line 1739... Line 1739...
1739
 
1739
 
1740
					#不要改用「'」包住參數
1740
					#不要改用「'」包住參數
1741
					$useApostrophe[]="false";
1741
					$useApostrophe[]="false";
1742
 
1742
 
1743
					}#if end
1743
					}#if end
1744
					
1744
 
1745
				# 反之使用新的cookie
1745
				# 反之使用新的cookie
1746
				else{
1746
				else{
1747
 
1747
 
1748
					$arguments[]="-c ".$conf["cookie"];
1748
					$arguments[]="-c ".$conf["cookie"];
1749
 
1749
 
Line 1760... Line 1760...
1760
			#反之不存在 cookie 檔案
1760
			#反之不存在 cookie 檔案
1761
			else{
1761
			else{
1762
 
1762
 
1763
				#設置使用新的cookie
1763
				#設置使用新的cookie
1764
				$arguments[]="-c ".$conf["cookie"];
1764
				$arguments[]="-c ".$conf["cookie"];
1765
				
1765
 
1766
				#不要包住參數
1766
				#不要包住參數
1767
				$plainArgu[]="true";
1767
				$plainArgu[]="true";
1768
 
1768
 
1769
				#不要改用「'」包住參數
1769
				#不要改用「'」包住參數
1770
				$useApostrophe[]="false";
1770
				$useApostrophe[]="false";
Line 1773... Line 1773...
1773
 
1773
 
1774
			}#if end
1774
			}#if end
1775
 
1775
 
1776
		#如果要允許轉址
1776
		#如果要允許轉址
1777
		if($conf["followRedirection"]==="true"){
1777
		if($conf["followRedirection"]==="true"){
1778
		
1778
 
1779
			#follow redirection - start
1779
			#follow redirection - start
1780
			$arguments[]="-L";
1780
			$arguments[]="-L";
1781
					
1781
 
1782
			#不要包住參數
1782
			#不要包住參數
1783
			$plainArgu[]="true";
1783
			$plainArgu[]="true";
1784
 
1784
 
1785
			#不要改用「'」包住參數
1785
			#不要改用「'」包住參數
1786
			$useApostrophe[]="false";
1786
			$useApostrophe[]="false";
1787
		
1787
 
1788
			}#if end
1788
			}#if end
1789
 
1789
 
1790
		#要執行的command
1790
		#要執行的command
1791
		$cmd="curl";
1791
		$cmd="curl";
1792
 
1792
 
1793
		#如果要透過 proc 放在背景中運行
1793
		#如果要透過 proc 放在背景中運行
1794
		if( $conf["inBg"]==="true" && $conf["bgInProc"]==="true" ){
1794
		if( $conf["inBg"]==="true" && $conf["bgInProc"]==="true" ){
1795
		
1795
 
1796
			#涵式說明:
1796
			#涵式說明:
1797
			#呼叫shell執行系統命令,並取得回傳的內容.
1797
			#呼叫shell執行系統命令,並取得回傳的內容.
1798
			#回傳的結果:
1798
			#回傳的結果:
1799
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1799
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1800
			#$result["error"],錯誤訊息陣列.
1800
			#$result["error"],錯誤訊息陣列.
Line 1848... Line 1848...
1848
			#exec=>http://php.net/manual/en/function.exec.php
1848
			#exec=>http://php.net/manual/en/function.exec.php
1849
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1849
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1850
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1850
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1851
			$callShell=external::callShell($conf["external::callShell"]);
1851
			$callShell=external::callShell($conf["external::callShell"]);
1852
			unset($conf["external::callShell"]);
1852
			unset($conf["external::callShell"]);
1853
		
1853
 
1854
			#如果尋找關鍵字失敗
1854
			#如果尋找關鍵字失敗
1855
			if($callShell["status"]==="false"){
1855
			if($callShell["status"]==="false"){
1856
 
1856
 
1857
				#設置執行失敗
1857
				#設置執行失敗
1858
				$result["status"]="false";
1858
				$result["status"]="false";
Line 1862... Line 1862...
1862
 
1862
 
1863
				#回傳結果
1863
				#回傳結果
1864
				return $result;
1864
				return $result;
1865
 
1865
 
1866
				}#if end
1866
				}#if end
1867
		
1867
 
1868
			#初始化要透過proc執行的指令
1868
			#初始化要透過proc執行的指令
1869
			$cmdAndArguForThreadsProc=$callShell["escape"]["array"];
1869
			$cmdAndArguForThreadsProc=$callShell["escape"]["array"];
1870
		
1870
 
1871
			#函式說明:
1871
			#函式說明:
1872
			#透過proc來多執行序運作.
1872
			#透過proc來多執行序運作.
1873
			#回傳結果:
1873
			#回傳結果:
1874
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1874
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1875
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1875
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 1893... Line 1893...
1893
			#https://www.php.net/manual/en/function.proc-get-status.php
1893
			#https://www.php.net/manual/en/function.proc-get-status.php
1894
			#備註:
1894
			#備註:
1895
			#無.
1895
			#無.
1896
			$proc=threads::proc($conf["threads::proc"]);
1896
			$proc=threads::proc($conf["threads::proc"]);
1897
			unset($conf["threads::proc"]);
1897
			unset($conf["threads::proc"]);
1898
		
1898
 
1899
			#如果尋找關鍵字失敗
1899
			#如果尋找關鍵字失敗
1900
			if($proc["status"]==="false"){
1900
			if($proc["status"]==="false"){
1901
 
1901
 
1902
				#設置執行失敗
1902
				#設置執行失敗
1903
				$result["status"]="false";
1903
				$result["status"]="false";
Line 1907... Line 1907...
1907
 
1907
 
1908
				#回傳結果
1908
				#回傳結果
1909
				return $result;
1909
				return $result;
1910
 
1910
 
1911
				}#if end
1911
				}#if end
1912
				
1912
 
1913
			#取得 proc 資訊
1913
			#取得 proc 資訊
1914
			$result["content"]=$proc["content"];
1914
			$result["content"]=$proc["content"];
1915
		
1915
 
1916
			#設置執行正常
1916
			#設置執行正常
1917
			$result["status"]="true";
1917
			$result["status"]="true";
1918
		
1918
 
1919
			#回傳結果
1919
			#回傳結果
1920
			return $result;
1920
			return $result;
1921
		
1921
 
1922
			}#if end
1922
			}#if end
1923
 
1923
 
1924
		#涵式說明:
1924
		#涵式說明:
1925
		#呼叫shell執行系統命令,並取得回傳的內容.
1925
		#呼叫shell執行系統命令,並取得回傳的內容.
1926
		#回傳的結果:
1926
		#回傳的結果:
Line 1976... Line 1976...
1976
		#如果執行失敗
1976
		#如果執行失敗
1977
		if($callShell["status"]==="false"){
1977
		if($callShell["status"]==="false"){
1978
 
1978
 
1979
			#如果不是response header >= 400
1979
			#如果不是response header >= 400
1980
			if($callShell["statusCode"]!==22){
1980
			if($callShell["statusCode"]!==22){
1981
			
1981
 
1982
				#設置執行失敗
1982
				#設置執行失敗
1983
				$result["status"]="false";
1983
				$result["status"]="false";
1984
 
1984
 
1985
				#設置執行錯誤
1985
				#設置執行錯誤
1986
				$result["error"]=$callShell;
1986
				$result["error"]=$callShell;
1987
 
1987
 
1988
				#回傳結果
1988
				#回傳結果
1989
				return $result;
1989
				return $result;
1990
			
1990
 
1991
				}#if end
1991
				}#if end
1992
 
1992
 
1993
			}#if end
1993
			}#if end
1994
			
1994
 
1995
		#反之
1995
		#反之
1996
		else{
1996
		else{
1997
		
1997
 
1998
			#設置網址找到
1998
			#設置網址找到
1999
			$result["founded"]="true";
1999
			$result["founded"]="true";
2000
		
2000
 
2001
			}#else end
2001
			}#else end
2002
 
2002
 
2003
		#儲存得到的回應
2003
		#儲存得到的回應
2004
		$result["content"]=$callShell["output"];
2004
		$result["content"]=$callShell["output"];
2005
 
2005
 
2006
		#初始化完整回應為空字串
2006
		#初始化完整回應為空字串
2007
		$result["fullContent"]="";
2007
		$result["fullContent"]="";
2008
 
2008
 
2009
		#針對每列回應
2009
		#針對每列回應
2010
		foreach($result["content"] as $line){
2010
		foreach($result["content"] as $line){
2011
		
2011
 
2012
			#串接結果
2012
			#串接結果
2013
			$result["fullContent"]=$result["fullContent"].$line;
2013
			$result["fullContent"]=$result["fullContent"].$line;
2014
			
2014
 
2015
			}#foreach end
2015
			}#foreach end
2016
 
2016
 
2017
		#儲存執行的command
2017
		#儲存執行的command
2018
		$result["cmd"]=$callShell["cmd"];
2018
		$result["cmd"]=$callShell["cmd"];
2019
 
2019