Subversion Repositories php-qbpwcf

Rev

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

Rev 48 Rev 66
Line 4017... Line 4017...
4017
	#用shell檢查檔案是否存在,可以指定查詢時用的身份.
4017
	#用shell檢查檔案是否存在,可以指定查詢時用的身份.
4018
	#回傳的結果:
4018
	#回傳的結果:
4019
	#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
4019
	#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
4020
	#$result["function"],當前執行的函式名稱.
4020
	#$result["function"],當前執行的函式名稱.
4021
	#$result["error"],錯誤訊息陣列.
4021
	#$result["error"],錯誤訊息陣列.
4022
	#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案.
4022
	#$result["founded"],"true"代表有找到檔案,"false"代表沒有找到檔案,"?"代表沒有執行指令.
-
 
4023
	#$result["cmdStr"],查詢檔案是否存在的指令與參數字串.
-
 
4024
	#$result["escapedCmdArray"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
4023
	#必填參數:
4025
	#必填參數:
4024
	#$conf["fileName"],字串,要檢查的檔案名稱.
4026
	#$conf["fileName"],字串,要檢查的檔案名稱.
4025
	$conf["fileName"]="";
4027
	$conf["fileName"]="";
4026
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
4028
	#$conf["fileArgu"],字串,__FILE__的內容,預設為當前檔案的位置.
4027
	$conf["fileArgu"]=__FILE__;
4029
	$conf["fileArgu"]=__FILE__;
4028
	#可省略參數:
4030
	#可省略參數:
4029
	#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
4031
	#$conf["username"],字串,要用哪個身份來檢查檔案是否存在,預設不使用.
4030
	#$conf["username"]="";
4032
	#$conf["username"]="";
4031
	#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
4033
	#$conf["password"],字串,要用哪個身份來檢查檔案是否存在,預設不使用,若沒有設定好不用密碼即可登入,則在web端會直接出錯,在命令列則會提示輸入密碼.
4032
	#$conf["password"]="";
4034
	#$conf["password"]="";
-
 
4035
	#$conf["getCmdOnly"],字串,若不要執行指令,只要取得要執行的指令,則設置為"true";反之為預設值"false".
-
 
4036
	#$conf["getCmdOnly"]="";
4033
	#參考資料:
4037
	#參考資料:
4034
	#無.
4038
	#無.
4035
	#備註:
4039
	#備註:
4036
	#僅能在命令列環境下執行.
4040
	#僅能在命令列環境下執行.
4037
	*/
4041
	*/
Line 4106... Line 4110...
4106
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4110
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
4107
		#可以省略的參數:
4111
		#可以省略的參數:
4108
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
4112
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
4109
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4113
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
4110
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4114
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4111
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password");
4115
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("username","password","getCmdOnly");
4112
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4116
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
4113
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
4117
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
4114
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4118
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4115
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null);
4119
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($_SERVER["LOGNAME"],null,"false");
4116
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4120
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4117
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
4121
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array();
4118
		#參考資料來源:
4122
		#參考資料來源:
4119
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4123
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4120
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4124
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4121
		unset($conf["variableCheck::checkArguments"]);
4125
		unset($conf["variableCheck::checkArguments"]);
4122
 
4126
 
4123
		#如果檢查失敗
4127
		#如果檢查失敗
4124
		if($checkResult["status"]=="false"){
4128
		if($checkResult["status"]==="false"){
4125
 
4129
 
4126
			#設置錯誤狀態
4130
			#設置錯誤狀態
4127
			$result["status"]="false";
4131
			$result["status"]="false";
4128
 
4132
 
4129
			#設置錯誤提示
4133
			#設置錯誤提示
Line 4133... Line 4137...
4133
			return $result;
4137
			return $result;
4134
 
4138
 
4135
			}#if end
4139
			}#if end
4136
 
4140
 
4137
		#如果檢查不通過
4141
		#如果檢查不通過
4138
		if($checkResult["passed"]=="false"){
4142
		if($checkResult["passed"]==="false"){
4139
 
4143
 
4140
			#設置錯誤狀態
4144
			#設置錯誤狀態
4141
			$result["status"]="false";
4145
			$result["status"]="false";
4142
 
4146
 
4143
			#設置錯誤提示
4147
			#設置錯誤提示
Line 4163... Line 4167...
4163
		#回傳的結果:
4167
		#回傳的結果:
4164
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4168
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4165
		#$result["error"],錯誤訊息陣列.
4169
		#$result["error"],錯誤訊息陣列.
4166
		#$result["function"],當前執行的函式名稱.
4170
		#$result["function"],當前執行的函式名稱.
4167
		#$result["cmd"],執行的指令內容.
4171
		#$result["cmd"],執行的指令內容.
-
 
4172
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
4168
		#$result["output"],爲執行完二元碼後的輸出陣列.
4173
		#$result["output"],爲執行完二元碼後的輸出陣列.
-
 
4174
		#$result["escape"],陣列,儲存重新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
-
 
4175
		#$result["noEcaped"],陣列,儲存重新排序過未經過escape過的指令(key為"cmd")與參數(key為"argu")與兩者組合的一維陣列(key為"array").
4169
		#必填參數
4176
		#必填參數
4170
		#$conf["command"],字串,要執行的指令與.
4177
		#$conf["command"],字串,要執行的指令與.
4171
		$conf["external::callShell"]["command"]=$cmd;
4178
		$conf["external::callShell"]["command"]=$cmd;
4172
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4179
		#$conf["fileArgu"],字串,變數__FILE__的內容.
4173
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4180
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
4174
		#可省略參數:
4181
		#可省略參數:
4175
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4182
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
4176
		$conf["external::callShell"]["argu"]=array("if","[","-e","\${target}","]",";","then","echo","\${target}","found",";","else","echo","\${target}","not founnd",";","fi",";");
4183
		#$conf["external::callShell"]["argu"]=array("if","[","-e","\${target}","]",";","then","echo","\${target}","found",";","else","echo","\${target}","not founnd",";","fi",";");
-
 
4184
		$conf["external::callShell"]["argu"]=array("if","[","-e","\${target}","]",";","then","echo","found",";","else","echo","not founnd",";","fi",";");
4177
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4185
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
4178
		#$conf["enablePrintDescription"]="true";
4186
		#$conf["enablePrintDescription"]="true";
4179
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4187
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容.
4180
		#$conf["printDescription"]="";
4188
		#$conf["printDescription"]="";
4181
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
4189
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
Line 4204... Line 4212...
4204
				$conf["external::callShell"]["password"]=$conf["password"];
4212
				$conf["external::callShell"]["password"]=$conf["password"];
4205
 
4213
 
4206
				}#if end
4214
				}#if end
4207
 
4215
 
4208
			}#if end
4216
			}#if end
-
 
4217
		
-
 
4218
		#如果不要運行指令,只要取得要執行的指令
-
 
4219
		if($conf["getCmdOnly"]==="true"){
-
 
4220
 
-
 
4221
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
-
 
4222
			$conf["external::callShell"]["doNotRun"]="false";
-
 
4223
		
-
 
4224
			}#if end
4209
 
4225
 
4210
		#備註:
4226
		#備註:
4211
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
4227
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行.
4212
		#參考資料:
4228
		#參考資料:
4213
		#exec=>http://php.net/manual/en/function.exec.php
4229
		#exec=>http://php.net/manual/en/function.exec.php
Line 4215... Line 4231...
4215
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4231
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
4216
		$callShell=external::callShell($conf["external::callShell"]);
4232
		$callShell=external::callShell($conf["external::callShell"]);
4217
		unset($conf["external::callShell"]);
4233
		unset($conf["external::callShell"]);
4218
 
4234
 
4219
		#如果執行腳本失敗
4235
		#如果執行腳本失敗
4220
		if($callShell["status"]=="false"){
4236
		if($callShell["status"]==="false"){
4221
 
4237
 
4222
			#設置錯誤識別
4238
			#設置錯誤識別
4223
			$result["status"]="false";
4239
			$result["status"]="false";
4224
 
4240
 
4225
			#設置錯誤提示
4241
			#設置錯誤提示
Line 4227... Line 4243...
4227
 
4243
 
4228
			#回傳結果
4244
			#回傳結果
4229
			return $result;
4245
			return $result;
4230
 
4246
 
4231
			}#if end
4247
			}#if end
-
 
4248
 
-
 
4249
		#儲存要執行的指令
-
 
4250
		$result["cmdStr"]=$callShell["cmd"];
-
 
4251
		
-
 
4252
		#用陣列儲存的指令與參數資訊
-
 
4253
		$result["escapedCmdArray"]=$callShell["noEscaped"];
-
 
4254
 
-
 
4255
		#如果不要運行指令,只要取得要執行的指令
-
 
4256
		if($conf["getCmdOnly"]==="true"){
-
 
4257
		
-
 
4258
			#設置執行正常的識別
-
 
4259
			$result["status"]="true";
-
 
4260
			
-
 
4261
			#因為沒有執行指令,所以設置為"?"
-
 
4262
			$result["founded"]="?";
-
 
4263
			
-
 
4264
			#回傳結果
-
 
4265
			return $result;
-
 
4266
		
-
 
4267
			}#if end
4232
 
4268
 
4233
		#如果有找到檔案
4269
		#如果有找到檔案
4234
		if($callShell["output"][0]===$conf["fileName"]." found"){
4270
		if($callShell["output"][0]==="found"){
4235
 
4271
 
4236
			#設置執行正常的識別
4272
			#設置執行正常的識別
4237
			$result["status"]="true";
4273
			$result["status"]="true";
4238
 
4274
 
4239
			#設置有找到檔案
4275
			#設置有找到檔案
Line 4242... Line 4278...
4242
			#回傳結果
4278
			#回傳結果
4243
			return $result;
4279
			return $result;
4244
 
4280
 
4245
			}#if end
4281
			}#if end
4246
 
4282
 
4247
		#如果有找到檔案
4283
		#如果沒有找到檔案
4248
		else if($callShell["output"][0]===$conf["fileName"]." not found"){
4284
		else if($callShell["output"][0]==="not found"){
4249
 
4285
 
4250
			#設置執行正常的識別
4286
			#設置執行正常的識別
4251
			$result["status"]="true";
4287
			$result["status"]="true";
4252
 
4288
 
4253
			#設置有找到檔案
4289
			#設置有找到檔案
Line 16211... Line 16247...
16211
							#可省略參數:
16247
							#可省略參數:
16212
							#無.
16248
							#無.
16213
							#參考資料:
16249
							#參考資料:
16214
							#無.
16250
							#無.
16215
							#備註:
16251
							#備註:
16216
							#無.							
16252
							#無.
16217
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16253
							$clearStrSymbol=stringProcess::clearStrSymbol($conf["stringProcess::clearStrSymbol"]);
16218
							unset($conf["stringProcess::clearStrSymbol"]);
16254
							unset($conf["stringProcess::clearStrSymbol"]);
16219
 
16255
 
16220
							#如果運行失敗
16256
							#如果運行失敗
16221
							if($clearStrSymbol["status"]==="false")
16257
							if($clearStrSymbol["status"]==="false"){
16222
							{
16258
							
16223
								#設置執行失敗
16259
								#設置執行失敗
16224
								$result["status"]="false";
16260
								$result["status"]="false";
16225
								
16261
								
16226
								#設置執行失敗訊息
16262
								#設置執行失敗訊息
16227
								$result["error"]=$clearStrSymbol;
16263
								$result["error"]=$clearStrSymbol;
16228
								
16264
								
16229
								#回傳結果
16265
								#回傳結果
16230
								return $result;
16266
								return $result;
16231
 
16267
 
16232
							}#if end
16268
								}#if end
16233
 
16269
 
16234
							#如果檔案不存在
16270
							#如果檔案不存在
16235
							if(!file_exists($clearStrSymbol["content"])){
16271
							if(!file_exists($clearStrSymbol["content"])){
16236
 
16272
 
16237
								#提示檔案不存在
16273
								#提示檔案不存在