Subversion Repositories php-qbpwcf

Rev

Rev 226 | Go to most recent revision | Details | 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.
6
    Copyright (C) 2015~2025 Min-Jhin,Chen
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
類別說明:
28
提供類似cronjob服務的類別.
29
備註:
30
無.
31
*/
32
class autoService{
33
 
34
	/*
35
	#函式說明:
36
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
37
	#回傳結果:
38
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
39
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
40
	#$result["function"],當前執行的函式名稱.
41
	#必填參數:
42
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
43
	#$arguments,陣列,為呼叫方法時所用的參數.
44
	#參考資料:
45
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
46
	*/
47
	public function __call($method,$arguments){
48
 
49
		#取得當前執行的函式
50
		$result["function"]=__FUNCTION__;
51
 
52
		#設置執行不正常
53
		$result["status"]="false";
54
 
55
		#設置執行錯誤
56
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
57
 
58
		#設置所丟入的參數
59
		$result["error"][]=$arguments;
60
 
61
		#回傳結果
62
		return $result;
63
 
64
		}#function __call end
65
 
66
	/*
67
	#函式說明:
68
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
69
	#回傳結果:
70
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
71
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
72
	#$result["function"],當前執行的函式名稱.
73
	#必填參數:
74
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
75
	#$arguments,陣列,為呼叫方法時所用的參數.
76
	#參考資料:
77
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
78
	*/
79
	public static function __callStatic($method,$arguments){
80
 
81
		#取得當前執行的函式
82
		$result["function"]=__FUNCTION__;
83
 
84
		#設置執行不正常
85
		$result["status"]="false";
86
 
87
		#設置執行錯誤
88
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
89
 
90
		#設置所丟入的參數
91
		$result["error"][]=$arguments;
92
 
93
		#回傳結果
94
		return $result;
95
 
96
		}#function __callStatic end
97
 
98
	/*
99
	#函式說明:
100
	#新增或覆蓋系統上有哪些要自動執行的工作.
101
	#回傳結果:
102
	#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
103
	#$result["error"],錯誤訊息陣列.
104
	#$result["function"],當前執行的函式名稱.
105
	#$result["content"],當前排程資訊內容.
106
	#$result["argu"],使用的參數.
107
	#必填參數:
108
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
109
	$conf["fileArgu"]=__FILE__;
110
	#$conf["actions"],字串陣列,每個元素代表要執行的事情,每個事情為要執行的指令與參數所組成的一維陣列.
111
	$conf["actions"]=array();
112
	#$conf["times"],字串陣列,每個元素代表要執行事情的時間點,單為為秒.格式為UTC時區的「年年年年-月月-日日 時 時:分分:秒秒」格式,事情不存在於啟動的狀態且當前時間大於等於之就會執行.
113
	$conf["times"]=array();
114
	#$conf["repeat"],字串陣列,每個元素為一維陣列,代表要執行事情的重複方式.key為"times"代表剩下幾次可以執行,其value為"N"代表剩下N次(若N等於-1,則代表無限重複執行;若N等於0,則代表不用執行);key為"after"代表下次執行的時間為times+加其value;key為"fixed"代表下次執行的時間為一個循環的固定時間點,value為每次循環的固定時間點,例如每天01:05則為 yearOfTimes-monthOfTimes-dayOfTimes 01:05:SeccondOfTimes.
115
	$conf["repeat"]=array();
116
	#可省略參數:
117
	#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
118
	#$conf["config"]="";
119
	#$conf["uuids"],字串陣列,每個排程的uuid,若不指定則會自動產生,若跟既有action的uuid相同,則會覆蓋其相關資訊.
120
	#$conf["uuids"]=array();
121
	#參考資料:
122
	#無.
123
	#備註:
124
	#無.
125
	*/
126
	public static function createList(&$conf){
127
 
128
		#初始化要回傳的變數
129
		$result=array();
130
 
131
		#初始化當前執行的函數名稱
132
		$result["function"]=__FUNCTION__;
133
 
134
		#如果 $conf 不為陣列
135
		if(gettype($conf)!="array"){
136
 
137
			#設置執行失敗
138
			$result["status"]="false";
139
 
140
			#設置執行錯誤訊息
141
			$result["error"][]="\$conf變數須為陣列形態";
142
 
143
			#如果傳入的參數為 null
144
			if($conf==null){
145
 
146
				#設置執行錯誤訊息
147
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
148
 
149
				}#if end
150
 
151
			#回傳結果
152
			return $result;
153
 
154
			}#if end
155
 
156
		#取得使用的參數
157
		$result["argu"]=$conf;
158
 
159
		#函式說明:
160
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
161
		#回傳結果:
162
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
163
		#$result["error"],執行不正常結束的錯訊息陣列.
164
		#$result["simpleError"],簡單表示的錯誤訊息.
165
		#$result["function"],當前執行的函式名稱.
166
		#$result["argu"],設置給予的參數.
167
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
168
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
169
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
170
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
171
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
172
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
173
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
174
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
175
		#必填參數:
176
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
177
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
178
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
179
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
180
		#可省略參數:
181
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
182
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","actions","times","repeat");
183
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
184
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array","array","array");
185
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
186
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
187
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
188
		#$conf["canNotBeEmpty"]=array();
189
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
190
		#$conf["canBeEmpty"]=array();
191
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
192
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("config");
193
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
194
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config","uuids");
195
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
196
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array");
197
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
198
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php",null);
199
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
200
		#$conf["disallowAllSkipableVarIsEmpty"]="";
201
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
202
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
203
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
204
		#$conf["disallowAllSkipableVarNotExist"]="";
205
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
206
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");
207
		#參考資料:
208
		#array_keys=>http://php.net/manual/en/function.array-keys.php
209
		#備註:
210
		#無.
211
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
212
		unset($conf["variableCheck::checkArguments"]);
213
 
214
		#如果 $checkArguments["status"] 等於 "false"
215
		if($checkArguments["status"]==="false"){
216
 
217
			#設置錯誤識別
218
			$result["status"]="false";
219
 
220
			#設置錯誤訊息
221
			$result["error"]=$checkArguments;
222
 
223
			#回傳結果
224
			return $result;				
225
 
226
			}#if end
227
 
228
		#如果 $checkArguments["passed"] 等於 "false"
229
		if($checkArguments["passed"]==="false"){
230
 
231
			#設置錯誤識別
232
			$result["status"]="false";
233
 
234
			#設置錯誤訊息
235
			$result["error"]=$checkArguments;
236
 
237
			#回傳結果
238
			return $result;
239
 
240
			}#if end
241
 
242
		#檢查每個 time 的格式
243
		foreach($conf["times"] as $time){
244
 
245
			#函式說明:
246
			#檢查字串是否符合 RFC 3339/ISO-8601 格式
247
			#回傳結果:
248
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
249
			#$result["passed"],檢查是否通過,"true"代表通過,"false"代表不通過.
250
			#$result["argu"],使用的參數.
251
			#$result["function"],當前執行的函數.
252
			#$result["error"],涵式錯誤訊息陣列.
253
			#必填參數:
254
			#$conf["input"],字串,要檢查格式的字串.
255
			$conf["variableCheck::checkRFC3339"]["input"]=$time;
256
			#可省略參數:
257
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"true",代表要;反之為"false".
258
			#$conf["variableCheck::checkRFC3339"]["UTC"]="false";
259
			#參考資料:
260
			#ISO 8601-2:2019=>https://www.rfc-editor.org/info/rfc3339
261
			#rfc3339=>https://www.rfc-editor.org/rfc/rfc3339
262
			#備註:
263
			#無.
264
			$checkRFC3339=variableCheck::checkRFC3339($conf["variableCheck::checkRFC3339"]);
265
			unset($conf["variableCheck::checkRFC3339"]);
266
 
267
			#如果執行出錯
268
			if($checkRFC3339["status"]==="false"){
269
 
270
				#設置錯誤識別
271
				$result["status"]="false";
272
 
273
				#設置錯誤訊息
274
				$result["error"]=$checkRFC3339;
275
 
276
				#回傳結果
277
				return $result;
278
 
279
				}#if end
280
 
281
			#如果檢查不通過
282
			if($checkRFC3339["passed"]==="false"){
283
 
284
				#設置錯誤識別
285
				$result["status"]="false";
286
 
287
				#設置錯誤訊息
288
				$result["error"]=$checkRFC3339;
289
 
290
				#回傳結果
291
				return $result;
292
 
293
				}#if end
294
 
295
			}#foreach end
296
 
297
		#取得uuid的數量應該要多少
298
		$uuidCount=count($conf["actions"]);
299
 
300
		#如果沒有指定 uuids
301
		if(!isset($conf["uuids"])){
302
 
303
			#初始化 uuids
304
			$conf["uuids"]=array();
305
 
306
			#產生對應數量的uuid
307
			for($i=0;$i<$uuidCount;$i++){
308
 
309
				#函式說明:
310
				#使用 linux 的 uuid 指令來產生 uuid 字串
311
				#回傳結果:
312
				#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
313
				#$result["error"],錯誤訊息.
314
				#$result["function"],當前執行的函式名稱.
315
				#必填參數:
316
				#無.
317
				#可省略參數:
318
				#無.
319
				#參考資料:
320
				#無.
321
				#備註:
322
				#無.
323
				$uuid=cmd::uuid();
324
 
325
				#如果執行失敗
326
				if($uuid["status"]==="false"){
327
 
328
					#設置錯誤識別
329
					$result["status"]="false";
330
 
331
					#設置錯誤訊息
332
					$result["error"]=$uuid;
333
 
334
					#回傳結果
335
					return $result;	
336
 
337
					}#if end
338
 
339
				#儲存新的uuid
340
				$conf["uuids"][]=$uuid["content"];
341
 
342
				}#for end
343
 
344
			}#if end
345
 
346
		#讀取既有排程設定檔
347
		#函式說明:
348
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
349
		#回傳的變數說明:
350
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
351
		#$result["error"],錯誤訊息提示.
352
		#$result["warning"],警告訊息.
353
		#$result["function"],當前執行的函數名稱.
354
		#$result["fileContent"],爲檔案的內容陣列.
355
		#$result["lineCount"],爲檔案內容總共的行數.
356
		#$result["fullContent"],為檔案的完整內容.
357
		#$result["base64data"],為檔案的base64內容.
358
		#$result["mimeType"],為檔案的mime type.
359
		#必填參數:
360
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
361
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["config"];
362
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
363
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
364
		#可省略參數:
365
		#$conf["web"],是要取得網路上的檔案則為"true";反之預設為"false".
366
		#$conf["web"]="true";
367
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
368
		$conf["fileAccess::getFileContent"]["createIfnotExist"]="true";
369
		#參考資料:
370
		#file(),取得檔案內容的行數.
371
		#file=>http:#php.net/manual/en/function.file.php
372
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
373
		#filesize=>http://php.net/manual/en/function.filesize.php
374
		#參考資料:
375
		#無.
376
		#備註:
377
		#無.
378
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
379
		unset($conf["fileAccess::getFileContent"]);
380
 
381
		#如果執行失敗
382
		if($getFileContent["status"]=="false"){
383
 
384
			#設置錯誤識別
385
			$result["status"]="false";
386
 
387
			#設置錯誤訊息
388
			$result["error"]=$getFileContent;
389
 
390
			#回傳結果
391
			return $result;	
392
 
393
			}#if end
394
 
395
		#初始化原始設定擋內容
396
		$oriConfig=array();
397
 
398
		#針對每行內容
399
		foreach($getFileContent["fileContent"] as $lineNo=>$line){
400
 
401
			#解析內容
402
			#函式說明:
403
			#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
404
			#回傳結果:
405
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
406
			#$result["function"],當前執行的函數名稱.
407
			#$result["content"],加密後的結果.
408
			#$result["error"],錯誤訊息陣列.
409
			#$result["argu"],使用的參數.
410
			#必填參數:
411
			#$conf["enCodeStr"],"字串",要加密的字串.
412
			$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;
413
			#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
414
			$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";
415
			#可省略參數:
416
			#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
417
			#$conf["sha1Raw"]="false";
418
			#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
419
			#$conf["p_hash"]="";
420
			#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
421
			#$conf["keyForAes256"]="";
422
			#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
423
			#$conf["aes256Encode"]="";
424
			#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
425
			$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";
426
			#參考資料:
427
			#sha1=>http://php.net/manual/en/function.sha1.php
428
			#md5=>http://php.net/manual/en/function.md5.php
429
			#password_hash=>http://php.net/manual/en/function.password-hash.php
430
			#password_verify=>http://php.net/manual/en/function.password-verify.php
431
			#json_decode=>https://www.php.net/manual/en/function.json-decode.php
432
			#備註:
433
			#無.
434
			$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
435
			unset($conf["authenticate::enCodeStr"]);
436
 
437
			#如果執行失敗
438
			if($enCodeStr["status"]==="false"){
439
 
440
				#設置錯誤識別
441
				$result["status"]="false";
442
 
443
				#設置錯誤訊息
444
				$result["error"]=$enCodeStr;
445
 
446
				#回傳結果
447
				return $result;	
448
 
449
				}#if end
450
 
451
			#解碼後的內容
452
			$oriConfig[]=$enCodeStr["content"];
453
 
454
			}#foreach end
455
 
456
		#針對每個要新增的排程
457
		foreach($conf["actions"] as $index => $action){
458
 
459
			#針對每個既有的排程
460
			foreach($oriConfig as $indexFor_oriConfig => $oCfg){
461
 
462
				#針對既有排程的uuid
463
				$ouuid=$oCfg->uuid;
464
 
465
				#函式說明:
466
				#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
467
				#回傳結果:
468
				#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
469
				#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
470
				#$result["error"],錯誤訊息
471
				#$result["function"],當前執行的函數名稱
472
				#$result["argv"],使用的參數
473
				#$result["equalVarName"],相等的變數名稱或key.
474
				#$result["equalVarValue"],相等的變數數值內容.
475
				#必填參數:
476
				#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
477
				$conf["search::getEqualVar"]["conditionElement"]=$ouuid;
478
				#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
479
				$conf["search::getEqualVar"]["compareElements"]=$conf["uuids"];
480
				#可省略參數:
481
				#無.
482
				#參考資料:
483
				#無.
484
				#備註:
485
				#無.
486
				$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
487
				unset($conf["search::getEqualVar"]);
488
 
489
				#如果執行失敗
490
				if($getEqualVar["status"]==="false"){
491
 
492
					#設置錯誤識別
493
					$result["status"]="false";
494
 
495
					#設置錯誤訊息
496
					$result["error"]=$getEqualVar;
497
 
498
					#回傳結果
499
					return $result;	
500
 
501
					}#if end
502
 
503
				#如果有找到相同uuid
504
				if($getEqualVar["founded"]==="true"){
505
 
506
					#移除舊排程
507
					unset($oriConfig[$indexFor_oriConfig]);
508
 
509
					#換看下個新排程的uuid
510
					break;
511
 
512
					}#if end
513
 
514
				}#foreach end
515
 
516
			}#foreach end
517
 
518
		#初始化儲存未加密的排程資訊
519
		$rawScheduleInfo=$oriConfig;
520
 
521
		#將剩下的每個舊排程
522
		foreach($oriConfig as $index => $config){
523
 
524
			#加密內容
525
			#函式說明:
526
			#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
527
			#回傳結果:
528
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
529
			#$result["function"],當前執行的函數名稱.
530
			#$result["content"],加密後的結果.
531
			#$result["error"],錯誤訊息陣列.
532
			#$result["argu"],使用的參數.
533
			#必填參數:
534
			#$conf["enCodeStr"],"字串",要加密的字串.
535
			$conf["authenticate::enCodeStr"]["enCodeStr"]=$config;
536
			#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
537
			$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";
538
			#可省略參數:
539
			#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
540
			#$conf["sha1Raw"]="false";
541
			#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
542
			#$conf["p_hash"]="";
543
			#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
544
			#$conf["keyForAes256"]="";
545
			#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
546
			#$conf["aes256Encode"]="";
547
			#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
548
			#$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";
549
			#參考資料:
550
			#sha1=>http://php.net/manual/en/function.sha1.php
551
			#md5=>http://php.net/manual/en/function.md5.php
552
			#password_hash=>http://php.net/manual/en/function.password-hash.php
553
			#password_verify=>http://php.net/manual/en/function.password-verify.php
554
			#json_decode=>https://www.php.net/manual/en/function.json-decode.php
555
			#備註:
556
			#無.
557
			$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
558
			unset($conf["authenticate::enCodeStr"]);
559
 
560
			#如果執行失敗
561
			if($enCodeStr["status"]==="false"){
562
 
563
				#設置錯誤識別
564
				$result["status"]="false";
565
 
566
				#設置錯誤訊息
567
				$result["error"]=$enCodeStr;
568
 
569
				#回傳結果
570
				return $result;	
571
 
572
				}#if end
573
 
574
			#取得加密後的內容
575
			$newConfig[]=$enCodeStr["content"];
576
 
577
			}#foreach end
578
 
579
		#針對每個要新增的排程
580
		foreach($conf["actions"] as $index => $action){
581
 
582
			#取得該uuid
583
			$uuid=$conf["uuids"][$index];
584
 
585
			#取得該time
586
			$time=$conf["times"][$index];
587
 
588
			#函式說明:
589
			#計算時間點距離1970/01/01多少秒,亦即unixtime.
590
			#回傳結果:
591
			#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
592
			#$result["error"],錯誤訊息陣列.
593
			#$result["content"],時間點距離1970/01/01的多少秒.
594
			#$result["argu"],使用的參數.
595
			#$result["unixtime"],執行本函式時的unixtime.
596
			#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
597
			#必填參數:
598
			#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
599
			$conf["time::caculateTimeAmount"]["dateAndTime"]=$time;
600
			#可省略參數:
601
			#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
602
			$conf["time::caculateTimeAmount"]["UTC"]="true";
603
			#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
604
			#$conf["replace0"]="true";
605
			#參考資料:
606
			#無.
607
			#備註:
608
			#無.
609
			$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
610
			unset($conf["time::caculateTimeAmount"]);
611
 
612
			#如果執行失敗
613
			if($caculateTimeAmount["status"]==="false"){
614
 
615
				#設置錯誤識別
616
				$result["status"]="false";
617
 
618
				#設置錯誤訊息
619
				$result["error"]=$caculateTimeAmount;
620
 
621
				#回傳結果
622
				return $result;	
623
 
624
				}#if end
625
 
626
			#轉換成unixtime
627
			$time=$caculateTimeAmount["content"];
628
 
629
			#取得新增/覆蓋排程設定時的unixtime
630
			$lastUpdateUnixTime=$time;
631
 
632
			#取代該repeat
633
			$repeat=$conf["repeat"][$index];
634
 
635
			#如果有指定固定時間執行
636
			if(isset($repeat["fixed"])){
637
 
638
				#函式說明:
639
				#計算時間點距離1970/01/01多少秒,亦即unixtime.
640
				#回傳結果:
641
				#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
642
				#$result["error"],錯誤訊息陣列.
643
				#$result["content"],時間點距離1970/01/01的多少秒.
644
				#$result["argu"],使用的參數.
645
				#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.
646
				#必填參數:
647
				#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
648
				$conf["time::caculateTimeAmount"]["dateAndTime"]=$repeat["fixed"];
649
				#可省略參數:
650
				#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
651
				$conf["time::caculateTimeAmount"]["UTC"]="true";
652
				#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
653
				#$conf["replace0"]="true";
654
				#參考資料:
655
				#無.
656
				#備註:
657
				#無.
658
				$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
659
				unset($conf["time::caculateTimeAmount"]);
660
 
661
				#如果執行失敗
662
				if($caculateTimeAmount["status"]==="false"){
663
 
664
					#設置錯誤識別
665
					$result["status"]="false";
666
 
667
					#設置錯誤訊息
668
					$result["error"]=$caculateTimeAmount;
669
 
670
					#回傳結果
671
					return $result;	
672
 
673
					}#if end
674
 
675
				#更新時間為unixtime
676
				$repeat["fixed"]=$caculateTimeAmount["content"];
677
 
678
				}#if end
679
 
680
			#要加密的排程資訊,uuid(排程的識別碼),time(預計要執行的時間),repeat(重複的方式),update(新增/覆蓋排程設定時的unixtime)
681
			$scheduleInfo=array("uuid"=>$uuid,"action"=>$action,"time"=>$time,"repeat"=>$repeat,"update"=>$time);
682
 
683
			#儲存未加密的排程資訊
684
			$rawScheduleInfo[]=$scheduleInfo;
685
 
686
			#加密內容
687
			#函式說明:
688
			#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
689
			#回傳結果:
690
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
691
			#$result["function"],當前執行的函數名稱.
692
			#$result["content"],加密後的結果.
693
			#$result["error"],錯誤訊息陣列.
694
			#$result["argu"],使用的參數.
695
			#必填參數:
696
			#$conf["enCodeStr"],"字串",要加密的字串.
697
			$conf["authenticate::enCodeStr"]["enCodeStr"]=$scheduleInfo;
698
			#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
699
			$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";
700
			#可省略參數:
701
			#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
702
			#$conf["sha1Raw"]="false";
703
			#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
704
			#$conf["p_hash"]="";
705
			#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
706
			#$conf["keyForAes256"]="";
707
			#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
708
			#$conf["aes256Encode"]="";
709
			#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
710
			#$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";
711
			#參考資料:
712
			#sha1=>http://php.net/manual/en/function.sha1.php
713
			#md5=>http://php.net/manual/en/function.md5.php
714
			#password_hash=>http://php.net/manual/en/function.password-hash.php
715
			#password_verify=>http://php.net/manual/en/function.password-verify.php
716
			#json_decode=>https://www.php.net/manual/en/function.json-decode.php
717
			#備註:
718
			#無.
719
			$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
720
			unset($conf["authenticate::enCodeStr"]);
721
 
722
			#如果執行失敗
723
			if($enCodeStr["status"]==="false"){
724
 
725
				#設置錯誤識別
726
				$result["status"]="false";
727
 
728
				#設置錯誤訊息
729
				$result["error"]=$enCodeStr;
730
 
731
				#回傳結果
732
				return $result;	
733
 
734
				}#if end
735
 
736
			#取得加密後的內容
737
			$newConfig[]=$enCodeStr["content"];
738
 
739
			}#foreach end
740
 
741
		#更新排程設定檔 
742
		#函式說明:
743
		#將多行字串寫入到檔案
744
		#回傳結果:
745
		#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
746
		#$result["error"],錯誤訊息陣列.
747
		#$result["function"],當前執行函數的名稱.
748
		#必填參數:
749
		#$conf["fileName"],字串,爲要編輯的檔案名稱
750
		$conf["fileAccess::writeMultiLine"]["fileName"]=$conf["config"];
751
		#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
752
		$conf["fileAccess::writeMultiLine"]["inputString"]=$newConfig;
753
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
754
		$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
755
		#可省略參數:
756
		#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
757
		#$conf["fileAccess::writeMultiLine"]["writeMethod"]="a";
758
		#參考資料:
759
		#無.
760
		#備註:
761
		#無.
762
		$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
763
		unset($conf["fileAccess::writeMultiLine"]);
764
 
765
		#如果執行失敗
766
		if($writeMultiLine["status"]=="false"){
767
 
768
			#設置錯誤識別
769
			$result["status"]="false";
770
 
771
			#設置錯誤訊息
772
			$result["error"]=$writeMultiLine;
773
 
774
			#回傳結果
775
			return $result;
776
 
777
			}#if end
778
 
779
		#設置當前排程結果資訊
780
		$result["content"]=$rawScheduleInfo;
781
 
782
		#設置執行正常
783
		$result["status"]="true";
784
 
785
		return $result;
786
 
787
		}#function createList end
788
 
789
	/*
790
	#函式說明:
791
	#查詢系統上有哪些要自動執行的工作
792
	#回傳結果:
793
	#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
794
	#$result["error"],錯誤訊息陣列.
795
	#$result["content"],回傳的結果,排程的工作資訊陣列,每個元素的key有"uuid"跟"cmd&argu",前者為用於執行完畢時回報的排程項目識別;後者為該排程事項的指令與參數.
796
	#$result["function"],當前執行的函式名稱.
797
	必填參數:
798
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
799
	$conf["fileArgu"]=__FILE__;
800
	#可省略參數:
801
	#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
802
	#$conf["config"]="";
803
	#可省略參數:
804
	#無.
805
	#參考資料:
806
	#無.
807
	#備註:
808
	#無.
809
	*/
810
	public static function getList(&$conf){
811
 
812
		#初始化要回傳的變數
813
		$result=array();
814
 
815
		#初始化當前執行的函數名稱
816
		$result["function"]=__FUNCTION__;
817
 
818
		#如果 $conf 不為陣列
819
		if(gettype($conf)!="array"){
820
 
821
			#設置執行失敗
822
			$result["status"]="false";
823
 
824
			#設置執行錯誤訊息
825
			$result["error"][]="\$conf變數須為陣列形態";
826
 
827
			#如果傳入的參數為 null
828
			if($conf==null){
829
 
830
				#設置執行錯誤訊息
831
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
832
 
833
				}#if end
834
 
835
			#回傳結果
836
			return $result;
837
 
838
			}#if end
839
 
840
		#取得使用的參數
841
		$result["argu"]=$conf;
842
 
843
		#檢查參數
844
		#函式說明:
845
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
846
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
847
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
848
		#$result["function"],當前執行的函式名稱.
849
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
850
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
851
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
852
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
853
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
854
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
855
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
856
		#必填寫的參數:
857
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
858
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
859
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
860
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
861
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
862
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
863
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
864
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
865
		#可以省略的參數:
866
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
867
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
868
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
869
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config");
870
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
871
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
872
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
873
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php");
874
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
875
		#$conf["arrayCountEqualCheck"][]=array();
876
		#參考資料來源:
877
		#array_keys=>http://php.net/manual/en/function.array-keys.php
878
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
879
		unset($conf["variableCheck::checkArguments"]);
880
 
881
		#如果 $checkArguments["status"] 等於 "false"
882
		if($checkArguments["status"]=="false"){
883
 
884
			#設置錯誤識別
885
			$result["status"]="false";
886
 
887
			#設置錯誤訊息
888
			$result["error"]=$checkArguments;
889
 
890
			#回傳結果
891
			return $result;
892
 
893
			}#if end
894
 
895
		#如果 $checkArguments["passed"] 等於 "false"
896
		if($checkArguments["passed"]=="false"){
897
 
898
			#設置錯誤識別
899
			$result["status"]="false";
900
 
901
			#設置錯誤訊息
902
			$result["error"]=$checkArguments;
903
 
904
			#回傳結果
905
			return $result;
906
 
907
			}#if end
908
 
909
		#函式說明:
910
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
911
		#回傳的變數說明:
912
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
913
		#$result["error"],錯誤訊息提示.
914
		#$result["warning"],警告訊息.
915
		#$result["function"],當前執行的函數名稱.
916
		#$result["fileContent"],爲檔案的內容陣列.
917
		#$result["lineCount"],爲檔案內容總共的行數.
918
		#$result["fullContent"],為檔案的完整內容.
919
		#$result["base64data"],為檔案的base64內容.
920
		#$result["mimeType"],為檔案的mime type.
921
		#必填的參數:
922
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
923
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["config"];
924
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
925
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
926
		#可省略參數:
927
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
928
		$conf["fileAccess::getFileContent"]["web"]="false";
929
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
930
		$conf["fileAccess::getFileContent"]["createIfnotExist"]="true";
931
		#參考資料:
932
		#file(),取得檔案內容的行數.
933
		#file=>http:#php.net/manual/en/function.file.php
934
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
935
		#filesize=>http://php.net/manual/en/function.filesize.php
936
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
937
		unset($conf["fileAccess::getFileContent"]);
938
 
939
		#如果取得檔案失敗
940
		if($getFileContent["status"]==="false"){
941
 
942
			#設置錯誤識別
943
			$result["status"]="false";
944
 
945
			#設置錯誤訊息
946
			$result["error"]=$getFileContent;
947
 
948
			#回傳結果
949
			return $result;	
950
 
951
			}#if end
952
 
953
		#解析檔案內容
954
 
955
		#針對每行內容
956
		foreach($getFileContent["fileContent"] as $line){
957
 
958
			#加密內容
959
			#函式說明:
960
			#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
961
			#回傳結果:
962
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
963
			#$result["function"],當前執行的函數名稱.
964
			#$result["content"],加密後的結果.
965
			#$result["error"],錯誤訊息陣列.
966
			#$result["argu"],使用的參數.
967
			#必填參數:
968
			#$conf["enCodeStr"],"字串",要加密的字串.
969
			$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;
970
			#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
971
			$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";
972
			#可省略參數:
973
			#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
974
			#$conf["sha1Raw"]="false";
975
			#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
976
			#$conf["p_hash"]="";
977
			#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
978
			#$conf["keyForAes256"]="";
979
			#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
980
			#$conf["aes256Encode"]="";
981
			#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
982
			$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";
983
			#參考資料:
984
			#sha1=>http://php.net/manual/en/function.sha1.php
985
			#md5=>http://php.net/manual/en/function.md5.php
986
			#password_hash=>http://php.net/manual/en/function.password-hash.php
987
			#password_verify=>http://php.net/manual/en/function.password-verify.php
988
			#json_decode=>https://www.php.net/manual/en/function.json-decode.php
989
			#備註:
990
			#無.
991
			$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
992
			unset($conf["authenticate::enCodeStr"]);
993
 
994
			#如果執行失敗失敗
995
			if($enCodeStr["status"]==="false"){
996
 
997
				#設置錯誤識別
998
				$result["status"]="false";
999
 
1000
				#設置錯誤訊息
1001
				$result["error"]=$enCodeStr;
1002
 
1003
				#回傳結果
1004
				return $result;	
1005
 
1006
				}#if end
1007
 
1008
			#取得解密後的內容
1009
			$line=$enCodeStr["content"];
1010
 
1011
			#debug
1012
			#var_dump($line);
1013
 
1014
			#如果內容沒有 uuid
1015
			if(!isset($line->uuid)){
1016
 
1017
				#忽略該行
1018
				continue;
1019
 
1020
				}#if end
1021
 
1022
			#取得排程的uuid
1023
			$actionUuid=&$line->uuid;	
1024
 
1025
			#如果內容沒有 time ,亦即排程設定的(預期/已)執行時間
1026
			if(!isset($line->time)){
1027
 
1028
				#忽略該行
1029
				continue;
1030
 
1031
				}#if end
1032
 
1033
			#取得排程的時間
1034
			$actionUnixTime=&$line->time;	
1035
 
1036
			#如果內容沒有 action ,亦即排程設定的指令與參數.
1037
			if(!isset($line->action)){
1038
 
1039
				#忽略該行
1040
				continue;
1041
 
1042
				}#if end
1043
 
1044
			#取得排程要做的事情資訊
1045
			$actionInfo=&$line->action;
1046
 
1047
			#如果內容沒有 repeat ,亦即排程設定的執行模式.
1048
			if(!isset($line->repeat)){
1049
 
1050
				#忽略該行
1051
				continue;
1052
 
1053
				}#if end
1054
 
1055
			#反之若不是無窮執行
1056
			else if($line->repeat!=="-1"){
1057
 
1058
				#如果內容有 repeat->times ,亦即排程設定的剩下重複次數.
1059
				if(isset($line->repeat->times)){
1060
 
1061
					#取得剩下的重複執行次數
1062
					$leftRepeatTimes=&$line->repeat->times;
1063
 
1064
					}#if end
1065
 
1066
				#反之如果內容沒有 repeat->after(亦即排程設定的重複條件為time的之後多久) 跟 repeat->time->fixed(亦即排程設定的重複條件為用update mask過後的指定時間). 
1067
				else if( !isset($line->repeat->after) && !isset($line->repeat->fixed) ){
1068
 
1069
					#忽略該行
1070
					continue;
1071
 
1072
					}#else end
1073
 
1074
				}#if end
1075
 
1076
			#如果內容沒有 update,亦即排程設定最後更新的時間
1077
			if(!isset($line->update)){
1078
 
1079
				#忽略該行
1080
				continue;
1081
 
1082
				}#if end
1083
 
1084
			#初始化要執行的事情資訊
1085
			$jobInfo=array();
1086
 
1087
			#設置其uuid
1088
			$jobInfo["uuid"]=$actionUuid;
1089
 
1090
			#設置其指令與參數
1091
			$jobInfo["cmd&argu"]=$actionInfo;
1092
 
1093
			#設置其預期執行的unixtime
1094
			$jobInfo["time"]=$actionUnixTime;
1095
 
1096
			#設置其重複規則
1097
			$jobInfo["repeat"]=$line->repeat;
1098
 
1099
			#儲存工作資訊
1100
			$result["content"][]=$jobInfo;
1101
 
1102
			}#foreach end
1103
 
1104
		#設置執行正常
1105
		$result["status"]="true";
1106
 
1107
		#回傳結果
1108
		return $result;
1109
 
1110
		}#function getList end
1111
 
1112
	/*
1113
	#函式說明:
1114
	#查詢系統上有哪些於當下要自動執行的工作
1115
	#回傳結果:
1116
	#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
1117
	#$result["error"],錯誤訊息陣列.
1118
	#$result["content"],回傳的結果,要執行的工作資訊陣列,每個元素的key有"uuid"跟"cmd&argu",前者為用於執行完畢時回報的排程項目識別;後者為該排程事項的指令與參數.
1119
	#$result["function"],當前執行的函式名稱.
1120
	#$result["found"],識別是否有要執行的動作.
1121
	#必填參數:
1122
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1123
	$conf["fileArgu"]=__FILE__;
1124
	#可省略參數:
1125
	#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
1126
	#$conf["config"]="";
1127
	#可省略參數:
1128
	#無.
1129
	#參考資料:
1130
	#無.
1131
	#備註:
1132
	#無.
1133
	*/
1134
	public static function checkList(&$conf){
1135
 
1136
		#初始化要回傳的變數
1137
		$result=array();
1138
 
1139
		#初始化當前執行的函數名稱
1140
		$result["function"]=__FUNCTION__;
1141
 
1142
		#如果 $conf 不為陣列
1143
		if(gettype($conf)!="array"){
1144
 
1145
			#設置執行失敗
1146
			$result["status"]="false";
1147
 
1148
			#設置執行錯誤訊息
1149
			$result["error"][]="\$conf變數須為陣列形態";
1150
 
1151
			#如果傳入的參數為 null
1152
			if($conf==null){
1153
 
1154
				#設置執行錯誤訊息
1155
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1156
 
1157
				}#if end
1158
 
1159
			#回傳結果
1160
			return $result;
1161
 
1162
			}#if end
1163
 
1164
		#取得使用的參數
1165
		$result["argu"]=$conf;
1166
 
1167
		#檢查參數
1168
		#函式說明:
1169
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1170
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1171
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1172
		#$result["function"],當前執行的函式名稱.
1173
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1174
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1175
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1176
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1177
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1178
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1179
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1180
		#必填寫的參數:
1181
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1182
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1183
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1184
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
1185
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
1186
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
1187
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1188
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1189
		#可以省略的參數:
1190
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1191
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1192
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1193
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config");
1194
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
1195
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
1196
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1197
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php");
1198
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1199
		#$conf["arrayCountEqualCheck"][]=array();
1200
		#參考資料來源:
1201
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1202
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1203
		unset($conf["variableCheck::checkArguments"]);
1204
 
1205
		#如果 $checkArguments["status"] 等於 "false"
1206
		if($checkArguments["status"]=="false"){
1207
 
1208
			#設置錯誤識別
1209
			$result["status"]="false";
1210
 
1211
			#設置錯誤訊息
1212
			$result["error"]=$checkArguments;
1213
 
1214
			#回傳結果
1215
			return $result;				
1216
 
1217
			}#if end
1218
 
1219
		#如果 $checkArguments["passed"] 等於 "false"
1220
		if($checkArguments["passed"]=="false"){
1221
 
1222
			#設置錯誤識別
1223
			$result["status"]="false";
1224
 
1225
			#設置錯誤訊息
1226
			$result["error"]=$checkArguments;
1227
 
1228
			#回傳結果
1229
			return $result;				
1230
 
1231
			}#if end
1232
 
1233
		#函式說明:
1234
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
1235
		#回傳的變數說明:
1236
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
1237
		#$result["error"],錯誤訊息提示.
1238
		#$result["warning"],警告訊息.
1239
		#$result["function"],當前執行的函數名稱.
1240
		#$result["fileContent"],爲檔案的內容陣列.
1241
		#$result["lineCount"],爲檔案內容總共的行數.
1242
		#$result["fullContent"],為檔案的完整內容.
1243
		#$result["base64data"],為檔案的base64內容.
1244
		#$result["mimeType"],為檔案的mime type.
1245
		#必填的參數:
1246
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
1247
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["config"];
1248
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1249
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
1250
		#可省略參數:
1251
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
1252
		$conf["fileAccess::getFileContent"]["web"]="false";
1253
		#$conf["createIfnotExist"],字串,預設為"false"代表檔案不存在也不需要建立;反之為"true".
1254
		$conf["fileAccess::getFileContent"]["createIfnotExist"]="true";
1255
		#參考資料:
1256
		#file(),取得檔案內容的行數.
1257
		#file=>http:#php.net/manual/en/function.file.php
1258
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
1259
		#filesize=>http://php.net/manual/en/function.filesize.php
1260
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
1261
		unset($conf["fileAccess::getFileContent"]);
1262
 
1263
		#如果取得檔案失敗
1264
		if($getFileContent["status"]==="false"){
1265
 
1266
			#設置錯誤識別
1267
			$result["status"]="false";
1268
 
1269
			#設置錯誤訊息
1270
			$result["error"]=$getFileContent;
1271
 
1272
			#回傳結果
1273
			return $result;	
1274
 
1275
			}#if end
1276
 
1277
		#解析檔案內容
1278
 
1279
		#針對每行內容
1280
		foreach($getFileContent["fileContent"] as $line){
1281
 
1282
			#加密內容
1283
			#函式說明:
1284
			#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
1285
			#回傳結果:
1286
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
1287
			#$result["function"],當前執行的函數名稱.
1288
			#$result["content"],加密後的結果.
1289
			#$result["error"],錯誤訊息陣列.
1290
			#$result["argu"],使用的參數.
1291
			#必填參數:
1292
			#$conf["enCodeStr"],"字串",要加密的字串.
1293
			$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;
1294
			#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
1295
			$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";
1296
			#可省略參數:
1297
			#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
1298
			#$conf["sha1Raw"]="false";
1299
			#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
1300
			#$conf["p_hash"]="";
1301
			#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
1302
			#$conf["keyForAes256"]="";
1303
			#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
1304
			#$conf["aes256Encode"]="";
1305
			#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
1306
			$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";
1307
			#參考資料:
1308
			#sha1=>http://php.net/manual/en/function.sha1.php
1309
			#md5=>http://php.net/manual/en/function.md5.php
1310
			#password_hash=>http://php.net/manual/en/function.password-hash.php
1311
			#password_verify=>http://php.net/manual/en/function.password-verify.php
1312
			#json_decode=>https://www.php.net/manual/en/function.json-decode.php
1313
			#備註:
1314
			#無.
1315
			$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
1316
			unset($conf["authenticate::enCodeStr"]);
1317
 
1318
			#如果執行失敗失敗
1319
			if($enCodeStr["status"]==="false"){
1320
 
1321
				#設置錯誤識別
1322
				$result["status"]="false";
1323
 
1324
				#設置錯誤訊息
1325
				$result["error"]=$enCodeStr;
1326
 
1327
				#回傳結果
1328
				return $result;	
1329
 
1330
				}#if end
1331
 
1332
			#取得解密後的內容
1333
			$line=$enCodeStr["content"];
1334
 
1335
			#如果內容沒有 uuid
1336
			if(!isset($line->uuid)){
1337
 
1338
				#忽略該行
1339
				continue;
1340
 
1341
				}#if end
1342
 
1343
			#取得排程的uuid
1344
			$actionUuid=&$line->uuid;	
1345
 
1346
			#如果內容沒有 time ,亦即排程設定的(預期/已)執行時間
1347
			if(!isset($line->time)){
1348
 
1349
				#忽略該行
1350
				continue;
1351
 
1352
				}#if end
1353
 
1354
			#取得排程的時間
1355
			$actionUnixTime=&$line->time;	
1356
 
1357
			#如果內容沒有 action ,亦即排程設定的指令與參數.
1358
			if(!isset($line->action)){
1359
 
1360
				#忽略該行
1361
				continue;
1362
 
1363
				}#if end
1364
 
1365
			#取得排程要做的事情資訊
1366
			$actionInfo=&$line->action;
1367
 
1368
			#如果內容沒有 repeat ,亦即排程設定的執行模式.
1369
			if(!isset($line->repeat)){
1370
 
1371
				#忽略該行
1372
				continue;
1373
 
1374
				}#if end
1375
 
1376
			#反之若不是無窮執行
1377
			else if($line->repeat!=="-1"){
1378
 
1379
				#如果內容有 repeat->times ,亦即排程設定的剩下重複次數.
1380
				if(isset($line->repeat->times)){
1381
 
1382
					#取得剩下的重複執行次數
1383
					$leftRepeatTimes=&$line->repeat->times;
1384
 
1385
					}#if end
1386
 
1387
				#反之如果內容沒有 repeat->after(亦即排程設定的重複條件為time的之後多久) 跟 repeat->time->fixed(亦即排程設定的重複條件為用update mask過後的指定時間). 
1388
				else if( !isset($line->repeat->after) && !isset($line->repeat->fixed) ){
1389
 
1390
					#忽略該行
1391
					continue;
1392
 
1393
					}#else end
1394
 
1395
				}#if end
1396
 
1397
			#如果內容沒有 update,亦即排程設定最後更新的時間
1398
			if(!isset($line->update)){
1399
 
1400
				#忽略該行
1401
				continue;
1402
 
1403
				}#if end
1404
 
1405
			#取得當下時間
1406
			$currenUnixTime=time::unix()["content"];
1407
 
1408
			#如果當前時間大於等於排程的時間
1409
			if($currenUnixTime>=$actionUnixTime){
1410
 
1411
				#如果有抓到剩下的執行次數
1412
				if(isset($leftRepeatTimes)){
1413
 
1414
					#如果剩下的次數為0
1415
					if((int)$leftRepeatTimes===0){
1416
 
1417
						#跳過不執行
1418
						continue;
1419
 
1420
						}#if end
1421
 
1422
					}#if end
1423
 
1424
				#初始化要執行的事情資訊
1425
				$jobInfo=array();
1426
 
1427
				#設置其uuid
1428
				$jobInfo["uuid"]=$actionUuid;
1429
 
1430
				#設置其指令與參數
1431
				$jobInfo["cmd&argu"]=$actionInfo;
1432
 
1433
				#儲存工作資訊
1434
				$result["content"][]=$jobInfo;
1435
 
1436
				}#if end
1437
 
1438
			}#foreach end
1439
 
1440
		#預設置沒有事情要執行
1441
		$result["found"]="false";
1442
 
1443
		#如果有要執行的事情
1444
		if(isset($result["content"])){
1445
 
1446
			#設置有事情要執行
1447
			$result["found"]="true";
1448
 
1449
			}#if end
1450
 
1451
		#設置執行正常
1452
		$result["status"]="true";
1453
 
1454
		#回傳結果
1455
		return $result;
1456
 
1457
		}#function checkList end
1458
 
1459
	/*
1460
	#函式說明:
1461
	#依照autoService::createList建立的設定檔案來執行排程事項,執行完畢後會更新排程設定檔案,並輸出執行結果.
1462
	#回傳結果:
1463
	#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
1464
	#$result["error"],錯誤訊息陣列.
1465
	#$result["function"],當前執行的函式名稱.
1466
	#$result["content"],要執行排程的執行結果陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表輸出的陣列,其元素的key有"std"(標準輸出)與"err"(非標準輸出);
1467
	#$result["updatedConfigContent"],新的排程內容,有異動才會有這數值.
1468
	#$result["argu"],所使用的參數.
1469
	#$result["cache"],若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則該回傳內容,可以複寫cache,變成下次呼叫本函式的serverCache參數.若沒有執行任何排程,則不會回傳該結果.
1470
	#必填參數:
1471
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1472
	$conf["fileArgu"]=__FILE__;
1473
	#可省略參數:
1474
	#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
1475
	#$conf["config"]="";
1476
	#$conf["client"],陣列,若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則此為所有用戶的資訊.
1477
	#$conf["client"]=;
1478
	#$conf["serverCache"],陣列,若本函式作為 sock::unixDomainSockServer 的 funcToRunWhenIdle 參數,則此為要帶入的暫存資料.
1479
	#$conf["serverCache"]=;
1480
	#$conf["info"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
1481
	#$conf["info"]="";
1482
	#$conf["log"],字串,要將log寫到哪個地方,若有指定就會嘗試寫log.
1483
	#$conf["log"]="";
1484
	#可省略參數:
1485
	#無.
1486
	#參考資料:
1487
	#無.
1488
	#備註:
1489
	#無.
1490
	*/
1491
	public static function runList(&$conf){
1492
 
1493
		#初始化要回傳的變數
1494
		$result=array();
1495
 
1496
		#初始化當前執行的函數名稱
1497
		$result["function"]=__FUNCTION__;
1498
 
1499
		#如果 $conf 不為陣列
1500
		if(gettype($conf)!="array"){
1501
 
1502
			#設置執行失敗
1503
			$result["status"]="false";
1504
 
1505
			#設置執行錯誤訊息
1506
			$result["error"][]="\$conf變數須為陣列形態";
1507
 
1508
			#如果傳入的參數為 null
1509
			if($conf==null){
1510
 
1511
				#設置執行錯誤訊息
1512
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1513
 
1514
				}#if end
1515
 
1516
			#設置 cache result
1517
			$result["cache"]["result"]=&$result;
1518
 
1519
			#回傳結果
1520
			return $result;
1521
 
1522
			}#if end
1523
 
1524
		#取得使用的參數
1525
		$result["argu"]=$conf;
1526
 
1527
		#函式說明:
1528
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
1529
		#回傳結果:
1530
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1531
		#$result["error"],執行不正常結束的錯訊息陣列.
1532
		#$result["simpleError"],簡單表示的錯誤訊息.
1533
		#$result["function"],當前執行的函式名稱.
1534
		#$result["argu"],設置給予的參數.
1535
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1536
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1537
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1538
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
1539
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
1540
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1541
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1542
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
1543
		#必填參數:
1544
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1545
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1546
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1547
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
1548
		#可省略參數:
1549
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1550
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
1551
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
1552
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
1553
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
1554
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1555
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
1556
		#$conf["canNotBeEmpty"]=array();
1557
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
1558
		#$conf["canBeEmpty"]=array();
1559
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
1560
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("config");
1561
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1562
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config","client","serverCache","info","log");
1563
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
1564
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","array","array","array","string");
1565
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1566
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php",null,null,null,null);
1567
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
1568
		#$conf["disallowAllSkipableVarIsEmpty"]="";
1569
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
1570
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
1571
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
1572
		#$conf["disallowAllSkipableVarNotExist"]="";
1573
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1574
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");
1575
		#參考資料:
1576
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1577
		#備註:
1578
		#無.
1579
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1580
		unset($conf["variableCheck::checkArguments"]);
1581
 
1582
		#如果檢查出錯
1583
		if($checkArguments["status"]==="false"){
1584
 
1585
			#設置錯誤識別
1586
			$result["status"]="false";
1587
 
1588
			#設置錯誤訊息
1589
			$result["error"]=$checkArguments;
1590
 
1591
			#設置 cache result
1592
			$result["cache"]["result"]=&$result;
1593
 
1594
			#回傳結果
1595
			return $result;
1596
 
1597
			}#if end
1598
 
1599
		#如果檢查不通過
1600
		if($checkArguments["passed"]==="false"){
1601
 
1602
			#設置錯誤識別
1603
			$result["status"]="false";
1604
 
1605
			#設置錯誤訊息
1606
			$result["error"]=$checkArguments;
1607
 
1608
			#設置 cache result
1609
			$result["cache"]["result"]=&$result;
1610
 
1611
			#回傳結果
1612
			return $result;
1613
 
1614
			}#if end
1615
 
1616
		#debug
1617
		#var_dump(__LINE__,$conf["log"]);
1618
 
1619
		#初始化預設要回傳的cache
1620
		$result["cache"]=array();
1621
 
1622
		#若有暫存資料要處理
1623
		if(isset($conf["serverCache"])){
1624
 
1625
			/*
1626
 
1627
			#如果要寫log
1628
			if(isset($conf["log"])){
1629
 
1630
				#initial debug data
1631
				$debug=array();
1632
 
1633
				#set debug file info
1634
				$debug["file"]=__FILE__;
1635
 
1636
				#set debug function info
1637
				$debug["function"]=__FUNCTION__;
1638
 
1639
				#set debug line info
1640
				$debug["line"]=__LINE__;
1641
 
1642
				#set debug content
1643
				$debug["content"]=$conf["serverCache"];
1644
 
1645
				#write debug info
1646
				#函式說明:
1647
				#撰寫log
1648
				#回傳結果:
1649
				#$result["status"],狀態,"true"或"false".
1650
				#$result["error"],錯誤訊息陣列.
1651
				#$result["function"],當前函式的名稱.
1652
				#$result["argu"],使用的參數.
1653
				#$result["content"],要寫入log的內容字串.
1654
				#必填參數:
1655
				#$conf["path"],字串,log檔案的路徑與名稱.
1656
				$conf["logs::record"]["path"]=$conf["log"];
1657
				#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1658
				$conf["logs::record"]["content"]=$debug;
1659
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1660
				$conf["logs::record"]["fileArgu"]=__FILE__;
1661
				#可省略參數:
1662
				#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1663
				#$conf["rewrite"]="false";
1664
				#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
1665
				#$conf["returnOnly"]="true";
1666
				#參考資料:
1667
				#無.
1668
				#備註:
1669
				#無.
1670
				$record=logs::record($conf["logs::record"]);
1671
				unset($conf["logs::record"]);
1672
 
1673
				#如果執行失敗
1674
				if($record["status"]==="false"){
1675
 
1676
					#設置錯誤識別
1677
					$result["status"]="false";
1678
 
1679
					#設置錯誤訊息
1680
					$result["error"]=$record;
1681
 
1682
					#設置 cache result
1683
					$result["cache"]["result"]=&$result;
1684
 
1685
					#回傳結果
1686
					return $result;
1687
 
1688
					}#if end
1689
 
1690
				}#if end
1691
 
1692
			*/	
1693
 
1694
			#更新預設要回傳的cache
1695
			$result["cache"]=&$conf["serverCache"];
1696
 
1697
			#初始化儲存要更新排程設定的uuid
1698
			$uuidsForUpdateList=array();
1699
 
1700
			#如果有之前的資料
1701
			if(count($conf["serverCache"])>0){
1702
 
1703
				#如果有之前運行的結果
1704
				if(isset($conf["serverCache"]["result"])){
1705
 
1706
					/*
1707
 
1708
					#如果要寫log
1709
					if(isset($conf["log"])){
1710
 
1711
						#initial debug data
1712
						$debug=array();
1713
 
1714
						#set debug file info
1715
						$debug["file"]=__FILE__;
1716
 
1717
						#set debug function info
1718
						$debug["function"]=__FUNCTION__;
1719
 
1720
						#set debug line info
1721
						$debug["line"]=__LINE__;
1722
 
1723
						#set debug content
1724
						$debug["content"]=$conf["serverCache"]["result"];
1725
 
1726
						#write debug info
1727
						#函式說明:
1728
						#撰寫log
1729
						#回傳結果:
1730
						#$result["status"],狀態,"true"或"false".
1731
						#$result["error"],錯誤訊息陣列.
1732
						#$result["function"],當前函式的名稱.
1733
						#$result["argu"],使用的參數.
1734
						#$result["content"],要寫入log的內容字串.
1735
						#必填參數:
1736
						#$conf["path"],字串,log檔案的路徑與名稱.
1737
						$conf["logs::record"]["path"]=$conf["log"];
1738
						#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1739
						$conf["logs::record"]["content"]=$debug;
1740
						#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1741
						$conf["logs::record"]["fileArgu"]=__FILE__;
1742
						#可省略參數:
1743
						#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1744
						#$conf["rewrite"]="false";
1745
						#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
1746
						#$conf["returnOnly"]="true";
1747
						#參考資料:
1748
						#無.
1749
						#備註:
1750
						#無.
1751
						$record=logs::record($conf["logs::record"]);
1752
						unset($conf["logs::record"]);
1753
 
1754
						#如果執行失敗
1755
						if($record["status"]==="false"){
1756
 
1757
							#設置錯誤識別
1758
							$result["status"]="false";
1759
 
1760
							#設置錯誤訊息
1761
							$result["error"]=$record;
1762
 
1763
							#設置 cache result
1764
							$result["cache"]["result"]=&$result;
1765
 
1766
							#回傳結果
1767
							return $result;
1768
 
1769
							}#if end
1770
 
1771
						}#if end
1772
 
1773
					*/
1774
 
1775
					#如果之前運行正常
1776
					if($conf["serverCache"]["result"]["status"]==="true"){
1777
 
1778
						#如果有 cache 存在
1779
						if(isset($conf["serverCache"]["result"]["cache"])){
1780
 
1781
							#如果有 result
1782
							if(isset($conf["serverCache"]["result"]["cache"]["result"])){
1783
 
1784
								#如果有 content
1785
								if(isset($conf["serverCache"]["result"]["cache"]["result"]["content"])){
1786
 
1787
									#針對之前執行的排程事項
1788
									foreach($conf["serverCache"]["result"]["cache"]["result"]["content"] as $lastRanIndex => $lastRanInfo){
1789
 
1790
										#debug
1791
										#var_dump(__FILE__,__LINE__,$lastRanIndex,$lastRanInfo);
1792
 
1793
										#如果記錄上顯示該程序尚在執行中
1794
										if($lastRanInfo["proc_get_status"]["running"]===true){
1795
 
1796
											#嘗試取得該程序的狀態
1797
											$proc_get_status=proc_get_status($lastRanInfo["process"]);
1798
 
1799
											#如果已經結束執行
1800
											if($proc_get_status["running"]===false){
1801
 
1802
												#儲存要更新排程設定的uuid
1803
												$uuidsForUpdateList[]=$lastRanInfo["uuid"];
1804
 
1805
												#移除已經跑完的排程
1806
												unset($conf["serverCache"]["result"]["cache"]["result"]["content"][$lastRanIndex]);
1807
 
1808
												}#if end
1809
 
1810
											}#if end
1811
 
1812
										}#foreach end
1813
 
1814
									}#if end
1815
 
1816
								}#if end
1817
 
1818
							}#if end
1819
 
1820
						}#if end
1821
 
1822
					}#if end
1823
 
1824
				}#if end
1825
 
1826
			#如果有發現已經完工的排程
1827
			if(count($uuidsForUpdateList)>0){
1828
 
1829
				#函式說明:
1830
				#將指定uuid的已執行排程,依照repeat的規格,進行資料更新.
1831
				#回傳結果:
1832
				#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
1833
				#$result["error"],錯誤訊息陣列.
1834
				#$result["function"],當前執行的函式名稱.
1835
				#$result["content"],當前排程資訊內容.
1836
				#$result["argu"],使用的參數.
1837
				#必填參數:
1838
				#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1839
				$conf["autoService::updateList"]["fileArgu"]=$conf["fileArgu"];
1840
				#$conf["uuids"],字串陣列,每個排程的uuid,若不指定則會自動產生,若跟既有action的uuid相同,則會覆蓋其相關資訊.
1841
				$conf["autoService::updateList"]["uuids"]=$uuidsForUpdateList;
1842
				#可省略參數:
1843
				#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
1844
				$conf["autoService::updateList"]["config"]=$conf["config"];
1845
				#參考資料:
1846
				#無.
1847
				#備註:
1848
				#無.
1849
				$updateList=autoService::updateList($conf["autoService::updateList"]);
1850
				unset($conf["autoService::updateList"]);
1851
 
1852
				#如果執行出錯
1853
				if($updateList["status"]==="false"){
1854
 
1855
					#設置錯誤識別
1856
					$result["status"]="false";
1857
 
1858
					#設置錯誤訊息
1859
					$result["error"]=$updateList;
1860
 
1861
					#設置 cache result
1862
					$result["cache"]["result"]=&$result;
1863
 
1864
					#回傳結果
1865
					return $result;
1866
 
1867
					}#if end
1868
 
1869
				#如果有更新後的排程內容
1870
				if(isset($updateList["content"])){
1871
 
1872
					#取得新的排程內容
1873
					$result["updatedConfigContent"]=$updateList["content"];
1874
 
1875
					}#if end
1876
 
1877
				}#if end
1878
 
1879
			}#if end
1880
 
1881
		#函式說明:
1882
		#查詢系統上有哪些要自動執行的工作檔案
1883
		#回傳結果:
1884
		#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
1885
		#$result["error"],錯誤訊息陣列.
1886
		#$result["content"],回傳的結果,要執行的工作資訊陣列,每個元素的key有"uuid"跟"cmd&argu",前者為用於執行完畢時回報的排程項目識別;後者為該排程事項的指令與參數.
1887
		#$result["function"],當前執行的函式名稱.
1888
		#$result["found"],識別是否有要執行的動作.
1889
		#必填參數:
1890
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1891
		$conf["autoService::checkList"]["fileArgu"]=$conf["fileArgu"];
1892
		#可省略參數:
1893
		#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
1894
		$conf["autoService::checkList"]["config"]=$conf["config"];
1895
		#可省略參數:
1896
		#無.
1897
		#參考資料:
1898
		#無.
1899
		#備註:
1900
		#無.
1901
		$checkList=autoService::checkList($conf["autoService::checkList"]);
1902
		unset($conf["autoService::checkList"]);
1903
 
1904
		#如果執行失敗
1905
		if($checkList["status"]==="false"){
1906
 
1907
			#設置錯誤識別
1908
			$result["status"]="false";
1909
 
1910
			#設置錯誤訊息
1911
			$result["error"]=$checkList;
1912
 
1913
			#設置 cache result
1914
			$result["cache"]["result"]=&$result;
1915
 
1916
			#回傳結果
1917
			return $result;
1918
 
1919
			}#if end
1920
 
1921
		#如果無事可做
1922
		if($checkList["found"]==="false"){
1923
 
1924
			#設置錯誤識別
1925
			$result["status"]="true";
1926
 
1927
			#設置 cache result
1928
			$result["cache"]["result"]=&$result;
1929
 
1930
			#回傳結果
1931
			return $result;
1932
 
1933
			}#if end
1934
 
1935
		#debug
1936
		#var_dump(__FILE__,__LINE__,$checkList);
1937
 
1938
		#針對每個要執行的排程 
1939
		foreach($checkList["content"] as $index => $actionInfo){
1940
 
1941
			#如果有cache參數
1942
			if(isset($conf["serverCache"])){
1943
 
1944
				#如果有之前的資料
1945
				if(count($conf["serverCache"])>0){
1946
 
1947
					#如果有之前運行的結果
1948
					if(isset($conf["serverCache"]["result"])){
1949
 
1950
						#debug
1951
						#var_dump(__FILE__,__LINE__,$conf["serverCache"]["result"]);
1952
 
1953
						/*
1954
 
1955
						#如果要寫log
1956
						if(isset($conf["log"])){
1957
 
1958
							#initial debug data
1959
							$debug=array();
1960
 
1961
							#set debug file info
1962
							$debug["file"]=__FILE__;
1963
 
1964
							#set debug function info
1965
							$debug["function"]=__FUNCTION__;
1966
 
1967
							#set debug line info
1968
							$debug["line"]=__LINE__;
1969
 
1970
							#set debug content
1971
							$debug["content"]=$conf["serverCache"]["result"];
1972
 
1973
							#write debug info
1974
							#函式說明:
1975
							#撰寫log
1976
							#回傳結果:
1977
							#$result["status"],狀態,"true"或"false".
1978
							#$result["error"],錯誤訊息陣列.
1979
							#$result["function"],當前函式的名稱.
1980
							#$result["argu"],使用的參數.
1981
							#$result["content"],要寫入log的內容字串.
1982
							#必填參數:
1983
							#$conf["path"],字串,log檔案的路徑與名稱.
1984
							$conf["logs::record"]["path"]=$conf["log"];
1985
							#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
1986
							$conf["logs::record"]["content"]=$debug;
1987
							#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
1988
							$conf["logs::record"]["fileArgu"]=__FILE__;
1989
							#可省略參數:
1990
							#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
1991
							#$conf["rewrite"]="false";
1992
							#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
1993
							#$conf["returnOnly"]="true";
1994
							#參考資料:
1995
							#無.
1996
							#備註:
1997
							#無.
1998
							$record=logs::record($conf["logs::record"]);
1999
							unset($conf["logs::record"]);
2000
 
2001
							#如果執行失敗
2002
							if($record["status"]==="false"){
2003
 
2004
								#設置錯誤識別
2005
								$result["status"]="false";
2006
 
2007
								#設置錯誤訊息
2008
								$result["error"]=$record;
2009
 
2010
								#設置 cache result
2011
								$result["cache"]["result"]=&$result;
2012
 
2013
								#回傳結果
2014
								return $result;
2015
 
2016
								}#if end
2017
 
2018
							}#if end
2019
 
2020
						*/
2021
 
2022
						#如果之前運行正常
2023
						if($conf["serverCache"]["result"]["status"]==="true"){
2024
 
2025
							#如果有 cache 存在
2026
							if(isset($conf["serverCache"]["result"]["cache"])){
2027
 
2028
								#如果有 result
2029
								if(isset($conf["serverCache"]["result"]["cache"]["result"])){
2030
 
2031
									#如果有 content
2032
									if(isset($conf["serverCache"]["result"]["cache"]["result"]["content"])){
2033
 
2034
										#針對之前執行的排程事項
2035
										foreach($conf["serverCache"]["result"]["cache"]["result"]["content"] as $lastRanIndex => $lastRanInfo){
2036
 
2037
											#如果記錄上顯示該程序尚在執行中
2038
											if($lastRanInfo["proc_get_status"]["running"]===true){
2039
 
2040
												#如果是同排程的事項,亦即尚在執行中.
2041
												if($actionInfo["uuid"]===$lastRanInfo["uuid"]){
2042
 
2043
													#跳過該排程的執行
2044
													continue 2;
2045
 
2046
													}#if end
2047
 
2048
												}#if end
2049
 
2050
											}#foreach end
2051
 
2052
										}#if end
2053
 
2054
									}#if end
2055
 
2056
								}#if end
2057
 
2058
							}#if end
2059
 
2060
						}#if end
2061
 
2062
					}#if end
2063
 
2064
				}#if end
2065
 
2066
			#取得排程的uuid
2067
			$actionUuids[]=$actionInfo["uuid"];
2068
 
2069
			/*
2070
			#函式說明:
2071
			#將一維陣列轉換為用特定符號間隔的字串,ex:array("1","2","3") to "a;b;c;".
2072
			#回傳的結果:
2073
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2074
			#$result["function"],當前執行的function名稱
2075
			#$result["error"],錯誤訊息陣列.
2076
			#$result["content"],處理好的字串.
2077
			#$result["argu"],使用的參數.
2078
			#必填參數:
2079
			#$conf["inputArray"],字串陣列,要轉成字串的一維陣列.
2080
			$conf["arrays::arrayToString"]["inputArray"]=$actionInfo["cmd&argu"];
2081
			#可省略參數:
2082
			#$conf["spiltSymbol"],字串,用來區隔字串的符號,預設為;
2083
			$conf["arrays::arrayToString"]["spiltSymbol"]=" ";
2084
			#$conf["skipEnd"],字串,結尾是否不要加上符號,預設為"false",要加上符號,"true"代表不要加上符號。
2085
			#$conf["skipEnd"]="";
2086
			#參考資料:
2087
			#無.
2088
			#備註:
2089
			#無.
2090
			$arrayToString=arrays::arrayToString($conf["arrays::arrayToString"]);
2091
			unset($conf["arrays::arrayToString"]);
2092
 
2093
			#如果執行失敗
2094
			if($arrayToString["status"]==="false"){
2095
 
2096
				#設置錯誤識別
2097
				$result["status"]="false";
2098
 
2099
				#設置錯誤訊息
2100
				$result["error"]=$arrayToString;
2101
 
2102
				#設置 cache result
2103
				$result["cache"]["result"]=&$result;
2104
 
2105
				#回傳結果
2106
				return $result;
2107
 
2108
				}#if end
2109
 
2110
			#儲存排程的指令與參數
2111
			$cmdStrs[]=$arrayToString["content"];
2112
			*/
2113
 
2114
			#儲存排程的指令與參數
2115
			$cmdStrs[]=$actionInfo["cmd&argu"];
2116
 
2117
			}#foreach end
2118
 
2119
		#debug
2120
		#var_dump(__FILE__,__LINE__,$cmdStrs);
2121
 
2122
		#如果有要執行的指令
2123
		if(isset($cmdStrs)){
2124
 
2125
			#函式說明:
2126
			#透過proc來多執行序運作.
2127
			#回傳結果:
2128
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2129
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
2130
			#$result["function"],當前執行的函式名稱.
2131
			#$result["content"],陣列,每個元素為其指令執行的結果訊息陣列,key為"status"代表執行是否正常的識別;key為"statusCode"代表程式結束後回傳給對應executeBy程式的數值;key為"output"代表標準輸出,若為resource,則代表為pipe;key為"error"代表非標準輸出,若為resource,則代表為pipe;key為"input"代表成功輸入的指令;key為"process"代表該程序經proc_open後的process source;key為"proc_get_status"代表程序的資訊.
2132
			#必填參數:
2133
			#$conf["cmds"],字串陣列,每個元素代表要執行的指令與參數.
2134
			$conf["threads::proc"]["cmds"]=$cmdStrs;
2135
			#可省略參數:
2136
			#$conf["wait"],字串,是否需要等待所有程序結束,預設為"true"要等待;反之為"false"不要等待.
2137
			$conf["threads::proc"]["wait"]="false";
2138
			#$conf["workingDir"],字串陣列,個別程式執行時的家目錄,預設不指定.
2139
			#$conf["workingDir"]=array("path");
2140
			#$conf["envs"],2維字串陣列,每個元素代表個別程式執行時的指定環境變數,key變數名稱;value為變數內容.預設為array("QBPWCF" => "Quick Build PHP Website Componment base on Fedora Linux");
2141
			#$conf["envs"]=array(array("key"=>"value"));
2142
			#$conf["executeBy"],字串陣列,每個元素代表個別指令要用什麼程式執行,預設為"bash".
2143
			#$conf["executeBy"]=array("bash");
2144
			#參考資料:
2145
			#https://www.php.net/manual/en/function.proc-open.php
2146
			#https://www.php.net/manual/en/function.proc-get-status.php
2147
			#備註:
2148
			#無.
2149
			$proc=threads::proc($conf["threads::proc"]);
2150
			unset($conf["threads::proc"]);
2151
 
2152
			#如果執行失敗
2153
			if($proc["status"]==="false"){
2154
 
2155
				#設置錯誤識別
2156
				$result["status"]="false";
2157
 
2158
				#設置錯誤訊息
2159
				$result["error"]=$proc;
2160
 
2161
				#設置 cache result
2162
				$result["cache"]["result"]=&$result;
2163
 
2164
				#回傳結果
2165
				return $result;
2166
 
2167
				}#if end
2168
 
2169
			#針對每個proc資訊
2170
			foreach($proc["content"] as $index => $procInfo){
2171
 
2172
				#附加用於識別排程的uuid
2173
				$proc["content"][$index]["uuid"]=$actionUuids[$index];
2174
 
2175
				#如果要寫log
2176
				if(isset($conf["log"])){
2177
 
2178
					#儲存要提示跑了什麼排程
2179
					$comment="運行排程 uuid:".$actionUuids[$index]." pid:".$proc["content"][$index]["proc_get_status"]["pid"]." 進入點:".$proc["content"][$index]["proc_get_status"]["command"]." 指令:".$cmdStrs[$index];
2180
 
2181
					#提示運行了什麼排程
2182
					#函式說明:
2183
					#顯示多行文字.
2184
					#回傳的結果:
2185
					#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
2186
					#$result["error"],錯誤訊息陣列.
2187
					#$result["function"],當前執行的函數名稱.
2188
					#$result["content"],語法.
2189
					#必填參數:
2190
					#$conf["string"],字串陣列,要放置的內容.
2191
					$conf["text::multiLine"]["string"]=array($comment);
2192
					#可省略參數:
2193
					#$conf["class"],字串,要使用的css樣式名稱,預設為"__defaultTextStyle"
2194
					#$conf["class"]="";
2195
					#$conf["type"],字串,要用"div"或"span"或"br"或"p"或"EOL"或"textarea"來段行,預設為"EOL".
2196
					#$conf["type"]="EOL";
2197
					#參考資料:
2198
					#無.
2199
					#備註:
2200
					#無.
2201
					$multiLine=text::multiLine($conf["text::multiLine"]);
2202
					unset($conf["text::multiLine"]);
2203
 
2204
					#如果執行失敗
2205
					if($multiLine["status"]==="false"){
2206
 
2207
						#設置錯誤識別
2208
						$result["status"]="false";
2209
 
2210
						#設置錯誤訊息
2211
						$result["error"]=$multiLine;
2212
 
2213
						#設置 cache result
2214
						$result["cache"]["result"]=&$result;
2215
 
2216
						#回傳結果
2217
						return $result;
2218
 
2219
						}#if end
2220
 
2221
					#initial debug data
2222
					$debug=array();
2223
 
2224
					#set debug file info
2225
					$debug["file"]=__FILE__;
2226
 
2227
					#set debug function info
2228
					$debug["function"]=__FUNCTION__;
2229
 
2230
					#set debug line info
2231
					$debug["line"]=__LINE__;
2232
 
2233
					#set debug content
2234
					$debug["content"]=$multiLine["content"];
2235
 
2236
					#write debug info
2237
					#函式說明:
2238
					#撰寫log
2239
					#回傳結果:
2240
					#$result["status"],狀態,"true"或"false".
2241
					#$result["error"],錯誤訊息陣列.
2242
					#$result["function"],當前函式的名稱.
2243
					#$result["argu"],使用的參數.
2244
					#$result["content"],要寫入log的內容字串.
2245
					#必填參數:
2246
					#$conf["path"],字串,log檔案的路徑與名稱.
2247
					$conf["logs::record"]["path"]=$conf["log"];
2248
					#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
2249
					$conf["logs::record"]["content"]=$debug;
2250
					#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2251
					$conf["logs::record"]["fileArgu"]=__FILE__;
2252
					#可省略參數:
2253
					#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
2254
					#$conf["rewrite"]="false";
2255
					#$conf["returnOnly"],預設為"false",會寫入到log檔案.若為"true"則不會寫入log.
2256
					#$conf["returnOnly"]="true";
2257
					#參考資料:
2258
					#無.
2259
					#備註:
2260
					#無.
2261
					$record=logs::record($conf["logs::record"]);
2262
					unset($conf["logs::record"]);
2263
 
2264
					#如果執行失敗
2265
					if($record["status"]==="false"){
2266
 
2267
						#設置錯誤識別
2268
						$result["status"]="false";
2269
 
2270
						#設置錯誤訊息
2271
						$result["error"]=$record;
2272
 
2273
						#設置 cache result
2274
						$result["cache"]["result"]=&$result;
2275
 
2276
						#回傳結果
2277
						return $result;
2278
 
2279
						}#if end
2280
 
2281
					}#if end
2282
 
2283
				}#foreach end
2284
 
2285
			#依照每個剛執行的程序
2286
			foreach($proc["content"] as $procJustRan){
2287
 
2288
				#取得每個程序執的執行結果
2289
				$result["content"][]=$procJustRan;
2290
 
2291
				}#foreach end
2292
 
2293
			}#if end
2294
 
2295
		#設置執行正常
2296
		$result["status"]="true";
2297
 
2298
		#設置 cache result
2299
		$result["cache"]["result"]=&$result;
2300
 
2301
		#如果該次沒有執行排程
2302
		if(!isset($result["content"])){
2303
 
2304
			#從 cache 取得 content
2305
			$result["content"]=&$result["cache"]["serverSide"]["funcToRunWhenIdle"]["\QBPWCF\autoService::runList"]["result"]["content"];
2306
 
2307
			}#if end
2308
 
2309
		#debug
2310
		#var_dump(__FILE__,__LINE__,$result);
2311
 
2312
		#回傳結果
2313
		return $result;
2314
 
2315
		}#function runList end
2316
 
2317
	/*
2318
	#函式說明:
2319
	#將指定uuid的已執行排程,依照repeat的規格,進行資料更新.
2320
	#回傳結果:
2321
	#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
2322
	#$result["error"],錯誤訊息陣列.
2323
	#$result["function"],當前執行的函式名稱.
2324
	#$result["content"],當前排程資訊內容.
2325
	#$result["argu"],使用的參數.
2326
	#必填參數:
2327
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2328
	$conf["fileArgu"]=__FILE__;
2329
	#$conf["uuids"],字串陣列,每個排程的uuid,若不指定則會自動產生,若跟既有action的uuid相同,則會覆蓋其相關資訊.
2330
	#$conf["uuids"]=array();
2331
	#可省略參數:
2332
	#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
2333
	#$conf["config"]="";
2334
	#參考資料:
2335
	#無.
2336
	#備註:
2337
	#無.
2338
	*/
2339
	public static function updateList(&$conf){
2340
 
2341
		#初始化要回傳的變數
2342
		$result=array();
2343
 
2344
		#初始化當前執行的函數名稱
2345
		$result["function"]=__FUNCTION__;
2346
 
2347
		#如果 $conf 不為陣列
2348
		if(gettype($conf)!="array"){
2349
 
2350
			#設置執行失敗
2351
			$result["status"]="false";
2352
 
2353
			#設置執行錯誤訊息
2354
			$result["error"][]="\$conf變數須為陣列形態";
2355
 
2356
			#如果傳入的參數為 null
2357
			if($conf==null){
2358
 
2359
				#設置執行錯誤訊息
2360
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2361
 
2362
				}#if end
2363
 
2364
			#回傳結果
2365
			return $result;
2366
 
2367
			}#if end
2368
 
2369
		#取得使用的參數
2370
		$result["argu"]=$conf;
2371
 
2372
		#函式說明:
2373
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
2374
		#回傳結果:
2375
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2376
		#$result["error"],執行不正常結束的錯訊息陣列.
2377
		#$result["simpleError"],簡單表示的錯誤訊息.
2378
		#$result["function"],當前執行的函式名稱.
2379
		#$result["argu"],設置給予的參數.
2380
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2381
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2382
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2383
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
2384
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
2385
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2386
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2387
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
2388
		#必填參數:
2389
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2390
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2391
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2392
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
2393
		#可省略參數:
2394
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2395
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","uuids");
2396
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
2397
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","array");
2398
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
2399
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
2400
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
2401
		#$conf["canNotBeEmpty"]=array();
2402
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
2403
		#$conf["canBeEmpty"]=array();
2404
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
2405
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("config");
2406
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2407
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config");
2408
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
2409
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
2410
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2411
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php");
2412
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
2413
		#$conf["disallowAllSkipableVarIsEmpty"]="";
2414
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
2415
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
2416
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
2417
		#$conf["disallowAllSkipableVarNotExist"]="";
2418
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2419
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");
2420
		#參考資料:
2421
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2422
		#備註:
2423
		#無.
2424
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2425
		unset($conf["variableCheck::checkArguments"]);
2426
 
2427
		#如果 $checkArguments["status"] 等於 "false"
2428
		if($checkArguments["status"]==="false"){
2429
 
2430
			#設置錯誤識別
2431
			$result["status"]="false";
2432
 
2433
			#設置錯誤訊息
2434
			$result["error"]=$checkArguments;
2435
 
2436
			#回傳結果
2437
			return $result;				
2438
 
2439
			}#if end
2440
 
2441
		#如果 $checkArguments["passed"] 等於 "false"
2442
		if($checkArguments["passed"]==="false"){
2443
 
2444
			#設置錯誤識別
2445
			$result["status"]="false";
2446
 
2447
			#設置錯誤訊息
2448
			$result["error"]=$checkArguments;
2449
 
2450
			#回傳結果
2451
			return $result;
2452
 
2453
			}#if end
2454
 
2455
		#函式說明:
2456
		#依據行號分隔抓取檔案的內容,結果會回傳一個陣列
2457
		#回傳的變數說明:
2458
		#$result["status"],執行是否成功,"true"代表成功;"fasle"代表失敗.
2459
		#$result["error"],錯誤訊息提示.
2460
		#$result["warning"],警告訊息.
2461
		#$result["function"],當前執行的函數名稱.
2462
		#$result["fileContent"],爲檔案的內容陣列.
2463
		#$result["lineCount"],爲檔案內容總共的行數.
2464
		#$result["fullContent"],為檔案的完整內容.
2465
		#$result["base64data"],為檔案的base64內容.
2466
		#$result["mimeType"],為檔案的mime type.
2467
		#必填的參數:
2468
		#$conf["filePositionAndName"],字串,爲檔案的位置以及名稱.
2469
		$conf["fileAccess::getFileContent"]["filePositionAndName"]=$conf["config"];
2470
		#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
2471
		$conf["fileAccess::getFileContent"]["fileArgu"]=$conf["fileArgu"];
2472
		#可省略參數:
2473
		#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false".
2474
		$conf["fileAccess::getFileContent"]["web"]="false";
2475
		#參考資料:
2476
		#file(),取得檔案內容的行數.
2477
		#file=>http:#php.net/manual/en/function.file.php
2478
		#rtrim(),剔除透過file()取得每行內容結尾的換行符號.
2479
		#filesize=>http://php.net/manual/en/function.filesize.php
2480
		$getFileContent=fileAccess::getFileContent($conf["fileAccess::getFileContent"]);
2481
		unset($conf["fileAccess::getFileContent"]);
2482
 
2483
		#如果取得檔案失敗
2484
		if($getFileContent["status"]==="false"){
2485
 
2486
			#設置錯誤識別
2487
			$result["status"]="false";
2488
 
2489
			#設置錯誤訊息
2490
			$result["error"]=$getFileContent;
2491
 
2492
			#回傳結果
2493
			return $result;	
2494
 
2495
			}#if end
2496
 
2497
		#解析檔案內容
2498
 
2499
		#針對每行內容
2500
		foreach($getFileContent["fileContent"] as $line){
2501
 
2502
			#解密內容
2503
			#函式說明:
2504
			#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
2505
			#回傳結果:
2506
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
2507
			#$result["function"],當前執行的函數名稱.
2508
			#$result["content"],加密後的結果.
2509
			#$result["error"],錯誤訊息陣列.
2510
			#$result["argu"],使用的參數.
2511
			#必填參數:
2512
			#$conf["enCodeStr"],"字串",要加密的字串.
2513
			$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;
2514
			#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
2515
			$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";
2516
			#可省略參數:
2517
			#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
2518
			#$conf["sha1Raw"]="false";
2519
			#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
2520
			#$conf["p_hash"]="";
2521
			#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
2522
			#$conf["keyForAes256"]="";
2523
			#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
2524
			#$conf["aes256Encode"]="";
2525
			#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
2526
			$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";
2527
			#參考資料:
2528
			#sha1=>http://php.net/manual/en/function.sha1.php
2529
			#md5=>http://php.net/manual/en/function.md5.php
2530
			#password_hash=>http://php.net/manual/en/function.password-hash.php
2531
			#password_verify=>http://php.net/manual/en/function.password-verify.php
2532
			#json_decode=>https://www.php.net/manual/en/function.json-decode.php
2533
			#備註:
2534
			#無.
2535
			$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
2536
			unset($conf["authenticate::enCodeStr"]);
2537
 
2538
			#如果執行失敗失敗
2539
			if($enCodeStr["status"]==="false"){
2540
 
2541
				#設置錯誤識別
2542
				$result["status"]="false";
2543
 
2544
				#設置錯誤訊息
2545
				$result["error"]=$enCodeStr;
2546
 
2547
				#回傳結果
2548
				return $result;	
2549
 
2550
				}#if end
2551
 
2552
			#取得解密後的內容
2553
			$line=$enCodeStr["content"];
2554
 
2555
			#debug
2556
			#var_dump(__LINE__,$line);
2557
 
2558
			#如果內容沒有 uuid
2559
			if(!isset($line->uuid)){
2560
 
2561
				#忽略該行
2562
				continue;
2563
 
2564
				}#if end
2565
 
2566
			#取得排程的uuid
2567
			$uuidInFile=$line->uuid;	
2568
 
2569
			#如果內容沒有 time ,亦即排程設定的(預期/已)執行時間
2570
			if(!isset($line->time)){
2571
 
2572
				#忽略該行
2573
				continue;
2574
 
2575
				}#if end
2576
 
2577
			#取得排程的時間
2578
			$actionUnixTimeInFile=&$line->time;	
2579
 
2580
			#如果內容沒有 action ,亦即排程設定的指令與參數.
2581
			if(!isset($line->action)){
2582
 
2583
				#忽略該行
2584
				continue;
2585
 
2586
				}#if end
2587
 
2588
			#取得排程要做的事情資訊
2589
			$actionInFile=$line->action;
2590
 
2591
			#如果內容沒有 repeat ,亦即排程設定的執行模式.
2592
			if(!isset($line->repeat)){
2593
 
2594
				#忽略該行
2595
				continue;
2596
 
2597
				}#if end
2598
 
2599
			#取得重複的方式
2600
			$repeatInFile=$line->repeat;
2601
 
2602
			#如果內容沒有 repeat->time ,亦即排程設定的剩下重複次數.
2603
			if(!isset($line->repeat->times)){
2604
 
2605
				#忽略該行
2606
				continue;
2607
 
2608
				}#if end
2609
 
2610
			#取得剩下的重複執行次數
2611
			$leftRepeatTimesInFile=&$line->repeat->times;
2612
 
2613
			#如果內容沒有 repeat->after(亦即排程設定的重複條件為time的之後多久) 跟 repeat->time->fixed(亦即排程設定的重複條件為用update mask過後的指定時間). 
2614
			if( !isset($line->repeat->after) && !isset($line->repeat->fixed) ){
2615
 
2616
				#忽略該行
2617
				continue;
2618
 
2619
				}#if end
2620
 
2621
			#如果內容沒有 update,亦即排程設定最後更新的時間
2622
			if(!isset($line->update)){
2623
 
2624
				#忽略該行
2625
				continue;
2626
 
2627
				}#if end
2628
 
2629
			#取得排程設定產生/更新的時間點
2630
			$updateTimeInFile=$line->update;
2631
 
2632
			#判斷是否為目標排程的uuid
2633
			#函式說明:
2634
			#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
2635
			#回傳結果:
2636
			#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
2637
			#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
2638
			#$result["error"],錯誤訊息
2639
			#$result["function"],當前執行的函數名稱
2640
			#$result["argv"],使用的參數
2641
			#$result["equalVarName"],相等的變數名稱或key.
2642
			#$result["equalVarValue"],相等的變數數值內容.
2643
			#必填參數:
2644
			#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
2645
			$conf["search::getEqualVar"]["conditionElement"]=$uuidInFile;
2646
			#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
2647
			$conf["search::getEqualVar"]["compareElements"]=$conf["uuids"];
2648
			#可省略參數:
2649
			#無.
2650
			#參考資料:
2651
			#無.
2652
			#備註:
2653
			#無.
2654
			$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
2655
			unset($conf["search::getEqualVar"]);
2656
 
2657
			#debug
2658
			#var_dump(__LINE__,$getEqualVar);
2659
 
2660
			#如果執行失敗
2661
			if($getEqualVar["status"]==="false"){
2662
 
2663
				#設置錯誤識別
2664
				$result["status"]="false";
2665
 
2666
				#設置錯誤訊息
2667
				$result["error"]=$getEqualVar;
2668
 
2669
				#回傳結果
2670
				return $result;	
2671
 
2672
				}#if end
2673
 
2674
			#如果有相符的uuid
2675
			if($getEqualVar["founded"]==="true"){
2676
 
2677
				#當前unixtime
2678
				$currentUnixTime=time::unix()["content"];
2679
 
2680
				#檔案中的排程時間
2681
				#$actionUnixTimeInFile
2682
 
2683
				#檔案中的排程重複方式
2684
				#$repeatInFile
2685
 
2686
				#debug
2687
				#var_dump(__LINE__,$repeatInFile);
2688
 
2689
				#檔案中排程設定產生/更新的時間點
2690
				#$updateTimeInFile
2691
 
2692
				#如果是要固定時間執行
2693
				if(isset($repeatInFile->fixed)){
2694
 
2695
					#如果西元元相等
2696
					if( gmdate("Y",$repeatInFile->fixed)===gmdate("Y",$updateTimeInFile) ){
2697
 
2698
						#debug
2699
						#var_dump(__LINE__,"西元元相等(".gmdate("Y",$repeatInFile->fixed)."=".gmdate("Y",$updateTimeInFile).")");
2700
 
2701
						#如果月份相同
2702
						if( gmdate("m",$repeatInFile->fixed)===gmdate("m",$updateTimeInFile) ){
2703
 
2704
							#debug
2705
							#var_dump(__LINE__,"月份相同(".gmdate("m",$repeatInFile->fixed)."=".gmdate("m",$updateTimeInFile).")");
2706
 
2707
							#如果日相同
2708
							if( gmdate("d",$repeatInFile->fixed)===gmdate("d",$updateTimeInFile) ){
2709
 
2710
								#debug
2711
								#var_dump(__LINE__,"日相同(".gmdate("d",$repeatInFile->fixed)."=".gmdate("d",$updateTimeInFile).")");
2712
 
2713
								#如果時相同
2714
								if( gmdate("H",$repeatInFile->fixed)===gmdate("H",$updateTimeInFile) ){
2715
 
2716
									#debug
2717
									#var_dump(__LINE__,"時相同(".gmdate("H",$repeatInFile->fixed)."=".gmdate("H",$updateTimeInFile).")");
2718
 
2719
									#如果分相同
2720
									if( gmdate("i",$repeatInFile->fixed)===gmdate("i",$updateTimeInFile) ){
2721
 
2722
										#debug
2723
										#var_dump(__LINE__,"分相同(".gmdate("i",$repeatInFile->fixed)."=".gmdate("i",$updateTimeInFile).")");
2724
 
2725
										#代表要在固定秒數執行
2726
										$runAtThisSec=gmdate("s",$repeatInFile->fixed);
2727
 
2728
										#更新下次執行排程的時間,為1分鐘後
2729
										$line->time=$repeatInFile->fixed+60;
2730
 
2731
										#更新用於代表要在固定秒數執行的設定
2732
										$line->repeat->fixed=$line->time+60;
2733
 
2734
										#debug
2735
										#var_dump(__LINE__,"分相同(".gmdate("i",$repeatInFile->fixed)."=".gmdate("i",$updateTimeInFile).")");
2736
 
2737
										}#if end
2738
 
2739
									#反之到小時都相同
2740
									else{
2741
 
2742
										#代表要在固定分鐘數執行
2743
										$runAtThisMin=gmdate("i",$repeatInFile->fixed);
2744
 
2745
										#更新下次執行排程的時間,為小1時後.
2746
										$line->time=$repeatInFile->fixed+60*60;
2747
 
2748
										#更新用於代表要在固定分鐘數執行的設定
2749
										$line->repeat->fixed=$line->time+60*60;
2750
 
2751
										}#else end
2752
 
2753
									}#if end
2754
 
2755
								#反之到日都相等
2756
								else{
2757
 
2758
									#代表要在固定時數執行
2759
									$runAtThisHour=gmdate("H",$repeatInFile->fixed);
2760
 
2761
									#更新下次執行排程的時間,為1天後.
2762
									$line->time=$repeatInFile->fixed+60*60*24;
2763
 
2764
									#更新用於代表要在固定小時數執行的設定
2765
									$line->repeat->fixed=$line->time+60*60*24;
2766
 
2767
									}#else end
2768
 
2769
								}#if end
2770
 
2771
							#反之到月都相等
2772
							else{
2773
 
2774
								#代表要在固定日執行
2775
								$runAtThisDay=gmdate("d",$repeatInFile->fixed);
2776
 
2777
								#取得該次執行的年份
2778
								$year=gmdate("Y",$repeatInFile->fixed);
2779
 
2780
								#取得執行該次的月份
2781
								$month=gmdate("m",$repeatInFile->fixed);
2782
 
2783
								#如果月份等於"12"
2784
								if($month==="12"){
2785
 
2786
									#將之變為01
2787
									$month="01";
2788
 
2789
									#西元年也加1
2790
									$year=$year+1;
2791
 
2792
									}#if end
2793
 
2794
								#反之
2795
								else{
2796
 
2797
									#月份+1
2798
									$month=printf("02s",$month+1);
2799
 
2800
									}#else end
2801
 
2802
								#組合YYYY-mm-dd HH:ii:ss字串參數
2803
								$dateAndTime=$year."-".$month."-".$runAtThisDay." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);
2804
 
2805
								#函式說明:
2806
								#計算時間點距離1970/01/01多少秒,亦即unixtime.
2807
								#回傳結果:
2808
								#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
2809
								#$result["error"],錯誤訊息陣列.
2810
								#$result["content"],時間點距離1970/01/01的多少秒.
2811
								#$result["argu"],使用的參數.
2812
								#$result["unixtime"],執行本函式時的unixtime.
2813
								#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.	
2814
								#必填參數:
2815
								#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
2816
								$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;
2817
								#可省略參數:
2818
								#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
2819
								$conf["time::caculateTimeAmount"]["UTC"]="true";
2820
								#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
2821
								$conf["time::caculateTimeAmount"]["replace0"]="false";
2822
								#參考資料:
2823
								#無.
2824
								#備註:
2825
								#無.
2826
								$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
2827
								unset($conf["time::caculateTimeAmount"]);
2828
 
2829
								#如果執行失敗
2830
								if($caculateTimeAmount["status"]=="false"){
2831
 
2832
									#設置執行失敗的訊息
2833
									$result["status"]="false";
2834
 
2835
									#設置錯誤訊息
2836
									$result["error"]=$caculateTimeAmount;
2837
 
2838
									#回傳結果
2839
									return $result;
2840
 
2841
									}#if end
2842
 
2843
								#更新下次執行排程的時間,為1個月後.
2844
								$line->time=$caculateTimeAmount["content"];
2845
 
2846
								#代表要在固定日執行
2847
								$runAtThisDay=gmdate("d",$repeatInFile->fixed);
2848
 
2849
								#如果月份等於"12"
2850
								if($month==="12"){
2851
 
2852
									#將之變為01
2853
									$month="01";
2854
 
2855
									#西元年也加1
2856
									$year=$year+1;
2857
 
2858
									}#if end
2859
 
2860
								#反之
2861
								else{
2862
 
2863
									#月份+1
2864
									$month=printf("02s",$month+1);
2865
 
2866
									}#else end
2867
 
2868
								#組合YYYY-mm-dd HH:ii:ss字串參數
2869
								$dateAndTime=$year."-".$month."-".$runAtThisDay." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);
2870
 
2871
								#函式說明:
2872
								#計算時間點距離1970/01/01多少秒,亦即unixtime.
2873
								#回傳結果:
2874
								#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
2875
								#$result["error"],錯誤訊息陣列.
2876
								#$result["content"],時間點距離1970/01/01的多少秒.
2877
								#$result["argu"],使用的參數.
2878
								#$result["unixtime"],執行本函式時的unixtime.
2879
								#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.	
2880
								#必填參數:
2881
								#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
2882
								$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;
2883
								#可省略參數:
2884
								#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
2885
								$conf["time::caculateTimeAmount"]["UTC"]="true";
2886
								#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
2887
								$conf["time::caculateTimeAmount"]["replace0"]="false";
2888
								#參考資料:
2889
								#無.
2890
								#備註:
2891
								#無.
2892
								$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
2893
								unset($conf["time::caculateTimeAmount"]);
2894
 
2895
								#如果執行失敗
2896
								if($caculateTimeAmount["status"]=="false"){
2897
 
2898
									#設置執行失敗的訊息
2899
									$result["status"]="false";
2900
 
2901
									#設置錯誤訊息
2902
									$result["error"]=$caculateTimeAmount;
2903
 
2904
									#回傳結果
2905
									return $result;
2906
 
2907
									}#if end
2908
 
2909
								#更新用於代表要在固定日子執行的設定
2910
								$line->repeat->fixed=$caculateTimeAmount["content"];
2911
 
2912
								}#else end
2913
 
2914
							}#if end
2915
 
2916
						#反之到年都相等
2917
						else{
2918
 
2919
							#代表要在固定月執行
2920
							$runAtThisMonth=gmdate("m",$repeatInFile->fixed);
2921
 
2922
							#取得該次執行的年份
2923
							$year=gmdate("Y",$repeatInFile->fixed);
2924
 
2925
							#明年執行
2926
							$year=$year+1;
2927
 
2928
							#組合YYYY-mm-dd HH:ii:ss字串參數
2929
							$dateAndTime=$year."-".$runAtThisMonth."-".gmdate("d",$repeatInFile->fixed)." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);
2930
 
2931
							#函式說明:
2932
							#計算時間點距離1970/01/01多少秒,亦即unixtime.
2933
							#回傳結果:
2934
							#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
2935
							#$result["error"],錯誤訊息陣列.
2936
							#$result["content"],時間點距離1970/01/01的多少秒.
2937
							#$result["argu"],使用的參數.
2938
							#$result["unixtime"],執行本函式時的unixtime.
2939
							#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.	
2940
							#必填參數:
2941
							#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
2942
							$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;
2943
							#可省略參數:
2944
							#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
2945
							$conf["time::caculateTimeAmount"]["UTC"]="true";
2946
							#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
2947
							$conf["time::caculateTimeAmount"]["replace0"]="false";
2948
							#參考資料:
2949
							#無.
2950
							#備註:
2951
							#無.
2952
							$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
2953
							unset($conf["time::caculateTimeAmount"]);
2954
 
2955
							#如果執行失敗
2956
							if($caculateTimeAmount["status"]=="false"){
2957
 
2958
								#設置執行失敗的訊息
2959
								$result["status"]="false";
2960
 
2961
								#設置錯誤訊息
2962
								$result["error"]=$caculateTimeAmount;
2963
 
2964
								#回傳結果
2965
								return $result;
2966
 
2967
								}#if end
2968
 
2969
							#更新下次執行排程的時間,為1年後.
2970
							$line->time=$caculateTimeAmount["content"];
2971
 
2972
							#代表要在固定月執行
2973
							$runAtThisMonth=gmdate("m",$repeatInFile->fixed);
2974
 
2975
							#取得該次執行的年份
2976
							$year=gmdate("Y",$repeatInFile->fixed);
2977
 
2978
							#明年執行
2979
							$year=$year+1;
2980
 
2981
							#組合YYYY-mm-dd HH:ii:ss字串參數
2982
							$dateAndTime=$year."-".$runAtThisMonth."-".gmdate("d",$repeatInFile->fixed)." ".gmdate("H",$repeatInFile->fixed).":".gmdate("i",$repeatInFile->fixed).":".gmdate("s",$repeatInFile->fixed);
2983
 
2984
							#函式說明:
2985
							#計算時間點距離1970/01/01多少秒,亦即unixtime.
2986
							#回傳結果:
2987
							#$result["stauts"],執行是否成功,"true"代表執行成功;"false"代表執行失敗.
2988
							#$result["error"],錯誤訊息陣列.
2989
							#$result["content"],時間點距離1970/01/01的多少秒.
2990
							#$result["argu"],使用的參數.
2991
							#$result["unixtime"],執行本函式時的unixtime.
2992
							#$result["oriDateAndTime"],原始輸入的內容,若replace0參數為"true",才會有該回傳內容.	
2993
							#必填參數:
2994
							#$conf["dateAndTime"],字串,格式爲 2011-05-27 23:59:59.
2995
							$conf["time::caculateTimeAmount"]["dateAndTime"]=$dateAndTime;
2996
							#可省略參數:
2997
							#$conf["UTC"],字串,是否要用當前時區的設定去換算成unixtime,預設為"false",代表不要;反之為"true".
2998
							$conf["time::caculateTimeAmount"]["UTC"]="true";
2999
							#$conf["replace0"],字串,是否要將連續為0的內容替換成當下時間,預設為"true"代表要;反之為"false".
3000
							$conf["time::caculateTimeAmount"]["replace0"]="false";
3001
							#參考資料:
3002
							#無.
3003
							#備註:
3004
							#無.
3005
							$caculateTimeAmount=time::caculateTimeAmount($conf["time::caculateTimeAmount"]);
3006
							unset($conf["time::caculateTimeAmount"]);
3007
 
3008
							#如果執行失敗
3009
							if($caculateTimeAmount["status"]=="false"){
3010
 
3011
								#設置執行失敗的訊息
3012
								$result["status"]="false";
3013
 
3014
								#設置錯誤訊息
3015
								$result["error"]=$caculateTimeAmount;
3016
 
3017
								#回傳結果
3018
								return $result;
3019
 
3020
								}#if end
3021
 
3022
							#更新用於代表要在固定月份執行的設定
3023
							$line->repeat->fixed=$caculateTimeAmount["content"];
3024
 
3025
							}#else end
3026
 
3027
						}#if end
3028
 
3029
					#反之,從年份就不同
3030
					else{
3031
 
3032
						#執行到這邊代表是一次性排程,以後不會在碰到,除非時光倒退.
3033
 
3034
						}#else end
3035
 
3036
					}#if end
3037
 
3038
				#如果是要特定時間後執行
3039
				else if(isset($repeatInFile->after)){
3040
 
3041
					#debug
3042
					#var_dump(__LINE__,"要特定時間後執行");
3043
 
3044
					#更新下次執行排程的時間
3045
					$line->time=$currentUnixTime+$repeatInFile->after;
3046
 
3047
					}#if end
3048
 
3049
				#更新異動的時間
3050
				$line->update=$currentUnixTime;
3051
 
3052
				#如果檔案中剩下的可執行次數大於0
3053
				if($leftRepeatTimesInFile>0){
3054
 
3055
					#檔案中剩下的可執行次數-1
3056
					$line->repeat->times=$leftRepeatTimesInFile-1;
3057
 
3058
					}#if end
3059
 
3060
				}#if end
3061
 
3062
			#debug
3063
			#var_dump(__LINE__,$line);
3064
 
3065
			#取得解密後新排程的內容
3066
			$result["content"][]=$line;
3067
 
3068
			#加密 $line
3069
			#函式說明:
3070
			#加密字串,可以用的方法有sha1,md5,password_sha,sha1可以回傳20或40的數值字串,md5可以回傳32個數值字串,password_hash可以回傳60~255個字元.
3071
			#回傳結果:
3072
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常. 
3073
			#$result["function"],當前執行的函數名稱.
3074
			#$result["content"],加密後的結果.
3075
			#$result["error"],錯誤訊息陣列.
3076
			#$result["argu"],使用的參數.
3077
			#必填參數:
3078
			#$conf["enCodeStr"],"字串",要加密的字串.
3079
			$conf["authenticate::enCodeStr"]["enCodeStr"]=$line;
3080
			#$conf["enCodeType"],"字串",加密的類型,有"sha1"與"md5"與"p_hash"與"aes256"與"qbpwcf"5種,"sha1"較耗時,"md5"較快,"p_hash"適用於密碼加密,"aes256"是對稱式加解密,"qbpwcf"是透過urlenocde、json_encode、base64_encode的結果.
3081
			$conf["authenticate::enCodeStr"]["enCodeType"]="qbpwcf";
3082
			#可省略參數:
3083
			#$conf["sha1Raw"],字串,sha1加密的結果要用20個0與1組合還是要用40位數的16進位數值,"true"代表前者,"false"代表後者,預設為"false".
3084
			#$conf["sha1Raw"]="false";
3085
			#$conf["p_hash"],字串,p_hash加密過後的字串,該參數若存在且$conf["enCodeType"]為"p_hash",則代表是要檢查$conf["enCodeStr"]是否為符合$conf["p_hash"]的密碼.
3086
			#$conf["p_hash"]="";
3087
			#$conf["keyForAes256"],字串,用來 AES256 加解密的金鑰.
3088
			#$conf["keyForAes256"]="";
3089
			#$conf["aes256Encode"],字串,"true"代表是要加密,"false"代表是要解密.
3090
			#$conf["aes256Encode"]="";
3091
			#$conf["qbpwcfDecode"],字串,若"enCodeType"為"qbpwcf",則預設為"false",代表加密;反之為"true",代表解密.
3092
			#$conf["authenticate::enCodeStr"]["qbpwcfDecode"]="true";
3093
			#參考資料:
3094
			#sha1=>http://php.net/manual/en/function.sha1.php
3095
			#md5=>http://php.net/manual/en/function.md5.php
3096
			#password_hash=>http://php.net/manual/en/function.password-hash.php
3097
			#password_verify=>http://php.net/manual/en/function.password-verify.php
3098
			#json_decode=>https://www.php.net/manual/en/function.json-decode.php
3099
			#備註:
3100
			#無.
3101
			$enCodeStr=authenticate::enCodeStr($conf["authenticate::enCodeStr"]);
3102
			unset($conf["authenticate::enCodeStr"]);
3103
 
3104
			#如果執行失敗失敗
3105
			if($enCodeStr["status"]==="false"){
3106
 
3107
				#設置錯誤識別
3108
				$result["status"]="false";
3109
 
3110
				#設置錯誤訊息
3111
				$result["error"]=$enCodeStr;
3112
 
3113
				#回傳結果
3114
				return $result;	
3115
 
3116
				}#if end
3117
 
3118
			#取得加密後的內容
3119
			$line=$enCodeStr["content"];
3120
 
3121
			#將新的內容儲存起來
3122
			$content2write[]=$line;
3123
 
3124
			}#foreach end
3125
 
3126
		#如果有要更新排程的內容
3127
		if(isset($content2write)){
3128
 
3129
			#重新寫入排程檔案.
3130
			#函式說明:
3131
			#將多行字串寫入到檔案
3132
			#回傳結果:
3133
			#$result["status"],"true"表示檔案寫入成功,"false"表示檔案寫入失敗.
3134
			#$result["error"],錯誤訊息陣列.
3135
			#$result["function"],當前執行函數的名稱.
3136
			#必填參數:
3137
			#$conf["fileName"],字串,爲要編輯的檔案名稱
3138
			$conf["fileAccess::writeMultiLine"]["fileName"]=$conf["config"];
3139
			#$conf["inputString"],字串陣列,爲要寫入到 $conf["fileName"] 裏面的內容. $conf["inputString"][$i] 代表第 $i+1 行。
3140
			$conf["fileAccess::writeMultiLine"]["inputString"]=$content2write;
3141
			#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3142
			$conf["fileAccess::writeMultiLine"]["fileArgu"]=$conf["fileArgu"];
3143
			#可省略參數:
3144
			#$conf["writeMethod"]="a";#爲檔案撰寫的方式,可省略,是複寫'a'還是,重新寫入'w',預設爲'w',重新寫入。
3145
			#參考資料:
3146
			#無.
3147
			#備註:
3148
			#無.
3149
			$writeMultiLine=fileAccess::writeMultiLine($conf["fileAccess::writeMultiLine"]);
3150
			unset($conf["fileAccess::writeMultiLine"]);
3151
 
3152
			#如果執行失敗失敗
3153
			if($writeMultiLine["status"]==="false"){
3154
 
3155
				#設置錯誤識別
3156
				$result["status"]="false";
3157
 
3158
				#設置錯誤訊息
3159
				$result["error"]=$writeMultiLine;
3160
 
3161
				#回傳結果
3162
				return $result;	
3163
 
3164
				}#if end
3165
 
3166
			}#if end
3167
 
3168
		#設置執行正常
3169
		$result["status"]="true";
3170
 
3171
		#回傳結果
3172
		return $result;
3173
 
3174
		}#function updateList end
3175
 
3176
	/*
3177
	#函式說明:
3178
	#建立unix domain socket server,依照設定檔autoService::createList建立的設定檔案來執行排程事項.
3179
	#回傳結果:
3180
	#$result["ststus"],執行是否正常,"true"代表執行正常,"false"代表執行不正常.
3181
	#$result["error"],錯誤訊息陣列.
3182
	#$result["function"],當前執行的函式名稱.
3183
	#$result["argu"],所使用的參數.
3184
	#必填參數:
3185
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
3186
	$conf["fileArgu"]=__FILE__;
3187
	#可省略參數:
3188
	#$conf["config"],字串,排程的設定檔位置,預設為"/usr/local/etc/qbpwcf-schedule.conf.php".
3189
	#$conf["config"]="";
3190
	#$conf["unixDomainSocket"],字串,unix domain socket 檔案要放在哪裡,預設為"/usr/lib/qbpwcf/qbpwcf-autoService.sock".
3191
	#$conf["unixDomainSocket"]="";
3192
	#$conf["log"],字串,要將log寫到哪個地方,若有指定就會嘗試寫log.
3193
	#$conf["log"]="";
3194
	#參考資料:
3195
	#無.
3196
	#備註:
3197
	#無.
3198
	*/
3199
	public static function daemon(&$conf){
3200
 
3201
		#初始化要回傳的變數
3202
		$result=array();
3203
 
3204
		#初始化當前執行的函數名稱
3205
		$result["function"]=__FUNCTION__;
3206
 
3207
		#如果 $conf 不為陣列
3208
		if(gettype($conf)!="array"){
3209
 
3210
			#設置執行失敗
3211
			$result["status"]="false";
3212
 
3213
			#設置執行錯誤訊息
3214
			$result["error"][]="\$conf變數須為陣列形態";
3215
 
3216
			#如果傳入的參數為 null
3217
			if($conf==null){
3218
 
3219
				#設置執行錯誤訊息
3220
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3221
 
3222
				}#if end
3223
 
3224
			#回傳結果
3225
			return $result;
3226
 
3227
			}#if end
3228
 
3229
		#取得使用的參數
3230
		$result["argu"]=$conf;
3231
 
3232
		#函式說明:
3233
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
3234
		#回傳結果:
3235
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
3236
		#$result["error"],執行不正常結束的錯訊息陣列.
3237
		#$result["simpleError"],簡單表示的錯誤訊息.
3238
		#$result["function"],當前執行的函式名稱.
3239
		#$result["argu"],設置給予的參數.
3240
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3241
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3242
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
3243
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
3244
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
3245
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
3246
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
3247
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
3248
		#必填參數:
3249
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
3250
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
3251
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
3252
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
3253
		#可省略參數:
3254
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
3255
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu");
3256
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
3257
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
3258
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
3259
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
3260
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
3261
		#$conf["canNotBeEmpty"]=array();
3262
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
3263
		#$conf["canBeEmpty"]=array();
3264
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
3265
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("config","unixDomainSocket");
3266
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
3267
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("config","unixDomainSocket","log");
3268
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
3269
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string");
3270
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
3271
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("/usr/local/etc/qbpwcf-schedule.conf.php","/usr/lib/qbpwcf/qbpwcf-autoService.sock",null);
3272
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
3273
		#$conf["disallowAllSkipableVarIsEmpty"]="";
3274
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
3275
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
3276
		#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
3277
		#$conf["disallowAllSkipableVarNotExist"]="";
3278
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
3279
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("actions","times","repeat");
3280
		#參考資料:
3281
		#array_keys=>http://php.net/manual/en/function.array-keys.php
3282
		#備註:
3283
		#無.
3284
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
3285
		unset($conf["variableCheck::checkArguments"]);
3286
 
3287
		#debug
3288
		#var_dump(__LINE__,$checkArguments);
3289
 
3290
		#如果 $checkArguments["status"] 等於 "false"
3291
		if($checkArguments["status"]==="false"){
3292
 
3293
			#設置錯誤識別
3294
			$result["status"]="false";
3295
 
3296
			#設置錯誤訊息
3297
			$result["error"]=$checkArguments;
3298
 
3299
			#回傳結果
3300
			return $result;
3301
 
3302
			}#if end
3303
 
3304
		#如果 $checkArguments["passed"] 等於 "false"
3305
		if($checkArguments["passed"]==="false"){
3306
 
3307
			#設置錯誤識別
3308
			$result["status"]="false";
3309
 
3310
			#設置錯誤訊息
3311
			$result["error"]=$checkArguments;
3312
 
3313
			#回傳結果
3314
			return $result;
3315
 
3316
			}#if end
3317
 
3318
		#初始化閒置時要給予 \QBPWCF\autoService::runList 的參數
3319
		$paramsForFuncToRunWhenIdle=array("config"=>$conf["config"],"fileArgu"=>$conf["fileArgu"]);
3320
 
3321
		#如果有指定 log 參數
3322
		if(isset($conf["log"])){
3323
 
3324
			#增加之
3325
			$paramsForFuncToRunWhenIdle["log"]=$conf["log"];
3326
 
3327
			}#if end
3328
 
3329
		#debug
3330
		#var_dump(__LINE__,$paramsForFuncToRunWhenIdle);
3331
 
3332
		#函式說明:
3333
		#建立 unix domain socket server, 僅提供具備檔案存取權限的用戶使用,預設提供可以下達任何指令的功能.
3334
		#回傳結果:
3335
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
3336
		#$result["error"],錯誤訊息陣列.
3337
		#$result["function"],當前執行的函式名稱.
3338
		#$result["serverCache"],函式結束前,儲存在serverCache的內容.
3339
		#必填參數:
3340
		#$conf["sock"],字串,socket檔案要放在哪邊,名稱為何.
3341
		$conf["sock::unixDomainSockServer"]["sock"]=$conf["unixDomainSocket"];
3342
		#$conf["fileArgu"],字串,變數__FILE__的內容.
3343
		$conf["sock::unixDomainSockServer"]["fileArgu"]=$conf["fileArgu"];
3344
		#可省略參數:
3345
		#$conf["changeOwner"],字串,要將socket檔案的擁有着權限進行修改."user.group"代表擁有者帳號為user,群組為group.
3346
		#$conf["changeOwner"]="";
3347
		#$conf["changePermission"],字串,要將socket檔案的權限設為多少.ex: "0666"(所有帳戶都有存取的權限) 或 "0660"(僅有擁有者與群組帳戶有存取的權限) 或 "0600"(只有擁有者有權限執行).
3348
		#$conf["changePermission"]="";
3349
		#$conf["sessionTimeout"],字串,當連線結束後於下一次連線間隔多久就算session timeout,server端會將記錄移除,client端需要重新拿取id,預設為300秒.
3350
		#$conf["sessionTimeout"]="300";
3351
		#$conf["addOnProcessFunc"],字串陣列,增加用於處理 json request 的函式名稱,給予的參數為array("request"=>收到的json訊息,"sock"=>用戶的socket),回傳的內容必須為陣列,例如 $res["continue"]="true"代表要繼續執行下一個addOnProcessFunc;"false"代表代表到此為止. $res["content"]="replaced content";代表要將收到的訊息取代成"replaced content". 最少要有回傳 $res["status"]數值"true"代表執行正常;"false"代表執行不正常.
3352
		#$conf["addOnProcessFunc"]=array();
3353
		#$conf["funcToRunWhenIdle"],字串陣列,當沒有事件產生時,要執行的函式名稱,給予參數為array("client"=>所有用戶,"serverCache"=>$result["serverCache"]["serverSide"]["funcToRunWhenIdle"][$funcToRunWhenIdle]).
3354
		$conf["sock::unixDomainSockServer"]["funcToRunWhenIdle"]=array("\QBPWCF\autoService::runList");
3355
		#$conf["paramsForFuncToRunWhenIdle"],2維陣列,每個元素代表指定給予funcToRunWhenIdle參數中的指定元素的參數.
3356
		$conf["sock::unixDomainSockServer"]["paramsForFuncToRunWhenIdle"]=array($paramsForFuncToRunWhenIdle);
3357
		#$conf["infoToFunction"],陣列,需要增加給addOnProcessFunc跟funcToRunWhenIdle函式的資訊,在函式中其參數的info鍵值.
3358
		#$conf["infoToFunction"]=array("debug"=>$debug);
3359
		#參考資料:
3360
		#http://php.net/manual/en/function.stream-socket-server.php
3361
		#備註:
3362
		#無.
3363
		$unixDomainSockServer=sock::unixDomainSockServer($conf["sock::unixDomainSockServer"]);
3364
		unset($conf["sock::unixDomainSockServer"]);
3365
 
3366
		#如果執行出錯
3367
		if($unixDomainSockServer["status"]==="false"){
3368
 
3369
			#設置錯誤識別
3370
			$result["status"]="false";
3371
 
3372
			#設置錯誤訊息
3373
			$result["error"]=$unixDomainSockServer;
3374
 
3375
			#回傳結果
3376
			return $result;	
3377
 
3378
			}#if end
3379
 
3380
		#設置正常識別
3381
		$result["status"]="true";
3382
 
3383
		#回傳結果
3384
		return $result;	
3385
 
3386
		}#function daemon end
3387
 
3388
	}#class autoService end
3389
 
3390
?>