Skip to content

Commit

Permalink
Application page .authme rollback file support #152
Browse files Browse the repository at this point in the history
  • Loading branch information
Levminer committed Nov 13, 2021
1 parent cc88b15 commit e1ab6f8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
33 changes: 27 additions & 6 deletions app/application/src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ if (!fs.existsSync(path.join(file_path, "hash.authme"))) {

// eslint-disable-next-line
let prev = false
let text
let save_text
const query = []
const description_query = []
Expand Down Expand Up @@ -79,19 +80,33 @@ const sort_number = file.experimental.sort
const loadFile = () => {
dialog
.showOpenDialog({
title: "Import from Authme Import Text file",
title: "Import from Authme import file",
properties: ["openFile"],
filters: [{ name: "Text file", extensions: ["txt"] }],
filters: [{ name: "Authme file", extensions: ["authme"] }],
})
.then((result) => {
canceled = result.canceled
filepath = result.filePaths

if (canceled === false) {
const text = fs.readFileSync(filepath.toString(), "utf-8")
save_text = text
const /** @type{LibAuthmeFile} */ loaded = JSON.parse(fs.readFileSync(filepath.toString(), "utf-8"))

processdata(text)
if (loaded.role === "import" || loaded.role === "export") {
text = Buffer.from(loaded.codes, "base64").toString()
save_text = text

processdata(text)
} else {
dialog.showMessageBox({
title: "Authme",
buttons: ["Close"],
defaultId: 0,
cancelId: 0,
type: "error",
noLink: true,
message: `This file is an Authme ${loaded.role} file! \n\nYou need an Authme export or import file!`,
})
}
}
})
}
Expand Down Expand Up @@ -732,10 +747,16 @@ const newSave = () => {

const encrypted = aes.encrypt(save_text, key)

/**
* Save codes
* @type{LibAuthmeFile}
* */
const codes = {
role: "codes",
encrypted: true,
codes: encrypted.toString("base64"),
date: new Date().toISOString().replace("T", "-").replaceAll(":", "-").substring(0, 19),
version: "2",
version: "3",
}

fs.writeFileSync(path.join(file_path, "codes", "codes.authme"), JSON.stringify(codes, null, "\t"))
Expand Down
2 changes: 1 addition & 1 deletion lib/typedef.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
/**
* .authme file structure
* @typedef {Object} LibAuthmeFile
* @property {String} role - Role of the file (codes, import, export)
* @property {String} role - Role of the file (codes, import, export, rollback, backup)
* @property {Boolean} encrypted - Is the file encrypted
* @property {String} codes - Base64 encoded string
* @property {Date} date - Date when the file created
Expand Down

0 comments on commit e1ab6f8

Please sign in to comment.