Subversion Repositories php-qbpwcf

Rev

Rev 368 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
239 liveuser 6
    Copyright (C) 2014~2026 MIN ZHI, CHEN
3 liveuser 7
 
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
namespace qbpwcf;
25
 
26
/*
27
類別說明:
368 liveuser 28
跟網頁、資訊安全性有關的類別.
3 liveuser 29
備註:
30
無.
31
*/
32
class security{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#可省略參數:
45
	#無.
46
	#參考資料:
47
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
48
	#備註:
49
	#無.
50
	*/
51
	public function __call($method,$arguments){
226 liveuser 52
 
3 liveuser 53
		#取得當前執行的函式
54
		$result["function"]=__FUNCTION__;
226 liveuser 55
 
3 liveuser 56
		#設置執行不正常
57
		$result["status"]="false";
226 liveuser 58
 
3 liveuser 59
		#設置執行錯誤
60
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 61
 
3 liveuser 62
		#設置所丟入的參數
63
		$result["error"][]=$arguments;
226 liveuser 64
 
3 liveuser 65
		#回傳結果
66
		return $result;
226 liveuser 67
 
3 liveuser 68
		}#function __call end
226 liveuser 69
 
3 liveuser 70
	/*
71
	#函式說明:
72
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
73
	#回傳結果:
74
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
75
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
76
	#$result["function"],當前執行的函式名稱.
77
	#必填參數:
78
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
79
	#$arguments,陣列,為呼叫方法時所用的參數.
80
	#可省略參數:
81
	#無.
82
	#參考資料:
83
	#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
84
	#備註:
85
	#無.
86
	*/
87
	public static function __callStatic($method,$arguments){
226 liveuser 88
 
3 liveuser 89
		#取得當前執行的函式
90
		$result["function"]=__FUNCTION__;
226 liveuser 91
 
3 liveuser 92
		#設置執行不正常
93
		$result["status"]="false";
226 liveuser 94
 
3 liveuser 95
		#設置執行錯誤
96
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
226 liveuser 97
 
3 liveuser 98
		#設置所丟入的參數
99
		$result["error"][]=$arguments;
226 liveuser 100
 
3 liveuser 101
		#回傳結果
102
		return $result;
226 liveuser 103
 
3 liveuser 104
		}#function __callStatic end
226 liveuser 105
 
3 liveuser 106
	/*
226 liveuser 107
	#函式說明:
3 liveuser 108
	#禁止特定的angent訪問我們的網站,例如google與百度的搜尋引擎。
109
	#回傳結果:
110
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
111
	#$result["error"],錯誤訊息.
112
	#$result["function"],當前執行的函數名稱.
113
	#必填參數:
114
	#$conf["disableAngentName"],字串,要禁止拜訪的用戶端資訊,代表要禁止哪些瀏覽器/搜尋引擎瀏覽,格式爲 /(含有哪些關鍵字,若有多個請用「|」隔開。)/i.
115
	$conf["disableAngentName"]="/(Chrome|Mozilla|Internet)/i";
116
	#可省略參數:
117
	#$conf["transferLocation"],字串,如果是要禁止搜尋引擎,要轉址到那個地方?,若沒設定,則預設爲資安素養網的臉書(https://zh-tw.facebook.com/isafemoe).
118
	#$conf["transferLocation"]="";
119
	#參考資料:
120
	#http://php.net/manual/en/function.preg-match.php
121
	#備註:
122
	#無.
123
	*/
124
	public static function preventSerchEngine(&$conf){
125
 
126
		#初始化要回傳的內容
127
		$result=array();
226 liveuser 128
 
3 liveuser 129
		#取得當前執行的函式
130
		$result["function"]=__FUNCTION__;
226 liveuser 131
 
3 liveuser 132
		#如果 $conf 不為陣列
133
		if(gettype($conf)!="array"){
226 liveuser 134
 
3 liveuser 135
			#設置執行失敗
136
			$result["status"]="false";
226 liveuser 137
 
3 liveuser 138
			#設置執行錯誤訊息
139
			$result["error"][]="\$conf變數須為陣列形態";
140
 
141
			#如果傳入的參數為 null
142
			if($conf==null){
226 liveuser 143
 
3 liveuser 144
				#設置執行錯誤訊息
145
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 146
 
3 liveuser 147
				}#if end
148
 
149
			#回傳結果
150
			return $result;
226 liveuser 151
 
3 liveuser 152
			}#if end
153
 
154
		#debug,檢查 $_SERVER["HTTP_USER_AGENT"] 的內容
155
		#var_dump($_SERVER['HTTP_USER_AGENT']);
226 liveuser 156
 
3 liveuser 157
		#檢查參數
158
		#函式說明:
159
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
160
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
161
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
162
		#$result["function"],當前執行的函式名稱.
163
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
164
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
165
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
166
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
167
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
168
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
169
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
170
		#必填寫的參數:
171
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
172
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
173
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
174
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("disableAngentName");
226 liveuser 175
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 176
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
177
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
178
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
179
		#可以省略的參數:
180
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
181
		#$conf["canBeEmptyString"]="false";
182
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
183
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("transferLocation");
226 liveuser 184
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 185
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
186
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
187
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("https://zh-tw.facebook.com/isafemoe");
188
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
189
		#$conf["arrayCountEqualCheck"][]=array();
190
		#參考資料來源:
191
		#array_keys=>http://php.net/manual/en/function.array-keys.php
192
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
193
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 194
 
3 liveuser 195
		#如果檢查失敗
196
		if($checkArguments["status"]=="false"){
226 liveuser 197
 
3 liveuser 198
			#設置執行失敗
199
			$result["status"]="false";
226 liveuser 200
 
3 liveuser 201
			#設置執行錯誤訊息
202
			$result["error"]=$checkArguments;
203
 
204
			#回傳結果
205
			return $result;
226 liveuser 206
 
207
			}#if end
208
 
3 liveuser 209
		#如果檢查不通過
210
		if($checkArguments["passed"]=="false"){
226 liveuser 211
 
3 liveuser 212
			#設置執行失敗
213
			$result["status"]="false";
226 liveuser 214
 
3 liveuser 215
			#設置執行錯誤訊息
216
			$result["error"]=$checkArguments;
217
 
218
			#回傳結果
219
			return $result;
226 liveuser 220
 
221
			}#if end
222
 
3 liveuser 223
		#如果使用者的瀏覽器出現變數 $conf["disableAngentName"] 裡面的關鍵字
224
		if(preg_match($conf["disableAngentName"],$_SERVER["HTTP_USER_AGENT"])){
225
 
226
			#則轉址特定頁面
227
			#函式說明:
228
			#設定session變數後,立即轉址.
229
			#回傳結果:
230
			#$result["status"],執行是否成功,"true"代表成功,"false"代表不成功.
231
			#$result["function"],當前執行的函數名稱.
232
			#$result["error"],錯誤訊息陣列.
233
			#必填的參數:
234
			#$conf["header::redirectionNow"]["headerLocation"],為要轉址到的地方,若爲 $_SERVER["PHP_SELF"],則爲回到目前頁面,全民資安素養網爲 https://isafe.moe.edu.tw/.
235
			$conf["header::redirectionNow"]["headerLocation"]=$conf["transferLocation"];
236
			#可省略的參數:
237
			#$conf["sessionName"],字串陣列,可以指派session變數的名稱.
238
			#$conf["sessionName"]=array("");
239
			#$conf["sessionValue"]字串陣列,可以指派session變數的內容.
240
			#$conf["sessionValue"]=array("");
241
			#參靠資料來源:
242
			#http://php.net/manual/en/reserved.variables.server.php
243
			$redirectionNow=header::redirectionNow($conf["header::redirectionNow"]);
226 liveuser 244
			unset($conf["header::redirectionNow"]);
245
 
3 liveuser 246
			#如果轉址失敗
247
			if($redirectionNow["status"]=="false"){
226 liveuser 248
 
3 liveuser 249
				#設置執行失敗
250
				$result["status"]="false";
226 liveuser 251
 
3 liveuser 252
				#設置執行錯誤訊息
253
				$result["error"]=$redirectionNow;
254
 
255
				#回傳結果
256
				return $result;
226 liveuser 257
 
3 liveuser 258
				}#if end
226 liveuser 259
 
260
			}#if end
261
 
3 liveuser 262
		#執行到這邊代表是可以拜訪的網頁瀏覽器
263
		$result["status"]="true";
226 liveuser 264
 
3 liveuser 265
		#回傳結果
266
		return $result;
267
 
268
		}#function preventSerchEngine end
269
 
270
	/*
271
	#函式說明:
272
	#禁止做任違反版權的事情,禁止在網頁按下滑鼠右鍵,禁止複製圖片,禁止開新分頁(失敗), 版權所有、Power by訊息.
273
	#回傳的內容:
274
	#保護版權的語法
275
	#必填參數:
276
	#無
277
	#可省略參數:
278
	#$conf["name"],字串,公司、組織、單位的名稱,預設不指定.
279
	#$conf["name"]="";
280
	#$conf["powerBy"],字串,由誰提供,預設爲QBPWCF.
281
	#$conf["powerBy"]="";
282
	#$conf["powerByLink"],字串,power by字串的連結目標,預設爲"https://www.qbpwcf.org".
283
	#$conf["powerByLink"]="";
284
	#$conf["bgColor"],字串,背景顏色,預設爲淡藍色.
285
	#$conf["bgColor"]="";
286
	#參考資料:
287
	#http://www.w3schools.com/jsref/dom_obj_event.asp
288
	#備註:
289
	#無.
290
	*/
291
	public static function copyRight(&$conf){
226 liveuser 292
 
3 liveuser 293
		#初始化要回傳的結果
294
		$result=array();
295
 
296
		#取得當前執行的函數名稱
297
		$result["function"]=__FUNCTION__;
298
 
299
		#取得參數
300
		$result["argu"]=$conf;
301
 
302
		#如果 $conf 不為陣列
303
		if(gettype($conf)!="array"){
304
 
305
			#設置執行失敗
306
			$result["status"]="false";
307
 
308
			#設置執行錯誤訊息
309
			$result["error"][]="\$conf變數須為陣列形態";
310
 
311
			#如果傳入的參數為 null
312
			if(is_null($conf)){
313
 
314
				#設置執行錯誤訊息
315
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
316
 
317
				}#if end
318
 
319
			#回傳結果
320
			return $result;
321
 
322
			}#if end
226 liveuser 323
 
3 liveuser 324
		#初始化 content
226 liveuser 325
		$result["content"]="";
326
 
3 liveuser 327
		#函式說明:
328
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
329
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
330
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
331
		#$result["function"],當前執行的函式名稱.
332
		#$result["argu"],設置給予的參數.
333
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
334
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
335
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
336
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
337
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
338
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
339
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
340
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
341
		#必填寫的參數:
342
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
343
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
344
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
345
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
346
		#可以省略的參數:
347
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
348
		#$conf["mustBeFilledVariableName"]=array();
349
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
350
		#$conf["mustBeFilledVariableType"]=array();
351
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
352
		#$conf["canBeEmptyString"]="false";
353
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
354
		#$conf["canNotBeEmpty"]=array();
355
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
356
		#$conf["canBeEmpty"]=array();
357
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
358
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("powerBy","powerByLink","bgColor");
359
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
360
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("name","powerBy","powerByLink","bgColor");
361
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
362
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string");
363
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
364
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("","QBPWCF","https://www.qbpwcf.org","#DDDDFF");
365
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
366
		#$conf["disallowAllSkipableVarIsEmpty"]="";
367
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
368
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
369
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
370
		#$conf["arrayCountEqualCheck"][]=array();
371
		#參考資料來源:
372
		#array_keys=>http://php.net/manual/en/function.array-keys.php
373
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
374
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 375
 
3 liveuser 376
		#如果檢查失敗
377
		if($checkArguments["status"]=="false"){
378
 
379
			#設置錯誤狀態
380
			$result["status"]="false";
381
 
382
			#設置錯誤提示
383
			$result["error"]=$checkArguments;
384
 
385
			#回傳結果
386
			return $result;
387
 
388
			}#if end
389
 
390
		#如果檢查不通過
391
		if($checkArguments["passed"]=="false"){
392
 
393
			#設置錯誤狀態
394
			$result["status"]="false";
395
 
396
			#設置錯誤提示
397
			$result["error"]=$checkArguments;
398
 
399
			#回傳結果
400
			return $result;
401
 
402
			}#if end
226 liveuser 403
 
3 liveuser 404
		#函式說明:
405
		#將要執行的script語法透過該函式執行(會在程式外層用<script></script>包起來).
406
		#回傳結果:
407
		#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
408
		#$result["error"],錯誤訊息陣列
409
		#$result["function"],當前執行的函數名稱
410
		#$result["content"],要執行的javaScript語法
411
		#必填參數:
412
		#$conf["script"],字串,要執行的javaScript語法.
413
		$conf["javaScript::toScript"]["script"]="
226 liveuser 414
 
415
 
416
 
3 liveuser 417
		var copyRightSpan=document.createElement('span');
418
		var copyRightText=document.createTextNode('".$conf["name"]."');
419
		copyRightSpan.appendChild(copyRightText);
226 liveuser 420
 
207 liveuser 421
		//建立power by span
3 liveuser 422
		var powerBySpan=document.createElement('span');
423
		var powerByA=document.createElement('a');
424
		powerByA.href='".$conf["powerByLink"]."';
425
		powerByA.target='_blank';
426
		var powerByText=document.createTextNode('Powered by '+'".$conf["powerBy"]."');
427
		powerByA.appendChild(powerByText);
428
		powerBySpan.appendChild(powerByA);
226 liveuser 429
 
207 liveuser 430
		//建立 copy right div
431
		var copyRightDiv=document.createElement('div');
3 liveuser 432
		copyRightDiv.appendChild(copyRightSpan);
433
		copyRightDiv.appendChild(powerBySpan);
434
		copyRightDiv.style.backgroundColor='".$conf["bgColor"]."';
435
		copyRightDiv.style.textAlign='center';
226 liveuser 436
 
207 liveuser 437
		//顯現 copy right
3 liveuser 438
		document.body.appendChild(copyRightDiv);
226 liveuser 439
 
3 liveuser 440
		";
441
		#可省略參數:
442
		#$conf["onReady"],字串,是否要在網頁完全載入後再執行,"false"為不等載入完就先執行,預設為"true"要等載入完再執行.
443
		#$conf["onReady"]="true";
444
		#$conf["globalJs"],字串陣列,為要放入<script>標籤的js全域變數.
445
		#$conf["globalJs"]=array();
446
		#$conf["jsFunciton"],字串陣列,為要放入<script>標籤的js函數.
447
		#$conf["jsFunciton"]=array();
448
		#參考資料:
449
		#http://stackoverflow.com/questions/9899372/pure-javascript-equivalent-to-jquerys-ready-how-to-call-a-function-when-the
450
		$toScript=javaScript::toScript($conf["javaScript::toScript"]);
451
		unset($conf["javaScript::toScript"]);
226 liveuser 452
 
3 liveuser 453
		#如果建立 javascript 語法失敗
226 liveuser 454
		if($toScript["status"]==="false"){
455
 
3 liveuser 456
			#設置執行失敗
457
			$result["status"]="false";
226 liveuser 458
 
3 liveuser 459
			#設置執行錯誤訊息
460
			$result["error"]=$toScript;
461
 
462
			#回傳結果
226 liveuser 463
			return $result;
464
 
3 liveuser 465
			}#if end
226 liveuser 466
 
467
		#傳接 content
3 liveuser 468
		$result["content"]=$result["content"].$toScript["content"];
226 liveuser 469
 
3 liveuser 470
		#保護版權的語法
471
		#oncontextmenu,按下滑鼠右鍵
472
		#onContextMenu,按下滑鼠右鍵
473
		#ondragstart,開始拖曳
474
		#onselsect,選取區塊時
475
		#onselectstart,開始選取區塊
476
		#onkeydown='if(event.tKey && event.ctrlKey),按下ctrl+t開分頁時
477
		$result["content"]=$result["content"]."
478
			<html
226 liveuser 479
			oncontextmenu=\"return false\"
3 liveuser 480
			onContextMenu=\"window.event.returnValue=false\"
481
			onselect=\"return false\"
226 liveuser 482
			onselectstart=\"return false\"
483
			ondragstart=\"return false\"
3 liveuser 484
			oncopy=\"return false\"
485
			onbeforeprint=\"return false\"
486
			>\r\n";
226 liveuser 487
 
3 liveuser 488
		#設置執行正常
489
		$result["status"]="true";
226 liveuser 490
 
3 liveuser 491
		#回傳語法
492
		return $result;
226 liveuser 493
 
3 liveuser 494
		}#函式結束
495
 
496
	/*
226 liveuser 497
	#函式說明:
3 liveuser 498
	#放置用空白圖片擋住要呈現的圖片
499
	#回傳結果:
500
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
501
	#$result["error"],錯誤訊息.
502
	#$result["function"],當前執行的函數名稱.
503
	#$result["content"],語法.
504
	#必填參數:
505
	$conf["imgAddress"],字串,要放的圖片位置和名稱.
506
	$conf["imgAddress"]="";
507
	$conf["imgWidth"],字串,爲圖片的寬.
508
	$conf["imgWidth"]="";
509
	$conf["imgHeight"],字串,爲圖片的高.
510
	$conf["imgHeight"]="";
511
	$conf["imgLeft"]=,字串,爲圖片放置的位置距離網頁左邊多少.
512
	$conf["imgLeft"]="";
513
	$conf["imgTop"]=,字串,爲圖片放置的位置距離網頁頂端多少.
514
	$conf["imgTop"]="";
515
	#可省略參數:
516
	#$conf["useBase64"],字串,是否要用base64的方式呈現圖片,預設為"true"代表要用base64的方式呈現,反之可用"false".
517
	#$conf["useBase64"]="true";
518
	#參考資料:
519
	#無.
520
	#備註:
521
	#無.
226 liveuser 522
	*/
3 liveuser 523
	public static function imgProtect(&$conf){
524
 
525
		#初始化要回傳的內容
526
		$result=array();
226 liveuser 527
 
3 liveuser 528
		#取得當前執行的函式
529
		$result["function"]=__FUNCTION__;
226 liveuser 530
 
3 liveuser 531
		#如果 $conf 不為陣列
532
		if(gettype($conf)!="array"){
226 liveuser 533
 
3 liveuser 534
			#設置執行失敗
535
			$result["status"]="false";
226 liveuser 536
 
3 liveuser 537
			#設置執行錯誤訊息
538
			$result["error"][]="\$conf變數須為陣列形態";
539
 
540
			#如果傳入的參數為 null
541
			if($conf==null){
226 liveuser 542
 
3 liveuser 543
				#設置執行錯誤訊息
544
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 545
 
3 liveuser 546
				}#if end
547
 
548
			#回傳結果
549
			return $result;
226 liveuser 550
 
3 liveuser 551
			}#if end
552
 
553
		#初始化程式碼
554
		$result["content"]="";
226 liveuser 555
 
3 liveuser 556
		#檢查參數
557
		#函式說明:
558
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
559
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
560
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
561
		#$result["function"],當前執行的函式名稱.
562
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
563
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
564
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
565
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
566
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
567
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
568
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
569
		#必填寫的參數:
570
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
571
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
572
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
573
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("imgAddress","imgWidth","imgHeight","imgLeft","imgTop");
226 liveuser 574
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 575
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
576
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
577
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
578
		#可以省略的參數:
579
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
580
		#$conf["canBeEmptyString"]="false";
581
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
582
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("useBase64");
226 liveuser 583
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 584
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
585
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
586
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
587
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
588
		#$conf["arrayCountEqualCheck"][]=array();
589
		#參考資料來源:
590
		#array_keys=>http://php.net/manual/en/function.array-keys.php
591
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
592
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 593
 
3 liveuser 594
		#如果檢查失敗
595
		if($checkArguments["status"]=="false"){
226 liveuser 596
 
3 liveuser 597
			#設置執行失敗
598
			$result["status"]="false";
226 liveuser 599
 
3 liveuser 600
			#設置執行錯誤訊息
601
			$result["error"]=$checkArguments;
602
 
603
			#回傳結果
604
			return $result;
226 liveuser 605
 
606
			}#if end
607
 
3 liveuser 608
		#如果檢查不通過
609
		if($checkArguments["passed"]=="false"){
226 liveuser 610
 
3 liveuser 611
			#設置執行失敗
612
			$result["status"]="false";
226 liveuser 613
 
3 liveuser 614
			#設置執行錯誤訊息
615
			$result["error"]=$checkArguments;
616
 
617
			#回傳結果
618
			return $result;
226 liveuser 619
 
3 liveuser 620
			}#if end
621
 
622
		#建立要放置的圖片樣式
226 liveuser 623
		#函式說明:
3 liveuser 624
		#創建 css 樣式
625
		#回傳結果:
626
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
627
		#$result["css"],css設定內容
628
		#$result["function"],當前執行的函數
226 liveuser 629
		#$result["error"],涵式錯誤訊息,若爲""則表示沒有錯誤
3 liveuser 630
		$conf["css"]["createCssStyle"]["cssStyleName"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
631
		$conf["css"]["createCssStyle"]["attributes"]=array("width","height","position","top","left");
632
		$conf["css"]["createCssStyle"]["content"]=array($conf["imgWidth"],$conf["imgHeight"],"absolute",$conf["imgTop"],$conf["imgLeft"]);
633
		$css=css::createCssStyle($conf["css"]["createCssStyle"]);
634
		unset($conf["css"]["createCssStyle"]);#清空變數避免出錯
226 liveuser 635
 
3 liveuser 636
		#如果建立css樣式失敗
637
		if($css["status"]=="false"){
226 liveuser 638
 
3 liveuser 639
			#設置執行失敗
640
			$result["status"]="false";
226 liveuser 641
 
3 liveuser 642
			#設置執行錯誤訊息
643
			$result["error"]=$css;
644
 
645
			#回傳結果
646
			return $result;
226 liveuser 647
 
3 liveuser 648
			}#if end
226 liveuser 649
 
3 liveuser 650
		#串接css語法
651
		$result["content"]=$result["content"].$css["css"];
652
 
653
		#如果要用base64顯示圖片
654
		if($conf["useBase64"]=="true"){
226 liveuser 655
 
3 liveuser 656
			#將圖片用base64加密呈現
657
			#函數說明:
658
			#用data:mimeType;base64,imgVar的形式來提供圖片的連結,亦即圖片儲存在變數裡面,本函式包含顯示圖片的語法.
659
			#回傳結果:
660
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
661
			#$result["error"],錯誤訊息
662
			#$result["content"],圖片的連結資訊
226 liveuser 663
			#$result["function"],當前執行的函數名稱
3 liveuser 664
			#必填參數:
665
			#$conf["img::data"]["imgPosition"],要轉存成2元碼的圖片檔案位置與名稱
666
			$conf["img::data"]["imgPosition"]=$conf["imgAddress"];
667
			#可省略參數:
668
			#$conf["img::data"]["alt"],若沒有圖片要用什麼文字顯示。
669
			$conf["img::data"]["alt"]="not found";
670
			#$conf["img::data"]["class"],圖片要套用的css樣式名稱.
671
			$conf["img::data"]["class"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
672
			#$conf["mimeType"],2元碼的內容是什麼,預設為"image/*".
673
			#$conf["mimeType"]="image/*";
674
			#$conf["compressType"],2元碼壓縮的方式,預設為"base64".
675
			#$conf["compressType"]="base64";
676
			#$conf["delImg"],讀取完圖片檔案後,要移除圖片嗎?"true"代表要移除,"false"代表不要移除,預設為"false".
677
			#$conf["delImg"]="false";
678
			#參考資料:
679
			#將檔案用字串變數儲存起來=>http://php.net/manual/en/function.file-get-contents.php
680
			#壓縮2元碼=>http://php.net/manual/en/function.base64-encode.php
681
			$data=img::data($conf["img::data"]);
682
			unset($conf["img::data"]);
683
 
684
			#將圖片用base64加密呈現失敗
685
			if($data["status"]=="false"){
226 liveuser 686
 
3 liveuser 687
				#設置執行失敗
688
				$result["status"]="false";
226 liveuser 689
 
3 liveuser 690
				#設置執行錯誤訊息
691
				$result["error"]=$data;
692
 
693
				#回傳結果
694
				return $result;
226 liveuser 695
 
3 liveuser 696
				}#if end
226 liveuser 697
 
3 liveuser 698
			#取得用base64放置圖片的語法
699
			$result["content"]=$result["content"].$data["content"];
226 liveuser 700
 
3 liveuser 701
			}#if end
702
 
703
		#反之為一般放置圖片的方式
704
		else{
226 liveuser 705
 
3 liveuser 706
			#放置要放的圖片
707
			#函式說明:
708
			#放置可以套用css樣式的圖片
709
			#回傳結果:
710
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
711
			#$result["error"],錯誤訊息陣列
712
			#$result["function"],當前函數執行的名稱
226 liveuser 713
			#$result["content"],印出圖片的語法。
3 liveuser 714
			$conf["img"]["show"]["position"]=$conf["imgAddress"];
715
			$conf["img"]["show"]["alt"]="not found";
716
			$conf["img"]["show"]["class"]="imgStyle-".$conf["imgLeft"].$conf["imgTop"];
717
			$show=img::show($conf["img"]["show"]);
718
			unset($conf["img"]["show"]);#清空變數避免出錯
719
 
720
			#如果放置圖片的語法建立失敗
721
			if($show["status"]=="false"){
226 liveuser 722
 
3 liveuser 723
				#設置執行失敗
724
				$result["status"]="false";
226 liveuser 725
 
3 liveuser 726
				#設置執行錯誤訊息
727
				$result["error"]=$show;
728
 
729
				#回傳結果
730
				return $result;
226 liveuser 731
 
3 liveuser 732
				}#if end
226 liveuser 733
 
3 liveuser 734
			#串接顯示圖片的語法
735
			$result["content"]=$result["content"].$show["content"];
226 liveuser 736
 
3 liveuser 737
			}#else end
738
 
739
		#建立圖片隔離層樣式
740
		$conf["css"]["createCssStyle"]["cssStyleName"]="imgIsolationLayerStyle".$conf["imgLeft"].$conf["imgTop"];
741
		$conf["css"]["createCssStyle"]["attributes"]=array("width","height","opacity","position","top","left");
742
		$conf["css"]["createCssStyle"]["content"]=array($conf["imgWidth"],$conf["imgHeight"],".0","absolute",$conf["imgTop"],$conf["imgLeft"]);
743
		$css=css::createCssStyle($conf["css"]["createCssStyle"]);
744
		unset($conf["css"]["createCssStyle"]);#清空變數避免出錯
226 liveuser 745
 
3 liveuser 746
		#如果建立css樣式失敗
747
		if($css["status"]=="false"){
226 liveuser 748
 
3 liveuser 749
			#設置執行失敗
750
			$result["status"]="false";
226 liveuser 751
 
3 liveuser 752
			#設置執行錯誤訊息
753
			$result["error"]=$css;
754
 
755
			#回傳結果
756
			return $result;
226 liveuser 757
 
3 liveuser 758
			}#if end
226 liveuser 759
 
3 liveuser 760
		#取得圖片隔離層樣式程式碼
761
		$result["content"]=$result["content"].$css["css"];
762
 
763
		#放置隔離層
764
		#函式說明:
765
		#放置可以套用css樣式的圖片
766
		#回傳結果:
767
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
768
		#$result["error"],錯誤訊息陣列
769
		#$result["function"],當前函數執行的名稱
226 liveuser 770
		#$result["content"],印出圖片的語法。
3 liveuser 771
		#必填參數:
772
		$conf["img"]["show"]["position"]="copyRight.png";#圖片位置
773
		#可省略參數:
774
		#$conf["img"]["show"]["alt"]="not found";#若沒有圖片要用什麼文字顯示。
775
		$conf["img"]["show"]["class"]="imgIsolationLayerStyle".$conf["imgLeft"].$conf["imgTop"];#要套用的css樣式類別名稱。
776
		$show=img::show($conf["img"]["show"]);
777
		unset($conf["img"]["show"]);
226 liveuser 778
 
3 liveuser 779
		#如果放置圖片的語法建立失敗
780
		if($show["status"]=="false"){
226 liveuser 781
 
3 liveuser 782
			#設置執行失敗
783
			$result["status"]="false";
226 liveuser 784
 
3 liveuser 785
			#設置執行錯誤訊息
786
			$result["error"]=$show;
787
 
788
			#回傳結果
789
			return $result;
226 liveuser 790
 
3 liveuser 791
			}#if end
226 liveuser 792
 
3 liveuser 793
		#串接顯示隔離層圖片的語法
794
		$result["content"]=$result["content"].$show["content"];
795
 
796
		#執行到這邊代表執行成功
797
		$result["status"]="true";
226 liveuser 798
 
3 liveuser 799
		#回傳語法
800
		return $result;
801
 
802
		}#function imgProtect end
803
 
804
	/*
805
	#函式說明:
806
	#加密php檔案的內容將結果輸出.
807
	#回傳結果:
808
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
809
	#$result["error"],錯誤訊息陣列.
810
	#$result["function"],當前執行的函式名稱.
811
	#$result["content"],加密好的php內容字串.
812
	#必填參數:
813
	#$conf["phpFile"],字串,要加密的php檔案位置與名稱.
814
	$conf["phpFile"]="";
815
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
816
	$conf["fileArgu"]=__FILE__;
817
	#可省略參數:
818
	#無.
819
	#參考資料:
820
	#無.
821
	#備註:
822
	#僅支援單行只出現<?php、?>、其他內容的PHP檔案格式內容.
823
	*/
824
	public static function encodePHP(&$conf){
226 liveuser 825
 
3 liveuser 826
		#初始化要回傳的內容
827
		$result=array();
226 liveuser 828
 
3 liveuser 829
		#取得當前執行的函式
830
		$result["function"]=__FUNCTION__;
226 liveuser 831
 
3 liveuser 832
		#如果 $conf 不為陣列
833
		if(gettype($conf)!="array"){
226 liveuser 834
 
3 liveuser 835
			#設置執行失敗
836
			$result["status"]="false";
226 liveuser 837
 
3 liveuser 838
			#設置執行錯誤訊息
839
			$result["error"][]="\$conf變數須為陣列形態";
840
 
841
			#如果傳入的參數為 null
842
			if($conf==null){
226 liveuser 843
 
3 liveuser 844
				#設置執行錯誤訊息
845
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
226 liveuser 846
 
3 liveuser 847
				}#if end
848
 
849
			#回傳結果
850
			return $result;
226 liveuser 851
 
3 liveuser 852
			}#if end
853
 
854
		#初始加密好的php程式內容
855
		$result["content"]="";
226 liveuser 856
 
3 liveuser 857
		#檢查參數
858
		#函式說明:
859
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
860
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
861
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
862
		#$result["function"],當前執行的函式名稱.
863
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
864
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
865
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
866
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
867
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
868
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
869
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
870
		#必填寫的參數:
871
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
872
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
873
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
874
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("phpFile","fileArgu");
226 liveuser 875
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object");
3 liveuser 876
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
877
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
878
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
879
		#可以省略的參數:
880
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
881
		#$conf["canBeEmptyString"]="false";
882
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
883
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("useBase64");
226 liveuser 884
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3 liveuser 885
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
886
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
887
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("true");
888
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
889
		#$conf["arrayCountEqualCheck"][]=array();
890
		#參考資料來源:
891
		#array_keys=>http://php.net/manual/en/function.array-keys.php
892
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
893
		unset($conf["variableCheck::checkArguments"]);
226 liveuser 894
 
3 liveuser 895
		#如果檢查失敗
896
		if($checkArguments["status"]=="false"){
226 liveuser 897
 
3 liveuser 898
			#設置執行失敗
899
			$result["status"]="false";
226 liveuser 900
 
3 liveuser 901
			#設置執行錯誤訊息
902
			$result["error"]=$checkArguments;
903
 
904
			#回傳結果
905
			return $result;
226 liveuser 906
 
907
			}#if end
908
 
3 liveuser 909
		#如果檢查不通過
910
		if($checkArguments["passed"]=="false"){
226 liveuser 911
 
3 liveuser 912
			#設置執行失敗
913
			$result["status"]="false";
226 liveuser 914
 
3 liveuser 915
			#設置執行錯誤訊息
916
			$result["error"]=$checkArguments;
917
 
918
			#回傳結果
919
			return $result;
226 liveuser 920
 
3 liveuser 921
			}#if end
226 liveuser 922
 
3 liveuser 923
		#函式說明:
924
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
925
		#回傳的變數說明:
926
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
927
		#$result["error"],錯誤訊息提示.
928
		#$result["warning"],警告訊息.
929
		#$result["function"],當前執行的函數名稱.
930
		#$result["fileContent"],爲檔案的內容陣列.
931
		#$result["lineCount"],爲檔案內容總共的行數.
932
		#$result["fullContent"],為檔案的完整內容.
933
		#$result["base64data"],為檔案的base64內容.
934
		#$result["mimeType"],為檔案的mime type.
935
		#必填參數:
936
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
937
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["phpFile"];
938
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
939
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
940
		#可省略參數:
941
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
942
		$conf["fileAccess::getFileContent"]["web"]="false";
943
		#參考資料:
944
		#file(),取得檔案內容的行數.
945
		#file=>http:#php.net/manual/en/function.file.php
946
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
947
		#filesize=>http://php.net/manual/en/function.filesize.php
948
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
949
		unset($conf["fileAccess::getFileContent"]);
226 liveuser 950
 
3 liveuser 951
		#如果讀取檔案內容失敗
952
		if($getFileContent["status"]==="false"){
226 liveuser 953
 
3 liveuser 954
			#設置執行失敗
955
			$result["status"]="false";
226 liveuser 956
 
3 liveuser 957
			#設置執行錯誤訊息
958
			$result["error"]=$getFileContent;
959
 
960
			#回傳結果
961
			return $result;
226 liveuser 962
 
3 liveuser 963
			}#if end
226 liveuser 964
 
3 liveuser 965
		#加密過後的php內容
966
		$contentWithoutPhpTagArray=array();
226 liveuser 967
 
3 liveuser 968
		#識別是否開始php語法了.
969
		$isPHP=false;
226 liveuser 970
 
3 liveuser 971
		#識別是否讀取到php tag開頭
972
		$phpStart=false;
226 liveuser 973
 
3 liveuser 974
		#識別是否讀取到php tag結尾
975
		$phpEed=true;
226 liveuser 976
 
3 liveuser 977
		#針對每行內容
978
		foreach($getFileContent["fileContent"] as $index=>$line){
226 liveuser 979
 
3 liveuser 980
			#debug
981
			#echo "處理第".($index+1)."行".PHP_EOL;
226 liveuser 982
 
3 liveuser 983
			#函式說明:
984
			#將固定格式的字串分開,並回傳分開的結果。
985
			#回傳結果:
986
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
987
			#$result["error"],錯誤訊息陣列
988
			#$result["function"],當前執行的函數名稱.
989
			#$result["argu"],使用的參數.
990
			#$result["oriStr"],要分割的原始字串內容
991
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
992
			#$result["dataCounts"],爲總共分成幾段
993
			#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
994
			#必填的參數:
995
			#$conf["stringIn"],字串,要處理的字串.
996
			$conf["stringProcess::spiltString"]["stringIn"]=$line;
997
			#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
998
			$conf["stringProcess::spiltString"]["spiltSymbol"]="<?php";
999
			#可省略參數:
1000
			#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
1001
			$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
1002
			$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
1003
			unset($conf["stringProcess::spiltString"]);
1004
 
1005
			#如果執行失敗
1006
			if($spiltString["status"]==="false"){
226 liveuser 1007
 
3 liveuser 1008
				#設置執行失敗
1009
				$result["status"]="false";
226 liveuser 1010
 
3 liveuser 1011
				#設置執行錯誤訊息
1012
				$result["error"]=$spiltString;
1013
 
1014
				#回傳結果
1015
				return $result;
226 liveuser 1016
 
3 liveuser 1017
				}#if end
226 liveuser 1018
 
3 liveuser 1019
			#初始化該行的資訊描述
1020
			$lineInfo=array();
226 liveuser 1021
 
3 liveuser 1022
			#如果沒有關鍵字
1023
			if($spiltString["found"]==="false" && $isPHP===false){
226 liveuser 1024
 
3 liveuser 1025
				#初始化暫存的資訊
1026
				$tempLineInfo=array();
226 liveuser 1027
 
3 liveuser 1028
				#預設該行不是php的內容
1029
				$tempLineInfo["isPHP"]=false;
226 liveuser 1030
 
3 liveuser 1031
				#放置內容
1032
				$tempLineInfo["content"]=$line;
226 liveuser 1033
 
3 liveuser 1034
				#儲存一行資訊描述
1035
				$lineInfo[]=$tempLineInfo;
226 liveuser 1036
 
3 liveuser 1037
				}#if end
1038
 
1039
			#反之有關鍵字且 現在是屬於 php 的範圍
1040
			else if($spiltString["found"]==="false" && $isPHP===true){
226 liveuser 1041
 
3 liveuser 1042
				#確認該段目前沒有 "?".">" 結尾
226 liveuser 1043
 
3 liveuser 1044
				#函式說明:
1045
				#將固定格式的字串分開,並回傳分開的結果。
1046
				#回傳結果:
1047
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1048
				#$result["error"],錯誤訊息陣列
1049
				#$result["function"],當前執行的函數名稱.
1050
				#$result["argu"],使用的參數.
1051
				#$result["oriStr"],要分割的原始字串內容
1052
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
1053
				#$result["dataCounts"],爲總共分成幾段
1054
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
1055
				#必填的參數:
1056
				#$conf["stringIn"],字串,要處理的字串.
1057
				$conf["stringProcess::spiltString"]["stringIn"]=$line;
1058
				#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
1059
				$conf["stringProcess::spiltString"]["spiltSymbol"]="?>";
1060
				#可省略參數:
1061
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
1062
				$conf["stringProcess::spiltString"]["allowEmptyStr"]="false";
1063
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
1064
				unset($conf["stringProcess::spiltString"]);
1065
 
1066
				#如果執行失敗
1067
				if($spiltString["status"]==="false"){
226 liveuser 1068
 
3 liveuser 1069
					#設置執行失敗
1070
					$result["status"]="false";
226 liveuser 1071
 
3 liveuser 1072
					#設置執行錯誤訊息
1073
					$result["error"]=$spiltString;
1074
 
1075
					#回傳結果
1076
					return $result;
226 liveuser 1077
 
3 liveuser 1078
					}#if end
226 liveuser 1079
 
3 liveuser 1080
				#反之有關鍵字且 現在是屬於 php 的範圍
1081
				if($spiltString["found"]==="false" && $isPHP===true){
226 liveuser 1082
 
3 liveuser 1083
					#初始化暫存的資訊
1084
					$tempLineInfo=array();
226 liveuser 1085
 
3 liveuser 1086
					#預設該行不是php的內容
1087
					$tempLineInfo["isPHP"]=true;
226 liveuser 1088
 
3 liveuser 1089
					#放置內容
1090
					$tempLineInfo["content"]=$line;
226 liveuser 1091
 
3 liveuser 1092
					#儲存一行資訊描述
1093
					$lineInfo[]=$tempLineInfo;
226 liveuser 1094
 
3 liveuser 1095
					}#if end
226 liveuser 1096
 
3 liveuser 1097
				#反之有找到關鍵字,且現在屬於 php 的範圍
1098
				else if($spiltString["found"]==="true" && $isPHP===true){
1099
 
1100
					#如果分割成0段
1101
					if($spiltString["dataCounts"]===0){
226 liveuser 1102
 
3 liveuser 1103
						#識別是否開始php語法了.
1104
						$isPHP=false;
226 liveuser 1105
 
3 liveuser 1106
						#識別是否讀取到php tag開頭
1107
						$phpStart=false;
226 liveuser 1108
 
3 liveuser 1109
						#識別是否讀取到php tag結尾
1110
						$phpEed=true;
226 liveuser 1111
 
3 liveuser 1112
						}#if end
226 liveuser 1113
 
3 liveuser 1114
					#如果分割成其他段落
1115
					else{
226 liveuser 1116
 
3 liveuser 1117
						#設置執行錯誤訊息
1118
						$result["error"][]="not supported now";
226 liveuser 1119
 
3 liveuser 1120
						}#else end
226 liveuser 1121
 
3 liveuser 1122
					}#if end
226 liveuser 1123
 
3 liveuser 1124
				}#if end
1125
 
1126
			#反之有關鍵字
1127
			else if($spiltString["found"]==="true"){
226 liveuser 1128
 
3 liveuser 1129
				#識別是否開始php語法了.
1130
				$isPHP=true;
226 liveuser 1131
 
3 liveuser 1132
				#識別是否讀取到php tag開頭
1133
				$phpStart=true;
226 liveuser 1134
 
3 liveuser 1135
				#識別是否讀取到php tag結尾
1136
				$phpEed=false;
226 liveuser 1137
 
3 liveuser 1138
				#如果切成兩段
1139
				if($spiltString["dataCounts"]===2){
226 liveuser 1140
 
3 liveuser 1141
					#儲存非 php 的字串
1142
					$noPHPstr=$spiltString["dataArray"][0];
226 liveuser 1143
 
3 liveuser 1144
					#初始化暫存的資訊
1145
					$tempLineInfo=array();
226 liveuser 1146
 
3 liveuser 1147
					#預設該行不是php的內容
1148
					$tempLineInfo["isPHP"]=false;
226 liveuser 1149
 
3 liveuser 1150
					#放置內容
1151
					$tempLineInfo["content"]=$noPHPstr;
226 liveuser 1152
 
3 liveuser 1153
					#儲存屬於 php 的字串
1154
					$phpStr=$spiltString["dataArray"][1];
226 liveuser 1155
 
3 liveuser 1156
					#初始化暫存的資訊
1157
					$tempLineInfo=array();
226 liveuser 1158
 
3 liveuser 1159
					#預設該行不是php的內容
1160
					$tempLineInfo["isPHP"]=true;
226 liveuser 1161
 
3 liveuser 1162
					#放置內容
1163
					$tempLineInfo["content"]=$noPHPstr;
226 liveuser 1164
 
3 liveuser 1165
					}#if end
226 liveuser 1166
 
3 liveuser 1167
				#反之切成一段
1168
				else if($spiltString["dataCounts"]===1){
226 liveuser 1169
 
3 liveuser 1170
					#設置執行失敗
1171
					$result["status"]="false";
226 liveuser 1172
 
3 liveuser 1173
					#設置執行錯誤訊息
1174
					$result["error"][]="not supported now";
1175
 
1176
					#回傳結果
1177
					return $result;
226 liveuser 1178
 
3 liveuser 1179
					}#else end
226 liveuser 1180
 
3 liveuser 1181
				#反之切成0段
1182
				else if($spiltString["dataCounts"]===0){
226 liveuser 1183
 
3 liveuser 1184
					#do nothing
226 liveuser 1185
 
3 liveuser 1186
					}#else end
226 liveuser 1187
 
3 liveuser 1188
				#反之
1189
				else{
1190
					#設置執行失敗
1191
					$result["status"]="false";
226 liveuser 1192
 
3 liveuser 1193
					#設置執行錯誤訊息
1194
					$result["error"][]="not supported now";
1195
 
1196
					#回傳結果
1197
					return $result;
226 liveuser 1198
 
3 liveuser 1199
					}#else end
226 liveuser 1200
 
3 liveuser 1201
				}#else end
1202
 
1203
			#真對每個字串
1204
			foreach($lineInfo as $linfo){
226 liveuser 1205
 
1206
				#記錄起來
3 liveuser 1207
				$contentWithoutPhpTagArray[]=$linfo;
226 liveuser 1208
 
3 liveuser 1209
				}#foreach end
226 liveuser 1210
 
3 liveuser 1211
			}#foreach end
226 liveuser 1212
 
3 liveuser 1213
		#debug
1214
		#var_dump($contentWithoutPhpTagArray);
226 liveuser 1215
 
3 liveuser 1216
		#儲存每行的檔案內容
1217
		$res=array();
226 liveuser 1218
 
3 liveuser 1219
		#php段落
1220
		$phpSection="";
226 liveuser 1221
 
3 liveuser 1222
		#針對每行程式
1223
		foreach($contentWithoutPhpTagArray as $lineInfo){
226 liveuser 1224
 
3 liveuser 1225
			#如果不是 php
1226
			if($lineInfo["isPHP"]===false){
226 liveuser 1227
 
3 liveuser 1228
				#如果有php段落
1229
				if(!empty($phpSection)){
226 liveuser 1230
 
1231
					#加密php程式
3 liveuser 1232
					$encodedPHP=base64_encode($phpSection);
226 liveuser 1233
 
3 liveuser 1234
					#串接內容
1235
					$res[]="<?php eval(base64_decode(\"".$encodedPHP."\")); ?>";
226 liveuser 1236
 
3 liveuser 1237
					}#if end
226 liveuser 1238
 
3 liveuser 1239
				#清空php段落
1240
				$phpSection="";
226 liveuser 1241
 
3 liveuser 1242
				#串接內容
1243
				$res[]=$lineInfo["content"].PHP_EOL;
226 liveuser 1244
 
3 liveuser 1245
				}#if end
226 liveuser 1246
 
3 liveuser 1247
			#反之是 PHP 內容
1248
			else{
1249
				#有內容才處理
1250
				if(!empty($lineInfo["content"])){
226 liveuser 1251
 
3 liveuser 1252
					#串接php語法
1253
					$phpSection=$phpSection.$lineInfo["content"].PHP_EOL;
226 liveuser 1254
 
3 liveuser 1255
					}#if end
226 liveuser 1256
 
3 liveuser 1257
				}#else end
226 liveuser 1258
 
3 liveuser 1259
			}#foreach end
226 liveuser 1260
 
3 liveuser 1261
		#如果有php段落
1262
		if(!empty($phpSection)){
226 liveuser 1263
 
1264
			#加密php程式
3 liveuser 1265
			$encodedPHP=base64_encode($phpSection);
226 liveuser 1266
 
3 liveuser 1267
			#串接內容
1268
			$res[]="<?php eval(base64_decode(\"".$encodedPHP."\")); ?>";
226 liveuser 1269
 
3 liveuser 1270
			}#if end
226 liveuser 1271
 
3 liveuser 1272
		#var_dump($res);exit;
226 liveuser 1273
 
3 liveuser 1274
		#針對每個要寫入的行內容
1275
		foreach($res as $line){
226 liveuser 1276
 
3 liveuser 1277
			$result["content"]=$result["content"].$line;
226 liveuser 1278
 
3 liveuser 1279
			}#foreach end
226 liveuser 1280
 
3 liveuser 1281
		#設置執行正常
1282
		$result["status"]="true";
226 liveuser 1283
 
3 liveuser 1284
		#回傳結果
1285
		return $result;
226 liveuser 1286
 
3 liveuser 1287
		}#function encodePHP end
368 liveuser 1288
 
1289
	/*
1290
	#函式說明:
1291
	#檢查 apache http(s) log 中疑似攻擊的記錄.
1292
	#回傳結果:
1293
	#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
1294
	#$result["error"],錯誤訊息陣列.
1295
	#$result["function"],字串,當前執行的函式名稱.
1296
	#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
1297
	#必填參數:
1298
	#無.
1299
	#可省略參數:
1300
	#$conf["logPath"],http log的路徑,預設為"/var/log/httpd".
1301
	#$conf["logPath"]="/var/log/httpd";
1302
	#$conf["https"],字串,是否為要查https的log,預設為"false",代表為http.
1303
	#$conf["https"]="false";
1304
	#參考資料:
1305
	#無.
1306
	#備註:
1307
	#目前僅支援 apache 提供的 http(s) 服務.
1308
	#攻擊者的定義包含http回應的code為4開頭或用戶使用 HTTP/1.0 協定或用戶使用 CONNECT method,且時間間隔不超過1秒鐘,次數達到3次.
1309
	*/
1310
	public static function checkHttpAttackLog(&$conf){
1311
 
1312
		#初始化要回傳的結果
1313
		$result=array();
3 liveuser 1314
 
368 liveuser 1315
		#取得當前執行的函數名稱
1316
		$result["function"]=__FUNCTION__;
1317
 
1318
		#取得參數
1319
		$result["argu"]=$conf;
1320
 
1321
		#如果 $conf 不為陣列
1322
		if(gettype($conf)!="array"){
1323
 
1324
			#設置執行失敗
1325
			$result["status"]="false";
1326
 
1327
			#設置執行錯誤訊息
1328
			$result["error"][]="\$conf變數須為陣列形態";
1329
 
1330
			#如果傳入的參數為 null
1331
			if(is_null($conf)){
1332
 
1333
				#設置執行錯誤訊息
1334
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1335
 
1336
				}#if end
1337
 
1338
			#回傳結果
1339
			return $result;
1340
 
1341
			}#if end
1342
 
1343
		#函式說明:
1344
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1345
		#回傳結果:
1346
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1347
		#$result["error"],執行不正常結束的錯訊息陣列.
1348
		#$result["simpleError"],簡單表示的錯誤訊息.
1349
		#$result["function"],當前執行的函式名稱.
1350
		#$result["argu"],設置給予的參數.
1351
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1352
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1353
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1354
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1355
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1356
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1357
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1358
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1359
		#必填參數:
1360
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1361
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1362
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1363
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1364
		#可省略參數:
1365
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1366
		#$conf["mustBeFilledVariableName"]=array();
1367
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
1368
		#$conf["mustBeFilledVariableType"]=array();
1369
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1370
		#$conf["canBeEmptyString"]="false";
1371
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1372
		#$conf["canNotBeEmpty"]=array();
1373
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1374
		#$conf["canBeEmpty"]=array();
1375
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
1376
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("logPath","https");
1377
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1378
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("logPath","https");
1379
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1380
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
1381
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1382
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/var/log/httpd","false");
1383
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1384
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1385
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1386
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1387
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
1388
		#$conf["disallowAllSkipableVarNotExist"]="";
1389
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1390
		#$conf["arrayCountEqualCheck"][]=array();
1391
		#參考資料:
1392
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1393
		#備註:
1394
		#無.
1395
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1396
		unset($conf["variableCheck::checkArguments"]);
1397
 
1398
		#預設為http的log
1399
		$logFile="access_log";
1400
 
1401
		#如果 https 為 "true"
1402
		if($conf["https"]==="true"){
1403
 
1404
			#設置為 https 的 log
1405
			$logFile="ssl_access_log";
1406
 
1407
			}#if end
1408
 
1409
		#取得 http 存取記錄的 log
1410
		#函式說明:
1411
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1412
		#回傳的變數說明:
1413
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1414
		#$result["error"],錯誤訊息提示.
376 liveuser 1415
		#$result["fileNotExist"],字串,"true"代表目標檔案不存在;"false"代表目標檔案存在.
1416
		#$result["fileCreated"],字串,"true"代表目標檔案被本函式建立;"false"代表檔案不是透過本函式建立.
368 liveuser 1417
		#$result["function"],當前執行的函數名稱.
1418
		#$result["fileContent"],爲檔案的內容陣列.
1419
		#$result["lineCount"],爲檔案內容總共的行數.
1420
		#$result["fullContent"],為檔案的完整內容.
1421
		#$result["base64dataOnly"],檔案的base64data.
1422
		#$result["base64data"],為在網頁上給予src參數的數值.
1423
		#$result["mimeType"],為檔案的mime type.
1424
		#必填參數:
1425
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1426
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["logPath"]."/".$logFile;
1427
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1428
		$conf["fileAccess::getFileContent"]["fileArgu"]=__FILE__;
1429
		#可省略參數:
1430
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
1431
		#$conf["web"]="true";
1432
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1433
		#$conf["createIfnotExist"]="false";
1434
		#$conf["autoDeleteSpaceOnEachLineStart"],字串,預設為"false",不做額外處理;反之為"true"
1435
		#$conf["autoDeleteSpaceOnEachLineStart"]="false";
1436
		#參考資料:
1437
		#file(),取得檔案內容的行數.
1438
		#file=>http:#php.net/manual/en/function.file.php
1439
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1440
		#filesize=>http://php.net/manual/en/function.filesize.php
1441
		#參考資料:
1442
		#無.
1443
		#備註:
1444
		#無.
1445
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1446
		unset($conf["fileAccess::getFileContent"]);
1447
 
1448
		#如果執行失敗
1449
		if($getFileContent["status"]==="false"){
1450
 
376 liveuser 1451
			#如果檔案不存在
1452
			if($getFileContent["fileNotExist"]==="true"){
1453
 
1454
				#設置結果
1455
				$result["content"]=array();
1456
 
1457
				#設置執行正常
1458
				$result["status"]="true";
1459
 
1460
				#回傳結果
1461
				return $result;
1462
 
1463
				}#if end
1464
 
368 liveuser 1465
			#設置執行失敗
1466
			$result["status"]="false";
1467
 
1468
			#設置錯誤訊息
1469
			$result["error"]=$getFileContent;
1470
 
1471
			#回傳結果
1472
			return $result;
1473
 
1474
			}#if end
1475
 
1476
		/*
1477
		http log 範例:
1478
		36.149.205.198 - - [22/Jun/2026:15:49:21 +0800] "CONNECT api.ipapi.is:443 HTTP/1.1" 200 -
1479
		36.149.205.198 - - [22/Jun/2026:15:49:24 +0800] "CONNECT ipwho.is:443 HTTP/1.1" 200 -
1480
		36.149.205.198 - - [22/Jun/2026:15:49:18 +0800] "CONNECT push.services.mozilla.com:443 HTTP/1.1" 200 -
1481
		120.48.6.159 - - [22/Jun/2026:15:49:20 +0800] "CONNECT ifconfig.me:443 HTTP/1.1" 200 -
1482
		36.149.205.198 - - [22/Jun/2026:15:49:24 +0800] "CONNECT ipwho.is:443 HTTP/1.1" 200 -
1483
		36.149.205.198 - - [22/Jun/2026:15:49:25 +0800] "CONNECT api.ipapi.is:443 HTTP/1.1" 200 -
1484
		36.149.205.198 - - [22/Jun/2026:15:49:28 +0800] "CONNECT ipwho.is:443 HTTP/1.1" 200 -
1485
		36.149.205.198 - - [22/Jun/2026:15:49:30 +0800] "CONNECT nexus.officeapps.live.com:443 HTTP/1.1" 200 -
1486
		172.238.244.28 - - [22/Jun/2026:15:49:31 +0800] "GET / HTTP/1.0" 400 402
1487
		36.149.205.198 - - [22/Jun/2026:15:49:29 +0800] "CONNECT api.ipapi.is:443 HTTP/1.1" 200 -
1488
		36.149.205.198 - - [22/Jun/2026:15:49:33 +0800] "CONNECT qaz23.com:2869 HTTP/1.1" 403 353
1489
		36.149.205.198 - - [22/Jun/2026:15:49:34 +0800] "CONNECT qaz23.com:2869 HTTP/1.1" 403 353
1490
		*/
1491
 
1492
		#初始化給予 search::getMatchFormatsStrings 使用的 formats 參數
1493
		$formatsParamsOfsearchGetMatchFormatsStrings=array();		
1494
		$formatsParamsOfsearchGetMatchFormatsStrings[]="\${ip} \${doNotNeed} [\${day}/\${month}/\${year}:\${hour}:\${min}:\${sec} \${timezone}] \${method} \${path} \${protocol} \${responseCode} \${bytesSend}";
1495
 
1496
		#尋找 http code 為 4xx 的內容行
1497
		#函式說明:
1498
		#尋找多個字串中是否含有符合多個格式之一的內容,且回傳解析好的變數數值.
1499
		#回傳結果:
1500
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1501
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1502
		#$result["function"],當前執行的函式名稱.
1503
		#$result["argu"],所使用的參數.
1504
		#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1505
		#$result["content"],陣列,第一維為對應formats參數的索引,第二維的key為lineNo者為inputs參數的索引;第二維的key為content者為符合的資訊,若為n個${*},則當found為"true"時,就會回傳n個元素;第二維的key為parsedVar者為符合的資訊,其數值以變數名稱作為索引,元素的索引為0~N,代表有幾個符合的同名變數.
1506
		#必填參數:
1507
		#$conf["inputs"],字串陣列,要檢查的字串集合.
1508
		$conf["search::getMatchFormatsStrings"]["inputs"]=$getFileContent["fileContent"];
1509
		#$conf["format"],格式字串陣列,要尋找的可能格式字串集合.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1510
		$conf["search::getMatchFormatsStrings"]["formats"]=$formatsParamsOfsearchGetMatchFormatsStrings;
1511
		#可省略參數:
1512
		#無.
1513
		#參考資料:
1514
		#無.
1515
		#備註:
1516
		#無.
1517
		$getMatchFormatsStrings=search::getMatchFormatsStrings($conf["search::getMatchFormatsStrings"]);
1518
		unset($conf["search::getMatchFormatsStrings"]);
1519
 
1520
		#如果執行異常
1521
		if($getMatchFormatsStrings["status"]==="false"){
1522
 
1523
			#設置執行失敗
1524
			$result["status"]="false";
1525
 
1526
			#設置錯誤訊息
1527
			$result["error"]=$getMatchFormatsStrings;
1528
 
1529
			#回傳結果
1530
			return $result;
1531
 
1532
			}#if end
1533
 
1534
		#如果沒有符合的項目
1535
		if($getMatchFormatsStrings["found"]==="false"){
1536
 
1537
			#設置結果
1538
			$result["content"]=array();
1539
 
1540
			#設置執行正常
1541
			$result["status"]="true";
1542
 
1543
			#回傳結果
1544
			return $result;
1545
 
1546
			}#if end
1547
 
1548
		#初始化要處理的ip資訊
1549
		$ips=array();
1550
 
1551
		#初始化用 ip 為索引來儲存資料行
1552
		$ips_byIp=array();
1553
 
1554
		#針對每個符合的規則
1555
		foreach($getMatchFormatsStrings["content"] as $matchInfo){
1556
 
1557
			#取得符合條件的行索引
1558
			$index=$matchInfo["lineNo"];
1559
 
1560
			#取得用戶要求的method
1561
			$method=$matchInfo["parsedVar"][0]["method"][0];
1562
 
1563
			#取得用戶要求的protocal
1564
			$protocol=$matchInfo["parsedVar"][0]["protocol"][0];
1565
 
1566
			#取得回應的code
1567
			$responseCode=$matchInfo["parsedVar"][0]["responseCode"][0];
1568
 
1569
			#如果 method 為 "CONNECT"
1570
			if($method==="CONNECT"){
1571
 
1572
				#這裡不做事情,但後面繼續執行
1573
 
1574
				}#if end
1575
 
1576
			#如果 protocol 為 "HTTP/1.0"
1577
			else if($protocol==="HTTP/1.0"){
1578
 
1579
				#這裡不做事情,但後面繼續執行
1580
 
1581
				}#if end
1582
 
1583
			#如果回應的 code 不為 4 開頭
1584
			else if($responseCode[0]!=="4"){
1585
 
1586
				#略過,看下一行
1587
				continue;
1588
 
1589
				}#if end
1590
 
1591
			#取得用戶要求的路徑
1592
			$path=$matchInfo["parsedVar"][0]["path"][0];
1593
 
1594
			#剔除要求的資源名稱結尾為 ".css" ".js" "favicon.ico" ".jpg" ".png" 者. - start
1595
 
1596
			#函式說明:
1597
			#尋找字串中是否含有符合多個格式之一的內容,且回傳解析好的變數數值.
1598
			#回傳結果:
1599
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1600
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
1601
			#$result["function"],當前執行的函式名稱.
1602
			#$result["argu"],所使用的參數.
1603
			#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1604
			#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1605
			#必填參數:
1606
			#$conf["input"],字串,要檢查的字串.
1607
			$conf["search::findSpecifyStrFormats"]["input"]=$getFileContent["fileContent"][$index];
1608
			#$conf["format"],格式字串陣列,要尋找的可能格式字串集合.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1609
			$conf["search::findSpecifyStrFormats"]["formats"]=array("\${str}.css","\${str}.js","\${str}.favicon.ico","\${str}.jpg","\${str}.jpeg","\${str}.png","\${str}.webp");
1610
			#可省略參數:
1611
			#無.
1612
			#參考資料:
1613
			#無.
1614
			#備註:
1615
			#無.
1616
			$findSpecifyStrFormats=search::findSpecifyStrFormats($conf["search::findSpecifyStrFormats"]);
1617
			unset($conf["search::findSpecifyStrFormats"]);
1618
 
1619
			#如果執行異常
1620
			if($findSpecifyStrFormats["status"]==="false"){
1621
 
1622
				#設置執行失敗
1623
				$result["status"]="false";
1624
 
1625
				#設置錯誤訊息
1626
				$result["error"]=$findSpecifyStrFormats;
1627
 
1628
				#回傳結果
1629
				return $result;
1630
 
1631
				}#if end
1632
 
1633
			#如果有符合的項目
1634
			if($findSpecifyStrFormats["found"]==="true"){
1635
 
1636
				#略過,看下一行
1637
				continue;
1638
 
1639
				}#if end
1640
 
1641
			#剔除要求的資源名稱結尾為 ".css" ".js" "favicon.ico" ".jpg" ".jpeg" ".png" ".webp" 者. - end
1642
 
1643
			#時間格式的參考
1644
			# [\${day}/\${month}/\${year}:\${hour}:\${min}:\${sec} \${timezone}]
1645
 
1646
			#取得 log 的時間點
1647
			$time=$matchInfo["parsedVar"][0]["day"][0]."/".$matchInfo["parsedVar"][0]["month"][0]."/".$matchInfo["parsedVar"][0]["year"][0].":".$matchInfo["parsedVar"][0]["hour"][0].":".$matchInfo["parsedVar"][0]["min"][0].":".$matchInfo["parsedVar"][0]["sec"][0]." ".$matchInfo["parsedVar"][0]["timezone"][0];
1648
 
1649
			#以 ip 為索引來儲存資料行
1650
			$ips_byIp[$matchInfo["parsedVar"][0]["ip"][0]][]=array("log"=>$getFileContent["fileContent"][$index],"time"=>$time,"ip"=>$matchInfo["parsedVar"][0]["ip"][0]);
1651
 
1652
			}#foreach end
1653
 
1654
		#針對每個可能有問題的IP
1655
		foreach($ips_byIp as $ip => $infos){
1656
 
1657
			#計數 ip 於同時間前來的計數
1658
			$ipSameTimeCount=0;
1659
 
1660
			#用來存放來存取的同一時間
1661
			$ipSameTime="";
1662
 
1663
			#看來拜訪的時間點
1664
			foreach($infos as $info){
1665
 
1666
				#如果是初次
1667
				if($ipSameTime===""){
1668
 
1669
					#記錄時間點
1670
					$ipSameTime=$info["time"];
1671
 
1672
					#同時間點計數加1
1673
					$ipSameTimeCount++;
1674
 
1675
					}#if end
1676
 
1677
				#反之如果時間點相同
1678
				else if($ipSameTime===$info["time"]){
1679
 
1680
					#同時間點計數加1
1681
					$ipSameTimeCount++;
1682
 
1683
					}#if end
1684
 
1685
				#反之時間點不相同
1686
				else{
1687
 
1688
					#記錄時間點
1689
					$ipSameTime=$info["time"];
1690
 
1691
					#同時間點計數重設為1
1692
					$ipSameTimeCount=1;
1693
 
1694
					}#else end
1695
 
1696
				#如果同時間的計數達到3
1697
				if($ipSameTimeCount===3){
1698
 
1699
					#初始化暫存的陣列
1700
					$tmp=array();
1701
 
1702
					#儲存資訊
1703
					$tmp["info"]=$infos;
1704
 
1705
					#儲存ip
1706
					$tmp["ip"]=$info["ip"];
1707
 
1708
					#取得有問題的IP
1709
					$ips[]=$tmp;
1710
 
1711
					#換檢查下一個IP
1712
					continue 2;
1713
 
1714
					}#if end
1715
 
1716
				}#foreach end
1717
 
1718
			}#foreach end
1719
 
1720
		#設置結果
1721
		$result["content"]=$ips;
1722
 
1723
		#設置執行正常
1724
		$result["status"]="true";
1725
 
1726
		#回傳結果
1727
		return $result;
1728
 
1729
		}#funcion checkHttpAttackLog end
1730
 
1731
	/*
1732
	#函式說明:
1733
	#檢查 postfixv log 中疑似攻擊的記錄.
1734
	#回傳結果:
1735
	#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
1736
	#$result["error"],錯誤訊息陣列.
1737
	#$result["function"],字串,當前執行的函式名稱.
1738
	#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
1739
	#必填參數:
1740
	#無.
1741
	#可省略參數:
1742
	#無
1743
	#參考資料:
1744
	#無.
1745
	#備註:
1746
	#無.
1747
	*/
1748
	public static function checkPostfixAttackLog(){
1749
 
1750
		#初始化要回傳的結果
1751
		$result=array();
1752
 
1753
		#取得當前執行的函數名稱
1754
		$result["function"]=__FUNCTION__;
1755
 
1756
		#透過 journalctl -a -e -f --unit=postfix.service | grep "authentication failed" 來取得認證失敗的 ip
1757
		#函式說明:
1758
		#呼叫shell執行系統命令,並取得回傳的內容.
1759
		#回傳的結果:
1760
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1761
		#$result["error"],錯誤訊息陣列.
1762
		#$result["function"],當前執行的函式名稱.
1763
		#$result["argu"],使用的參數.
1764
		#$result["cmd"],執行的指令內容.
1765
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
1766
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
1767
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
1768
		#$result["running"],是否還在執行.
1769
		#$result["pid"],pid.
1770
		#$result["statusCode"],執行結束後的代碼.
1771
		#必填參數:
1772
		#$conf["command"],字串,要執行的指令與.
1773
		$conf["external::callShell"]["command"]="journalctl";
1774
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1775
		$conf["external::callShell"]["fileArgu"]=__FILE__;
1776
		#可省略參數:
1777
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1778
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=postfix.service","|","grep","authentication failed","|","cat");
1779
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1780
		#$conf["arguIsAddr"]=array();
1781
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1782
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1783
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1784
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1785
		#$conf["enablePrintDescription"]="true";
1786
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
1787
		#$conf["printDescription"]="";
1788
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
1789
		$conf["external::callShell"]["escapeshellarg"]="true";
1790
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
1791
		#$conf["username"]="";
1792
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1793
		#$conf["password"]="";
1794
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
1795
		#$conf["useScript"]="";
1796
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
1797
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1798
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
1799
		#$conf["inBackGround"]="";
1800
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
1801
		#$conf["getErr"]="false";
1802
		#備註:
1803
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1804
		#參考資料:
1805
		#exec=>http://php.net/manual/en/function.exec.php
1806
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1807
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1808
		$callShell=external::callShell($conf["external::callShell"]);
1809
		unset($conf["external::callShell"]);
1810
 
1811
		if($callShell["status"]==="false"){
1812
 
1813
			#如果有 statusCode
1814
			if(isset($callShell["statusCode"])){
1815
 
1816
				#如果shell回傳不為0也不為1
1817
				if($callShell["statusCode"]!==0 && $callShell["statusCode"]!==1){
1818
 
1819
					#設置執行失敗
1820
					$result["status"]="false";
1821
 
1822
					#設置錯誤訊息
1823
					$result["error"]=$callShell;
1824
 
1825
					#回傳結果
1826
					return $result;
1827
 
1828
					}#if end
1829
 
1830
				}#if end
1831
 
1832
			#設置執行失敗
1833
			$result["status"]="false";
1834
 
1835
			#設置錯誤訊息
1836
			$result["error"]=$callShell;
1837
 
1838
			#回傳結果
1839
			return $result;
1840
 
1841
			}#if end
1842
 
1843
		#儲存有問題的smtp IP
1844
		$ips_smtp=array();
1845
 
1846
		#狀態碼不為1才執行
1847
		if($callShell["statusCode"]!==1){
1848
 
1849
			#初始化記錄每行log的時間點
1850
			$occurTime=array();
1851
 
1852
			#初始化儲存log行資訊的變數
1853
			$oriLog=array();
1854
 
1855
			#根據每筆記錄
1856
			foreach($callShell["output"] as $index => $line){
1857
 
1858
				#截取出的格式
1859
				#Sep 28 07:54:16 qbpwcf.org postfix/smtpd[2766456]: warning: unknown[158.94.208.72]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=1q2w
1860
				#Sep 28 07:57:15 qbpwcf.org postfix/smtpd[2768441]: warning: unknown[213.209.157.249]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=sybase
1861
				#Sep 28 08:01:09 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[213.209.157.165]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=spam
1862
				#Sep 28 08:01:51 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[103.109.20.174]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=print@qbpwcf.org
1863
				#Sep 28 08:03:14 qbpwcf.org postfix/smtpd[2771112]: warning: unknown[62.60.130.148]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=admin2
1864
				#Sep 28 08:16:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[103.109.20.174]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=user@qbpwcf.org
1865
				#Sep 28 08:16:44 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
1866
				#Sep 28 08:16:53 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
1867
				#Sep 28 08:17:06 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=hualing@qbpwcf.org
1868
				#Sep 28 08:17:16 qbpwcf.org postfix/smtpd[2781279]: warning: unknown[178.16.53.142]: SASL LOGIN authentication failed: Connection lost to authentication server, sasl_username=hualing@qbpwcf.org
1869
				#Sep 28 08:20:28 qbpwcf.org postfix/smtpd[2784204]: warning: unknown[158.94.208.72]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=1q2w1q2w
1870
				#Sep 28 08:23:09 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[213.209.157.249]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=informix
1871
				#Sep 28 08:23:39 qbpwcf.org postfix/smtpd[2785986]: warning: unknown[62.60.130.148]: SASL LOGIN authentication failed: (reason unavailable), sasl_username=admin3
1872
				#May 22 12:58:54 qbpwcf.org postfix/smtpd[2059124]: warning: unknown[80.94.95.242]: SASL LOGIN authentication failed: Invalid authentication mechanism: 'LOGIN', sasl_username=(unavailable)
1873
				#May 22 12:58:59 qbpwcf.org postfix/smtpd[2059124]: warning: unknown[80.94.95.242]: SASL PLAIN authentication failed: (reason unavailable), sasl_username=nonexistent_user_26@qbpwcf.org
1874
				#May 22 12:59:07 qbpwcf.org postfix/smtpd[2059124]: warning: unknown[80.94.95.242]: SASL PLAIN authentication failed: (reason unavailable), sasl_username=finance@qbpwcf.org#"${doNotNeed} postfix/smtpd[${pid}]${doNotNeed}[${ip}]"
1875
 
1876
				#用 " " 分割 以取得 月日時分秒
1877
				#函式說明:
1878
				#將固定格式的字串分開,並回傳分開的結果.
1879
				#回傳結果:
1880
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1881
				#$result["error"],錯誤訊息陣列
1882
				#$result["function"],當前執行的函數名稱.
1883
				#$result["argu"],使用的參數.
1884
				#$result["oriStr"],要分割的原始字串內容
1885
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
1886
				#$result["dataCounts"],爲總共分成幾段
1887
				#$result["found"],是否有在$conf["stringIn"]找到$conf["spiltSymbol"],"true"代表有找到,"false"代表沒有找到.
1888
				#必填參數:
1889
				#$conf["stringIn"],字串,要處理的字串.
1890
				$conf["stringProcess::spiltString"]["stringIn"]=$line;
1891
				#$conf["spiltSymbol"],字串,爲以哪個符號作爲分割.
1892
				$conf["stringProcess::spiltString"]["spiltSymbol"]=" ";
1893
				#可省略參數:
1894
				#$conf["allowEmptyStr"],是否允許分割出來空字串,預設為"false"不允許;"true"代表允許.
1895
				#$conf["allowEmptyStr"]="false";
1896
				#參考資料:
1897
				#無.
1898
				#備註:
1899
				#無.
1900
				$spiltString=stringProcess::spiltString($conf["stringProcess::spiltString"]);
1901
				unset($conf["stringProcess::spiltString"]);
1902
 
1903
				#如果分割失敗
1904
				if($spiltString["status"]==="false"){
1905
 
1906
					#設置執行失敗
1907
					$result["status"]="false";
1908
 
1909
					#設置錯誤訊息
1910
					$result["error"]=$spiltString;
1911
 
1912
					#回傳結果
1913
					return $result;
1914
 
1915
					}#if end
1916
 
1917
				#如果分割失敗
1918
				if($spiltString["dataCounts"]<3){
1919
 
1920
					#設置執行失敗
1921
					$result["status"]="false";
1922
 
1923
					#設置錯誤訊息
1924
					$result["error"]=$spiltString;
1925
 
1926
					#回傳結果
1927
					return $result;
1928
 
1929
					}#if end
1930
 
1931
				#儲存時間
1932
				$occurTime[$index]=strtotime($spiltString["dataArray"][0]." ".$spiltString["dataArray"][1]." ".$spiltString["dataArray"][2]);
1933
 
1934
				#取得 ip
1935
				#函式說明:
1936
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
1937
				#回傳結果:
1938
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1939
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
1940
				#$result["function"],當前執行的函式名稱.
1941
				#$result["argu"],所使用的參數.
1942
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
1943
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
1944
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
1945
				#必填參數:
1946
				#$conf["input"],字串,要檢查的字串.
1947
				$conf["search::findSpecifyStrFormat"]["input"]=$line;
1948
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
1949
				$conf["search::findSpecifyStrFormat"]["format"]="\${doNotNeed} postfix/smtpd[\${pid}]\${doNotNeed}[\${ip}]:[\${reason}]";
1950
				#可省略參數:
1951
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
1952
				#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
1953
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
1954
				#$conf["varCon"]=array("no_tail"=>" not");
1955
				#參考資料:
1956
				#無.
1957
				#備註:
1958
				#無.
1959
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
1960
				unset($conf["search::findSpecifyStrFormat"]);
1961
 
1962
				#如果分割失敗
1963
				if($findSpecifyStrFormat["status"]==="false"){
1964
 
1965
					#設置執行失敗
1966
					$result["status"]="false";
1967
 
1968
					#設置錯誤訊息
1969
					$result["error"]=$findSpecifyStrFormat;
1970
 
1971
					#回傳結果
1972
					return $result;
1973
 
1974
					}#if end
1975
 
1976
				#如果沒有符合格式
1977
				if($findSpecifyStrFormat["found"]==="false"){
1978
 
1979
					#剔除時間點 記錄
1980
					array_pop($occurTime);
1981
 
1982
					#跳過該行
1983
					continue;
1984
 
1985
					}#if end
1986
 
1987
				#取得解析好的ip
1988
				$ip=$findSpecifyStrFormat["parsedVar"]["ip"];
1989
 
1990
				#儲存原始的log行內容
1991
				$oriLog[$index]=$spiltMutiString["spiltString"][$index ]["oriStr"];
1992
 
1993
				#初始化暫存的陣列
1994
				$tmp=array();
1995
 
1996
				#設置log、time
1997
				$tmp["info"][]=array("log"=>$oriLog[$index],"time"=>$occurTime[$index]);
1998
 
1999
				#設置問題ip
2000
				$tmp["ip"]=$ip;
2001
 
2002
				#取得所需的有問題的IP
2003
				$ips_smtp[]=$tmp;
2004
 
2005
				}#foreach end
2006
 
2007
			}#if end
2008
 
2009
		#設置結果
2010
		$result["content"]=$ips_smtp;
2011
 
2012
		#設置執行正常
2013
		$result["status"]="true";
2014
 
2015
		#回傳結果
2016
		return $result;
2017
 
2018
		}#function checkPostfixAttackLog end
2019
 
2020
	/*
2021
	#函式說明:
2022
	#檢查 named log 中疑似攻擊的記錄.
2023
	#回傳結果:
2024
	#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
2025
	#$result["error"],錯誤訊息陣列.
2026
	#$result["function"],字串,當前執行的函式名稱.
2027
	#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
2028
	#必填參數:
2029
	#無.
2030
	#可省略參數:
2031
	#無
2032
	#參考資料:
2033
	#無.
2034
	#備註:
2035
	#無.
2036
	*/
2037
	public static function checkNamedAttackLog(){
2038
 
2039
		#初始化要回傳的結果
2040
		$result=array();
2041
 
2042
		#取得當前執行的函數名稱
2043
		$result["function"]=__FUNCTION__;
2044
 
2045
		#透過 journalctl -a -e -f --unit=named.service | grep ' query ' 來取得 IP
2046
		#函式說明:
2047
		#呼叫shell執行系統命令,並取得回傳的內容.
2048
		#回傳的結果:
2049
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2050
		#$result["error"],錯誤訊息陣列.
2051
		#$result["function"],當前執行的函式名稱.
2052
		#$result["argu"],使用的參數.
2053
		#$result["cmd"],執行的指令內容.
2054
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
2055
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
2056
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
2057
		#$result["running"],是否還在執行.
2058
		#$result["pid"],pid.
2059
		#$result["statusCode"],執行結束後的代碼.
2060
		#必填參數:
2061
		#$conf["command"],字串,要執行的指令與.
2062
		$conf["external::callShell"]["command"]="journalctl";
2063
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2064
		$conf["external::callShell"]["fileArgu"]=__FILE__;
2065
		#可省略參數:
2066
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2067
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=named.service","|","grep"," query ","|","cat");
2068
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
2069
		#$conf["arguIsAddr"]=array();
2070
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
2071
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
2072
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
2073
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2074
		#$conf["enablePrintDescription"]="true";
2075
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
2076
		#$conf["printDescription"]="";
2077
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2078
		$conf["external::callShell"]["escapeshellarg"]="true";
2079
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
2080
		#$conf["username"]="";
2081
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2082
		#$conf["password"]="";
2083
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
2084
		#$conf["useScript"]="";
2085
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
2086
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
2087
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
2088
		#$conf["inBackGround"]="";
2089
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
2090
		#$conf["getErr"]="false";
2091
		#備註:
2092
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
2093
		#參考資料:
2094
		#exec=>http://php.net/manual/en/function.exec.php
2095
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2096
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2097
		$callShell=external::callShell($conf["external::callShell"]);
2098
		unset($conf["external::callShell"]);
2099
 
2100
		#如果執行失敗
2101
		if($callShell["status"]==="false"){
2102
 
2103
			#如果有 statusCode
2104
			if(isset($callShell["statusCode"])){
2105
 
2106
				#如果shell回傳不為0也不為1
2107
				if($callShell["statusCode"]!==0 && $callShell["statusCode"]!==1){
2108
 
2109
					#設置執行失敗
2110
					$result["status"]="false";
2111
 
2112
					#設置錯誤訊息
2113
					$result["error"]=$callShell;
2114
 
2115
					#回傳結果
2116
					return $result;
2117
 
2118
					}#if end
2119
 
2120
				}#if end
2121
 
2122
			#設置執行失敗
2123
			$result["status"]="false";
2124
 
2125
			#設置錯誤訊息
2126
			$result["error"]=$callShell;
2127
 
2128
			#回傳結果
2129
			return $result;
2130
 
2131
			}#if end
2132
 
2133
		#記錄攻擊者的IP
2134
		$attacker_ips_namd=array();
2135
 
2136
		#狀態碼不為1才執行
2137
		if($callShell["statusCode"]!==1){
2138
 
2139
			#截取出的格式
2140
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2141
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2142
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2143
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2144
			#Nov 24 20:55:15 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#6238 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2145
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2146
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2147
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2148
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2149
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 34.80.86.198#31220 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2150
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2151
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f77180297c0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2152
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f770c077bf0 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2153
			#Nov 24 20:55:17 localhost.localdomain named[99512]: client @0x7f7714041d10 191.7.219.100#8794 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2154
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2155
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f770c077bf0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2156
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2157
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2158
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2159
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f77180297c0 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2160
			#Nov 24 20:55:18 localhost.localdomain named[99512]: client @0x7f7714041d10 5.29.224.190#10027 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2161
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2162
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2163
			#Nov 24 20:55:22 localhost.localdomain named[99512]: client @0x7f7714041d10 123.253.64.16#54404 (PEACECORPS.GOV): query (cache) 'PEACECORPS.GOV/ANY/IN' denied
2164
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#40052 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
2165
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#48628 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
2166
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#52460 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
2167
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#60457 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
2168
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#10213 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
2169
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc801bc80 61.220.11.198#44377 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
2170
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#4481 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
2171
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#53061 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
2172
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc8003700 61.220.11.198#31654 (dns.qbpwcf.org): query 'dns.qbpwcf.org/AAAA/IN' denied
2173
			#Dec 14 18:51:45 localhost.localdomain named[1159]: client @0x7f3dc802a410 61.220.11.198#57701 (aesopower-cms-sock-latest.qbpwcf.org): query 'aesopower-cms-sock-latest.qbpwcf.org/A/IN' denied
2174
			#Sep 29 03:37:20 dns.qbpwcf.org named[94]: client @0x7f60e00734e8 61.166.210.84#49954 (twitter.com): query failed (REFUSED) for twitter.com/IN/AAAA at ../../../lib/ns/query.c:5691
2175
			#Sep 29 03:37:20 dns.qbpwcf.org named[94]: client @0x7f60e006f428 61.166.210.84#49954 (twitter.com): query failed (REFUSED) for twitter.com/IN/A at ../../../lib/ns/query.c:5691
2176
			#Sep 29 03:37:21 dns.qbpwcf.org named[94]: client @0x7f60e80889a8 61.166.210.84#50057 (astrill4u.com): query failed (REFUSED) for astrill4u.com/IN/AAAA at ../../../lib/ns/query.c:5691
2177
			#Sep 29 03:37:21 dns.qbpwcf.org named[94]: client @0x7f60e805ed08 61.166.210.84#50057 (astrill4u.com): query failed (REFUSED) for astrill4u.com/IN/A at ../../../lib/ns/query.c:5691
2178
			#Sep 29 03:46:33 dns.qbpwcf.org named[94]: client @0x7f60d402b618 165.22.223.147#16200 (tool.lu): query failed (REFUSED) for tool.lu/IN/A at ../../../lib/ns/query.c:5691
2179
			#Sep 29 03:49:16 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
2180
			#Sep 29 04:19:10 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
2181
			#Sep 29 04:20:28 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
2182
			#Sep 29 04:24:20 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
2183
			#Sep 29 04:24:59 dns.qbpwcf.org named[94]: client @0x7f60e0060a28 76.20.229.207#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
2184
			#Sep 29 04:40:48 dns.qbpwcf.org named[94]: client @0x7f60f9377888 174.96.56.126#80 (sl): query failed (REFUSED) for sl/IN/ANY at ../../../lib/ns/query.c:5691
2185
			#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} client ${doNotNeed} ${ip}#${remoteRevPort} (${$queryTarget}): ${doNotNeed}
2186
 
2187
			#函式說明:
2188
			#檢查多個字串中的每個字串是否有多個關鍵字
2189
			#回傳結果:
2190
			#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
2191
			#$result["function"],當前執行的函數名稱.
2192
			#$result["error"],錯誤訊息.
2193
			#$result["argu"],使用的參數.
2194
			#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
2195
			#$result["foundedKeyWords"],找到的關鍵字陣列.
2196
			#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
2197
			#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
2198
			#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
2199
			#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
2200
			#必填參數:
2201
			#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
2202
			$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array("(REFUSED)"," denied");
2203
			#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
2204
			$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
2205
			#可省略參數:
2206
			#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
2207
			#$conf["completeEqual"]="true";
2208
			#參考資料:
2209
			#無.
2210
			#備註:
2211
			#無.
2212
			$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
2213
			unset($conf["search::findManyKeyWordsFromManyString"]);
2214
 
2215
			#如果執行失敗
2216
			if($findManyKeyWordsFromManyString["status"]==="false"){
2217
 
2218
				#設置執行失敗
2219
				$result["status"]="false";
2220
 
2221
				#設置錯誤訊息
2222
				$result["error"]=$findManyKeyWordsFromManyString;
2223
 
2224
				#回傳結果
2225
				return $result;
2226
 
2227
				}#if end
2228
 
2229
			#初始化儲存原始log行內容
2230
			#$oriLog=array();
2231
 
2232
			#儲存疑似有問題的IP
2233
			$ips_named=array();
2234
 
2235
			#初始化儲存確定有問題的ip
2236
			$attacker_ips_namd=array();
2237
 
2238
			#針對每個符合的行
2239
			foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $oriLog){
2240
 
2241
				#初始化儲存資訊的暫存陣列
2242
				$info=array();
2243
 
2244
				#解析時間與來源ip
2245
				#函式說明:
2246
				#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2247
				#回傳結果:
2248
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2249
				#$reuslt["error"],執行不正常結束的錯訊息陣列.
2250
				#$result["function"],當前執行的函式名稱.
2251
				#$result["argu"],所使用的參數.
2252
				#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2253
				#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2254
				#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2255
				#必填參數:
2256
				#$conf["input"],字串,要檢查的字串.
2257
				$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
2258
				#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2259
				$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} client \${doNotNeed} \${ip}#\${remoteRevPort} (\${queryTarget}): \${doNotNeed}";
2260
				#可省略參數:
2261
				#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2262
				#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
2263
				#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2264
				#$conf["varCon"]=array("no_tail"=>" not");
2265
				#參考資料:
2266
				#無.
2267
				#備註:
2268
				#無.
2269
				$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2270
				unset($conf["search::findSpecifyStrFormat"]);
2271
 
2272
				#如果分割失敗
2273
				if($findSpecifyStrFormat["status"]==="false"){
2274
 
2275
					#設置執行失敗
2276
					$result["status"]="false";
2277
 
2278
					#設置錯誤訊息
2279
					$result["error"]=$findSpecifyStrFormat;
2280
 
2281
					#回傳結果
2282
					return $result;
2283
 
2284
					}#if end
2285
 
2286
				#如果沒有符合格式
2287
				if($findSpecifyStrFormat["found"]==="false"){
2288
 
2289
					#跳過該行
2290
					continue;
2291
 
2292
					}#if end
2293
 
2294
				#儲存時間點
2295
				$info["time"]=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
2296
 
2297
				#儲存ip
2298
				$info["ip"]=$findSpecifyStrFormat["parsedVar"]["ip"][0];
2299
 
2300
				#儲存log
2301
				$info["log"]=$oriLog;
2302
 
2303
				#儲存查詢的目標
2304
				$info["queryTarget"]=$findSpecifyStrFormat["parsedVar"]["queryTarget"][0];
2305
 
2306
				#儲存疑似有問題的ip
2307
				$ips_named[$info["ip"]][]=$info;
2308
 
2309
				}#foreach end
2310
 
2311
			#針對每個可能有問題ip的每個log行
2312
			foreach($ips_named as $ip => $infos){
2313
 
2314
				#初始化記錄ip來訪不大於1分鐘的計數
2315
				$count=0;
2316
 
2317
				#初始化記錄歷史log跟time
2318
				$history=array();
2319
 
2320
				#針對每個log行資訊
2321
				foreach($infos as $index => $info){
2322
 
2323
					#unixtime
2324
					$time=strtotime($info["time"]);
2325
 
2326
					#如果沒有下筆記錄
2327
					if(!isset($infos[$index+1])){
2328
 
2329
						#結束 foreach
2330
						break;
2331
 
2332
						}#if end
2333
 
2334
					#取得unixtime
2335
					$next_time=strtotime($infos[$index+1]["time"]);
2336
 
2337
					#如果時間間隔大於60秒
2338
					if($next_time-$time>60){
2339
 
2340
						#跳過,看下筆記錄
2341
						continue;
2342
 
2343
						}#if end
2344
 
2345
					#計數+1
2346
					$count++;
2347
 
2348
					#記錄歷史資訊
2349
					$history[]=array("time"=>$time,"log"=>$info["log"]);
2350
 
2351
					}#foreach end
2352
 
2353
				#如果有達到3次
2354
				if($count>=3){
2355
 
2356
					#初始化暫存的陣列
2357
					$tmp=array();
2358
 
2359
					#設置ip
2360
					$tmp["ip"]=$ip;
2361
 
2362
					#設置info
2363
					$tmp["info"]=$history;
2364
 
2365
					#記錄攻擊者的IP
2366
					$attacker_ips_namd[]=$tmp;
2367
 
2368
					}#if end
2369
 
2370
				}#foreach end
2371
 
2372
			}#if end
2373
 
2374
		#設置結果
2375
		$result["content"]=$attacker_ips_namd;
2376
 
2377
		#設置執行正常
2378
		$result["status"]="true";
2379
 
2380
		#回傳結果
2381
		return $result;
2382
 
2383
		}#function checkNamedAttackLog end
2384
 
2385
	/*
2386
	#函式說明:
2387
	#檢查 dovecot log 中疑似攻擊的記錄.
2388
	#回傳結果:
2389
	#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
2390
	#$result["error"],錯誤訊息陣列.
2391
	#$result["function"],字串,當前執行的函式名稱.
2392
	#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
2393
	#必填參數:
2394
	#無.
2395
	#可省略參數:
2396
	#無
2397
	#參考資料:
2398
	#無.
2399
	#備註:
2400
	#無.
2401
	*/
2402
	public static function checkDovecotAttackLog(){
2403
 
2404
		#初始化要回傳的結果
2405
		$result=array();
2406
 
2407
		#取得當前執行的函數名稱
2408
		$result["function"]=__FUNCTION__;
2409
 
2410
		#透過 journalctl -a -e --unit=dovecot.service 來取得 IP
2411
		#函式說明:
2412
		#呼叫shell執行系統命令,並取得回傳的內容.
2413
		#回傳的結果:
2414
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2415
		#$result["error"],錯誤訊息陣列.
2416
		#$result["function"],當前執行的函式名稱.
2417
		#$result["argu"],使用的參數.
2418
		#$result["cmd"],執行的指令內容.
2419
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
2420
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
2421
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
2422
		#$result["running"],是否還在執行.
2423
		#$result["pid"],pid.
2424
		#$result["statusCode"],執行結束後的代碼.
2425
		#必填參數:
2426
		#$conf["command"],字串,要執行的指令與.
2427
		$conf["external::callShell"]["command"]="journalctl";
2428
		#$conf["fileArgu"],字串,變數__FILE__的內容.
2429
		$conf["external::callShell"]["fileArgu"]=__FILE__;
2430
		#可省略參數:
2431
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
2432
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=dovecot.service");
2433
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
2434
		#$conf["arguIsAddr"]=array();
2435
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
2436
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
2437
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
2438
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
2439
		#$conf["enablePrintDescription"]="true";
2440
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
2441
		#$conf["printDescription"]="";
2442
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
2443
		$conf["external::callShell"]["escapeshellarg"]="true";
2444
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
2445
		#$conf["username"]="";
2446
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
2447
		#$conf["password"]="";
2448
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
2449
		#$conf["useScript"]="";
2450
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
2451
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
2452
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
2453
		#$conf["inBackGround"]="";
2454
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
2455
		#$conf["getErr"]="false";
2456
		#備註:
2457
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
2458
		#參考資料:
2459
		#exec=>http://php.net/manual/en/function.exec.php
2460
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
2461
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
2462
		$callShell=external::callShell($conf["external::callShell"]);
2463
		unset($conf["external::callShell"]);
2464
 
2465
		#如果執行失敗
2466
		if($callShell["status"]==="false"){
2467
 
2468
			#如果有 statusCode
2469
			if(isset($callShell["statusCode"])){
2470
 
2471
				#如果shell回傳不為0也不為1
2472
				if($callShell["statusCode"]!==0 && $callShell["statusCode"]!==1){
2473
 
2474
					#設置執行失敗
2475
					$result["status"]="false";
2476
 
2477
					#設置錯誤訊息
2478
					$result["error"]=$callShell;
2479
 
2480
					#回傳結果
2481
					return $result;
2482
 
2483
					}#if end
2484
 
2485
				}#if end
2486
 
2487
			#設置執行失敗
2488
			$result["status"]="false";
2489
 
2490
			#設置錯誤訊息
2491
			$result["error"]=$callShell;
2492
 
2493
			#回傳結果
2494
			return $result;
2495
 
2496
			}#if end
2497
 
2498
		#記錄攻擊者的IP
2499
		$attacker_ips_imap=array();
2500
 
2501
		/* $callShell["output"] 範例截取結果
2502
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MxQuPu+73xpliNc9>
2503
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hH8xPu+7dBtliNc9>
2504
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nmI0Pu+7zhtliNc9>
2505
		Feb 23 00:24:58 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1GU2Pu+7NBhliNc9>
2506
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0Io5Pu+7sRhliNc9>
2507
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zbQ+Pu+7rhlliNc9>
2508
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0P5APu+7/BlliNc9>
2509
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gKRDPu+7XhpliNc9>
2510
		Feb 23 00:24:59 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4hNHPu+77hpliNc9>
2511
		Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<belIPu+7bBtliNc9>
2512
		Feb 23 00:25:00 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VhRLPu+7xBtliNc9>
2513
		Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<loiMiu+7cxhliNc9>
2514
		Feb 23 00:46:19 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RNCQiu+7/xhliNc9>
2515
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NWCTiu+7PBlliNc9>
2516
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<2tiViu+7hBlliNc9>
2517
		Feb 23 00:46:20 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<w6Sbiu+7/xlliNc9>
2518
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkWkiu+7gBtliNc9>
2519
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<bGCmiu+7qBtliNc9>
2520
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0E+oiu+76RtliNc9>
2521
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<FBGriu+7UhhliNc9>
2522
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<AeSsiu+7iBhliNc9>
2523
		Feb 23 00:46:21 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<gpSuiu+70hhliNc9>
2524
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zYfITPC7RBlliNc9>
2525
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<GULMTPC7zhlliNc9>
2526
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3jjOTPC7CBpliNc9>
2527
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vhHQTPC7UBpliNc9>
2528
		Feb 23 01:40:38 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vArTTPC7rxpliNc9>
2529
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hDTXTPC7GhtliNc9>
2530
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<c6vZTPC7SRtliNc9>
2531
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rQzcTPC7jBtliNc9>
2532
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LSffTPC78htliNc9>
2533
		Feb 23 01:40:39 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<XLThTPC7KBhliNc9>
2534
		Feb 23 01:40:40 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tZfjTPC7dxhliNc9>
2535
		Feb 23 03:27:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<i3bIyfG7AxtliNc9>
2536
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sLVyfG7uxtliNc9>
2537
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<BJXZyfG7BhhliNc9>
2538
		Feb 23 03:27:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<xK3cyfG7SxhliNc9>
2539
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<q43gyfG7aRhliNc9>
2540
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Oj3syfG7FBlliNc9>
2541
		Feb 23 03:27:12 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SF7uyfG7RhlliNc9>
2542
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IM/wyfG7ZRlliNc9>
2543
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<pXv1yfG7vBlliNc9>
2544
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8ub4yfG7/xlliNc9>
2545
		Feb 23 03:27:13 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H0j7yfG7NRpliNc9>
2546
		Feb 23 06:10:07 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Zw6FEPS7WxhliNc9>
2547
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<vmKTEPS7cRpliNc9>
2548
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SkOXEPS7BxtliNc9>
2549
		Feb 23 06:10:08 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<H42bEPS7WRtliNc9>
2550
		Feb 23 06:10:09 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<jFqoEPS7SRhliNc9>
2551
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TNy4EPS7DhpliNc9>
2552
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JYW7EPS7mBpliNc9>
2553
		Feb 23 06:10:10 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</Ve+EPS76hpliNc9>
2554
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<StLGEPS7qhtliNc9>
2555
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<7RnLEPS7DBhliNc9>
2556
		Feb 23 06:10:11 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6xTOEPS7eBhliNc9>
2557
		Feb 23 06:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<YHy0VfS7uBhliNc9>
2558
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<WLW4VfS7fxlliNc9>
2559
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lM66VfS73BlliNc9>
2560
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Q4K9VfS7NxpliNc9>
2561
		Feb 23 06:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JiLBVfS7rRpliNc9>
2562
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DETIVfS7qxtliNc9>
2563
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<UlLLVfS7GhhliNc9>
2564
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<safNVfS7txhliNc9>
2565
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M/DQVfS7LxlliNc9>
2566
		Feb 23 06:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+zPTVfS7eRlliNc9>
2567
		Feb 23 06:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dxXWVfS72hlliNc9>
2568
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<S0pci/S7SxhliNc9>
2569
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<zThji/S78RhliNc9>
2570
		Feb 23 06:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8PJoi/S7ixlliNc9>
2571
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Qkhui/S7PBpliNc9>
2572
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<SXVzi/S7hhtliNc9>
2573
		Feb 23 06:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=</X55i/S7uhhliNc9>
2574
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MHJ9i/S74hlliNc9>
2575
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<RBWBi/S7pRpliNc9>
2576
		Feb 23 06:44:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NJeGi/S7yhtliNc9>
2577
		Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QsaMi/S7rxhliNc9>
2578
		Feb 23 06:44:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8fiPi/S7uBlliNc9>
2579
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<dt04yPS7KBlliNc9>
2580
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<ZMI9yPS7WxpliNc9>
2581
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<nTVAyPS7ARtliNc9>
2582
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wj1CyPS7lxtliNc9>
2583
		Feb 23 07:01:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<u7RFyPS7YRhliNc9>
2584
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<tpBLyPS7ZhlliNc9>
2585
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<CRdOyPS7wxlliNc9>
2586
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<v9NQyPS7JxpliNc9>
2587
		Feb 23 07:01:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<81lUyPS73hpliNc9>
2588
		Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<PCZXyPS7TRtliNc9>
2589
		Feb 23 07:01:31 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<VnNZyPS7qxtliNc9>
2590
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<op+l9vS7ZxhliNc9>
2591
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aBCr9vS7CBlliNc9>
2592
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<0sOt9vS7dRlliNc9>
2593
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<NFaw9vS7xhlliNc9>
2594
		Feb 23 07:14:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<QS609vS7SRpliNc9>
2595
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<4FW79vS76htliNc9>
2596
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Fxu+9vS7gBhliNc9>
2597
		Feb 23 07:14:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3djA9vS75RhliNc9>
2598
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<hgzE9vS7mxlliNc9>
2599
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<J8TG9vS7GBpliNc9>
2600
		Feb 23 07:14:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<t87I9vS7mBpliNc9>
2601
		Feb 23 07:29:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<1xBILPW7MRtliNc9>
2602
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<IXZNLPW79htliNc9>
2603
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<6OdPLPW7chhliNc9>
2604
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<M5BSLPW78hhliNc9>
2605
		Feb 23 07:29:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Nv9VLPW7UxlliNc9>
2606
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<foJbLPW7KRpliNc9>
2607
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<EoVeLPW7nxpliNc9>
2608
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<DwNhLPW7JRtliNc9>
2609
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<mKhkLPW7ohtliNc9>
2610
		Feb 23 07:29:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<3nhnLPW7/htliNc9>
2611
		Feb 23 07:29:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<e+lpLPW7XRhliNc9>
2612
		Feb 23 07:44:27 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KtTtYfW7dBhliNc9>
2613
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<MLTxYfW77BhliNc9>
2614
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9GL0YfW7KBlliNc9>
2615
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<JNT2YfW7fRlliNc9>
2616
		Feb 23 07:44:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8Zv5YfW72RlliNc9>
2617
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<lbv/YfW73BpliNc9>
2618
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<5zsCYvW7EBtliNc9>
2619
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<aE8EYvW7bRtliNc9>
2620
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<LEIHYvW75RtliNc9>
2621
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<rLsJYvW7MRhliNc9>
2622
		Feb 23 07:44:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<9oMMYvW7ihhliNc9>
2623
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<x7SUl/W7mBpliNc9>
2624
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<k1KZl/W73xtliNc9>
2625
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Veabl/W7PxhliNc9>
2626
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Yamel/W7sxhliNc9>
2627
		Feb 23 07:59:28 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<wpGil/W7OBlliNc9>
2628
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<+VCol/W7aBpliNc9>
2629
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<TMaql/W7zhpliNc9>
2630
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<KnKtl/W7GBtliNc9>
2631
		Feb 23 07:59:29 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<Lkixl/W7ixtliNc9>
2632
		Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 1 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<8bWzl/W7ARhliNc9>
2633
		Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<70q2l/W7PBhliNc9>
2634
		Sep 29 06:53:42 qbpwcf.org dovecot[98]: imap-login: Disconnected: Connection closed (no auth attempts in 0 secs): user=<>, rip=3.231.151.171, lip=169.254.2.1, TLS, session=<MaKQGOs/wIMD55er>
2635
		Sep 29 07:42:58 qbpwcf.org auth[3737748]: pam_unix(dovecot:auth): check pass; user unknown
2636
		Sep 29 07:42:58 qbpwcf.org auth[3737748]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=account@qbpwcf.org rhost=62.60.131.29
2637
		Sep 29 08:10:02 qbpwcf.org dovecot[98]: imap(liveuser)<3755807><SvyIKew/xLpyIuFn>: Disconnected: Connection closed (UID SEARCH finished 0.039 secs ago) in=119 out=1504 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
2638
		Sep 29 08:12:02 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=149.102.158.38, lip=169.254.2.1, mpid=3757116, TLS, session=<B2O9MOw/TrmVZp4m>
2639
		Sep 29 08:12:04 qbpwcf.org dovecot[98]: imap(liveuser)<3757116><B2O9MOw/TrmVZp4m>: Disconnected: Logged out in=240 out=21891 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
2640
		Sep 29 08:12:06 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=149.102.158.38, lip=169.254.2.1, mpid=3757144, TLS, session=<S0rwMOw/XLmVZp4m>
2641
		Sep 29 08:12:09 qbpwcf.org dovecot[98]: imap(liveuser)<3757144><S0rwMOw/XLmVZp4m>: Disconnected: Logged out in=885 out=25454 deleted=0 expunged=0 trashed=0 hdr_count=2 hdr_bytes=21658 body_count=0 body_bytes=0
2642
		Sep 29 08:28:48 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768144, TLS, session=<Gk6ybOw/nNpyIuFn>
2643
		Sep 29 08:28:51 qbpwcf.org dovecot[98]: imap(liveuser)<3768144><Gk6ybOw/nNpyIuFn>: Disconnected: Connection closed (LIST finished 1.939 secs ago) in=50 out=17609 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
2644
		Sep 29 08:28:51 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768149, TLS, session=<ct7bbOw/qtpyIuFn>
2645
		Sep 29 08:28:52 qbpwcf.org dovecot[98]: imap(liveuser)<3768149><ct7bbOw/qtpyIuFn>: Disconnected: Connection closed (UID FETCH finished 0.045 secs ago) in=196 out=2381 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
2646
		Sep 29 08:28:53 qbpwcf.org dovecot[98]: imap-login: Login: user=<liveuser>, method=PLAIN, rip=114.34.225.103, lip=169.254.2.1, mpid=3768155, TLS, session=<DvP1bOw/tNpyIuFn>
2647
		Sep 29 08:28:55 qbpwcf.org dovecot[98]: imap(liveuser)<3768155><DvP1bOw/tNpyIuFn>: Disconnected: Connection closed (UID SEARCH finished 0.180 secs ago) in=119 out=1504 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
2648
		Sep 29 08:39:24 qbpwcf.org auth[3775219]: pam_unix(dovecot:auth): check pass; user unknown
2649
		Sep 29 08:39:24 qbpwcf.org auth[3775219]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=test rhost=196.251.92.78
2650
		Sep 29 08:40:44 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): check pass; user unknown
2651
		Sep 29 08:40:44 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=1q2w3e4r5t4567 rhost=158.94.208.72
2652
		Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): check pass; user unknown
2653
		Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=spam rhost=62.60.130.148
2654
		*/
2655
 
2656
		#認證失敗的關鍵字
2657
		$keyWordAF="authentication failure";
2658
 
2659
		#未認證或SSL錯誤
2660
		$keyWordNAA="no auth attempts";
2661
 
2662
		#搜尋符合關鍵字的log行
2663
		#函式說明:
2664
		#檢查多個字串中的每個字串是否有多個關鍵字
2665
		#回傳結果:
2666
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
2667
		#$result["function"],當前執行的函數名稱.
2668
		#$result["error"],錯誤訊息.
2669
		#$result["argu"],使用的參數.
2670
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
2671
		#$result["foundedKeyWords"],找到的關鍵字陣列.
2672
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
2673
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
2674
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
2675
		#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
2676
		#必填參數:
2677
		#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
2678
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordAF,$keyWordNAA);
2679
		#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
2680
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
2681
		#可省略參數:
2682
		#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
2683
		#$conf["completeEqual"]="true";
2684
		#參考資料:
2685
		#無.
2686
		#備註:
2687
		#無.
2688
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
2689
		unset($conf["search::findManyKeyWordsFromManyString"]);
2690
 
2691
		#如果執行失敗
2692
		if($findManyKeyWordsFromManyString["status"]==="false"){
2693
 
2694
			#設置執行失敗
2695
			$result["status"]="false";
2696
 
2697
			#設置錯誤訊息
2698
			$result["error"]=$findManyKeyWordsFromManyString;
2699
 
2700
			#回傳結果
2701
			return $result;
2702
 
2703
			}#if end
2704
 
2705
		#初始化儲存可能有問題的存取Dovecot服務遠端ip
2706
		$rickyIpsOfDocecot=array();
2707
 
2708
		#針對每個符合的log行
2709
		foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $index => $oriLog){
2710
 
2711
			#找到的關鍵字
2712
			$foundKeyWord=$findManyKeyWordsFromManyString["foundedTrueKeyWords"][$index][0];
2713
 
2714
			#依照符合的關鍵字
2715
			switch($foundKeyWord){
2716
 
2717
				#如果是認證失敗
2718
				case $keyWordAF:
2719
 
2720
					#範例
2721
					#Sep 29 08:41:18 qbpwcf.org auth[3776113]: pam_unix(dovecot:auth): authentication failure; logname=liveuser uid=0 euid=0 tty=dovecot ruser=spam rhost=62.60.130.148
2722
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} : authentication failure; logname=${account} ${doNotNeed} rhost=${ip}
2723
 
2724
					#取得時間點跟遠端IP
2725
					#函式說明:
2726
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2727
					#回傳結果:
2728
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2729
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2730
					#$result["function"],當前執行的函式名稱.
2731
					#$result["argu"],所使用的參數.
2732
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2733
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2734
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2735
					#必填參數:
2736
					#$conf["input"],字串,要檢查的字串.
2737
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
2738
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2739
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} : authentication failure; logname=\${account} \${doNotNeed} rhost=\${ip}";
2740
					#可省略參數:
2741
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2742
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
2743
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2744
					#$conf["varCon"]=array("no_tail"=>" not");
2745
					#參考資料:
2746
					#無.
2747
					#備註:
2748
					#無.
2749
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2750
					unset($conf["search::findSpecifyStrFormat"]);
2751
 
2752
					#如果分割失敗
2753
					if($findSpecifyStrFormat["status"]==="false"){
2754
 
2755
						#設置執行失敗
2756
						$result["status"]="false";
2757
 
2758
						#設置錯誤訊息
2759
						$result["error"]=$findSpecifyStrFormat;
2760
 
2761
						#回傳結果
2762
						return $result;
2763
 
2764
						}#if end
2765
 
2766
					#如果沒有符合格式
2767
					if($findSpecifyStrFormat["found"]==="false"){
2768
 
2769
						#跳過該行
2770
						continue 2;
2771
 
2772
						}#if end
2773
 
2774
					#取得時間點
2775
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
2776
 
2777
					#取得ip
2778
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
2779
 
2780
					#儲存其資訊
2781
					$rickyIpsOfDocecot[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
2782
 
2783
					#跳出  switch
2784
					break;
2785
 
2786
				#如果是未認證或SSL錯誤
2787
				case $keyWordNAA:
2788
 
2789
					#範例
2790
					#Feb 23 07:59:30 localhost.localdomain dovecot[1427]: imap-login: Disconnected (no auth attempts in 0 secs): user=<>, rip=101.136.215.61, lip=169.254.1.1, TLS handshaking: SSL_accept() failed: error:14094416:SSL routines:ssl3_read_bytes:sslv3 alert certificate unknown: SSL alert number 46, session=<70q2l/W7PBhliNc9>
2791
					#Sep 29 06:53:42 qbpwcf.org dovecot[98]: imap-login: Disconnected: Connection closed (no auth attempts in 0 secs): user=<>, rip=3.231.151.171, lip=169.254.2.1, TLS, session=<MaKQGOs/wIMD55er>
2792
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} ( no auth attempts in ${doNotNeed} user=<${account}>, rip=${ip}, ${doNotNeed}
2793
 
2794
					#取得時間點跟遠端IP
2795
					#函式說明:
2796
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
2797
					#回傳結果:
2798
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2799
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
2800
					#$result["function"],當前執行的函式名稱.
2801
					#$result["argu"],所使用的參數.
2802
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
2803
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
2804
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
2805
					#必填參數:
2806
					#$conf["input"],字串,要檢查的字串.
2807
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
2808
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
2809
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} ( no auth attempts in \${doNotNeed} user=<\${account}>, rip=\${ip}, \${doNotNeed}";
2810
					#可省略參數:
2811
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
2812
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
2813
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
2814
					#$conf["varCon"]=array("no_tail"=>" not");
2815
					#參考資料:
2816
					#無.
2817
					#備註:
2818
					#無.
2819
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
2820
					unset($conf["search::findSpecifyStrFormat"]);
2821
 
2822
					#如果分割失敗
2823
					if($findSpecifyStrFormat["status"]==="false"){
2824
 
2825
						#設置執行失敗
2826
						$result["status"]="false";
2827
 
2828
						#設置錯誤訊息
2829
						$result["error"]=$findSpecifyStrFormat;
2830
 
2831
						#回傳結果
2832
						return $result;
2833
 
2834
						}#if end
2835
 
2836
					#如果沒有符合格式
2837
					if($findSpecifyStrFormat["found"]==="false"){
2838
 
2839
						#跳過該行
2840
						continue 2;
2841
 
2842
						}#if end
2843
 
2844
					#取得時間點
2845
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
2846
 
2847
					#取得ip
2848
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
2849
 
2850
					#儲存其資訊
2851
					$rickyIpsOfDocecot[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
2852
 
2853
					#跳出  switch
2854
					break;
2855
 
2856
				#不應該執行到這邊
2857
				default:
2858
 
2859
					#設置執行失敗
2860
					$result["status"]="false";
2861
 
2862
					#設置錯誤訊息
2863
					$result["error"][]="unexpected error";
2864
 
2865
					#設置錯誤訊息
2866
					$result["error"][]=$findManyKeyWordsFromManyString;
2867
 
2868
					#回傳結果
2869
					return $result;
2870
 
2871
				}#switch end
2872
 
2873
			}#foreach end
2874
 
2875
		#初始化儲存可能有問題的ip資訊
2876
		$risky_ips=array();
2877
 
2878
		#針對每個ip
2879
		foreach($rickyIpsOfDocecot as $ip => $info){
2880
 
2881
			#如果同樣ip不到3次
2882
			if(count($rickyIpsOfDocecot[$ip])<3){
2883
 
2884
				#換看下個ip
2885
				continue;
2886
 
2887
				}#if end
2888
 
2889
			#儲存可能有問題的ip資訊
2890
			$risky_ips[]=$rickyIpsOfDocecot[$ip];
2891
 
2892
			}#foreach end
2893
 
2894
		#針對每個可能有問題ip的每個log行
2895
		foreach($risky_ips as $ip => $infos){
2896
 
2897
			#初始化暫存歷史資訊的陣列
2898
			$history=array();
2899
 
2900
			#初始化記錄ip來訪不大於1分鐘的計數
2901
			$count=0;
2902
 
2903
			#針對每個log行資訊
2904
			foreach($infos as $index => $info){
2905
 
2906
				#unixtime
2907
				$time=strtotime($info["time"]);
2908
 
2909
				#如果沒有下筆記錄
2910
				if(!isset($infos[$index+1])){
2911
 
2912
					#結束 foreach
2913
					break;
2914
 
2915
					}#if end
2916
 
2917
				#取得unixtime
2918
				$next_time=strtotime($infos[$index+1]["time"]);
2919
 
2920
				#如果時間間隔大於60秒
2921
				if($next_time-$time>60){
2922
 
2923
					#跳過,看下筆記錄
2924
					continue;
2925
 
2926
					}#if end
2927
 
2928
				#計數+1
2929
				$count++;
2930
 
2931
				#記錄該次事件資訊
2932
				$history[]=array("time"=>$time,"log"=>$info["log"]);
2933
 
2934
				}#foreach end
2935
 
2936
			#如果有達到3次
2937
			if($count>=3){
2938
 
2939
				#初始化陣列
2940
				$tmp=array();
2941
 
2942
				#記錄ip
2943
				$tmp["ip"]=$ip;
2944
 
2945
				#記錄歷史資訊
2946
				$tmp["info"]=$history;
2947
 
2948
				#記錄攻擊者的IP
2949
				$attacker_ips_imap[]=$ip;
2950
 
2951
				}#if end
2952
 
2953
			}#foreach end
2954
 
2955
		#設置結果
2956
		$result["content"]=$attacker_ips_imap;
2957
 
2958
		#設置執行正常
2959
		$result["status"]="true";
2960
 
2961
		#回傳結果
2962
		return $result;
2963
 
2964
		}#function checkDovecotAttackLog end
2965
 
2966
	/*
2967
	#函式說明:
2968
	#檢查 ssh log 中疑似攻擊的記錄.
2969
	#回傳結果:
2970
	#$result["status"],字串,執行是否正常,"true"代表正常,"false"代表不正常.
2971
	#$result["error"],錯誤訊息陣列.
2972
	#$result["function"],字串,當前執行的函式名稱.
2973
	#$result["content"],陣列,攻擊記錄資訊,每個元素為陣列key為"ip"者為攻擊者的ip;key為info者為其資訊陣列,其key為"log"者代表log的行內容;key為"time"者代表時間點;key為ip者代表ip.
2974
	#必填參數:
2975
	#無.
2976
	#可省略參數:
2977
	#無
2978
	#參考資料:
2979
	#無.
2980
	#備註:
2981
	#無.
2982
	*/
2983
	public static function checkSshAttackLog(){
2984
 
2985
		#初始化要回傳的結果
2986
		$result=array();
2987
 
2988
		#取得當前執行的函數名稱
2989
		$result["function"]=__FUNCTION__;
2990
 
2991
		#記錄ssh攻擊者的IP
2992
		$attacker_ips_ssh=array();
2993
 
2994
		#透過 journalctl -a -e --unit=sshd.service來取得 ssh 攻擊者的 IP
2995
		#函式說明:
2996
		#呼叫shell執行系統命令,並取得回傳的內容.
2997
		#回傳的結果:
2998
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2999
		#$result["error"],錯誤訊息陣列.
3000
		#$result["function"],當前執行的函式名稱.
3001
		#$result["argu"],使用的參數.
3002
		#$result["cmd"],執行的指令內容.
3003
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
3004
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
3005
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
3006
		#$result["running"],是否還在執行.
3007
		#$result["pid"],pid.
3008
		#$result["statusCode"],執行結束後的代碼.
3009
		#必填參數:
3010
		#$conf["command"],字串,要執行的指令與.
3011
		$conf["external::callShell"]["command"]="journalctl";
3012
		#$conf["fileArgu"],字串,變數__FILE__的內容.
3013
		$conf["external::callShell"]["fileArgu"]=__FILE__;
3014
		#可省略參數:
3015
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
3016
		$conf["external::callShell"]["argu"]=array("-a","-e","--unit=sshd.service");
3017
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函式的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
3018
		#$conf["arguIsAddr"]=array();
3019
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
3020
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
3021
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
3022
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
3023
		#$conf["enablePrintDescription"]="true";
3024
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
3025
		#$conf["printDescription"]="";
3026
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
3027
		$conf["external::callShell"]["escapeshellarg"]="true";
3028
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
3029
		#$conf["username"]="";
3030
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
3031
		#$conf["password"]="";
3032
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
3033
		#$conf["useScript"]="";
3034
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
3035
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
3036
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
3037
		#$conf["inBackGround"]="";
3038
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
3039
		#$conf["getErr"]="false";
3040
		#備註:
3041
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
3042
		#參考資料:
3043
		#exec=>http://php.net/manual/en/function.exec.php
3044
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
3045
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
3046
		$callShell=external::callShell($conf["external::callShell"]);
3047
		unset($conf["external::callShell"]);
3048
 
3049
		#如果執行失敗
3050
		if($callShell["status"]==="false"){
3051
 
3052
			#如果有 statusCode
3053
			if(isset($callShell["statusCode"])){
3054
 
3055
				#如果shell回傳不為0也不為1
3056
				if($callShell["statusCode"]!==0 && $callShell["statusCode"]!==1){
3057
 
3058
					#設置執行失敗
3059
					$result["status"]="false";
3060
 
3061
					#設置錯誤訊息
3062
					$result["error"]=$callShell;
3063
 
3064
					#回傳結果
3065
					return $result;
3066
 
3067
					}#if end
3068
 
3069
				}#if end
3070
 
3071
			#設置執行失敗
3072
			$result["status"]="false";
3073
 
3074
			#設置錯誤訊息
3075
			$result["error"]=$callShell;
3076
 
3077
			#回傳結果
3078
			return $result;
3079
 
3080
			}#if end
3081
 
3082
		/*
3083
		得到的範例輸出
3084
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
3085
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: pam_unix(sshd:auth): check pass; user unknown
3086
		Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.69
3087
		Sep 30 00:36:38 silverblue-guest.qbpwcf.org sshd-session[1607010]: Failed password for invalid user lizepeng from 60.213.10.69 port 39156 ssh2
3088
		Sep 30 00:36:40 silverblue-guest.qbpwcf.org sshd-session[1607010]: Connection closed by invalid user lizepeng 60.213.10.69 port 39156 [preauth]
3089
		Sep 30 05:54:01 silverblue-guest.qbpwcf.org sshd-session[2346022]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.81  user=root
3090
		Sep 30 05:54:03 silverblue-guest.qbpwcf.org sshd-session[2346022]: Failed password for root from 60.213.10.81 port 41644 ssh2
3091
		Sep 30 05:54:04 silverblue-guest.qbpwcf.org sshd-session[2346022]: Connection closed by authenticating user root 60.213.10.81 port 41644 [preauth]
3092
		Sep 30 05:54:20 silverblue-guest.qbpwcf.org sshd-session[2346860]: Invalid user qy from 60.213.10.81 port 42960
3093
		Sep 30 05:54:21 silverblue-guest.qbpwcf.org sshd-session[2346860]: pam_unix(sshd:auth): check pass; user unknown
3094
		Sep 30 05:54:21 silverblue-guest.qbpwcf.org sshd-session[2346860]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=60.213.10.81
3095
		Sep 30 05:54:22 silverblue-guest.qbpwcf.org sshd-session[2346860]: Failed password for invalid user qy from 60.213.10.81 port 42960 ssh2
3096
		Sep 30 05:54:23 silverblue-guest.qbpwcf.org sshd-session[2346860]: Connection closed by invalid user qy 60.213.10.81 port 42960 [preauth]
3097
		Sep 30 06:08:06 silverblue-guest.qbpwcf.org sshd-session[2378295]: Connection closed by 167.94.145.105 port 55712 [preauth]
3098
		Sep 30 08:09:51 silverblue-guest.qbpwcf.org sshd-session[2662907]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.13.207.69  user=root
3099
		Sep 30 08:09:54 silverblue-guest.qbpwcf.org sshd-session[2662907]: Failed password for root from 183.13.207.69 port 18258 ssh2
3100
		Sep 30 08:09:54 silverblue-guest.qbpwcf.org sshd-session[2662907]: Connection closed by authenticating user root 183.13.207.69 port 18258 [preauth]
3101
		Sep 30 08:10:11 silverblue-guest.qbpwcf.org sshd-session[2663658]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=183.13.207.69  user=root
3102
		Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Failed password for root from 183.13.207.69 port 17293 ssh2
3103
		Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Connection closed by authenticating user root 183.13.207.69 port 17293 [preauth]
3104
		*/
3105
 
3106
		#認證失敗的關鍵字
3107
		$keyWordFP=" Failed password ";
3108
 
3109
		#不存在使用者的關鍵字
3110
		$keyWordIU=" Invalid user ";
3111
 
3112
		#搜尋符合關鍵字的log行
3113
		#函式說明:
3114
		#檢查多個字串中的每個字串是否有多個關鍵字
3115
		#回傳結果:
3116
		#$result["status"],整體來說,執行是否成功,"true"代表執行成功,"false"代表執行失敗。
3117
		#$result["function"],當前執行的函數名稱.
3118
		#$result["error"],錯誤訊息.
3119
		#$result["argu"],使用的參數.
3120
		#$result["foundedTrueKey"],結果為"true"的被搜尋元素key陣列,與其數值內容.
3121
		#$result["foundedKeyWords"],找到的關鍵字陣列.
3122
		#$result["foundedFalseKey"],結果為"false"的被搜尋元素key陣列,與其數值內容.
3123
		#$result["foundedTrueKeyWords"],二維陣列,各個字串有找到的關鍵字陣列.
3124
		#$result["foundedAll"],是否每個關鍵字都有找到,"true"代表每個都有找到,"false"代表沒有每個都找到.
3125
		#$result["keyWordsIncludeStr"],陣列,儲存有找到關鍵字的來源的索引(sourceIndex)與其內容(sourceVal)跟找到的關鍵字項目陣列(KeyWords).
3126
		#必填參數:
3127
		#$conf["keyWords"],字串陣列,想要搜尋的關鍵字.
3128
		$conf["search::findManyKeyWordsFromManyString"]["keyWords"]=array($keyWordFP,$keyWordIU);
3129
		#$conf["stringArray"],字串陣列,要被搜尋的字串內容陣列.
3130
		$conf["search::findManyKeyWordsFromManyString"]["stringArray"]=$callShell["output"];
3131
		#可省略參數:
3132
		#$conf["completeEqual"],字串,是否內容要完全符合,不能多出任何不符合的內容,預設為"false"不需要完全符合.
3133
		#$conf["completeEqual"]="true";
3134
		#參考資料:
3135
		#無.
3136
		#備註:
3137
		#無.
3138
		$findManyKeyWordsFromManyString=search::findManyKeyWordsFromManyString($conf["search::findManyKeyWordsFromManyString"]);
3139
		unset($conf["search::findManyKeyWordsFromManyString"]);
3140
 
3141
		#如果執行失敗
3142
		if($findManyKeyWordsFromManyString["status"]==="false"){
3143
 
3144
			#設置執行失敗
3145
			$result["status"]="false";
3146
 
3147
			#設置錯誤訊息
3148
			$result["error"]=$findManyKeyWordsFromManyString;
3149
 
3150
			#回傳結果
3151
			return $result;
3152
 
3153
			}#if end
3154
 
3155
		#初始化儲存可能有問題的存取ssh服務遠端ip
3156
		$risky_ips=array();
3157
 
3158
		#針對每個符合的log行
3159
		foreach($findManyKeyWordsFromManyString["foundedTrueKey"] as $index => $oriLog){
3160
 
3161
			#找到的關鍵字
3162
			$foundKeyWord=$findManyKeyWordsFromManyString["foundedTrueKeyWords"][$index][0];
3163
 
3164
			#依照符合的關鍵字
3165
			switch($foundKeyWord){
3166
 
3167
				#如果是秘密碼錯誤
3168
				case $keyWordFP:
3169
 
3170
					#範例
3171
					#Sep 30 08:10:13 silverblue-guest.qbpwcf.org sshd-session[2663658]: Failed password for root from 183.13.207.69 port 17293 ssh2
3172
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} Failed password for ${account} from ${ip} ${doNotNeed}
3173
 
3174
					#取得時間點跟遠端IP
3175
					#函式說明:
3176
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3177
					#回傳結果:
3178
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3179
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
3180
					#$result["function"],當前執行的函式名稱.
3181
					#$result["argu"],所使用的參數.
3182
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3183
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3184
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3185
					#必填參數:
3186
					#$conf["input"],字串,要檢查的字串.
3187
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
3188
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3189
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} Failed password for \${account} from \${ip} \${doNotNeed}";
3190
					#可省略參數:
3191
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3192
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
3193
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3194
					#$conf["varCon"]=array("no_tail"=>" not");
3195
					#參考資料:
3196
					#無.
3197
					#備註:
3198
					#無.
3199
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3200
					unset($conf["search::findSpecifyStrFormat"]);
3201
 
3202
					#如果分割失敗
3203
					if($findSpecifyStrFormat["status"]==="false"){
3204
 
3205
						#設置執行失敗
3206
						$result["status"]="false";
3207
 
3208
						#設置錯誤訊息
3209
						$result["error"]=$findSpecifyStrFormat;
3210
 
3211
						#回傳結果
3212
						return $result;
3213
 
3214
						}#if end
3215
 
3216
					#如果沒有符合格式
3217
					if($findSpecifyStrFormat["found"]==="false"){
3218
 
3219
						#跳過該行
3220
						continue 2;
3221
 
3222
						}#if end
3223
 
3224
					#取得時間點
3225
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
3226
 
3227
					#取得ip
3228
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
3229
 
3230
					#儲存其資訊
3231
					$risky_ips[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
3232
 
3233
					#跳出  switch
3234
					break;
3235
 
3236
				#如果是不存在的使用者
3237
				case $keyWordIU:
3238
 
3239
					#範例
3240
					#Sep 30 00:36:36 silverblue-guest.qbpwcf.org sshd-session[1607010]: Invalid user lizepeng from 60.213.10.69 port 39156
3241
					#${month} ${day} ${hour}:${min}:${sec} ${doNotNeed} Invalid user ${account} from ${ip} port ${doNotNeed}
3242
 
3243
					#取得時間點跟遠端IP
3244
					#函式說明:
3245
					#尋找字串中是否含有符合格式的內容,且回傳解析好的變數數值.
3246
					#回傳結果:
3247
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3248
					#$reuslt["error"],執行不正常結束的錯訊息陣列.
3249
					#$result["function"],當前執行的函式名稱.
3250
					#$result["argu"],所使用的參數.
3251
					#$result["found"],是否有找到符合格式的字串內容,"true"代表有找到,"false"代表沒有找到.
3252
					#$result["content"],陣列,若為n個${*},則當found為"true"時,就會回傳n個元素.
3253
					#$result["parsedVar"][varName],陣列,解析好的變數陣列,varName為${}中的內容.
3254
					#必填參數:
3255
					#$conf["input"],字串,要檢查的字串.
3256
					$conf["search::findSpecifyStrFormat"]["input"]=$oriLog;
3257
					#$conf["format"],格式字串,要尋找的格式字串.格式為固定的字串("fixedStr format")與變數("${keyWordVarName}")組成.
3258
					$conf["search::findSpecifyStrFormat"]["format"]="\${month} \${day} \${hour}:\${min}:\${sec} \${doNotNeed} Invalid user \${account} from \${ip} port \${doNotNeed}";
3259
					#可省略參數:
3260
					#$conf["varEqual"],陣列,變數對應的數值,null代表不指定,其他內容代表該變數解析出來必須要為該內容.
3261
					#$conf["search::findSpecifyStrFormat"]["varEqual"]=array(null,"found");
3262
					#$conf["varCon"],陣列,每個varEqual為null者,其是否有其他條件,預設為null代表無其他條件,條件的表示是用陣列的key與value來表達,例如:array("no_tail"=>" not"),就代表變數的結尾不能為" not",可以用的key有"head",代表開頭要有什麼;"no_head",代表不能為什麼開頭;"tail",代表要什麼結尾;"no_tail",代表不能什麼結尾.
3263
					#$conf["varCon"]=array("no_tail"=>" not");
3264
					#參考資料:
3265
					#無.
3266
					#備註:
3267
					#無.
3268
					$findSpecifyStrFormat=search::findSpecifyStrFormat($conf["search::findSpecifyStrFormat"]);
3269
					unset($conf["search::findSpecifyStrFormat"]);
3270
 
3271
					#如果分割失敗
3272
					if($findSpecifyStrFormat["status"]==="false"){
3273
 
3274
						#設置執行失敗
3275
						$result["status"]="false";
3276
 
3277
						#設置錯誤訊息
3278
						$result["error"]=$findSpecifyStrFormat;
3279
 
3280
						#回傳結果
3281
						return $result;
3282
 
3283
						}#if end
3284
 
3285
					#如果沒有符合格式
3286
					if($findSpecifyStrFormat["found"]==="false"){
3287
 
3288
						#跳過該行
3289
						continue 2;
3290
 
3291
						}#if end
3292
 
3293
					#取得時間點
3294
					$time=$findSpecifyStrFormat["parsedVar"]["month"][0]." ".$findSpecifyStrFormat["parsedVar"]["day"][0]." ".$findSpecifyStrFormat["parsedVar"]["hour"][0].":".$findSpecifyStrFormat["parsedVar"]["min"][0].":".$findSpecifyStrFormat["parsedVar"]["sec"][0];
3295
 
3296
					#取得ip
3297
					$ip=$findSpecifyStrFormat["parsedVar"]["ip"][0];
3298
 
3299
					#儲存其資訊
3300
					$risky_ips[$ip][]=array("time"=>$time,"ip"=>$ip,"log"=>$oriLog);
3301
 
3302
					#跳出  switch
3303
					break;
3304
 
3305
				#不應該執行到這邊
3306
				default:
3307
 
3308
					#設置執行失敗
3309
					$result["status"]="false";
3310
 
3311
					#設置錯誤訊息
3312
					$result["error"][]="unexpected error";
3313
 
3314
					#設置錯誤訊息
3315
					$result["error"][]=$findManyKeyWordsFromManyString;
3316
 
3317
					#回傳結果
3318
					return $result;
3319
 
3320
				}#switch end
3321
 
3322
			}#foreach end
3323
 
3324
		#針對每個可能有問題ip的每個log行
3325
		foreach($risky_ips as $ip => $infos){
3326
 
3327
			#初始化暫存歷史記錄的陣列
3328
			$history=array();
3329
 
3330
			#初始化記錄ip來訪不大於1分鐘的計數
3331
			$count=0;
3332
 
3333
			#針對每個log行資訊
3334
			foreach($infos as $index => $info){
3335
 
3336
				#unixtime
3337
				$time=strtotime($info["time"]);
3338
 
3339
				#如果沒有下筆記錄
3340
				if(!isset($infos[$index+1])){
3341
 
3342
					#結束 foreach
3343
					break;
3344
 
3345
					}#if end
3346
 
3347
				#取得unixtime
3348
				$next_time=strtotime($infos[$index+1]["time"]);
3349
 
3350
				#如果下筆時間記錄與當前這筆間隔大於60秒
3351
				if($next_time-$time>60){
3352
 
3353
					#跳過,看下筆記錄
3354
					continue;
3355
 
3356
					}#if end
3357
 
3358
				#計數+1
3359
				$count++;
3360
 
3361
				#記錄該次記錄
3362
				$history[]=array("time"=>$time,"log"=>$info["log"]);
3363
 
3364
				}#foreach end
3365
 
3366
			#如果有達到3次
3367
			if($count>=3){
3368
 
3369
				#初始化暫存的陣列
3370
				$tmp=array();
3371
 
3372
				#取得資訊
3373
				$tmp["info"]=$history;
3374
 
3375
				#取得問題ip
3376
				$tmp["ip"]=$ip;
3377
 
3378
				#記錄攻擊者的IP
3379
				$attacker_ips_ssh[]=$tmp;
3380
 
3381
				}#if end
3382
 
3383
			}#foreach end
3384
 
3385
		#設置結果
3386
		$result["content"]=$attacker_ips_ssh;
3387
 
3388
		#設置執行正常
3389
		$result["status"]="true";
3390
 
3391
		#回傳結果
3392
		return $result;
3393
 
3394
		}#function checkSshAttackLog end
3395
 
3 liveuser 3396
	}#class security end
3397
 
3398
?>