summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/core
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2016-09-06 19:27:31 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2016-09-07 10:04:45 -0400
commit7a6e187e0a970ad6fb722fc9dfd3be784b254c06 (patch)
tree70092fe6f1635b7a22266c8e136510eb6934f162 /src/leap/bitmask/core
parent1d51bc24ec9afcbb30b05905217bc7aafedca5f1 (diff)
[feat] Add manual provider registration
- Resolves: #8400
Diffstat (limited to 'src/leap/bitmask/core')
-rw-r--r--src/leap/bitmask/core/dispatcher.py62
-rw-r--r--src/leap/bitmask/core/web/bitmask.js116
-rw-r--r--src/leap/bitmask/core/web/index.html72
3 files changed, 202 insertions, 48 deletions
diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py
index 368a5bb6..55b19600 100644
--- a/src/leap/bitmask/core/dispatcher.py
+++ b/src/leap/bitmask/core/dispatcher.py
@@ -46,23 +46,71 @@ class SubCommand(object):
_method = None
if not _method:
- raise RuntimeError('No such subcommand')
+ raise RuntimeError('No such subcommand: ' + subcmd)
return defer.maybeDeferred(_method, service, *parts, **kw)
+class BonafideCmd(SubCommand):
+
+ label = 'bonafide'
+
+ def __init__(self):
+ self.subcommand_user = UserCmd()
+ self.subcommand_provider = ProviderCmd()
+
+ def do_USER(self, bonafide, *parts):
+ return self.subcommand_user.dispatch(bonafide, *parts[1:])
+
+ def do_PROVIDER(self, bonafide, *parts):
+ return self.subcommand_provider.dispatch(bonafide, *parts[1:])
+
+
+class ProviderCmd(SubCommand):
+
+ label = 'bonafide.provider'
+
+ @register_method("{'domain': str, 'api_uri': str, 'api_version': str}")
+ def do_CREATE(self, bonafide, *parts):
+ domain = parts[2]
+ return bonafide.do_provider_create(domain)
+
+ @register_method("{'domain': str, 'api_uri': str, 'api_version': str}")
+ def do_READ(self, bonafide, *parts):
+ domain = parts[2]
+ return bonafide.do_provider_read(domain)
+
+ @register_method("")
+ def do_DELETE(self, bonafide, *parts):
+ domain = parts[2]
+ bonafide.do_provider_delete(domain)
+
+ @register_method("[{'domain': str}]")
+ def do_LIST(self, bonafide, *parts):
+ seeded = False
+ if len(parts) > 2:
+ seeded = parts[2]
+ return bonafide.do_provider_list(seeded)
+
+
class UserCmd(SubCommand):
- label = 'user'
+ label = 'bonafide.user'
@register_method("{'srp_token': unicode, 'uuid': unicode}")
def do_AUTHENTICATE(self, bonafide, *parts):
user, password = parts[2], parts[3]
- return bonafide.do_authenticate(user, password)
+ autoconf = False
+ if len(parts) > 4:
+ autoconf = parts[4]
+ return bonafide.do_authenticate(user, password, autoconf)
@register_method("{'signup': 'ok', 'user': str}")
def do_SIGNUP(self, bonafide, *parts):
user, password = parts[2], parts[3]
- return bonafide.do_signup(user, password)
+ autoconf = False
+ if len(parts) > 4:
+ autoconf = parts[4]
+ return bonafide.do_signup(user, password, autoconf)
@register_method("{'logout': 'ok'}")
def do_LOGOUT(self, bonafide, *parts):
@@ -286,7 +334,7 @@ class CommandDispatcher(object):
def __init__(self, core):
self.core = core
- self.subcommand_user = UserCmd()
+ self.subcommand_bonafide = BonafideCmd()
self.subcommand_eip = EIPCmd()
self.subcommand_mail = MailCmd()
self.subcommand_keys = KeysCmd()
@@ -314,9 +362,9 @@ class CommandDispatcher(object):
# -----------------------------------------------
- def do_USER(self, *parts):
+ def do_BONAFIDE(self, *parts):
bonafide = self._get_service('bonafide')
- d = self.subcommand_user.dispatch(bonafide, *parts)
+ d = self.subcommand_bonafide.dispatch(bonafide, *parts)
d.addCallbacks(_format_result, _format_error)
return d
diff --git a/src/leap/bitmask/core/web/bitmask.js b/src/leap/bitmask/core/web/bitmask.js
index 39e677f3..9ac11b7b 100644
--- a/src/leap/bitmask/core/web/bitmask.js
+++ b/src/leap/bitmask/core/web/bitmask.js
@@ -29,9 +29,14 @@
*/
var bitmask = function(){
var event_handlers = {};
+
+ var api_url = '/API/';
+ if (window.location.protocol === "file:") {
+ api_url = 'http://localhost:7070/API/';
+ }
function call(command) {
- var url = '/API/' + command.slice(0, 2).join('/');
+ var url = api_url + command.slice(0, 2).join('/');
var data = JSON.stringify(command.slice(2));
return new Promise(function(resolve, reject) {
@@ -88,50 +93,83 @@ var bitmask = function(){
};
return {
- /**
- * uids are of the form user@provider.net
- */
- user: {
- /**
- * Check wich user is active
- *
- * @return {Promise<string>} The uid of the active user
- */
- active: function() {
- return call(['user', 'active']);
- },
+ bonafide: {
+ provider: {
+ create: function(domain) {
+ return call(['bonafide', 'provider', 'create', domain]);
+ },
- /**
- * Register a new user
- *
- * @param {string} uid The uid to be created
- * @param {string} password The user password
- */
- create: function(uid, password) {
- return call(['user', 'create', uid, password]);
- },
+ read: function(domain) {
+ return call(['bonafide', 'provider', 'read', domain]);
+ },
- /**
- * Login
- *
- * @param {string} uid The uid to log in
- * @param {string} password The user password
- */
- auth: function(uid, password) {
- return call(['user', 'authenticate', uid, password]);
+ delete: function(domain) {
+ return call(['bonafide', 'provider', 'delete', domain]);
+ },
+
+ list: function(seeded) {
+ if (typeof seeded !== 'boolean') {
+ seeded = false;
+ }
+ return call(['bonafide', 'provider', 'list', seeded]);
+ }
},
/**
- * Logout
- *
- * @param {string} uid The uid to log out.
- * If no uid is provided the active user will be used
+ * uids are of the form user@provider.net
*/
- logout: function(uid) {
- if (typeof uid !== 'string') {
- uid = "";
+ user: {
+ /**
+ * Check wich user is active
+ *
+ * @return {Promise<string>} The uid of the active user
+ */
+ active: function() {
+ return call(['bonafide', 'user', 'active']);
+ },
+
+ /**
+ * Register a new user
+ *
+ * @param {string} uid The uid to be created
+ * @param {string} password The user password
+ * @param {boolean} autoconf If the provider should be autoconfigured if it's not allready known
+ * If it's not provided it will default to false
+ */
+ create: function(uid, password, autoconf) {
+ if (typeof autoconf !== 'boolean') {
+ autoconf = false;
+ }
+ return call(['bonafide', 'user', 'create', uid, password, autocnof]);
+ },
+
+ /**
+ * Login
+ *
+ * @param {string} uid The uid to log in
+ * @param {string} password The user password
+ * @param {boolean} autoconf If the provider should be autoconfigured if it's not allready known
+ * If it's not provided it will default to false
+ */
+ auth: function(uid, password, autoconf) {
+ if (typeof autoconf !== 'boolean') {
+ autoconf = false;
+ }
+ return call(['bonafide', 'user', 'authenticate', uid, password, autoconf]);
+ },
+
+ /**
+ * Logout
+ *
+ * @param {string} uid The uid to log out.
+ * If no uid is provided the active user will be used
+ */
+ logout: function(uid) {
+ if (typeof uid !== 'string') {
+ uid = "";
+ }
+ return call(['bonafide', 'user', 'logout', uid]);
}
- return call(['user', 'logout', uid]);
}
},
@@ -153,7 +191,7 @@ var bitmask = function(){
* @return {Promise<string>} The token
*/
get_token: function() {
- return call(['mail', 'get-token']);
+ return call(['mail', 'get_token']);
}
},
diff --git a/src/leap/bitmask/core/web/index.html b/src/leap/bitmask/core/web/index.html
index 7ffbb3f1..9951a9b2 100644
--- a/src/leap/bitmask/core/web/index.html
+++ b/src/leap/bitmask/core/web/index.html
@@ -12,10 +12,57 @@
bitmask.events.register("KEYMANAGER_KEY_FOUND", event_handler);
};
+ function configure() {
+ var domain = document.getElementById('domain').value;
+ bitmask.bonafide.provider.create(domain).then(function(response) {
+ log("Provider configured: ");
+ for (k in response) {
+ log(" " + k + ": " + response[k]);
+ }
+ }, function(error) {
+ log("Some error ocurred: " + error);
+ });
+ };
+
+ function read() {
+ var domain = document.getElementById('domain').value;
+ bitmask.bonafide.provider.read(domain).then(function(response) {
+ log("Provider configuration: ");
+ for (k in response) {
+ log(" " + k + ": " + response[k]);
+ }
+ }, function(error) {
+ log("Some error ocurred: " + error);
+ });
+ };
+
+ function del() {
+ var domain = document.getElementById('domain').value;
+ bitmask.bonafide.provider.delete(domain).then(function(response) {
+ log("Provider deleted: ");
+ for (k in response) {
+ log(" " + k + ": " + response[k]);
+ }
+ }, function(error) {
+ log("Some error ocurred: " + error);
+ });
+ };
+
+ function list() {
+ bitmask.bonafide.provider.list().then(function(response) {
+ log("List providers: ");
+ for (k in response) {
+ log(" domain: " + response[k]["domain"]);
+ }
+ }, function(error) {
+ log("Some error ocurred: " + error);
+ });
+ };
+
function login() {
var email = document.getElementById('email').value;
var password = document.getElementById('password').value;
- bitmask.user.auth(email, password).then(function(response) {
+ bitmask.bonafide.user.auth(email, password).then(function(response) {
log("We are logged in: ");
for (k in response) {
log(" " + k + ": " + response[k]);
@@ -26,7 +73,7 @@
};
function logout() {
- bitmask.user.logout().then(function(response) {
+ bitmask.bonafide.user.logout().then(function(response) {
log("We are logged out: ");
for (k in response) {
log(" " + k + ": " + response[k]);
@@ -36,6 +83,19 @@
});
};
+ function user() {
+ bitmask.bonafide.user.active().then(function(response) {
+ log("The active user is: " + response);
+ }, function(error) {
+ log("Some error ocurred: " + error);
+ });
+ bitmask.mail.get_token().then(function(response) {
+ log("The token is: " + response);
+ }, function(error) {
+ log("Some error ocurred: " + error);
+ });
+ };
+
function event_handler(evnt, content) {
log("Event: " + evnt);
for (i in content) {
@@ -53,11 +113,19 @@
<h1>Bitmask Control Panel</h1>
<noscript>You must enable JavaScript</noscript>
<form>
+ <p>Provider: <input id="domain" type="text" size="50" maxlength="50" value="mail.bitmask.net"></p>
+ </form>
+ <button onclick='configure();'>Configure provider</button>
+ <button onclick='read();'>Read providers</button>
+ <button onclick='del();'>Delete providers</button>
+ <button onclick='list();'>List providers</button>
+ <form>
<p>Email address: <input id="email" type="text" size="50" maxlength="50" value="user@mail.bitmask.net"></p>
<p>Password: <input id="password" type="password" size="50" maxlength="50" ></p>
</form>
<button onclick='login();'>Log In</button>
<button onclick='logout();'>Log Out</button>
+ <button onclick='user();'>User</button>
<pre id="log" style="height: 20em; overflow-y: scroll; background-color: #faa;"></pre>
</body>
</html>