Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 922 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
#!/bin/php
2
<?php
3
 
119 liveuser 4
/*
464 liveuser 5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
619 liveuser 6
    Copyright (C) 2015~2024 Min-Jhin,Chen
119 liveuser 7
 
464 liveuser 8
    This file is part of QBPWCF.
9
 
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
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
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/>.
22
 
23
*/
24
 
25
/*
26
 
119 liveuser 27
說明:
28
監控系統若負載超過總執行序就警報
29
 
30
參考資料:
31
https://www.php.net/manual/en/function.htmlentities.php
32
 
33
*/
34
 
1 liveuser 35
#使用命名空間qbpwcf
36
namespace qbpwcf;
37
 
953 liveuser 38
#取得 lib path
39
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
40
 
41
#如果執行失敗
42
if($status!==0){
43
 
44
	#debug
45
	var_dump(__LINE__,$output);
46
 
47
	#結束執行,回傳shell 1.
48
	exit(1);
49
 
50
	}#if end
51
 
52
#儲存lib path
53
$folderOfUsrLib=$output[0];
54
 
466 liveuser 55
#以該檔案的實際位置的 lib path 為 include path 首位
953 liveuser 56
$output=array();
57
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
58
 
59
#如果執行失敗
60
if($status!==0){
61
 
62
	#debug
63
	var_dump(__LINE__,$output);
64
 
65
	#結束執行,回傳shell 1.
66
	exit(1);
67
 
68
	}#if end
69
 
70
#設置 include path 
466 liveuser 71
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
72
 
464 liveuser 73
#匯入外部套件
466 liveuser 74
include("allInOne.php");
1 liveuser 75
 
70 liveuser 76
#上一封信件寄送的分鐘
77
$lastEmailMinute=gmdate("i");
78
 
1 liveuser 79
#預設執行間隔為1秒鐘
80
$interval=1;
81
 
70 liveuser 82
#預設不開啟所有訊息
83
$verbose=false;
84
 
1 liveuser 85
#預設每天執行的時間範圍為0跟23,亦即每個小時都執行
86
$s=0;
87
$e=23;
88
 
89
#函式說明:
90
#抓取命令列的參數.
91
#回傳結果:
92
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
93
#$reuslt["error"],執行不正常結束的錯訊息陣列.
94
#$result["function"],當前執行的函式名稱.
95
#$result["argu"],使用的參數陣列.
96
#$result["content"],要回傳的參數陣列.
97
#$result["count"],參數的數量.
98
#必填參數:
99
#無
100
#可省略參數:
101
#$conf["echo"],"true"代表要將抓到的參數一個個印出來,"false"代表用回傳的方式,預設為"false".
102
$conf["echo"]="false";
103
$getArgu=cmd::getArgu($conf);
104
unset($conf);
105
 
106
#如果執行失敗
107
if($getArgu["status"]==="false"){
108
 
109
	#結束執行
110
	return false;
111
 
112
	}#if end
113
 
114
#如果存在一個參數
115
if(isset($getArgu["content"][1])){
116
 
117
	#如果有參數 -h 或 --help 存在
118
	if( $getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help" ){
119
 
120
		#印出指令說明
70 liveuser 121
		echo "Usage ".basename(__FILE__).":".PHP_EOL; 
122
		echo "\t-i 秒數間隔 -s 開始小時 -e 結束小時".PHP_EOL;
118 liveuser 123
		echo "\t--verbose on 代表提示所有訊息".PHP_EOL;
70 liveuser 124
		echo "\t--eacct 用於寄信的gmail賬戶".PHP_EOL;
125
		echo "\t--epass 用於寄信的gmail密碼".PHP_EOL;
126
		echo "\t--receiver 收件人,一次指定一個收件人".PHP_EOL;
127
		echo "\t--target 監控的主機名稱".PHP_EOL;
1 liveuser 128
 
129
		#結束執行
130
		exit;
131
 
132
		}#if end
133
 
134
	}#if end
135
 
136
#函式說明:
137
#解析參數.
138
#回傳結果:
139
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
140
#$reuslt["error"],執行不正常結束的錯訊息陣列.
141
#$result["function"],當前執行的函式名稱.
142
#$result["content"],解析好的參數陣列.
143
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
144
#$result["program"],字串,執行的程式名稱.
145
#必填參數:
146
#無
147
#可省略參數:
148
#無
149
#備註:
150
#僅能在命令列底下執行.
151
#建議:
152
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
104 liveuser 153
$conf=array();
154
$parseArgu=cmd::parseArgu($conf);
155
unset($conf);
1 liveuser 156
 
157
#如果執行失敗
158
if($parseArgu["status"]==="false"){
159
 
160
	#結束執行
161
	return false;
162
 
163
	}#if end
164
 
165
#如果有參數
166
if(isset($parseArgu["content"])){
167
 
168
	#如果有參數 i
169
	if(isset($parseArgu["content"]["i"])){
170
 
171
		#如果有一個參數 i
172
		if(isset($parseArgu["content"]["i"][0])){
173
 
174
			#如果是正常的數值
175
			if((int)$parseArgu["content"]["i"][0]>0){
176
 
177
				#設置新的 interval
178
				$interval=(int)$parseArgu["content"]["i"][0];
179
 
180
				}#if end
181
 
182
			}#if end
183
 
184
		}#if end
185
 
186
	#如果有參數 s
187
	if(isset($parseArgu["content"]["s"])){
188
 
189
		#如果有一個參數 s
190
		if(isset($parseArgu["content"]["s"][0])){
191
 
192
			#如果是正常的數值
193
			if( (int)$parseArgu["content"]["s"][0]>0 && (int)$parseArgu["content"]["s"][0]<23 ){
194
 
195
				#設置新的開始小時
196
				$s=(int)$parseArgu["content"]["s"][0];
197
 
198
				}#if end
199
 
200
			}#if end
201
 
202
		}#if end
203
 
204
	#如果有參數 e
205
	if(isset($parseArgu["content"]["e"])){
206
 
207
		#如果有一個參數 e
208
		if(isset($parseArgu["content"]["e"][0])){
209
 
210
			#如果是正常的數值
211
			if( (int)$parseArgu["content"]["e"][0]>0 && (int)$parseArgu["content"]["e"][0]<23 ){
212
 
213
				#設置新的結束小時
214
				$e=(int)$parseArgu["content"]["e"][0];
215
 
216
				}#if end
217
 
218
			}#if end
219
 
220
		}#if end
221
 
70 liveuser 222
	#如果有參數 verbose
223
	if(isset($parseArgu["content"]["verbose"])){
224
 
225
		#如果有一個參數verbose
226
		if(isset($parseArgu["content"]["verbose"][0])){
227
 
228
			#設置要 verbose
229
			$verbose=true;
230
 
231
			}#if end
232
 
233
		}#if end
234
 
235
	#如果有參數 eacct
236
	if(isset($parseArgu["content"]["eacct"])){
237
 
238
		#如果有一個參數eacct
239
		if(isset($parseArgu["content"]["eacct"][0])){
240
 
241
			#設置eacct
242
			$eacct=$parseArgu["content"]["eacct"][0];
243
 
244
			}#if end
245
 
246
		}#if end
247
 
248
	#如果有參數 epass
249
	if(isset($parseArgu["content"]["epass"])){
250
 
251
		#如果有一個參數epass
252
		if(isset($parseArgu["content"]["epass"][0])){
253
 
254
			#設置epass
255
			$epass=$parseArgu["content"]["epass"][0];
256
 
257
			}#if end
258
 
259
		}#if end
260
 
261
	#如果有參數 receiver
262
	if(isset($parseArgu["content"]["receiver"])){
263
 
264
		#設置receiver
265
		$receiver=$parseArgu["content"]["receiver"];
266
 
267
		}#if end
268
 
269
	#如果有參數 target
270
	if(isset($parseArgu["content"]["target"])){
271
 
272
		#如果有一個參數target
273
		if(isset($parseArgu["content"]["target"][0])){
274
 
275
			#設置target
276
			$target=$parseArgu["content"]["target"][0];
277
 
278
			}#if end
279
 
280
		}#if end
281
 
1 liveuser 282
	}#if end	
283
 
70 liveuser 284
#如果參數有缺
285
if( !isset($eacct) || !isset($epass) || !isset($receiver) || !isset($target) )
286
{
287
	echo "參數 --eacct 跟 --epass 跟 --receiver 跟 --target 必填".PHP_EOL;
288
	exit;
289
}
290
 
291
#預設上次不需要警示
292
$lastAlert=false;
293
 
294
#預設上次的警示數值為0
295
$lastAlertValue=0;
296
 
1 liveuser 297
#無窮迴圈
298
while(true){
299
 
300
	#取得現在時間
301
	#涵式說明:
302
	#呼叫shell執行系統命令,並取得回傳的內容.
303
	#回傳的結果:
304
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
305
	#$result["error"],錯誤訊息陣列.
306
	#$result["function"],當前執行的函數名稱.
307
	#$result["argu"],使用的參數.
308
	#$result["cmd"],執行的指令內容.
309
	#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
310
	#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
311
	#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
312
	#$result["running"],是否還在執行.
313
	#$result["pid"],pid.
314
	#$result["statusCode"],執行結束後的代碼.
315
	#必填的參數
316
	#$conf["command"],字串,要執行的指令與.
317
	$conf["command"]="date";
318
	#$conf["fileArgu"],字串,變數__FILE__的內容.
319
	$conf["fileArgu"]=__FILE__;		
320
	#可省略參數:
321
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
322
	$conf["argu"]=array("-d","now","+%H");
323
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
324
	#$conf["arguIsAddr"]=array();	
325
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
326
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
327
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
328
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
329
	#$conf["enablePrintDescription"]="true";
330
	#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
331
	#$conf["printDescription"]="";
332
	#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
453 liveuser 333
	$conf["escapeshellarg"]="true";
1 liveuser 334
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
335
	#$conf["username"]="";
336
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
337
	#$conf["password"]="";
338
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
339
	#$conf["useScript"]="";
340
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
341
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
342
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
343
	#$conf["inBackGround"]="";
344
	#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
345
	#$conf["getErr"]="false";
346
	#備註:
347
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
348
	#參考資料:
349
	#exec=>http://php.net/manual/en/function.exec.php
350
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
351
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
352
	$callShell=external::callShell($conf);
353
	unset($conf);
354
 
355
	#如果執行出錯
356
	if($callShell["status"]===false){
357
 
358
		#結束執行
359
		return false;
360
 
361
		}#if end
362
 
363
	#如果沒有回小時
364
	if(!isset($callShell["output"][0])){
365
 
366
		#結束執行
367
		return false;
368
 
369
		}#if end
370
 
371
	#取得輸出
372
	$hour=$callShell["output"][0];
373
 
374
	#如果小於開始小時
375
	if($hour<(int)$s){
376
 
377
		#休息一小時
378
		sleep(3600);
379
 
380
		#再跑一次
381
		continue;
382
 
383
		}#if end
384
 
385
	#如果大於結束小時
386
	if($hour>(int)$e){
387
 
388
		#休息一小時
389
		sleep(3600);
390
 
391
		#再跑一次
392
		continue;
393
 
394
		}#if end
395
 
396
	#取得現在時間
397
	#涵式說明:
398
	#呼叫shell執行系統命令,並取得回傳的內容.
399
	#回傳的結果:
400
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
401
	#$result["error"],錯誤訊息陣列.
402
	#$result["function"],當前執行的函數名稱.
403
	#$result["argu"],使用的參數.
404
	#$result["cmd"],執行的指令內容.
405
	#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
406
	#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
407
	#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
408
	#$result["running"],是否還在執行.
409
	#$result["pid"],pid.
410
	#$result["statusCode"],執行結束後的代碼.
411
	#必填的參數
412
	#$conf["command"],字串,要執行的指令與.
413
	$conf["command"]="date";
414
	#$conf["fileArgu"],字串,變數__FILE__的內容.
415
	$conf["fileArgu"]=__FILE__;		
416
	#可省略參數:
417
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
418
	#$conf["argu"]=array("");
419
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
420
	#$conf["arguIsAddr"]=array();	
421
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
422
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
423
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
424
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
425
	#$conf["enablePrintDescription"]="true";
426
	#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
427
	#$conf["printDescription"]="";
428
	#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
453 liveuser 429
	$conf["escapeshellarg"]="true";
1 liveuser 430
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
431
	#$conf["username"]="";
432
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
433
	#$conf["password"]="";
434
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
435
	#$conf["useScript"]="";
436
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
437
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
438
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
439
	#$conf["inBackGround"]="";
440
	#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
441
	#$conf["getErr"]="false";
442
	#備註:
443
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
444
	#參考資料:
445
	#exec=>http://php.net/manual/en/function.exec.php
446
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
447
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
448
	$callShell=external::callShell($conf);
449
	unset($conf);
450
 
451
	#如果執行出錯
70 liveuser 452
	if($callShell["status"]==="false"){
1 liveuser 453
 
454
		#結束執行
455
		return false;
456
 
457
		}#if end
458
 
459
	#取得輸出
460
	$time=$callShell["output"];
461
 
462
	#涵式說明:
463
	#呼叫shell執行系統命令,並取得回傳的內容.
464
	#回傳的結果:
465
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
466
	#$result["error"],錯誤訊息陣列.
467
	#$result["function"],當前執行的函數名稱.
468
	#$result["argu"],使用的參數.
469
	#$result["cmd"],執行的指令內容.
470
	#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
471
	#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
472
	#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
473
	#$result["running"],是否還在執行.
474
	#$result["pid"],pid.
475
	#$result["statusCode"],執行結束後的代碼.
476
	#必填的參數
477
	#$conf["command"],字串,要執行的指令與.
478
	$conf["command"]="uptime";
479
	#$conf["fileArgu"],字串,變數__FILE__的內容.
480
	$conf["fileArgu"]=__FILE__;		
481
	#可省略參數:
482
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
483
	#$conf["argu"]=array("");
484
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
485
	#$conf["arguIsAddr"]=array();	
486
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
487
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
488
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
489
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
490
	#$conf["enablePrintDescription"]="true";
491
	#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
492
	#$conf["printDescription"]="";
493
	#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
453 liveuser 494
	$conf["escapeshellarg"]="true";
1 liveuser 495
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
496
	#$conf["username"]="";
497
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
498
	#$conf["password"]="";
499
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
500
	#$conf["useScript"]="";
501
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
502
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
503
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
504
	#$conf["inBackGround"]="";
505
	#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
506
	#$conf["getErr"]="false";
507
	#備註:
508
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
509
	#參考資料:
510
	#exec=>http://php.net/manual/en/function.exec.php
511
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
512
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
513
	$callShell=external::callShell($conf);
514
	unset($conf);
515
 
516
	#如果執行出錯
517
	if($callShell["status"]===false){
518
 
519
		#結束執行
520
		return false;
521
 
522
		}#if end
523
 
524
	#取得輸出
525
	$uptime=$callShell["output"];
526
 
70 liveuser 527
	#用來分割的關鍵字
528
	$splitWord="load average: ";
529
 
530
	#函式說明:
531
	#將固定格式的字串分開,並回傳分開的結果。
532
	#回傳結果:
533
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
534
	#$result["error"],錯誤訊息陣列
535
	#$result["function"],當前執行的函數名稱.
536
	#$result["argu"],使用的參數.
537
	#$result["oriStr"],要分割的原始字串內容
538
	#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
539
	#$result["dataCounts"],爲總共分成幾段
540
	#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
541
	#必填參數:
542
	#$conf["stringIn"],字串,要處理的字串.
543
	$conf["stringIn"]=$uptime[0];
544
	#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
545
	$conf["spiltSymbol"]=$splitWord;
546
	#可省略參數:
547
	#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
548
	$conf["allowEmptyStr"]="false";
549
	#備註:
550
	#無.
551
	$spiltString=stringProcess::spiltString($conf);
552
	unset($conf);
553
 
554
	#如果執行失敗
555
	if($spiltString["status"]==="false")
556
	{
557
		#結束執行
558
		return false;
559
	}
560
 
561
	#如果沒有指令的關鍵字存在
562
	if($spiltString["found"]==="false")
563
	{
564
		#結束執行
565
		return false;
566
	}
567
 
568
	#用來分割的關鍵字
569
	$splitWord=", ";
570
 
571
	#函式說明:
572
	#將固定格式的字串分開,並回傳分開的結果。
573
	#回傳結果:
574
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
575
	#$result["error"],錯誤訊息陣列
576
	#$result["function"],當前執行的函數名稱.
577
	#$result["argu"],使用的參數.
578
	#$result["oriStr"],要分割的原始字串內容
579
	#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
580
	#$result["dataCounts"],爲總共分成幾段
581
	#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
582
	#必填參數:
583
	#$conf["stringIn"],字串,要處理的字串.
584
	$conf["stringIn"]=$spiltString["dataArray"][1];
585
	#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
586
	$conf["spiltSymbol"]=$splitWord;
587
	#可省略參數:
588
	#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
589
	$conf["allowEmptyStr"]="false";
590
	#備註:
591
	#無.
592
	$spiltString=stringProcess::spiltString($conf);
593
	unset($conf);
594
 
595
	#如果執行失敗
596
	if($spiltString["status"]==="false")
597
	{
598
		#結束執行
599
		return false;
600
	}
601
 
602
	#如果沒有指令的關鍵字存在
603
	if($spiltString["found"]==="false")
604
	{
605
		#結束執行
606
		return false;
607
	}
608
 
609
	#取得uptime的當下數值
610
	$uptimeVal=$spiltString["dataArray"][0];
611
 
612
	#取得CPU有多少執行序
1 liveuser 613
	#涵式說明:
614
	#呼叫shell執行系統命令,並取得回傳的內容.
615
	#回傳的結果:
616
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
617
	#$result["error"],錯誤訊息陣列.
618
	#$result["function"],當前執行的函數名稱.
619
	#$result["argu"],使用的參數.
620
	#$result["cmd"],執行的指令內容.
621
	#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
622
	#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
623
	#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
624
	#$result["running"],是否還在執行.
625
	#$result["pid"],pid.
626
	#$result["statusCode"],執行結束後的代碼.
627
	#必填的參數
628
	#$conf["command"],字串,要執行的指令與.
453 liveuser 629
	$conf["command"]="lscpu";
70 liveuser 630
	#$conf["fileArgu"],字串,變數__FILE__的內容.
631
	$conf["fileArgu"]=__FILE__;		
632
	#可省略參數:
633
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
453 liveuser 634
	$conf["argu"]=array("|","grep","CPU(s)","|","grep","-v","NUMA");
70 liveuser 635
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
636
	#$conf["arguIsAddr"]=array();	
637
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
638
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
639
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
640
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
641
	#$conf["enablePrintDescription"]="true";
642
	#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
643
	#$conf["printDescription"]="";
644
	#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
453 liveuser 645
	$conf["escapeshellarg"]="true";
70 liveuser 646
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
647
	#$conf["username"]="";
648
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
649
	#$conf["password"]="";
650
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
651
	#$conf["useScript"]="";
652
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
653
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
654
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
655
	#$conf["inBackGround"]="";
656
	#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
657
	#$conf["getErr"]="false";
658
	#備註:
659
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
660
	#參考資料:
661
	#exec=>http://php.net/manual/en/function.exec.php
662
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
663
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
664
	$callShell=external::callShell($conf);
665
	unset($conf);
666
 
667
	#如果執行出錯
668
	if($callShell["status"]==="false"){
669
 
670
		#結束執行
671
		return false;
672
 
673
		}#if end
674
 
675
	#取得輸出
676
	$lscpu=$callShell["output"];
677
 
678
	#用來分割的關鍵字
679
	$splitWord="CPU(s): ";
680
 
681
	#函式說明:
682
	#將固定格式的字串分開,並回傳分開的結果。
683
	#回傳結果:
684
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
685
	#$result["error"],錯誤訊息陣列
686
	#$result["function"],當前執行的函數名稱.
687
	#$result["argu"],使用的參數.
688
	#$result["oriStr"],要分割的原始字串內容
689
	#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
690
	#$result["dataCounts"],爲總共分成幾段
691
	#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
692
	#必填參數:
693
	#$conf["stringIn"],字串,要處理的字串.
694
	$conf["stringIn"]=$lscpu[0];
695
	#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
696
	$conf["spiltSymbol"]=$splitWord;
697
	#可省略參數:
698
	#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
699
	$conf["allowEmptyStr"]="false";
700
	#備註:
701
	#無.
702
	$spiltString=stringProcess::spiltString($conf);
703
	unset($conf);
704
 
705
	#如果執行失敗
706
	if($spiltString["status"]==="false")
707
	{
708
		#結束執行
709
		return false;
710
	}
711
 
712
	#如果沒有指令的關鍵字存在
713
	if($spiltString["found"]==="false")
714
	{
715
		#結束執行
716
		return false;
717
	}
718
 
719
	#取得uptime的當下數值
720
	$lscpuVal=(int)$spiltString["dataArray"][0];
721
 
722
	#如果有程序必須等待cpu給予資源
723
	if($uptimeVal>=$lscpuVal)
724
	{
725
		#設置需要警示
726
		$alert=true;
727
	}
728
	#反之解除
729
	else
730
	{
731
		#設置需要警示
732
		$alert=false;
733
	}
734
 
735
	#設置警示數值
736
	$alertValue=$uptimeVal;
737
 
98 liveuser 738
	#取得當前程序樹
70 liveuser 739
	#涵式說明:
740
	#呼叫shell執行系統命令,並取得回傳的內容.
741
	#回傳的結果:
742
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
743
	#$result["error"],錯誤訊息陣列.
744
	#$result["function"],當前執行的函數名稱.
745
	#$result["argu"],使用的參數.
746
	#$result["cmd"],執行的指令內容.
747
	#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
748
	#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
749
	#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
750
	#$result["running"],是否還在執行.
751
	#$result["pid"],pid.
752
	#$result["statusCode"],執行結束後的代碼.
753
	#必填的參數
754
	#$conf["command"],字串,要執行的指令與.
453 liveuser 755
	$conf["command"]="ps";
1 liveuser 756
	#$conf["fileArgu"],字串,變數__FILE__的內容.
757
	$conf["fileArgu"]=__FILE__;		
758
	#可省略參數:
759
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
453 liveuser 760
	$conf["argu"]=array("axuwf","|","cat");
1 liveuser 761
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
762
	#$conf["arguIsAddr"]=array();	
763
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
764
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
765
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
766
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
767
	#$conf["enablePrintDescription"]="true";
768
	#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
769
	#$conf["printDescription"]="";
770
	#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
453 liveuser 771
	$conf["escapeshellarg"]="true";
1 liveuser 772
	#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
773
	#$conf["username"]="";
774
	#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
775
	#$conf["password"]="";
776
	#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
777
	#$conf["useScript"]="";
778
	#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
779
	#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
780
	#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
781
	#$conf["inBackGround"]="";
782
	#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
783
	#$conf["getErr"]="false";
784
	#備註:
785
	#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
786
	#參考資料:
787
	#exec=>http://php.net/manual/en/function.exec.php
788
	#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
789
	#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
790
	$callShell=external::callShell($conf);
791
	unset($conf);
792
 
793
	#如果執行出錯
70 liveuser 794
	if($callShell["status"]==="false"){
1 liveuser 795
 
796
		#結束執行
797
		return false;
798
 
799
		}#if end
800
 
801
	#取得輸出
802
	$output=$callShell["output"];
803
 
804
	#$time,現在時間
805
	#$uptime,load average.
806
	#$output,完整工作程序樹
807
 
70 liveuser 808
	#設置郵件參數
809
	$conf["acct"]=$eacct;
810
	$conf["pass"]=$epass;
811
	$conf["receiver"]=$receiver;
1 liveuser 812
 
70 liveuser 813
	#設置時間
814
	$date=date("Y-m-d H:i:s");
1 liveuser 815
 
70 liveuser 816
	#如果從正常狀態進入需要警示的狀態
817
	if($lastAlert===false && $alert===true)
818
	{	
819
		#警示超過負荷
820
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 超過負荷(".$alertValue.">".$lscpuVal.")了".PHP_EOL;
72 liveuser 821
 
98 liveuser 822
		#串接完整的工作樹
823
		foreach($output as $line)
72 liveuser 824
		{
825
			$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
118 liveuser 826
			$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
72 liveuser 827
		}
98 liveuser 828
 
70 liveuser 829
		#寄送通知信件
830
		sendMail($conf);			
831
 
832
		#更新寄送的分鐘
833
		$lastEmailMinute=gmdate("i");
834
 
835
	}#if end
836
 
837
	#反之如果負載更嚴重了
838
	else if($lastAlert===true && $alert===true && $alertValue>$lastAlertValue)
839
	{
840
		#警示超過負荷
841
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 負荷更重了(".$alertValue.">".$lscpuVal.")了".PHP_EOL;
1 liveuser 842
 
98 liveuser 843
		#如果不同分鐘,且超過5分鐘了
844
		if($lastEmailMinute!==gmdate("i") && (gmdate("i")-$lastEmailMinute)>5 )
70 liveuser 845
		{
98 liveuser 846
			#串接完整的工作樹
847
			foreach($output as $line)
72 liveuser 848
			{
849
				$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
118 liveuser 850
				$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
72 liveuser 851
			}
852
 
853
			#加上pre tag
854
			$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
855
 
70 liveuser 856
			#寄送通知信件
857
			sendMail($conf);
858
 
859
			#更新寄送的分鐘
860
			$lastEmailMinute=gmdate("i");
861
 
1 liveuser 862
		}#if end
863
 
70 liveuser 864
	}#if end
1 liveuser 865
 
70 liveuser 866
	#反之如果可以負荷了
867
	else if($lastAlert===true && $alert===false)
868
	{
869
		#提示恢復正常了
870
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 恢復正常了".PHP_EOL;
871
 
98 liveuser 872
		#串接完整的工作樹
873
		foreach($output as $line)
72 liveuser 874
		{
875
			$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
118 liveuser 876
			$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
72 liveuser 877
		}
878
 
879
		#加上pre tag
880
		$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
881
 
70 liveuser 882
		#寄送通知信件
883
		sendMail($conf);
1 liveuser 884
 
70 liveuser 885
	}#if end
1 liveuser 886
 
70 liveuser 887
	#其他不需要警示與提示的狀況,如果有開啟 $verbose
888
	else if($verbose===true)
889
	{
890
		#verbose訊息
891
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 正常(".$alertValue."<".$lscpuVal.")".PHP_EOL;
892
 
98 liveuser 893
		#如果不同分鐘,且超過5分鐘了
894
		if($lastEmailMinute!==gmdate("i") && (gmdate("i")-$lastEmailMinute)>5 )
70 liveuser 895
		{
98 liveuser 896
			#串接完整的工作樹
897
			foreach($output as $line)
72 liveuser 898
			{
899
				$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
118 liveuser 900
				$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
72 liveuser 901
			}
902
 
903
			#加上pre tag
904
			$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
905
 
70 liveuser 906
			#寄送通知信件
907
			sendMail($conf);
908
 
909
			#更新寄送的分鐘
910
			$lastEmailMinute=gmdate("i");
911
 
1 liveuser 912
		}#if end
913
 
70 liveuser 914
	}#else end
123 liveuser 915
 
70 liveuser 916
	#移除mail參數
917
	unset($conf);
123 liveuser 918
 
70 liveuser 919
	#更新上次的是否需要警示識別
920
	$lastAlert=$alert;
921
 
922
	#更新上次的警示數值為
923
	$lastAlertValue=$alertValue;
123 liveuser 924
 
1 liveuser 925
	#休息 $interval 秒
926
	sleep($interval);
927
 
928
	}#while end
929
 
70 liveuser 930
#寄送email
931
function sendMail($conf)
932
{
933
	#接收參數
934
	$acct=$conf["acct"];
935
	$pass=$conf["pass"];
936
	$receiver=$conf["receiver"];
937
	$subject=$conf["subject"];
938
	$plainBody=$conf["plainBody"];
939
	$htmlBody=$conf["htmlBody"];
940
	unset($conf);
941
 
942
	#函式說明:
943
	#使用 curl 來透過SMTP伺服器寄信
944
	#回傳結果:
945
	#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
946
	#$result["error"],錯誤訊息陣列
947
	#$result["function"],當前執行的函數
948
	#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
949
	#$result["cmd"],寄信的指令.
950
	#$result["detailCmd"],較詳細的寄信指令.
951
	#必填參數:
952
	#$conf["username"],字串,用來登入郵件伺服器的帳號
953
	$conf["username"]=$acct;
954
	#$conf["password"],字串,用來登入郵件伺服器的密碼
955
	$conf["password"]=$pass;
956
	#$conf["receiverMail"],陣列,收件人的信箱
957
	$conf["receiverMail"]=$receiver;
958
	#$conf["subject"],字串,郵件的主題
959
	$conf["subject"]=$subject;
960
	#$conf["plainBody"],字串,郵件本文的純文字內容.
961
	$conf["plainBody"]=$plainBody;
962
	#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
963
	$conf["htmlBody"]=$htmlBody;
964
	#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
965
	$conf["fileArgu"]=__FILE__;
966
	#可省略參數:
967
	#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
968
	#$conf["mailServer"]="";
969
	#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
970
	#$conf["mailerMailDisplay"]="";
971
	#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
972
	#$conf["mailerNameDisplay"]="";
973
	#$conf["receiverMailDisplay"],陣列,要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
974
	#$conf["receiverMailDisplay"]="";#
975
	#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
976
	#$conf["receiverNameDisplay"]="";
977
	#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
978
	#$conf["attachment"]=array();
979
	#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
980
	#$conf["attachmentName"]=array();
981
	#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
982
	#$conf["attachmentMimeType"]array();
983
	#範例語句:
984
	#curl --url smtps://smtp.gmail.com:465 -u username@gmail.com:userPassword --mail-from username@gmail.com --mail-rcpt receiver@mail.com --upload-file mail.txt -v
985
	#範例信件內容:
986
	#From: "userName" <username@gmail.com>
987
	#To: "receiverName" <userPassword@yahoo.com.tw>
988
	#Subject: This is a test
989
	#本文~
990
	#參考資料來源:
991
	#用curl來寄信=>http://stackoverflow.com/questions/14722556/using-curl-to-send-email
992
	#降低安全性標準讓curl可以使用=>https://www.google.com/settings/security/lesssecureapps
993
	#信件內容header的設定=>http://jjdai.zhupiter.com/2010/10/php-%E5%A6%82%E4%BD%95%E5%82%B3%E9%80%81%E4%B8%80%E5%B0%81-mime-html-%E6%A0%BC%E5%BC%8F%E7%9A%84-email-%E4%BF%A1%E4%BB%B6/
994
	#檔案每列不得超超過70個字元=>http://php.net/manual/en/function.mail.php
995
	#寄信給多人=>https://github.com/curl/curl/issues/784
996
	#備註:
997
	#信件的內容格式有錯,導致本文無法顯示.
998
	$curlSmtp=mail::curlSmtp($conf);
999
	unset($conf);
1000
 
1001
	#如果執行失敗
1002
	if($curlSmtp["status"]==="false")
1003
	{
1004
		#印出內容
1005
		var_dump($curlSmtp);
1006
 
1007
		#結束執行
1008
		exit;		
1009
 
1010
	}#if end
1011
 
123 liveuser 1012
}#function sendMail end