1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-10-27 02:33:19 +00:00

add update

This commit is contained in:
nishiki 2013-07-11 19:52:53 +02:00
parent 29247ad08d
commit c1551c7084

View file

@ -7,8 +7,8 @@ require 'rubygems'
require 'gpgme' require 'gpgme'
require 'csv' require 'csv'
FILE_GPG = '/home/nishiki/.password-manager.gpg' FILE_GPG = './pass.gpg'
KEY = 'nishiki@yaegashi.fr' KEY = 'a.waksberg@yaegashi.fr'
FILE_PWD = '/tmp/.password-manager.pwd' FILE_PWD = '/tmp/.password-manager.pwd'
TIMEOUT_PWD = 300 TIMEOUT_PWD = 300
@ -98,7 +98,6 @@ class ManagePasswd
row = line.parse_csv row = line.parse_csv
if line =~ /^.*#{search}.*$/ if line =~ /^.*#{search}.*$/
if type.nil? || type.eql?(row[TYPE]) if type.nil? || type.eql?(row[TYPE])
puts "test"
result.push(row) result.push(row)
end end
end end
@ -137,17 +136,17 @@ class ManagePasswd
puts "# --------------------" puts "# --------------------"
row[ID] = Time.now.to_i.to_s(16) row[ID] = Time.now.to_i.to_s(16)
print "Enter the server name or ip: " print "Enter the server name or ip: "
row[SERVER] = $stdin.gets row[SERVER] = $stdin.gets.chomp
print "Enter the type of connection (ssh, web, other): " print "Enter the type of connection (ssh, web, other): "
row[TYPE] = $stdin.gets row[TYPE] = $stdin.gets.chomp
print "Enter the login connection: " print "Enter the login connection: "
row[LOGIN] = $stdin.gets row[LOGIN] = $stdin.gets.chomp
print "Enter the the password: " print "Enter the the password: "
row[PASSWORD] = $stdin.gets row[PASSWORD] = $stdin.gets.chomp
print "Enter the connection port (optinal): " print "Enter the connection port (optinal): "
row[PORT] = $stdin.gets row[PORT] = $stdin.gets.chomp
print "Enter a comment (optinal): " print "Enter a comment (optinal): "
row[COMMENT] = $stdin.gets row[COMMENT] = $stdin.gets.chomp
@data << "#{row.join(',')}\n" @data << "#{row.join(',')}\n"
end end
@ -159,25 +158,32 @@ class ManagePasswd
@data.lines do |line| @data.lines do |line|
row = line.parse_csv row = line.parse_csv
if id.eql?(row[ID]) if id.eql?(row[ID])
update_row = Array.new() row_update = Array.new()
puts "# Add a new password" puts "# Add a new password"
puts "# --------------------" puts "# --------------------"
puts "Enter the server name or ip [#{row[SERVER]}]: " print "Enter the server name or ip [#{row[SERVER]}]: "
server = $stdin.gets server = $stdin.gets.chomp
puts = "Enter the type of connection [#{row[TYPE]}]: " print "Enter the type of connection [#{row[TYPE]}]: "
type = $stdin.gets type = $stdin.gets.chomp
puts "Enter the login connection [#{row[LOGIN]}]: " print "Enter the login connection [#{row[LOGIN]}]: "
login = $stdin.gets login = $stdin.gets.chomp
puts "Enter the the password: " print "Enter the the password: "
passwd = $stdin.gets passwd = $stdin.gets.chomp
puts "Enter the connection port [#{row[PORT]}]: " print "Enter the connection port [#{row[PORT]}]: "
port = $stdin.gets port = $stdin.gets.chomp
puts "Enter a comment [#{row[COMMENT]}]: " print "Enter a comment [#{row[COMMENT]}]: "
comment = $stdin.gets comment = $stdin.gets.chomp
# TODO row_update[ID] = row[ID]
server.empty? ? (row_update[SERVER] = row[SERVER]) : (row_update[SERVER] = server)
type.empty? ? (row_update[TYPE] = row[TYPE]) : (row_update[TYPE] = type)
login.empty? ? (row_update[LOGIN] = row[LOGIN]) : (row_update[LOGIN] = login)
passwd.empty? ? (row_update[PASSWORD] = row[PASSWORD]) : (row_update[PASSWORD] = passwd)
port.empty? ? (row_update[PORT] = row[PORT]) : (row_update[PORT] = port)
comment.empty? ? (row_update[COMMENT] = row[COMMENT]) : (row_update[COMMENT] = comment)
data_tmp << "#{row_update.join(',')}\n"
else else
data_tmp << line data_tmp << line
end end
@ -251,7 +257,7 @@ if num_argv >= 2 && ARGV[0] == '-d'
if num_argv == 3 if num_argv == 3
manage.display(ARGV[1], ARGV[2]) manage.display(ARGV[1], ARGV[2])
else else
manage.display(ARGV[3]) manage.display(ARGV[1])
end end
# Remove an item # Remove an item