Subversion Repositories php-qbpwcf

Rev

Rev 83 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 83 Rev 222
Line 7... Line 7...
7
 
7
 
8
將設定檔變數 $config 寫入到檔案裡面.
8
將設定檔變數 $config 寫入到檔案裡面.
9
 
9
 
10
*/
10
*/
11
 
11
 
-
 
12
#使用命名空間qbpwcf
-
 
13
namespace qbpwcf;
-
 
14
 
-
 
15
#初始化輸出
-
 
16
$output=array();
-
 
17
 
-
 
18
#取得 lib path
-
 
19
exec("php -f ".escapeshellarg(pathinfo(__FILE__)["dirname"]."/../../../../../usr/bin/libexec/folderOfUsrLib.php"),$output,$status);
-
 
20
 
-
 
21
#如果執行失敗
-
 
22
if($status!==0){
-
 
23
 
-
 
24
	#debug
-
 
25
	var_dump(__LINE__,$output);
-
 
26
 
-
 
27
	#結束執行,回傳shell 1.
-
 
28
	exit(1);
-
 
29
 
-
 
30
	}#if end
-
 
31
 
-
 
32
#儲存lib path
-
 
33
$folderOfUsrLib=$output[0];
-
 
34
 
-
 
35
#初始化輸出
-
 
36
$output=array();
-
 
37
 
-
 
38
#以該檔案的實際位置的 lib path 為 include path 首位
-
 
39
exec("cd ".pathinfo(__FILE__)["dirname"]."/../../../../../usr/".$folderOfUsrLib."/qbpwcf;pwd;",$output,$status);
-
 
40
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
-
 
41
 
-
 
42
#匯入套件
-
 
43
require_once("allInOneForCmd.php");
-
 
44
 
-
 
45
#建議的log位置
-
 
46
$logFile=$_SERVER["DOCUMENT_ROOT"].$_SERVER["PHP_SELF"].".log";
-
 
47
 
12
$configFile=".hta_config:server";
48
$configFile=".hta_config:server";
13
 
49
 
14
#初始化設定值
50
#初始化設定值
15
$config=array();
51
$config=array();
16
 
52
 
Line 46... Line 82...
46
$config["149.102.158.38"]["dig -x"]=$domainNames;
82
$config["149.102.158.38"]["dig -x"]=$domainNames;
47
 
83
 
48
#給予設定檔好記的名稱
84
#給予設定檔好記的名稱
49
$config[$name]=&$config["149.102.158.38"];
85
$config[$name]=&$config["149.102.158.38"];
50
 
86
 
-
 
87
#函式說明:
51
#新的設定檔內容
88
#建立供 apache 讀取的設定檔案.
-
 
89
#回傳結果:
-
 
90
#$result["status"],執行是否正常,"true"為正常,"false"為不正常.
-
 
91
#$result["error"],錯誤訊息陣列.
52
$str=base64_encode(urlencode(json_encode($config)));
92
#$result["function"],當前執行的函數名稱.
-
 
93
#$result["content"],定義對應的內容.
53
 
94
#必填參數:
-
 
95
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
54
#提示為舊的設定
96
$conf["fileArgu"]=__FILE__;
-
 
97
#$conf["configFileAddr"],字串,定義檔位置與名稱
-
 
98
$conf["configFileAddr"]=$configFile;
-
 
99
#$conf["content"],陣列,要儲存的key -> value 陣列.
55
echo "old config:".PHP_EOL;
100
$conf["content"]=$config;
56
 
-
 
57
#顯示既有的設定檔內容
101
#可省略參數:
-
 
102
#$conf["web"],是要取得網路上的檔案則為"true";反之則為"false",預設為後者.
58
system("cat ".$configFile);
103
#$conf["web"]="false";
-
 
104
#參考資料:
59
 
105
#無.
60
#換行
106
#備註:
-
 
107
#檔案內容的格式為多行json編碼然後url編碼然後base64編碼後的內容,每行代表一組定義.每組定義的json格式為php多維陣列所組成.
-
 
108
$create=config::create($conf);
61
echo PHP_EOL;
109
unset($conf);
62
 
110
 
63
#提示即將寫入的新設定
111
#如果執行失敗
64
echo "new config:".PHP_EOL;
112
if($create["status"]==="false"){
65
 
113
 
-
 
114
	#函式說明:
-
 
115
	#撰寫log
-
 
116
	#回傳結果:
-
 
117
	#$result["status"],狀態,"true"或"false".
-
 
118
	#$result["error"],錯誤訊息陣列.
-
 
119
	#$result["function"],當前函式的名稱.
66
#顯示既有的設定檔內容
120
	#$result["argu"],使用的參數.
-
 
121
	#必填參數:
-
 
122
	#$conf["path"],字串,log檔案的路徑與名稱.
67
echo $str.PHP_EOL;
123
	$conf["path"]=$logFile;
68
 
-
 
-
 
124
	#$conf["content"],any,要寫的內容,若內容不為字串則會用var_dump的格式寫入.
-
 
125
	$conf["content"]=$create;
-
 
126
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
-
 
127
	$conf["fileArgu"]=__FILE__;
69
#提示寫入新的設定
128
	#可省略參數:
-
 
129
	#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
70
echo "write new config...";
130
	#$conf["rewrite"]="false";
-
 
131
	#參考資料:
71
 
132
	#無.
72
#寫入新的設定檔
133
	#備註:
-
 
134
	#無.
73
system("echo ".$str." > ".$configFile);
135
	$record=logs::record($conf);
-
 
136
	unset($conf);
74
 
137
	
75
#提示寫入新的設定完成
138
	#結束執行
76
echo "done!".PHP_EOL;
139
	exit(1);
-
 
140
	
-
 
141
	}#if end
77
 
142
 
78
?>
143
?>