| Line 549... |
Line 549... |
| 549 |
#$conf["cmdContainArgu"]="false";
|
549 |
#$conf["cmdContainArgu"]="false";
|
| 550 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
550 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
| 551 |
#$conf["remoteIp"]="";
|
551 |
#$conf["remoteIp"]="";
|
| 552 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
552 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
| 553 |
#$conf["remoteUser"]="";
|
553 |
#$conf["remoteUser"]="";
|
| - |
|
554 |
#$conf["sshOptions"],陣列,當具備 "remoteIp" 參數時,該參數每個元素為ssh指令的參數.
|
| - |
|
555 |
#$conf["sshOptions"]=array();
|
| 554 |
#參考資料:
|
556 |
#參考資料:
|
| 555 |
#exec=>http://php.net/manual/en/function.exec.php
|
557 |
#exec=>http://php.net/manual/en/function.exec.php
|
| 556 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
558 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
| 557 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
559 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
| 558 |
#備註:
|
560 |
#備註:
|
| Line 613... |
Line 615... |
| 613 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
615 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
| 614 |
#可以省略的參數:
|
616 |
#可以省略的參數:
|
| 615 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
617 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
| 616 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
618 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
| 617 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
619 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 618 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","doNotRun","thereIsShellVar","remoteIp","remoteUser","cmdContainArgu");
|
620 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","enablePrintDescription","printDescription","argu","escapeshellarg","username","password","useScript","logFilePath","inBackGround","arguIsAddr","getErr","doNotRun","thereIsShellVar","remoteIp","remoteUser","cmdContainArgu","sshOptions");
|
| 619 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
621 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 620 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","string","array","string","string","string");
|
622 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","array","string","string","string","string","string","string","array","string","string","array","string","string","string","array");
|
| 621 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
623 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 622 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,null,"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false","false",null,null,null,"false");
|
624 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"false",null,array(),"false",null,null,"false",".qbpwcf_tmp/external/callShell/","false",null,"false","false",null,null,null,"false",array());
|
| 623 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
625 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
| 624 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("argu","arguIsAddr");
|
626 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("argu","arguIsAddr");
|
| 625 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
627 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 626 |
unset($conf["variableCheck::checkArguments"]);
|
628 |
unset($conf["variableCheck::checkArguments"]);
|
| 627 |
|
629 |
|
| 628 |
#如果檢查參數失敗
|
630 |
#如果檢查參數失敗
|
| 629 |
if($checkResult["status"]=="false"){
|
631 |
if($checkResult["status"]==="false"){
|
| 630 |
|
632 |
|
| 631 |
#設置執行失敗
|
633 |
#設置執行失敗
|
| 632 |
$result["status"]="false";
|
634 |
$result["status"]="false";
|
| 633 |
|
635 |
|
| 634 |
#設置執行錯誤
|
636 |
#設置執行錯誤
|
| Line 638... |
Line 640... |
| 638 |
return $result;
|
640 |
return $result;
|
| 639 |
|
641 |
|
| 640 |
}#if end
|
642 |
}#if end
|
| 641 |
|
643 |
|
| 642 |
#如果檢查參數不通過
|
644 |
#如果檢查參數不通過
|
| 643 |
if($checkResult["passed"]=="false"){
|
645 |
if($checkResult["passed"]==="false"){
|
| 644 |
|
646 |
|
| 645 |
#設置執行失敗
|
647 |
#設置執行失敗
|
| 646 |
$result["status"]="false";
|
648 |
$result["status"]="false";
|
| 647 |
|
649 |
|
| 648 |
#設置執行錯誤
|
650 |
#設置執行錯誤
|
| Line 784... |
Line 786... |
| 784 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
786 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
| 785 |
#必填參數:
|
787 |
#必填參數:
|
| 786 |
#$conf["input"],字串,要檢查的字串.
|
788 |
#$conf["input"],字串,要檢查的字串.
|
| 787 |
$conf["search::findSpecifyStrFormat"]["input"]=$conf["command"];
|
789 |
$conf["search::findSpecifyStrFormat"]["input"]=$conf["command"];
|
| 788 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
790 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
| 789 |
$conf["search::findSpecifyStrFormat"]["format"]="${cmdAndArgu} | ssh ${remoteIp}";
|
791 |
$conf["search::findSpecifyStrFormat"]["format"]="\${cmdAndArgu} | ssh \${options}";
|
| 790 |
#可省略參數:
|
792 |
#可省略參數:
|
| 791 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
793 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
| 792 |
$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,null);
|
794 |
$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,null);
|
| 793 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
795 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
| 794 |
#$conf["varCon"]=array("no_tail"=>" not");
|
796 |
#$conf["varCon"]=array("no_tail"=>" not");
|
| Line 809... |
Line 811... |
| 809 |
$result["status"]="false";
|
811 |
$result["status"]="false";
|
| 810 |
|
812 |
|
| 811 |
return $result;
|
813 |
return $result;
|
| 812 |
|
814 |
|
| 813 |
}#if end
|
815 |
}#if end
|
| - |
|
816 |
|
| - |
|
817 |
#取得原始的程式與參數
|
| - |
|
818 |
$cmdAndArgu=$findSpecifyStrFormat["parsedVar"]["cmdAndArgu"][0];
|
| - |
|
819 |
|
| - |
|
820 |
#debug
|
| - |
|
821 |
#var_dump(__LINE__,$cmdAndArgu,$findSpecifyStrFormat["parsedVar"],$conf["command"]);
|
| - |
|
822 |
|
| - |
|
823 |
#解析成指令與參數
|
| - |
|
824 |
#函式說明:
|
| - |
|
825 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
| - |
|
826 |
#回傳結果:
|
| - |
|
827 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| - |
|
828 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
| - |
|
829 |
#$result["function"],當前執行的函式名稱.
|
| - |
|
830 |
#$result["content"],解析好的指令陣列.
|
| - |
|
831 |
#$result["cmd"],解析好的指令名稱.
|
| - |
|
832 |
#$result["argus"],解析好的參數陣列.
|
| - |
|
833 |
#$result["argu"],所使用的參數.
|
| - |
|
834 |
#必填參數
|
| - |
|
835 |
#$conf["cmdStr"],字串,要解析的指令字串
|
| - |
|
836 |
$conf["cmd::parseCmdString"]["cmdStr"]=$cmdAndArgu;
|
| - |
|
837 |
#可省略參數:
|
| - |
|
838 |
#無.
|
| - |
|
839 |
#參考資料:
|
| - |
|
840 |
#無.
|
| - |
|
841 |
#備註:
|
| - |
|
842 |
#無.
|
| - |
|
843 |
$parseCmdString=cmd::parseCmdString($conf["cmd::parseCmdString"]);
|
| - |
|
844 |
unset($conf["cmd::parseCmdString"]);
|
| - |
|
845 |
|
| - |
|
846 |
#若執行異常
|
| - |
|
847 |
if($parseCmdString["status"]==="false"){
|
| - |
|
848 |
|
| - |
|
849 |
#設置執行錯誤
|
| - |
|
850 |
$result["error"]=$parseCmdString;
|
| - |
|
851 |
|
| - |
|
852 |
#設置執行異常識別
|
| - |
|
853 |
$result["status"]="false";
|
| 814 |
|
854 |
|
| - |
|
855 |
return $result;
|
| - |
|
856 |
|
| - |
|
857 |
}#if end
|
| - |
|
858 |
|
| 815 |
#如果有找到符合的格式
|
859 |
#如果有找到符合的格式
|
| 816 |
if($findSpecifyStrFormat["found"]==="true"){
|
860 |
if($findSpecifyStrFormat["found"]==="true"){
|
| 817 |
|
861 |
|
| - |
|
862 |
#取得要執行的指令
|
| - |
|
863 |
$conf["command"]=$parseCmdString["cmd"];
|
| - |
|
864 |
|
| - |
|
865 |
#取得要使用的參數
|
| - |
|
866 |
$conf["argu"]=$parseCmdString["argus"];
|
| - |
|
867 |
|
| 818 |
#取得尚未解析的指令與參數
|
868 |
#取得尚未解析的指令與參數
|
| - |
|
869 |
$options=$findSpecifyStrFormat["parsedVar"]["options"][0];
|
| - |
|
870 |
|
| - |
|
871 |
#解析 $options
|
| - |
|
872 |
#函式說明:
|
| - |
|
873 |
#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
|
| - |
|
874 |
#回傳結果:
|
| - |
|
875 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| - |
|
876 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
| - |
|
877 |
#$result["function"],當前執行的函式名稱.
|
| - |
|
878 |
#$result["argu"],所使用的參數.
|
| - |
|
879 |
#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
|
| - |
|
880 |
#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
|
| - |
|
881 |
#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容,變數的key從0開始.
|
| - |
|
882 |
#必填參數:
|
| - |
|
883 |
#$conf["input"],字串,要檢查的字串.
|
| - |
|
884 |
$conf["search::findSpecifyStrFormat"]["input"]=$options;
|
| - |
|
885 |
#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
|
| - |
|
886 |
$conf["search::findSpecifyStrFormat"]["format"]="\${left}@\${right}";
|
| - |
|
887 |
#可省略參數:
|
| - |
|
888 |
#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
|
| - |
|
889 |
$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,null);
|
| 819 |
$cmdAndArgu=$findSpecifyStrFormat["parsedVar"]["cmdAndArgu"][0];
|
890 |
#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
|
| - |
|
891 |
#$conf["varCon"]=array("no_tail"=>" not");
|
| - |
|
892 |
#參考資料:
|
| - |
|
893 |
#無.
|
| - |
|
894 |
#備註:
|
| - |
|
895 |
#無.
|
| - |
|
896 |
$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
|
| - |
|
897 |
unset($conf["search::findSpecifyStrFormat"]);
|
| - |
|
898 |
|
| - |
|
899 |
#若執行異常
|
| - |
|
900 |
if($findSpecifyStrFormat["status"]==="false"){
|
| - |
|
901 |
|
| - |
|
902 |
#設置執行錯誤
|
| - |
|
903 |
$result["error"]=$findSpecifyStrFormat;
|
| - |
|
904 |
|
| - |
|
905 |
#設置執行異常識別
|
| - |
|
906 |
$result["status"]="false";
|
| - |
|
907 |
|
| - |
|
908 |
return $result;
|
| - |
|
909 |
|
| - |
|
910 |
}#if end
|
| - |
|
911 |
|
| - |
|
912 |
#如果有找到符合的格式
|
| - |
|
913 |
if($findSpecifyStrFormat["found"]==="true"){
|
| - |
|
914 |
|
| - |
|
915 |
#代表有指定遠端使用者與ip
|
| - |
|
916 |
|
| - |
|
917 |
#取得尚未解析的左邊指令與參數
|
| - |
|
918 |
$leftContainUser=$findSpecifyStrFormat["parsedVar"]["left"][0];
|
| - |
|
919 |
|
| - |
|
920 |
#函式說明:
|
| - |
|
921 |
#將字串進行解析,變成多個參數.
|
| - |
|
922 |
#回傳結果:
|
| - |
|
923 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
| - |
|
924 |
#$result["function"],當前執行的函式內容.
|
| - |
|
925 |
#$result["error"],錯誤訊息陣列.
|
| - |
|
926 |
#$result["content"],參數陣列.
|
| - |
|
927 |
#$result["count"],總共有幾個參數.
|
| - |
|
928 |
#必填參數:
|
| - |
|
929 |
#$conf["input"],字串,要解析成參數的字串.
|
| - |
|
930 |
$conf["stringProcess::parse"]["input"]=$leftContainUser;
|
| - |
|
931 |
#可省略參數:
|
| - |
|
932 |
#無.
|
| - |
|
933 |
#參考資料:
|
| - |
|
934 |
#無.
|
| - |
|
935 |
#備註:
|
| - |
|
936 |
#無.
|
| - |
|
937 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
| - |
|
938 |
unset($conf["stringProcess::parse"]);
|
| - |
|
939 |
|
| - |
|
940 |
#若執行異常
|
| - |
|
941 |
if($parse["status"]==="false"){
|
| - |
|
942 |
|
| - |
|
943 |
#設置執行錯誤
|
| - |
|
944 |
$result["error"]=$parse;
|
| - |
|
945 |
|
| - |
|
946 |
#設置執行異常識別
|
| - |
|
947 |
$result["status"]="false";
|
| - |
|
948 |
|
| - |
|
949 |
return $result;
|
| - |
|
950 |
|
| - |
|
951 |
}#if end
|
| - |
|
952 |
|
| - |
|
953 |
#取得遠端使用者名稱
|
| - |
|
954 |
$conf["remoteUser"]=$parse["content"][$parse["count"]-1];
|
| - |
|
955 |
|
| - |
|
956 |
#初始ssh的額外參數
|
| - |
|
957 |
$sshOptions=array();
|
| - |
|
958 |
|
| - |
|
959 |
#如果還有其他參數
|
| - |
|
960 |
if($parse["count"]>1){
|
| - |
|
961 |
|
| - |
|
962 |
#移除已經解析好的參數
|
| - |
|
963 |
unset($parse["content"][$parse["count"]-1]);
|
| - |
|
964 |
|
| - |
|
965 |
#取得ssh的額外參數
|
| - |
|
966 |
$sshOptions=$parse["content"];
|
| - |
|
967 |
|
| - |
|
968 |
}#if end
|
| - |
|
969 |
|
| - |
|
970 |
#取得尚未解析的右邊指令與參數
|
| - |
|
971 |
$rightContainUser=$findSpecifyStrFormat["parsedVar"]["right"][0];
|
| - |
|
972 |
|
| - |
|
973 |
#函式說明:
|
| - |
|
974 |
#將字串進行解析,變成多個參數.
|
| - |
|
975 |
#回傳結果:
|
| - |
|
976 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
| - |
|
977 |
#$result["function"],當前執行的函式內容.
|
| - |
|
978 |
#$result["error"],錯誤訊息陣列.
|
| - |
|
979 |
#$result["content"],參數陣列.
|
| - |
|
980 |
#$result["count"],總共有幾個參數.
|
| - |
|
981 |
#必填參數:
|
| - |
|
982 |
#$conf["input"],字串,要解析成參數的字串.
|
| - |
|
983 |
$conf["stringProcess::parse"]["input"]=$rightContainUser;
|
| - |
|
984 |
#可省略參數:
|
| - |
|
985 |
#無.
|
| - |
|
986 |
#參考資料:
|
| - |
|
987 |
#無.
|
| - |
|
988 |
#備註:
|
| - |
|
989 |
#無.
|
| - |
|
990 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
| - |
|
991 |
unset($conf["stringProcess::parse"]);
|
| - |
|
992 |
|
| - |
|
993 |
#若執行異常
|
| - |
|
994 |
if($parse["status"]==="false"){
|
| - |
|
995 |
|
| - |
|
996 |
#設置執行錯誤
|
| - |
|
997 |
$result["error"]=$parse;
|
| - |
|
998 |
|
| - |
|
999 |
#設置執行異常識別
|
| - |
|
1000 |
$result["status"]="false";
|
| - |
|
1001 |
|
| - |
|
1002 |
return $result;
|
| - |
|
1003 |
|
| - |
|
1004 |
}#if end
|
| - |
|
1005 |
|
| - |
|
1006 |
#取得遠端使用者名稱
|
| - |
|
1007 |
$conf["remoteIp"]=$parse["content"][0];
|
| - |
|
1008 |
|
| - |
|
1009 |
#如果還有其他參數
|
| - |
|
1010 |
if($parse["count"]>1){
|
| - |
|
1011 |
|
| - |
|
1012 |
#移除已經解析好的參數
|
| - |
|
1013 |
unset($parse["content"][0]);
|
| - |
|
1014 |
|
| - |
|
1015 |
#合併參數
|
| - |
|
1016 |
#$parse["content"];
|
| - |
|
1017 |
|
| - |
|
1018 |
#函式說明:
|
| - |
|
1019 |
#將多個一維陣列串聯起來,key從0開始排序.
|
| - |
|
1020 |
#回傳的結果:
|
| - |
|
1021 |
#$result["status"],"true"表執行正常,"false"代表執行不正常.
|
| - |
|
1022 |
#$result["error"],錯誤訊息陣列.
|
| - |
|
1023 |
#$result["function"],當前執行的函數.
|
| - |
|
1024 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
| - |
|
1025 |
#$result["content"],合併好的一維陣列.
|
| - |
|
1026 |
#必填參數
|
| - |
|
1027 |
#$conf["inputArray"],陣列,要合併的一維陣列變數,例如:=array($array1,$array2);
|
| - |
|
1028 |
$conf["arrays::mergeArray"]["inputArray"]=array($sshOptions,$parse["content"]);
|
| - |
|
1029 |
#可省略參數:
|
| - |
|
1030 |
#$conf["allowRepeat"],字串,預設為"true",允許重複的結果;若為"false"則不會出現重複的元素內容.
|
| - |
|
1031 |
#$conf["allowRepeat"]="true";
|
| - |
|
1032 |
#$conf["looseDiff"],字串,預設為"false",代表要嚴謹判斷為有相異,例如陣列中元素的key順序不同(整數)就代表有相異;反之為"true",例如陣列中元素的key順序不同(非整數),但value有相同,則視為無相異.
|
| - |
|
1033 |
#$conf["looseDiff"]="false";
|
| - |
|
1034 |
#參考資料:
|
| - |
|
1035 |
#無.
|
| - |
|
1036 |
#備註:
|
| - |
|
1037 |
#無.
|
| - |
|
1038 |
$mergeArray=arrays::mergeArray($conf["arrays::mergeArray"]);
|
| - |
|
1039 |
unset($conf["arrays::mergeArray"]);
|
| - |
|
1040 |
|
| - |
|
1041 |
#若執行異常
|
| - |
|
1042 |
if($mergeArray["status"]==="false"){
|
| - |
|
1043 |
|
| - |
|
1044 |
#設置執行錯誤
|
| - |
|
1045 |
$result["error"]=$mergeArray;
|
| - |
|
1046 |
|
| - |
|
1047 |
#設置執行異常識別
|
| - |
|
1048 |
$result["status"]="false";
|
| - |
|
1049 |
|
| - |
|
1050 |
return $result;
|
| - |
|
1051 |
|
| - |
|
1052 |
}#if end
|
| - |
|
1053 |
|
| - |
|
1054 |
#取得合併好的ssh額外參數
|
| - |
|
1055 |
$conf["sshOptions"]=$mergeArray["content"];
|
| - |
|
1056 |
|
| - |
|
1057 |
#遞迴
|
| - |
|
1058 |
#函式說明:
|
| - |
|
1059 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
| - |
|
1060 |
#回傳結果:
|
| - |
|
1061 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| - |
|
1062 |
#$result["error"],錯誤訊息陣列.
|
| - |
|
1063 |
#$result["function"],當前執行的函數名稱.
|
| - |
|
1064 |
#$result["argu"],使用的參數.
|
| - |
|
1065 |
#$result["cmd"],執行的指令內容.
|
| - |
|
1066 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
| - |
|
1067 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
| - |
|
1068 |
#$result["content"],為執行完後的輸出字串.
|
| - |
|
1069 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
| - |
|
1070 |
#$result["running"],是否還在執行.
|
| - |
|
1071 |
#$result["pid"],pid.
|
| - |
|
1072 |
#$result["statusCode"],執行結束後的代碼.
|
| - |
|
1073 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
| - |
|
1074 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
| - |
|
1075 |
#必填參數:
|
| - |
|
1076 |
#$conf["command"],字串,要執行的指令.
|
| - |
|
1077 |
#$conf["command"]="ssh";
|
| - |
|
1078 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| - |
|
1079 |
#$conf["fileArgu"]=__FILE__;
|
| - |
|
1080 |
#可省略參數:
|
| - |
|
1081 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| - |
|
1082 |
#$conf["argu"]=array("");
|
| - |
|
1083 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
| - |
|
1084 |
#$conf["arguIsAddr"]=array();
|
| - |
|
1085 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
| - |
|
1086 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
| - |
|
1087 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
| - |
|
1088 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
| - |
|
1089 |
#$conf["enablePrintDescription"]="true";
|
| - |
|
1090 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
| - |
|
1091 |
#$conf["printDescription"]="";
|
| - |
|
1092 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
| - |
|
1093 |
#$conf["escapeshellarg"]="false";
|
| - |
|
1094 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
| - |
|
1095 |
#$conf["thereIsShellVar"]=array();
|
| - |
|
1096 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
| - |
|
1097 |
#$conf["username"]="";
|
| - |
|
1098 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
| - |
|
1099 |
#$conf["password"]="";
|
| - |
|
1100 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
| - |
|
1101 |
#$conf["useScript"]="";
|
| - |
|
1102 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
| - |
|
1103 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
| - |
|
1104 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
| - |
|
1105 |
#$conf["inBackGround"]="";
|
| - |
|
1106 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
| - |
|
1107 |
#$conf["getErr"]="false";
|
| - |
|
1108 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
| - |
|
1109 |
#$conf["doNotRun"]="false";
|
| - |
|
1110 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
| - |
|
1111 |
$conf["cmdContainArgu"]="false";
|
| - |
|
1112 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
| - |
|
1113 |
#$conf["remoteIp"]="";
|
| - |
|
1114 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
| - |
|
1115 |
#$conf["remoteUser"]="";
|
| - |
|
1116 |
#$conf["sshOptions"],陣列,當具備 "remoteIp" 參數時,該參數每個元素為ssh指令的參數.
|
| - |
|
1117 |
#$conf["sshOptions"]=$conf["sshOptions"];
|
| - |
|
1118 |
#參考資料:
|
| - |
|
1119 |
#exec=>http://php.net/manual/en/function.exec.php
|
| - |
|
1120 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
| - |
|
1121 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
| - |
|
1122 |
#備註:
|
| - |
|
1123 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
| - |
|
1124 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
| - |
|
1125 |
return external::callShell($conf);
|
| - |
|
1126 |
|
| - |
|
1127 |
}#if end
|
| - |
|
1128 |
|
| - |
|
1129 |
#反之
|
| - |
|
1130 |
else{
|
| - |
|
1131 |
|
| - |
|
1132 |
#只有指定 ip 或 domain name 以及可能有額外 ssh 參數
|
| - |
|
1133 |
|
| - |
|
1134 |
#函式說明:
|
| - |
|
1135 |
#將字串進行解析,變成多個參數.
|
| - |
|
1136 |
#回傳結果:
|
| - |
|
1137 |
#$result["status"],執行正常與否,"false"代表不正常,"true"代表正常.
|
| - |
|
1138 |
#$result["function"],當前執行的函式內容.
|
| - |
|
1139 |
#$result["error"],錯誤訊息陣列.
|
| - |
|
1140 |
#$result["content"],參數陣列.
|
| - |
|
1141 |
#$result["count"],總共有幾個參數.
|
| - |
|
1142 |
#必填參數:
|
| - |
|
1143 |
#$conf["input"],字串,要解析成參數的字串.
|
| - |
|
1144 |
$conf["stringProcess::parse"]["input"]=$options;
|
| - |
|
1145 |
#可省略參數:
|
| - |
|
1146 |
#無.
|
| - |
|
1147 |
#參考資料:
|
| - |
|
1148 |
#無.
|
| - |
|
1149 |
#備註:
|
| - |
|
1150 |
#無.
|
| - |
|
1151 |
$parse=stringProcess::parse($conf["stringProcess::parse"]);
|
| - |
|
1152 |
unset($conf["stringProcess::parse"]);
|
| - |
|
1153 |
|
| - |
|
1154 |
#若執行異常
|
| - |
|
1155 |
if($parse["status"]==="false"){
|
| - |
|
1156 |
|
| - |
|
1157 |
#設置執行錯誤
|
| - |
|
1158 |
$result["error"]=$parse;
|
| - |
|
1159 |
|
| - |
|
1160 |
#設置執行異常識別
|
| - |
|
1161 |
$result["status"]="false";
|
| - |
|
1162 |
|
| - |
|
1163 |
return $result;
|
| - |
|
1164 |
|
| - |
|
1165 |
}#if end
|
| - |
|
1166 |
|
| - |
|
1167 |
#取得 sshOptions
|
| - |
|
1168 |
$conf["sshOptions"]=$parse["content"];
|
| - |
|
1169 |
|
| - |
|
1170 |
}#else end
|
| - |
|
1171 |
|
| - |
|
1172 |
}#if end
|
| 820 |
|
1173 |
|
| 821 |
#函式說明:
|
1174 |
#函式說明:
|
| 822 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
1175 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
| 823 |
#回傳結果:
|
1176 |
#回傳結果:
|
| 824 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
1177 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| Line 904... |
Line 1257... |
| 904 |
|
1257 |
|
| 905 |
#設置cmd參數已經不含argu了
|
1258 |
#設置cmd參數已經不含argu了
|
| 906 |
$conf["cmdContainArgu"]="false";
|
1259 |
$conf["cmdContainArgu"]="false";
|
| 907 |
|
1260 |
|
| 908 |
#遞迴呼叫
|
1261 |
#遞迴呼叫
|
| - |
|
1262 |
|
| - |
|
1263 |
#函式說明:
|
| - |
|
1264 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
| - |
|
1265 |
#回傳結果:
|
| - |
|
1266 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| - |
|
1267 |
#$result["error"],錯誤訊息陣列.
|
| - |
|
1268 |
#$result["function"],當前執行的函數名稱.
|
| - |
|
1269 |
#$result["argu"],使用的參數.
|
| - |
|
1270 |
#$result["cmd"],執行的指令內容.
|
| - |
|
1271 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
| - |
|
1272 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
| - |
|
1273 |
#$result["content"],為執行完後的輸出字串.
|
| - |
|
1274 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
| - |
|
1275 |
#$result["running"],是否還在執行.
|
| - |
|
1276 |
#$result["pid"],pid.
|
| - |
|
1277 |
#$result["statusCode"],執行結束後的代碼.
|
| - |
|
1278 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
| - |
|
1279 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
| - |
|
1280 |
#必填參數:
|
| - |
|
1281 |
#$conf["command"],字串,要執行的指令.
|
| - |
|
1282 |
#$conf["command"]="";
|
| - |
|
1283 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| - |
|
1284 |
#$conf["fileArgu"]=__FILE__;
|
| - |
|
1285 |
#可省略參數:
|
| - |
|
1286 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| - |
|
1287 |
#$conf["argu"]=array("");
|
| - |
|
1288 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
| - |
|
1289 |
#$conf["arguIsAddr"]=array();
|
| - |
|
1290 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
| - |
|
1291 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
| - |
|
1292 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
| - |
|
1293 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
| - |
|
1294 |
#$conf["enablePrintDescription"]="true";
|
| - |
|
1295 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
| - |
|
1296 |
#$conf["printDescription"]="";
|
| - |
|
1297 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
| - |
|
1298 |
#$conf["escapeshellarg"]="false";
|
| - |
|
1299 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
| - |
|
1300 |
#$conf["thereIsShellVar"]=array();
|
| - |
|
1301 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
| - |
|
1302 |
#$conf["username"]="";
|
| - |
|
1303 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
| - |
|
1304 |
#$conf["password"]="";
|
| - |
|
1305 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
| - |
|
1306 |
#$conf["useScript"]="";
|
| - |
|
1307 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
| - |
|
1308 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
| - |
|
1309 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
| - |
|
1310 |
#$conf["inBackGround"]="";
|
| - |
|
1311 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
| - |
|
1312 |
#$conf["getErr"]="false";
|
| - |
|
1313 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
| - |
|
1314 |
#$conf["doNotRun"]="false";
|
| - |
|
1315 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
| - |
|
1316 |
$conf["cmdContainArgu"]="false";
|
| - |
|
1317 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
| - |
|
1318 |
#$conf["remoteIp"]="";
|
| - |
|
1319 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
| - |
|
1320 |
#$conf["remoteUser"]="";
|
| - |
|
1321 |
#$conf["sshOptions"],陣列,當具備 "remoteIp" 參數時,該參數每個元素為ssh指令的參數.
|
| - |
|
1322 |
#$conf["sshOptions"]=array();
|
| - |
|
1323 |
#參考資料:
|
| - |
|
1324 |
#exec=>http://php.net/manual/en/function.exec.php
|
| - |
|
1325 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
| - |
|
1326 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
| - |
|
1327 |
#備註:
|
| - |
|
1328 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
| - |
|
1329 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
| 909 |
return self::callShell($conf);
|
1330 |
return self::callShell($conf);
|
| 910 |
|
1331 |
|
| 911 |
}#if end
|
1332 |
}#if end
|
| 912 |
|
1333 |
|
| 913 |
#反之
|
1334 |
#反之
|
| 914 |
else{
|
1335 |
else{
|
| 915 |
|
1336 |
|
| 916 |
#函式說明:
|
1337 |
#函式說明:
|
| 917 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
1338 |
#將指令字串解析成陣列,方便給予 external::callShell 使用
|
| Line 996... |
Line 1417... |
| 996 |
|
1417 |
|
| 997 |
#設置cmd參數已經不含argu了
|
1418 |
#設置cmd參數已經不含argu了
|
| 998 |
$conf["cmdContainArgu"]="false";
|
1419 |
$conf["cmdContainArgu"]="false";
|
| 999 |
|
1420 |
|
| 1000 |
#遞迴呼叫
|
1421 |
#遞迴呼叫
|
| - |
|
1422 |
#函式說明:
|
| - |
|
1423 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
| - |
|
1424 |
#回傳結果:
|
| - |
|
1425 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| - |
|
1426 |
#$result["error"],錯誤訊息陣列.
|
| - |
|
1427 |
#$result["function"],當前執行的函數名稱.
|
| - |
|
1428 |
#$result["argu"],使用的參數.
|
| - |
|
1429 |
#$result["cmd"],執行的指令內容.
|
| - |
|
1430 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
| - |
|
1431 |
#$result["output"],爲執行完後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
| - |
|
1432 |
#$result["content"],為執行完後的輸出字串.
|
| - |
|
1433 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
| - |
|
1434 |
#$result["running"],是否還在執行.
|
| - |
|
1435 |
#$result["pid"],pid.
|
| - |
|
1436 |
#$result["statusCode"],執行結束後的代碼.
|
| - |
|
1437 |
#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
| - |
|
1438 |
#$result["noEscaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
|
| - |
|
1439 |
#必填參數:
|
| - |
|
1440 |
#$conf["command"],字串,要執行的指令.
|
| - |
|
1441 |
#$conf["command"]="";
|
| - |
|
1442 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| - |
|
1443 |
#$conf["fileArgu"]=__FILE__;
|
| - |
|
1444 |
#可省略參數:
|
| - |
|
1445 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
| - |
|
1446 |
#$conf["argu"]=array("");
|
| - |
|
1447 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
| - |
|
1448 |
#$conf["arguIsAddr"]=array();
|
| - |
|
1449 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
| - |
|
1450 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
| - |
|
1451 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
| - |
|
1452 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
| - |
|
1453 |
#$conf["enablePrintDescription"]="true";
|
| - |
|
1454 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
| - |
|
1455 |
#$conf["printDescription"]="";
|
| - |
|
1456 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
| - |
|
1457 |
#$conf["escapeshellarg"]="false";
|
| - |
|
1458 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
| - |
|
1459 |
#$conf["thereIsShellVar"]=array();
|
| - |
|
1460 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
| - |
|
1461 |
#$conf["username"]="";
|
| - |
|
1462 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
| - |
|
1463 |
#$conf["password"]="";
|
| - |
|
1464 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
| - |
|
1465 |
#$conf["useScript"]="";
|
| - |
|
1466 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
| - |
|
1467 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
| - |
|
1468 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
| - |
|
1469 |
#$conf["inBackGround"]="";
|
| - |
|
1470 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
| - |
|
1471 |
#$conf["getErr"]="false";
|
| - |
|
1472 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
| - |
|
1473 |
#$conf["doNotRun"]="false";
|
| - |
|
1474 |
#$conf["cmdContainArgu"],字串,cmd參數是否已經含有參數,預設為"false"代表沒有;反之為"true".
|
| - |
|
1475 |
#$conf["cmdContainArgu"]="false";
|
| - |
|
1476 |
#$conf["remoteIp"],字串,遠端ip或domainName,預設不使用,若存在則會透過ssh指令進行連線,然後執行指令.
|
| - |
|
1477 |
#$conf["remoteIp"]="";
|
| - |
|
1478 |
#$conf["remoteUser"],字串,遠端的使用者賬戶,預設不指定,亦即跟為運行該php程式的使用者.
|
| - |
|
1479 |
#$conf["remoteUser"]="";
|
| - |
|
1480 |
#$conf["sshOptions"],陣列,當具備 "remoteIp" 參數時,該參數每個元素為ssh指令的參數.
|
| - |
|
1481 |
#$conf["sshOptions"]=array();
|
| - |
|
1482 |
#參考資料:
|
| - |
|
1483 |
#exec=>http://php.net/manual/en/function.exec.php
|
| - |
|
1484 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
| - |
|
1485 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
| - |
|
1486 |
#備註:
|
| - |
|
1487 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
| - |
|
1488 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
| 1001 |
return self::callShell($conf);
|
1489 |
return self::callShell($conf);
|
| 1002 |
|
1490 |
|
| 1003 |
}#else end
|
1491 |
}#else end
|
| 1004 |
|
1492 |
|
| 1005 |
}#if end
|
1493 |
}#if end
|
| Line 1840... |
Line 2328... |
| 1840 |
|
2328 |
|
| 1841 |
#設定ssh指令
|
2329 |
#設定ssh指令
|
| 1842 |
$ssh="ssh ".$conf["remoteUser"]."@".$conf["remoteIp"];
|
2330 |
$ssh="ssh ".$conf["remoteUser"]."@".$conf["remoteIp"];
|
| 1843 |
|
2331 |
|
| 1844 |
}#if end
|
2332 |
}#if end
|
| - |
|
2333 |
|
| - |
|
2334 |
#如果有設置 ssh 的 options
|
| - |
|
2335 |
if(isset($conf["sshOptions"])){
|
| - |
|
2336 |
|
| - |
|
2337 |
#根據每個 ssh options
|
| - |
|
2338 |
foreach($conf["sshOptions"] as $sshOption){
|
| - |
|
2339 |
|
| - |
|
2340 |
#串接 ssh options
|
| - |
|
2341 |
$ssh=$ssh." ".$sshOption;
|
| - |
|
2342 |
|
| - |
|
2343 |
}#foreach end
|
| - |
|
2344 |
|
| - |
|
2345 |
}#if end
|
| 1845 |
|
2346 |
|
| 1846 |
#檢測能否成功遠端的指令
|
2347 |
#檢測能否成功遠端的指令
|
| 1847 |
$testRemote="echo 'env | grep SSH_CONNECTION' | ".$ssh;
|
2348 |
$testRemote="echo \"'env' | grep 'SSH_CONNECTION'\" | ".$ssh;
|
| 1848 |
|
2349 |
|
| 1849 |
#debug
|
2350 |
#debug
|
| 1850 |
#var_dump(__LINE__,$testRemote);
|
2351 |
#var_dump(__LINE__,$testRemote);
|
| 1851 |
|
2352 |
|
| 1852 |
#初始化輸出
|
2353 |
#初始化輸出
|
| Line 2043... |
Line 2544... |
| 2043 |
$cmd="echo";
|
2544 |
$cmd="echo";
|
| 2044 |
|
2545 |
|
| 2045 |
#初始化要在遠端執行的參數
|
2546 |
#初始化要在遠端執行的參數
|
| 2046 |
$argu=array($arrayToString["content"],"|","ssh",$remote);
|
2547 |
$argu=array($arrayToString["content"],"|","ssh",$remote);
|
| 2047 |
|
2548 |
|
| - |
|
2549 |
#如果有設置 ssh 的 options
|
| - |
|
2550 |
if(isset($conf["sshOptions"])){
|
| - |
|
2551 |
|
| - |
|
2552 |
#根據每個 ssh options
|
| - |
|
2553 |
foreach($conf["sshOptions"] as $sshOption){
|
| - |
|
2554 |
|
| - |
|
2555 |
#串接 ssh options
|
| - |
|
2556 |
$argu[]=$sshOption;
|
| - |
|
2557 |
|
| - |
|
2558 |
}#foreach end
|
| - |
|
2559 |
|
| - |
|
2560 |
}#if end
|
| - |
|
2561 |
|
| 2048 |
#函式說明:
|
2562 |
#函式說明:
|
| 2049 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
2563 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
| 2050 |
#回傳結果:
|
2564 |
#回傳結果:
|
| 2051 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
2565 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 2052 |
#$result["error"],錯誤訊息陣列.
|
2566 |
#$result["error"],錯誤訊息陣列.
|