Guest User

Untitled

a guest
Jan 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 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. }
  24.  
  25. function listDir($args) {
  26. $dir = isset($args) ? $args : '.';
  27. $files = array();
  28. if ($handle = opendir($dir)) {
  29. while (false !== ($file = readdir($handle))) {
  30. if ($file != '.' && $file != '..') {
  31. array_push($files, $file);
  32. }
  33. }
  34. closedir($handle);
  35. }
  36.  
  37. return $files;
  38. }
  39.  
  40. function download($args){
  41. $remote = $args[0];
  42. $file = $args[1];
  43.  
  44. if(function_exists('curl_init'))
  45. return $this->download_curl($remote, $file);
  46.  
  47. $data = file_get_contents($remote);
  48. if(($handle = fopen($file, 'w+')) != false) {
  49. fwrite($handle, $data);
  50. fclose($handle);
  51. return true;
  52. } else
  53. return false;
  54. }
  55.  
  56. function download_curl($remote, $file){
  57. $handle = fopen ($file, 'w+');
  58. $ch = curl_init($remote);
  59. curl_setopt($ch, CURLOPT_TIMEOUT, 50);
  60. curl_setopt($ch, CURLOPT_FILE, $handle);
  61. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  62. curl_exec($ch);
  63. curl_close($ch);
  64. fclose($handle);
  65.  
  66. if(!file_exists($file))
  67. return false;
  68.  
  69. return true;
  70. }
  71.  
  72. function update($args){
  73. $remote = $args;
  74. // overwrite own file
  75. return $this->download(array($remote, 'server.php'));
  76. }
  77. }
  78.  
  79. $server = new Server();
  80.  
  81. ?>
Add Comment
Please, Sign In to add comment