Guest User

Untitled

a guest
Jan 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. <?php
  2.  
  3. require 'IXR_Library.php';
  4.  
  5. class Server extends IXR_Server {
  6.  
  7. private $version = 0.4;
  8.  
  9. function Server() {
  10. parent::IXR_Server(array(
  11. 'system.info' => 'this:info',
  12. 'system.listDir' => 'this:listDir',
  13. 'system.download' => 'this:download',
  14. 'system.update' => 'this:update'
  15. ));
  16. }
  17.  
  18. function info($args){
  19. return
  20. array(
  21. 'version' => $this->version,
  22. 'time' => time(),
  23. 'extensions' => get_loaded_extensions()
  24. );
  25. }
  26.  
  27. function listDir($args) {
  28. $dir = isset($args) ? $args : '.';
  29. $files = array();
  30. if ($handle = opendir($dir)) {
  31. while (false !== ($file = readdir($handle))) {
  32. if ($file != '.' && $file != '..') {
  33. array_push($files, $file);
  34. }
  35. }
  36. closedir($handle);
  37. }
  38.  
  39. return $files;
  40. }
  41.  
  42. function download($args){
  43. $remote = $args[0];
  44. $file = $args[1];
  45.  
  46. if(function_exists('curl_init'))
  47. return $this->download_curl($remote, $file);
  48.  
  49. $data = file_get_contents($remote);
  50. if(($handle = fopen($file, 'w+')) != false) {
  51. fwrite($handle, $data);
  52. fclose($handle);
  53. return true;
  54. } else
  55. return false;
  56. }
  57.  
  58. function download_curl($remote, $file){
  59. $handle = fopen ($file, 'w+');
  60. $ch = curl_init($remote);
  61. curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  62. curl_setopt($ch, CURLOPT_FILE, $handle);
  63. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  64. curl_exec($ch);
  65. curl_close($ch);
  66. fclose($handle);
  67.  
  68. if(!file_exists($file))
  69. return false;
  70.  
  71. return true;
  72. }
  73.  
  74. function update($args){
  75. $remote = $args;
  76. // overwrite own file
  77. return $this->download(array($remote, 'server.php'));
  78. }
  79. }
  80.  
  81. $server = new Server();
  82.  
  83. ?>
Add Comment
Please, Sign In to add comment