From 31751455c59c34e44b202793b6a29aafe3761e49 Mon Sep 17 00:00:00 2001
From: nishiki <nishiki@yaegashi.fr>
Date: Fri, 13 May 2016 15:51:17 +0200
Subject: [PATCH] secure the wallet config

---
 lib/mpw/mpw.rb | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb
index e488805..2408515 100644
--- a/lib/mpw/mpw.rb
+++ b/lib/mpw/mpw.rb
@@ -22,7 +22,7 @@ class MPW
 
 	# Read mpw file
 	def read_data
-		@config    = nil
+		@config    = {}
 		@data      = []
 		@keys      = {}
 		@passwords = {}
@@ -187,7 +187,15 @@ class MPW
 	# Set config
 	# args: config -> a hash with config options
 	def set_config(config)
-		@config = config
+		@config['sync'] = {} if @config['sync'].nil?
+
+		@config['sync']['type']      = config['sync']['type']
+		@config['sync']['host']      = config['sync']['host']
+		@config['sync']['port']      = config['sync']['port']
+		@config['sync']['user']      = config['sync']['user']
+		@config['sync']['password']  = config['sync']['password']
+		@config['sync']['path']      = config['sync']['path']
+		@config['sync']['last_sync'] = @config['sync']['last_sync'].nil? ? 0 : @config['sync']['last_sync']
 	end
 
 	# Add a new item
@@ -300,7 +308,7 @@ class MPW
 
 	# Sync data with remote file
 	def sync
-		return if @config['sync'].nil?
+		return if @config.empty? or @config['sync'].nil?
 		
 		tmp_file  = "#{@wallet_file}.sync"
 		last_sync = @config['last_sync'].to_i