Subversion Repositories qbpwcf-lib(archive)

Rev

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

Rev 708 Rev 709
Line -... Line 1...
-
 
1
#!/bin/php
1
<?php
2
<?php
2
 
3
 
3
/*
4
/*
4
 
5
 
5
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
        QBPWCF, Quick Build PHP website Component base on Fedora Linux.
Line 64... Line 65...
64
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
65
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
65
#$conf["enablePrintDescription"]="true";
66
#$conf["enablePrintDescription"]="true";
66
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
67
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
67
#$conf["printDescription"]="";
68
#$conf["printDescription"]="";
68
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
69
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
69
#$conf["escapeshellarg"]="false";
70
$conf["escapeshellarg"]="true";
70
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
71
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
71
#$conf["thereIsShellVar"]=array();
72
#$conf["thereIsShellVar"]=array();
72
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
73
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
73
#$conf["username"]="";
74
#$conf["username"]="";
74
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
75
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
Line 102... Line 103...
102
	#結束執行,回傳1給shell.
103
	#結束執行,回傳1給shell.
103
	exit(1);
104
	exit(1);
104
 
105
 
105
	}#if end
106
	}#if end
106
 
107
 
-
 
108
#debug
-
 
109
#var_dump(__LINE__,$callShell);exit;
-
 
110
 
107
#函式說明:
111
#函式說明:
108
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
112
#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
109
#回傳的結果:
113
#回傳的結果:
110
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
114
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
111
#$result["function"],當前執行的function名稱
115
#$result["function"],當前執行的function名稱
Line 177... Line 181...
177
	#結束執行,回傳1給shell.
181
	#結束執行,回傳1給shell.
178
	exit(1);
182
	exit(1);
179
 
183
 
180
	}#if end
184
	}#if end
181
 
185
 
-
 
186
#debug
-
 
187
#var_dump(__LINE__,$proc);exit;
-
 
188
 
-
 
189
#停1秒
-
 
190
sleep(1);
-
 
191
 
182
#函式說明:
192
#函式說明:
183
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
193
#查尋有使用 server 函式提供組態設定檔的服務,取得key的value.
184
#回傳結果:
194
#回傳結果:
185
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
195
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
186
#$result["error"],錯誤訊息陣列.
196
#$result["error"],錯誤訊息陣列.
187
#$result["function"],當前執行的函數名稱.
197
#$result["function"],當前執行的函數名稱.
188
#$result["rawContent"],得到的原始訊息.
198
#$result["rawContent"],得到的原始訊息.
189
#$result["content"],用json_decode後的結果;若"inBg"為"true",則其每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
199
#$result["content"],用json_decode後的結果;若"inBg"為"true",則其每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
190
#必填參數:
200
#必填參數:
191
#$conf["server"],字串,組態服務設定服務的網址
201
#$conf["server"],字串,組態服務設定服務的網址
192
$conf["server"]="https://qbpwc.sourceforge.io/demo/configServerDemo.php";
202
$conf["server"]="https://latest.qbpwcf.org/sample/config::server.php";
193
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
203
#$conf["postName"],字串,POST變數的名稱,亦即要查尋的定義名稱.
194
$conf["postName"]="";
204
$conf["postName"]="";
195
#$conf["fileArgu"],字串,變數__FILE__的內容.
205
#$conf["fileArgu"],字串,變數__FILE__的內容.
196
$conf["fileArgu"]=__FILE__;
206
$conf["fileArgu"]=__FILE__;
197
#可省略參數:
207
#可省略參數:
Line 206... Line 216...
206
#備註:
216
#備註:
207
#目前僅能跟server函式提供的服務對接.
217
#目前僅能跟server函式提供的服務對接.
208
$client=config::client($conf);
218
$client=config::client($conf);
209
unset($conf);
219
unset($conf);
210
 
220
 
-
 
221
#如果程式最後狀態為進行中
-
 
222
if($proc["content"][0]["proc_get_status"]["running"]===true){
-
 
223
 
-
 
224
	#debug
-
 
225
	#var_dump(__LINE__,$proc["content"][0]);
-
 
226
 
-
 
227
	#取得新狀態
-
 
228
	$proc["content"][0]["proc_get_status"]=proc_get_status($proc["content"][0]["process"]);
-
 
229
 
-
 
230
	#debug
-
 
231
	#var_dump(__LINE__,$proc["content"][0]);
-
 
232
 
-
 
233
	}#if end
-
 
234
	
-
 
235
#debug
-
 
236
#var_dump(__LINE__,$proc["content"][0]);
-
 
237
 
-
 
238
#如果有 $proc["content"][0]["content"]
-
 
239
if(isset($proc["content"][0]["content"])){
-
 
240
 
-
 
241
	#取得clientCacheDaemon的標準輸出
-
 
242
	$clientCacheDaemonStdOutput=$proc["content"][0]["content"];
-
 
243
 
-
 
244
	#debug
-
 
245
	#var_dump(__LINE__,gettype($proc["content"][0]["content"]));
-
 
246
 
-
 
247
	#如果輸出為 resource
-
 
248
	if(gettype($proc["content"][0]["content"])==="resource"){
-
 
249
 
-
 
250
		#取得clientCacheDaemon的標準輸出
-
 
251
		$clientCacheDaemonStdOutput=stream_get_contents($proc["content"][0]["content"]);
-
 
252
 
-
 
253
		#關閉 output
-
 
254
		fclose($proc["content"][0]["content"]);
-
 
255
 
-
 
256
		}#if end
-
 
257
 
-
 
258
	}#if end
-
 
259
 
-
 
260
#如果有 $proc["content"][0]["error"]
-
 
261
if(isset($proc["content"][0]["error"])){
-
 
262
 
-
 
263
	#取得clientCacheDaemon的錯誤輸出
-
 
264
	$clientCacheDaemonErrorOutput=$proc["content"][0]["error"];
-
 
265
 
-
 
266
	#debug
-
 
267
	#var_dump(__LINE__,gettype($proc["content"][0]["error"]));
211
 
268
 
-
 
269
	#如果錯誤輸出為 resource
-
 
270
	if(gettype($proc["content"][0]["error"])==="resource"){
-
 
271
 
-
 
272
		#取得clientCacheDaemon的錯誤輸出
-
 
273
		$clientCacheDaemonErrorOutput=stream_get_contents($proc["content"][0]["error"]);
-
 
274
 
-
 
275
		#關閉 error
-
 
276
		fclose($proc["content"][0]["error"]);
-
 
277
 
-
 
278
		}#if end
-
 
279
 
-
 
280
	}#if end
-
 
281
 
-
 
282
#如果有 $proc["process"]
-
 
283
if(isset($proc["content"][0]["process"])){
-
 
284
 
-
 
285
	#結束 clientCacheDaemon.php 
-
 
286
	$clientCacheDaemonStatusCode = proc_close($proc["content"][0]["process"]);
-
 
287
 
-
 
288
	#debug
-
 
289
	#var_dump(__LINE__,$clientCacheDaemonStatusCode);exit;
-
 
290
 
-
 
291
	#如果 clientCacheDaemon.php 不是正常結束
-
 
292
	if($clientCacheDaemonStatusCode!==0){
-
 
293
 
-
 
294
		#提示 clientCacheDaemon.php 未正常結束
-
 
295
		echo "clientCacheDaemon.php 未正常結束(".$clientCacheDaemonStatusCode.")".PHP_EOL;
-
 
296
 
-
 
297
		#如果有 $clientCacheDaemonStdOutput
-
 
298
		if(isset($clientCacheDaemonStdOutput)){
-
 
299
		
-
 
300
			#提示 clientCacheDaemon.php 的標準輸出內容
-
 
301
			echo "clientCacheDaemon.php 的標準輸出內容:".PHP_EOL.$clientCacheDaemonStdOutput.PHP_EOL;
-
 
302
		
-
 
303
			}#if end
-
 
304
 
-
 
305
		#如果有 $clientCacheDaemonErrorOutput
-
 
306
		if(isset($clientCacheDaemonErrorOutput)){
-
 
307
		
-
 
308
			#提示 clientCacheDaemon.php 的錯誤輸出內容
-
 
309
			echo "clientCacheDaemon.php 的錯誤輸出內容:".PHP_EOL.$clientCacheDaemonErrorOutput.PHP_EOL;
-
 
310
		
-
 
311
			}#if end
-
 
312
 
-
 
313
		}#if end
-
 
314
		
-
 
315
		#結束執行,回傳1給shell.
-
 
316
		exit(1);
-
 
317
 
-
 
318
	}#if end
-
 
319
 
-
 
320
#如果執行失敗
-
 
321
if($client["status"]==="false"){
-
 
322
 
-
 
323
	#debug
-
 
324
	var_dump($client);
-
 
325
 
-
 
326
	#結束執行,回傳1給shell.
-
 
327
	exit(1);
-
 
328
 
-
 
329
	}#if end
-
 
330
	
-
 
331
#印出結果
-
 
332
var_dump($client);
212
 
333
 
213
?>
334
?>
214
335