Skip to content

Commit 0abbc12

Browse files
Merge pull request #289 from aleksei-burlakov/remove-rootpw
Dev: wizards: don't use root password
2 parents 9f555fd + 12b741d commit 0abbc12

File tree

6 files changed

+9
-43
lines changed

6 files changed

+9
-43
lines changed

hawk/app/assets/javascripts/module/wizards.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ $(function() {
101101
var errors = $.map(xhr.responseJSON, function(e) { return '<pre class="bg-danger">' + e + '</pre>'; }).join("");
102102
vform.find(".notifications").html(errors);
103103
});
104-
vform.on("change", "#rootpw", function() {
105-
vform.find(".submit").prop("disabled", false);
106-
});
107104

108105
$('.hljs').each(function(i, block) {
109106
hljs.highlightBlock(block);

hawk/app/controllers/wizards_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ def submit
5050
@wizard.verify(pa)
5151
if @wizard.errors.length > 0
5252
render json: @wizard.errors.to_json, status: :unprocessable_entity
53-
elsif current_cib.sim? && @wizard.need_rootpw
53+
elsif current_cib.sim?
5454
render json: [_("Wizard cannot be applied when the simulator is active")], status: :unprocessable_entity
5555
else
56-
@wizard.run(pa, params[:rootpw])
56+
@wizard.run(pa)
5757
if @wizard.errors.length > 0
5858
render json: @wizard.errors.to_json, status: :unprocessable_entity
5959
else

hawk/app/lib/crm_script.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def cleanerr(err)
3939
end
4040
module_function :cleanerr
4141

42-
def run(jsondata, rootpw)
42+
def run(jsondata)
4343
user = current_user
4444
cmd = crmsh_escape(JSON.dump(jsondata))
4545
tmpf = Tempfile.new 'crmscript'

hawk/app/models/wizard.rb

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class Wizard
2020
attr_reader :actions
2121
attr_reader :output
2222
attr_reader :errors
23-
attr_reader :need_rootpw
2423

2524
def persisted?
2625
true
@@ -39,7 +38,6 @@ def initialize(name, category, shortdesc, longdesc)
3938
@actions = nil
4039
@output = nil
4140
@errors = nil
42-
@need_rootpw = false
4341
end
4442

4543
def id
@@ -63,26 +61,14 @@ def verify(params)
6361
@params = params
6462
@actions = []
6563
@errors = []
66-
CrmScript.run ["verify", @name, params], nil do |action, err|
64+
CrmScript.run ["verify", @name, params] do |action, err|
6765
@errors << err if err
6866
unless action.nil?
6967
@errors << action["error"] if action.key? "error"
7068
action['text'].gsub!(/\t/, " ") if action.key? "text"
7169
@actions << action unless action.key? "error"
7270
end
7371
end
74-
75-
@need_rootpw = @errors.empty? && @actions.any? do |action|
76-
return false if action['name'] == 'cib'
77-
if action['name'] == 'crm'
78-
t = (action['text'] || '').split.first || ''
79-
return false if ['configure', 'resource', 'cib'].any? { |c| c == t }
80-
end
81-
if action['name'] == 'call' && action['sudo'].nil? && action['nodes'] == 'local'
82-
return false
83-
end
84-
true
85-
end
8672
end
8773

8874
def command_string
@@ -99,14 +85,14 @@ def command_string
9985
base.join(" ")
10086
end
10187

102-
def run(params, rootpw=nil)
88+
def run(params)
10389
# TODO: live-update frontend
10490
@params = params
10591
@actions = []
10692
@errors = []
10793
@output = nil
10894
CrmEvents.instance.push command_string
109-
CrmScript.run ["run", @name, @params], rootpw do |result, err|
95+
CrmScript.run ["run", @name, @params] do |result, err|
11096
@errors << err if err
11197
unless result.nil?
11298
Rails.logger.debug "result: #{result}"
@@ -152,7 +138,7 @@ def parse_full(data)
152138

153139
def find(name)
154140
w = nil
155-
CrmScript.run ["show", name], nil do |item, err|
141+
CrmScript.run ["show", name] do |item, err|
156142
Rails.logger.error "Wizard.find: #{err}" unless err.nil?
157143
raise Cib::RecordNotFound, _("Requested wizard does not exist") unless err.nil?
158144
w = Wizard.parse_full(item) unless item.nil?
@@ -178,7 +164,7 @@ def wizard_ok(item)
178164
def all
179165
Rails.cache.fetch(:all_wizards, expires_in: 2.hours) do
180166
[].tap do |wizards|
181-
CrmScript.run ["list"], nil do |item, err|
167+
CrmScript.run ["list"] do |item, err|
182168
Rails.logger.debug "Error listing scripts: #{err}" unless err.blank?
183169
wizards.push Wizard.parse_brief(item) if wizard_ok(item)
184170
end

hawk/app/views/wizards/update.html.erb

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,6 @@
6161
<% end %>
6262
</ul>
6363
</div>
64-
<% if @wizard.need_rootpw %>
65-
<div class="alert alert-warning">
66-
<p>
67-
<%= _("To apply the changes, Hawk requires root access, and password-less SSH access must be configured. See the Hawk documentation for more information.") %>
68-
</p>
69-
</div>
70-
<div class="form-group">
71-
<div class="col-sm-5 text-right">
72-
<%= label_tag(:rootpw, _("Root password")) %>
73-
</div>
74-
<div class="col-sm-7">
75-
<%= password_field_tag :rootpw, nil, class: "form-control", required: true %>
76-
</div>
77-
<div class="col-sm-5 help-block"></div>
78-
</div>
79-
<% end %>
8064
</fieldset>
8165
<%= main_form.button_group class: "wizard" do %>
8266
<%= link_to _("Cancel"), cib_wizards_path(cib_id: current_cib.id), class: "btn btn-default", data: { confirm: _("Do you really want to cancel the wizard setup?") } %>

hawk/config/initializers/filter.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
Rails.application.config.tap do |config|
55
config.filter_parameters += [
6-
:password,
7-
:rootpw
6+
:password
87
]
98
end

0 commit comments

Comments
 (0)