Created
August 5, 2024 17:22
-
-
Save abraham/9165aa369b16d0829d9de4e8f7bb6028 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'uri' | |
require 'cgi' | |
require 'json' | |
known_keys = [ | |
"secret", | |
"digits", | |
"period", | |
] | |
configs = [] | |
File.readlines("2fas.txt", chomp: true).each do |line| | |
# puts CGI.unescape(line) | |
uri = URI(line) | |
params = CGI::parse(uri.query) | |
raise "unknown key: #{params.keys}" if (params.keys - known_keys).any? | |
parts = CGI.unescape(uri.path[1...]).split(":") | |
raise "too many :" if parts.length > 2 | |
issuer = parts[0]&.strip | |
account = parts[1]&.strip | |
raise "missing account and issueer" unless issuer || account | |
configs << { | |
"kind": "TOTP", | |
"account": account || "", | |
"secret": params["secret"].first, | |
"iconType": nil, | |
"issuer": issuer || "", | |
"timer": "30", | |
"digits": params["digits"].first || 6, | |
"counter": "0", | |
"algorithm": "SHA1", | |
"iconValue": nil | |
} | |
end | |
File.open("2fas.json","w") do |f| | |
f.write(JSON.pretty_generate(configs)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment