From 78a6c49198c681a3c16d787f1d052bf5c9be9976 Mon Sep 17 00:00:00 2001 From: Josh Sherman Date: Thu, 1 Sep 2011 21:58:34 -0400 Subject: [PATCH] Base server, no parsing of dbus-send output. --- README.md | 3 +++ ubuntuone.js | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 README.md create mode 100644 ubuntuone.js diff --git a/README.md b/README.md new file mode 100644 index 0000000..85b24f3 --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +Launch the server and punch this in your browser: + +http://localhost:3000/status/current_downloads diff --git a/ubuntuone.js b/ubuntuone.js new file mode 100644 index 0000000..32c235d --- /dev/null +++ b/ubuntuone.js @@ -0,0 +1,33 @@ +var http = require('http'), + exec = require('child_process').exec, + pieces, interface, method, dbus_send, child; + +http.createServer(function(request, response) +{ + pieces = request.url.split('/'); + + response.writeHead(200, {'Content-Type': 'text/plain'}); + + if (pieces.length == 3) + { + interface = pieces[1].toLowerCase(); + method = pieces[2].toLowerCase(); + + dbus_send = 'dbus-send --session --print-reply --type=method_call' + + ' --dest=com.ubuntuone.SyncDaemon /' + interface + + ' com.ubuntuone.SyncDaemon.' + interface.charAt(0).toUpperCase() + interface.slice(1) + '.' + method.toLowerCase(); + + child = exec(dbus_send, function(error, stdout, stderr) + { + if (error !== null) + { + response.end(stderr); + } + else + { + response.end(stdout); + } + + }); + } +}).listen(3000, "127.0.0.1");