mirror of
https://github.com/nishiki/manage-password.git
synced 2025-03-19 21:04:35 +00:00
generate a config file
This commit is contained in:
parent
6b9c878ea7
commit
1f7c177eea
2 changed files with 85 additions and 6 deletions
81
cli.rb
Executable file
81
cli.rb
Executable file
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/ruby
|
||||
# author: nishiki
|
||||
# mail: nishiki@yaegashi.fr
|
||||
# info: a simple script who manage your passwords
|
||||
|
||||
require 'rubygems'
|
||||
require 'highline/import'
|
||||
require 'yaml'
|
||||
|
||||
class Cli
|
||||
|
||||
attr_accessor :key
|
||||
attr_accessor :file_gpg
|
||||
attr_accessor :file_pwd
|
||||
attr_accessor :timeout_pwd
|
||||
|
||||
def initialize()
|
||||
@file_config = "#{Dir.home()}/.mpw.cfg"
|
||||
|
||||
if !File.exist?(@file_config) || !self.checkconfig()
|
||||
self.setup()
|
||||
if not self.checkconfig()
|
||||
puts "Error during the checkconfig post setup!"
|
||||
exit 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Create a new config file
|
||||
def setup()
|
||||
key = ask("Enter the GPG key: ")
|
||||
file_gpg = ask("Enter the path to encrypt file [default=#{Dir.home()}/.mpw.gpg]: ")
|
||||
file_pwd = ask("Enter te path to password file [default=#{Dir.home()}/.mpw.pwd]: ")
|
||||
timeout_pwd = ask("Enter the timeout (in seconde) to GPG password [default=300]: ")
|
||||
|
||||
if not key =~ /[a-zA-Z0-9.-_]*\@[a-zA-Z0-9]*\.[a-zA-Z]*/
|
||||
puts "GPG key is invalid!"
|
||||
exit 2
|
||||
end
|
||||
|
||||
if file_gpg.empty?
|
||||
file_gpg = "#{Dir.home()}/.mpw.gpg"
|
||||
end
|
||||
|
||||
if file_pwd.empty?
|
||||
file_pwd = "#{Dir.home()}/.mpw.pwd"
|
||||
end
|
||||
|
||||
timeout_pwd.empty? ? (timeout_pwd = 300) : (timeout_pwd = timeout_pwd.to_i)
|
||||
|
||||
config = {'config' => {'key' => key,
|
||||
'file_gpg' => file_gpg,
|
||||
'timeout_pwd' => timeout_pwd,
|
||||
'file_pwd' => file_pwd}}
|
||||
|
||||
File.open(@file_config, 'w') do |file|
|
||||
file << config.to_yaml
|
||||
end
|
||||
end
|
||||
|
||||
# Check the config file
|
||||
# @rtrn: true if the config file is correct
|
||||
def checkconfig()
|
||||
begin
|
||||
config = YAML::load_file(@file_config)
|
||||
@key = config['config']['key']
|
||||
@file_gpg = config['config']['file_gpg']
|
||||
@file_pwd = config['config']['file_pwd']
|
||||
@timeout_pwd = config['config']['timeout_pwd'].to_i
|
||||
|
||||
if @key.empty? || @file_gpg.empty? || @file_pwd.empty?
|
||||
return false
|
||||
end
|
||||
|
||||
rescue
|
||||
return false
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
10
mpw
10
mpw
|
@ -6,11 +6,7 @@
|
|||
require 'rubygems'
|
||||
require 'optparse'
|
||||
require './manage-password.rb'
|
||||
|
||||
FILE_GPG = './pass.gpg'
|
||||
KEY = 'a.waksberg@yaegashi.fr'
|
||||
FILE_PWD = '/tmp/.password-manager.pwd'
|
||||
TIMEOUT_PWD = 300
|
||||
require './cli.rb'
|
||||
|
||||
options = {}
|
||||
OptionParser.new do |opts|
|
||||
|
@ -47,7 +43,9 @@ OptionParser.new do |opts|
|
|||
end
|
||||
end.parse!
|
||||
|
||||
manage = ManagePasswd.new(KEY, FILE_GPG, FILE_PWD)
|
||||
cli = Cli.new
|
||||
|
||||
manage = ManagePasswd.new(cli.key, cli.file_gpg, cli.file_pwd)
|
||||
|
||||
# Display the item's informations
|
||||
if not options[:display].nil?
|
||||
|
|
Loading…
Add table
Reference in a new issue