Subversion Repositories php-qbpwcf

Rev

Rev 3 | 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
#!/usr/bin/php
1
#!/usr/bin/php
2
<?php
2
<?php
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~2024 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 17... Line 17...
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
18
    GNU General Public License for more details.
19
 
19
 
20
    You should have received a copy of the GNU General Public License
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
    
22
 
23
*/
23
*/
24
 
24
 
25
/*
25
/*
26
 
26
 
27
確認網路連線是否正常,若有必要會重新進行連線
27
確認網路連線是否正常,若有必要會重新進行連線
Line 61... Line 61...
61
	#結束執行,回傳shell 1.
61
	#結束執行,回傳shell 1.
62
	exit(1);
62
	exit(1);
63
 
63
 
64
	}#if end
64
	}#if end
65
 
65
 
66
#設置 include path 
66
#設置 include path
67
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
67
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
68
 
68
 
69
#匯入外部套件
69
#匯入外部套件
70
include("allInOne.php");
70
include("allInOne.php");
71
 
71
 
Line 114... Line 114...
114
		help();
114
		help();
115
 
115
 
116
		}#if end
116
		}#if end
117
 
117
 
118
	}#if end
118
	}#if end
119
	
119
 
120
#函式說明:
120
#函式說明:
121
#解析參數.
121
#解析參數.
122
#回傳結果:
122
#回傳結果:
123
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
123
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
124
#$reuslt["error"],執行不正常結束的錯訊息陣列.
124
#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 150... Line 150...
150
	#stop
150
	#stop
151
	exit();
151
	exit();
152
 
152
 
153
	}#if end
153
	}#if end
154
 
154
 
155
/*	
155
/*
156
#debug
156
#debug
157
var_dump($parseArgu);
157
var_dump($parseArgu);
158
exit;
158
exit;
159
*/
159
*/
160
 
160
 
Line 187... Line 187...
187
	#fix array to string error
187
	#fix array to string error
188
	$pV=$pV[0];
188
	$pV=$pV[0];
189
 
189
 
190
	#判斷參數
190
	#判斷參數
191
	switch($pN){
191
	switch($pN){
192
	
192
 
193
		#如果是以連線名稱
193
		#如果是以連線名稱
194
		case "conn":
194
		case "conn":
195
		
195
 
196
			#確認網路正常
196
			#確認網路正常
197
			/*
197
			/*
198
			["DEVICE"]=>
198
			["DEVICE"]=>
199
			string(2) "--"
199
			string(2) "--"
200
			["TYPE"]=>
200
			["TYPE"]=>
201
			string(6) "bridge"
201
			string(6) "bridge"
202
			["UUID"]=>
202
			["UUID"]=>
203
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
203
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
204
			["NAME"]=>
204
			["NAME"]=>
205
			string(12) "dockerBridge" 
205
			string(12) "dockerBridge"
206
 
206
 
207
			$cdev=&$infos["DEVICE"];
207
			$cdev=&$infos["DEVICE"];
208
			$ctype=&$infos["TYPE"];
208
			$ctype=&$infos["TYPE"];
209
			$cid=&$infos["UUID"];
209
			$cid=&$infos["UUID"];
210
			$cname=&$infos["NAME"];
210
			$cname=&$infos["NAME"];
211
 
211
 
212
			可省略參參數:
212
			可省略參參數:
213
			$checkFrom,字串,可以為"cname","cid".
213
			$checkFrom,字串,可以為"cname","cid".
214
			*/
214
			*/
215
			var_dump(makeSureNetWorkFine("cname",$pV));		
215
			var_dump(makeSureNetWorkFine("cname",$pV));
216
					
216
 
217
			#跳出switch
217
			#跳出switch
218
			break;
218
			break;
219
		
219
 
220
		#如果是以連線uuid
220
		#如果是以連線uuid
221
		case "uuid":
221
		case "uuid":
222
		
222
 
223
			#確認網路正常
223
			#確認網路正常
224
			/*
224
			/*
225
			["DEVICE"]=>
225
			["DEVICE"]=>
226
			string(2) "--"
226
			string(2) "--"
227
			["TYPE"]=>
227
			["TYPE"]=>
228
			string(6) "bridge"
228
			string(6) "bridge"
229
			["UUID"]=>
229
			["UUID"]=>
230
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
230
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
231
			["NAME"]=>
231
			["NAME"]=>
232
			string(12) "dockerBridge" 
232
			string(12) "dockerBridge"
233
 
233
 
234
			$cdev=&$infos["DEVICE"];
234
			$cdev=&$infos["DEVICE"];
235
			$ctype=&$infos["TYPE"];
235
			$ctype=&$infos["TYPE"];
236
			$cid=&$infos["UUID"];
236
			$cid=&$infos["UUID"];
237
			$cname=&$infos["NAME"];
237
			$cname=&$infos["NAME"];
238
 
238
 
239
			可省略參參數:
239
			可省略參參數:
240
			$checkFrom,字串,可以為"cname","cid".
240
			$checkFrom,字串,可以為"cname","cid".
241
			*/
241
			*/
242
			var_dump(makeSureNetWorkFine("cid",$pV));
242
			var_dump(makeSureNetWorkFine("cid",$pV));
243
			
243
 
244
		#如果是以連線type
244
		#如果是以連線type
245
		case "type":
245
		case "type":
246
		
246
 
247
			#確認網路正常
247
			#確認網路正常
248
			/*
248
			/*
249
			["DEVICE"]=>
249
			["DEVICE"]=>
250
			string(2) "--"
250
			string(2) "--"
251
			["TYPE"]=>
251
			["TYPE"]=>
252
			string(6) "bridge"
252
			string(6) "bridge"
253
			["UUID"]=>
253
			["UUID"]=>
254
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
254
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
255
			["NAME"]=>
255
			["NAME"]=>
256
			string(12) "dockerBridge" 
256
			string(12) "dockerBridge"
257
 
257
 
258
			$cdev=&$infos["DEVICE"];
258
			$cdev=&$infos["DEVICE"];
259
			$ctype=&$infos["TYPE"];
259
			$ctype=&$infos["TYPE"];
260
			$cid=&$infos["UUID"];
260
			$cid=&$infos["UUID"];
261
			$cname=&$infos["NAME"];
261
			$cname=&$infos["NAME"];
262
 
262
 
263
			可省略參參數:
263
			可省略參參數:
264
			$checkFrom,字串,可以為"cname","cid".
264
			$checkFrom,字串,可以為"cname","cid".
265
			*/
265
			*/
266
			var_dump(makeSureNetWorkFine("ctype",$pV));
266
			var_dump(makeSureNetWorkFine("ctype",$pV));
267
		
267
 
268
		default:
268
		default:
269
			
269
 
270
			#提示用法
270
			#提示用法
271
			help();
271
			help();
272
			
272
 
273
			#stop
273
			#stop
274
			exit;
274
			exit;
275
	
275
 
276
		}#switch
276
		}#switch
277
 
277
 
278
	}#foreach end
278
	}#foreach end
279
 
279
 
280
#說明
280
#說明
281
function help(){
281
function help(){
282
	
282
 
283
	#說明陣列
283
	#說明陣列
284
	$comments=array("Usage:");
284
	$comments=array("Usage:");
285
	$comments[]="";
285
	$comments[]="";
286
	$comments[]="help:";
286
	$comments[]="help:";
287
	$comments[]=$_SERVER["PHP_SELF"]." --help";
287
	$comments[]=$_SERVER["PHP_SELF"]." --help";
Line 289... Line 289...
289
	$comments[]="";
289
	$comments[]="";
290
	$comments[]="keep net conn:";
290
	$comments[]="keep net conn:";
291
	$comments[]=$_SERVER["PHP_SELF"]." --conn [connect name]";
291
	$comments[]=$_SERVER["PHP_SELF"]." --conn [connect name]";
292
	$comments[]=$_SERVER["PHP_SELF"]." --uuid [connect UUID]";
292
	$comments[]=$_SERVER["PHP_SELF"]." --uuid [connect UUID]";
293
	$comments[]=$_SERVER["PHP_SELF"]." --type [pppoe]";
293
	$comments[]=$_SERVER["PHP_SELF"]." --type [pppoe]";
294
	
294
 
295
	#函式說明:
295
	#函式說明:
296
	#印出多行文字,結尾自動換行.
296
	#印出多行文字,結尾自動換行.
297
	#回傳的結果:
297
	#回傳的結果:
298
	#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
298
	#$result["status"],執行是否成功,"true"代表成功,"false"代表失敗.
299
	#$result["function"],當前執行的函數名稱.
299
	#$result["function"],當前執行的函數名稱.
Line 304... Line 304...
304
	$echoMultiLine=cmd::echoMultiLine($conf);
304
	$echoMultiLine=cmd::echoMultiLine($conf);
305
	unset($conf);
305
	unset($conf);
306
 
306
 
307
	#如果執行失敗
307
	#如果執行失敗
308
	if($echoMultiLine["status"]==="false"){
308
	if($echoMultiLine["status"]==="false"){
309
	
309
 
310
		#debug
310
		#debug
311
		var_dump($echoMultiLine);
311
		var_dump($echoMultiLine);
312
		
312
 
313
		#stop
313
		#stop
314
		exit;
314
		exit;
315
	
315
 
316
		}#if end
316
		}#if end
317
	
317
 
318
	}#function help end
318
	}#function help end
319
	
319
 
320
#確認網路正常
320
#確認網路正常
321
/*
321
/*
322
["DEVICE"]=>
322
["DEVICE"]=>
323
string(2) "--"
323
string(2) "--"
324
["TYPE"]=>
324
["TYPE"]=>
325
string(6) "bridge"
325
string(6) "bridge"
326
["UUID"]=>
326
["UUID"]=>
327
string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
327
string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
328
["NAME"]=>
328
["NAME"]=>
329
string(12) "dockerBridge" 
329
string(12) "dockerBridge"
330
 
330
 
331
$cdev=&$infos["DEVICE"];
331
$cdev=&$infos["DEVICE"];
332
$ctype=&$infos["TYPE"];
332
$ctype=&$infos["TYPE"];
333
$cid=&$infos["UUID"];
333
$cid=&$infos["UUID"];
334
$cname=&$infos["NAME"];
334
$cname=&$infos["NAME"];
Line 377... Line 377...
377
		#/*
377
		#/*
378
		#debug
378
		#debug
379
		var_dump($nmcli_list);
379
		var_dump($nmcli_list);
380
		#exit;
380
		#exit;
381
		#*/
381
		#*/
382
		
382
 
383
		#根據每個網路連線設定檔名稱
383
		#根據每個網路連線設定檔名稱
384
		foreach($nmcli_list["content"] as $index=>$infos){
384
		foreach($nmcli_list["content"] as $index=>$infos){
385
 
385
 
386
			#/*
386
			#/*
387
			#debug
387
			#debug
Line 396... Line 396...
396
			["TYPE"]=>
396
			["TYPE"]=>
397
			string(6) "bridge"
397
			string(6) "bridge"
398
			["UUID"]=>
398
			["UUID"]=>
399
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
399
			string(36) "55f65234-ee44-4531-9c13-0ececc75e7cf"
400
			["NAME"]=>
400
			["NAME"]=>
401
			string(12) "dockerBridge" 
401
			string(12) "dockerBridge"
402
			*/
402
			*/
403
			$cdev=&$infos["DEVICE"];
403
			$cdev=&$infos["DEVICE"];
404
			$ctype=&$infos["TYPE"];
404
			$ctype=&$infos["TYPE"];
405
			$cid=&$infos["UUID"];
405
			$cid=&$infos["UUID"];
406
			$cname=&$infos["NAME"];
406
			$cname=&$infos["NAME"];
407
			
407
 
408
			#/*
408
			#/*
409
			#debug
409
			#debug
410
			echo "connection name:".$$checkFrom.PHP_EOL;
410
			echo "connection name:".$$checkFrom.PHP_EOL;
411
			echo "currunet connection name:".$pV.PHP_EOL;
411
			echo "currunet connection name:".$pV.PHP_EOL;
412
			#*/
412
			#*/
413
 
413
 
414
			#如果是要找的連線設定檔
414
			#如果是要找的連線設定檔
415
			if($$checkFrom===$pV){
415
			if($$checkFrom===$pV){
416
 
416
 
417
				#/*
417
				#/*
418
				#debug 
418
				#debug
419
				echo "found connection ".$checkFrom.PHP_EOL;
419
				echo "found connection ".$checkFrom.PHP_EOL;
420
				#*/
420
				#*/
421
 
421
 
422
				#如果設備名稱不爲空,代表已經連線了
422
				#如果設備名稱不爲空,代表已經連線了
423
				if($cdev!=="--"){
423
				if($cdev!=="--"){
424
					
424
 
425
					#/*
425
					#/*
426
					#debug
426
					#debug
427
					echo "connection is on".PHP_EOL;
427
					echo "connection is on".PHP_EOL;
428
					#*/
428
					#*/
429
					
429
 
430
					#測試連線是否存活
430
					#測試連線是否存活
431
					#涵式說明:
431
					#涵式說明:
432
					#依據提供查詢IP服務的網站取得伺服器對外的IP.
432
					#依據提供查詢IP服務的網站取得伺服器對外的IP.
433
					#回傳的結果:
433
					#回傳的結果:
434
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
434
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 438... Line 438...
438
					#必填參數:
438
					#必填參數:
439
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
439
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
440
					$conf["fileArgu"]=__FILE__;
440
					$conf["fileArgu"]=__FILE__;
441
					$getServerRealIP=csInformation::getServerRealIP($conf);
441
					$getServerRealIP=csInformation::getServerRealIP($conf);
442
					unset($conf);
442
					unset($conf);
443
					
443
 
444
					#debug
444
					#debug
445
					echo "ping test info:".PHP_EOL;
445
					echo "ping test info:".PHP_EOL;
446
					var_dump($getServerRealIP);
446
					var_dump($getServerRealIP);
447
					
447
 
448
					#如果取得對外IP失敗
448
					#如果取得對外IP失敗
449
					if($getServerRealIP["status"]==="false"){
449
					if($getServerRealIP["status"]==="false"){
450
					
450
 
451
						#涵式說明:
451
						#涵式說明:
452
						#透過 ping -c 3 -I [ppp0/網路界面名稱] 1.1.1.1 ,來判斷是否該界面有跟外部連線。
452
						#透過 ping -c 3 -I [ppp0/網路界面名稱] 1.1.1.1 ,來判斷是否該界面有跟外部連線。
453
						#回傳結果:
453
						#回傳結果:
454
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
454
						#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
455
						#$result["error"],錯誤訊息.
455
						#$result["error"],錯誤訊息.
Line 466... Line 466...
466
						#$conf["pingTarget"]="";
466
						#$conf["pingTarget"]="";
467
						#備註:
467
						#備註:
468
						#待測試
468
						#待測試
469
						$pingOutsideTest=cmd::pingOutsideTest($conf);
469
						$pingOutsideTest=cmd::pingOutsideTest($conf);
470
						unset($conf);
470
						unset($conf);
471
						
471
 
472
						#debug
472
						#debug
473
						echo "ping test info:".PHP_EOL;
473
						echo "ping test info:".PHP_EOL;
474
						var_dump($pingOutsideTest);
474
						var_dump($pingOutsideTest);
475
						
475
 
476
						#如果 ping 失敗
476
						#如果 ping 失敗
477
						if($pingOutsideTest["status"]==="false"){
477
						if($pingOutsideTest["status"]==="false"){
478
						
478
 
479
							#代表連線是無效的應該要重新連線
479
							#代表連線是無效的應該要重新連線
480
							#函式說明:
480
							#函式說明:
481
							#fedora的nmcli指令,重新連線指定的連線。
481
							#fedora的nmcli指令,重新連線指定的連線。
482
							#回傳結果:
482
							#回傳結果:
483
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
483
							#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 494... Line 494...
494
							#無.
494
							#無.
495
							#備註:
495
							#備註:
496
							#僅能在命令列環境下執行.
496
							#僅能在命令列環境下執行.
497
							$nmcli_reconnect=cmd::nmcli_reconnect($conf["cmd::nmcli_reconnect"]);
497
							$nmcli_reconnect=cmd::nmcli_reconnect($conf["cmd::nmcli_reconnect"]);
498
							unset($conf["cmd::nmcli_reconnect"]);
498
							unset($conf["cmd::nmcli_reconnect"]);
499
						
499
 
500
							#如果執行失敗
500
							#如果執行失敗
501
							if($nmcli_reconnect["status"]==="false"){
501
							if($nmcli_reconnect["status"]==="false"){
502
 
502
 
503
								#debug
503
								#debug
504
								var_dump($nmcli_reconnect);
504
								var_dump($nmcli_reconnect);
505
 
505
 
506
								#stop
506
								#stop
507
								exit;
507
								exit;
508
 
508
 
509
								}#if end
509
								}#if end
510
						
510
 
511
							}#if end
511
							}#if end
512
						
512
 
513
						}#if end
513
						}#if end
514
					
514
 
515
					#/*
515
					#/*
516
					#debug
516
					#debug
517
					echo "connection is truely on".PHP_EOL;
517
					echo "connection is truely on".PHP_EOL;
518
					#*/
518
					#*/
519
 
519
 
520
					#確認連線是活的
520
					#確認連線是活的
521
					continue 2;
521
					continue 2;
522
					
522
 
523
					}#if end
523
					}#if end
524
				
524
 
525
				#反之設備名稱爲空,代表沒有建立連線。
525
				#反之設備名稱爲空,代表沒有建立連線。
526
				else{
526
				else{
527
					
527
 
528
					#/*
528
					#/*
529
					#debug
529
					#debug
530
					echo "connection is off".PHP_EOL;
530
					echo "connection is off".PHP_EOL;
531
					#*/
531
					#*/
532
					
532
 
533
					#建立連線
533
					#建立連線
534
					#函式說明:
534
					#函式說明:
535
					#fedora的nmcli指令,重新連線指定的連線。
535
					#fedora的nmcli指令,重新連線指定的連線。
536
					#回傳結果:
536
					#回傳結果:
537
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
537
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
Line 564... Line 564...
564
 
564
 
565
						#stop
565
						#stop
566
						exit;
566
						exit;
567
 
567
 
568
						}#if end
568
						}#if end
569
					
569
 
570
					
570
 
571
					#確認連線是活的
571
					#確認連線是活的
572
					continue 2;
572
					continue 2;
573
					
573
 
574
					}#else end
574
					}#else end
575
 
575
 
576
				#跳出 foreach
576
				#跳出 foreach
577
				break;
577
				break;
578
 
578
 
579
				}#if end
579
				}#if end
580
	
580
 
581
			}#foreach end
581
			}#foreach end
582
 
582
 
583
		}#while end	
583
		}#while end
584
 
584
 
585
	}#function makeSureNetWorkFine end
585
	}#function makeSureNetWorkFine end
586
 
586
 
587
?>
587
?>