mirror of
https://github.com/seiichiro0185/sailotp.git
synced 2024-11-22 07:39:42 +00:00
Added possibility to Reorder the List of Tokens.
This commit is contained in:
parent
95f00e8dd0
commit
7b48f929c5
3 changed files with 59 additions and 12 deletions
|
@ -38,15 +38,22 @@ function getDB() {
|
||||||
// Initialize an empty DB, Create the Table
|
// Initialize an empty DB, Create the Table
|
||||||
db.changeVersion("", "2",
|
db.changeVersion("", "2",
|
||||||
function(tx) {
|
function(tx) {
|
||||||
tx.executeSql("CREATE TABLE IF NOT EXISTS OTPStorage(title TEXT, secret TEXT, type TEXT DEFAULT 'TOPT', counter INTEGER DEFAULT 0, fav INTEGER DEFAULT 0);");
|
tx.executeSql("CREATE TABLE IF NOT EXISTS OTPStorage(title TEXT, secret TEXT, type TEXT DEFAULT 'TOPT', counter INTEGER DEFAULT 0, fav INTEGER DEFAULT 0, sort INTEGER DEFAULT 0);");
|
||||||
});
|
});
|
||||||
} else if (db.version == "1.0") {
|
} else if (db.version == "1.0") {
|
||||||
// Upgrade DB Schema to Version 2
|
// Upgrade DB Schema to Version 3
|
||||||
db.changeVersion("1.0", "2",
|
db.changeVersion("1.0", "3",
|
||||||
function(tx) {
|
function(tx) {
|
||||||
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN type TEXT DEFAULT 'TOTP';");
|
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN type TEXT DEFAULT 'TOTP';");
|
||||||
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN counter INTEGER DEFAULT 0;");
|
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN counter INTEGER DEFAULT 0;");
|
||||||
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN fav INTEGER DEFAULT 0;");
|
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN fav INTEGER DEFAULT 0;");
|
||||||
|
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN sort INTEGER DEFAULT 0;");
|
||||||
|
});
|
||||||
|
} else if (db.version == "2") {
|
||||||
|
// Upgrade DB Schema to Version 3
|
||||||
|
db.changeVersion("2", "3",
|
||||||
|
function(tx) {
|
||||||
|
tx.executeSql("ALTER TABLE OTPStorage ADD COLUMN sort INTEGER DEFAULT 0;");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -63,9 +70,9 @@ function getOTP() {
|
||||||
|
|
||||||
db.transaction(
|
db.transaction(
|
||||||
function(tx) {
|
function(tx) {
|
||||||
var res = tx.executeSql("select * from OTPStorage;");
|
var res = tx.executeSql("select * from OTPStorage order by sort;");
|
||||||
for (var i=0; i < res.rows.length; i++) {
|
for (var i=0; i < res.rows.length; i++) {
|
||||||
appWin.appendOTP(res.rows.item(i).title, res.rows.item(i).secret, res.rows.item(i).type, res.rows.item(i).counter, res.rows.item(i).fav);
|
appWin.appendOTP(res.rows.item(i).title, res.rows.item(i).secret, res.rows.item(i).type, res.rows.item(i).counter, res.rows.item(i).fav, res.rows.item(i).sort);
|
||||||
if (res.rows.item(i).fav) appWin.setCover(i);
|
if (res.rows.item(i).fav) appWin.setCover(i);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -85,12 +92,13 @@ function db2json() {
|
||||||
"secret": res.rows.item(i).secret,
|
"secret": res.rows.item(i).secret,
|
||||||
"type": res.rows.item(i).type,
|
"type": res.rows.item(i).type,
|
||||||
"counter": res.rows.item(i).counter,
|
"counter": res.rows.item(i).counter,
|
||||||
|
"sort": res.rows.item(i).sort,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (otpList.length > 0) {
|
if (otpList.length > 0) {
|
||||||
return(JSON.stringify({"app": "sailotp", "version": 1, "otplist": otpList}));
|
return(JSON.stringify({"app": "sailotp", "version": 2, "otplist": otpList}));
|
||||||
} else {
|
} else {
|
||||||
return("")
|
return("")
|
||||||
}
|
}
|
||||||
|
@ -101,7 +109,7 @@ function json2db(jsonString, error) {
|
||||||
var json = JSON.parse(jsonString);
|
var json = JSON.parse(jsonString);
|
||||||
error = "";
|
error = "";
|
||||||
|
|
||||||
if (json.version != "1" && json.app != "sailotp" ) {
|
if ((json.version != "1" || json.version != "2") && json.app != "sailotp" ) {
|
||||||
error = "Unrecognized format, file is not a SailOTP export";
|
error = "Unrecognized format, file is not a SailOTP export";
|
||||||
return(false);
|
return(false);
|
||||||
} else {
|
} else {
|
||||||
|
@ -111,7 +119,11 @@ function json2db(jsonString, error) {
|
||||||
while(otpList.length > 0) {
|
while(otpList.length > 0) {
|
||||||
var otpItem = otpList.shift();
|
var otpItem = otpList.shift();
|
||||||
if (otpItem.title != "" & otpItem.secret.length >= 16) {
|
if (otpItem.title != "" & otpItem.secret.length >= 16) {
|
||||||
addOTP(otpItem.title, otpItem.secret, otpItem.type, otpItem.counter);
|
if (json.version == "1") {
|
||||||
|
addOTP(otpItem.title, otpItem.secret, otpItem.type, otpItem.counter, 0);
|
||||||
|
} else {
|
||||||
|
addOTP(otpItem.title, otpItem.secret, otpItem.type, otpItem.counter, otpItem.sort);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
parentPage.refreshOTPList();
|
parentPage.refreshOTPList();
|
||||||
|
@ -124,7 +136,7 @@ function json2db(jsonString, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a new OTP
|
// Add a new OTP
|
||||||
function addOTP(title, secret, type, counter) {
|
function addOTP(title, secret, type, counter, sort) {
|
||||||
var db = getDB();
|
var db = getDB();
|
||||||
|
|
||||||
db.transaction(
|
db.transaction(
|
||||||
|
@ -132,7 +144,7 @@ function addOTP(title, secret, type, counter) {
|
||||||
if (checkOTP(title, secret)) {
|
if (checkOTP(title, secret)) {
|
||||||
console.log("Token " + title + " is already in DB");
|
console.log("Token " + title + " is already in DB");
|
||||||
} else {
|
} else {
|
||||||
tx.executeSql("INSERT INTO OTPStorage VALUES(?, ?, ?, ?, ?);", [title, secret, type, counter, 0]);
|
tx.executeSql("INSERT INTO OTPStorage VALUES(?, ?, ?, ?, ?, ?);", [title, secret, type, counter, 0, sort]);
|
||||||
console.log("Token " + title + " added.");
|
console.log("Token " + title + " added.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -197,6 +209,20 @@ function changeOTP(title, secret, type, counter, oldtitle, oldsecret) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function changeOTPSort(title, secret, sort) {
|
||||||
|
var db = getDB();
|
||||||
|
|
||||||
|
db.transaction(
|
||||||
|
function(tx) {
|
||||||
|
if (!checkOTP(title, secret)) {
|
||||||
|
console.log("Token " + title + " is not in DB");
|
||||||
|
} else {
|
||||||
|
tx.executeSql("UPDATE OTPStorage SET sort=? WHERE title=? and secret=?;", [sort, title, secret]);
|
||||||
|
console.log("Token " + title + " modified.");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Get the counter for a HOTP value, incerment the counter on request
|
// Get the counter for a HOTP value, incerment the counter on request
|
||||||
function getCounter(title, secret, increment) {
|
function getCounter(title, secret, increment) {
|
||||||
var db = getDB();
|
var db = getDB();
|
||||||
|
|
|
@ -122,7 +122,7 @@ Dialog {
|
||||||
DB.changeOTP(otpLabel.text, otpSecret.text, paramType, otpCounter.text, paramLabel, paramKey)
|
DB.changeOTP(otpLabel.text, otpSecret.text, paramType, otpCounter.text, paramLabel, paramKey)
|
||||||
} else {
|
} else {
|
||||||
// There were no parameters -> Add new entry
|
// There were no parameters -> Add new entry
|
||||||
DB.addOTP(otpLabel.text, otpSecret.text, paramType, otpCounter.text);
|
DB.addOTP(otpLabel.text, otpSecret.text, paramType, otpCounter.text, appWin.listModel.count);
|
||||||
}
|
}
|
||||||
// Refresh the main Page
|
// Refresh the main Page
|
||||||
parentPage.refreshOTPList();
|
parentPage.refreshOTPList();
|
||||||
|
|
|
@ -148,6 +148,17 @@ Page {
|
||||||
remorseAction(qsTr("Deleting"), function() { DB.removeOTP(title, secret); appWin.listModel.remove(index) })
|
remorseAction(qsTr("Deleting"), function() { DB.removeOTP(title, secret); appWin.listModel.remove(index) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function moveEntry(direction, index) {
|
||||||
|
if (direction) {
|
||||||
|
appWin.listModel.move(index, index-1, 1);
|
||||||
|
} else {
|
||||||
|
appWin.listModel.move(index, index+1, 1);
|
||||||
|
}
|
||||||
|
for (var i=0; i<appWin.listModel.count; i++) {
|
||||||
|
DB.changeOTPSort(appWin.listModel.get(i).title, appWin.listModel.get(i).secret, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
Clipboard.text = otp
|
Clipboard.text = otp
|
||||||
notify.show(qsTr("Token for ") + title + qsTr(" copied to clipboard"), 3000);
|
notify.show(qsTr("Token for ") + title + qsTr(" copied to clipboard"), 3000);
|
||||||
|
@ -217,6 +228,16 @@ Page {
|
||||||
Component {
|
Component {
|
||||||
id: otpContextMenu
|
id: otpContextMenu
|
||||||
ContextMenu {
|
ContextMenu {
|
||||||
|
MenuItem {
|
||||||
|
text: qsTr("Move up")
|
||||||
|
visible: index > 0 ? true : false;
|
||||||
|
onClicked: moveEntry(1, index);
|
||||||
|
}
|
||||||
|
MenuItem {
|
||||||
|
text: qsTr("Move down")
|
||||||
|
visible: index < appWin.listModel.count - 1 ? true : false;
|
||||||
|
onClicked: moveEntry(0, index);
|
||||||
|
}
|
||||||
MenuItem {
|
MenuItem {
|
||||||
text: qsTr("Edit")
|
text: qsTr("Edit")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
|
|
Loading…
Reference in a new issue