Subversion Repositories php-qbpwcf

Rev

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

Rev 192 Rev 226
Line 1... Line 1...
1
#!/usr/bin/php
1
#!/usr/bin/php
2
<?php
2
<?php
3
 
3
 
4
/*
4
/*
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
6
    Copyright (C) 2015~2024 Min-Jhin,Chen
6
    Copyright (C) 2014~2025 MIN ZHI, CHEN
7
 
7
 
8
    This file is part of QBPWCF.
8
    This file is part of QBPWCF.
9
 
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
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
11
    it under the terms of the GNU General Public License as published by
Line 17... Line 17...
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
18
    GNU General Public License for more details.
19
 
19
 
20
    You should have received a copy of the GNU General Public License
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/>.
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
    
22
 
23
*/
23
*/
24
 
24
 
25
/*
25
/*
26
 
26
 
27
備註:
27
備註:
Line 62... Line 62...
62
	#結束執行,回傳shell 1.
62
	#結束執行,回傳shell 1.
63
	exit(1);
63
	exit(1);
64
 
64
 
65
	}#if end
65
	}#if end
66
 
66
 
67
#設置 include path 
67
#設置 include path
68
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
68
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
69
 
69
 
70
#匯入外部套件
70
#匯入外部套件
71
require_once("allInOne.php");
71
require_once("allInOne.php");
72
 
72
 
Line 189... Line 189...
189
#如果有設置參數
189
#如果有設置參數
190
if(count($parseArgu["content"])>0){
190
if(count($parseArgu["content"])>0){
191
 
191
 
192
	#如果有 ipAndPort 參數
192
	#如果有 ipAndPort 參數
193
	if(isset($parseArgu["content"]["ipAndPort"])){
193
	if(isset($parseArgu["content"]["ipAndPort"])){
194
	
194
 
195
		#針對每個條件
195
		#針對每個條件
196
		foreach($parseArgu["content"]["ipAndPort"] as $ipAndPort){
196
		foreach($parseArgu["content"]["ipAndPort"] as $ipAndPort){
197
		
197
 
198
			#增加參數
198
			#增加參數
199
			$checkListen[]=array("ip"=>$ipAndPort."/tcp");
199
			$checkListen[]=array("ip"=>$ipAndPort."/tcp");
200
		
200
 
201
			}#foreach end
201
			}#foreach end
202
	
202
 
203
		}#if end
203
		}#if end
204
		
204
 
205
	#如果有 reportOnly 參數
205
	#如果有 reportOnly 參數
206
	if(isset($parseArgu["content"]["reportOnly"])){
206
	if(isset($parseArgu["content"]["reportOnly"])){
207
	
207
 
208
		#針對每個條件
208
		#針對每個條件
209
		foreach($parseArgu["content"]["reportOnly"] as $reportOnly){
209
		foreach($parseArgu["content"]["reportOnly"] as $reportOnly){
210
		
210
 
211
			#設置 reportOnly 參數要啟用
211
			#設置 reportOnly 參數要啟用
212
			$reportOnly="true";
212
			$reportOnly="true";
213
		
213
 
214
			}#foreach end
214
			}#foreach end
215
		
215
 
216
		}#if end
216
		}#if end
217
		
217
 
218
	#如果有 config 參數
218
	#如果有 config 參數
219
	if(isset($parseArgu["content"]["config"])){
219
	if(isset($parseArgu["content"]["config"])){
220
	
220
 
221
		#針對每個條件
221
		#針對每個條件
222
		foreach($parseArgu["content"]["config"] as $config){
222
		foreach($parseArgu["content"]["config"] as $config){
223
		
223
 
224
			#取得設定檔內容
224
			#取得設定檔內容
225
			#函式說明:
225
			#函式說明:
226
			#解析PHP檔案裡面的變數.
226
			#解析PHP檔案裡面的變數.
227
			#回傳結果:
227
			#回傳結果:
228
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
228
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
229
			#$result["error"],錯誤訊息.
229
			#$result["error"],錯誤訊息.
230
			#$result["function"],當前執行的函數名稱.
230
			#$result["function"],當前執行的函數名稱.
231
			#$result["argu"],所使用的參數.	
231
			#$result["argu"],所使用的參數.
232
			#$result["content"],找到的變數內容陣列.
232
			#$result["content"],找到的變數內容陣列.
233
			#$result["content"]["value"],依找到變數順序的數值.
233
			#$result["content"]["value"],依找到變數順序的數值.
234
			#$result["content"]["struc"],依找到變數順序的階層結構.
234
			#$result["content"]["struc"],依找到變數順序的階層結構.
235
			#$result["content"]["direct"],變數名稱對應的數值內容.
235
			#$result["content"]["direct"],變數名稱對應的數值內容.
236
			#必填參數:
236
			#必填參數:
Line 247... Line 247...
247
			#https://www.php.net/manual/en/function.parse-str.php
247
			#https://www.php.net/manual/en/function.parse-str.php
248
			#備註:
248
			#備註:
249
			#無.
249
			#無.
250
			$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf);
250
			$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf);
251
			unset($conf);
251
			unset($conf);
252
			
252
 
253
			#如果失敗
253
			#如果失敗
254
			if($parseVaraiableInPHPfile["status"]==="false"){
254
			if($parseVaraiableInPHPfile["status"]==="false"){
255
			
255
 
256
				#印出結果
256
				#印出結果
257
				var_dump($parseVaraiableInPHPfile);
257
				var_dump($parseVaraiableInPHPfile);
258
				
258
 
259
				#結束執行
259
				#結束執行
260
				exit;
260
				exit;
261
			
261
 
262
				}#if end
262
				}#if end
263
		
263
 
264
			#針對每個 ipAndPort 參數
264
			#針對每個 ipAndPort 參數
265
			foreach($parseVaraiableInPHPfile["content"]["ipAndPort"] as $ipAndPort){
265
			foreach($parseVaraiableInPHPfile["content"]["ipAndPort"] as $ipAndPort){
266
			
266
 
267
				#增加參數
267
				#增加參數
268
				$checkListen[]=array("ip"=>$ipAndPort."/tcp");
268
				$checkListen[]=array("ip"=>$ipAndPort."/tcp");
269
			
269
 
270
				}#foreach end
270
				}#foreach end
271
			
271
 
272
			#針對每個 reportOnly 參數
272
			#針對每個 reportOnly 參數
273
			foreach($parseVaraiableInPHPfile["content"]["reportOnly"] as $reportOnly){
273
			foreach($parseVaraiableInPHPfile["content"]["reportOnly"] as $reportOnly){
274
			
274
 
275
				#設置 reportOnly 參數要啟用
275
				#設置 reportOnly 參數要啟用
276
				$reportOnly="true";
276
				$reportOnly="true";
277
			
277
 
278
				}#foreach end
278
				}#foreach end
279
		
279
 
280
			}#foreach end
280
			}#foreach end
281
	
281
 
282
		}#if end
282
		}#if end
283
 
283
 
284
	}#if end
284
	}#if end
285
 
285
 
286
#反之
286
#反之
287
else{
287
else{
288
 
288
 
289
	#嘗試從 etc/qbpwcf/etc/sshd_config.php 取得設定
289
	#嘗試從 etc/qbpwcf/etc/sshd_config.php 取得設定
290
	
290
 
291
	#預設的設定檔案位置
291
	#預設的設定檔案位置
292
	$defaultConfigAddr=pathinfo(__FILE__)["dirname"]."/../../etc/qbpwcf/sshd_config.php";
292
	$defaultConfigAddr=pathinfo(__FILE__)["dirname"]."/../../etc/qbpwcf/sshd_config.php";
293
	
293
 
294
	#取得設定檔內容
294
	#取得設定檔內容
295
	#函式說明:
295
	#函式說明:
296
	#解析PHP檔案裡面的變數.
296
	#解析PHP檔案裡面的變數.
297
	#回傳結果:
297
	#回傳結果:
298
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
298
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
299
	#$result["error"],錯誤訊息.
299
	#$result["error"],錯誤訊息.
300
	#$result["function"],當前執行的函數名稱.
300
	#$result["function"],當前執行的函數名稱.
301
	#$result["argu"],所使用的參數.	
301
	#$result["argu"],所使用的參數.
302
	#$result["content"],找到的變數內容陣列.
302
	#$result["content"],找到的變數內容陣列.
303
	#$result["content"]["value"],依找到變數順序的數值.
303
	#$result["content"]["value"],依找到變數順序的數值.
304
	#$result["content"]["struc"],依找到變數順序的階層結構.
304
	#$result["content"]["struc"],依找到變數順序的階層結構.
305
	#$result["content"]["direct"],變數名稱對應的數值內容.
305
	#$result["content"]["direct"],變數名稱對應的數值內容.
306
	#必填參數:
306
	#必填參數:
Line 317... Line 317...
317
	#https://www.php.net/manual/en/function.parse-str.php
317
	#https://www.php.net/manual/en/function.parse-str.php
318
	#備註:
318
	#備註:
319
	#無.
319
	#無.
320
	$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf);
320
	$parseVaraiableInPHPfile=fileAccess::parseVaraiableInPHPfile($conf);
321
	unset($conf);
321
	unset($conf);
322
	
322
 
323
	#exit
323
	#exit
324
	#var_dump(__LINE__,$parseVaraiableInPHPfile);
324
	#var_dump(__LINE__,$parseVaraiableInPHPfile);
325
	
325
 
326
	#如果失敗
326
	#如果失敗
327
	if($parseVaraiableInPHPfile["status"]==="false"){
327
	if($parseVaraiableInPHPfile["status"]==="false"){
328
	
328
 
329
		#印出結果
329
		#印出結果
330
		var_dump($parseVaraiableInPHPfile);
330
		var_dump($parseVaraiableInPHPfile);
331
		
331
 
332
		#結束執行
332
		#結束執行
333
		exit;
333
		exit;
334
	
334
 
335
		}#if end
335
		}#if end
336
 
336
 
337
	#如果有指定 ipAndPort
337
	#如果有指定 ipAndPort
338
	if(isset($parseVaraiableInPHPfile["content"]["ipAndPort"])){
338
	if(isset($parseVaraiableInPHPfile["content"]["ipAndPort"])){
339
 
339
 
340
		#針對每個 ipAndPort 參數
340
		#針對每個 ipAndPort 參數
341
		foreach($parseVaraiableInPHPfile["content"]["ipAndPort"] as $ipAndPort){
341
		foreach($parseVaraiableInPHPfile["content"]["ipAndPort"] as $ipAndPort){
342
		
342
 
343
			#增加參數
343
			#增加參數
344
			$checkListen[]=array("ip"=>$ipAndPort."/tcp");
344
			$checkListen[]=array("ip"=>$ipAndPort."/tcp");
345
		
345
 
346
			}#foreach end
346
			}#foreach end
347
			
347
 
348
		}#if end
348
		}#if end
349
	
349
 
350
	#如果有指定 reportOnly
350
	#如果有指定 reportOnly
351
	if(isset($parseVaraiableInPHPfile["content"]["reportOnly"])){
351
	if(isset($parseVaraiableInPHPfile["content"]["reportOnly"])){
352
	
352
 
353
		#針對每個 reportOnly 參數
353
		#針對每個 reportOnly 參數
354
		foreach($parseVaraiableInPHPfile["content"]["reportOnly"] as $reportOnly){
354
		foreach($parseVaraiableInPHPfile["content"]["reportOnly"] as $reportOnly){
355
		
355
 
356
			#設置 reportOnly 參數要啟用
356
			#設置 reportOnly 參數要啟用
357
			$reportOnly="true";
357
			$reportOnly="true";
358
		
358
 
359
			}#foreach end
359
			}#foreach end
360
			
360
 
361
		}#if end
361
		}#if end
362
		
362
 
363
	#如果有指定 verbose
363
	#如果有指定 verbose
364
	if(isset($parseVaraiableInPHPfile["content"]["verbose"])){
364
	if(isset($parseVaraiableInPHPfile["content"]["verbose"])){
365
	
365
 
366
		#針對每個 verbose 參數
366
		#針對每個 verbose 參數
367
		foreach($parseVaraiableInPHPfile["content"]["verbose"] as $verbose){
367
		foreach($parseVaraiableInPHPfile["content"]["verbose"] as $verbose){
368
		
368
 
369
			#設置 reportOnly 參數要啟用
369
			#設置 reportOnly 參數要啟用
370
			$verbose="true";
370
			$verbose="true";
371
		
371
 
372
			}#foreach end
372
			}#foreach end
373
			
373
 
374
		}#if end
374
		}#if end
375
	
375
 
376
	}#else end
376
	}#else end
377
 
377
 
378
#函式說明:
378
#函式說明:
379
#執行 systemd 程序來確保服務是運行中.
379
#執行 systemd 程序來確保服務是運行中.
380
#回傳結果:
380
#回傳結果: