Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
iwl-live
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Anthony.Suerte
iwl-live
Commits
6d0c3621
Commit
6d0c3621
authored
Oct 04, 2021
by
Antonio.Suerte
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
System Debug Settings
parent
6a160d60
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
294 additions
and
19 deletions
+294
-19
DevComponents.php
system/api/dev/DevComponents.php
+0
-11
DevTools.php
system/api/dev/DevTools.php
+218
-4
common_base.php
system/lib/common_base.php
+15
-0
db_access.php
system/lib/db_access.php
+60
-3
model.php
system/logic/developer/model.php
+1
-1
No files found.
system/api/dev/DevComponents.php
View file @
6d0c3621
...
...
@@ -61,15 +61,4 @@ class DevComponents extends System {
date
(
"Y-m-d H:i:s"
)
],
false
);
}
/**
*
* @param string $string
* @return boolean
*/
public
function
isJSON
(
$string
){
return
is_string
(
$string
)
&&
is_array
(
json_decode
(
$string
,
true
))
&&
(
json_last_error
()
==
JSON_ERROR_NONE
)
?
true
:
false
;
}
}
\ No newline at end of file
system/api/dev/DevTools.php
View file @
6d0c3621
...
...
@@ -2,6 +2,7 @@
require_once
'DevComponents.php'
;
use
Firebase\JWT\JWT
;
use
Defuse\Crypto\Crypto
;
class
DevTools
extends
DevComponents
{
...
...
@@ -41,7 +42,7 @@ class DevTools extends DevComponents {
$stops
=
[];
$isDevTokenNotPresent
=
empty
(
$this
->
devToken
);
$isPayloadNotJSONString
=
!
$this
->
isJSON
(
$this
->
payload
);
$isPayloadNotJSONString
=
!
$this
->
checkJSONString
(
$this
->
payload
);
$conditions
=
[
[
...
...
@@ -85,7 +86,7 @@ class DevTools extends DevComponents {
case
"authentication"
:
{
$decodedToken
=
base64_decode
(
$this
->
devToken
);
if
(
$this
->
isJSON
(
$decodedToken
)){
if
(
$this
->
checkJSONString
(
$decodedToken
)){
$decodedToken
=
json_decode
(
$decodedToken
);
$devCredential
=
$this
->
getDevCred
(
$decodedToken
->
devKey
);
...
...
@@ -97,7 +98,7 @@ class DevTools extends DevComponents {
try
{
$decodedToken
=
base64_decode
(
$this
->
devToken
);
if
(
$this
->
isJSON
(
$decodedToken
)){
if
(
$this
->
checkJSONString
(
$decodedToken
)){
$decodedToken
=
json_decode
(
$decodedToken
);
$jwtDecodedObject
=
JWT
::
decode
(
$decodedToken
->
payload
,
$decodedToken
->
secretKey
,
[
"HS256"
]);
...
...
@@ -303,7 +304,7 @@ class DevTools extends DevComponents {
$settingValue
=
$this
->
getColumnData
(
$composerSettings
,
"dev_setting_value"
);
if
(
$this
->
isJSON
(
$settingValue
))
if
(
$this
->
checkJSONString
(
$settingValue
))
$composerSettings
=
json_decode
(
$settingValue
);
$extDir
=
SITE_ROOT
.
"system/lib/ext/"
;
...
...
@@ -343,6 +344,215 @@ class DevTools extends DevComponents {
}
}
private
function
adminDebugCommands
(
$debugCommand
){
$action
=
explode
(
DELIMIT_SPACE
,
$debugCommand
->
action
);
if
(
$this
->
isLoopData
(
$action
)){
$debugSettings
=
$this
->
getDevSetting
(
"sys_debug_conf"
);
$debugContainer
=
LIBRARIES
.
"debug-container.txt"
;
switch
(
$action
[
NO_COUNT
]){
case
"create-debugger"
:
if
(
!@
file_exists
(
$debugContainer
)){
if
(
isset
(
$action
[
VAL_INT_1
])
&&
$action
[
VAL_INT_1
]
==
$debugCommand
->
confirm_passphrase
){
$debugPayloads
=
json_encode
([
"ip_address"
=>
[],
"my_commands"
=>
[],
"enabled"
=>
true
,
"create_time"
=>
date
(
"Y-m-d H:i:s"
),
"update_time"
=>
""
]);
$debugSettings
->
debugger_passphrase
=
$debugCommand
->
confirm_passphrase
;
$debugPayloads
=
Crypto
::
encryptWithPassword
(
$debugPayloads
,
$debugSettings
->
debugger_passphrase
);
$this
->
updateDevSetting
(
"sys_debug_conf"
,
json_encode
(
$debugSettings
));
file_put_contents
(
$debugContainer
,
$debugPayloads
);
echo
"OK"
;
}
else
echo
"Confirm Passphrase doesn't match"
;
}
else
echo
"Debug Container already exists"
;
break
;
case
"remove-debugger"
:
if
(
@
file_exists
(
$debugContainer
)){
if
(
isset
(
$action
[
VAL_INT_1
])
&&
$action
[
VAL_INT_1
]
==
$debugSettings
->
debugger_passphrase
){
$debugSettings
->
debugger_passphrase
=
NO_STRING
;
$this
->
updateDevSetting
(
"sys_debug_conf"
,
json_encode
(
$debugSettings
));
unlink
(
$debugContainer
);
echo
"OK"
;
}
else
echo
"Incorrect Passphrase."
;
}
else
echo
"Debug Container already deleted."
;
break
;
case
"change-passphrase"
:
if
(
@
file_exists
(
$debugContainer
)){
if
(
isset
(
$action
[
VAL_INT_1
])
&&
$action
[
VAL_INT_1
]
==
$debugSettings
->
debugger_passphrase
){
if
(
isset
(
$action
[
VAL_INT_2
])){
if
(
$action
[
VAL_INT_2
]
==
$debugCommand
->
confirm_passphrase
){
$containerContent
=
Crypto
::
decryptWithPassword
(
file_get_contents
(
$debugContainer
),
$action
[
VAL_INT_1
]);
$containerContent
=
json_decode
(
$containerContent
);
$containerContent
->
update_time
=
date
(
"Y-m-d H:i:s"
);
$debugSettings
->
debugger_passphrase
=
$action
[
VAL_INT_2
];
$debugPayloads
=
Crypto
::
encryptWithPassword
(
json_encode
(
$containerContent
),
$debugSettings
->
debugger_passphrase
);
$this
->
updateDevSetting
(
"sys_debug_conf"
,
json_encode
(
$debugSettings
));
file_put_contents
(
$debugContainer
,
$debugPayloads
);
echo
"OK"
;
}
else
echo
"Confirm Passphrase doesn't match"
;
}
else
echo
"New Passphrase wasn't entered."
;
}
else
echo
"Incorrect old passphrase."
;
}
break
;
default
:
echo
"Unknown admin command:
{
$action
[
NO_COUNT
]
}
"
;
break
;
}
}
}
private
function
modDebugCommands
(
$debugCommand
){
$action
=
explode
(
DELIMIT_SPACE
,
$debugCommand
->
action
);
$debugSettings
=
$this
->
getDevSetting
(
"sys_debug_conf"
);
$debugContainer
=
LIBRARIES
.
"debug-container.txt"
;
$toUpdateDebugContainer
=
false
;
if
(
$this
->
isLoopData
(
$action
)){
if
(
!@
file_exists
(
$debugContainer
)){
echo
"Debug container isn't established yet."
;
return
;
}
if
(
$debugCommand
->
passphrase
!=
$debugSettings
->
debugger_passphrase
){
echo
"Incorrect Passphrase"
;
return
;
}
$containerContent
=
Crypto
::
decryptWithPassword
(
file_get_contents
(
$debugContainer
),
$debugCommand
->
passphrase
);
$containerContent
=
json_decode
(
$containerContent
);
switch
(
$action
[
NO_COUNT
]){
case
"show.debug.settings"
:
echo
json_encode
(
$containerContent
);
break
;
case
"add.ip"
:
if
(
isset
(
$action
[
VAL_INT_1
])){
if
(
!
in_array
(
$action
[
VAL_INT_1
],
$containerContent
->
ip_address
)){
$containerContent
->
ip_address
[]
=
$action
[
VAL_INT_1
];
$toUpdateDebugContainer
=
true
;
}
else
echo
"IP Address already whitelisted!"
;
}
break
;
case
"rmv.ip"
:
if
(
isset
(
$action
[
VAL_INT_1
])){
if
(
in_array
(
$action
[
VAL_INT_1
],
$containerContent
->
ip_address
)){
foreach
(
$containerContent
->
ip_address
as
$key
=>
$ipAddr
){
if
(
$ipAddr
==
$action
[
VAL_INT_1
])
unset
(
$containerContent
->
ip_address
[
$key
]);
}
$toUpdateDebugContainer
=
true
;
}
else
echo
"IP Address not found"
;
}
break
;
case
"add.mcmd"
:
if
(
isset
(
$action
[
VAL_INT_1
])){
$displayFunc
=
isset
(
$action
[
VAL_INT_2
])
?
$action
[
VAL_INT_2
]
:
"print"
;
$preTagFormat
=
isset
(
$action
[
VAL_INT_3
])
?
$action
[
VAL_INT_3
]
:
false
;
$queryMap
=
array_map
(
function
(
$element
){
return
$element
->
query_name
;
},
$containerContent
->
my_commands
);
if
(
!
in_array
(
$action
[
VAL_INT_1
],
$queryMap
)){
$containerContent
->
my_commands
[]
=
[
"query_name"
=>
$action
[
VAL_INT_1
],
"display_func"
=>
$displayFunc
,
"dp_pre_tag"
=>
$preTagFormat
];
$toUpdateDebugContainer
=
true
;
}
else
echo
"Query name already listed."
;
}
break
;
case
"rmv.mcmd"
:
if
(
isset
(
$action
[
VAL_INT_1
])){
$queryMap
=
array_map
(
function
(
$element
){
return
$element
->
query_name
;
},
$containerContent
->
my_commands
);
if
(
in_array
(
$action
[
VAL_INT_1
],
$queryMap
)){
foreach
(
$containerContent
->
my_commands
as
$key
=>
$nested
){
if
(
$nested
->
query_name
==
$action
[
VAL_INT_1
])
unset
(
$containerContent
->
my_commands
[
$key
]);
}
$toUpdateDebugContainer
=
true
;
}
else
echo
"Query name not found"
;
}
break
;
case
"enable"
:
if
(
isset
(
$action
[
VAL_INT_1
])){
switch
(
strtolower
(
$action
[
VAL_INT_1
])){
case
"true"
:
case
"false"
:
$toUpdateDebugContainer
=
true
;
break
;
default
:
echo
"Invalid boolean value. (true|false) only"
;
break
;
}
$containerContent
->
enabled
=
filter_var
(
$action
[
VAL_INT_1
],
FILTER_VALIDATE_BOOLEAN
);
}
break
;
default
:
echo
"Unknown mod command:
{
$action
[
NO_COUNT
]
}
"
;
break
;
}
if
(
$toUpdateDebugContainer
){
$containerContent
->
update_time
=
date
(
"Y-m-d H:i:s"
);
$debugPayloads
=
Crypto
::
encryptWithPassword
(
json_encode
(
$containerContent
),
$debugSettings
->
debugger_passphrase
);
file_put_contents
(
$debugContainer
,
$debugPayloads
);
echo
"OK"
;
}
}
}
private
function
sysDebug
(){
$debugCommand
=
$this
->
decodedPayload
->
cstring
;
switch
(
$debugCommand
->
mode
){
case
"admin"
:
{
$this
->
adminDebugCommands
(
$debugCommand
);
break
;
}
case
"mod"
:
{
$this
->
modDebugCommands
(
$debugCommand
);
break
;
}
default
:
echo
"Unknown Debug Mode:
{
$debugCommand
->
mode
}
"
;
break
;
}
}
public
function
listen
(){
switch
(
$this
->
decodedPayload
->
purpose
){
case
"authentication"
:
{
...
...
@@ -361,6 +571,10 @@ class DevTools extends DevComponents {
$this
->
composing
();
break
;
}
case
"sysDebug"
:
{
$this
->
sysDebug
();
break
;
}
default
:
{
echo
json_encode
([
"code"
=>
"W01"
,
...
...
system/lib/common_base.php
View file @
6d0c3621
...
...
@@ -109,6 +109,21 @@ class CommonBase {
return
FALSE
;
}
}
/*-------------------------------------------------------------------------
* @function_name: デバッグコンフィグレーション
* @parameter : なし
* @return : bool|string
-------------------------------------------------------------------------*/
public
function
getDebuggerConf
(){
$debugContainer
=
LIBRARIES
.
"debug-container.txt"
;
if
(
@
file_exists
(
$debugContainer
)){
return
file_get_contents
(
$debugContainer
);
}
return
false
;
}
/*-------------------------------------------------------------------------
* @function_name: 提示文言多语言设置
...
...
system/lib/db_access.php
View file @
6d0c3621
<?php
use
Defuse\Crypto\Crypto
;
class
DBAccess
extends
Cnnector
{
/*-------------------------------------------------------------------------
* @ メンバ変数
-------------------------------------------------------------------------*/
public
$sqlXml
;
// SQLファイルの配列
private
$debugConf
;
private
$cryptConf
;
private
$containerContent
;
/*-------------------------------------------------------------------------
* @function_name: DBアクセスクラスコンストラクタ
...
...
@@ -31,6 +37,7 @@ class DBAccess extends Cnnector {
throw
new
Exception
(
$this
->
getMessage
(
ERROR
,
E_CAN_NOT_OPEN_SQL_FILE
,
array
()),
-
1
);
}
$this
->
cryptConf
=
$this
->
getDebuggerConf
();
}
catch
(
Exception
$e
)
{
die
(
$e
->
getMessage
()
.
'<br>'
);
}
...
...
@@ -51,7 +58,6 @@ class DBAccess extends Cnnector {
$result
;
// 結果セット
try
{
// SQL発行
$result
=
$this
->
publishSQL
(
$sqlId
,
$elementArr
);
...
...
@@ -103,7 +109,6 @@ class DBAccess extends Cnnector {
$result
;
// 結果セット
try
{
// SQL発行
$result
=
$this
->
publishSQL
(
$sqlId
,
$elementArr
);
...
...
@@ -128,7 +133,7 @@ class DBAccess extends Cnnector {
$result
;
// 結果セット
try
{
$this
->
debugQuery
(
$sqlId
,
$elementArr
);
// パラメータを設定する
$sqlString
=
$this
->
setElementParam
(
$sqlId
,
$elementArr
);
...
...
@@ -146,6 +151,58 @@ class DBAccess extends Cnnector {
// 結果セット
return
(
$result
);
}
/*-------------------------------------------------------------------------
* @function_name: デバッグクエリー
* @parameter : SQLID,パラメータ配列
* @return : bool
-------------------------------------------------------------------------*/
private
function
debugQuery
(
$sqlId
,
$elementArr
){
if
(
!
$this
->
cryptConf
)
return
false
;
if
(
!
isset
(
$this
->
debugConf
)){
$sqlString
=
$this
->
setElementParam
(
"SELECT_DEV_SETTING"
,
[
"sys_debug_conf"
]);
$result
=
$this
->
getRowData
(
$this
->
rawSQL
(
$sqlString
));
if
(
$this
->
checkJSONString
(
$result
[
"dev_setting_value"
]))
$this
->
debugConf
=
json_decode
(
$result
[
"dev_setting_value"
]);
}
$ipAddress
=
$_SERVER
[
"REMOTE_ADDR"
];
if
(
!
isset
(
$this
->
containerContent
)){
$this
->
containerContent
=
Crypto
::
decryptWithPassword
(
$this
->
cryptConf
,
$this
->
debugConf
->
debugger_passphrase
);
$this
->
containerContent
=
json_decode
(
$this
->
containerContent
);
}
if
(
!
$this
->
containerContent
->
enabled
)
return
false
;
if
(
in_array
(
$ipAddress
,
$this
->
containerContent
->
ip_address
)){
$queryMap
=
array_map
(
function
(
$element
){
return
$element
->
query_name
;
},
$this
->
containerContent
->
my_commands
);
if
(
in_array
(
$sqlId
,
$queryMap
)){
foreach
(
$this
->
containerContent
->
my_commands
as
$query
){
if
(
$query
->
query_name
==
$sqlId
){
$displayFunc
=
$query
->
display_func
;
$dispAsPreTag
=
$query
->
dp_pre_tag
;
$queryString
=
$this
->
setElementParam
(
$sqlId
,
$elementArr
);
$display
=
(
$dispAsPreTag
)
?
"<pre>
{
$queryString
}
</pre>"
:
$queryString
;
$displayFunc
==
"die"
?
die
(
$display
)
:
print
(
$display
);
break
;
}
}
}
}
return
true
;
}
public
function
rawSQL
(
$sqlString
){
$result
=
NO_STRING
;
...
...
system/logic/developer/model.php
View file @
6d0c3621
...
...
@@ -124,7 +124,7 @@ class DeveloperModelClass extends ModelClassEx {
switch
(
$this
->
getType
()){
case
TYPE_DEV_CREDENTIAL_EDIT
:
case
TYPE_DEV_CREDENTIAL_MODIFY_PASSCODE
:
case
TYPE_DEV_CREDENTIAL_
UPDATE_PASSCOD
E
:
case
TYPE_DEV_CREDENTIAL_
PASSCODE_UPDAT
E
:
case
TYPE_DEV_CREDENTIAL_UPDATE
:
if
(
!
$this
->
checkAdminUserAccess
(
'DEVF'
,
array
(
''
,
'1'
))){
$this
->
popUpSessionMessage
(
ERROR
,
'E_ERROR_NO_PAGE_ACCESS'
,
array
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment