Remote admin is a feature of OpenSim that allows commands to be sent to the server in order to be executed. In order to make this work, OpenSim has to be configured in the following way:
[RemoteAdmin] enabled = true ; turn remote admin on port = 10000 ; the access port access_password = "password" ; password to access the console enabled_methods = admin_console_command, admin_authenticate_user ; this pairs with the script below
after which the server should be restarted.
The following example PHP script can be used to send the command "alert hello world" to OpenSim:
<?php # include the KOS class require_once 'wasRemoteAdmin.php'; # create a new connection to the OpenSim server # with the hostname "OPENSIM" and port "10000" # using the password "password" $req = new wasRemoteAdmin('http://OPENSIM:10000', 'password'); # send the console command "show info" to OpenSim print $req->admin_console_command('alert hello world');
it will broadcast the "hello world" message to every avatar in the OpenSim instance. The script uses wasRemoteAdmin.php
that must be downloaded from below and placed in the same directory as the example.
<?php ///////////////////////////////////////////////////////////// // Wizardry and Steamworks (c) grimore.org - 2013, License: MIT // // // // Permission is hereby granted, free of charge, to any // // person obtaining a copy of this software and associated // // documentation files (the "Software"), to deal in the // // Software without restriction, //including without // // limitation the rights to use, copy, modify, merge, // // publish, distribute, sublicense, and/or sell copies of // // the Software, and to permit persons to whom the // // Software is furnished to do so, subject to the // // following conditions: // // // // The above copyright notice and this permission notice // // shall be included in all copies or substantial portions // // of the Software. // // // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS // // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO // // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER // // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR // // THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ///////////////////////////////////////////////////////////// /* Requires pear module HTTP Request2 and XML Serializer. */ require_once 'HTTP/Request2.php'; require_once 'XML/Serializer.php'; class wasRemoteAdmin { var $url; var $raPassword; var $options; function wasRemoteAdmin($url,$raPassword) { $this->url = $url; $this->raPassword = $raPassword; $this->options = array ( "indent" => " ", "linebreak" => "\n", "typeHints" => false, "addDecl" => true, "encoding" => "UTF-8", "rootName" => "methodCall", "defaultTagName" => "member", "mode" => "simplexml" ); } function admin_console_command($console_command) { $request = new HTTP_Request2($this->url, HTTP_Request2::METHOD_POST); $serializer = new XML_Serializer($this->options); $xml = array( "methodName" => htmlspecialchars('admin_console_command'), "params" => array( "param" => array( "value" => array("struct" => array( "member" => array( "name" => 'password', "value" => array( "string" => htmlspecialchars($this->raPassword) ), ), array( "name" => 'command', "value" => array( "string" => htmlspecialchars($console_command) ) ) ), ), ), ), ); $serializer->serialize($xml); $xml_load = $serializer->getSerializedData(); $request->setBody($xml_load); return $request->send()->getBody(); } function admin_authenticate_user($firstname, $lastname, $password, $tokentime) { $request = new HTTP_Request2($this->url, HTTP_Request2::METHOD_POST); $serializer = new XML_Serializer($this->options); $xml = array( "methodName" => htmlspecialchars('admin_authenticate_user'), "params" => array( "param" => array( "value" => array("struct" => array( "member" => array( "name" => 'password', "value" => array( "string" => htmlspecialchars($this->raPassword) ), ), array( "name" => 'user_firstname', "value" => htmlspecialchars($firstname) ), array( "name" => 'user_lastname', "value" => htmlspecialchars($lastname) ), array( "name" => 'user_password', "value" => htmlspecialchars($password) ), array( "name" => 'token_lifetime', "value" => htmlspecialchars($tokentime) ), ), ), ), ), ); $serializer->serialize($xml); $xml_load = $serializer->getSerializedData(); $request->setBody($xml_load); return $request->send()->getBody(); } function admin_create_user($firstname, $lastname, $password, $region_x, $region_y) { $request = new HTTP_Request2($this->url, HTTP_Request2::METHOD_POST); $serializer = new XML_Serializer($this->options); $xml = array( "methodName" => htmlspecialchars('admin_create_user'), "params" => array( "param" => array( "value" => array("struct" => array( "member" => array( "name" => 'password', "value" => array( "string" => htmlspecialchars($this->raPassword) ), ), array( "name" => 'user_firstname', "value" => htmlspecialchars($firstname) ), array( "name" => 'user_lastname', "value" => htmlspecialchars($lastname) ), array( "name" => 'user_password', "value" => htmlspecialchars($password) ), array( "name" => 'start_region_x', "value" => htmlspecialchars($region_x) ), array( "name" => 'start_region_y', "value" => htmlspecialchars($region_y) ), ), ), ), ), ); $serializer->serialize($xml); $xml_load = $serializer->getSerializedData(); $request->setBody($xml_load); return $request->send()->getBody(); } function admin_get_agents($region_name, $include_children) { $request = new HTTP_Request2($this->url, HTTP_Request2::METHOD_POST); $serializer = new XML_Serializer($this->options); $xml = array( "methodName" => htmlspecialchars('admin_get_agents'), "params" => array( "param" => array( "value" => array("struct" => array( "member" => array( "name" => 'password', "value" => array( "string" => htmlspecialchars($this->raPassword) ), ), array( "name" => 'region_name', "value" => htmlspecialchars($region_name) ), array( "name" => 'include_children', "value" => htmlspecialchars($include_children) ), ), ), ), ), ); $serializer->serialize($xml); $xml_load = $serializer->getSerializedData(); $request->setBody($xml_load); return $request->send()->getBody(); } }