From 80c6ab8aafc95508ac1d33147a6f300f98b48001 Mon Sep 17 00:00:00 2001 From: paintballrefjosh Date: Sat, 1 Apr 2017 13:56:26 -0500 Subject: [PATCH] Fixed remote-access issues Remote access was left out of SQL queries for adding / updateing realms. Rewrote the RA socket class to be more user friendly and work with the new database structure. Fixes #43 --- core/SDL/class.rasocket.php | 34 ++++++++++++------------- inc/admin/script_files/admin.realms.php | 11 ++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/core/SDL/class.rasocket.php b/core/SDL/class.rasocket.php index 00e381b..c304f5e 100644 --- a/core/SDL/class.rasocket.php +++ b/core/SDL/class.rasocket.php @@ -209,16 +209,16 @@ private function writeDebugLog() Returns 2 if it's not authenticated @param $command the command to enter on console */ - public function executeCommand($type, $shost, $remote, $command) + public function executeCommand($type, $host, $port, $user, $pass, $command) { if($type == 0) { - if(!$this->connect($shost, $remote[1])) + if(!$this->connect($host, $port)) { return 0; } - if(!$this->auth($remote[2], $remote[3])) + if(!$this->auth($user, $pass)) { return 2; } @@ -272,7 +272,7 @@ public function executeCommand($type, $shost, $remote, $command) } else # type is SOAP { - $client = $this->soapHandle($shost, $remote); + $client = $this->soapHandle($host, $port, $user, $pass); // If multiple commands if(is_array($command)) { @@ -338,29 +338,29 @@ public function executeCommand($type, $shost, $remote, $command) // ************************************************************ // Setups the Soap Handle - private function soapHandle($shost, $remote) + private function soapHandle($host, $port, $user, $pass) { global $mwe_config; if($mwe_config['emulator'] == 'mangos') { $client = new SoapClient(NULL, array( - "location" => "http://".$shost.":".$remote[1]."/", + "location" => "http://".$host.":".$port."/", "uri" => "urn:MaNGOS", "style" => SOAP_RPC, - "login" => $remote[2], - "password" => $remote[3] + "login" => $user, + "password" => $pass )); } else { $client = new SoapClient(NULL, array( - "location" => "http://".$shost.":".$remote[1]."/", + "location" => "http://".$host.":".$port."/", "uri" => "urn:TC", "style" => SOAP_RPC, - "login" => $remote[2], - "password" => $remote[3] + "login" => $user, + "password" => $pass )); } return $client; @@ -378,17 +378,15 @@ private function soapHandle($shost, $remote) */ function send($command, $realm) { - global $RDB; + global $RDB, $DB; // Get the remote access information from the realm database - $get_remote = $RDB->selectRow("SELECT * FROM `realmlist` WHERE id='".$realm."'"); - $remote = explode(';', $get_remote['ra_info']); - $shost = $get_remote['address']; - + $remote = $DB->selectRow("SELECT ra_type, ra_port, ra_user, ra_pass FROM `mw_realm` WHERE `realm_id`='".$realm."'"); + $host = $RDB->selectCell("SELECT `address` FROM `realmlist` WHERE `id` = '$realm'"); // Make sure the remote access type is either 1 or 0 - if($remote[0] == 0 || $remote[0] == 1) + if((int)$remote['ra_type'] == 0 || (int)$remote['ra_type'] == 1) { - $result = $this->executeCommand($remote[0], $shost, $remote, $command); + $result = $this->executeCommand($remote['ra_type'], $host, $remote['ra_port'], $remote['ra_user'], $remote['ra_pass'], $command); if($result != 1) { if($result == 0) diff --git a/inc/admin/script_files/admin.realms.php b/inc/admin/script_files/admin.realms.php index f29200c..8f4762d 100644 --- a/inc/admin/script_files/admin.realms.php +++ b/inc/admin/script_files/admin.realms.php @@ -40,6 +40,9 @@ function updateRealm() if(empty($_POST['db_char_port'])) $_POST['db_char_port'] = 0; + if(empty($_POST['ra_port'])) + $_POST['ra_port'] = 0; + if($realm > 0) { $DB->query("UPDATE `mw_realm` SET @@ -53,6 +56,10 @@ function updateRealm() `db_char_port` = '".$_POST['db_char_port']."', `db_char_user` = '".$_POST['db_char_user']."', `db_char_pass` = '".$_POST['db_char_pass']."', + `ra_type` = '".$_POST['ra_type']."', + `ra_port` = '".$_POST['ra_port']."', + `ra_user` = '".$_POST['ra_user']."', + `ra_pass` = '".$_POST['ra_pass']."', `site_enabled` = '".$_POST['site_enabled']."' WHERE `realm_id` = ".$_GET['id']." "); @@ -70,6 +77,10 @@ function updateRealm() `db_char_port` = '".$_POST['db_char_port']."', `db_char_user` = '".$_POST['db_char_user']."', `db_char_pass` = '".$_POST['db_char_pass']."', + `ra_type` = '".$_POST['ra_type']."', + `ra_port` = '".$_POST['ra_port']."', + `ra_user` = '".$_POST['ra_user']."', + `ra_pass` = '".$_POST['ra_pass']."', `site_enabled` = '".$_POST['site_enabled']."', `realm_id` = ".$_GET['id']."; ");