@@ -16,12 +16,14 @@ <h2>Stored sites:</h2>
1616 < thead > < tr > < th > sitename< th > (matching)< th > count< th > type< th > ver
1717< tbody >
1818</ table >
19+ < button id ="export_mpsites "> export</ button >
1920< script src ="./js/jquery-2.1.3.min.js "> </ script >
2021< script type ="text/javascript ">
2122
2223( function ( ) {
2324
2425 var stored_sites = { } ;
26+ var username = "" ;
2527
2628function save_sites_to_backend ( ) {
2729 var event = document . createEvent ( 'CustomEvent' ) ;
@@ -90,8 +92,9 @@ <h2>Stored sites:</h2>
9092}
9193
9294window . addEventListener ( 'masterpassword-configload' , function ( e ) {
93- stored_sites = e . detail ;
94- $ . each ( e . detail , function ( domain , v ) {
95+ stored_sites = e . detail . sites ;
96+ username = e . detail . username ;
97+ $ . each ( stored_sites , function ( domain , v ) {
9598 $ . each ( v , function ( site , settings ) {
9699 stored_sites_table_append ( domain , site , settings . type , settings . generation , "3" )
97100 } ) ;
@@ -159,6 +162,66 @@ <h2>Stored sites:</h2>
159162
160163} ) ;
161164
165+ $ ( '#export_mpsites' ) . on ( 'click' , function ( ) {
166+ var x = make_mpsites ( ) ;
167+ start_data_download ( x , 'firefox.mpsites' ) ;
168+ } ) ;
169+
170+ function make_mpsites ( ) {
171+ var a = [ '# Master Password site export\n' ,
172+ '# Export of site names and stored passwords (unless device-private) encrypted with the master key.\n' ,
173+ '#\n' ,
174+ '##\n' ,
175+ '# Format: 1\n' ,
176+ '# Date: 2015-03-24T14:44:51Z\n' ,
177+ '# User Name: ' + username + '\n' ,
178+ '# Full Name: ' + username + '\n' ,
179+ '# Avatar: 0\n' ,
180+ '# Key ID:\n' ,
181+ '# Version: 2.2\n' ,
182+ '# Algorithm: 3\n' ,
183+ '# Default Type: 17\n' ,
184+ '# Passwords: PROTECTED\n' ,
185+ '##\n' ,
186+ '#\n' ,
187+ '# Last Times Password Login\t Site\tSite\n' ,
188+ '# used used type name\t name\tpassword\n' ] ;
189+
190+ $ . each ( stored_sites , function ( domain , v ) {
191+ $ . each ( v , function ( site , settings ) {
192+ var x ;
193+ switch ( settings . type ) {
194+ case 's' : x = '20' ; break ;
195+ case 'x' : x = '16' ; break ;
196+ case 'i' : x = '21' ; break ;
197+ case 'b' : x = '19' ; break ;
198+ case 'p' : x = '31' ; break ;
199+ case 'n' : x = '30' ; break ;
200+ case 'l' : x = '17' ; break ;
201+ case 'm' : x = '18' ; break ;
202+ default : throw "unknown password type" ;
203+ }
204+ x += ':3:' + settings . generation ;
205+ while ( x . length < 8 ) x = " " + x ;
206+ while ( site . length < 25 ) site = " " + site ;
207+ a . push ( '2015-03-23T13:06:35Z 0 ' + x + ' \t' + site + '\t\n' ) ;
208+ } ) ;
209+ } ) ;
210+ return a ;
211+ }
212+
213+ function start_data_download ( stringarr , filename ) {
214+ var a = window . document . createElement ( 'a' ) ;
215+ a . href = window . URL . createObjectURL ( new Blob ( stringarr , { type : 'text/plain' } ) ) ;
216+ a . download = filename ;
217+
218+ // Append anchor to body.
219+ document . body . appendChild ( a )
220+ a . click ( ) ;
221+
222+ // Remove anchor from body
223+ document . body . removeChild ( a )
224+ }
162225
163226
164227} ( ) ) ;
0 commit comments