Subversion Repositories php-qbpwcf

Rev

Rev 106 | Rev 222 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 106 Rev 183
Line 59... Line 59...
59
 
59
 
60
#匯入外部套件
60
#匯入外部套件
61
include("allInOneForJson.php");
61
include("allInOneForJson.php");
62
 
62
 
63
#建議的log位置
63
#建議的log位置
64
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log"
64
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
65
 
65
 
-
 
66
#預設的範例資料參數
66
/*
67
$params=array();
-
 
68
$params["dbSecret"]=$dbSecret;
-
 
69
$params["dbAddr"]=$dbAddress;
-
 
70
$params["dbPort"]=$dbPort;
-
 
71
$params["dbName"]=$dbName;
-
 
72
$params["dbUser"]=$dbAccount;
-
 
73
$params["dbPass"]=$dbPassword;
-
 
74
$params["dtName"]="namespace";
-
 
75
$params["cols"]=array("comment",);
-
 
76
$params["vals"]=array("updated not exist namespace");
-
 
77
$params["wcols"]=array("name");
-
 
78
$params["wvals"]=array("notExist");
67
 
79
 
-
 
80
#加密參數
-
 
81
#函式說明:
-
 
82
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
-
 
83
#回傳結果:
-
 
84
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
-
 
85
#$result["function"],當前執行的函數名稱.
-
 
86
#$result["content"],加密後的結果.
-
 
87
#$result["error"],錯誤訊息陣列.
-
 
88
#$result["argu"],使用的參數.
-
 
89
#必填參數:
-
 
90
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
-
 
91
$conf["enCodeStr"]=$params;
68
# test case - 1 - start
92
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
-
 
93
$conf["enCodeType"]="qbpwcf";
-
 
94
#可省略參數:
-
 
95
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
-
 
96
#$conf["sha1Raw"]="false";
-
 
97
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
-
 
98
#$conf["p_hash"]="";
-
 
99
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
-
 
100
#$conf["keyForAes256"]="";
-
 
101
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
-
 
102
#$conf["aes256Encode"]="";
-
 
103
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
-
 
104
#$conf["qbpwcfDecode"]="false";
-
 
105
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
106
#$conf["gpgDecrypt"]="false";
-
 
107
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
-
 
108
#$conf["gpgId"]="";
-
 
109
#參考資料:
-
 
110
#sha1=>http://php.net/manual/en/function.sha1.php
-
 
111
#md5=>http://php.net/manual/en/function.md5.php
-
 
112
#password_hash=>http://php.net/manual/en/function.password-hash.php
-
 
113
#password_verify=>http://php.net/manual/en/function.password-verify.php
-
 
114
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
-
 
115
#備註:
-
 
116
#無.
-
 
117
$enCodeStr=authenticate::enCodeStr($conf);
-
 
118
unset($conf);
69
 
119
 
70
$params=array();
120
#如果執行異常
71
$params["dbSecret"]="";
-
 
72
$params["dbAddr"]="localhost";
-
 
73
$params["dbPort"]="3306";
-
 
74
$params["dbName"]="test";
-
 
75
$params["dbUser"]="test";
-
 
76
$params["dbPass"]="test";
121
if($enCodeStr["status"]==="false"){
77
$params["dtName"]="member";
-
 
78
$params["cols"]=array("account","password","comment");
-
 
79
$params["vals"]=array("test acct","test pass updated","test comment updated");
-
 
80
$params["wcols"]=array("account");
-
 
81
$params["wvals"]=array("test acct");
-
 
82
 
122
 
-
 
123
	#函式說明:
-
 
124
	#撰寫log
-
 
125
	#回傳結果:
-
 
126
	#$result["status"],狀態,"true"或"false".
-
 
127
	#$result["error"],錯誤訊息陣列.
-
 
128
	#$result["function"],當前函式的名稱.
-
 
129
	#$result["argu"],使用的參數.
83
#設置參數
130
	#必填參數:
-
 
131
	#$conf["path"],log檔案的路徑與名稱.
-
 
132
	$conf["path"]=$logFile;
-
 
133
	#$conf["content"],字串,要寫的內容.
84
$_POST["params"]=base64_encode(urlencode(json_encode($params)));
134
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
-
 
135
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
136
	$conf["fileArgu"]=__FILE__;
-
 
137
	#可省略參數:
-
 
138
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
139
	#$conf["rewrite"]="false";
-
 
140
	#參考資料:
-
 
141
	#無.
-
 
142
	#備註:
-
 
143
	#無.	
-
 
144
	$record=logs::record($conf);
-
 
145
	unset($conf);
-
 
146
 
-
 
147
	#如果寫log 失敗
-
 
148
	if($record["status"]==="false"){
-
 
149
 
-
 
150
		#印出訊息
-
 
151
		echo json_encode($record);
-
 
152
		
-
 
153
		#異常結束執行
-
 
154
		exit(1);
85
 
155
 
-
 
156
		}#if end
-
 
157
		
86
# test case - 1 - end
158
	#異常結束執行
-
 
159
	exit(1);
87
 
160
 
-
 
161
	}#if end
-
 
162
	
-
 
163
#加密參數
-
 
164
#函式說明:
-
 
165
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
-
 
166
#回傳結果:
-
 
167
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
-
 
168
#$result["function"],當前執行的函數名稱.
-
 
169
#$result["content"],加密後的結果.
-
 
170
#$result["error"],錯誤訊息陣列.
-
 
171
#$result["argu"],使用的參數.
-
 
172
#必填參數:
-
 
173
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
-
 
174
$conf["enCodeStr"]=$enCodeStr["content"];
88
*/
175
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
-
 
176
$conf["enCodeType"]="gpg";
-
 
177
#可省略參數:
-
 
178
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
-
 
179
#$conf["sha1Raw"]="false";
-
 
180
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
-
 
181
#$conf["p_hash"]="";
-
 
182
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
-
 
183
#$conf["keyForAes256"]="";
-
 
184
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
-
 
185
#$conf["aes256Encode"]="";
-
 
186
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
-
 
187
#$conf["qbpwcfDecode"]="false";
-
 
188
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
189
$conf["gpgDecrypt"]="false";
-
 
190
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
-
 
191
#$conf["gpgId"]="";
-
 
192
#參考資料:
-
 
193
#sha1=>http://php.net/manual/en/function.sha1.php
-
 
194
#md5=>http://php.net/manual/en/function.md5.php
-
 
195
#password_hash=>http://php.net/manual/en/function.password-hash.php
-
 
196
#password_verify=>http://php.net/manual/en/function.password-verify.php
-
 
197
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
-
 
198
#備註:
-
 
199
#無.
-
 
200
$enCodeStr=authenticate::enCodeStr($conf);
-
 
201
unset($conf);
-
 
202
 
-
 
203
#如果執行異常
-
 
204
if($enCodeStr["status"]==="false"){
-
 
205
 
-
 
206
	#函式說明:
-
 
207
	#撰寫log
-
 
208
	#回傳結果:
-
 
209
	#$result["status"],狀態,"true"或"false".
-
 
210
	#$result["error"],錯誤訊息陣列.
-
 
211
	#$result["function"],當前函式的名稱.
-
 
212
	#$result["argu"],使用的參數.
-
 
213
	#必填參數:
-
 
214
	#$conf["path"],log檔案的路徑與名稱.
-
 
215
	$conf["path"]=$logFile;
-
 
216
	#$conf["content"],字串,要寫的內容.
-
 
217
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
-
 
218
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
219
	$conf["fileArgu"]=__FILE__;
-
 
220
	#可省略參數:
-
 
221
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
222
	#$conf["rewrite"]="false";
-
 
223
	#參考資料:
-
 
224
	#無.
-
 
225
	#備註:
-
 
226
	#無.	
-
 
227
	$record=logs::record($conf);
-
 
228
	unset($conf);
-
 
229
 
-
 
230
	#如果寫log 失敗
-
 
231
	if($record["status"]==="false"){
-
 
232
 
-
 
233
		#印出訊息
-
 
234
		echo json_encode($record);
-
 
235
		
-
 
236
		#異常結束執行
-
 
237
		exit(1);
89
 
238
 
-
 
239
		}#if end
-
 
240
	
-
 
241
	#異常結束執行
-
 
242
	exit(1);
-
 
243
 
-
 
244
	}#if end
-
 
245
	
-
 
246
#編碼參數
-
 
247
#函式說明:
-
 
248
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
-
 
249
#回傳結果:
-
 
250
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
-
 
251
#$result["function"],當前執行的函數名稱.
-
 
252
#$result["content"],加密後的結果.
-
 
253
#$result["error"],錯誤訊息陣列.
-
 
254
#$result["argu"],使用的參數.
-
 
255
#必填參數:
-
 
256
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
-
 
257
$conf["enCodeStr"]=$enCodeStr["content"];
90
#涵式說明:
258
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
-
 
259
$conf["enCodeType"]="bin2hex";
-
 
260
#可省略參數:
-
 
261
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
-
 
262
#$conf["sha1Raw"]="false";
-
 
263
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
-
 
264
#$conf["p_hash"]="";
-
 
265
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
-
 
266
#$conf["keyForAes256"]="";
-
 
267
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
-
 
268
#$conf["aes256Encode"]="";
-
 
269
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
-
 
270
#$conf["qbpwcfDecode"]="false";
-
 
271
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
272
#$conf["gpgDecrypt"]="false";
-
 
273
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
-
 
274
#$conf["gpgId"]="";
-
 
275
#參考資料:
-
 
276
#sha1=>http://php.net/manual/en/function.sha1.php
-
 
277
#md5=>http://php.net/manual/en/function.md5.php
-
 
278
#password_hash=>http://php.net/manual/en/function.password-hash.php
-
 
279
#password_verify=>http://php.net/manual/en/function.password-verify.php
-
 
280
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
-
 
281
#備註:
-
 
282
#無.
-
 
283
$enCodeStr=authenticate::enCodeStr($conf);
-
 
284
unset($conf);
-
 
285
 
-
 
286
#如果執行異常
-
 
287
if($enCodeStr["status"]==="false"){
-
 
288
 
-
 
289
	#函式說明:
-
 
290
	#撰寫log
-
 
291
	#回傳結果:
-
 
292
	#$result["status"],狀態,"true"或"false".
-
 
293
	#$result["error"],錯誤訊息陣列.
-
 
294
	#$result["function"],當前函式的名稱.
-
 
295
	#$result["argu"],使用的參數.
-
 
296
	#必填參數:
-
 
297
	#$conf["path"],log檔案的路徑與名稱.
-
 
298
	$conf["path"]=$logFile;
-
 
299
	#$conf["content"],字串,要寫的內容.
-
 
300
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
-
 
301
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
302
	$conf["fileArgu"]=__FILE__;
-
 
303
	#可省略參數:
-
 
304
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
305
	#$conf["rewrite"]="false";
-
 
306
	#參考資料:
-
 
307
	#無.
-
 
308
	#備註:
-
 
309
	#無.	
-
 
310
	$record=logs::record($conf);
-
 
311
	unset($conf);
-
 
312
 
-
 
313
	#如果寫log 失敗
-
 
314
	if($record["status"]==="false"){
-
 
315
 
-
 
316
		#印出訊息
-
 
317
		echo json_encode($record);
-
 
318
		
-
 
319
		#異常結束執行
-
 
320
		exit(1);
-
 
321
 
-
 
322
		}#if end
-
 
323
		
-
 
324
	#異常結束執行
-
 
325
	exit(1);
-
 
326
 
-
 
327
	}#if end
-
 
328
 
-
 
329
#更新POST的預設參數
-
 
330
$_POST["params"]=$enCodeStr["content"];
-
 
331
 
-
 
332
#涵式說明:
91
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
333
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
92
#回傳的結果:
334
#回傳的結果:
93
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
335
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
94
#$result["error"],錯誤訊息陣列.
336
#$result["error"],錯誤訊息陣列.
95
#$resutl["function"],當前執行的涵式名稱.
337
#$resutl["function"],當前執行的涵式名稱.
96
#$result["warning"],警告訊息陣列.
338
#$result["warning"],警告訊息陣列.
97
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
339
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
Line 130... Line 372...
130
#備註:
372
#備註:
131
#表單變數的名稱若含有「.」,則會變成「-」。
373
#表單變數的名稱若含有「.」,則會變成「-」。
132
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf);
374
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf);
133
unset($conf);
375
unset($conf);
134
 
376
 
-
 
377
#如果執行異常
-
 
378
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
-
 
379
 
-
 
380
	#函式說明:
-
 
381
	#撰寫log
-
 
382
	#回傳結果:
-
 
383
	#$result["status"],狀態,"true"或"false".
-
 
384
	#$result["error"],錯誤訊息陣列.
-
 
385
	#$result["function"],當前函式的名稱.
-
 
386
	#$result["argu"],使用的參數.
-
 
387
	#必填參數:
-
 
388
	#$conf["path"],log檔案的路徑與名稱.
-
 
389
	$conf["path"]=$logFile;
-
 
390
	#$conf["content"],字串,要寫的內容.
-
 
391
	$conf["content"]="Form data error, please see json:".json_encode($responseMultiInputDataSecurityEnhance).PHP_EOL;
-
 
392
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
393
	$conf["fileArgu"]=__FILE__;
-
 
394
	#可省略參數:
-
 
395
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
396
	#$conf["rewrite"]="false";
-
 
397
	#參考資料:
-
 
398
	#無.
-
 
399
	#備註:
-
 
400
	#無.	
-
 
401
	$record=logs::record($conf);
-
 
402
	unset($conf);
-
 
403
 
-
 
404
	#如果寫log 失敗
-
 
405
	if($record["status"]==="false"){
-
 
406
 
-
 
407
		#印出訊息
-
 
408
		echo json_encode($record);
-
 
409
		
-
 
410
		#異常結束執行
-
 
411
		exit(1);
-
 
412
 
-
 
413
		}#if end
-
 
414
		
-
 
415
	#異常結束執行
-
 
416
	exit(1);
-
 
417
	
-
 
418
	}#if end
-
 
419
 
135
#函式說明:
420
#函式說明:
136
#撰寫log
421
#撰寫log
137
#回傳結果:
422
#回傳結果:
138
#$result["status"],狀態,"true"或"false".
423
#$result["status"],狀態,"true"或"false".
139
#$result["error"],錯誤訊息陣列.
424
#$result["error"],錯誤訊息陣列.
Line 160... Line 445...
160
if($record["status"]==="false"){
445
if($record["status"]==="false"){
161
 
446
 
162
	#印出訊息
447
	#印出訊息
163
	echo json_encode($record);
448
	echo json_encode($record);
164
	
449
	
165
	#結束執行
450
	#異常結束執行
166
	exit;
451
	exit(1);
167
 
452
 
168
	}#if end
453
	}#if end
169
 
454
 
170
#如果執行失敗
455
#取得參數
171
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
456
$params=$responseMultiInputDataSecurityEnhance["inputDataContent"]["params"];
172
 
457
 
-
 
458
#解碼參數
173
	#印出訊息
459
#函式說明:
-
 
460
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
-
 
461
#回傳結果:
-
 
462
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
-
 
463
#$result["function"],當前執行的函數名稱.
-
 
464
#$result["content"],加密後的結果.
-
 
465
#$result["error"],錯誤訊息陣列.
-
 
466
#$result["argu"],使用的參數.
-
 
467
#必填參數:
-
 
468
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
-
 
469
$conf["enCodeStr"]=$params;
174
	echo json_encode($responseMultiInputDataSecurityEnhance);
470
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
-
 
471
$conf["enCodeType"]="hex2bin";
-
 
472
#可省略參數:
-
 
473
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
-
 
474
#$conf["sha1Raw"]="false";
-
 
475
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
-
 
476
#$conf["p_hash"]="";
-
 
477
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
-
 
478
#$conf["keyForAes256"]="";
-
 
479
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
-
 
480
#$conf["aes256Encode"]="";
-
 
481
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
-
 
482
#$conf["qbpwcfDecode"]="false";
-
 
483
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
484
#$conf["gpgDecrypt"]="false";
-
 
485
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
-
 
486
#$conf["gpgId"]="";
-
 
487
#參考資料:
-
 
488
#sha1=>http://php.net/manual/en/function.sha1.php
-
 
489
#md5=>http://php.net/manual/en/function.md5.php
-
 
490
#password_hash=>http://php.net/manual/en/function.password-hash.php
-
 
491
#password_verify=>http://php.net/manual/en/function.password-verify.php
-
 
492
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
-
 
493
#備註:
-
 
494
#無.
-
 
495
$enCodeStr=authenticate::enCodeStr($conf);
-
 
496
unset($conf);
175
 
497
 
-
 
498
#debug
-
 
499
#var_dump(__LINE__,$enCodeStr);
-
 
500
 
-
 
501
#如果執行異常
-
 
502
if($enCodeStr["status"]==="false"){
-
 
503
 
-
 
504
	#函式說明:
-
 
505
	#撰寫log
-
 
506
	#回傳結果:
-
 
507
	#$result["status"],狀態,"true"或"false".
-
 
508
	#$result["error"],錯誤訊息陣列.
-
 
509
	#$result["function"],當前函式的名稱.
-
 
510
	#$result["argu"],使用的參數.
-
 
511
	#必填參數:
-
 
512
	#$conf["path"],log檔案的路徑與名稱.
-
 
513
	$conf["path"]=$logFile;
-
 
514
	#$conf["content"],字串,要寫的內容.
-
 
515
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
-
 
516
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
517
	$conf["fileArgu"]=__FILE__;
-
 
518
	#可省略參數:
-
 
519
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
520
	#$conf["rewrite"]="false";
-
 
521
	#參考資料:
-
 
522
	#無.
-
 
523
	#備註:
-
 
524
	#無.	
-
 
525
	$record=logs::record($conf);
-
 
526
	unset($conf);
-
 
527
 
-
 
528
	#如果寫log 失敗
-
 
529
	if($record["status"]==="false"){
-
 
530
 
-
 
531
		#印出訊息
-
 
532
		echo json_encode($record);
-
 
533
		
176
	#結束執行
534
		#異常結束執行
177
	exit;
535
		exit(1);
178
 
536
 
-
 
537
		}#if end
-
 
538
		
-
 
539
	#異常結束執行
-
 
540
	exit(1);
-
 
541
	
179
	}#if end
542
	}#if end
-
 
543
	
-
 
544
#解密參數
-
 
545
#函式說明:
-
 
546
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
-
 
547
#回傳結果:
-
 
548
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
-
 
549
#$result["function"],當前執行的函數名稱.
-
 
550
#$result["content"],加密後的結果.
-
 
551
#$result["error"],錯誤訊息陣列.
-
 
552
#$result["argu"],使用的參數.
-
 
553
#必填參數:
-
 
554
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
-
 
555
$conf["enCodeStr"]=$enCodeStr["content"];
-
 
556
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
-
 
557
$conf["enCodeType"]="gpg";
-
 
558
#可省略參數:
-
 
559
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
-
 
560
#$conf["sha1Raw"]="false";
-
 
561
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
-
 
562
#$conf["p_hash"]="";
-
 
563
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
-
 
564
#$conf["keyForAes256"]="";
-
 
565
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
-
 
566
#$conf["aes256Encode"]="";
-
 
567
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
-
 
568
#$conf["qbpwcfDecode"]="true";
-
 
569
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
570
$conf["gpgDecrypt"]="true";
-
 
571
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
-
 
572
#$conf["gpgId"]="";
-
 
573
#參考資料:
-
 
574
#sha1=>http://php.net/manual/en/function.sha1.php
-
 
575
#md5=>http://php.net/manual/en/function.md5.php
-
 
576
#password_hash=>http://php.net/manual/en/function.password-hash.php
-
 
577
#password_verify=>http://php.net/manual/en/function.password-verify.php
-
 
578
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
-
 
579
#備註:
-
 
580
#無.
-
 
581
$enCodeStr=authenticate::enCodeStr($conf);
-
 
582
unset($conf);
180
 
583
 
181
#如果邊數檢查不通過
584
#debug
182
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
585
#var_dump(__LINE__,$enCodeStr);exit;
183
 
586
 
184
	#印出訊息
587
#如果執行異常
185
	echo json_encode($responseMultiInputDataSecurityEnhance);
588
if($enCodeStr["status"]==="false"){
186
 
589
 
-
 
590
	#函式說明:
-
 
591
	#撰寫log
-
 
592
	#回傳結果:
-
 
593
	#$result["status"],狀態,"true"或"false".
-
 
594
	#$result["error"],錯誤訊息陣列.
-
 
595
	#$result["function"],當前函式的名稱.
-
 
596
	#$result["argu"],使用的參數.
-
 
597
	#必填參數:
-
 
598
	#$conf["path"],log檔案的路徑與名稱.
-
 
599
	$conf["path"]=$logFile;
-
 
600
	#$conf["content"],字串,要寫的內容.
-
 
601
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
-
 
602
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
603
	$conf["fileArgu"]=__FILE__;
-
 
604
	#可省略參數:
-
 
605
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
606
	#$conf["rewrite"]="false";
-
 
607
	#參考資料:
-
 
608
	#無.
-
 
609
	#備註:
-
 
610
	#無.	
-
 
611
	$record=logs::record($conf);
-
 
612
	unset($conf);
-
 
613
 
-
 
614
	#如果寫log 失敗
-
 
615
	if($record["status"]==="false"){
-
 
616
 
-
 
617
		#印出訊息
-
 
618
		echo json_encode($record);
-
 
619
		
187
	#結束執行
620
		#異常結束執行
188
	exit;
621
		exit(1);
189
 
622
 
-
 
623
		}#if end
-
 
624
		
-
 
625
	#異常結束執行
-
 
626
	exit(1);
-
 
627
	
190
	}#if end
628
	}#if end
-
 
629
	
-
 
630
#解密參數
-
 
631
#函式說明:
-
 
632
#加密或編碼字串,可以用的方法有sha1,md5,password_sha,qbpwcf,bin2hex,hex2bin,gpg,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
-
 
633
#回傳結果:
-
 
634
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
-
 
635
#$result["function"],當前執行的函數名稱.
-
 
636
#$result["content"],加密後的結果.
-
 
637
#$result["error"],錯誤訊息陣列.
-
 
638
#$result["argu"],使用的參數.
-
 
639
#必填參數:
-
 
640
#$conf["enCodeStr"],any,要加密的字串,陣列,物件.
-
 
641
$conf["enCodeStr"]=$enCodeStr["content"];
-
 
642
#$conf["enCodeType"],"字串",加密或編碼的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"與"bin2hex"與"hex2bin"與"gpg"與"hex2bin&gpg",9種,"sha1"較耗時;"md5"較快;"p_hash"適用於密碼加密;"aes256"是對稱式加解密;"qbpwcf"是透過urlencode、json_encode、base64_encode的結果;"bin2hex"是依照每個byte的整數數值轉成"00"~"FF"後的結果,反之為"hex2bin";"gpg"是應用gpg進行加解密,需要先有ID對應的key;"hex2bin&gpg"為先hex2bin在進行gpg加解密.
-
 
643
$conf["enCodeType"]="qbpwcf";
-
 
644
#可省略參數:
-
 
645
#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
-
 
646
#$conf["sha1Raw"]="false";
-
 
647
#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
-
 
648
#$conf["p_hash"]="";
-
 
649
#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
-
 
650
#$conf["keyForAes256"]="";
-
 
651
#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
-
 
652
#$conf["aes256Encode"]="";
-
 
653
#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
-
 
654
$conf["qbpwcfDecode"]="true";
-
 
655
#$conf["gpgDecrypt"],字串,若"enCodeType"為"gpg",則預設為"false",代表加密;反之為"true",代表解密.
-
 
656
#$conf["gpgDecrypt"]="true";
-
 
657
#$conf["gpgId"],字串,若"enCodeType"為"gpg"時,要使用的gpg id,預設為gnupgId.
-
 
658
#$conf["gpgId"]="";
-
 
659
#參考資料:
-
 
660
#sha1=>http://php.net/manual/en/function.sha1.php
-
 
661
#md5=>http://php.net/manual/en/function.md5.php
-
 
662
#password_hash=>http://php.net/manual/en/function.password-hash.php
-
 
663
#password_verify=>http://php.net/manual/en/function.password-verify.php
-
 
664
#json_decode=>https://www.php.net/manual/en/function.json-decode.php
-
 
665
#備註:
-
 
666
#無.
-
 
667
$enCodeStr=authenticate::enCodeStr($conf);
-
 
668
unset($conf);
191
 
669
 
192
#取得參數
670
#debug
193
$params=$responseMultiInputDataSecurityEnhance["inputDataContent"]["params"];
671
#var_dump(__LINE__,$enCodeStr);exit;
194
 
672
 
-
 
673
#如果執行異常
-
 
674
if($enCodeStr["status"]==="false"){
-
 
675
 
-
 
676
	#函式說明:
-
 
677
	#撰寫log
-
 
678
	#回傳結果:
-
 
679
	#$result["status"],狀態,"true"或"false".
-
 
680
	#$result["error"],錯誤訊息陣列.
-
 
681
	#$result["function"],當前函式的名稱.
-
 
682
	#$result["argu"],使用的參數.
195
#解析變數
683
	#必填參數:
-
 
684
	#$conf["path"],log檔案的路徑與名稱.
-
 
685
	$conf["path"]=$logFile;
-
 
686
	#$conf["content"],字串,要寫的內容.
196
$params=json_decode(urldecode(base64_decode($params)));
687
	$conf["content"]=json_encode($enCodeStr).PHP_EOL;
-
 
688
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
689
	$conf["fileArgu"]=__FILE__;
-
 
690
	#可省略參數:
-
 
691
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
692
	#$conf["rewrite"]="false";
-
 
693
	#參考資料:
-
 
694
	#無.
-
 
695
	#備註:
-
 
696
	#無.	
-
 
697
	$record=logs::record($conf);
-
 
698
	unset($conf);
-
 
699
 
-
 
700
	#如果寫log 失敗
-
 
701
	if($record["status"]==="false"){
-
 
702
 
-
 
703
		#印出訊息
-
 
704
		echo json_encode($record);
-
 
705
		
-
 
706
		#異常結束執行
-
 
707
		exit(1);
-
 
708
 
-
 
709
		}#if end
-
 
710
		
-
 
711
	#異常結束執行
-
 
712
	exit(1);
-
 
713
	
-
 
714
	}#if end
-
 
715
 
-
 
716
#取得解碼後的結果
-
 
717
$params=$enCodeStr["content"];
197
 
718
 
198
#轉換為陣列
719
#轉換為陣列
199
$params=(array)$params;
720
$params=(array)$params;
200
 
721
 
201
#函式說明:
722
#函式說明:
Line 245... Line 766...
245
else{
766
else{
246
 
767
 
247
	#若dbSecret錯誤
768
	#若dbSecret錯誤
248
	if($params["dbSecret"]!==dbSecret){
769
	if($params["dbSecret"]!==dbSecret){
249
	
770
	
-
 
771
		#函式說明:
-
 
772
		#撰寫log
-
 
773
		#回傳結果:
-
 
774
		#$result["status"],狀態,"true"或"false".
-
 
775
		#$result["error"],錯誤訊息陣列.
-
 
776
		#$result["function"],當前函式的名稱.
-
 
777
		#$result["argu"],使用的參數.
-
 
778
		#必填參數:
-
 
779
		#$conf["path"],log檔案的路徑與名稱.
-
 
780
		$conf["path"]=$logFile;
-
 
781
		#$conf["content"],字串,要寫的內容.
-
 
782
		$conf["content"]="wrong dbSecret".PHP_EOL;
-
 
783
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
784
		$conf["fileArgu"]=__FILE__;
-
 
785
		#可省略參數:
-
 
786
		#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
787
		#$conf["rewrite"]="false";
-
 
788
		#參考資料:
-
 
789
		#無.
-
 
790
		#備註:
-
 
791
		#無.	
-
 
792
		$record=logs::record($conf);
-
 
793
		unset($conf);
-
 
794
 
-
 
795
		#如果寫log 失敗
-
 
796
		if($record["status"]==="false"){
-
 
797
 
-
 
798
			#印出訊息
-
 
799
			echo json_encode($record);
-
 
800
			
-
 
801
			#異常結束執行
-
 
802
			exit(1);
-
 
803
 
-
 
804
			}#if end
-
 
805
	
250
		#結束執行
806
		#結束執行
251
		exit;
807
		exit;
252
	
808
	
253
		}#if end
809
		}#if end
254
	
810
	
Line 362... Line 918...
362
	#結束執行
918
	#結束執行
363
	exit;
919
	exit;
364
 
920
 
365
	}#if end
921
	}#if end
366
 
922
 
-
 
923
/*
367
#取得資料庫連線參數
924
#可能存在的參數
368
$params["dbAddr"];
925
$params["dbAddr"];
369
$params["dbPort"];#預設為3306
926
$params["dbPort"];
370
$params["dbName"];
927
$params["dbName"];
371
$params["dbUser"];
928
$params["dbUser"];
372
$params["dbPass"];
929
$params["dbPass"];
373
$params["dtName"];
930
$params["dtName"];
374
$params["cols"];#要更新的欄位
931
$params["cols"];#要更新的欄位
375
$params["vals"];#要更新的欄位數值
932
$params["vals"];#要更新的欄位數值
376
$params["wcols"];#條件欄位
933
$params["wcols"];#條件欄位
377
$params["wvals"];#條件欄位對應數值
934
$params["wvals"];#條件欄位對應數值
-
 
935
*/
378
 
936
 
379
#函式說明:
937
#函式說明:
380
#更新資料表裏面的資料
938
#更新資料表裏面的資料
381
#回傳的結果:
939
#回傳的結果:
382
#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
940
#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
Line 408... Line 966...
408
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
966
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
409
$conf["dbPort"]=$params["dbPort"];
967
$conf["dbPort"]=$params["dbPort"];
410
$updateDataTableContent=db::updateDataTableContent($conf);
968
$updateDataTableContent=db::updateDataTableContent($conf);
411
unset($conf);
969
unset($conf);
412
 
970
 
-
 
971
#如果執行異常
-
 
972
if($updateDataTableContent["status"]==="false"){
-
 
973
 
-
 
974
	#函式說明:
-
 
975
	#撰寫log
-
 
976
	#回傳結果:
-
 
977
	#$result["status"],狀態,"true"或"false".
-
 
978
	#$result["error"],錯誤訊息陣列.
-
 
979
	#$result["function"],當前函式的名稱.
-
 
980
	#$result["argu"],使用的參數.
-
 
981
	#必填參數:
-
 
982
	#$conf["path"],log檔案的路徑與名稱.
-
 
983
	$conf["path"]=$logFile;
-
 
984
	#$conf["content"],字串,要寫的內容.
-
 
985
	$conf["content"]=json_encode($updateDataTableContent).PHP_EOL;
-
 
986
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
987
	$conf["fileArgu"]=__FILE__;
-
 
988
	#可省略參數:
-
 
989
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
-
 
990
	#$conf["rewrite"]="false";
-
 
991
	#參考資料:
-
 
992
	#無.
-
 
993
	#備註:
-
 
994
	#無.	
-
 
995
	$record=logs::record($conf);
-
 
996
	unset($conf);
-
 
997
 
-
 
998
	#如果寫log 失敗
-
 
999
	if($record["status"]==="false"){
-
 
1000
 
-
 
1001
		#印出訊息
-
 
1002
		echo json_encode($record);
-
 
1003
		
-
 
1004
		#異常結束執行
-
 
1005
		exit(1);
-
 
1006
 
-
 
1007
		}#if end
-
 
1008
		
-
 
1009
	#異常結束執行
-
 
1010
	exit(1);
-
 
1011
 
-
 
1012
	}#if end
-
 
1013
 
413
#函式說明:
1014
#函式說明:
414
#撰寫log
1015
#撰寫log
415
#回傳結果:
1016
#回傳結果:
416
#$result["status"],狀態,"true"或"false".
1017
#$result["status"],狀態,"true"或"false".
417
#$result["error"],錯誤訊息陣列.
1018
#$result["error"],錯誤訊息陣列.