PageRenderTime 51ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/php/dus-lib.php

https://github.com/WimHager/DUS
PHP | 138 lines | 88 code | 23 blank | 27 comment | 4 complexity | 4366477de31ee9f32810fe21ffcf0455 MD5 | raw file
  1. <?php
  2. /*
  3. This file is part of DUS.
  4. DUS is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. DUS is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with DUS. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. // DUS is Dynamic UUID System for Prims
  16. // W. Hager founder and project leader
  17. $headers = request_headers(); //apache_request_headers();
  18. //if (count($headers) < 15) {echo "SHA-2 cryption key wrong!! Bye."; exit;} //let them guess ;)
  19. $objectgrid = $headers["X-SecondLife-Shard"];
  20. $objectname = $headers["X-SecondLife-Object-Name"];
  21. $objectkey = $headers["X-SecondLife-Object-Key"];
  22. $objectpos = $headers["X-SecondLife-Local-Position"];
  23. $ownerkey = $headers["X-SecondLife-Owner-Key"];
  24. $ownername = $headers["X-SecondLife-Owner-Name"];
  25. $regiondata = $headers["X-SecondLife-Region"];
  26. $regiontmp = explode ("(",$regiondata); // cut cords off
  27. $regionpos = explode (")",$regiontmp[1]); //
  28. $regionname = substr($regiontmp[0],0,-1); // cut last space from simname
  29. $Methode = $_POST["func"];
  30. $PrimUrl = $_POST["url"];
  31. $PrimTtl = $_POST["ttl"];
  32. $UUID = $_GET["uuid"];
  33. //check all input
  34. $DbName= "dus.db";
  35. $DusArr= array();
  36. function write_log($filename, $message) {
  37. $fp = fopen($filename, "a+");
  38. fwrite($fp, date("[Y/m/d-H:i:s];").$message."\n");
  39. fclose($fp);
  40. }
  41. function load_array_dump($filename) {
  42. $content= file_get_contents($filename);
  43. $array= unserialize($content);
  44. return($array);
  45. }
  46. function save_array_dump($filename, $array) {
  47. $dump= serialize($array);
  48. file_put_contents($filename, $dump);
  49. file_put_contents("dus.arr", print_r($array, true));
  50. }
  51. function request_headers() { // Replacement if apache_request_headers not exist
  52. foreach($_SERVER as $name => $value)
  53. if(substr($name, 0, 5) == 'HTTP_')
  54. $headers[str_replace('X-Secondlife-', 'X-SecondLife-', str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))))] = $value;
  55. return $headers;
  56. }
  57. function GetUrl($uuid) { //Returns url for given UUID
  58. global $DusArr;
  59. return $DusArr[$uuid]["url"];
  60. }
  61. function CleanUp() { //Removes all old Records
  62. global $DusArr;
  63. $TmpArr= $DusArr;
  64. $Now= time();
  65. foreach ($TmpArr as &$Content) {
  66. $MaxLife= $Content["upd"] + $Content["ttl"];
  67. if ( $Now > $MaxLife) {
  68. write_log("dus.log",key($DusArr)." Removed TTL timeout");
  69. unset($DusArr[key($DusArr)]);
  70. }
  71. }
  72. unset($Content);
  73. }
  74. function UpdateRecord($uuid, $url, $ttl) { //Updates record for given UUID
  75. global $DusArr;
  76. $DusArr[$uuid]["url"]= $url;
  77. $DusArr[$uuid]["upd"]= time();
  78. $DusArr[$uuid]["ttl"]= $ttl;
  79. }
  80. //Function by Simba Fuhr
  81. //Use under the GPL License
  82. function CallLSLScript($URL, $Data, $Timeout = 10) {
  83. //Parse the URL into Server, Path and Port
  84. $Host = str_ireplace("http://", "", $URL);
  85. $Path = explode("/", $Host, 2);
  86. $Host = $Path[0];
  87. $Path = $Path[1];
  88. $PrtSplit = explode(":", $Host);
  89. $Host = $PrtSplit[0];
  90. $Port = $PrtSplit[1];
  91. //Open Connection
  92. $Socket = fsockopen($Host, $Port, $Dummy1, $Dummy2, $Timeout);
  93. if ($Socket) {
  94. //Send Header and Data
  95. fputs($Socket, "POST /$Path HTTP/1.1\r\n");
  96. fputs($Socket, "Host: $Host\r\n");
  97. fputs($Socket, "Content-type: application/x-www-form-urlencoded\r\n");
  98. fputs($Socket, "User-Agent: Opera/9.01 (Windows NT 5.1; U; en)\r\n");
  99. fputs($Socket, "Accept-Language: de-DE,de;q=0.9,en;q=0.8\r\n");
  100. fputs($Socket, "Content-length: ".strlen($Data)."\r\n");
  101. fputs($Socket, "Connection: close\r\n\r\n");
  102. fputs($Socket, $Data);
  103. //Receive Data
  104. while(!feof($Socket))
  105. {$res .= fgets($Socket, 128);}
  106. fclose($Socket);
  107. }
  108. //ParseData and return it
  109. $res = explode("\r\n\r\n", $res);
  110. return $res[1];
  111. }
  112. ?>