summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/core/web/index.html
blob: 9951a9b200eaad134bae6df8f3e8c8f3171ae788 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html>
   <head>
      <title>Bitmask.js example</title>
      <script src="bitmask.js"></script>
      <script type="text/javascript">
         var ellog = null;

         window.onload = function() {
            ellog = document.getElementById('log');

            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.bonafide.user.auth(email, password).then(function(response) {
                log("We are logged in: ");
                for (k in response) {
                    log("    " + k + ": " + response[k]);
                }
            }, function(error) {
                log("Some error ocurred: " + error);
            });
         };

         function logout() {
            bitmask.bonafide.user.logout().then(function(response) {
                log("We are logged out: ");
                for (k in response) {
                    log("    " + k + ": " + response[k]);
                }
            }, function(error) {
                log("Some error ocurred: " + error);
            });
	 };

         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) {
               log("    " + content[i]);
            }
         };

         function log(m) {
            ellog.innerHTML += m + '\n';
            ellog.scrollTop = ellog.scrollHeight;
         };
      </script>
   </head>
   <body>
      <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>