methods = array( 'opmlCommunityServer.getServerInfo' => 'this:getServerInfo', 'opmlCommunityServer.registerUser' => 'this:registerUser', 'opmlCommunityServer.checkPassword' => 'this:checkPassword', 'opmlCommunityServer.ping' => 'this:ping', 'opmlCommunityServer.getFilesChangedSince' => 'this:getFilesChangedSince', 'opmlCommunityServer.saveFile' => 'this:saveFile', 'opmlCommunityServer.deleteFile' => 'this:deleteFile', ); $this->IXR_Server($this->methods); } /** */ function getServerInfo($args) { return array( 'blogsname' => BLOGS_NAME, 'hostname' => HOST_NAME, 'server' => 'foobar' ); } /** */ function registerUser($args) { list($domain, $username, $password, $subdomain) = $args; global $users, $log; $users->registerUser($domain, $username, $password, $subdomain); $log->info("Registered $username@$domain/$subdomain"); return true; } /** */ function checkPassword($args) { list($domain, $username, $password) = $args; global $users, $log; if ($users->checkPassword($domain, $username, $password)) { $log->info("Login by $username@$domain"); return true; } else { $log->info("Failed login by $username@$domain"); return false; } } /** */ function ping($args) { list($name, $url) = $args; global $users, $log; $log->warn("Ping is unimplemented"); } /** */ function getFilesChangedSince($args) { list($domain, $username, $password, $when) = $args; global $users, $log; if (!$users->checkPassword($domain, $username, $password)) return false; } /** */ function saveFile($args) { list($domain, $username, $password, $path, $bytes) = $args; global $users, $log; if (!$users->checkPassword($domain, $username, $password)) return false; // Construct the full path to the file, including user's subdomain. // TODO: Cleanse path to ensure no attempt to jump above user's $user = $users->get($domain, $username); $subdomain = $user['subdomain']; $fullpath = FILES_PATH.'/'.$subdomain.'/'.$path; // Create the parent directories, if necessary. $parent_dir = dirname($fullpath); if (!is_dir($parent_dir)) { if (!mkdir($parent_dir, 0777, 1)) { $log->err("Failed creating dir $parent_dir"); } } // Write the file out to disk. // TODO: Error checking on file write? file_put_contents($fullpath, $bytes); $log->info("[$username@$domain] Saved $fullpath"); } /** */ function deleteFile($args) { list($domain, $username, $password, $path) = $args; global $users, $log; if (!$users->checkPassword($domain, $username, $password)) return false; // Construct the full path to the file, including user's subdomain. // TODO: Cleanse path to ensure no attempt to jump above user's $user = $users->get($domain, $username); $subdomain = $user['subdomain']; $fullpath = FILES_PATH.'/'.$subdomain.'/'.$path; delete($fullpath); $log->info("[$username@$domain] Deleted $fullpath"); } } $server = new Decafbad_OPML_Server(); ?>