RemoteAdmin:RemoteAdmin Class
From OpenSimulator
(Difference between revisions)
(→RemoteAdmin Class: Add version compatible with PHP 7.x) |
(→RemoteAdmin Class: Remove dead link) |
||
Line 5: | Line 5: | ||
'''This is a modified version of Remote Admin Class''' | '''This is a modified version of Remote Admin Class''' | ||
</div> | </div> | ||
− | + | Tested with OpenSimulator v0.9.1.0 Dev (2019) and <b>PHP 7.3</b> | |
− | Tested with OpenSimulator v0.9.1.0 Dev and <b>PHP 7.3</b> | + | |
− | + | ||
<source lang="php"> | <source lang="php"> | ||
<?php | <?php | ||
Line 92: | Line 90: | ||
?> | ?> | ||
</source> | </source> | ||
− | + | Tested with OpenSimulator v0.9.1.0 Dev (2018) and PHP <b>PHP 5.6</b> | |
− | + | ||
− | Tested with OpenSimulator v0.9.1.0 Dev and PHP <b>PHP 5.6</b> | + | |
− | + | ||
<source lang="php"> | <source lang="php"> | ||
<?php | <?php | ||
Line 181: | Line 176: | ||
</source> | </source> | ||
− | |||
[[Category:RemoteAdmin]] | [[Category:RemoteAdmin]] |
Revision as of 04:00, 11 January 2019
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)>(.*)</\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 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)>(.*)</\2></value>#U', $response, $regs, PREG_SET_ORDER)) { foreach($regs as $key => $val) { $result[$val[1]] = $val[3]; } } return $result; } } } ?>