RemoteAdmin:RemoteAdmin Class
From OpenSimulator
(Difference between revisions)
(→RemoteAdmin Class: Doublon) |
(→RemoteAdmin Class: Fix preg_match) |
||
Line 77: | Line 77: | ||
$result = array(); | $result = array(); | ||
− | if (preg_match_all('#<name>(.+)</name><value><(string|int)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) | + | if (preg_match_all('#<name>(.+)</name><value><(string|int|boolean|i4)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) |
{ | { | ||
foreach($regs as $key => $val) | foreach($regs as $key => $val) | ||
Line 162: | Line 162: | ||
$result = array(); | $result = array(); | ||
− | if (preg_match_all('#<name>(.+)</name><value><(string|int)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) | + | if (preg_match_all('#<name>(.+)</name><value><(string|int|boolean|i4)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) |
{ | { | ||
foreach($regs as $key => $val) | foreach($regs as $key => $val) |
Latest revision as of 16:48, 19 June 2019
[edit] RemoteAdmin Class
This is a modified version of Remote Admin Class
Tested with OpenSimulator v0.9.1.0 Dev (2019) and PHP 7.3
<?php class RemoteAdmin { function __construct($sURL, $sPort, $pass) { $this->simulatorURL = $sURL; $this->simulatorPort = $sPort; $this->password = $pass; } function SendCommand($command, $params=array()) { $paramsNames = array_keys($params); $paramsValues = array_values($params); $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 .= is_int($paramsValues[$p]) ? '<value><int>'.$paramsValues[$p].'</int></value></member>' : '<value><string>'.htmlspecialchars($paramsValues[$p]).'</string></value></member>'; } } $xml .= '</struct> </value> </param> </params> </methodCall>'; $host = $this->simulatorURL; $port = $this->simulatorPort; $timeout = 5; error_reporting(0); $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if (!$fp) { return 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")); $result = array(); if (preg_match_all('#<name>(.+)</name><value><(string|int|boolean|i4)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) { foreach($regs as $key => $val) { $result[$val[1]] = $val[3]; } } return $result; } } } ?>
Tested with OpenSimulator v0.9.1.0 Dev (2018) and PHP 5.6
<?php class RemoteAdmin { function RemoteAdmin($sURL, $sPort, $pass) { $this->simulatorURL = $sURL; $this->simulatorPort = $sPort; $this->password = $pass; } function SendCommand($command, $params=array()) { $paramsNames = array_keys($params); $paramsValues = array_values($params); $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 .= is_int($paramsValues[$p]) ? '<value><int>'.$paramsValues[$p].'</int></value></member>' : '<value><string>'.htmlspecialchars($paramsValues[$p]).'</string></value></member>'; } } $xml .= '</struct> </value> </param> </params> </methodCall>'; $host = $this->simulatorURL; $port = $this->simulatorPort; $timeout = 5; error_reporting(0); $fp = fsockopen($host, $port, $errno, $errstr, $timeout); if (!$fp) { return 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")); $result = array(); if (preg_match_all('#<name>(.+)</name><value><(string|int|boolean|i4)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) { foreach($regs as $key => $val) { $result[$val[1]] = $val[3]; } } return $result; } } } ?>