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 65... Line 65...
65
	#結束執行,回傳shell 1.
65
	#結束執行,回傳shell 1.
66
	exit(1);
66
	exit(1);
67
 
67
 
68
	}#if end
68
	}#if end
69
 
69
 
70
#設置 include path 
70
#設置 include path
71
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
71
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
72
 
72
 
73
#匯入外部套件
73
#匯入外部套件
74
include("allInOne.php");
74
include("allInOne.php");
75
 
75
 
Line 114... Line 114...
114
#如果存在一個參數
114
#如果存在一個參數
115
if(isset($getArgu["content"][1])){
115
if(isset($getArgu["content"][1])){
116
 
116
 
117
	#如果有參數 -h 或 --help 存在
117
	#如果有參數 -h 或 --help 存在
118
	if( $getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help" ){
118
	if( $getArgu["content"][1]==="-h" || $getArgu["content"][1]==="--help" ){
119
	
119
 
120
		#印出指令說明
120
		#印出指令說明
121
		echo "Usage ".basename(__FILE__).":".PHP_EOL; 
121
		echo "Usage ".basename(__FILE__).":".PHP_EOL;
122
		echo "\t-i 秒數間隔 -s 開始小時 -e 結束小時".PHP_EOL;
122
		echo "\t-i 秒數間隔 -s 開始小時 -e 結束小時".PHP_EOL;
123
		echo "\t--verbose on 代表提示所有訊息".PHP_EOL;
123
		echo "\t--verbose on 代表提示所有訊息".PHP_EOL;
124
		echo "\t--eacct 用於寄信的gmail賬戶".PHP_EOL;
124
		echo "\t--eacct 用於寄信的gmail賬戶".PHP_EOL;
125
		echo "\t--epass 用於寄信的gmail密碼".PHP_EOL;
125
		echo "\t--epass 用於寄信的gmail密碼".PHP_EOL;
126
		echo "\t--receiver 收件人,一次指定一個收件人".PHP_EOL;
126
		echo "\t--receiver 收件人,一次指定一個收件人".PHP_EOL;
127
		echo "\t--target 監控的主機名稱".PHP_EOL;
127
		echo "\t--target 監控的主機名稱".PHP_EOL;
128
	
128
 
129
		#結束執行
129
		#結束執行
130
		exit;
130
		exit;
131
	
131
 
132
		}#if end
132
		}#if end
133
 
133
 
134
	}#if end
134
	}#if end
135
 
135
 
136
#函式說明:
136
#函式說明:
Line 165... Line 165...
165
#如果有參數
165
#如果有參數
166
if(isset($parseArgu["content"])){
166
if(isset($parseArgu["content"])){
167
 
167
 
168
	#如果有參數 i
168
	#如果有參數 i
169
	if(isset($parseArgu["content"]["i"])){
169
	if(isset($parseArgu["content"]["i"])){
170
	
170
 
171
		#如果有一個參數 i
171
		#如果有一個參數 i
172
		if(isset($parseArgu["content"]["i"][0])){
172
		if(isset($parseArgu["content"]["i"][0])){
173
		
173
 
174
			#如果是正常的數值
174
			#如果是正常的數值
175
			if((int)$parseArgu["content"]["i"][0]>0){
175
			if((int)$parseArgu["content"]["i"][0]>0){
176
			
176
 
177
				#設置新的 interval
177
				#設置新的 interval
178
				$interval=(int)$parseArgu["content"]["i"][0];
178
				$interval=(int)$parseArgu["content"]["i"][0];
179
			
179
 
180
				}#if end
180
				}#if end
181
						
181
 
182
			}#if end
182
			}#if end
183
	
183
 
184
		}#if end
184
		}#if end
185
		
185
 
186
	#如果有參數 s
186
	#如果有參數 s
187
	if(isset($parseArgu["content"]["s"])){
187
	if(isset($parseArgu["content"]["s"])){
188
	
188
 
189
		#如果有一個參數 s
189
		#如果有一個參數 s
190
		if(isset($parseArgu["content"]["s"][0])){
190
		if(isset($parseArgu["content"]["s"][0])){
191
	
191
 
192
			#如果是正常的數值
192
			#如果是正常的數值
193
			if( (int)$parseArgu["content"]["s"][0]>0 && (int)$parseArgu["content"]["s"][0]<23 ){
193
			if( (int)$parseArgu["content"]["s"][0]>0 && (int)$parseArgu["content"]["s"][0]<23 ){
194
		
194
 
195
				#設置新的開始小時
195
				#設置新的開始小時
196
				$s=(int)$parseArgu["content"]["s"][0];
196
				$s=(int)$parseArgu["content"]["s"][0];
197
		
197
 
198
				}#if end
198
				}#if end
199
		
199
 
200
			}#if end
200
			}#if end
201
		
201
 
202
		}#if end
202
		}#if end
203
		
203
 
204
	#如果有參數 e
204
	#如果有參數 e
205
	if(isset($parseArgu["content"]["e"])){
205
	if(isset($parseArgu["content"]["e"])){
206
	
206
 
207
		#如果有一個參數 e
207
		#如果有一個參數 e
208
		if(isset($parseArgu["content"]["e"][0])){
208
		if(isset($parseArgu["content"]["e"][0])){
209
	
209
 
210
			#如果是正常的數值
210
			#如果是正常的數值
211
			if( (int)$parseArgu["content"]["e"][0]>0 && (int)$parseArgu["content"]["e"][0]<23 ){
211
			if( (int)$parseArgu["content"]["e"][0]>0 && (int)$parseArgu["content"]["e"][0]<23 ){
212
		
212
 
213
				#設置新的結束小時
213
				#設置新的結束小時
214
				$e=(int)$parseArgu["content"]["e"][0];
214
				$e=(int)$parseArgu["content"]["e"][0];
215
		
215
 
216
				}#if end
216
				}#if end
217
		
217
 
218
			}#if end
218
			}#if end
219
		
219
 
220
		}#if end
220
		}#if end
221
	
221
 
222
	#如果有參數 verbose
222
	#如果有參數 verbose
223
	if(isset($parseArgu["content"]["verbose"])){
223
	if(isset($parseArgu["content"]["verbose"])){
224
	
224
 
225
		#如果有一個參數verbose
225
		#如果有一個參數verbose
226
		if(isset($parseArgu["content"]["verbose"][0])){
226
		if(isset($parseArgu["content"]["verbose"][0])){
227
	
227
 
228
			#設置要 verbose
228
			#設置要 verbose
229
			$verbose=true;
229
			$verbose=true;
230
					
230
 
231
			}#if end
231
			}#if end
232
		
232
 
233
		}#if end
233
		}#if end
234
 
234
 
235
	#如果有參數 eacct
235
	#如果有參數 eacct
236
	if(isset($parseArgu["content"]["eacct"])){
236
	if(isset($parseArgu["content"]["eacct"])){
237
	
237
 
238
		#如果有一個參數eacct
238
		#如果有一個參數eacct
239
		if(isset($parseArgu["content"]["eacct"][0])){
239
		if(isset($parseArgu["content"]["eacct"][0])){
240
	
240
 
241
			#設置eacct
241
			#設置eacct
242
			$eacct=$parseArgu["content"]["eacct"][0];
242
			$eacct=$parseArgu["content"]["eacct"][0];
243
					
243
 
244
			}#if end
244
			}#if end
245
		
245
 
246
		}#if end
246
		}#if end
247
		
247
 
248
	#如果有參數 epass
248
	#如果有參數 epass
249
	if(isset($parseArgu["content"]["epass"])){
249
	if(isset($parseArgu["content"]["epass"])){
250
	
250
 
251
		#如果有一個參數epass
251
		#如果有一個參數epass
252
		if(isset($parseArgu["content"]["epass"][0])){
252
		if(isset($parseArgu["content"]["epass"][0])){
253
	
253
 
254
			#設置epass
254
			#設置epass
255
			$epass=$parseArgu["content"]["epass"][0];
255
			$epass=$parseArgu["content"]["epass"][0];
256
					
256
 
257
			}#if end
257
			}#if end
258
		
258
 
259
		}#if end
259
		}#if end
260
	
260
 
261
	#如果有參數 receiver
261
	#如果有參數 receiver
262
	if(isset($parseArgu["content"]["receiver"])){
262
	if(isset($parseArgu["content"]["receiver"])){
263
	
263
 
264
		#設置receiver
264
		#設置receiver
265
		$receiver=$parseArgu["content"]["receiver"];
265
		$receiver=$parseArgu["content"]["receiver"];
266
		
266
 
267
		}#if end
267
		}#if end
268
	
268
 
269
	#如果有參數 target
269
	#如果有參數 target
270
	if(isset($parseArgu["content"]["target"])){
270
	if(isset($parseArgu["content"]["target"])){
271
	
271
 
272
		#如果有一個參數target
272
		#如果有一個參數target
273
		if(isset($parseArgu["content"]["target"][0])){
273
		if(isset($parseArgu["content"]["target"][0])){
274
	
274
 
275
			#設置target
275
			#設置target
276
			$target=$parseArgu["content"]["target"][0];
276
			$target=$parseArgu["content"]["target"][0];
277
					
277
 
278
			}#if end
278
			}#if end
279
		
279
 
280
		}#if end
280
		}#if end
281
	
281
 
282
	}#if end	
282
	}#if end
283
 
283
 
284
#如果參數有缺
284
#如果參數有缺
285
if( !isset($eacct) || !isset($epass) || !isset($receiver) || !isset($target) )
285
if( !isset($eacct) || !isset($epass) || !isset($receiver) || !isset($target) )
286
{
286
{
287
	echo "參數 --eacct 跟 --epass 跟 --receiver 跟 --target 必填".PHP_EOL;
287
	echo "參數 --eacct 跟 --epass 跟 --receiver 跟 --target 必填".PHP_EOL;
Line 314... Line 314...
314
	#$result["statusCode"],執行結束後的代碼.
314
	#$result["statusCode"],執行結束後的代碼.
315
	#必填的參數
315
	#必填的參數
316
	#$conf["command"],字串,要執行的指令與.
316
	#$conf["command"],字串,要執行的指令與.
317
	$conf["command"]="date";
317
	$conf["command"]="date";
318
	#$conf["fileArgu"],字串,變數__FILE__的內容.
318
	#$conf["fileArgu"],字串,變數__FILE__的內容.
319
	$conf["fileArgu"]=__FILE__;		
319
	$conf["fileArgu"]=__FILE__;
320
	#可省略參數:
320
	#可省略參數:
321
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
321
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
322
	$conf["argu"]=array("-d","now","+%H");
322
	$conf["argu"]=array("-d","now","+%H");
323
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
323
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
324
	#$conf["arguIsAddr"]=array();	
324
	#$conf["arguIsAddr"]=array();
325
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
325
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
326
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
326
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
327
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
327
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
328
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
328
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
329
	#$conf["enablePrintDescription"]="true";
329
	#$conf["enablePrintDescription"]="true";
Line 352... Line 352...
352
	$callShell=external::callShell($conf);
352
	$callShell=external::callShell($conf);
353
	unset($conf);
353
	unset($conf);
354
 
354
 
355
	#如果執行出錯
355
	#如果執行出錯
356
	if($callShell["status"]===false){
356
	if($callShell["status"]===false){
357
	
357
 
358
		#結束執行
358
		#結束執行
359
		return false;
359
		return false;
360
	
360
 
361
		}#if end
361
		}#if end
362
 
362
 
363
	#如果沒有回小時
363
	#如果沒有回小時
364
	if(!isset($callShell["output"][0])){
364
	if(!isset($callShell["output"][0])){
365
	
365
 
366
		#結束執行
366
		#結束執行
367
		return false;
367
		return false;
368
	
368
 
369
		}#if end
369
		}#if end
370
 
370
 
371
	#取得輸出
371
	#取得輸出
372
	$hour=$callShell["output"][0];
372
	$hour=$callShell["output"][0];
373
 
373
 
374
	#如果小於開始小時
374
	#如果小於開始小時
375
	if($hour<(int)$s){
375
	if($hour<(int)$s){
376
	
376
 
377
		#休息一小時
377
		#休息一小時
378
		sleep(3600);
378
		sleep(3600);
379
		
379
 
380
		#再跑一次
380
		#再跑一次
381
		continue;
381
		continue;
382
	
382
 
383
		}#if end
383
		}#if end
384
		
384
 
385
	#如果大於結束小時
385
	#如果大於結束小時
386
	if($hour>(int)$e){
386
	if($hour>(int)$e){
387
	
387
 
388
		#休息一小時
388
		#休息一小時
389
		sleep(3600);
389
		sleep(3600);
390
		
390
 
391
		#再跑一次
391
		#再跑一次
392
		continue;
392
		continue;
393
	
393
 
394
		}#if end
394
		}#if end
395
 
395
 
396
	#取得現在時間
396
	#取得現在時間
397
	#涵式說明:
397
	#涵式說明:
398
	#呼叫shell執行系統命令,並取得回傳的內容.
398
	#呼叫shell執行系統命令,並取得回傳的內容.
Line 410... Line 410...
410
	#$result["statusCode"],執行結束後的代碼.
410
	#$result["statusCode"],執行結束後的代碼.
411
	#必填的參數
411
	#必填的參數
412
	#$conf["command"],字串,要執行的指令與.
412
	#$conf["command"],字串,要執行的指令與.
413
	$conf["command"]="date";
413
	$conf["command"]="date";
414
	#$conf["fileArgu"],字串,變數__FILE__的內容.
414
	#$conf["fileArgu"],字串,變數__FILE__的內容.
415
	$conf["fileArgu"]=__FILE__;		
415
	$conf["fileArgu"]=__FILE__;
416
	#可省略參數:
416
	#可省略參數:
417
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
417
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
418
	#$conf["argu"]=array("");
418
	#$conf["argu"]=array("");
419
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
419
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
420
	#$conf["arguIsAddr"]=array();	
420
	#$conf["arguIsAddr"]=array();
421
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
421
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
422
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
422
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
423
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
423
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
424
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
424
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
425
	#$conf["enablePrintDescription"]="true";
425
	#$conf["enablePrintDescription"]="true";
Line 448... Line 448...
448
	$callShell=external::callShell($conf);
448
	$callShell=external::callShell($conf);
449
	unset($conf);
449
	unset($conf);
450
 
450
 
451
	#如果執行出錯
451
	#如果執行出錯
452
	if($callShell["status"]==="false"){
452
	if($callShell["status"]==="false"){
453
	
453
 
454
		#結束執行
454
		#結束執行
455
		return false;
455
		return false;
456
	
456
 
457
		}#if end
457
		}#if end
458
 
458
 
459
	#取得輸出
459
	#取得輸出
460
	$time=$callShell["output"];
460
	$time=$callShell["output"];
461
 
461
 
Line 475... Line 475...
475
	#$result["statusCode"],執行結束後的代碼.
475
	#$result["statusCode"],執行結束後的代碼.
476
	#必填的參數
476
	#必填的參數
477
	#$conf["command"],字串,要執行的指令與.
477
	#$conf["command"],字串,要執行的指令與.
478
	$conf["command"]="uptime";
478
	$conf["command"]="uptime";
479
	#$conf["fileArgu"],字串,變數__FILE__的內容.
479
	#$conf["fileArgu"],字串,變數__FILE__的內容.
480
	$conf["fileArgu"]=__FILE__;		
480
	$conf["fileArgu"]=__FILE__;
481
	#可省略參數:
481
	#可省略參數:
482
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
482
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
483
	#$conf["argu"]=array("");
483
	#$conf["argu"]=array("");
484
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
484
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
485
	#$conf["arguIsAddr"]=array();	
485
	#$conf["arguIsAddr"]=array();
486
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
486
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
487
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
487
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
488
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
488
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
489
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
489
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
490
	#$conf["enablePrintDescription"]="true";
490
	#$conf["enablePrintDescription"]="true";
Line 513... Line 513...
513
	$callShell=external::callShell($conf);
513
	$callShell=external::callShell($conf);
514
	unset($conf);
514
	unset($conf);
515
 
515
 
516
	#如果執行出錯
516
	#如果執行出錯
517
	if($callShell["status"]===false){
517
	if($callShell["status"]===false){
518
	
518
 
519
		#結束執行
519
		#結束執行
520
		return false;
520
		return false;
521
	
521
 
522
		}#if end
522
		}#if end
523
 
523
 
524
	#取得輸出
524
	#取得輸出
525
	$uptime=$callShell["output"];
525
	$uptime=$callShell["output"];
526
 
526
 
527
	#用來分割的關鍵字
527
	#用來分割的關鍵字
528
	$splitWord="load average: ";
528
	$splitWord="load average: ";
529
	
529
 
530
	#函式說明:
530
	#函式說明:
531
	#將固定格式的字串分開,並回傳分開的結果。
531
	#將固定格式的字串分開,並回傳分開的結果。
532
	#回傳結果:
532
	#回傳結果:
533
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
533
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
534
	#$result["error"],錯誤訊息陣列
534
	#$result["error"],錯誤訊息陣列
Line 548... Line 548...
548
	$conf["allowEmptyStr"]="false";
548
	$conf["allowEmptyStr"]="false";
549
	#備註:
549
	#備註:
550
	#無.
550
	#無.
551
	$spiltString=stringProcess::spiltString($conf);
551
	$spiltString=stringProcess::spiltString($conf);
552
	unset($conf);
552
	unset($conf);
553
	
553
 
554
	#如果執行失敗
554
	#如果執行失敗
555
	if($spiltString["status"]==="false")
555
	if($spiltString["status"]==="false")
556
	{
556
	{
557
		#結束執行
557
		#結束執行
558
		return false;
558
		return false;
559
	}
559
	}
560
	
560
 
561
	#如果沒有指令的關鍵字存在
561
	#如果沒有指令的關鍵字存在
562
	if($spiltString["found"]==="false")
562
	if($spiltString["found"]==="false")
563
	{
563
	{
564
		#結束執行
564
		#結束執行
565
		return false;
565
		return false;
Line 589... Line 589...
589
	$conf["allowEmptyStr"]="false";
589
	$conf["allowEmptyStr"]="false";
590
	#備註:
590
	#備註:
591
	#無.
591
	#無.
592
	$spiltString=stringProcess::spiltString($conf);
592
	$spiltString=stringProcess::spiltString($conf);
593
	unset($conf);
593
	unset($conf);
594
	
594
 
595
	#如果執行失敗
595
	#如果執行失敗
596
	if($spiltString["status"]==="false")
596
	if($spiltString["status"]==="false")
597
	{
597
	{
598
		#結束執行
598
		#結束執行
599
		return false;
599
		return false;
600
	}
600
	}
601
	
601
 
602
	#如果沒有指令的關鍵字存在
602
	#如果沒有指令的關鍵字存在
603
	if($spiltString["found"]==="false")
603
	if($spiltString["found"]==="false")
604
	{
604
	{
605
		#結束執行
605
		#結束執行
606
		return false;
606
		return false;
607
	}
607
	}
608
	
608
 
609
	#取得uptime的當下數值
609
	#取得uptime的當下數值
610
	$uptimeVal=$spiltString["dataArray"][0];
610
	$uptimeVal=$spiltString["dataArray"][0];
611
 
611
 
612
	#取得CPU有多少執行序
612
	#取得CPU有多少執行序
613
	#涵式說明:
613
	#涵式說明:
Line 626... Line 626...
626
	#$result["statusCode"],執行結束後的代碼.
626
	#$result["statusCode"],執行結束後的代碼.
627
	#必填的參數
627
	#必填的參數
628
	#$conf["command"],字串,要執行的指令與.
628
	#$conf["command"],字串,要執行的指令與.
629
	$conf["command"]="lscpu";
629
	$conf["command"]="lscpu";
630
	#$conf["fileArgu"],字串,變數__FILE__的內容.
630
	#$conf["fileArgu"],字串,變數__FILE__的內容.
631
	$conf["fileArgu"]=__FILE__;		
631
	$conf["fileArgu"]=__FILE__;
632
	#可省略參數:
632
	#可省略參數:
633
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
633
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
634
	$conf["argu"]=array("|","grep","CPU(s)","|","grep","-v","NUMA");
634
	$conf["argu"]=array("|","grep","CPU(s)","|","grep","-v","NUMA");
635
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
635
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
636
	#$conf["arguIsAddr"]=array();	
636
	#$conf["arguIsAddr"]=array();
637
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
637
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
638
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
638
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
639
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
639
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
640
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
640
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
641
	#$conf["enablePrintDescription"]="true";
641
	#$conf["enablePrintDescription"]="true";
Line 664... Line 664...
664
	$callShell=external::callShell($conf);
664
	$callShell=external::callShell($conf);
665
	unset($conf);
665
	unset($conf);
666
 
666
 
667
	#如果執行出錯
667
	#如果執行出錯
668
	if($callShell["status"]==="false"){
668
	if($callShell["status"]==="false"){
669
	
669
 
670
		#結束執行
670
		#結束執行
671
		return false;
671
		return false;
672
	
672
 
673
		}#if end
673
		}#if end
674
 
674
 
675
	#取得輸出
675
	#取得輸出
676
	$lscpu=$callShell["output"];
676
	$lscpu=$callShell["output"];
677
	
677
 
678
	#用來分割的關鍵字
678
	#用來分割的關鍵字
679
	$splitWord="CPU(s): ";
679
	$splitWord="CPU(s): ";
680
 
680
 
681
	#函式說明:
681
	#函式說明:
682
	#將固定格式的字串分開,並回傳分開的結果。
682
	#將固定格式的字串分開,並回傳分開的結果。
Line 699... Line 699...
699
	$conf["allowEmptyStr"]="false";
699
	$conf["allowEmptyStr"]="false";
700
	#備註:
700
	#備註:
701
	#無.
701
	#無.
702
	$spiltString=stringProcess::spiltString($conf);
702
	$spiltString=stringProcess::spiltString($conf);
703
	unset($conf);
703
	unset($conf);
704
	
704
 
705
	#如果執行失敗
705
	#如果執行失敗
706
	if($spiltString["status"]==="false")
706
	if($spiltString["status"]==="false")
707
	{
707
	{
708
		#結束執行
708
		#結束執行
709
		return false;
709
		return false;
710
	}
710
	}
711
	
711
 
712
	#如果沒有指令的關鍵字存在
712
	#如果沒有指令的關鍵字存在
713
	if($spiltString["found"]==="false")
713
	if($spiltString["found"]==="false")
714
	{
714
	{
715
		#結束執行
715
		#結束執行
716
		return false;
716
		return false;
717
	}
717
	}
718
	
718
 
719
	#取得uptime的當下數值
719
	#取得uptime的當下數值
720
	$lscpuVal=(int)$spiltString["dataArray"][0];
720
	$lscpuVal=(int)$spiltString["dataArray"][0];
721
	
721
 
722
	#如果有程序必須等待cpu給予資源
722
	#如果有程序必須等待cpu給予資源
723
	if($uptimeVal>=$lscpuVal)
723
	if($uptimeVal>=$lscpuVal)
724
	{
724
	{
725
		#設置需要警示
725
		#設置需要警示
726
		$alert=true;
726
		$alert=true;
Line 752... Line 752...
752
	#$result["statusCode"],執行結束後的代碼.
752
	#$result["statusCode"],執行結束後的代碼.
753
	#必填的參數
753
	#必填的參數
754
	#$conf["command"],字串,要執行的指令與.
754
	#$conf["command"],字串,要執行的指令與.
755
	$conf["command"]="ps";
755
	$conf["command"]="ps";
756
	#$conf["fileArgu"],字串,變數__FILE__的內容.
756
	#$conf["fileArgu"],字串,變數__FILE__的內容.
757
	$conf["fileArgu"]=__FILE__;		
757
	$conf["fileArgu"]=__FILE__;
758
	#可省略參數:
758
	#可省略參數:
759
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
759
	#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
760
	$conf["argu"]=array("axuwf","|","cat");
760
	$conf["argu"]=array("axuwf","|","cat");
761
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
761
	#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
762
	#$conf["arguIsAddr"]=array();	
762
	#$conf["arguIsAddr"]=array();
763
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
763
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
764
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
764
	#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
765
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
765
	#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
766
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
766
	#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
767
	#$conf["enablePrintDescription"]="true";
767
	#$conf["enablePrintDescription"]="true";
Line 790... Line 790...
790
	$callShell=external::callShell($conf);
790
	$callShell=external::callShell($conf);
791
	unset($conf);
791
	unset($conf);
792
 
792
 
793
	#如果執行出錯
793
	#如果執行出錯
794
	if($callShell["status"]==="false"){
794
	if($callShell["status"]==="false"){
795
	
795
 
796
		#結束執行
796
		#結束執行
797
		return false;
797
		return false;
798
	
798
 
799
		}#if end
799
		}#if end
800
 
800
 
801
	#取得輸出
801
	#取得輸出
802
	$output=$callShell["output"];
802
	$output=$callShell["output"];
803
	
803
 
804
	#$time,現在時間
804
	#$time,現在時間
805
	#$uptime,load average.
805
	#$uptime,load average.
806
	#$output,完整工作程序樹
806
	#$output,完整工作程序樹
807
	
807
 
808
	#設置郵件參數
808
	#設置郵件參數
809
	$conf["acct"]=$eacct;
809
	$conf["acct"]=$eacct;
810
	$conf["pass"]=$epass;
810
	$conf["pass"]=$epass;
811
	$conf["receiver"]=$receiver;
811
	$conf["receiver"]=$receiver;
812
	
812
 
813
	#設置時間
813
	#設置時間
814
	$date=date("Y-m-d H:i:s");
814
	$date=date("Y-m-d H:i:s");
815
	
815
 
816
	#如果從正常狀態進入需要警示的狀態
816
	#如果從正常狀態進入需要警示的狀態
817
	if($lastAlert===false && $alert===true)
817
	if($lastAlert===false && $alert===true)
818
	{	
818
	{
819
		#警示超過負荷
819
		#警示超過負荷
820
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 超過負荷(".$alertValue.">".$lscpuVal.")了".PHP_EOL;
820
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 超過負荷(".$alertValue.">".$lscpuVal.")了".PHP_EOL;
821
		
821
 
822
		#串接完整的工作樹
822
		#串接完整的工作樹
823
		foreach($output as $line)
823
		foreach($output as $line)
824
		{
824
		{
825
			$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
825
			$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
826
			$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
826
			$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
827
		}
827
		}
828
						
828
 
829
		#寄送通知信件
829
		#寄送通知信件
830
		sendMail($conf);			
830
		sendMail($conf);
831
	
831
 
832
		#更新寄送的分鐘
832
		#更新寄送的分鐘
833
		$lastEmailMinute=gmdate("i");
833
		$lastEmailMinute=gmdate("i");
834
	
834
 
835
	}#if end
835
	}#if end
836
	
836
 
837
	#反之如果負載更嚴重了
837
	#反之如果負載更嚴重了
838
	else if($lastAlert===true && $alert===true && $alertValue>$lastAlertValue)
838
	else if($lastAlert===true && $alert===true && $alertValue>$lastAlertValue)
839
	{
839
	{
840
		#警示超過負荷
840
		#警示超過負荷
841
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 負荷更重了(".$alertValue.">".$lscpuVal.")了".PHP_EOL;
841
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 負荷更重了(".$alertValue.">".$lscpuVal.")了".PHP_EOL;
842
		
842
 
843
		#如果不同分鐘,且超過5分鐘了
843
		#如果不同分鐘,且超過5分鐘了
844
		if($lastEmailMinute!==gmdate("i") && (gmdate("i")-$lastEmailMinute)>5 )
844
		if($lastEmailMinute!==gmdate("i") && (gmdate("i")-$lastEmailMinute)>5 )
845
		{
845
		{
846
			#串接完整的工作樹
846
			#串接完整的工作樹
847
			foreach($output as $line)
847
			foreach($output as $line)
848
			{
848
			{
849
				$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
849
				$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
850
				$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
850
				$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
851
			}
851
			}
852
		
852
 
853
			#加上pre tag
853
			#加上pre tag
854
			$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
854
			$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
855
		
855
 
856
			#寄送通知信件
856
			#寄送通知信件
857
			sendMail($conf);
857
			sendMail($conf);
858
		
858
 
859
			#更新寄送的分鐘
859
			#更新寄送的分鐘
860
			$lastEmailMinute=gmdate("i");
860
			$lastEmailMinute=gmdate("i");
861
		
861
 
862
		}#if end
862
		}#if end
863
	
863
 
864
	}#if end
864
	}#if end
865
	
865
 
866
	#反之如果可以負荷了
866
	#反之如果可以負荷了
867
	else if($lastAlert===true && $alert===false)
867
	else if($lastAlert===true && $alert===false)
868
	{
868
	{
869
		#提示恢復正常了
869
		#提示恢復正常了
870
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 恢復正常了".PHP_EOL;
870
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 恢復正常了".PHP_EOL;
871
		
871
 
872
		#串接完整的工作樹
872
		#串接完整的工作樹
873
		foreach($output as $line)
873
		foreach($output as $line)
874
		{
874
		{
875
			$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
875
			$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
876
			$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
876
			$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
877
		}
877
		}
878
		
878
 
879
		#加上pre tag
879
		#加上pre tag
880
		$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
880
		$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
881
		
881
 
882
		#寄送通知信件
882
		#寄送通知信件
883
		sendMail($conf);
883
		sendMail($conf);
884
	
884
 
885
	}#if end
885
	}#if end
886
	
886
 
887
	#其他不需要警示與提示的狀況,如果有開啟 $verbose
887
	#其他不需要警示與提示的狀況,如果有開啟 $verbose
888
	else if($verbose===true)
888
	else if($verbose===true)
889
	{
889
	{
890
		#verbose訊息
890
		#verbose訊息
891
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 正常(".$alertValue."<".$lscpuVal.")".PHP_EOL;
891
		$conf["subject"]=$conf["plainBody"]=$conf["htmlBody"]=$target." 於 ".$date." 正常(".$alertValue."<".$lscpuVal.")".PHP_EOL;
892
		
892
 
893
		#如果不同分鐘,且超過5分鐘了
893
		#如果不同分鐘,且超過5分鐘了
894
		if($lastEmailMinute!==gmdate("i") && (gmdate("i")-$lastEmailMinute)>5 )
894
		if($lastEmailMinute!==gmdate("i") && (gmdate("i")-$lastEmailMinute)>5 )
895
		{
895
		{
896
			#串接完整的工作樹
896
			#串接完整的工作樹
897
			foreach($output as $line)
897
			foreach($output as $line)
898
			{
898
			{
899
				$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
899
				$conf["plainBody"]=$conf["plainBody"].PHP_EOL.$line;
900
				$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
900
				$conf["htmlBody"]=$conf["htmlBody"]."<br>".htmlentities($line);
901
			}
901
			}
902
		
902
 
903
			#加上pre tag
903
			#加上pre tag
904
			$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
904
			$conf["htmlBody"]="<pre>".$conf["htmlBody"]."<pre/>";
905
		
905
 
906
			#寄送通知信件
906
			#寄送通知信件
907
			sendMail($conf);
907
			sendMail($conf);
908
		
908
 
909
			#更新寄送的分鐘
909
			#更新寄送的分鐘
910
			$lastEmailMinute=gmdate("i");
910
			$lastEmailMinute=gmdate("i");
911
		
911
 
912
		}#if end
912
		}#if end
913
	
913
 
914
	}#else end
914
	}#else end
915
 
915
 
916
	#移除mail參數
916
	#移除mail參數
917
	unset($conf);
917
	unset($conf);
918
 
918
 
Line 1001... Line 1001...
1001
	#如果執行失敗
1001
	#如果執行失敗
1002
	if($curlSmtp["status"]==="false")
1002
	if($curlSmtp["status"]==="false")
1003
	{
1003
	{
1004
		#印出內容
1004
		#印出內容
1005
		var_dump($curlSmtp);
1005
		var_dump($curlSmtp);
1006
		
1006
 
1007
		#結束執行
1007
		#結束執行
1008
		exit;		
1008
		exit;
1009
	
1009
 
1010
	}#if end
1010
	}#if end
1011
	
-
 
1012
}#function sendMail end
-
 
1013
1011
 
-
 
1012
}#function sendMail end
-
 
1013