Skip to content

Commit

Permalink
settings: export sites to .mpsites
Browse files Browse the repository at this point in the history
  • Loading branch information
ttyridal committed Mar 25, 2015
1 parent 786d928 commit 7b76142
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 3 deletions.
67 changes: 65 additions & 2 deletions ext/data/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ <h2>Stored sites:</h2>
<thead><tr><th>sitename<th>(matching)<th>count<th>type<th>ver
<tbody>
</table>
<button id="export_mpsites">export</button>
<script src="./js/jquery-2.1.3.min.js"></script>
<script type="text/javascript">

(function(){

var stored_sites={};
var username="";

function save_sites_to_backend() {
var event = document.createEvent('CustomEvent');
Expand Down Expand Up @@ -90,8 +92,9 @@ <h2>Stored sites:</h2>
}

window.addEventListener('masterpassword-configload', function(e){
stored_sites = e.detail;
$.each(e.detail, function(domain,v){
stored_sites = e.detail.sites;
username = e.detail.username;
$.each(stored_sites, function(domain,v){
$.each(v, function(site, settings){
stored_sites_table_append(domain,site,settings.type,settings.generation,"3")
});
Expand Down Expand Up @@ -159,6 +162,66 @@ <h2>Stored sites:</h2>

});

$('#export_mpsites').on('click',function(){
var x = make_mpsites();
start_data_download(x, 'firefox.mpsites');
});

function make_mpsites() {
var a=[ '# Master Password site export\n',
'# Export of site names and stored passwords (unless device-private) encrypted with the master key.\n',
'#\n',
'##\n',
'# Format: 1\n',
'# Date: 2015-03-24T14:44:51Z\n',
'# User Name: '+username+'\n',
'# Full Name: '+username+'\n',
'# Avatar: 0\n',
'# Key ID:\n',
'# Version: 2.2\n',
'# Algorithm: 3\n',
'# Default Type: 17\n',
'# Passwords: PROTECTED\n',
'##\n',
'#\n',
'# Last Times Password Login\t Site\tSite\n',
'# used used type name\t name\tpassword\n'];

$.each(stored_sites, function(domain,v){
$.each(v, function(site, settings){
var x;
switch(settings.type){
case 's': x='20'; break;
case 'x': x='16'; break;
case 'i': x='21'; break;
case 'b': x='19'; break;
case 'p': x='31'; break;
case 'n': x='30'; break;
case 'l': x='17'; break;
case 'm': x='18'; break;
default: throw "unknown password type";
}
x+=':3:'+settings.generation;
while (x.length<8) x=" "+x;
while (site.length<25) site=" "+site;
a.push('2015-03-23T13:06:35Z 0 '+x+' \t'+site+'\t\n');
});
});
return a;
}

function start_data_download(stringarr,filename) {
var a = window.document.createElement('a');
a.href = window.URL.createObjectURL(new Blob(stringarr, {type: 'text/plain'}));
a.download = filename;

// Append anchor to body.
document.body.appendChild(a)
a.click();

// Remove anchor from body
document.body.removeChild(a)
}


}());
Expand Down
2 changes: 1 addition & 1 deletion ext/lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function createPanel() {
if (! /^resource:.*config\.html$/.test(tab.url)) return;
var worker = tab.attach({ contentScriptFile: self.data.url('config-cs.js') });
worker.port.on('configload', function(m) {
worker.port.emit('configload',session_store.sites);
worker.port.emit('configload', {sites:session_store.sites, username:session_store.username});
});
worker.port.on('configstore', function(d) {
session_store.sites = d;
Expand Down

0 comments on commit 7b76142

Please sign in to comment.