RemoteAdmin/de

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
(PHP Beispiele)
Line 27: Line 27:
  
 
== PHP Beispiele ==
 
== PHP Beispiele ==
 
+
OpenSimRemoteClass.php - PHP 8
RemoteAdminTest.php (ACHTUNG: $params nicht $parameters BEACHTEN!)
+
 
+
 
<source lang="php">
 
<source lang="php">
 
 
<?php
 
<?php
 +
/*
 +
    // PHP Example for handling
  
// Dieses Beispiel gibt eine Meldung heraus und fährt OpenSim herunter
+
    // Include the class file
//
+
    require_once 'OpenSimRemoteClass.php';
// admin_broadcast ist das kommando für Nachrichten
+
// $params hier wird die Meldung hineingeschrieben
+
//
+
// Das Kommando admin_shutdown fährt OpenSim herunter
+
  
 +
    // Instantiate the OpenSimRemoteClass object with required parameters
 +
    $OpenSimulatorURL = 'example.com';
 +
    $OpenSimulatorPort = 1234;
 +
    $OpenSimPassword = 'your_password';
  
 +
    $openSim = new OpenSimRemoteClass($OpenSimulatorURL, $OpenSimulatorPort, $OpenSimPassword);
  
include('RemoteAdmin.php'); // RemoteAdmin.php Ist der Name der PHP-Klasse
+
    // Example command and parameters
 +
    $command = 'example_command';
 +
    $params = array(
 +
        'param1' => 'value1',
 +
        'param2' => 'value2'
 +
    );
  
// Instanzieren der Klasse (IP oder Adresse, Port, Passwort)
+
    // Send the command to the simulator
$myRA = new RemoteAdmin('127.0.0.1', 9000, 'secret');
+
    $response = $openSim->SendCommand($command, $params);
 
+
// RemoteAdmin-Befehle ausführen
+
$params = array('message' => 'Diese Nachricht wird an alle Regionen des OpenSimulators gesendet!');
+
 
+
$myRA->SendCommand('admin_broadcast', $params);
+
 
+
// Wenn für einen RemoteAdmin-Befehl keine Parameter benötigt,
+
// müssen Sie den zweiten Parameter in der Funktion SendCommand nicht angeben.
+
$myRA->SendCommand('admin_shutdown');  
+
  
 +
    // Display the response
 +
    echo "Response from simulator:\n";
 +
    print_r($response);
 +
*/
 
?>
 
?>
  
</source>
+
<?php
 +
class OpenSimRemoteClass
 +
{
 +
    // Properties to store simulator URL, port, and OpenSimPassword
 +
    private $OpenSimulatorURL;
 +
    private $OpenSimulatorPort;
 +
    private $OpenSimPassword;
  
RemoteAdmin.php
+
    // Constructor to initialize the class with required parameters
 +
    public function __construct($sURL, $sPort, $pass)
 +
    {
 +
        $this->OpenSimulatorURL = $sURL;
 +
        $this->OpenSimulatorPort = $sPort;
 +
        $this->OpenSimPassword = $pass;
 +
    }
  
<source lang="php">
+
    // Method to send a command to the simulator
 +
    public function SendCommand($command, $params = [])
 +
    {
 +
        // Extract parameter names and values
 +
        $paramsNames = array_keys($params);
 +
        $paramsValues = array_values($params);
  
<?php
+
        // Construct the XML-RPC request
+
        $xml = '<methodCall><methodName>' . htmlspecialchars($command) . '</methodName><params><param><value><struct><member><name>OpenSimPassword</name><value><string>' . htmlspecialchars($this->OpenSimPassword) . '</string></value></member>';
/***********************************************************************
+
       
 +
        // Add parameters to the XML-RPC request if any
 +
        if (count($params) != 0)
 +
        {
 +
            foreach ($params as $paramName => $paramValue)
 +
            {
 +
                $xml .= '<member><name>' . htmlspecialchars($paramName) . '</name><value>' . htmlspecialchars($paramValue) . '</value></member>';
 +
            }
 +
        }
  
+
        // Complete the XML-RPC request
Copyright (c) 2008, The New World Grid Regents http://www.newworldgrid.com and Contributors
+
        $xml .= '</struct></value></param></params></methodCall>';
All rights reserved.
+
  
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
        // Set up connection parameters
 +
        $host = $this->OpenSimulatorURL;
 +
        $port = $this->OpenSimulatorPort;
 +
        $timeout = 5;
  
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
        // Suppress error reporting
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer
+
        error_reporting(0);
in the documentation and/or other materials provided with the distribution.
+
* Neither the name of the New World Grid nor the names of its contributors may be used to endorse or promote products derived
+
from this software without specific prior written permission.
+
  
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+
        // Open a network connection to the simulator
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+
        $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,  
+
        if (!$fp)
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;  
+
        {
OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+
            return FALSE; // Unable to establish connection
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
        }
 +
        else
 +
        {
 +
            // Send the XML-RPC request
 +
            fputs($fp, "POST / HTTP/1.1\r\n");
 +
            fputs($fp, "Host: $host\r\n");
 +
            fputs($fp, "Content-type: text/xml\r\n");
 +
            fputs($fp, "Content-length: ". strlen($xml) ."\r\n");
 +
            fputs($fp, "Connection: close\r\n\r\n");
 +
            fputs($fp, $xml);
  
 +
            // Read server response
 +
            $res = "";
 +
            while(!feof($fp)) {
 +
                $res .= fgets($fp, 128);
 +
            }
 +
            fclose($fp);
  
***********************************************************************/
+
            // Extract and parse the response
+
            $response = substr($res, strpos($res, "\r\n\r\n"));;
+
            $result = [];
// How to instantiate a RemoteAdmin object ?
+
            if (preg_match_all('#<name>(.+)</name><value><(string|int)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) {
// $myremoteadmin = new RemoteAdmin("mySimulatorURL", Port, "secret password")
+
                foreach($regs as $key => $val) {
 
+
                    $result[$val[1]] = $val[3];
 
+
                }
// How to send commands to remoteadmin plugin ?
+
            }
// $myremoteadmin->SendCommand('admin_broadcast', array('message' => 'Message to broadcast to all regions'));
+
            return $result; // Return parsed response
// $myremoteadmin->SendCommand('admin_shutdown');
+
        }  
// Commands like admin_shutdown don't need params, so you can left the second SendCommand functino param empty ;)
+
    }  
+
}  
// Example for error handling
+
//
+
// include('classes/RemoteAdmin.php');
+
// $RA = new RemoteAdmin('localhost', 9000, 'secret');
+
// $retour = $RA->SendCommand('admin_shutdown');
+
// if ($retour === FALSE)
+
// {
+
// echo 'ERROR';
+
// }
+
+
+
+
class RemoteAdmin
+
{
+
+
function RemoteAdmin($sURL, $sPort, $pass)
+
{
+
+
$this->simulatorURL = $sURL; // String
+
$this->simulatorPort = $sPort; // Integer
+
$this->password = $pass;
+
+
}
+
+
function SendCommand($command, $params=array())
+
{
+
+
$paramsNames = array_keys($params);
+
$paramsValues = array_values($params);
+
+
// Building the XML data to pass to RemoteAdmin through XML-RPC ;)
+
+
$xml = '<methodCall>
+
<methodName>' . htmlspecialchars($command) . '</methodName>
+
<params>
+
<param>
+
<value>
+
<struct>
+
<member>
+
<name>password</name>
+
<value><string>' . htmlspecialchars($this->password) . '</string></value>
+
</member>';
+
if (count($params) != 0)
+
{
+
+
for ($p = 0; $p < count($params); $p++)
+
{
+
+
$xml .= '<member><name>' . htmlspecialchars($paramsNames[$p]) . '</name>';
+
$xml .= '<value>' . htmlspecialchars($paramsValues[$p]) . '</value></member>';
+
+
}
+
+
}
+
+
$xml .= ' </struct>
+
</value>
+
</param>
+
</params>
+
</methodCall>';
+
+
//
+
// echo $xml;
+
//
+
+
+
// Now building headers and sending the data ;)
+
$host = $this->simulatorURL;
+
$port = $this->simulatorPort;
+
$timeout = 5; // Timeout in seconds
+
+
error_reporting(0);
+
+
$fp = fsockopen($host, $port, $errno, $errstr, $timeout);
+
if (!$fp)
+
{
+
return FALSE; // If contacting host timeouts or impossible to create the socket, the method returns FALSE
+
}
+
else
+
{
+
fputs($fp, "POST / HTTP/1.1\r\n");
+
fputs($fp, "Host: $host\r\n");
+
fputs($fp, "Content-type: text/xml\r\n");
+
fputs($fp, "Content-length: ". strlen($xml) ."\r\n");
+
fputs($fp, "Connection: close\r\n\r\n");
+
fputs($fp, $xml);
+
$res = "";
+
while(!feof($fp)) {
+
$res .= fgets($fp, 128);
+
}
+
fclose($fp);
+
$response = substr($res, strpos($res, "\r\n\r\n"));;
+
+
// Now parsing the XML response from RemoteAdmin ;)
+
+
$result = array();
+
if (preg_match_all('#<name>(.+)</name><value><(string|int)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) {
+
  foreach($regs as $key=>$val) {
+
$result[$val[1]] = $val[3];
+
  }
+
}
+
return $result;
+
}
+
+
}
+
+
}
+
+
 
?>
 
?>
 
 
</source>
 
</source>
  

Revision as of 14:20, 23 March 2024


Contents

Einführung

RemoteAdmin ist eine Schnittstelle des OpenSimulator, die verschiedene Operationen können außerhalb des OpenSimulator ausgeführt werden. Operationen, die sich selbst auf den Simulator beziehen (zB teleport user) sind immer verfügbar. Diejenigen, die sich auf Griddienstleistungen (user creation und updating) beziehen, sind nur im Standalone-Modus Verfügbar. Im Gridmodus, muss man die ROBUST Ebene verwenden UserManipulation statt Fähigkeiten.

Das Remote Admin Interface Setup

Zuerst sollte man die Remote-Admin-Interface ermöglichen. Nur die folgenden Zeilen zu Ihrer OpenSim.ini FILE-Port hinzufügen sollte auf einen Wert ungleich null gesetzt werden, um die Remote-Admin auf einem anderen Port zu haben.

Ab Version r/16843 können Sie den Zugriff auf Remote-Admin auf bestimmte IP-Adressen beschränken, indem sie optionale access_ip_addresses verwenden. Sie können alle IP-Liste erlaubt durch RemoteAdmin für den Zugriff auf jede IP durch ein Komma trennt. Wenn access_ip_addresses nicht gesetzt ist, dann können alle IP-Adressen RemoteAdmin zugreifen.

[RemoteAdmin]
enabled = true
access_password = secret
enabled_methods = all

Siehe OpenSim.ini.example im opensim/bin/ Verzeichnis für weitere Details.

Weitere Optionen

Sie können auch einen anderen Port für die XMLRPCAdmin command listener aus dem Standard-Simulator HTTP-Port angeben.

[RemoteAdmin]
port = <port-number>

PHP Beispiele

OpenSimRemoteClass.php - PHP 8

<?php
/*
    // PHP Example for handling
 
    // Include the class file
    require_once 'OpenSimRemoteClass.php';
 
    // Instantiate the OpenSimRemoteClass object with required parameters
    $OpenSimulatorURL = 'example.com';
    $OpenSimulatorPort = 1234;
    $OpenSimPassword = 'your_password';
 
    $openSim = new OpenSimRemoteClass($OpenSimulatorURL, $OpenSimulatorPort, $OpenSimPassword);
 
    // Example command and parameters
    $command = 'example_command';
    $params = array(
        'param1' => 'value1',
        'param2' => 'value2'
    );
 
    // Send the command to the simulator
    $response = $openSim->SendCommand($command, $params);
 
    // Display the response
    echo "Response from simulator:\n";
    print_r($response);
*/
?>
 
<?php
class OpenSimRemoteClass
{ 
    // Properties to store simulator URL, port, and OpenSimPassword
    private $OpenSimulatorURL;
    private $OpenSimulatorPort;
    private $OpenSimPassword;
 
    // Constructor to initialize the class with required parameters
    public function __construct($sURL, $sPort, $pass)
    { 
        $this->OpenSimulatorURL = $sURL;
        $this->OpenSimulatorPort = $sPort;
        $this->OpenSimPassword = $pass; 
    }
 
    // Method to send a command to the simulator
    public function SendCommand($command, $params = [])
    { 
        // Extract parameter names and values
        $paramsNames = array_keys($params);
        $paramsValues = array_values($params);
 
        // Construct the XML-RPC request
        $xml = '<methodCall><methodName>' . htmlspecialchars($command) . '</methodName><params><param><value><struct><member><name>OpenSimPassword</name><value><string>' . htmlspecialchars($this->OpenSimPassword) . '</string></value></member>';
 
        // Add parameters to the XML-RPC request if any
        if (count($params) != 0)
        {
            foreach ($params as $paramName => $paramValue)
            {
                $xml .= '<member><name>' . htmlspecialchars($paramName) . '</name><value>' . htmlspecialchars($paramValue) . '</value></member>';
            } 
        }
 
        // Complete the XML-RPC request
        $xml .= '</struct></value></param></params></methodCall>';
 
        // Set up connection parameters
        $host = $this->OpenSimulatorURL;
        $port = $this->OpenSimulatorPort;
        $timeout = 5;
 
        // Suppress error reporting
        error_reporting(0);
 
        // Open a network connection to the simulator
        $fp = @fsockopen($host, $port, $errno, $errstr, $timeout);
        if (!$fp)
        {
            return FALSE; // Unable to establish connection
        }
        else
        {
            // Send the XML-RPC request
            fputs($fp, "POST / HTTP/1.1\r\n");
            fputs($fp, "Host: $host\r\n");
            fputs($fp, "Content-type: text/xml\r\n");
            fputs($fp, "Content-length: ". strlen($xml) ."\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $xml);
 
            // Read server response
            $res = "";
            while(!feof($fp)) {
                $res .= fgets($fp, 128);
            }
            fclose($fp);
 
            // Extract and parse the response
            $response = substr($res, strpos($res, "\r\n\r\n"));;
            $result = [];
            if (preg_match_all('#<name>(.+)</name><value><(string|int)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) {
                foreach($regs as $key => $val) {
                    $result[$val[1]] = $val[3];
                }
            }
            return $result; // Return parsed response
        } 
    } 
} 
?>

Python 3.6 Beispiele

Python 3.6 Beispiel - admin_broadcast -

Dieser Python 3.6 Beitrag ist ein User Projekt, es wird kein Support über die Admins geben.

Bitte seit vorsichtig, ich schließe jede Gewährleistung aus.

Ohne Programmierkenntnisse oder unsachgemäßer Anwendung, kann es zu Schäden am OpenSimulator oder/und dem Betriebssystem kommen.

Faustregel: Wenn ihr nicht sicher seit, ob ihr gesichert habt, dann sichert.

Dies ist zuletzt getestet am 23.04.2018 mit Python 3.6.3 auf Windows 10 und Ubuntu Server 17.10.

#!/usr/bin/python3
 
# admin_broadcast senden einer Nachricht an alle in einer Region.
# Python 3.6 - 21.04.2018 by Manfred Aabye
 
# Module laden
import xmlrpc.client 
 
# Information
print('---------------------------------------------------------------------')
print('Setup: Opensim.ini - Del ; - ConsoleUser -  ConsolePass')
print('---------------------------------------------------------------------')
print('Beispiel:')
print('---------------------------------------------------------------------')
print('SimulatorAdress = http://127.0.0.1:9000/ or http://myserver.com:9000/')
print('ConsoleUser = Test')
print('ConsolePass = secret')
print('RegionMessage = Dies ist ein toller Text an einem tollen Tag.')
print('---------------------------------------------------------------------')
 
# Abfragen
SimulatorAdress = input('SimulatorAdress:')
ConsoleUser = input('ConsoleUser:')
ConsolePass = input('ConsolePass:')
RegionMessage = input('RegionMessage:')
# Eingabe kann X Belibig geaendert werden RegionMessage = input('RegionMessage:') - X_Belibig = input('geben sie etwas fuer X_Belibig ein:')
# X_Belibig ist die Speicherstelle von input, der Text innerhalb der Klammern ist nur ein Text.
 
# Funktion admin_broadcast
def admin_broadcast():
    # Server Initialisieren 
    Simulator = xmlrpc.client.Server(SimulatorAdress) 
    # Password und Nachricht senden RegionMessage. Hier funktionieren auch alle anderen admin_ Befehle.
    # Bitte nicht vergessen auch die Eingabe zu aendern
    Simulator.admin_broadcast({'password': ConsolePass, 'message': RegionMessage})
 
# admin_broadcast Aufruf dieser kann nun an irgendeiner stelle aufgerufen werden. 
admin_broadcast()
 
# Ende admin_broadcast

Python 3.6 RemoteAdmin nur teilweise getestet

Dies basiert auf dem Python 3.6 Beispiel - admin_broadcast – und soll die Erweiterung/Veränderung des source vereinfachen.

# Agent Management
 
    Simulator.admin_teleport_agent({'password':ConsolePass,'agent_first_name':agent_first_name,'agent_last_name':agent_last_name,'region_name':region_name, 'pos_x':pos_x, 'pos_y':pos_y})
    Simulator.admin_get_agents({'password':ConsolePass,'region_name':region_name,'Regions-ID':Regions-ID})
 
    # Benutzerkontenverwaltung
 
    Simulator.admin_create_user({'password':ConsolePass,'user_firstname':user_firstname,'user_lastname':user_lastname,'user_password':user_password,'start_region_x':start_region_x,'start_region_y':start_region_y,'user_email':user_email})
    # Simulator.admin_create_user_email dies ist jetzt in admin_create_user enthalten.
    Simulator.admin_exists_user({'password':ConsolePass,'user_firstname':user_firstname,'user_lastname':user_lastname})
    Simulator.admin_update_user({'password':ConsolePass,'user_firstname':user_firstname,'user_lastname':user_lastname})
    Simulator.admin_authenticate_user({'password':ConsolePass,'user_firstname':user_firstname,'user_lastname':user_lastname,'user_password':user_password,'token_lifetime':token_lifetime})
 
    # Region Management
 
    Simulator.Simulator.admin_broadcast({'password': ConsolePass, 'message': RegionMessage})
    Simulator.admin_close_region({'password':ConsolePass,'region_name':region_name})
    Simulator.admin_create_region({'password':ConsolePass,'region_name':region_name,'listen_ip':listen_ip,'listen_port':listen_port,'external_address':external_address,'region_x':region_x,'region_y':region_y,'estate_name':estate_name})
    Simulator.admin_delete_region({'password':ConsolePass,'region_name':region_name})
    Simulator.admin_modify_region({'password':ConsolePass,'region_name':region_name})
    Simulator.admin_region_query({'password':ConsolePass,'region_name':region_name})
    Simulator.admin_restart({'password':ConsolePass,'region_id':region_id})
    Simulator.admin_shutdown({'password':ConsolePass,'milliseconds':milliseconds})
 
    # Region Dateiverwaltung
 
    Simulator.admin_load_heightmap({'password': ConsolePass,'region_name':region_name,'filename': filename})
    Simulator.admin_load_oar({'password': ConsolePass,'region_name':region_name,'filename': filename})
    Simulator.admin_load_xml({'password': ConsolePass,'region_name':region_name,'filename': filename})
    Simulator.admin_save_heightmap({'password': ConsolePass,'region_name':region_name,'filename': filename})
    Simulator.admin_save_oar({'password': ConsolePass,'region_name':region_name,'filename': filename})
    Simulator.admin_save_xml({'password': ConsolePass,'region_name':region_name,'filename': filename})
 
    # Region Zugangsmanagement
 
    Simulator.admin_acl_list({'password': ConsolePass,'region_name':region_name})
    Simulator.admin_acl_clear({'password': ConsolePass,'region_name':region_name})
    Simulator.admin_acl_add({'password': ConsolePass,'region_name':region_name,'users':users})
    Simulator.admin_acl_remove({'password': ConsolePass,'region_name':region_name,'users':users})
 
    # Estate Immobilienverwaltung
 
    Simulator.admin_estate_reload({'password':ConsolePass})
 
    # Administrationskonsole
 
    Simulator.admin_console_command({'password':ConsolePass,'console_command':console_command})
 
    # Verschiedenes 
 
    Simulator.admin_dialog({'password': ConsolePass, 'message': RegionMessage})
    #Simulator.admin_reset_land({'password':ConsolePass}) # keine ahnung
    #Simulator.admin_refresh_search({'password':ConsolePass}) # keine ahnung
    #Simulator.admin_refresh_map({'password':ConsolePass}) # keine ahnung
    #Simulator.admin_get_opensim_version({'password':ConsolePass}) # Rueckgabeparameter: Ich weiss nicht wie das geht.
    #Simulator.admin_get_agent_count({'password':ConsolePass}) # keine ahnung

RemoteAdmin Befehle

Alle Befehlsparameter die UUID einer Region nutzen "region_id" als Parameter. Alle anderen Parameter wie zB. region_uuid oder regionId sind nach Juni 2012 entfernt worden.


Agent management

User account management

Object management

Noch keine RemoteAdmin Befehle vorhanden.

Parcel management

Noch keine RemoteAdmin Befehle vorhanden.

Region management

Region file management