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/sync/ftp.rb
CHANGED
@@ -1,81 +1,68 @@
|
|
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
|
require 'net/ftp'
|
8
21
|
|
9
22
|
module MPW
|
10
|
-
|
11
|
-
|
12
|
-
attr_accessor :error_msg
|
13
|
-
attr_accessor :enable
|
14
|
-
|
15
|
-
# Constructor
|
16
|
-
# @args: host -> the server host
|
17
|
-
# port -> ther connection port
|
18
|
-
# gpg_key -> the gpg key
|
19
|
-
# password -> the remote password
|
20
|
-
# suffix -> the suffix file
|
21
|
-
def initialize(host, user, password, path, port=nil)
|
22
|
-
@error_msg = nil
|
23
|
-
@enable = false
|
23
|
+
class FTP
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@enable = false
|
42
|
-
else
|
43
|
-
return @enable
|
44
|
-
end
|
45
|
-
|
46
|
-
# Get data on server
|
47
|
-
# @args: gpg_password -> the gpg password
|
48
|
-
# @rtrn: nil if nothing data or error
|
49
|
-
def get(file_tmp)
|
50
|
-
return false if not @enable
|
51
|
-
|
52
|
-
Net::FTP.open(@host) do |ftp|
|
53
|
-
ftp.login(@user, @password)
|
54
|
-
ftp.gettextfile(@path, file_tmp)
|
55
|
-
end
|
56
|
-
|
57
|
-
return true
|
58
|
-
rescue Exception => e
|
59
|
-
@error_msg = "#{I18n.t('error.sync.download')}\n#{e}"
|
60
|
-
return false
|
25
|
+
# Constructor
|
26
|
+
# @args: config -> the config
|
27
|
+
def initialize(config)
|
28
|
+
@host = config['host']
|
29
|
+
@user = config['user']
|
30
|
+
@password = config['password']
|
31
|
+
@path = config['path']
|
32
|
+
@port = config['port'].instance_of?(Integer) ? 22 : config['port']
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Connect to server
|
37
|
+
def connect
|
38
|
+
Net::FTP.open(@host) do |ftp|
|
39
|
+
ftp.login(@user, @password)
|
40
|
+
break
|
61
41
|
end
|
62
|
-
|
63
|
-
#
|
64
|
-
|
65
|
-
# @rtrn: false if there is a problem
|
66
|
-
def update(file_gpg)
|
67
|
-
return true if not @enable
|
68
|
-
|
69
|
-
Net::FTP.open(@host) do |ftp|
|
70
|
-
ftp.login(@user, @password)
|
71
|
-
ftp.puttextfile(file_gpg, @path)
|
72
|
-
end
|
42
|
+
rescue Exception => e
|
43
|
+
raise "#{I18n.t('error.sync.connection')}\n#{e}"
|
44
|
+
end
|
73
45
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
46
|
+
# Get data on server
|
47
|
+
# @args: file_tmp -> the path where download the file
|
48
|
+
def get(file_tmp)
|
49
|
+
Net::FTP.open(@host) do |ftp|
|
50
|
+
ftp.login(@user, @password)
|
51
|
+
ftp.gettextfile(@path, file_tmp)
|
78
52
|
end
|
53
|
+
rescue Exception => e
|
54
|
+
raise "#{I18n.t('error.sync.download')}\n#{e}"
|
55
|
+
end
|
79
56
|
|
57
|
+
# Update the remote data
|
58
|
+
# @args: file_gpg -> the data to send on server
|
59
|
+
def update(file_gpg)
|
60
|
+
Net::FTP.open(@host) do |ftp|
|
61
|
+
ftp.login(@user, @password)
|
62
|
+
ftp.puttextfile(file_gpg, @path)
|
63
|
+
end
|
64
|
+
rescue Exception => e
|
65
|
+
raise "#{I18n.t('error.sync.upload')}\n#{e}"
|
80
66
|
end
|
81
67
|
end
|
68
|
+
end
|
data/lib/mpw/sync/ssh.rb
CHANGED
@@ -1,80 +1,67 @@
|
|
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
|
require 'net/ssh'
|
8
21
|
require 'net/sftp'
|
9
22
|
|
10
23
|
module MPW
|
11
|
-
|
12
|
-
|
13
|
-
attr_accessor :error_msg
|
14
|
-
attr_accessor :enable
|
15
|
-
|
16
|
-
# Constructor
|
17
|
-
# @args: host -> the server host
|
18
|
-
# port -> ther connection port
|
19
|
-
# gpg_key -> the gpg key
|
20
|
-
# password -> the remote password
|
21
|
-
def initialize(host, user, password, path, port=nil)
|
22
|
-
@error_msg = nil
|
23
|
-
@enable = false
|
24
|
+
class SyncSSH
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
def connect
|
35
|
-
Net::SSH.start(@host, @user, password: @password, port: @port) do |ssh|
|
36
|
-
@enable = true
|
37
|
-
end
|
38
|
-
rescue Exception => e
|
39
|
-
@error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
|
40
|
-
@enable = false
|
41
|
-
else
|
42
|
-
return @enable
|
43
|
-
end
|
44
|
-
|
45
|
-
# Get data on server
|
46
|
-
# @args: gpg_password -> the gpg password
|
47
|
-
# @rtrn: nil if nothing data or error
|
48
|
-
def get(file_tmp)
|
49
|
-
return false if not @enable
|
50
|
-
|
51
|
-
Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
|
52
|
-
sftp.lstat(@path) do |response|
|
53
|
-
sftp.download!(@path, file_tmp) if response.ok?
|
54
|
-
end
|
55
|
-
end
|
26
|
+
# Constructor
|
27
|
+
# @args: config -> the config
|
28
|
+
def initialize(config)
|
29
|
+
@host = config['host']
|
30
|
+
@user = config['user']
|
31
|
+
@password = config['password']
|
32
|
+
@path = config['path']
|
33
|
+
@port = config['port'].instance_of?(Integer) ? 22 : config['port']
|
34
|
+
end
|
56
35
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
36
|
+
# Connect to server
|
37
|
+
def connect
|
38
|
+
Net::SSH.start(@host, @user, password: @password, port: @port) do
|
39
|
+
break
|
61
40
|
end
|
62
|
-
|
63
|
-
#
|
64
|
-
|
65
|
-
# @rtrn: false if there is a problem
|
66
|
-
def update(file_gpg)
|
67
|
-
return true if not @enable
|
68
|
-
|
69
|
-
Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
|
70
|
-
sftp.upload!(file_gpg, @path)
|
71
|
-
end
|
41
|
+
rescue Exception => e
|
42
|
+
raise "#{I18n.t('error.sync.connection')}\n#{e}"
|
43
|
+
end
|
72
44
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
45
|
+
# Get data on server
|
46
|
+
# @args: file_tmp -> the path where download the file
|
47
|
+
def get(file_tmp)
|
48
|
+
Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
|
49
|
+
sftp.lstat(@path) do |response|
|
50
|
+
sftp.download!(@path, file_tmp) if response.ok?
|
51
|
+
end
|
77
52
|
end
|
53
|
+
rescue Exception => e
|
54
|
+
raise "#{I18n.t('error.sync.download')}\n#{e}"
|
55
|
+
end
|
78
56
|
|
57
|
+
# Update the remote data
|
58
|
+
# @args: file_gpg -> the data to send on server
|
59
|
+
def update(file_gpg)
|
60
|
+
Net::SFTP.start(@host, @user, password: @password, port: @port) do |sftp|
|
61
|
+
sftp.upload!(file_gpg, @path)
|
62
|
+
end
|
63
|
+
rescue Exception => e
|
64
|
+
raise "#{I18n.t('error.sync.upload')}\n#{e}"
|
79
65
|
end
|
80
66
|
end
|
67
|
+
end
|