RemoteAdmin:RemoteAdmin Examples
From OpenSimulator
m (moved Remoteadmin:ReamoteAdmin Examples to RemoteAdmin:RemoteAdmin Examples: Spelling) |
(→Example 1: Add url to revisited Class) |
||
(13 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
Below are a view Examples on how to send commands from a remote enviroment. | Below are a view Examples on how to send commands from a remote enviroment. | ||
− | == C# .NET | + | == C# .NET == |
=== Example 1 - "admin_create_user" === | === Example 1 - "admin_create_user" === | ||
− | This example needs the Nwc.XmlRpc library, located in your | + | This example needs the Nwc.XmlRpc library, located in your OpenSimulator bin folder. |
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
<source lang="csharp"> | <source lang="csharp"> | ||
Line 28: | Line 43: | ||
CreateUser(new Uri("http://yourgrid.com:9000/"), "secret", "Test2", "user2", "apassword", "email@address.com", 0, 0); | CreateUser(new Uri("http://yourgrid.com:9000/"), "secret", "Test2", "user2", "apassword", "email@address.com", 0, 0); | ||
} | } | ||
− | </source> | + | </source> |
=== Example 2 - "admin_create_user" === | === Example 2 - "admin_create_user" === | ||
Line 91: | Line 106: | ||
</source> | </source> | ||
− | == Python | + | == Python == |
=== Example 1 - admin_broadcast === | === Example 1 - admin_broadcast === | ||
Line 111: | Line 126: | ||
# invoke admin_alert: requires password and message | # invoke admin_alert: requires password and message | ||
simulator.admin_broadcast({'password': 'secret', 'message': 'the answer is 42'}) | simulator.admin_broadcast({'password': 'secret', 'message': 'the answer is 42'}) | ||
+ | </source> | ||
+ | |||
+ | === Python 3.6 Example - admin_create_user === | ||
+ | |||
+ | <source lang="python"> | ||
+ | #!/usr/bin/python3 | ||
+ | # OpenSim Remoteadmin createuser | ||
+ | # Python 3.6 - 2018 by Manfred Aabye Version 0.5.29 | ||
+ | |||
+ | # import library | ||
+ | from appJar import gui | ||
+ | import xmlrpc.client | ||
+ | import configparser | ||
+ | from tkinter import * | ||
+ | import tkinter as tk | ||
+ | import sys | ||
+ | import os | ||
+ | import gettext | ||
+ | gettext.bindtextdomain('OpenSimRemote', '/language') | ||
+ | gettext.textdomain('OpenSimRemote') | ||
+ | _ = gettext.gettext | ||
+ | # gettext einfügen funktioniert so: | ||
+ | # print(_('This is a translatable string.')) | ||
+ | |||
+ | # ----------------------------- createuser --------------------------------------------- | ||
+ | def createuser(): | ||
+ | |||
+ | # Button Auswertung | ||
+ | def createuserbutton(button): | ||
+ | if button == "Ende": | ||
+ | app.stop() | ||
+ | return | ||
+ | if button == "Hilfe": | ||
+ | app.infoBox("Hilfe", "Bitte Ihre Server Daten in die OpenSimAdmin.ini eintragen.") | ||
+ | return | ||
+ | if button == "Senden": | ||
+ | config = configparser.ConfigParser() | ||
+ | config.sections() | ||
+ | config.read('OpenSimAdmin.ini') | ||
+ | SimulatorAdress = config['DEFAULT']['SimulatorAdress'] | ||
+ | ConsoleUser = config['DEFAULT']['ConsoleUser'] | ||
+ | ConsolePass = config['DEFAULT']['ConsolePass'] | ||
+ | user_firstname = app.getEntry('user_firstname') | ||
+ | user_lastname = app.getEntry('user_lastname') | ||
+ | user_password = app.getEntry('user_password') | ||
+ | start_region_x = app.getEntry('start_region_x') | ||
+ | start_region_y = app.getEntry('start_region_y') | ||
+ | user_email = app.getEntry('user_email') | ||
+ | Simulator = xmlrpc.client.Server(SimulatorAdress) | ||
+ | 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}) | ||
+ | return | ||
+ | |||
+ | |||
+ | # Erstelle GUI Variablen Aufruf mit app | ||
+ | app = gui("create user", "355x260") # Fenster erstellen mit Namen und Groesse | ||
+ | app.setFont(12) # Textgroesse | ||
+ | app.startLabelFrame("create user") | ||
+ | |||
+ | # Nachrichten Text Abfragen | ||
+ | app.addLabelEntry("user_firstname") | ||
+ | app.addLabelEntry("user_lastname") | ||
+ | app.addLabelSecretEntry("user_password") | ||
+ | app.addLabelEntry("start_region_x") | ||
+ | app.addLabelEntry("start_region_y") | ||
+ | app.addLabelEntry("user_email") | ||
+ | |||
+ | # Buttons ruft die Function createuserbutton auf | ||
+ | app.addButtons(["Senden", "Hilfe", "Ende"], createuserbutton) | ||
+ | app.stopLabelFrame() | ||
+ | # start GUI | ||
+ | app.go() | ||
+ | |||
+ | createuser() | ||
+ | </source> | ||
+ | |||
+ | Create file: OpenSimAdmin.ini | ||
+ | |||
+ | <source lang="python"> | ||
+ | [DEFAULT] | ||
+ | SimulatorAdress = http://127.0.0.1:9000/ | ||
+ | ConsoleUser = Test | ||
+ | ConsolePass = secret | ||
</source> | </source> | ||
== XML-RPC string == | == XML-RPC string == | ||
− | === Example 1 - "create user" | + | === Example 1 - "create user" === |
(used with first C#.NET method above) | (used with first C#.NET method above) | ||
− | POST admin_create_user HTTP/1.0<br>Host: http://10.0.0.12:16384/<br>Content-type: text/xml<br>Content-Length: 993 | + | POST admin_create_user HTTP/1.0<br />Host: http://10.0.0.12:16384/<br />Content-type: text/xml<br />Content-Length: 993 |
− | <?xml version="1.0"?><br><methodCall><br> <methodName>admin_create_user</methodName><br> <params><br> <param><br> <value><br> <struct><br> <member><br> <name>password</name><br> <value><string>password</string></value><br> </member><br> <member><br> <name>user_firstname</name><br> <value><string>male</string></value> <br> </member><br> <member><br> <name>user_lastname</name><br> <value><string>9999</string></value><br> </member><br> <member><br> <name>user_password</name><br> <value><string>password</string></value><br> </member><br> <member><br> <name>user_email</name><br> <value><string>none@email.com</string></value><br> </member><br> <member><br> <name>start_region_x</name><br> <value><int>128</int></value><br> </member><br> <member><br> <name>start_region_y</name><br> <value><int>128</int></value><br> </member><br> </struct><br> </value><br> </param><br> </params><br> </methodCall> | + | <?xml version="1.0"?><br /><methodCall><br /> <methodName>admin_create_user</methodName><br /> <params><br /> <param><br /> <value><br /> <struct><br /> <member><br /> <name>password</name><br /> <value><string>password</string></value><br /> </member><br /> <member><br /> <name>user_firstname</name><br /> <value><string>male</string></value> <br /> </member><br /> <member><br /> <name>user_lastname</name><br /> <value><string>9999</string></value><br /> </member><br /> <member><br /> <name>user_password</name><br /> <value><string>password</string></value><br /> </member><br /> <member><br /> <name>user_email</name><br /> <value><string>none@email.com</string></value><br /> </member><br /> <member><br /> <name>start_region_x</name><br /> <value><int>128</int></value><br /> </member><br /> <member><br /> <name>start_region_y</name><br /> <value><int>128</int></value><br /> </member><br /> </struct><br /> </value><br /> </param><br /> </params><br /> </methodCall> |
− | == RemoteAdmin executable for Windows | + | == RemoteAdmin executable for Windows == |
The RemoteAdmin executable for Windows is a command line tool based on the RemoteAdmin PHP Class. | The RemoteAdmin executable for Windows is a command line tool based on the RemoteAdmin PHP Class. | ||
+ | <!-- | ||
+ | Downloads and documentation on the [http://lab.newworldgrid.com/index.php/RemoteAdmin_Executable RemoteAdmin Executable webpage] | ||
+ | !!! this is a broken link !!! needs fixing | ||
+ | --> | ||
− | + | == PHP == | |
− | + | ||
− | == PHP | + | |
=== Example 1 === | === Example 1 === | ||
− | This example needs the RemoteAdmin PHP Class file available [http://code.google.com/p/opensimtools/wiki/RemoteAdminPHPClass here]. <source lang="php"> | + | This example needs the RemoteAdmin PHP Class file available [http://code.google.com/p/opensimtools/wiki/RemoteAdminPHPClass here] (Original) or [http://opensimulator.org/wiki/RemoteAdmin:RemoteAdmin_Class here] (Revisited). |
+ | <source lang="php"> | ||
<?php | <?php | ||
Line 160: | Line 260: | ||
</source> | </source> | ||
− | Note: This script does not appear to work for create user because it tries to pass the start region x and y as a string when the RemoteAdmin needs a string. The class needs to be edited to pass it as a number or edit the remoteadmin source to convert the string to a unsigned int. | + | Note: This script does not appear to work for create user because it tries to pass the start region x and y as a string when the RemoteAdmin needs a string. The class needs to be edited to pass it as a number or edit the remoteadmin source to convert the string to a unsigned int. |
=== Example 2 === | === Example 2 === | ||
Line 192: | Line 292: | ||
?> | ?> | ||
</source> | </source> | ||
+ | === Example 3 === | ||
+ | Another example provided by MarcelEdward (triplehx3) can be found [https://github.com/MarcelEdward/OpenSim-RemoteAdmin here]. | ||
+ | (Tested with OpenSimulator v0.9.1.0 Dev). | ||
− | <br> | + | <br /> |
− | == Perl | + | == Perl == |
− | Because the | + | Because the OpenSimulator internal web server just accepts HTTP/1.0 requests, it's worth to give a perl example. It's not a daily thing to do HTTP/1.0 within the LWP environment. You can get the '''[[Users:Thomax:perl-xmlrpc|Perl example here]]'''. |
− | === Credits | + | === Credits === |
Thanks to DrScofield for the Python Script Sources : http://xyzzyxyzzy.net/2008/01/23/using-pythons-xmlrpclib-with-opensim/ | Thanks to DrScofield for the Python Script Sources : http://xyzzyxyzzy.net/2008/01/23/using-pythons-xmlrpclib-with-opensim/ | ||
− | + | ||
− | + | [[Category:RemoteAdmin]] | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | [[Category: | + |
Latest revision as of 04:05, 11 January 2019
Below are a view Examples on how to send commands from a remote enviroment.
Contents |
[edit] C# .NET
[edit] Example 1 - "admin_create_user"
This example needs the Nwc.XmlRpc library, located in your OpenSimulator bin folder.
public void CreateUser(Uri url, string adminPassword, string firstName, string lastName, string password, string email, int regionX, int regionY) { var address = Dns.GetHostEntry(url.DnsSafeHost).AddressList[0]; var ht = new Hashtable(); ht["password"] = adminPassword; ht["user_firstname"] = firstName; ht["user_lastname"] = lastName; ht["user_password"] = password; ht["user_email"] = email; ht["start_region_x"] = regionX; ht["start_region_y"] = regionY; var parameters = new List<Hashtable> { ht }; var rpc = new XmlRpcRequest("admin_create_user", parameters); rpc.Invoke(url.ToString()); } [Test] public void NativeUserRegistrationTest() { CreateUser(new Uri("http://yourgrid.com:9000/"), "secret", "Test2", "user2", "apassword", "email@address.com", 0, 0); }
[edit] Example 2 - "admin_create_user"
//Author Ottalese complements of yoursimspot.com //This example needs the CookComputing.XmlRpc library, this can be downloaded from http://www.xml-rpc.net/. //Recently updated code I originally posted, this can be secured using SSL. using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using CookComputing.XmlRpc; [XmlRpcUrl("http://ServerIpAddress:9000/")] public interface RemoteOpensim : IXmlRpcProxy { //Create new user [XmlRpcMethod("admin_create_user")] XmlRpcStruct admin_create_user(XmlRpcStruct Parameters); } public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void SubmitButton_Click(object sender, EventArgs e) { XmlRpcStruct NewUser = new XmlRpcStruct(); //Will contain return results. XmlRpcStruct Parameters = new XmlRpcStruct();//Parameters passed. try { RemoteOpensim Admin = XmlRpcProxyGen.Create<RemoteOpensim>(); Parameters.Add("password", "RemotePassword"); //Password you set in the .ini file for the RemoteAdmin Parameters.Add("user_firstname", SomeStringWithFirstName); Parameters.Add("user_lastname", SomeStringWithLastName); Parameters.Add("user_password", SomePassword); Parameters.Add("start_region_x", 0); Parameters.Add("start_region_y", 0); NewUser = Admin.admin_create_user(Parameters); foreach (DictionaryEntry ReturnResults in NewUser) { Response.Write(ReturnResults.Key.ToString() + " : " + d.Value.ToString());//Returns if the user was added or not } } catch (Exception ex) { Response.Write(ex.Message); } } }
[edit] Python
[edit] Example 1 - admin_broadcast
# Author : DrScofield # Source : http://xyzzyxyzzy.net/2008/01/23/using-pythons-xmlrpclib-with-opensim/ # License : BSD License #!/usr/bin/python import xmlrpclib # XML-RPC URL (http_listener_port) simulatorUrl = "http://127.0.0.1:9000" # instantiate server object simulator = xmlrpclib.Server(simulatorUrl) # invoke admin_alert: requires password and message simulator.admin_broadcast({'password': 'secret', 'message': 'the answer is 42'})
[edit] Python 3.6 Example - admin_create_user
#!/usr/bin/python3 # OpenSim Remoteadmin createuser # Python 3.6 - 2018 by Manfred Aabye Version 0.5.29 # import library from appJar import gui import xmlrpc.client import configparser from tkinter import * import tkinter as tk import sys import os import gettext gettext.bindtextdomain('OpenSimRemote', '/language') gettext.textdomain('OpenSimRemote') _ = gettext.gettext # gettext einfügen funktioniert so: # print(_('This is a translatable string.')) # ----------------------------- createuser --------------------------------------------- def createuser(): # Button Auswertung def createuserbutton(button): if button == "Ende": app.stop() return if button == "Hilfe": app.infoBox("Hilfe", "Bitte Ihre Server Daten in die OpenSimAdmin.ini eintragen.") return if button == "Senden": config = configparser.ConfigParser() config.sections() config.read('OpenSimAdmin.ini') SimulatorAdress = config['DEFAULT']['SimulatorAdress'] ConsoleUser = config['DEFAULT']['ConsoleUser'] ConsolePass = config['DEFAULT']['ConsolePass'] user_firstname = app.getEntry('user_firstname') user_lastname = app.getEntry('user_lastname') user_password = app.getEntry('user_password') start_region_x = app.getEntry('start_region_x') start_region_y = app.getEntry('start_region_y') user_email = app.getEntry('user_email') Simulator = xmlrpc.client.Server(SimulatorAdress) 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}) return # Erstelle GUI Variablen Aufruf mit app app = gui("create user", "355x260") # Fenster erstellen mit Namen und Groesse app.setFont(12) # Textgroesse app.startLabelFrame("create user") # Nachrichten Text Abfragen app.addLabelEntry("user_firstname") app.addLabelEntry("user_lastname") app.addLabelSecretEntry("user_password") app.addLabelEntry("start_region_x") app.addLabelEntry("start_region_y") app.addLabelEntry("user_email") # Buttons ruft die Function createuserbutton auf app.addButtons(["Senden", "Hilfe", "Ende"], createuserbutton) app.stopLabelFrame() # start GUI app.go() createuser()
Create file: OpenSimAdmin.ini
[DEFAULT] SimulatorAdress = http://127.0.0.1:9000/ ConsoleUser = Test ConsolePass = secret
[edit] XML-RPC string
[edit] Example 1 - "create user"
(used with first C#.NET method above)
POST admin_create_user HTTP/1.0
Host: http://10.0.0.12:16384/
Content-type: text/xml
Content-Length: 993
<?xml version="1.0"?>
<methodCall>
<methodName>admin_create_user</methodName>
<params>
<param>
<value>
<struct>
<member>
<name>password</name>
<value><string>password</string></value>
</member>
<member>
<name>user_firstname</name>
<value><string>male</string></value>
</member>
<member>
<name>user_lastname</name>
<value><string>9999</string></value>
</member>
<member>
<name>user_password</name>
<value><string>password</string></value>
</member>
<member>
<name>user_email</name>
<value><string>none@email.com</string></value>
</member>
<member>
<name>start_region_x</name>
<value><int>128</int></value>
</member>
<member>
<name>start_region_y</name>
<value><int>128</int></value>
</member>
</struct>
</value>
</param>
</params>
</methodCall>
[edit] RemoteAdmin executable for Windows
The RemoteAdmin executable for Windows is a command line tool based on the RemoteAdmin PHP Class.
[edit] PHP
[edit] Example 1
This example needs the RemoteAdmin PHP Class file available here (Original) or here (Revisited).
<?php // Author : Olish Newman // Source : http://code.google.com/p/opensimtools/wiki/RemoteAdminPHPClass // Licence : BSD License // Including the RemoteAdmin PHP class. It can be downloaded from the link above. include('RemoteAdmin.php'); // Instantiate the class with parameters identical to the Python example above $myRemoteAdmin = new RemoteAdmin('127.0.0.1', 9000, 'secret'); // Invoke admin_broadcast $parameters = array('message' => 'the answer is 42'); $myRemoteAdmin->SendCommand('admin_broadcast', $parameters); // Invoke admin_shutdown (example for use without parameters) $myRemoteAdmin->SendCommand('admin_shutdown'); // Invoke admin_create_user (multiple parameters) $parameters = array('user_firstname' => 'Ruth', 'user_lastname' => 'OpenSim', 'user_password' => 'MyPassword', 'start_region_x' => '1000', 'start_region_y' => '1000'); $myRemoteAdmin->SendCommand('admin_create_user', $parameters); ?>
Note: This script does not appear to work for create user because it tries to pass the start region x and y as a string when the RemoteAdmin needs a string. The class needs to be edited to pass it as a number or edit the remoteadmin source to convert the string to a unsigned int.
[edit] Example 2
Another example in PHP5, using CURL.//This is the slightly modified RPC-class of the BSD-licensed WiXTD webportal <?php class RemotePC { function __construct() { $this->serveruri = "http://myhost"; $this->serverport ="9000"; $this->password ="foobar"; } function call($command,$parameters) { $parameters['password'] = $this->password; $request = xmlrpc_encode_request($command, $parameters); $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $this->serveruri); curl_setopt( $ch, CURLOPT_PORT, $this->serverport]); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ( $ch, CURLOPT_POSTFIELDS, $request); curl_setopt ( $ch, CURLOPT_TIMEOUT, 5); $result = curl_exec($ch); curl_close($ch); return xmlrpc_decode($result); } } ?>
[edit] Example 3
Another example provided by MarcelEdward (triplehx3) can be found here. (Tested with OpenSimulator v0.9.1.0 Dev).
[edit] Perl
Because the OpenSimulator internal web server just accepts HTTP/1.0 requests, it's worth to give a perl example. It's not a daily thing to do HTTP/1.0 within the LWP environment. You can get the Perl example here.
[edit] Credits
Thanks to DrScofield for the Python Script Sources : http://xyzzyxyzzy.net/2008/01/23/using-pythons-xmlrpclib-with-opensim/