add auth key

This commit is contained in:
j 2010-08-18 14:02:10 +02:00
parent 4ec0a5c89e
commit 5be87d8adb
2 changed files with 16 additions and 14 deletions

View file

@ -614,11 +614,7 @@ class OxControl(Resource):
self.db = Database(self.db_path) self.db = Database(self.db_path)
self.putChild("media", File(self.db.get('media_cache', 'media'))) self.putChild("media", File(self.db.get('media_cache', 'media')))
''' self.authkey = self.db.get('username', 'fix')
#FIXME: this is just for debugging
if not 'Test' in self.db.volumes('0xdb.org', 'j'):
self.db.add_volume('0xdb.org', 'Test', '/media/2010/Movies')
'''
def putChild(self, name, child): def putChild(self, name, child):
self._children.append(name) self._children.append(name)
@ -641,6 +637,10 @@ class OxControl(Resource):
args[arg] = request.args.get(arg)[0] args[arg] = request.args.get(arg)[0]
return args return args
if request.args.get('key', '') != self.authkey:
response = {'status': '403', 'text': 'wrong authentication key provided'}
return json_response(request, response)
if request.path == '/add_volume': if request.path == '/add_volume':
args = required_args('site', 'user', 'name', 'path') args = required_args('site', 'user', 'name', 'path')
self.db.add_volume(**args) self.db.add_volume(**args)

View file

@ -46,10 +46,11 @@ function OxFF() {
oxff.set('username', ox.makeRandomString(8)); oxff.set('username', ox.makeRandomString(8));
oxff.set('password', ox.makeRandomString(8)); oxff.set('password', ox.makeRandomString(8));
} }
this.username = oxff.get('username'); this.authkey = oxff.get('username');
this.password = oxff.get('password'); this.password = oxff.get('password');
try { try {
//FF3.6 fallback
var em = Cc["@mozilla.org/extensions/manager;1"] var em = Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager); .getService(Ci.nsIExtensionManager);
var f = em.getInstallLocation('firefogg@firefogg.org').getItemFile('firefogg@firefogg.org', 'ffmpeg2theora'); var f = em.getInstallLocation('firefogg@firefogg.org').getItemFile('firefogg@firefogg.org', 'ffmpeg2theora');
@ -187,6 +188,7 @@ OxFF.prototype = {
if(!this.canAccess()) if(!this.canAccess())
return false; return false;
data["key"] = this.authkey;
data["site"] = this._site; data["site"] = this._site;
data["user"] = this._user; data["user"] = this._user;
@ -207,7 +209,7 @@ OxFF.prototype = {
var base = this.base; //later base can not be a public property var base = this.base; //later base can not be a public property
var url = base + action; var url = base + action;
//req.open("POST", url, true, this.username, this.password); //req.open("POST", url, true, this.authkey, this.password);
req.open("POST", url, true); req.open("POST", url, true);
try { try {
@ -218,6 +220,7 @@ OxFF.prototype = {
} }
} }
} catch(e) { } catch(e) {
//FF3.6 fallback
var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter); var converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"].createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8"; converter.charset = "UTF-8";
var boundary = "--------XX" + Math.random(); var boundary = "--------XX" + Math.random();
@ -356,11 +359,11 @@ OxFF.prototype = {
}, },
canAccess: function() { canAccess: function() {
if(!this._access) { if(!this._access) {
this.debug('permission deinied', action, data); this.debug('permission deinied');
return false; return false;
} }
if(!this._user) { if(!this._user) {
this.debug('login first', action, data); this.debug('login first');
return false; return false;
} }
return true; return true;
@ -373,11 +376,9 @@ OxFF.prototype = {
return false; return false;
} }
var osString = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS; var osString = Cc["@mozilla.org/xre/app-info;1"].getService(Ci.nsIXULRuntime).OS;
var daemon = ""; var daemon = "oxd.py";
if (osString == "WINNT") if (osString == "WINNT")
daemon = 'oxd.exe'; daemon = 'oxd.exe';
else
daemon = 'oxd.py';
function runDaemon(file) { function runDaemon(file) {
try { try {
@ -390,6 +391,7 @@ OxFF.prototype = {
} }
try { try {
//FF3.6 fallback
var em = Cc["@mozilla.org/extensions/manager;1"] var em = Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager); .getService(Ci.nsIExtensionManager);
var file = em.getInstallLocation(this.extensionID).getItemFile(this.extensionID, daemon); var file = em.getInstallLocation(this.extensionID).getItemFile(this.extensionID, daemon);