Subversion Repositories php-qbpwcf

Rev

Rev 226 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
66 liveuser 1
#!/usr/bin/php
2
<?php
3
 
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2014~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
 
25
/*
26
說明:
27
查詢目標節點(目錄、檔案)的擁有着與權限資訊.
28
 
29
範例:
30
 
31
getNodeInfo.php --node path/node
32
*/
33
 
34
#使用命名空間qbpwcf
35
namespace qbpwcf;
36
 
37
#取得 lib path
38
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/libexec/folderOfUsrLib.php"),$output,$status);
39
 
40
#如果執行失敗
41
if($status!==0){
42
 
43
	#debug
44
	var_dump(__LINE__,$output);
45
 
46
	#結束執行,回傳shell 1.
47
	exit(1);
48
 
49
	}#if end
50
 
51
#儲存lib path
52
$folderOfUsrLib=$output[0];
53
 
54
#以該檔案的實際位置的 lib path 為 include path 首位
55
$output=array();
56
exec("cd ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../".$folderOfUsrLib."/qbpwcf").";pwd;",$output,$status);
57
 
58
#如果執行失敗
59
if($status!==0){
60
 
61
	#debug
62
	var_dump(__LINE__,$output);
63
 
64
	#結束執行,回傳shell 1.
65
	exit(1);
66
 
67
	}#if end
68
 
69
#設置 include path 
70
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
71
 
72
#匯入外部套件
73
include("allInOne.php");
74
 
75
#說明函式
76
function help(){
77
 
78
	#印出指令說明
79
	echo "Usage of ".basename(__FILE__).":".PHP_EOL; 
80
	echo "--node path/node 取得指定節點的擁有着與權限資訊".PHP_EOL;
81
 
82
	#結束執行
83
	exit;
84
 
85
	}#function help end
86
 
87
#函式說明:
88
#解析參數.
89
#回傳結果:
90
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
91
#$reuslt["error"],執行不正常結束的錯訊息陣列.
92
#$result["function"],當前執行的函式名稱.
93
#$result["content"],解析好的參數陣列.
94
#$result["content"][$key][$i],參數 $key 的 $i+1 個參數數值內容.
95
#$result["program"],字串,執行的程式名稱.
96
#必填參數:
97
#無
98
#可省略參數:
99
#$conf["helpFunc"],如果解析的參數不成對,則要執行的函式名稱.
100
$conf["helpFunc"]="help";
101
#備註:
102
#僅能在命令列底下執行.
103
#建議:
104
#以後可將參數 --a--b 的名稱與後面的數值 $value 存成 $result["a"]["b"][$i]=$value .
105
$parseArgu=cmd::parseArgu($conf);
106
unset($conf);
107
 
108
#如果解析參數失敗
109
if($parseArgu["status"]==="false"){
110
 
111
	#印出結果
112
	var_dump($parseArgu);
113
 
114
	#結束執行,回傳shell 1,代表異常.
115
	exit(1);
116
 
117
	}#if end
118
 
119
#函式說明:
120
#使用 linux 的 uuid 指令來產生 uuid 字串
121
#回傳結果:
122
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
123
#$result["error"],錯誤訊息.
124
#$result["function"],當前執行的函式名稱.
125
#$result["content"],uuid.
126
#必填參數:
127
#無.
128
#可省略參數:
129
#無.
130
#參考資料:
131
#無.
132
#備註:
133
#無.
134
$uuid=cmd::uuid();
135
 
136
#如果建立uuid失敗
137
if($uuid["status"]==="false"){
138
 
139
	#印出結果
140
	var_dump($uuid);
141
 
142
	#結束執行,回傳shell 1,代表異常.
143
	exit(1);
144
 
145
	}#if end
146
 
147
#檢查參數
148
#函式說明:
149
#檢查必填與可省略參數,可省略參數可指定預設要給與什麼數值內容。
150
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
151
#$reuslt["error"],執行不正常結束的錯訊息陣列.
152
#$result["function"],當前執行的函式名稱.
153
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
154
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
155
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
156
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
157
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
158
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
159
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
160
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
161
#必填寫的參數:
162
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
163
$conf["varInput"]=&$parseArgu["content"];
164
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
165
$conf["referenceVarKey"]="variableCheck::checkArguments";
166
#可以省略的參數:
167
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
168
$conf["mustBeFilledVariableName"]=array("node");
169
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
170
$conf["mustBeFilledVariableType"]=array("array");
171
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
172
#$conf["canBeEmptyString"]="false";
173
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
174
#$conf["canNotBeEmpty"]=array();
175
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
176
#$conf["canBeEmpty"]=array();
177
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
178
#$conf["skipableVariableCanNotBeEmpty"]=array("backTime");
179
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
180
#$conf["skipableVariableName"]=array("daemon","socket","config","log","action","startTime","startDate","repeat","uuid","cycleTime","fixedMonth","fixedDay","fixedHour","fixedMin","getList");
181
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
182
#$conf["skipableVariableType"]=array("array","array","array","array","array","array","array","array","array","array","array","array","array","array","array");
183
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
184
#$conf["skipableVarDefaultValue"]=array(null,null,null,array("/var/log/auto.log"),null,null,null,array(array("times"=>"-1")),null,null,null,null,null,null,null);
185
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
186
#$conf["variableCheck::checkArguments"]["disallowAllSkipableVarIsEmpty"]="false";
187
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
188
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
189
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
190
#$conf["arrayCountEqualCheck"][]=array();
191
#參考資料來源:
192
#array_keys=>http://php.net/manual/en/function.array-keys.php
193
$checkArguments=variableCheck::checkArguments($conf);
194
unset($conf);
195
 
196
#若執行失敗
197
if($checkArguments["status"]==="false"){
198
 
199
	#印出結果
200
	var_dump($checkArguments);
201
 
202
	#結束執行,回傳shell 1,代表異常.
203
	exit(1);
204
 
205
	}#if end
206
 
207
#若檢查不通過
208
if($checkArguments["passed"]==="false"){
209
 
210
	#提示用法
211
	help();
212
 
213
	#結束執行
214
	exit;
215
 
216
	}#if end
217
 
218
#取得 node 參數
219
$node=$parseArgu["content"]["node"][0];
220
 
221
#取得 node 的擁有着與權限資訊
222
#函式說明:
223
#取得節點的資訊.
224
#回傳結果:
225
#$result["status"],"true"爲建立成功,"false"爲建立失敗.
226
#$result["error"],錯誤訊息陣列.
227
#$result["function"],函數名稱. 
228
#$result["content"],檔案資訊陣列.
229
#$result["content"]["is_folder"],是否為目錄,"true"代表是,"false"代表不是.	
230
#$result["content"]["ownerPerm"],檔案擁有者權限資訊.
231
#$result["content"]["groupPerm"],檔案歸屬群組權限資訊.
232
#$result["content"]["otherPerm"],檔案對於其他身份使用者的權限資訊.
233
#$result["content"]["subElementCount"],目錄底下的檔案目錄數量.
234
#$result["content"]["ownerName"],檔案擁有着資訊.
235
#$result["content"]["groupName"],檔案所屬擁有着資訊.
236
#$result["content"]["size"],檔案大小.
237
#$result["content"]["modifyDate"],檔案變更年月日.
238
#$result["content"]["modifyTime"],檔案變更時分秒.
239
#$result["content"]["modifyTimeFloat"],檔案變更時間秒的float數值.
240
#$result["content"]["timezone"],檔案變更時間的時區與UTC的差距.
241
#必填參數:
242
#$conf["fileArgu"],字串,當前檔案的位置亦即__FILE__的內容.
243
$conf["fileArgu"]=__FILE__;
244
#$conf["file"],字串,要查看擁有者資訊的檔案.
245
$conf["file"]=$node;
246
#可省略參數:
247
#$conf["web"],檔案是否位於網站上"true",若是在檔案系統則為"false",預設為"true".
248
$conf["web"]="false";
249
#參考資料:
250
#fileowner=>http://php.net/manual/en/function.fileowner.php
251
#posix_getpwuid=>http://php.net/manual/en/function.posix-getpwuid.php
252
#備註:
253
#無.
254
$fileInfo=fileAccess::fileInfo($conf);
255
unset($conf);
256
 
257
#如果執行異常
258
if($fileInfo["status"]==="false"){
259
 
260
	#印出結果
261
	var_dump($fileInfo);
262
 
263
	#結束執行,回傳shell 1,代表異常.
264
	exit(1);
265
 
266
	}#if end
267
 
268
#印出結果
269
echo json_encode($fileInfo["content"]);