Add export function

This commit is contained in:
Gregory Soutade 2015-09-17 20:32:29 +02:00
parent b255a8cd90
commit 1d22f425e9
3 changed files with 65 additions and 0 deletions

View File

@ -171,6 +171,19 @@ if ($user != "")
} }
?> ?>
</div> </div>
<div id="export_database">
<?php
global $user;
if ($user != "")
{
echo "<b>Export</b><br/>\n";
echo '<input type="button" value="Export" onclick="export_database();"/>';
echo '<a id="export_link">Download</a>';
}
?>
</div>
</div> </div>
</body> </body>
</html> </html>

View File

@ -79,6 +79,19 @@ body {
margin : 15px; margin : 15px;
} }
#export_database {
border-style:solid;
border-width:5px;
border-color:pink;
padding : 15px;
margin : 15px;
}
#export_link {
display:none;
visibility:hidden;
}
.error { .error {
text-align:center; text-align:center;
color:red; color:red;

View File

@ -819,3 +819,42 @@ function update_masterkey()
change_master_key(false); change_master_key(false);
} }
} }
function makeText(text) {
var data = new Blob([text], {type: 'application/xml'});
textFile = window.URL.createObjectURL(data);
// returns a URL you can use as a href
return textFile;
};
var text_link = null;
function export_database()
{
link = document.getElementById("export_link");
if (text_link != null) window.URL.revokeObjectURL(text_link);
text = "<passwords user=\"" + current_user + "\" addon_address=\"" + document.documentURI + current_user + "\">\n";
for(i=0; i<passwords.length; i++)
{
if (!passwords[i].unciphered) continue;
text += "\t<password_entry>\n"
text += "\t\t<url value=\"" + passwords[i].clear_url + "\"/>\n";
text += "\t\t<login value=\"" + passwords[i].clear_login + "\"/>\n";
text += "\t\t<password><![CDATA[" + passwords[i].clear_password.replace("]]>", "]]\\>", "g") + "]]></password>\n";
text += "\t</password_entry>\n"
}
text += "</passwords>\n";
text_link = makeText(text);
link.href = text_link;
link.style.display = "inline";
link.style.visibility = "visible";
alert_msg = "Click on download link to get all current unciphered passwords\n\n";
alert_msg += "\"]]>\" sequence has been replaced by \"]]\\>\"";
alert(alert_msg);
}