diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index 9d01cb7..c8f7eea 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -5,6 +5,22 @@ class Admin::SitePanelController < OrbitAdminController @app_title = "client_management" end + def update_cert_setting + site_params = params.require('site').permit! + if !site_params['cert_ver_file_content'].blank? + site_params['cert_ver_file_content'] = Nokogiri::HTML.parse(site_params['cert_ver_file_content'].gsub(/\r\n|\n/,'').gsub(//, "\n")).inner_text + end + if !site_params['cert_ver_location_path'].blank? && site_params['cert_ver_location_path'].start_with?('h') + site_params['cert_ver_location_path'] = URI(site_params['cert_ver_location_path']).path + end + site = SiteConstruct.where(id: site_params[:id]).first + site.update_attributes(site_params) + Thread.new do + system("bundle exec rake create_site:add_cert_ver_for_site['#{site_params[:id]}']") + end + redirect_to "/#{I18n.locale}/admin/site_panel/sites_list?server_name=#{site.server_type}" + end + def index @site_construct = SiteConstruct.new @module_app = ModuleApp.where(:title=>@app_title).first diff --git a/app/views/admin/site_panel/_sites_list_table.html.erb b/app/views/admin/site_panel/_sites_list_table.html.erb index e0c9e0c..238e0da 100644 --- a/app/views/admin/site_panel/_sites_list_table.html.erb +++ b/app/views/admin/site_panel/_sites_list_table.html.erb @@ -42,6 +42,21 @@ " title="Delete <%=site.domain_name%> from list" class="btn btn-primary" data-id="<%=site.id.to_s%>">Delete from list <% if site.status == "finish" || site.status == "closed" %> " title="Copy site to another site." class="btn btn-primary">Copy site + Edit cert Setting +
" class="cert-form" style="display: none;"> + <%= form_for site, as: 'site', url: "/#{I18n.locale}/admin/site_panel/update_cert_setting",method: "post" do |f| %> +
+ CSR txt path:  + <%= f.text_field 'cert_ver_location_path',style: 'width: calc(100% - 8em);margin: 0;' %> +
+
+ CSR txt content:  + <%= f.text_area 'cert_ver_file_content',class: 'ckeditor',value: site.cert_ver_file_content.to_s.gsub("\n",'
') %> +
+ <%= f.hidden_field 'id' %> + <%= f.submit 'edit',class: 'btn btn-primary' %> + <% end %> +
<% end %> @@ -249,5 +264,18 @@ } }); <% end %> + $(".cert-form").dialog({ + autoOpen: false, + show: "blind", + modal: true, + width: '90vw', + maxHeight: '80vh', + open: function() { + $(this).css("max-height", '80vh'); + } + }); + $('.open-cert-form').click(function(){ + $('#cert-form-'+$(this).data('id')).dialog('open') + }) }) \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index eebedd1..2e548c1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -48,6 +48,7 @@ Rails.application.routes.draw do get "site_panel/server_manager" => "site_panel#server_manager" get "site_panel/edit_server_info" => "site_panel#edit_server_info" post "site_panel/edit_server_info" => "site_panel#edit_server_info" + post "site_panel/update_cert_setting" => "site_panel#update_cert_setting" resources :site_panel end diff --git a/lib/tasks/add_cert_ver_for_site.rake b/lib/tasks/add_cert_ver_for_site.rake index 792ab6f..c46a2d5 100644 --- a/lib/tasks/add_cert_ver_for_site.rake +++ b/lib/tasks/add_cert_ver_for_site.rake @@ -18,11 +18,11 @@ namespace :create_site do end file_name = location_path.split('/')[-1] file_path = "#{site_construct.path}/#{site_construct.site_name}/tmp/#{file_name}" - site_construct.cert_ver_added_text = " location #{location_path}{\n alias #{file_path};\n }" + site_construct.cert_ver_added_text = " location #{location_path}{#add_by_site_module\n alias #{file_path};\n }" site_construct.save server_array = nginx_config.scan(/^[ \t]*server[ \t]{(?:(?!server[ \t]*{).)+}/m) server_array.each do |server| - tmp = server[0...-1] + site_construct.cert_ver_added_text + "\n }" + tmp = server[0...-1] + site_construct.cert_ver_added_text + "\n}" nginx_config = nginx_config.sub(server,tmp) end cmd = "x='#{cert_ver_file_content}'; echo '#{@password}' | sudo -S sh -c \"echo '$x' > #{file_path}\"; unset x" diff --git a/lib/tasks/change_site_server_name.rake b/lib/tasks/change_site_server_name.rake index 590546f..a349902 100644 --- a/lib/tasks/change_site_server_name.rake +++ b/lib/tasks/change_site_server_name.rake @@ -23,7 +23,7 @@ namespace :create_site do end def exec_command_by_user(session,command) output = session.exec!(command) - return output + return output[0..-1] end def exec_ssh_command_by_sudo(session,command) output = session.exec!("echo '#{@password}' | sudo -S #{command}")