mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-20 01:50:04 +00:00
feat: add import old version of mpw
This commit is contained in:
parent
8b5c7ae581
commit
dd02776baa
2 changed files with 81 additions and 0 deletions
46
lib/mpw/import/mpw_old.rb
Normal file
46
lib/mpw/import/mpw_old.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/usr/bin/ruby
|
||||
# MPW is a software to crypt and manage your passwords
|
||||
# Copyright (C) 2017 Adrien Waksberg <mpw@yae.im>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
require 'yaml'
|
||||
|
||||
module MPW
|
||||
module Import
|
||||
# Import an export mpw file
|
||||
# @param file [String] the file path to import
|
||||
def self.mpw_old(file)
|
||||
data = {}
|
||||
YAML.load_file(file).each do |id, item|
|
||||
url = ''
|
||||
url += "#{item['protocol']}://" if item['protocol']
|
||||
url += item['host']
|
||||
url += ":#{item['port']}" if item['port']
|
||||
|
||||
data[id] = {
|
||||
'comment' => item['comment'],
|
||||
'group' => item['group'],
|
||||
'otp' => item['otp'],
|
||||
'password' => item['password'],
|
||||
'url' => url,
|
||||
'user' => item['user']
|
||||
}
|
||||
end
|
||||
|
||||
data
|
||||
end
|
||||
end
|
||||
end
|
35
test/files/import-mpw_old.txt
Normal file
35
test/files/import-mpw_old.txt
Normal file
|
@ -0,0 +1,35 @@
|
|||
---
|
||||
1:
|
||||
host: fric.com
|
||||
user: 12345
|
||||
group: Bank
|
||||
password: secret
|
||||
protocol: http
|
||||
port:
|
||||
otp_key:
|
||||
comment: Fric money money
|
||||
last_edit: 1487623641
|
||||
created: 1485729356
|
||||
2:
|
||||
host: server.com
|
||||
user: sercret2
|
||||
group:
|
||||
password:
|
||||
protocol:
|
||||
port: 4222
|
||||
otp_key:
|
||||
comment: My little server
|
||||
last_edit: 1487623641
|
||||
created: 1485729356
|
||||
3:
|
||||
host: fric.com
|
||||
user: username
|
||||
group: Cloud
|
||||
password:
|
||||
protocol: ssh
|
||||
port: 4333
|
||||
otp_key:
|
||||
comment: bastion
|
||||
last_edit: 1487623641
|
||||
created: 1485729356
|
||||
|
Loading…
Add table
Reference in a new issue