From 7b94cfb0f65ce475df2ce4ebf932a03be9b633b5 Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Mon, 19 Sep 2022 17:39:01 -0300 Subject: [PATCH 01/11] Create a new table to log soap commands --- .../acore-wp-plugin/acore-wp-plugin.php | 2 ++ .../acore-wp-plugin/src/Manager/Tables.php | 29 +++++++++++++++++++ .../plugins/acore-wp-plugin/src/boot.php | 9 ++++++ 3 files changed, 40 insertions(+) create mode 100644 srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/acore-wp-plugin.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/acore-wp-plugin.php index 1facecd87..517056b79 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/acore-wp-plugin.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/acore-wp-plugin.php @@ -21,3 +21,5 @@ AnnotationRegistry::registerLoader([$loader, 'loadClass']); require ACORE_PATH_PLG . "/src/boot.php"; + +register_activation_hook( __FILE__, 'activate_acore_wp_plugin' ); diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php new file mode 100644 index 000000000..b23098eaf --- /dev/null +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php @@ -0,0 +1,29 @@ +get_charset_collate(); + + //* Create acore_soap_logs table + $table_name = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; + $sql = "CREATE TABLE $table_name ( + id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + success TINYINT(1) NOT NULL, + command TEXT NOT NULL, + result TEXT, + user_id BIGINT UNSIGNED, + order_id BIGINT UNSIGNED, + PRIMARY KEY (id) + ) $charset_collate;"; + + require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); + dbDelta( $sql ); +} diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/boot.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/boot.php index 9da3d17ba..b4486b43d 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/boot.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/boot.php @@ -16,3 +16,12 @@ require_once ACORE_PATH_PLG . 'src/Hooks/User/Include.php'; require_once ACORE_PATH_PLG . 'src/Hooks/WooCommerce/WooCommerce.php'; + +require_once ACORE_PATH_PLG . 'src/Manager/Tables.php'; + + +function activate_acore_wp_plugin() +{ + ACore\Manager\create_acore_soap_logs_table(); + do_action('activate_acore_wp_plugin'); +} From 33aa274987e53a92554585a490edfbfd31a48a8c Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Mon, 19 Sep 2022 17:47:42 -0300 Subject: [PATCH 02/11] Add logs possibility to soap command --- .../src/Components/Tools/ToolsApi.php | 2 +- .../Components/UserPanel/UserController.php | 3 +- .../src/Hooks/WooCommerce/CharChange.php | 16 ++++---- .../src/Manager/Soap/AccountService.php | 8 ++-- .../src/Manager/Soap/AcoreSoap.php | 17 +++++++- .../src/Manager/Soap/AcoreSoapTrait.php | 4 +- .../src/Manager/Soap/CharacterService.php | 40 ++++++++++++++----- .../src/Manager/Soap/MailService.php | 6 +-- 8 files changed, 65 insertions(+), 31 deletions(-) diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php index 16f31175e..106e419b0 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php @@ -13,7 +13,7 @@ public static function ItemRestoreList($request) { public static function ItemRestore($data) { $item = $data['item']; $cname = $data['cname']; - return ACoreServices::I()->getServerSoap()->executeCommand("item restore $item $cname"); + return ACoreServices::I()->getServerSoap()->executeCommand("item restore $item $cname", true); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/UserPanel/UserController.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/UserPanel/UserController.php index d4a3c2c31..92a308640 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/UserPanel/UserController.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/UserPanel/UserController.php @@ -78,7 +78,7 @@ public function showRafProgress() { if ($res instanceof \Exception) { $errorMessages[] = "The server seems to be offline, try again later!"; } else { - $res = $soap->executeCommand("bindraf $newRecruitId $recruiterCode"); + $res = $soap->executeCommand("bindraf $newRecruitId $recruiterCode", true); if ($res instanceof \Exception) { $errorMessages[] = "An error ocurred while binding accounts. Please try again later."; } @@ -129,7 +129,6 @@ public function showRafProgress() { public function showItemRestorationPage() { if ($_SERVER["REQUEST_METHOD"] == "POST") { - $this->saveCharacterOrder(); ?>

Character settings succesfully saved.

changeName($charName); + $res = $soap->changeName($charName, null, $order_id); if ($res instanceof \Exception) { throw new \Exception("There was an error with character rename on $charName - " . $res->getMessage()); } @@ -147,7 +147,7 @@ public static function payment_complete($order_id) { if (!$charName) { throw new \Exception("No character found, please check your selection."); } - $res = $soap->changeFaction($charName); + $res = $soap->changeFaction($charName, $order_id); if ($res instanceof \Exception) { throw new \Exception("There was an error with character change faction on $charName - " . $res->getMessage()); } @@ -157,7 +157,7 @@ public static function payment_complete($order_id) { if (!$charName) { throw new \Exception("No character found, please check your selection."); } - $res = $soap->changeRace($charName); + $res = $soap->changeRace($charName, $order_id); if ($res instanceof \Exception) { throw new \Exception("There was an error with character change race on $charName - " . $res->getMessage()); } @@ -167,7 +167,7 @@ public static function payment_complete($order_id) { if (!$charName) { throw new \Exception("No character found, please check your selection."); } - $res = $soap->charCustomization($charName); + $res = $soap->charCustomization($charName, $order_id); if ($res instanceof \Exception) { throw new \Exception("There was an error with character customization on $charName - " . $res->getMessage()); } @@ -175,7 +175,7 @@ public static function payment_complete($order_id) { case "char-restore-delete": $charName = $WoWSrv->getCharName($item["acore_char_sel"], true); $guid = $item["acore_char_sel"]; - self::charRestore($guid, $charName); + self::charRestore($guid, $charName, $order_id); break; } } @@ -185,7 +185,7 @@ public static function payment_complete($order_id) { } } - private static function charRestore($guid, $charName) { + private static function charRestore($guid, $charName, $order_id) { $soap = ACoreServices::I()->getCharactersSoap(); $query = "SELECT `guid`, `name` FROM `characters` WHERE `characters`.`name` = ?"; $conn = ACoreServices::I()->getCharacterEm()->getConnection(); @@ -198,13 +198,13 @@ private static function charRestore($guid, $charName) { $res = $soap->charRestore($guid, $charName . "èè"); $newName = true; } else { - $res = $soap->charRestore($guid); + $res = $soap->charRestore($guid, $order_id); } if ($res instanceof \Exception) { throw new \Exception("There was an error with character restore delete on $charName - " . $res->getMessage()); } else if ($newName) { - $res = $soap->changeName($charName . "èè"); + $res = $soap->changeName($charName . "èè", null, $order_id); if ($res instanceof \Exception) { throw new \Exception("There was an error renaming your character " . $res->getMessage()); } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AccountService.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AccountService.php index 4004285a7..1fd76a07c 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AccountService.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AccountService.php @@ -47,9 +47,9 @@ public function createAccount($name, $password) { /** * This is a static mail that won't change - * @param type $username - * @param type $email - * @return type + * @param string $username + * @param string $email + * @return mixed */ public function setAccountRegMail($username, $email) { $email = strtolower($email); @@ -83,7 +83,7 @@ public function deleteAccount($username) { // CarbonCopy tickets - https://github.com/55Honey/Acore_CarbonCopy/ public function addCCTickets($accoutName, $quantity) { - return $this->executeCommand("CCACCOUNTTICKETS $accoutName $quantity"); + return $this->executeCommand("CCACCOUNTTICKETS $accoutName $quantity", true); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php index 328d18fb7..689976367 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php @@ -18,7 +18,7 @@ public function isConfigured() return $this->params != null; } - public function executeCommand($command) + public function executeCommand($command, $logCommand = false, $orderId = null) { if (!$this->params) { throw new \Exception("Soap service is not configured, please use configure() function before!"); @@ -33,11 +33,26 @@ public function executeCommand($command) 'trace' => 1, 'keep_alive' => false //php 5.4 only )); + global $wpdb; + $userId = null; + if ($logCommand) { + $user = wp_get_current_user(); + $userId = $user->ID; + $soapLogsTableName = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; + $query = "INSERT INTO `$soapLogsTableName` (`user_id`, `command`, `success`, `result`, `order_id`) + VALUES ?, ?, ?, ?, ?"; + } try { $result = $soap->executeCommand(new \SoapParam($command, 'command')); + if ($logCommand) { + $wpdb->query($query, [$userId, $command, 1, $result, $orderId]); + } return $result; } catch (\Exception $e) { + if ($logCommand) { + $wpdb->query($query, [$userId, $command, 0, $e->getMessage(), $orderId]); + } return $e->getMessage(); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoapTrait.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoapTrait.php index db07727f8..21e8bc3ed 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoapTrait.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoapTrait.php @@ -28,8 +28,8 @@ public function configure($params) { $this->soap->configure($params); } - public function executeCommand($command) { - return $this->getSoap()->executeCommand($command); + public function executeCommand($command, $logCommand = false, $orderId = null) { + return $this->getSoap()->executeCommand($command, $logCommand, $orderId); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/CharacterService.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/CharacterService.php index 1d2a68228..cc8372dae 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/CharacterService.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/CharacterService.php @@ -8,24 +8,44 @@ class CharacterService { use AcoreSoapTrait; - public function changeName($charName, $newName = NULL) { - return $this->executeCommand(".character rename $charName $newName"); + public function changeName($charName, $newName = null, $orderId = null) { + return $this->executeCommand( + ".character rename $charName $newName", + true, + $orderId + ); } - public function changeFaction($charName) { - return $this->executeCommand(".character changefaction $charName"); + public function changeFaction($charName, $orderId = null) { + return $this->executeCommand( + ".character changefaction $charName", + true, + $orderId + ); } - public function changeRace($charName) { - return $this->executeCommand(".character changerace $charName"); + public function changeRace($charName, $orderId = null) { + return $this->executeCommand( + ".character changerace $charName", + true, + $orderId + ); } - public function charCustomization($charName) { - return $this->executeCommand(".character customize $charName"); + public function charCustomization($charName, $orderId = null) { + return $this->executeCommand( + ".character customize $charName", + true, + $orderId + ); } - public function charRestore($charGuid, $newName = NULL) { - return $this->executeCommand(".character deleted restore $charGuid $newName"); + public function charRestore($charGuid, $newName = null, $orderId = null) { + return $this->executeCommand( + ".character deleted restore $charGuid $newName", + true, + $orderId + ); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php index c212f6950..980f75fef 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php @@ -13,14 +13,14 @@ public function sendItem($playerName, $subject, $message, $itemId, $stack) { $_subject = addslashes($subject); $_itemId = intval($itemId); $_stack = intval($stack); - return $this->executeCommand('.send items ' . $playerName . ' "' . $_subject . '" "' . $_message . '" ' . $_itemId . ':' . $_stack); + return $this->executeCommand(".send items $playerName \"$_subject\" \"$_message\" $_itemId :$_stack"); } public function sendMoney($playerName, $subject, $message, $money) { $_message = addslashes(self::removeEmoji($message)); $_subject = addslashes($subject); $money = intval($money); - return $this->executeCommand('.send items ' . $playerName . ' "' . $_subject . '" "' . $_message . '" ' . $money); + return $this->executeCommand(".send items $playerName \"$_subject\" \"$_message\" $money"); } // requires https://github.com/55Honey/Acore_SendAndBind @@ -28,7 +28,7 @@ public function sendItemAndBind($guid, $message, $itemId, $stack) { $_message = addslashes(self::removeEmoji($message)); $_itemId = intval($itemId); $_stack = intval($stack); - return $this->executeCommand('.senditemandbind ' . $guid . ' ' . $_itemId . ' ' . $_stack . ' ' . $_message); + return $this->executeCommand(".senditemandbind $guid $_itemId $_stack $_message"); } public static function removeEmoji($text): string From 4d726784590513b2f6d33f6110c54c3364ab3872 Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Mon, 19 Sep 2022 20:54:04 -0300 Subject: [PATCH 03/11] Add executed datetime --- .../acore-wp-plugin/src/Manager/Soap/AcoreSoap.php | 4 ++-- .../plugins/acore-wp-plugin/src/Manager/Tables.php | 13 +++++++------ 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php index 689976367..cc86cba67 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php @@ -39,8 +39,8 @@ public function executeCommand($command, $logCommand = false, $orderId = null) $user = wp_get_current_user(); $userId = $user->ID; $soapLogsTableName = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; - $query = "INSERT INTO `$soapLogsTableName` (`user_id`, `command`, `success`, `result`, `order_id`) - VALUES ?, ?, ?, ?, ?"; + $query = "INSERT INTO `$soapLogsTableName` (`user_id`, `command`, `success`, `result`, `order_id`, `executed_at`) + VALUES ?, ?, ?, ?, ?, NOW()"; } try { diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php index b23098eaf..d9a674b3e 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php @@ -15,12 +15,13 @@ function create_acore_soap_logs_table() { //* Create acore_soap_logs table $table_name = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; $sql = "CREATE TABLE $table_name ( - id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, - success TINYINT(1) NOT NULL, - command TEXT NOT NULL, - result TEXT, - user_id BIGINT UNSIGNED, - order_id BIGINT UNSIGNED, + `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, + `success` TINYINT(1) NOT NULL, + `command` TEXT NOT NULL, + `result` TEXT, + `user_id` BIGINT UNSIGNED, + `order_id` BIGINT UNSIGNED, + `executed_at` datetime NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (id) ) $charset_collate;"; From db9b12f409e08a90dbb925dd29dedcb213aa5c9c Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Mon, 19 Sep 2022 20:57:27 -0300 Subject: [PATCH 04/11] Add view for logs --- .../src/Components/AdminPanel/AdminPanel.php | 17 ++ .../Components/AdminPanel/Pages/SoapLogs.php | 146 ++++++++++++++++++ .../AdminPanel/SettingsController.php | 78 +++++++++- .../Components/AdminPanel/SettingsView.php | 4 + .../src/Manager/Soap/AcoreSoap.php | 2 +- .../acore-wp-plugin/src/Manager/Tables.php | 1 - 6 files changed, 244 insertions(+), 4 deletions(-) create mode 100644 srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/AdminPanel.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/AdminPanel.php index 2776aa7bc..3de8a1c05 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/AdminPanel.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/AdminPanel.php @@ -59,6 +59,13 @@ function acore_tools_page() $SettingsCtrl->loadTools(); } + // mt_settings_page() displays the page content for the Test settings submenu + function acore_soap_logs_page() + { + $SettingsCtrl = new SettingsController(); + $SettingsCtrl->loadSoapLogs(); + } + // action function for above hook function acore_add_pages() { @@ -101,6 +108,16 @@ function acore_add_pages() ACORE_SLUG . '-tools', array($this, 'acore_tools_page') ); + + // Add a new submenu under Settings: + add_submenu_page( + 'acore', + __('ACore Settings Panel', Opts::I()->org_alias), + __('Soap Logs', Opts::I()->org_alias), + 'manage_options', + ACORE_SLUG . '-soap-logs', + array($this, 'acore_soap_logs_page') + ); } // action function for above hook diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php new file mode 100644 index 000000000..b319430da --- /dev/null +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php @@ -0,0 +1,146 @@ + + +
+

page_alias)?>

+

A list of the logged commands.

+
+
+
+
+
Soap Logs
+
+
+ +
+ + +
+
+ + +
+ +
+ + +
+ +
+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + "; + if ($item->success) { + echo ""; + } else { + echo ""; + } + echo ""; + echo ""; + $user_info = get_userdata($item->user_id); + echo ""; + echo ""; + echo ""; + } + ?> + +
#ResultDetailsCommandUserOrderExecuted DateTime
{$item->id}{$item->result}{$item->command}user_id) . "\">{$user_info->user_login}{$item->order_id}{$item->executed_at}
+
+
+
+
+
+ +
diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php index 949fb9af9..a26eafbd3 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php @@ -356,7 +356,7 @@ public function loadTools() { $result = ACoreServices::I()->getServerSoap()->executeCommand("item restore list"); if (strpos($result, '.item restore list')) $this->storeConf($key, $_POST[$key]); - else + else print "

Item restore service error: $result

"; } else { @@ -366,7 +366,7 @@ public function loadTools() { } // Reload configs - $this->data = $this->loadData(); + $this->data = $this->loadData(); ?>

Tools have been saved

getView()->getToolsRender(); } + public function loadSoapLogs() { + # defaults + $items = 10; + $pos = 1; + $userName = null; + $orderId = null; + $from = null; + $to = null; + + if (!is_admin()) { + wp_die(__('You do not have sufficient permissions to access this page.')); + } + global $wpdb; + $soapLogsTableName = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; + $query = "SELECT + sl.* + FROM $soapLogsTableName sl + ##JOIN USERS## + WHERE + 1=1 + ##WHERE USERS## + "; + if (isset($_GET["username"]) && !empty($_GET["username"])) { + $userName = $_GET['username']; + $query = str_replace("##JOIN USERS##", "INNER JOIN {$wpdb->users} u ON sl.user_id = u.ID", $query); + $query = str_replace("##WHERE USERS##", " AND u.user_login LIKE '%{$wpdb->_real_escape($userName)}%'", $query); + } else { + $query = str_replace("##JOIN USERS##", "", $query); + $query = str_replace("##WHERE USERS##", "", $query); + } + if (isset($_GET["order_id"]) && filter_var($_GET["order_id"], FILTER_VALIDATE_INT)) { + $orderId = (int) $_GET['order_id']; + $query .= " AND sl.order_id = $orderId"; + } + if (isset($_GET["from"]) && isset($_GET["to"])) { + $from = $wpdb->_real_escape($_GET['from']); + $to = $wpdb->_real_escape($_GET['to']); + $query .= " AND sl.executed_at BETWEEN '{$from}::00:00:00' AND '{$to}::23:59:59'"; + } + if (isset($_GET["items"]) && in_array($_GET["items"], ["10", "25", "50", "100"])) { + $items = (int) $_GET['items']; + } + if (isset($_GET["pos"])) { + $pos = (int) $_GET['pos']; + if ($pos <= 0) { + $pos = 1; + } + } + + $count = $wpdb->get_col("SELECT count(0) FROM ($query) total"); + + $offset = ($pos - 1) * $items; + $query .= " LIMIT $items OFFSET $offset"; + + $result = $wpdb->get_results($query); + $maxPage = ceil((int) $count[0] / $items); + + $data = [ + 'username' => $userName, + 'order_id' => $orderId, + 'from' => $from, + 'to' => $to, + 'items' => $items, + 'pos' => $pos, + 'count' => (int) $count[0], + 'max_page' => $maxPage, + ]; + + echo $this->getView()->getSoapLogsRender( + $data, + $result + ); + } + public function storeConf($conf, $value) { update_option($conf, $value); diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsView.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsView.php index 50256abf8..87a0f6581 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsView.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsView.php @@ -36,6 +36,10 @@ public function getToolsRender() { return $this->loadPageLayout('Tools'); } + public function getSoapLogsRender($data, $result) { + return $this->loadPageLayout('SoapLogs', ['data' => $data, 'result' => $result]); + } + private function loadPageLayout($pageName, $varExtract=null) { wp_enqueue_style('bootstrap-css', '//cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css', array(), '5.1.3'); wp_enqueue_style('acore-css', ACORE_URL_PLG . 'web/assets/css/main.css', array(), '0.1'); diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php index cc86cba67..4f4d3c153 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php @@ -40,7 +40,7 @@ public function executeCommand($command, $logCommand = false, $orderId = null) $userId = $user->ID; $soapLogsTableName = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; $query = "INSERT INTO `$soapLogsTableName` (`user_id`, `command`, `success`, `result`, `order_id`, `executed_at`) - VALUES ?, ?, ?, ?, ?, NOW()"; + VALUES (?, ?, ?, ?, ?, NOW())"; } try { diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php index d9a674b3e..fab5d4c32 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Tables.php @@ -9,7 +9,6 @@ */ function create_acore_soap_logs_table() { global $wpdb; - global $acore_db_version; $charset_collate = $wpdb->get_charset_collate(); //* Create acore_soap_logs table From e3824268731dfa442efe48629502b925c9caa9ae Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Wed, 21 Sep 2022 20:45:01 -0300 Subject: [PATCH 05/11] use
Soap Logs

-
- + +
- +
- +
@@ -58,7 +58,7 @@
  • 0): ?> - Results to from + Results to from No results From 3f8ac759ee6d50d74e2c98ce6d76eea691549c67 Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Wed, 21 Sep 2022 21:34:46 -0300 Subject: [PATCH 06/11] Fix insert query --- .../acore-wp-plugin/src/Manager/Soap/AcoreSoap.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php index 4f4d3c153..d5b438a2c 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/AcoreSoap.php @@ -38,20 +38,27 @@ public function executeCommand($command, $logCommand = false, $orderId = null) if ($logCommand) { $user = wp_get_current_user(); $userId = $user->ID; + if (!$orderId) { + $orderId = "NULL"; + } $soapLogsTableName = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; $query = "INSERT INTO `$soapLogsTableName` (`user_id`, `command`, `success`, `result`, `order_id`, `executed_at`) - VALUES (?, ?, ?, ?, ?, NOW())"; + VALUES ($userId, %s, %d, %s, $orderId, NOW())"; } try { $result = $soap->executeCommand(new \SoapParam($command, 'command')); if ($logCommand) { - $wpdb->query($query, [$userId, $command, 1, $result, $orderId]); + $wpdb->query( + $wpdb->prepare($query, [$command, 1, $result]) + ); } return $result; } catch (\Exception $e) { if ($logCommand) { - $wpdb->query($query, [$userId, $command, 0, $e->getMessage(), $orderId]); + $wpdb->query( + $wpdb->prepare($query, [$command, 0, $e->getMessage()]) + ); } return $e->getMessage(); } From 8932049aa95e908b296729652b025042a7c8f74f Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Wed, 21 Sep 2022 21:35:28 -0300 Subject: [PATCH 07/11] Fix creation process of the select query --- .../AdminPanel/SettingsController.php | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php index a26eafbd3..a616e11ad 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/SettingsController.php @@ -390,20 +390,16 @@ public function loadSoapLogs() { $soapLogsTableName = $wpdb->prefix . ACORE_SOAP_LOGS_TABLENAME; $query = "SELECT sl.* - FROM $soapLogsTableName sl - ##JOIN USERS## - WHERE - 1=1 - ##WHERE USERS## - "; + FROM $soapLogsTableName sl"; if (isset($_GET["username"]) && !empty($_GET["username"])) { $userName = $_GET['username']; - $query = str_replace("##JOIN USERS##", "INNER JOIN {$wpdb->users} u ON sl.user_id = u.ID", $query); - $query = str_replace("##WHERE USERS##", " AND u.user_login LIKE '%{$wpdb->_real_escape($userName)}%'", $query); - } else { - $query = str_replace("##JOIN USERS##", "", $query); - $query = str_replace("##WHERE USERS##", "", $query); + $query .= " INNER JOIN {$wpdb->users} u ON sl.user_id = u.ID"; + $query .= " AND u.user_login LIKE '%{$wpdb->_real_escape($userName)}%'"; } + $query .= " + WHERE + 1=1 + "; if (isset($_GET["order_id"]) && filter_var($_GET["order_id"], FILTER_VALIDATE_INT)) { $orderId = (int) $_GET['order_id']; $query .= " AND sl.order_id = $orderId"; @@ -426,7 +422,7 @@ public function loadSoapLogs() { $count = $wpdb->get_col("SELECT count(0) FROM ($query) total"); $offset = ($pos - 1) * $items; - $query .= " LIMIT $items OFFSET $offset"; + $query .= " ORDER BY id DESC LIMIT $items OFFSET $offset"; $result = $wpdb->get_results($query); $maxPage = ceil((int) $count[0] / $items); From 5147efafb65a104f5aea1980e2abb61b670a211d Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Wed, 21 Sep 2022 21:42:19 -0300 Subject: [PATCH 08/11] Improve readability in some strings --- .../Components/AdminPanel/Pages/SoapLogs.php | 39 ++++++------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php index ee43b4c8d..fcb776d54 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/SoapLogs.php @@ -44,15 +44,15 @@ 0 && $diff >= 0 ? $data["pos"] - $maxPagination : 1; - $end = $data["pos"] + $maxPagination < $data["max_page"] && $diff > 0 ? $data["pos"] + $maxPagination : $data["max_page"]; + $start = ($data["pos"] - $maxPagination > 0 && $diff >= 0) ? $data["pos"] - $maxPagination : 1; + $end = ($data["pos"] + $maxPagination < $data["max_page"] && $diff > 0) ? $data["pos"] + $maxPagination : $data["max_page"]; $link = menu_page_url(ACORE_SLUG . '-soap-logs', false); if ($data["username"]) { - $link .= "&username" . $data["username"]; + $link .= "&username=" . $data["username"]; } if ($data["order_id"]) { - $link .= "&order_id" . $data["order_id"]; + $link .= "&order_id=" . $data["order_id"]; } ?> @@ -67,9 +67,9 @@ 1) { - echo "
  • 1
  • "; + echo '
  • 1
  • '; if ($maxPagination <= $start) { - echo "
  • ...
  • "; + echo '
  • ...
  • '; } } for ($i = $start; $i <= $end; $i++) { @@ -79,13 +79,13 @@ $href = "#"; $class = " active"; } - echo "
  • $i
  • "; + echo '
  • ' . $i . '
  • '; } if ($end < $data["max_page"]) { if ($data["max_page"] - 1 != $end) { - echo "
  • ...
  • "; + echo '
  • ...
  • '; } - echo "
  • {$data["max_page"]}
  • "; + echo '
  • ' . $data["max_page"] . '
  • '; } ?> @@ -110,14 +110,14 @@ foreach ($result as $item) { echo "{$item->id}"; if ($item->success) { - echo ""; + echo ''; } else { - echo ""; + echo ''; } echo "{$item->result}"; echo "{$item->command}"; $user_info = get_userdata($item->user_id); - echo "user_id) . "\">{$user_info->user_login}"; + echo '' . $user_info->user_login . ''; echo "{$item->order_id}"; echo "{$item->executed_at}"; } @@ -128,19 +128,4 @@ -
    - From 442b074d4ba726ebffa7fab94a757c69148c14c0 Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Wed, 21 Sep 2022 21:42:30 -0300 Subject: [PATCH 09/11] Clean some code --- .../AdminPanel/Pages/ElunaSettings.php | 17 ----------------- .../AdminPanel/Pages/RealmSettings.php | 5 ++++- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/ElunaSettings.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/ElunaSettings.php index 9a6c9daf5..02332d237 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/ElunaSettings.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/ElunaSettings.php @@ -104,20 +104,3 @@ - - diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/RealmSettings.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/RealmSettings.php index 6c01d8f8b..d0f66781a 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/RealmSettings.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/AdminPanel/Pages/RealmSettings.php @@ -222,7 +222,10 @@ From 0c40220c5721026a1e35e147c9557eacce5006c0 Mon Sep 17 00:00:00 2001 From: Nicolas Aravena Date: Thu, 29 Sep 2022 20:54:41 -0300 Subject: [PATCH 11/11] Add remaining soap logger and fix send items --- .../src/Components/Tools/ToolsApi.php | 8 +++++-- .../src/Hooks/WooCommerce/ItemRestoration.php | 8 +++---- .../src/Hooks/WooCommerce/ItemSend.php | 8 +++---- .../src/Manager/Soap/GuildService.php | 8 +++++-- .../src/Manager/Soap/MailService.php | 24 ++++++++++++++----- 5 files changed, 38 insertions(+), 18 deletions(-) diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php index 106e419b0..d116dcb0f 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Components/Tools/ToolsApi.php @@ -10,10 +10,14 @@ public static function ItemRestoreList($request) { return ACoreServices::I()->getRestorableItemsByCharacter($request['cguid']); } - public static function ItemRestore($data) { + public static function ItemRestore($data, $orderId = null) { $item = $data['item']; $cname = $data['cname']; - return ACoreServices::I()->getServerSoap()->executeCommand("item restore $item $cname", true); + return ACoreServices::I()->getServerSoap()->executeCommand( + "item restore $item $cname", + true, + $orderId + ); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemRestoration.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemRestoration.php index 83f909652..9cafd5922 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemRestoration.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemRestoration.php @@ -30,7 +30,7 @@ public static function before_add_to_cart_button() { } $current_user = wp_get_current_user(); - + if ($current_user) { FieldElements::charList($current_user->user_login, false); wp_enqueue_script('power-js', 'https://wow.zamimg.com/widgets/power.js', array()); @@ -131,7 +131,7 @@ public static function payment_complete($order_id) { try { $order = new \WC_Order($order_id); $items = $order->get_items(); - + foreach ($items as $item) { if (isset($item["acore_item_sku"])) { if ($item["acore_item_sku"] == self::ITEM_RESTORATION_SKU) { @@ -148,7 +148,7 @@ public static function payment_complete($order_id) { if ($char) { $data = array('item' => $itemId, 'cname' => $char->getName()); - ToolsApi::ItemRestore($data); + ToolsApi::ItemRestore($data, $order_id); } else { throw new \Exception("Select a character!"); } @@ -232,7 +232,7 @@ function selectCharacter(charGuid) { itemList.style.display = 'none'; return; } - + document.querySelector("#itemList").innerHTML = ""; itemList.style.display = 'block'; diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemSend.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemSend.php index 1603c3b94..010fdd660 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemSend.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Hooks/WooCommerce/ItemSend.php @@ -204,13 +204,13 @@ public static function payment_complete($order_id) { $res = NULL; if ($sku->isStackable) { - $res = $soap->sendItem($charName, $obj, $msg, $sku->itemId, $qty); + $res = $soap->sendItem($charName, $obj, $msg, $sku->itemId, $qty, $order_id); // todo: use a conf to switch with senditemAndBind() - // $res = $soap->sendItemAndBind($item["acore_char_guid"], $msg, $sku->itemId, $qty); + // $res = $soap->sendItemAndBind($item["acore_char_guid"], $msg, $sku->itemId, $qty, $order_id); } else { for ($i = 0; $i < $qty; $i++) { - $res = $soap->sendItem($charName, $obj, $msg, $sku->itemId, 1); - // $res = $soap->sendItemAndBind($item["acore_char_guid"], $msg, $sku->itemId, 1); + $res = $soap->sendItem($charName, $obj, $msg, $sku->itemId, 1, $order_id); + // $res = $soap->sendItemAndBind($item["acore_char_guid"], $msg, $sku->itemId, 1, $order_id); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/GuildService.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/GuildService.php index d9a958590..a4ba43379 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/GuildService.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/GuildService.php @@ -8,7 +8,11 @@ class GuildService { use AcoreSoapTrait; - public function guildRename($oldname, $newname) { - return $this->executeCommand(".guild rename \"$oldname\" \"$newname\""); + public function guildRename($oldname, $newname, $orderId = null) { + return $this->executeCommand( + ".guild rename \"$oldname\" \"$newname\"", + true, + $orderId + ); } } diff --git a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php index 980f75fef..866639fb5 100644 --- a/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php +++ b/srv/wordpress/wp-content/plugins/acore-wp-plugin/src/Manager/Soap/MailService.php @@ -8,27 +8,39 @@ class MailService { use AcoreSoapTrait; - public function sendItem($playerName, $subject, $message, $itemId, $stack) { + public function sendItem($playerName, $subject, $message, $itemId, $stack, $orderId = null) { $_message = addslashes(self::removeEmoji($message)); $_subject = addslashes($subject); $_itemId = intval($itemId); $_stack = intval($stack); - return $this->executeCommand(".send items $playerName \"$_subject\" \"$_message\" $_itemId :$_stack"); + return $this->executeCommand( + ".send items $playerName \"$_subject\" \"$_message\" $_itemId:$_stack", + true, + $orderId + ); } - public function sendMoney($playerName, $subject, $message, $money) { + public function sendMoney($playerName, $subject, $message, $money, $orderId = null) { $_message = addslashes(self::removeEmoji($message)); $_subject = addslashes($subject); $money = intval($money); - return $this->executeCommand(".send items $playerName \"$_subject\" \"$_message\" $money"); + return $this->executeCommand( + ".send items $playerName \"$_subject\" \"$_message\" $money", + true, + $orderId + ); } // requires https://github.com/55Honey/Acore_SendAndBind - public function sendItemAndBind($guid, $message, $itemId, $stack) { + public function sendItemAndBind($guid, $message, $itemId, $stack, $orderId = null) { $_message = addslashes(self::removeEmoji($message)); $_itemId = intval($itemId); $_stack = intval($stack); - return $this->executeCommand(".senditemandbind $guid $_itemId $_stack $_message"); + return $this->executeCommand( + ".senditemandbind $guid $_itemId $_stack $_message", + true, + $orderId + ); } public static function removeEmoji($text): string