28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/vagrant-node/nodeserverpasswd.rb', line 28
def execute
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: vagrant nodeserver passwd"
end
i=0
begin
if (!DB::DBManager.check_config_file(@env.data_dir))
puts "Configuring Vagrant Node"
print "Insert privileged database user: "
user=STDIN.cooked(&:gets).chomp
print "Insert privileged database user password: "
password=STDIN.noecho(&:gets).chomp
print "\n"
print "Insert database name: "
database=STDIN.cooked(&:gets).chomp
print "\n"
DB::DBManager.create_config_file(@env.data_dir,'localhost',database,user,password)
end
db = DB::DBManager.new(@env.data_dir)
rescue Exception => e
if (!DB::DBManager.check_config_file(@env.data_dir))
retry
end
if (e.class==Mysql2::Error)
print "Can't connect to mysql with current configuration, please review provided credentials. Please execute again this command to reconfigure"
DB::DBManager.delete_config_file(@env.data_dir)
end
end
if (!db.nil?)
if (db.node_password_set? && !db.node_default_password_set?)
print "Insert current password: "
old_password=STDIN.noecho(&:gets).chomp
print "\n"
if !db.node_check_password?(old_password)
@env.ui.error("Password failed!")
return 0
end
end
pass_m = "Insert your new password for this Node: "
confirm_m = "Please Insert again the new password: "
if STDIN.respond_to?(:noecho)
print pass_m
password=STDIN.noecho(&:gets).chomp
print "\n#{confirm_m}"
confirm=STDIN.noecho(&:gets).chomp
print "\n"
else
password = @env.ui.ask(pass_m)
confirm = @env.ui.ask(confirm_m)
end
if (password==confirm)
db.node_password_set(password)
@env.ui.success("Password changed!")
else
@env.ui.error("Passwords does not match!")
end
end
0
end
|