Fernsteuerung

From OpenSimWiki
Jump to: navigation, search

RemoteAdmin Einstellungen

Einstellungen der Opensim.ini

[RemoteAdmin]

; RemoteAdmin ein/ausschalten true/false
enabled = true

; Das zugangspasswort einstellen
access_password = Passwort

; Welche Metoden zulässig sind
enabled_methods = all

RemoteAdminTest.php

Dieses Beispiel benötigt die Datei RemoteAdmin.php.

<?php

// Dieses Beispiel gibt eine Meldung heraus und fährt OpenSim herunter
//
// admin_broadcast ist das kommando für Nachrichten
// $params hier wird die Meldung hineingeschrieben
// 
// Das Kommando admin_shutdown fährt OpenSim herunter



include('RemoteAdmin.php'); // RemoteAdmin.php Ist der Name der PHP-Klasse

// Einstellung bitte anpassen (IP oder Adresse, Port, Passwort)
$myRA = new RemoteAdmin('127.0.0.1', 9000, 'Passwort');

// Nachricht in $params schreiben
$params = array('message' => 'Diese Nachricht wird an alle Regionen des OpenSimulators gesendet!');

// RemoteAdmin-Befehle ausführen
$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.

// RemoteAdmin-Befehle ausführen
$myRA->SendCommand('admin_shutdown'); 

?>

RemoteAdmin.php

<?php
	
/***********************************************************************

	
Copyright (c) 2008, The New World Grid Regents http://www.newworldgrid.com and Contributors 
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

	* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
	* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
	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, 
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
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 
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


***********************************************************************/
	
	
	// How to instantiate a RemoteAdmin object ?
	// $myremoteadmin = new RemoteAdmin("mySimulatorURL", Port, "secret password")


	// How to send commands to remoteadmin plugin ?
	// $myremoteadmin->SendCommand('admin_broadcast', array('message' => 'Message to broadcast to all regions'));
	// $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;
			}
			
		}
		
	}
		
?>

Funktionsüberblick

Agent

   admin_teleport_agent
   admin_get_agents

Benutzer

   admin_create_user
   admin_create_user_email
   admin_exists_user
   admin_update_user
   admin_authenticate_user 


Region

   admin_broadcast
   admin_close_region
   admin_create_region
   admin_delete_region
   admin_modify_region
   admin_region_query
   admin_restart
   admin_shutdown 

Dateiverwaltung

   admin_load_heightmap
   admin_load_oar
   admin_load_xml
   admin_save_heightmap
   admin_save_oar
   admin_save_xml 

Zugangsmanagement

   admin_acl_list
   admin_acl_clear
   admin_acl_add
   admin_acl_remove 

Immobilienverwaltung

   admin_estate_reload 

Administrationskonsole

   admin_console_command 

Verschiedenes

   admin_dialog
   admin_reset_land
   admin_refresh_search
   admin_refresh_map
   admin_get_opensim_version
   admin_get_agent_count