Skip to content

Commit

Permalink
Update csv-gen.rb
Browse files Browse the repository at this point in the history
Update to v1.1.0-beta

* Now checks for presence of 'Passwords.csv' before presenting options.
* Cleaner one line strings.
* Added version info next to title.
  • Loading branch information
JDsnyke authored Mar 12, 2022
1 parent 33946d9 commit 6bbbd38
Showing 1 changed file with 96 additions and 121 deletions.
217 changes: 96 additions & 121 deletions csv-gen.rb
Original file line number Diff line number Diff line change
@@ -1,138 +1,113 @@
puts ""
puts " Welcome to Safari Password Converter"
puts " ------------------------------------"
puts ""
puts " Your options are:"
puts ""
puts " +-----------------------------------------------+"
puts " | 1. Safari to Bitwarden CSV (OTP supported) |"
puts " | 2. Safari to Dashlane CSV (OTP unsupported) |"
puts " | 3. Safari to Lastpass CSV (OTP unsupported) |"
puts " | 4. Safari to 1Password CSV (OTP unsupported) |" # 1Password supports native safari csv import directly on their site!
puts " | 5. Safari to KeePass CSV (OTP unsupported) |"
puts " | 6. Safari to LogMeOnce CSV (OTP unsupported) |"
puts " | 7. Exit Script |"
puts " +-----------------------------------------------+"
puts ""
loop do
print " Enter corresponding option number to start relevant script : "
@input = gets.chomp
options = [1, 2, 3, 4, 5, 6, 7]
options_exit = ['exit', 'quit', 'close', 'end']
if options.include?(@input.to_i) == true
break
elsif options_exit.include?(@input.to_s) == true
puts ""
puts " Script ended!"
puts ""
exit()
elsif @input == ""
puts ""
puts " Option cannot stay blank. If you wish to end the script, type 'close'"
puts ""
else
puts ""
puts " Incorrect option number. Please try again."
puts ""
end
end
puts "\n Welcome to Safari Password Converter (v.1.1.0-beta)\n ------------------------------------\n\n"

if @input.to_i == 1
file = File.read("#{__dir__}/Passwords.csv")
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "folder,favorite,type,name,notes,fields,reprompt,login_uri,login_username,login_password,login_totp")
unless row.include?("folder")
row.gsub!(/^/, ",,,")
row.gsub!(",http", ",,,,http")
File.open("bitwarden-pass.csv", "a") {|f| f.write("#{row}") }
pass_file = "#{__dir__}/Passwords.csv"
if File.file?(pass_file) == true

puts " Your options are:\n\n +-----------------------------------------------+\n | 1. Safari to Bitwarden CSV (OTP supported) |\n | 2. Safari to Dashlane CSV (OTP unsupported) |\n | 3. Safari to Lastpass CSV (OTP unsupported) |\n | 4. Safari to 1Password CSV (OTP unsupported) |\n | 5. Safari to KeePass CSV (OTP unsupported) |\n | 6. Safari to LogMeOnce CSV (OTP unsupported) |\n | 7. Exit Script |\n +-----------------------------------------------+\n\n"
loop do
print " Enter corresponding option number to start : "
@input = gets.chomp
options = [1, 2, 3, 4, 5, 6, 7]
options_exit = ['exit', 'quit', 'close', 'end', 'x']
if options.include?(@input.to_i) == true
break
elsif options_exit.include?(@input.to_s) == true
puts "\n Script ended!\n\n"
exit()
elsif @input == ""
puts "\n Option cannot stay blank. If you wish to end the script, type 'close'.\n\n"
else
File.open("bitwarden-pass.csv", "w") {|f| f.write("#{row}") }
puts "\n Incorrect option number. Please try again.\n\n"
end
end
puts ""
puts " Sucessfully converted to Bitwarden CSV. File saved as bitwarden-pass.csv"
puts ""

elsif @input.to_i == 2
file = File.read("#{__dir__}/Passwords.csv")
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "name,url,username,password")
unless row.include?("name,url")
row.gsub!(/,otpauth(.*)/, ",")
File.open("dashlane-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("dashlane-pass.csv", "w") {|f| f.write("#{row}") }
if @input.to_i == 1
file = File.read(pass_file)
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "folder,favorite,type,name,notes,fields,reprompt,login_uri,login_username,login_password,login_totp")
unless row.include?("folder")
row.gsub!(/^/, ",,,")
row.gsub!(",http", ",,,,http")
File.open("bitwarden-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("bitwarden-pass.csv", "w") {|f| f.write("#{row}") }
end
end
end
puts ""
puts " Sucessfully converted to Dashlane CSV. File saved as dashlane-pass.csv"
puts ""
puts "\n Sucessfully converted to Bitwarden CSV. File saved as bitwarden-pass.csv\n\n"

elsif @input.to_i == 3
file = File.read("#{__dir__}/Passwords.csv")
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "name,url,username,password")
unless row.include?("name,url")
row.gsub!(/,otpauth(.*)/, ",")
File.open("lastpass-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("lastpass-pass.csv", "w") {|f| f.write("#{row}") }
elsif @input.to_i == 2
file = File.read(pass_file)
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "name,url,username,password")
unless row.include?("name,url")
row.gsub!(/,otpauth(.*)/, ",")
File.open("dashlane-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("dashlane-pass.csv", "w") {|f| f.write("#{row}") }
end
end
end
puts ""
puts " Sucessfully converted to Lastpass CSV. File saved as lastpass-pass.csv"
puts ""
puts "\n Sucessfully converted to Dashlane CSV. File saved as dashlane-pass.csv\n\n"

elsif @input.to_i == 4
file = File.read("#{__dir__}/Passwords.csv")
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "Title,Website,Username,Password")
unless row.include?("Title,Website")
row.gsub!(/,otpauth(.*)/, ",")
File.open("1password-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("1password-pass.csv", "w") {|f| f.write("#{row}") }
elsif @input.to_i == 3
file = File.read(pass_file)
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "name,url,username,password")
unless row.include?("name,url")
row.gsub!(/,otpauth(.*)/, ",")
File.open("lastpass-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("lastpass-pass.csv", "w") {|f| f.write("#{row}") }
end
end
end
puts ""
puts " Sucessfully converted to 1Password CSV. File saved as 1password-pass.csv"
puts ""
puts "\n Sucessfully converted to Lastpass CSV. File saved as lastpass-pass.csv\n\n"

elsif @input.to_i == 5
file = File.read("#{__dir__}/Passwords.csv")
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", '"Account","Web Site","Login Name","Password"')
unless row.include?('"Account","Web Site"')
row.gsub!(/^/, '"')
row.gsub!(",", '",')
row.gsub!(/,otpauth(.*)/, ",")
File.open("keepass-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("keepass-pass.csv", "w") {|f| f.write("#{row}") }
elsif @input.to_i == 4
file = File.read(pass_file)
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "Title,Website,Username,Password")
unless row.include?("Title,Website")
row.gsub!(/,otpauth(.*)/, ",")
File.open("1password-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("1password-pass.csv", "w") {|f| f.write("#{row}") }
end
end
end
puts ""
puts " Sucessfully converted to KeePass CSV. File saved as keepass-pass.csv"
puts ""
puts "\n Sucessfully converted to 1Password CSV. File saved as 1password-pass.csv\n\n"

elsif @input.to_i == 6
file = File.read("#{__dir__}/Passwords.csv")
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "name,url,username,password")
unless row.include?("name,url")
row.gsub!(/,otpauth(.*)/, ",")
File.open("logmeonce-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("logmeonce-pass.csv", "w") {|f| f.write("#{row}") }
elsif @input.to_i == 5
file = File.read(pass_file)
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", '"Account","Web Site","Login Name","Password"')
unless row.include?('"Account","Web Site"')
row.gsub!(/^/, '"')
row.gsub!(",", '",')
row.gsub!(/,otpauth(.*)/, ",")
File.open("keepass-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("keepass-pass.csv", "w") {|f| f.write("#{row}") }
end
end
puts "\n Sucessfully converted to KeePass CSV. File saved as keepass-pass.csv\n\n"

elsif @input.to_i == 6
file = File.read(pass_file)
file.each_line do |row|
row.gsub!("Title,Url,Username,Password,OTPAuth", "name,url,username,password")
unless row.include?("name,url")
row.gsub!(/,otpauth(.*)/, ",")
File.open("logmeonce-pass.csv", "a") {|f| f.write("#{row}") }
else
File.open("logmeonce-pass.csv", "w") {|f| f.write("#{row}") }
end
end
puts "\n Sucessfully converted to LogMeOnce CSV. File saved as logmeonce-pass.csv\n\n"

elsif @input.to_i == 7
puts "\n Script ended!\n\n"
exit()
end
puts ""
puts " Sucessfully converted to LogMeOnce CSV. File saved as logmeonce-pass.csv"
puts ""

elsif @input.to_i == 7
puts ""
puts " Script ended!"
puts ""
else
puts " Passwords.csv file missing.\n\n Please place this alongside csv-gen.rb in same folder and re-run.\n\n"
exit()
end
end

0 comments on commit 6bbbd38

Please sign in to comment.