This commit is contained in:
BoHung Chiu 2022-12-02 13:09:43 +08:00
parent 09ac174c63
commit 9592608857
6 changed files with 48 additions and 28 deletions

View File

@ -327,22 +327,23 @@ class Admin::SitePanelController < OrbitAdminController
render :json =>{"success"=>true} render :json =>{"success"=>true}
end end
def edit_site def edit_site
if params[:type] == 'delete' case params[:type]
when 'delete'
Thread.new do Thread.new do
system("bundle exec rake create_site:delete_site[#{params[:id]}]") system("bundle exec rake create_site:delete_site[#{params[:id]}]")
end end
elsif params[:type] == 'close' when 'close'
Thread.new do Thread.new do
Rake::Task['exec_commands:exec_commands'].execute(Rake::TaskArguments.new([:site_construct_id,:commands,:type], [params[:id], '', 'close_site'])) Rake::Task['exec_commands:exec_commands'].execute(Rake::TaskArguments.new([:site_construct_id,:commands,:type], [params[:id], '', 'close_site']))
end end
elsif params[:type] == 'open' || params[:type] == 'restart' when 'open', 'restart'
Thread.new do Thread.new do
Rake::Task['exec_commands:exec_commands'].execute(Rake::TaskArguments.new([:site_construct_id,:commands,:type,:server_name,:rails_env], [params[:id], '', 'open_site', '', params[:env]])) Rake::Task['exec_commands:exec_commands'].execute(Rake::TaskArguments.new([:site_construct_id,:commands,:type,:server_name,:rails_env], [params[:id], '', 'open_site', '', params[:env]]))
end end
elsif params[:type] == 'detail' when 'detail'
@site_construct = SiteConstruct.find(params[:id]) @site_construct = SiteConstruct.find(params[:id])
render 'see_detail_for_created_site' and return render 'see_detail_for_created_site' and return
elsif params[:type] == 'change_server_name' when 'change_server_name'
site_construct = SiteConstruct.find(params[:id]) site_construct = SiteConstruct.find(params[:id])
site_construct.update_attributes(update_site_params) site_construct.update_attributes(update_site_params)
site_construct.update(:domain_name=>params[:site_construct][:domain_name]) site_construct.update(:domain_name=>params[:site_construct][:domain_name])
@ -352,14 +353,14 @@ class Admin::SitePanelController < OrbitAdminController
Bundler.with_clean_env{system(cmd)} Bundler.with_clean_env{system(cmd)}
end end
redirect_to admin_site_panel_edit_site_path(:id=>params[:id],:type=>'detail',:status=>'changing') and return redirect_to admin_site_panel_edit_site_path(:id=>params[:id],:type=>'detail',:status=>'changing') and return
elsif params[:type] == 'delete_from_list' when 'delete_from_list'
SiteConstruct.find(params[:id]).destroy SiteConstruct.find(params[:id]).destroy
if Is_Rails5 if Is_Rails5
redirect_back(fallback_location: { action: "sites_list"}) redirect_back(fallback_location: { action: "sites_list"})
else else
redirect_to :back and return redirect_to :back and return
end end
elsif params[:type] == 'select_cert' when 'select_cert'
is_certbot = true is_certbot = true
if params[:server_names] if params[:server_names]
is_certbot = false is_certbot = false
@ -386,7 +387,7 @@ class Admin::SitePanelController < OrbitAdminController
system("bundle exec rake create_site:change_site_cert[#{params[:id]},#{is_certbot},#{params[:is_server]}]") system("bundle exec rake create_site:change_site_cert[#{params[:id]},#{is_certbot},#{params[:is_server]}]")
end end
end end
elsif params[:type] == 'apply_change_users' when 'apply_change_users'
Thread.new do Thread.new do
exec_commands_args = {} exec_commands_args = {}
site_server = nil site_server = nil

View File

@ -169,7 +169,9 @@
if(need_close_info && status != 'execing'){ if(need_close_info && status != 'execing'){
close_info = true; close_info = true;
window.setTimeout(function(){ window.setTimeout(function(){
if(window.confirm("<%=t('client_management.finished_reload_page')%>")){
window.location.reload(); window.location.reload();
}
},1000); },1000);
}else{ }else{
if(status == 'execing'){ if(status == 'execing'){
@ -204,10 +206,17 @@
open: function(){ open: function(){
$(this).parent().css("top",$(document).height() - $(window).height() + "px"); $(this).parent().css("top",$(document).height() - $(window).height() + "px");
}, },
close: function(){close_info = true;}, close: function(){
close_info = true;
need_close_info = false;
},
buttons: { buttons: {
"<%= t('client_management.confirm') %>": function(){$( this ).dialog( "close" );close_info = true;}, "<%= t('client_management.confirm') %>": function(){
"stop update": function(){close_info = true;} $( this ).dialog( "close" );
},
"stop update": function(){
close_info = true;
}
} }
}); });
} }

View File

@ -146,11 +146,13 @@
if(current_location_search == ''){ if(current_location_search == ''){
current_location_search = '?'; current_location_search = '?';
} }
if(window.confirm("<%=t('client_management.finished_reload_page')%>")){
if(new_params_text == current_location_search){ if(new_params_text == current_location_search){
window.location.reload(); window.location.reload();
}else{ }else{
window.location.search = new_params_text; window.location.search = new_params_text;
} }
}
}, 1000); }, 1000);
} }
}else if(status == "changing"){ }else if(status == "changing"){
@ -187,10 +189,17 @@
maxHeight: 400, maxHeight: 400,
modal: true, modal: true,
width: '80%', width: '80%',
close: function(){$( this ).dialog( "close" );close_info = true;}, close: function(){
close_info = true;
need_close_info = false;
},
buttons: { buttons: {
"<%= t('client_management.confirm') %>": function(){$( this ).dialog( "close" );close_info = true;}, "<%= t('client_management.confirm') %>": function(){
"stop update": function(){close_info = true;} $( this ).dialog( "close" );
},
"stop update": function(){
close_info = true;
}
} }
}); });
} }

View File

@ -7,6 +7,7 @@ en:
upload_cert: Upload Cert upload_cert: Upload Cert
cert_management: Cert Management cert_management: Cert Management
client_management: client_management:
finished_reload_page: "Finished!\\nReload Page!"
apply_change: "Apply Change" apply_change: "Apply Change"
are_you_sure_to_delete: "Are you sure to delete?" are_you_sure_to_delete: "Are you sure to delete?"
user_name: "User Account" user_name: "User Account"

View File

@ -7,6 +7,7 @@ zh_tw:
upload_cert: 上傳憑證 upload_cert: 上傳憑證
cert_management: 憑證管理 cert_management: 憑證管理
client_management: client_management:
finished_reload_page: "已完成!\\n重新載入頁面!"
apply_change: "設定生效" apply_change: "設定生效"
are_you_sure_to_delete: "您確定要刪除嗎?" are_you_sure_to_delete: "您確定要刪除嗎?"
user_name: "使用者帳號" user_name: "使用者帳號"

View File

@ -188,11 +188,6 @@ namespace :exec_commands do
end end
def update_infos_for_exec(info,update_last=false,update_array=false) def update_infos_for_exec(info,update_last=false,update_array=false)
return if @site_construct.nil? return if @site_construct.nil?
if(update_array)
info.map!{|i| i.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => '')}
else
info.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => '')
end
if update_last && !@site_construct.infos.empty? if update_last && !@site_construct.infos.empty?
@site_construct.infos[-1] += info.to_s @site_construct.infos[-1] += info.to_s
else else
@ -238,12 +233,16 @@ namespace :exec_commands do
channel.exec("LANG=en.UTF8 #{command}") do |ch, success| channel.exec("LANG=en.UTF8 #{command}") do |ch, success|
abort "could not execute command: #{command}" unless success abort "could not execute command: #{command}" unless success
channel.on_data do |ch, data| channel.on_data do |ch, data|
if data.to_s.include?("sudo password:") || data.to_s.include?("Password:") data_str = data.to_s
data_str.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => '')
if data_str.include?("sudo password:") || data_str.include?("Password:")
channel.send_data "#{@password}\n" channel.send_data "#{@password}\n"
else else
print "#{data}" print data_str unless @no_stdout
data_str = data.to_s data_str.gsub!("\r\n", "\n")
if data.include?("\n") || outputs.empty? data_str.sub!(/\r$/, '')
next if data_str.length == 0
if data_str.include?("\n") || outputs.empty?
output_lines = data_str.split("\n") output_lines = data_str.split("\n")
first_output = output_lines[0] first_output = output_lines[0]
if first_output if first_output