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
用來檢測本機跟1.1.1.1、8.8.8.8是否連線正常,若不正常則用email提示或輸出訊息就好.檢查頻率為60秒一次.
27
用來檢測本機跟1.1.1.1、8.8.8.8是否連線正常,若不正常則用email提示或輸出訊息就好.檢查頻率為60秒一次.
Line 60... Line 60...
60
	#結束執行,回傳shell 1.
60
	#結束執行,回傳shell 1.
61
	exit(1);
61
	exit(1);
62
 
62
 
63
	}#if end
63
	}#if end
64
 
64
 
65
#設置 include path 
65
#設置 include path
66
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
66
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
67
 
67
 
68
#匯入外部套件
68
#匯入外部套件
69
include("allInOne.php");
69
include("allInOne.php");
70
 
70
 
Line 101... Line 101...
101
 
101
 
102
	#結束執行
102
	#結束執行
103
	exit;
103
	exit;
104
 
104
 
105
	}#function end
105
	}#function end
106
	
106
 
107
#函式說明:
107
#函式說明:
108
#解析參數.
108
#解析參數.
109
#回傳結果:
109
#回傳結果:
110
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
110
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
111
#$reuslt["error"],執行不正常結束的錯訊息陣列.
111
#$reuslt["error"],執行不正常結束的錯訊息陣列.
Line 142... Line 142...
142
#如果有新增ping的目標
142
#如果有新增ping的目標
143
if(isset($parseArgu["content"]["addPingTarget"])){
143
if(isset($parseArgu["content"]["addPingTarget"])){
144
 
144
 
145
	#針對每個要增加ping的對象
145
	#針對每個要增加ping的對象
146
	foreach($parseArgu["content"]["addPingTarget"] as $newPingTarget){
146
	foreach($parseArgu["content"]["addPingTarget"] as $newPingTarget){
147
	
147
 
148
		#增加新的ping目標
148
		#增加新的ping目標
149
		$pingTarget[]=$newPingTarget;
149
		$pingTarget[]=$newPingTarget;
150
	
150
 
151
		}#foreach end
151
		}#foreach end
152
 
152
 
153
	}#if end
153
	}#if end
154
 
154
 
155
#如果沒有設置收件人
155
#如果沒有設置收件人
Line 168... Line 168...
168
 
168
 
169
	#取得收件人
169
	#取得收件人
170
	$receiver=$parseArgu["content"]["receiver"];
170
	$receiver=$parseArgu["content"]["receiver"];
171
 
171
 
172
	}#else end
172
	}#else end
173
	
173
 
174
#如果沒有設置寄信用的 email 跟 密碼
174
#如果沒有設置寄信用的 email 跟 密碼
175
if( !isset($parseArgu["content"]["emailAcct"]) || !isset($parseArgu["content"]["emailPass"]) ){
175
if( !isset($parseArgu["content"]["emailAcct"]) || !isset($parseArgu["content"]["emailPass"]) ){
176
 
176
 
177
	#設置不要用smtp來寄信
177
	#設置不要用smtp來寄信
178
	$sendBySmtp="false";
178
	$sendBySmtp="false";
179
 
179
 
180
	}#if end
180
	}#if end
181
 
181
 
182
#反之	
182
#反之
183
else{
183
else{
184
 
184
 
185
	#設置要用smtp寄信
185
	#設置要用smtp寄信
186
	$sendBySmtp="true";
186
	$sendBySmtp="true";
187
 
187
 
Line 193... Line 193...
193
#如果有設置 levelForCheckSSL 參數
193
#如果有設置 levelForCheckSSL 參數
194
if(isset($parseArgu["content"]["levelForCheckSSL"])){
194
if(isset($parseArgu["content"]["levelForCheckSSL"])){
195
 
195
 
196
	#如果確實有該參數
196
	#如果確實有該參數
197
	if(isset($parseArgu["content"]["levelForCheckSSL"][0])){
197
	if(isset($parseArgu["content"]["levelForCheckSSL"][0])){
198
	
198
 
199
		#取得其設定
199
		#取得其設定
200
		$levelForCheckSSL=$parseArgu["content"]["levelForCheckSSL"][0];
200
		$levelForCheckSSL=$parseArgu["content"]["levelForCheckSSL"][0];
201
	
201
 
202
		}#if end
202
		}#if end
203
 
203
 
204
	}#if end
204
	}#if end
205
 
205
 
206
#無窮迴圈
206
#無窮迴圈
Line 274... Line 274...
274
 
274
 
275
			#結束執行
275
			#結束執行
276
			exit;
276
			exit;
277
 
277
 
278
			}#if end
278
			}#if end
279
			
279
 
280
		#針對每行輸出
280
		#針對每行輸出
281
		/*
281
		/*
282
		PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
282
		PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
283
 
283
 
284
		--- 1.1.1.1 ping statistics ---
284
		--- 1.1.1.1 ping statistics ---
285
		1 packets transmitted, 1 received, 0% packet loss, time 0ms
285
		1 packets transmitted, 1 received, 0% packet loss, time 0ms
286
		rtt min/avg/max/mdev = 46.251/46.251/46.251/0.000 ms
286
		rtt min/avg/max/mdev = 46.251/46.251/46.251/0.000 ms
287
		*/
287
		*/
288
		
288
 
289
		#函式說明:
289
		#函式說明:
290
		#檢查多個字串中的每個字串是否有多個關鍵字
290
		#檢查多個字串中的每個字串是否有多個關鍵字
291
		#回傳結果:
291
		#回傳結果:
292
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
292
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
293
		#$result["function"],當前執行的函數名稱.
293
		#$result["function"],當前執行的函數名稱.
Line 316... Line 316...
316
 
316
 
317
			#結束執行
317
			#結束執行
318
			exit;
318
			exit;
319
 
319
 
320
			}#if end
320
			}#if end
321
			
321
 
322
		#若沒有無遺失封包
322
		#若沒有無遺失封包
323
		if($findManyKeyWordsFromManyString["foundedAll"]==="false"){
323
		if($findManyKeyWordsFromManyString["foundedAll"]==="false"){
324
		
324
 
325
			#設置需要警報
325
			#設置需要警報
326
			$needAlarm="true";
326
			$needAlarm="true";
327
			
327
 
328
			#跳出foreach
328
			#跳出foreach
329
			break;
329
			break;
330
		
330
 
331
			}#if end
331
			}#if end
332
 
332
 
333
		}#foreach end
333
		}#foreach end
334
 
334
 
335
	#如果需要警報
335
	#如果需要警報
336
	if($needAlarm==="true"){
336
	if($needAlarm==="true"){
337
	
337
 
338
		#如果只要印出訊息
338
		#如果只要印出訊息
339
		if($echoOnly==="true"){
339
		if($echoOnly==="true"){
340
		
340
 
341
			#提示
341
			#提示
342
			echo "目前無法連線到指定的伺服器,請確認網路環境!".PHP_EOL;
342
			echo "目前無法連線到指定的伺服器,請確認網路環境!".PHP_EOL;
343
			
343
 
344
			#休息60秒
344
			#休息60秒
345
			sleep(60);
345
			sleep(60);
346
			
346
 
347
			#繼續執行
347
			#繼續執行
348
			continue;
348
			continue;
349
			
349
 
350
			}#if end
350
			}#if end
351
			
351
 
352
		#如果不透過smtp來寄信
352
		#如果不透過smtp來寄信
353
		if($sendBySmtp==="false"){
353
		if($sendBySmtp==="false"){
354
		
354
 
355
			#函式說明:
355
			#函式說明:
356
			#透過php的mail函數寄信
356
			#透過php的mail函數寄信
357
			#回傳結果:
357
			#回傳結果:
358
			#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
358
			#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
359
			#$result["error"],錯誤訊息陣列
359
			#$result["error"],錯誤訊息陣列
Line 363... Line 363...
363
			$conf["to"]=$receiver;
363
			$conf["to"]=$receiver;
364
			#$conf["subject"],字串,郵件標題.
364
			#$conf["subject"],字串,郵件標題.
365
			$conf["subject"]="目前無法連線到指定的伺服器,請確認網路環境!";
365
			$conf["subject"]="目前無法連線到指定的伺服器,請確認網路環境!";
366
			#$conf["content"],字串,要寄送的訊息內容.
366
			#$conf["content"],字串,要寄送的訊息內容.
367
			$conf["content"]="目前無法連線到指定的伺服器,請確認網路環境!";
367
			$conf["content"]="目前無法連線到指定的伺服器,請確認網路環境!";
368
			#可省略參數: 
368
			#可省略參數:
369
			#$conf["mailerEmail"],字串,顯示的寄件人.
369
			#$conf["mailerEmail"],字串,顯示的寄件人.
370
			#$conf["mailerEmail"]="";
370
			#$conf["mailerEmail"]="";
371
			#參考資料:
371
			#參考資料:
372
			#mail=>https://www.php.net/manual/en/function.mail.php
372
			#mail=>https://www.php.net/manual/en/function.mail.php
373
			#Internet Message Format=>http://www.faqs.org/rfcs/rfc2822
373
			#Internet Message Format=>http://www.faqs.org/rfcs/rfc2822
374
			$sendMail=mail::sendMail($conf);
374
			$sendMail=mail::sendMail($conf);
375
			unset($conf);
375
			unset($conf);
376
		
376
 
377
			#如果執行失敗
377
			#如果執行失敗
378
			if($sendMail["status"]==="false"){
378
			if($sendMail["status"]==="false"){
379
 
379
 
380
				#debug
380
				#debug
381
				var_dump($sendMail);
381
				var_dump($sendMail);
382
 
382
 
383
				#結束執行
383
				#結束執行
384
				exit;
384
				exit;
385
 
385
 
386
				}#if end
386
				}#if end
387
				
387
 
388
			#休息60秒
388
			#休息60秒
389
			sleep(60);
389
			sleep(60);
390
			
390
 
391
			#繼續執行
391
			#繼續執行
392
			continue;
392
			continue;
393
		
393
 
394
			}#if end
394
			}#if end
395
 
395
 
396
		#到這邊代表要用smtp寄信
396
		#到這邊代表要用smtp寄信
397
		#函式說明:
397
		#函式說明:
398
		#使用 curl 來透過SMTP伺服器寄信
398
		#使用 curl 來透過SMTP伺服器寄信
Line 466... Line 466...
466
 
466
 
467
			}#if end
467
			}#if end
468
 
468
 
469
		#休息60秒
469
		#休息60秒
470
		sleep(60);
470
		sleep(60);
471
		
471
 
472
		#繼續執行
472
		#繼續執行
473
		continue;
473
		continue;
474
 
474
 
475
		}#if end
475
		}#if end
476
		
476
 
477
	}#while end
477
	}#while end
478
 
478