Commit 6d0c3621 authored by Antonio.Suerte's avatar Antonio.Suerte

System Debug Settings

parent 6a160d60
...@@ -61,15 +61,4 @@ class DevComponents extends System { ...@@ -61,15 +61,4 @@ class DevComponents extends System {
date("Y-m-d H:i:s") date("Y-m-d H:i:s")
], false); ], 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
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
require_once 'DevComponents.php'; require_once 'DevComponents.php';
use Firebase\JWT\JWT; use Firebase\JWT\JWT;
use Defuse\Crypto\Crypto;
class DevTools extends DevComponents { class DevTools extends DevComponents {
...@@ -41,7 +42,7 @@ class DevTools extends DevComponents { ...@@ -41,7 +42,7 @@ class DevTools extends DevComponents {
$stops = []; $stops = [];
$isDevTokenNotPresent = empty($this -> devToken); $isDevTokenNotPresent = empty($this -> devToken);
$isPayloadNotJSONString = !$this -> isJSON($this -> payload); $isPayloadNotJSONString = !$this -> checkJSONString($this -> payload);
$conditions = [ $conditions = [
[ [
...@@ -85,7 +86,7 @@ class DevTools extends DevComponents { ...@@ -85,7 +86,7 @@ class DevTools extends DevComponents {
case "authentication":{ case "authentication":{
$decodedToken = base64_decode($this -> devToken); $decodedToken = base64_decode($this -> devToken);
if($this -> isJSON($decodedToken)){ if($this -> checkJSONString($decodedToken)){
$decodedToken = json_decode($decodedToken); $decodedToken = json_decode($decodedToken);
$devCredential = $this -> getDevCred($decodedToken -> devKey); $devCredential = $this -> getDevCred($decodedToken -> devKey);
...@@ -97,7 +98,7 @@ class DevTools extends DevComponents { ...@@ -97,7 +98,7 @@ class DevTools extends DevComponents {
try{ try{
$decodedToken = base64_decode($this -> devToken); $decodedToken = base64_decode($this -> devToken);
if($this -> isJSON($decodedToken)){ if($this -> checkJSONString($decodedToken)){
$decodedToken = json_decode($decodedToken); $decodedToken = json_decode($decodedToken);
$jwtDecodedObject = JWT::decode($decodedToken -> payload, $decodedToken -> secretKey, ["HS256"]); $jwtDecodedObject = JWT::decode($decodedToken -> payload, $decodedToken -> secretKey, ["HS256"]);
...@@ -303,7 +304,7 @@ class DevTools extends DevComponents { ...@@ -303,7 +304,7 @@ class DevTools extends DevComponents {
$settingValue = $this -> getColumnData($composerSettings, "dev_setting_value"); $settingValue = $this -> getColumnData($composerSettings, "dev_setting_value");
if($this -> isJSON($settingValue)) if($this -> checkJSONString($settingValue))
$composerSettings = json_decode($settingValue); $composerSettings = json_decode($settingValue);
$extDir = SITE_ROOT."system/lib/ext/"; $extDir = SITE_ROOT."system/lib/ext/";
...@@ -343,6 +344,215 @@ class DevTools extends DevComponents { ...@@ -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(){ public function listen(){
switch($this -> decodedPayload -> purpose){ switch($this -> decodedPayload -> purpose){
case "authentication":{ case "authentication":{
...@@ -361,6 +571,10 @@ class DevTools extends DevComponents { ...@@ -361,6 +571,10 @@ class DevTools extends DevComponents {
$this -> composing(); $this -> composing();
break; break;
} }
case "sysDebug":{
$this -> sysDebug();
break;
}
default:{ default:{
echo json_encode([ echo json_encode([
"code" => "W01", "code" => "W01",
......
...@@ -109,6 +109,21 @@ class CommonBase { ...@@ -109,6 +109,21 @@ class CommonBase {
return FALSE; 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: 提示文言多语言设置 * @function_name: 提示文言多语言设置
......
<?php <?php
use Defuse\Crypto\Crypto;
class DBAccess extends Cnnector { class DBAccess extends Cnnector {
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* @ メンバ変数 * @ メンバ変数
-------------------------------------------------------------------------*/ -------------------------------------------------------------------------*/
public $sqlXml; // SQLファイルの配列 public $sqlXml; // SQLファイルの配列
private $debugConf;
private $cryptConf;
private $containerContent;
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* @function_name: DBアクセスクラスコンストラクタ * @function_name: DBアクセスクラスコンストラクタ
...@@ -31,6 +37,7 @@ class DBAccess extends Cnnector { ...@@ -31,6 +37,7 @@ class DBAccess extends Cnnector {
throw new Exception($this -> getMessage(ERROR, E_CAN_NOT_OPEN_SQL_FILE, array()), -1); throw new Exception($this -> getMessage(ERROR, E_CAN_NOT_OPEN_SQL_FILE, array()), -1);
} }
$this -> cryptConf = $this -> getDebuggerConf();
} catch(Exception $e) { } catch(Exception $e) {
die($e -> getMessage() . '<br>'); die($e -> getMessage() . '<br>');
} }
...@@ -51,7 +58,6 @@ class DBAccess extends Cnnector { ...@@ -51,7 +58,6 @@ class DBAccess extends Cnnector {
$result; // 結果セット $result; // 結果セット
try { try {
// SQL発行 // SQL発行
$result = $this -> publishSQL($sqlId, $elementArr); $result = $this -> publishSQL($sqlId, $elementArr);
...@@ -103,7 +109,6 @@ class DBAccess extends Cnnector { ...@@ -103,7 +109,6 @@ class DBAccess extends Cnnector {
$result; // 結果セット $result; // 結果セット
try { try {
// SQL発行 // SQL発行
$result = $this -> publishSQL($sqlId, $elementArr); $result = $this -> publishSQL($sqlId, $elementArr);
...@@ -128,7 +133,7 @@ class DBAccess extends Cnnector { ...@@ -128,7 +133,7 @@ class DBAccess extends Cnnector {
$result; // 結果セット $result; // 結果セット
try { try {
$this -> debugQuery($sqlId, $elementArr);
// パラメータを設定する // パラメータを設定する
$sqlString = $this -> setElementParam($sqlId, $elementArr); $sqlString = $this -> setElementParam($sqlId, $elementArr);
...@@ -146,6 +151,58 @@ class DBAccess extends Cnnector { ...@@ -146,6 +151,58 @@ class DBAccess extends Cnnector {
// 結果セット // 結果セット
return($result); 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){ public function rawSQL($sqlString){
$result = NO_STRING; $result = NO_STRING;
......
...@@ -124,7 +124,7 @@ class DeveloperModelClass extends ModelClassEx { ...@@ -124,7 +124,7 @@ class DeveloperModelClass extends ModelClassEx {
switch($this -> getType()){ switch($this -> getType()){
case TYPE_DEV_CREDENTIAL_EDIT: case TYPE_DEV_CREDENTIAL_EDIT:
case TYPE_DEV_CREDENTIAL_MODIFY_PASSCODE: case TYPE_DEV_CREDENTIAL_MODIFY_PASSCODE:
case TYPE_DEV_CREDENTIAL_UPDATE_PASSCODE: case TYPE_DEV_CREDENTIAL_PASSCODE_UPDATE:
case TYPE_DEV_CREDENTIAL_UPDATE: case TYPE_DEV_CREDENTIAL_UPDATE:
if(!$this -> checkAdminUserAccess('DEVF', array('','1'))){ if(!$this -> checkAdminUserAccess('DEVF', array('','1'))){
$this -> popUpSessionMessage(ERROR, 'E_ERROR_NO_PAGE_ACCESS', array()); $this -> popUpSessionMessage(ERROR, 'E_ERROR_NO_PAGE_ACCESS', array());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment