mpw 2.0.3 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -5
- data/README.md +115 -6
- data/VERSION +1 -1
- data/bin/mpw +90 -58
- data/i18n/{cli/en.yml → en.yml} +43 -49
- data/i18n/{cli/fr.yml → fr.yml} +45 -51
- data/lib/mpw/config.rb +117 -206
- data/lib/mpw/item.rb +98 -88
- data/lib/mpw/mpw.rb +416 -288
- data/lib/mpw/sync/ftp.rb +55 -68
- data/lib/mpw/sync/ssh.rb +52 -65
- data/lib/mpw/ui/cli.rb +201 -175
- data/mpw.gemspec +9 -8
- metadata +28 -29
- data/bin/mpw-server +0 -78
- data/bin/mpw-ssh +0 -89
- data/i18n/server/en.yml +0 -26
- data/i18n/server/fr.yml +0 -26
- data/lib/mpw/server.rb +0 -343
- data/lib/mpw/sync/mpw.rb +0 -124
- data/lib/mpw/sync.rb +0 -138
- data/lib/mpw/ui/clissh.rb +0 -42
data/lib/mpw/item.rb
CHANGED
@@ -1,109 +1,119 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# MPW is a software to crypt and manage your passwords
|
3
|
+
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
|
4
|
+
#
|
5
|
+
# This program is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU General Public License
|
7
|
+
# as published by the Free Software Foundation; either version 2
|
8
|
+
# of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
4
18
|
|
5
|
-
require 'rubygems'
|
6
19
|
require 'i18n'
|
7
20
|
|
8
21
|
module MPW
|
9
|
-
|
22
|
+
class Item
|
10
23
|
|
11
|
-
|
24
|
+
attr_accessor :error_msg
|
12
25
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
attr_accessor :created
|
26
|
+
attr_accessor :id
|
27
|
+
attr_accessor :name
|
28
|
+
attr_accessor :group
|
29
|
+
attr_accessor :host
|
30
|
+
attr_accessor :protocol
|
31
|
+
attr_accessor :user
|
32
|
+
attr_accessor :port
|
33
|
+
attr_accessor :comment
|
34
|
+
attr_accessor :last_edit
|
35
|
+
attr_accessor :last_sync
|
36
|
+
attr_accessor :created
|
25
37
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty?
|
37
|
-
@id = generate_id
|
38
|
-
@created = Time.now.to_i
|
39
|
-
else
|
40
|
-
@id = options[:id]
|
41
|
-
@created = options[:created]
|
42
|
-
@last_edit = options[:last_edit]
|
43
|
-
options[:no_update_last_edit] = true
|
44
|
-
end
|
45
|
-
|
46
|
-
update(options)
|
38
|
+
# Constructor
|
39
|
+
# Create a new item
|
40
|
+
# @args: options -> a hash of parameter
|
41
|
+
# raise an error if the hash hasn't the key name
|
42
|
+
def initialize(options={})
|
43
|
+
if not options.has_key?(:name) or options[:name].to_s.empty?
|
44
|
+
@error_msg = I18n.t('error.update.name_empty')
|
45
|
+
raise @error_msg
|
47
46
|
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
48
|
+
if not options.has_key?(:id) or options[:id].to_s.empty? or not options.has_key?(:created) or options[:created].to_s.empty?
|
49
|
+
@id = generate_id
|
50
|
+
@created = Time.now.to_i
|
51
|
+
else
|
52
|
+
@id = options[:id]
|
53
|
+
@created = options[:created]
|
54
|
+
@last_edit = options[:last_edit]
|
55
|
+
options[:no_update_last_edit] = true
|
56
|
+
end
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
@host = options[:host] if options.has_key?(:host)
|
61
|
-
@protocol = options[:protocol] if options.has_key?(:protocol)
|
62
|
-
@user = options[:user] if options.has_key?(:user)
|
63
|
-
@password = options[:password] if options.has_key?(:password)
|
64
|
-
@port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty?
|
65
|
-
@comment = options[:comment] if options.has_key?(:comment)
|
66
|
-
@last_edit = Time.now.to_i if not options.has_key?(:no_update_last_edit)
|
58
|
+
update(options)
|
59
|
+
end
|
67
60
|
|
68
|
-
|
61
|
+
# Update the item
|
62
|
+
# @args: options -> a hash of parameter
|
63
|
+
# @rtrn: true if the item is update
|
64
|
+
def update(options={})
|
65
|
+
if options.has_key?(:name) and options[:name].to_s.empty?
|
66
|
+
@error_msg = I18n.t('error.update.name_empty')
|
67
|
+
return false
|
69
68
|
end
|
70
69
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
@name = options[:name] if options.has_key?(:name)
|
71
|
+
@group = options[:group] if options.has_key?(:group)
|
72
|
+
@host = options[:host] if options.has_key?(:host)
|
73
|
+
@protocol = options[:protocol] if options.has_key?(:protocol)
|
74
|
+
@user = options[:user] if options.has_key?(:user)
|
75
|
+
@port = options[:port].to_i if options.has_key?(:port) and not options[:port].to_s.empty?
|
76
|
+
@comment = options[:comment] if options.has_key?(:comment)
|
77
|
+
@last_edit = Time.now.to_i if not options.has_key?(:no_update_last_edit)
|
75
78
|
|
76
|
-
|
77
|
-
|
78
|
-
def delete
|
79
|
-
@id = nil
|
80
|
-
@name = nil
|
81
|
-
@group = nil
|
82
|
-
@host = nil
|
83
|
-
@protocol = nil
|
84
|
-
@user = nil
|
85
|
-
@password = nil
|
86
|
-
@port = nil
|
87
|
-
@comment = nil
|
88
|
-
@created = nil
|
89
|
-
@last_edit = nil
|
90
|
-
@last_sync = nil
|
79
|
+
return true
|
80
|
+
end
|
91
81
|
|
92
|
-
|
93
|
-
|
82
|
+
# Update last_sync
|
83
|
+
def set_last_sync
|
84
|
+
@last_sync = Time.now.to_i
|
85
|
+
end
|
94
86
|
|
95
|
-
|
96
|
-
|
97
|
-
|
87
|
+
# Delete all data
|
88
|
+
# @rtrn: true
|
89
|
+
def delete
|
90
|
+
@id = nil
|
91
|
+
@name = nil
|
92
|
+
@group = nil
|
93
|
+
@host = nil
|
94
|
+
@protocol = nil
|
95
|
+
@user = nil
|
96
|
+
@port = nil
|
97
|
+
@comment = nil
|
98
|
+
@created = nil
|
99
|
+
@last_edit = nil
|
100
|
+
@last_sync = nil
|
98
101
|
|
99
|
-
|
100
|
-
|
101
|
-
end
|
102
|
+
return true
|
103
|
+
end
|
102
104
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
105
|
+
def empty?
|
106
|
+
return @name.to_s.empty?
|
107
|
+
end
|
108
|
+
|
109
|
+
def nil?
|
110
|
+
return false
|
111
|
+
end
|
112
|
+
|
113
|
+
# Generate an random id
|
114
|
+
private
|
115
|
+
def generate_id
|
116
|
+
return ([*('A'..'Z'),*('a'..'z'),*('0'..'9')]).sample(16).join
|
108
117
|
end
|
118
|
+
end
|
109
119
|
end
|