How to send commands using SOAP to AzerothCore worldserver console?

2.2k Views Asked by At

How can I run a command after enabling SOAP to AzerothCore worldserver console?

2

There are 2 best solutions below

2
On BEST ANSWER

First of all, you have to put on worldserver.conf these parameters to enable SOAP:

SOAP.Enabled = 1
SOAP.IP = "127.0.0.1"
SOAP.Port = 7878

Afterwards, run your worldserver.

You can use a simple PHP script to run a command to the AzerothCore console like the following,

If you don't have php-soap, on Linux Ubuntu you can install it using sudo apt install php-soap (or php7.2-soap).

<?php

$soap_connection_info = array(
  'soap_uri' => 'urn:AC',
  'soap_host' => '127.0.0.1',
  'soap_port' => '7878',
  'account_name' => 'USERNAME',
  'account_password' => 'PASSWORD'
);

function RemoteCommandWithSOAP($username, $password, $COMMAND)
{
    global $soap_connection_info;
    $result = '';

    try {
        $conn = new SoapClient(NULL, array(
            'location' => 'http://' . $soap_connection_info['soap_host'] . ':' . $soap_connection_info['soap_port'] . '/',
            'uri' => $soap_connection_info['soap_uri'],
            'style' => SOAP_RPC,
            'login' => $username,
            'password' => $password
        ));
        $result = $conn->executeCommand(new SoapParam($COMMAND, 'command'));
        unset($conn);
    } catch (Exception $e) {

        $result = "Have error on soap!\n";

        if (strpos($e, 'There is no such command') !== false) {
            $result = 'There is no such command!';
        }
    }
    return $result;
}

echo RemoteCommandWithSOAP($soap_connection_info['account_name'], $soap_connection_info['account_password'], ".server info");

?>

In the last line you have to change "account_name", "account_password" using an account with gm level 3.

echo RemoteCommandWithSOAP($soap_connection_info['account_name'], $soap_connection_info['account_password'], ".server info");

You can replace .server info with any command.

Note: this works with other emulators just replacing urn:AC with:
- urn:MaNGOS for CMaNGOS (and related forks)
- urn:TC for TrinityCore
- urn:SF for SkyfireProject
- urn:Oregon for OregonCore
etc...

0
On

Here is a perl script to do the same thing, it requires libsoap-lite-perl, install with apt-get install libsoap-lite-perl

Put the code below in a file named soap.pl:

#!/usr/bin/perl

use strict;
use warnings;
use SOAP::Lite; # visit http://search.cpan.org/dist/SOAP-Lite/ or apt-get install libsoap-lite-perl

my ($user, $pass) = ('gm_account', '1234');
my $host          = 'http://127.0.0.1:7878/';
my $cmd           = '.server info';

BEGIN {
    sub SOAP::Transport::HTTP::Client::get_basic_credentials {
        return $user => $pass,
    }
}

my $soap = SOAP::Lite
    ->proxy($host)
    ->uri('urn:AC');

my $rc = $soap->call('executeCommand',
            SOAP::Data->name('command')->value($cmd));

die $rc->faultstring if ($rc->fault);

print
    $rc->result;

Then start your worldserver and run like that perl soap.pl.

It should return the result of the command ".server info"