mirror of
https://github.com/nishiki/manage-password.git
synced 2025-02-22 02:40:04 +00:00
remove mpw server protocol
This commit is contained in:
parent
855640c932
commit
dd0e236fc5
3 changed files with 0 additions and 205 deletions
|
@ -1,78 +0,0 @@
|
||||||
#!/usr/bin/ruby
|
|
||||||
# author: nishiki
|
|
||||||
# mail: nishiki@yaegashi.fr
|
|
||||||
# info: a simple script who manage your passwords
|
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require 'optparse'
|
|
||||||
require 'pathname'
|
|
||||||
require 'locale'
|
|
||||||
require 'i18n'
|
|
||||||
require 'mpw/server'
|
|
||||||
|
|
||||||
APP_ROOT = File.dirname(Pathname.new(__FILE__).realpath)
|
|
||||||
|
|
||||||
# --------------------------------------------------------- #
|
|
||||||
# Set local
|
|
||||||
# --------------------------------------------------------- #
|
|
||||||
|
|
||||||
lang = Locale::Tag.parse(ENV['LANG']).to_simple.to_s[0..1]
|
|
||||||
|
|
||||||
if defined?(I18n.enforce_available_locales)
|
|
||||||
I18n.enforce_available_locales = true
|
|
||||||
end
|
|
||||||
|
|
||||||
I18n::Backend::Simple.send(:include, I18n::Backend::Fallbacks)
|
|
||||||
I18n.load_path = Dir["#{APP_ROOT}/../i18n/server/*.yml"]
|
|
||||||
I18n.default_locale = :en
|
|
||||||
I18n.locale = lang.to_sym
|
|
||||||
|
|
||||||
# --------------------------------------------------------- #
|
|
||||||
# Options
|
|
||||||
# --------------------------------------------------------- #
|
|
||||||
|
|
||||||
options = {}
|
|
||||||
OptionParser.new do |opts|
|
|
||||||
opts.banner = "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
|
|
||||||
|
|
||||||
opts.on("-c", "--config CONFIG", I18n.t('option.config')) do |config|
|
|
||||||
options[:config] = config
|
|
||||||
end
|
|
||||||
|
|
||||||
opts.on("-t", "--checkconfig", I18n.t('option.checkconfig')) do |b|
|
|
||||||
options[:checkconfig] = b
|
|
||||||
end
|
|
||||||
|
|
||||||
opts.on("-s", "--setup", I18n.t('option.setup')) do |b|
|
|
||||||
options[:setup] = b
|
|
||||||
end
|
|
||||||
|
|
||||||
opts.on("-h", "--help", I18n.t('option.help')) do |b|
|
|
||||||
puts opts
|
|
||||||
exit 0
|
|
||||||
end
|
|
||||||
end.parse!
|
|
||||||
|
|
||||||
# --------------------------------------------------------- #
|
|
||||||
# Main
|
|
||||||
# --------------------------------------------------------- #
|
|
||||||
|
|
||||||
if options[:config].nil? or options[:config].empty?
|
|
||||||
puts "#{I18n.t('option.usage')}: mpw-server -c CONFIG [options]"
|
|
||||||
exit 2
|
|
||||||
end
|
|
||||||
|
|
||||||
server = MPW::Server.new
|
|
||||||
|
|
||||||
if options[:checkconfig]
|
|
||||||
server.checkconfig(options[:config])
|
|
||||||
elsif options[:setup]
|
|
||||||
server.setup(options[:config])
|
|
||||||
else
|
|
||||||
if server.checkconfig(options[:config])
|
|
||||||
server.start
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
server = nil
|
|
||||||
exit 0
|
|
|
@ -30,9 +30,6 @@ module MPW
|
||||||
# @rtrn: true if get the date, else false
|
# @rtrn: true if get the date, else false
|
||||||
def get_remote
|
def get_remote
|
||||||
case @config.sync_type
|
case @config.sync_type
|
||||||
when 'mpw'
|
|
||||||
require 'mpw/sync/mpw'
|
|
||||||
@sync = SyncMPW.new(@config.sync_host, @config.sync_user, @config.sync_pwd, @config.sync_path, @config.sync_port)
|
|
||||||
when 'sftp', 'scp', 'ssh'
|
when 'sftp', 'scp', 'ssh'
|
||||||
require 'mpw/sync/ssh'
|
require 'mpw/sync/ssh'
|
||||||
@sync = SyncSSH.new(@config.sync_host, @config.sync_user, @config.sync_pwd, @config.sync_path, @config.sync_port)
|
@sync = SyncSSH.new(@config.sync_host, @config.sync_user, @config.sync_pwd, @config.sync_path, @config.sync_port)
|
||||||
|
|
|
@ -1,124 +0,0 @@
|
||||||
#!/usr/bin/ruby
|
|
||||||
# author: nishiki
|
|
||||||
|
|
||||||
require 'rubygems'
|
|
||||||
require 'i18n'
|
|
||||||
require 'socket'
|
|
||||||
require 'json'
|
|
||||||
require 'timeout'
|
|
||||||
|
|
||||||
module MPW
|
|
||||||
class SyncMPW
|
|
||||||
|
|
||||||
attr_accessor :error_msg
|
|
||||||
attr_accessor :enable
|
|
||||||
|
|
||||||
# Constructor
|
|
||||||
# @args: host -> the server host
|
|
||||||
# port -> ther connection port
|
|
||||||
# gpg_key -> the gpg key
|
|
||||||
# password -> the remote password
|
|
||||||
# suffix -> the suffix file
|
|
||||||
def initialize(host, user, password, suffix, port=nil)
|
|
||||||
@error_msg = nil
|
|
||||||
@enable = false
|
|
||||||
|
|
||||||
@host = host
|
|
||||||
@port = !port.instance_of?(Integer) ? 2201 : port
|
|
||||||
@gpg_key = user
|
|
||||||
@password = password
|
|
||||||
@suffix = suffix
|
|
||||||
end
|
|
||||||
|
|
||||||
# Connect to server
|
|
||||||
# @rtrn: false if the connection fail
|
|
||||||
def connect
|
|
||||||
Timeout.timeout(10) do
|
|
||||||
begin
|
|
||||||
TCPSocket.open(@host, @port) do
|
|
||||||
@enable = true
|
|
||||||
end
|
|
||||||
rescue Errno::ENETUNREACH
|
|
||||||
retry
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue Timeout::Error
|
|
||||||
@error_msg = "#{I18n.t('error.timeout')}\n#{e}"
|
|
||||||
@enable = false
|
|
||||||
rescue Exception => e
|
|
||||||
@error_msg = "#{I18n.t('error.sync.connection')}\n#{e}"
|
|
||||||
@enable = false
|
|
||||||
else
|
|
||||||
return @enable
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get data on server
|
|
||||||
# @args: gpg_password -> the gpg password
|
|
||||||
# @rtrn: nil if nothing data or error
|
|
||||||
def get(file_tmp)
|
|
||||||
return false if not @enable
|
|
||||||
|
|
||||||
msg = nil
|
|
||||||
TCPSocket.open(@host, @port) do |socket|
|
|
||||||
send_msg = {action: 'get',
|
|
||||||
gpg_key: @gpg_key,
|
|
||||||
password: @password,
|
|
||||||
suffix: @suffix
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.puts send_msg.to_json
|
|
||||||
msg = JSON.parse(socket.gets)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not defined?(msg['error'])
|
|
||||||
@error_msg = I18n.t('error.sync.communication')
|
|
||||||
return false
|
|
||||||
elsif not msg['error'].nil?
|
|
||||||
@error_msg = I18n.t(msg['error'])
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
File.open(file_tmp, 'w') do |file|
|
|
||||||
file << msg['data']
|
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
|
||||||
rescue Exception => e
|
|
||||||
@error_msg = "#{I18n.t('error.sync.download')}\n#{e}"
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
# Update the remote data
|
|
||||||
# @args: data -> the data to send on server
|
|
||||||
# @rtrn: false if there is a problem
|
|
||||||
def update(file_gpg)
|
|
||||||
return true if not @enable
|
|
||||||
|
|
||||||
data = File.open(file_gpg, 'r').read
|
|
||||||
|
|
||||||
msg = nil
|
|
||||||
TCPSocket.open(@host, @port) do |socket|
|
|
||||||
send_msg = {action: 'update',
|
|
||||||
gpg_key: @gpg_key,
|
|
||||||
password: @password,
|
|
||||||
suffix: @suffix,
|
|
||||||
data: data
|
|
||||||
}
|
|
||||||
|
|
||||||
socket.puts send_msg.to_json
|
|
||||||
msg = JSON.parse(socket.gets)
|
|
||||||
end
|
|
||||||
|
|
||||||
if not defined?(msg['error'])
|
|
||||||
@error_msg = I18n.t('error.sync.communication')
|
|
||||||
return false
|
|
||||||
elsif msg['error'].nil?
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
@error_msg = I18n.t(msg['error'])
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
Loading…
Add table
Reference in a new issue