| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 625 |
liveuser |
6 |
Copyright (C) 2015~2024 Min-Jhin,Chen
|
| 1 |
liveuser |
7 |
|
|
|
8 |
This file is part of QBPWCF.
|
|
|
9 |
|
|
|
10 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
11 |
it under the terms of the GNU General Public License as published by
|
|
|
12 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
13 |
(at your option) any later version.
|
|
|
14 |
|
|
|
15 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
16 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
17 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
18 |
GNU General Public License for more details.
|
|
|
19 |
|
|
|
20 |
You should have received a copy of the GNU General Public License
|
|
|
21 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
22 |
|
|
|
23 |
*/
|
|
|
24 |
namespace qbpwcf;
|
|
|
25 |
|
| 244 |
liveuser |
26 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟維護有關的類別.
|
|
|
29 |
備註:
|
|
|
30 |
無.
|
|
|
31 |
*/
|
| 1 |
liveuser |
32 |
class maintain{
|
|
|
33 |
|
|
|
34 |
/*
|
|
|
35 |
#函式說明:
|
|
|
36 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
37 |
#回傳結果:
|
|
|
38 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
39 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
40 |
#$result["function"],當前執行的函式名稱.
|
|
|
41 |
#必填參數:
|
|
|
42 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
43 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
| 200 |
liveuser |
44 |
#可省略參數:
|
|
|
45 |
#無.
|
| 1 |
liveuser |
46 |
#參考資料:
|
|
|
47 |
#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
| 200 |
liveuser |
48 |
#備註:
|
|
|
49 |
#無.
|
| 1 |
liveuser |
50 |
*/
|
|
|
51 |
public function __call($method,$arguments){
|
|
|
52 |
|
|
|
53 |
#取得當前執行的函式
|
|
|
54 |
$result["function"]=__FUNCTION__;
|
|
|
55 |
|
|
|
56 |
#設置執行不正常
|
|
|
57 |
$result["status"]="false";
|
|
|
58 |
|
|
|
59 |
#設置執行錯誤
|
|
|
60 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
61 |
|
|
|
62 |
#設置所丟入的參數
|
|
|
63 |
$result["error"][]=$arguments;
|
|
|
64 |
|
|
|
65 |
#回傳結果
|
|
|
66 |
return $result;
|
|
|
67 |
|
|
|
68 |
}#function __call end
|
|
|
69 |
|
|
|
70 |
/*
|
|
|
71 |
#函式說明:
|
|
|
72 |
#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
|
|
|
73 |
#回傳結果:
|
|
|
74 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
76 |
#$result["function"],當前執行的函式名稱.
|
|
|
77 |
#必填參數:
|
|
|
78 |
#$method,物件,為物件實體或類別名稱,會自動置入該參數.
|
|
|
79 |
#$arguments,陣列,為呼叫方法時所用的參數.
|
| 200 |
liveuser |
80 |
#可省略參數:
|
|
|
81 |
#無.
|
| 1 |
liveuser |
82 |
#參考資料:
|
| 200 |
liveuser |
83 |
#__callStatic=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
|
|
|
84 |
#備註:
|
|
|
85 |
#無.
|
| 1 |
liveuser |
86 |
*/
|
|
|
87 |
public static function __callStatic($method,$arguments){
|
|
|
88 |
|
|
|
89 |
#取得當前執行的函式
|
|
|
90 |
$result["function"]=__FUNCTION__;
|
|
|
91 |
|
|
|
92 |
#設置執行不正常
|
|
|
93 |
$result["status"]="false";
|
|
|
94 |
|
|
|
95 |
#設置執行錯誤
|
|
|
96 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
|
|
97 |
|
|
|
98 |
#設置所丟入的參數
|
|
|
99 |
$result["error"][]=$arguments;
|
|
|
100 |
|
|
|
101 |
#回傳結果
|
|
|
102 |
return $result;
|
|
|
103 |
|
|
|
104 |
}#function __callStatic end
|
|
|
105 |
|
|
|
106 |
/*
|
|
|
107 |
#函式說明:
|
|
|
108 |
#寄送硬碟使用狀況給指定的信箱.
|
|
|
109 |
#必填參數:
|
|
|
110 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
111 |
$conf["fileArgu"]=__FILE__;
|
|
|
112 |
#$conf["username"],字串,用於認證信箱的帳戶.
|
|
|
113 |
$conf["username"]="";
|
|
|
114 |
#$conf["password"],字串,用於認證信箱的帳戶密碼.
|
|
|
115 |
$conf["password"]="";
|
|
|
116 |
#$conf["receiverMail"],陣列,收件人的信箱.
|
|
|
117 |
$conf["receiverMail"]=array("");
|
| 200 |
liveuser |
118 |
#可省略參數:
|
| 1 |
liveuser |
119 |
#$conf["sleep"],字串,要每幾秒執行一次,預設為60秒.
|
|
|
120 |
#$conf["sleep"]="60";
|
| 200 |
liveuser |
121 |
#可省略參數:
|
|
|
122 |
#無.
|
|
|
123 |
#參考資料:
|
|
|
124 |
#無.
|
|
|
125 |
#備註:
|
|
|
126 |
#無.
|
| 1 |
liveuser |
127 |
*/
|
| 200 |
liveuser |
128 |
public static function sendDiskUsageReport(&$conf){
|
| 1 |
liveuser |
129 |
|
|
|
130 |
#初始化要回傳的結果
|
|
|
131 |
$result=array();
|
|
|
132 |
|
|
|
133 |
#取得當前執行的函數名稱
|
|
|
134 |
$result["function"]=__FUNCTION__;
|
|
|
135 |
|
|
|
136 |
#如果沒有參數
|
|
|
137 |
if(func_num_args()==0){
|
|
|
138 |
|
|
|
139 |
#設置執行失敗
|
|
|
140 |
$result["status"]="false";
|
|
|
141 |
|
|
|
142 |
#設置執行錯誤訊息
|
|
|
143 |
$result["error"]="函數".$result["function"]."需要參數";
|
|
|
144 |
|
|
|
145 |
#回傳結果
|
|
|
146 |
return $result;
|
|
|
147 |
|
|
|
148 |
}#if end
|
|
|
149 |
|
|
|
150 |
#取得參數
|
|
|
151 |
$result["argu"]=$conf;
|
|
|
152 |
|
|
|
153 |
#如果 $conf 不為陣列
|
|
|
154 |
if(gettype($conf)!=="array"){
|
|
|
155 |
|
|
|
156 |
#設置執行失敗
|
|
|
157 |
$result["status"]="false";
|
|
|
158 |
|
|
|
159 |
#設置執行錯誤訊息
|
|
|
160 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
161 |
|
|
|
162 |
#如果傳入的參數為 null
|
|
|
163 |
if($conf===null){
|
|
|
164 |
|
|
|
165 |
#設置執行錯誤訊息
|
|
|
166 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
|
|
167 |
|
|
|
168 |
}#if end
|
|
|
169 |
|
|
|
170 |
#回傳結果
|
|
|
171 |
return $result;
|
|
|
172 |
|
|
|
173 |
}#if end
|
|
|
174 |
|
|
|
175 |
#檢查參數
|
|
|
176 |
#函式說明:
|
|
|
177 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
178 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
179 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
180 |
#$result["function"],當前執行的函式名稱.
|
|
|
181 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
182 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
183 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
184 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
185 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
186 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
187 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
188 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
189 |
#必填寫的參數:
|
|
|
190 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
191 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
192 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
193 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","username","password","receiverMail");
|
|
|
194 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
195 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","array");
|
|
|
196 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
197 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
198 |
#可以省略的參數:
|
|
|
199 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
200 |
#$conf["canBeEmptyString"]="false";
|
|
|
201 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
202 |
#$conf["canNotBeEmpty"]=array();
|
|
|
203 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
204 |
#$conf["canBeEmpty"]=array();
|
|
|
205 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
206 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
207 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
208 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("sleep");
|
|
|
209 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
210 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
211 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
212 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("60");
|
|
|
213 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
214 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
215 |
#參考資料來源:
|
|
|
216 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
217 |
#建議:
|
|
|
218 |
#增加可省略參數全部不能為空字串或空陣列的參數功能.
|
|
|
219 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
220 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
221 |
|
|
|
222 |
#如果檢查參數失敗
|
|
|
223 |
if($checkArguments["status"]==="false"){
|
|
|
224 |
|
|
|
225 |
#設置執行失敗
|
|
|
226 |
$result["status"]="false";
|
|
|
227 |
|
|
|
228 |
#設置執行錯誤
|
|
|
229 |
$result["error"]=$checkArguments;
|
|
|
230 |
|
|
|
231 |
#回傳結果
|
|
|
232 |
return $result;
|
|
|
233 |
|
|
|
234 |
}#if end
|
|
|
235 |
|
|
|
236 |
#如果檢查參數不通過
|
|
|
237 |
if($checkArguments["status"]==="false"){
|
|
|
238 |
|
|
|
239 |
#設置執行失敗
|
|
|
240 |
$result["status"]="false";
|
|
|
241 |
|
|
|
242 |
#設置執行錯誤
|
|
|
243 |
$result["error"]=$checkArguments;
|
|
|
244 |
|
|
|
245 |
#回傳結果
|
|
|
246 |
return $result;
|
|
|
247 |
|
|
|
248 |
}#if end
|
|
|
249 |
|
|
|
250 |
#函式說明:
|
|
|
251 |
#透過"df -h"取得伺服器上的磁碟空間用量
|
|
|
252 |
#回傳結果
|
|
|
253 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
254 |
#$result["error"],錯誤訊息陣列.
|
|
|
255 |
#$result["function"],當前執行的函數名稱.
|
|
|
256 |
#$result["argu"],使用的參數.
|
|
|
257 |
#$result["content"],磁碟空間用量.
|
|
|
258 |
#$result["oriOutput"],原始輸出的逐行內容.
|
|
|
259 |
#必填參數:
|
|
|
260 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
261 |
$conf["cmd::getStorageUsage"]["fileArgu"]=$conf["fileArgu"];
|
|
|
262 |
$getStorageUsage=cmd::getStorageUsage($conf["cmd::getStorageUsage"]);
|
|
|
263 |
unset($conf["cmd::getStorageUsage"]);
|
|
|
264 |
|
|
|
265 |
#如果執行失敗
|
|
|
266 |
if($getStorageUsage["status"]==="false"){
|
|
|
267 |
|
|
|
268 |
#設置執行失敗
|
|
|
269 |
$result["status"]="false";
|
|
|
270 |
|
|
|
271 |
#設置執行錯誤
|
|
|
272 |
$result["error"]=$getStorageUsage;
|
|
|
273 |
|
|
|
274 |
#回傳結果
|
|
|
275 |
return $result;
|
|
|
276 |
|
|
|
277 |
}#if end
|
|
|
278 |
|
|
|
279 |
#初始化純文字內容
|
|
|
280 |
$plainText="";
|
|
|
281 |
|
|
|
282 |
#初始化網頁的內容
|
|
|
283 |
$html="";
|
|
|
284 |
|
|
|
285 |
#針對每行原始結果
|
|
|
286 |
foreach($getStorageUsage["oriOutput"] as $line){
|
|
|
287 |
|
|
|
288 |
#串接plain text內容
|
|
|
289 |
$plainText=$plainText.$line."r\n";
|
|
|
290 |
|
|
|
291 |
}#foreach end
|
|
|
292 |
|
|
|
293 |
#識別是否需要警示
|
|
|
294 |
$warning=false;
|
|
|
295 |
|
|
|
296 |
#列開始
|
|
|
297 |
$html=$html."<table border=\"1px\">";
|
|
|
298 |
|
|
|
299 |
#初始化尚未設置 <thead>
|
|
|
300 |
$haveHeader=false;
|
|
|
301 |
|
|
|
302 |
#針對每行輸出結果
|
|
|
303 |
foreach($getStorageUsage["content"] as $line){
|
|
|
304 |
|
|
|
305 |
#如果尚未設置 haveHeader
|
|
|
306 |
if(!$haveHeader){
|
|
|
307 |
|
|
|
308 |
#開始 <thead>
|
|
|
309 |
$html=$html."<thead>";
|
|
|
310 |
|
|
|
311 |
#針對每個項目
|
|
|
312 |
foreach($line as $item=>$val){
|
|
|
313 |
|
|
|
314 |
$html=$html."<th>".$item."</th>";
|
|
|
315 |
|
|
|
316 |
}#foreach end
|
|
|
317 |
|
|
|
318 |
#結束 <thead>
|
|
|
319 |
$html=$html."</thead>";
|
|
|
320 |
|
|
|
321 |
#開始tbody
|
|
|
322 |
$html=$html."<tbody>";
|
|
|
323 |
|
|
|
324 |
#設置有<thead>了
|
|
|
325 |
$haveHeader=true;
|
|
|
326 |
|
|
|
327 |
}#if end
|
|
|
328 |
|
|
|
329 |
#列開始
|
|
|
330 |
$html=$html."<tr>";
|
|
|
331 |
|
|
|
332 |
#針對每個項目
|
|
|
333 |
foreach($line as $item=>$val){
|
|
|
334 |
|
|
|
335 |
#初始化fontStyle
|
|
|
336 |
$fontStyle="";
|
|
|
337 |
|
|
|
338 |
#如果是 "Use%"
|
|
|
339 |
if($item==="Use%"){
|
|
|
340 |
|
|
|
341 |
#取的比例與%
|
|
|
342 |
sscanf($val,'%d%s',$person,$sympol);
|
|
|
343 |
|
|
|
344 |
#如果大於90
|
|
|
345 |
if($person>=90){
|
|
|
346 |
|
|
|
347 |
#設置文字顏色
|
|
|
348 |
$fontStyle="style=\"color:red;font-weight:bold\";";
|
|
|
349 |
|
|
|
350 |
#設置需要警示
|
|
|
351 |
$warning=true;
|
|
|
352 |
|
|
|
353 |
}#if end
|
|
|
354 |
|
|
|
355 |
}#if end
|
|
|
356 |
|
|
|
357 |
#欄位內容
|
|
|
358 |
$html=$html."<td ".$fontStyle.">$val</td>";
|
|
|
359 |
|
|
|
360 |
}#foreach end
|
|
|
361 |
|
|
|
362 |
#列結束
|
|
|
363 |
$html=$html."</tr>";
|
|
|
364 |
|
|
|
365 |
}#foreach end
|
|
|
366 |
|
|
|
367 |
#表格結束
|
|
|
368 |
$html=$html."</tbody></table>";
|
|
|
369 |
|
|
|
370 |
#如果需要警示
|
|
|
371 |
if($warning){
|
|
|
372 |
|
|
|
373 |
#涵式說明:
|
|
|
374 |
#使用 curl 來透過SMTP伺服器寄信
|
|
|
375 |
#回傳的接結果:
|
|
|
376 |
#$result["status"],寄信的情況,若爲"true",則十之八九沒有問題.
|
|
|
377 |
#$result["error"],錯誤訊息陣列
|
|
|
378 |
#$result["function"],當前執行的函數
|
|
|
379 |
#$result["warning"],警示訊息,一些不會導致失敗但不能說是完美的問題.
|
|
|
380 |
#$result["cmd"],寄信的指令.
|
|
|
381 |
#$result["detailCmd"],較詳細的寄信指令.
|
|
|
382 |
#必填的參數:
|
|
|
383 |
#$conf["username"],字串,用來登入郵件伺服器的帳號
|
|
|
384 |
$conf["mail::curlSmtp"]["username"]=$conf["username"];
|
|
|
385 |
#$conf["password"],字串,用來登入郵件伺服器的密碼
|
|
|
386 |
$conf["mail::curlSmtp"]["password"]=$conf["password"];
|
|
|
387 |
#$conf["receiverMail"],陣列,收件人的信箱
|
|
|
388 |
$conf["mail::curlSmtp"]["receiverMail"]=$conf["receiverMail"];
|
|
|
389 |
#$conf["subject"],字串,郵件的主題
|
|
|
390 |
$conf["mail::curlSmtp"]["subject"]="磁碟空間使用狀況";
|
|
|
391 |
#$conf["plainBody"],字串,郵件本文的純文字內容.
|
|
|
392 |
$conf["mail::curlSmtp"]["plainBody"]=$plainText;
|
|
|
393 |
#$conf["htmlBody"]="";,字串,郵件本文的html內容,多媒體盡量不要用base64的方式來嵌入,因為大部分的郵件服務(Gmail)都不支援,如果是在單機上的郵件軟體就可能有支援,例如:Evolution.
|
|
|
394 |
$conf["mail::curlSmtp"]["htmlBody"]=$html;
|
|
|
395 |
#$conf["fileArgu"],字串,php內建變數「__FILE__」的內容.
|
|
|
396 |
$conf["mail::curlSmtp"]["fileArgu"]=$conf["fileArgu"];
|
|
|
397 |
#可省略的參數:
|
|
|
398 |
#$conf["mailServer"],字串,要使用的SMTP郵件伺服器網址與連接口,預設爲 smtps://smtp.gmail.com:465
|
|
|
399 |
#$conf["mailServer"]="";
|
|
|
400 |
#$conf["mailerMailDisplay"],字串,要顯示的寄件人信箱,預設爲 $conf["username"]
|
|
|
401 |
#$conf["mailerMailDisplay"]="";
|
|
|
402 |
#$conf["mailerNameDisplay"],字串,要顯示的寄件人姓名,預設爲 $conf["username"]
|
|
|
403 |
#$conf["mailerNameDisplay"]="";
|
|
|
404 |
#$conf["receiverMailDisplay"],陣列,要顯示的收件人信箱,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
405 |
#$conf["receiverMailDisplay"]="";#
|
|
|
406 |
#$conf["receiverNameDisplay"],陣列,要顯示的收件人姓名,預設爲 $conf["receiverMail"] 對應的元素.
|
|
|
407 |
#$conf["receiverNameDisplay"]="";
|
|
|
408 |
#$conf["attachment"],陣列,每個要寄送的附件路徑與檔案名稱
|
|
|
409 |
#$conf["attachment"]=array();
|
|
|
410 |
#$conf["attachmentName"],陣列,每個要寄送的附件顯示名稱,預設為$conf["attachment"]中的實際檔案名稱.
|
|
|
411 |
#$conf["attachmentName"]=array();
|
|
|
412 |
#$conf["attachmentMimeType"],陣列,每個附件的 mimeType,預設為"application/*".
|
|
|
413 |
#$conf["attachmentMimeType"]array();
|
|
|
414 |
#範例語句:
|
|
|
415 |
#curl --url smtps://smtp.gmail.com:465 -u username@gmail.com:userPassword --mail-from username@gmail.com --mail-rcpt receiver@mail.com --upload-file mail.txt -v
|
|
|
416 |
#範例信件內容:
|
|
|
417 |
#From: "userName" <username@gmail.com>
|
|
|
418 |
#To: "receiverName" <userPassword@yahoo.com.tw>
|
|
|
419 |
#Subject: This is a test
|
|
|
420 |
#本文~
|
|
|
421 |
#參考資料來源:
|
|
|
422 |
#用curl來寄信=>http://stackoverflow.com/questions/14722556/using-curl-to-send-email
|
|
|
423 |
#降低安全性標準讓curl可以使用=>https://www.google.com/settings/security/lesssecureapps
|
|
|
424 |
#信件內容header的設定=>http://jjdai.zhupiter.com/2010/10/php-%E5%A6%82%E4%BD%95%E5%82%B3%E9%80%81%E4%B8%80%E5%B0%81-mime-html-%E6%A0%BC%E5%BC%8F%E7%9A%84-email-%E4%BF%A1%E4%BB%B6/
|
|
|
425 |
#檔案每列不得超超過70個字元=>http://php.net/manual/en/function.mail.php
|
|
|
426 |
#寄信給多人=>https://github.com/curl/curl/issues/784
|
|
|
427 |
$curlSmtp=mail::curlSmtp($conf["mail::curlSmtp"]);
|
|
|
428 |
unset($conf["mail::curlSmtp"]);
|
|
|
429 |
|
|
|
430 |
#如果寄信失敗
|
|
|
431 |
if($curlSmtp["status"]==="false"){
|
|
|
432 |
|
|
|
433 |
#設置執行失敗
|
|
|
434 |
$result["status"]="false";
|
|
|
435 |
|
|
|
436 |
#設置執行錯誤
|
|
|
437 |
$result["error"]=$curlSmtp;
|
|
|
438 |
|
|
|
439 |
#回傳結果
|
|
|
440 |
return $result;
|
|
|
441 |
|
|
|
442 |
}#if end
|
|
|
443 |
|
|
|
444 |
}#if end
|
|
|
445 |
|
|
|
446 |
#暫停 $conf["sleep"] 秒
|
|
|
447 |
sleep($conf["sleep"]);
|
|
|
448 |
|
|
|
449 |
#呼叫自己
|
|
|
450 |
$sendDiskUsageReport=maintain::sendDiskUsageReport($conf);
|
|
|
451 |
unset($conf);
|
|
|
452 |
|
|
|
453 |
#如果呼叫自己失敗
|
|
|
454 |
if($sendDiskUsageReport["status"]==="false"){
|
|
|
455 |
|
|
|
456 |
#設置執行失敗
|
|
|
457 |
$result["status"]="false";
|
|
|
458 |
|
|
|
459 |
#設置執行錯誤
|
|
|
460 |
$result["error"]=$sendDiskUsageReport;
|
|
|
461 |
|
|
|
462 |
#回傳結果
|
|
|
463 |
return $result;
|
|
|
464 |
|
|
|
465 |
}#if end
|
|
|
466 |
|
|
|
467 |
}#function sendDiskUsageReport end
|
|
|
468 |
|
|
|
469 |
}#class maintain end
|
|
|
470 |
|
|
|
471 |
?>
|