mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-17 08:30:04 +00:00
fix import and export
This commit is contained in:
parent
1d3b127df0
commit
be00f04353
1 changed files with 10 additions and 30 deletions
38
MPW/MPW.rb
38
MPW/MPW.rb
|
@ -26,7 +26,7 @@ module MPW
|
||||||
# @args: password -> the GPG key password
|
# @args: password -> the GPG key password
|
||||||
# @rtrn: true if data has been decrypted
|
# @rtrn: true if data has been decrypted
|
||||||
def decrypt(passwd=nil)
|
def decrypt(passwd=nil)
|
||||||
@data = {}
|
@data = []
|
||||||
|
|
||||||
if File.exist?(@file_gpg)
|
if File.exist?(@file_gpg)
|
||||||
crypto = GPGME::Crypto.new(armor: true)
|
crypto = GPGME::Crypto.new(armor: true)
|
||||||
|
@ -54,9 +54,6 @@ module MPW
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
puts 'test'
|
|
||||||
puts data_to_encrypt
|
|
||||||
recipients = []
|
|
||||||
recipients.push(@key)
|
recipients.push(@key)
|
||||||
if !@share_keys.nil?
|
if !@share_keys.nil?
|
||||||
@share_keys.split.each { |k| recipients.push(k) }
|
@share_keys.split.each { |k| recipients.push(k) }
|
||||||
|
@ -196,10 +193,10 @@ module MPW
|
||||||
# @args: file -> a string to match
|
# @args: file -> a string to match
|
||||||
# @rtrn: true if export work
|
# @rtrn: true if export work
|
||||||
def export(file)
|
def export(file)
|
||||||
File.open(file, 'w+') do |file|
|
CSV.open(file, 'w', write_headers: true,
|
||||||
@data.each do |row|
|
headers: ['name', 'group', 'protocol', 'host', 'login', 'password', 'port', 'comment']) do |csv|
|
||||||
row.delete_at(:id).delete_at(:date)
|
@data.each do |r|
|
||||||
file << row.to_csv
|
csv << [r[:name], r[:group], r[:protocol], r[:host], r[:login], r[:password], r[:port], r[:comment]]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -213,16 +210,9 @@ module MPW
|
||||||
# @args: file -> path to file import
|
# @args: file -> path to file import
|
||||||
# @rtrn: true if the import work
|
# @rtrn: true if the import work
|
||||||
def import(file)
|
def import(file)
|
||||||
data_new = IO.read(file)
|
CSV.foreach(file, {headers: true, header_converters: :symbol}) do |row|
|
||||||
data_new.lines do |line|
|
if not update(row[:name], row[:group], row[:host], row[:protocol], row[:login], row[:password], row[:port], row[:comment])
|
||||||
if not line =~ /(.*,){6}/
|
|
||||||
@error_msg = I18n.t('error.import.bad_format')
|
|
||||||
return false
|
return false
|
||||||
else
|
|
||||||
row = line.parse_csv.unshift(0)
|
|
||||||
if not update(row[:name], row[:group], row[:host], row[:protocol], row[:login], row[:password], row[:port], row[:comment])
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -237,18 +227,8 @@ module MPW
|
||||||
# @rtrn: an array with the items to import, if there is an error return false
|
# @rtrn: an array with the items to import, if there is an error return false
|
||||||
def import_preview(file)
|
def import_preview(file)
|
||||||
result = []
|
result = []
|
||||||
id = 0
|
CSV.foreach(file, {headers: true, header_converters: :symbol}) do |row|
|
||||||
|
result << row
|
||||||
data = IO.read(file)
|
|
||||||
data.lines do |line|
|
|
||||||
if not line =~ /(.*,){6}/
|
|
||||||
@error_msg = I18n.t('error.import.bad_format')
|
|
||||||
return false
|
|
||||||
else
|
|
||||||
result.push(line.parse_csv.unshift(id))
|
|
||||||
end
|
|
||||||
|
|
||||||
id += 1
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Reference in a new issue