Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require 'IXR_Library.php';
- class Server extends IXR_Server {
- private $version = 0.4;
- function Server() {
- parent::IXR_Server(array(
- 'system.info' => 'this:info',
- 'system.listDir' => 'this:listDir',
- 'system.download' => 'this:download',
- 'system.update' => 'this:update'
- ));
- }
- function info($args){
- return
- array(
- 'version' => $this->version,
- 'time' => time(),
- 'extensions' => get_loaded_extensions()
- );
- }
- function listDir($args) {
- $dir = isset($args) ? $args : '.';
- $files = array();
- if ($handle = opendir($dir)) {
- while (false !== ($file = readdir($handle))) {
- if ($file != '.' && $file != '..') {
- array_push($files, $file);
- }
- }
- closedir($handle);
- }
- return $files;
- }
- function download($args){
- $remote = $args[0];
- $file = $args[1];
- if(function_exists('curl_init'))
- return $this->download_curl($remote, $file);
- $data = file_get_contents($remote);
- if(($handle = fopen($file, 'w+')) != false) {
- fwrite($handle, $data);
- fclose($handle);
- return true;
- } else
- return false;
- }
- function download_curl($remote, $file){
- $handle = fopen ($file, 'w+');
- $ch = curl_init($remote);
- curl_setopt($ch, CURLOPT_TIMEOUT, 50);
- curl_setopt($ch, CURLOPT_FILE, $handle);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
- curl_exec($ch);
- curl_close($ch);
- fclose($handle);
- if(!file_exists($file))
- return false;
- return true;
- }
- function update($args){
- $remote = $args;
- // overwrite own file
- return $this->download(array($remote, 'server.php'));
- }
- }
- $server = new Server();
- ?>
Add Comment
Please, Sign In to add comment