diff --git a/app/controllers/admin/site_panel_controller.rb b/app/controllers/admin/site_panel_controller.rb index 8c0671f..2303911 100644 --- a/app/controllers/admin/site_panel_controller.rb +++ b/app/controllers/admin/site_panel_controller.rb @@ -450,7 +450,7 @@ class Admin::SitePanelController < OrbitAdminController member_data.created_at = time; member_data.updated_at = time; if (member){ - member_data._id = member._id; + delete member_data[\"uid\"]; member = db.member_profiles.update(member_query, {$set: member_data}); }else{ member = db.member_profiles.insertOne(member_data); diff --git a/app/views/admin/site_panel/_form.html.erb b/app/views/admin/site_panel/_form.html.erb index bc6df87..7c45bc0 100644 --- a/app/views/admin/site_panel/_form.html.erb +++ b/app/views/admin/site_panel/_form.html.erb @@ -49,7 +49,7 @@
<%= select_tag :root_domain, - options_for_select(SiteServer.first.domain_names.collect{ |u| [u, u] }), + options_for_select((SiteServer.first.domain_names.collect{ |u| [u, u] } rescue [])), :class => "root_domain" %>
<%= button_tag 'add root domain',:type => 'button', :id => 'add_root_domain',class: 'btn btn-info',:style => 'margin-top: 1em;' %> @@ -84,7 +84,7 @@
- <%= SiteServer.first.domain_names[0] %> + <%= SiteServer.first.domain_names[0] rescue nil %> <%= hidden_field_tag nil,nil, :class => "domain_name",:id=>nil %>
<%= f.hidden_field :domain_name %> diff --git a/app/views/admin/site_panel/_server_manager_index.html.erb b/app/views/admin/site_panel/_server_manager_index.html.erb index b1a34b9..8771d89 100644 --- a/app/views/admin/site_panel/_server_manager_index.html.erb +++ b/app/views/admin/site_panel/_server_manager_index.html.erb @@ -63,12 +63,13 @@ <% if site_server.need_update_site_ids.count != 0 %> - <%=t("client_management.update_nginx_settings")%> + <%=t("client_management.update_nginx_settings")%> <% end %> - "><%=t(:edit)%> + "><%=t(:edit)%> ';}"><%=t(:remove)%> "><%= t('client_management.see_sites') %> - Detect sites + <%= t('client_management.backup_setting') %> + Detect sites <% end %> @@ -76,11 +77,11 @@ \ No newline at end of file diff --git a/app/views/admin/site_panel/edit_server_info.html.erb b/app/views/admin/site_panel/edit_server_info.html.erb index 4911ef9..03d5016 100644 --- a/app/views/admin/site_panel/edit_server_info.html.erb +++ b/app/views/admin/site_panel/edit_server_info.html.erb @@ -61,7 +61,7 @@
- <%= f.check_box :active,:id=>"active_server" %> + <%= f.check_box :active,:id=>"active_server",:title=>t("client_management.active") %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 7c6a08a..d360f38 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -108,8 +108,10 @@ en: server_manager: Server Manager confirm: Confirm cancel: Cancel - please_input_confirm_delete: "Please input 'Confirm delete' to here." - confirm_delete: Confirm delete + please_input_confirm_recreate: "Please input 'Confirm Recreate' to here." + please_input_confirm_delete: "Please input 'Confirm Delete' to here." + confirm_recreate: Confirm Recreate + confirm_delete: Confirm Delete action: Action see_logs: See logs see_logs_for_site: "see infos for %{site}" @@ -126,7 +128,7 @@ en: exec_commands_on_site: "Exec commands on %{site}" copy_site: Copy site copy_site_hint: Copy site to another site. - edit_cert_setting: Edit cert Setting + edit_cert_setting: Edit Cert CSR Setting delete_from_list: Delete from list delete_from_list_for_site: "Delete %{site} from list" detail: See details diff --git a/config/locales/zh_tw.yml b/config/locales/zh_tw.yml index a2f7287..afabc3a 100644 --- a/config/locales/zh_tw.yml +++ b/config/locales/zh_tw.yml @@ -21,12 +21,12 @@ zh_tw: domain_hint: "*僅能匹配一層的網址" redirect_to_default_domain_name: 跳轉到預設的domain name default_domain_names: 預設的domain names - disable: 關閉 - enable: 開啟 + disable: 停用 + enable: 啟用 option: '0': 預設 - '1': 關閉 - '2': 開啟 + '1': 停用 + '2': 啟用 alreay_install: 已安裝 not_install: 未安裝 active: 啟用 @@ -108,7 +108,9 @@ zh_tw: server_manager: 伺服器管理 confirm: Confirm cancel: Cancel + please_input_confirm_recreate: "請輸入'確認重新架站'。" please_input_confirm_delete: "請輸入'確認刪除'。" + confirm_recreate: 確認重新架站 confirm_delete: 確認刪除 action: 動作 see_logs: 查看log @@ -126,7 +128,7 @@ zh_tw: exec_commands_on_site: "在%{site}上執行指令" copy_site: 複製網站 copy_site_hint: 將該網站的資料複製到新的網站 - edit_cert_setting: 更改憑證設定 + edit_cert_setting: 更改憑證CSR設定 delete_from_list: 從列表上刪除 delete_from_list_for_site: "將%{site}從列表上移除(暫時隱藏)" detail: 查看設定 diff --git a/lib/tasks/exec_command.rake b/lib/tasks/exec_command.rake index 5cb52b0..42f969f 100644 --- a/lib/tasks/exec_command.rake +++ b/lib/tasks/exec_command.rake @@ -4,22 +4,29 @@ require 'json' require 'base64' namespace :exec_commands do desc "Exec commands Script" - task :exec_commands,[:base64_args,:site_construct_id,:commands,:type,:server_name,:rails_env] => :environment do |task,args| + task :exec_commands,[:base64_args,:site_construct_id,:commands,:type,:server_name,:rails_env,:commands_i18n] => :environment do |task,args| if args.base64_args.present? tmp = JSON.parse(Base64.decode64(args.base64_args)) rescue {} args = Rake::TaskArguments.new(tmp.keys, tmp.values) end @type = args.type - if !args.site_construct_id.blank? + if args.site_construct_id.present? @site_construct = SiteConstruct.find(args.site_construct_id) site_server = SiteServer.where(:server_name=>@site_construct.server_type).first site_servers = [site_server] + @site_construct.update(:status=>"execing",:infos=>[""]) else @site_construct = nil site_servers = SiteServer.where(:server_name.in=>args.server_name.split("////")).to_a end if args.type == "exec_all" - Multithread.where(:key=>'execing_commands').each{|thread| thread.destroy if (thread.status["status"] == "error" || thread.status["status"] == "finish")} + Multithread.where(:key=>'execing_commands').each do |thread| + if thread.status["status"] == "error" || thread.status["status"] == "finish" + thread.destroy + elsif thread.updated_at < (Time.now - 5.minute) + thread.destroy + end + end @thread = Multithread.where(:key=>'execing_commands').first else @thread = nil @@ -38,8 +45,12 @@ namespace :exec_commands do @command_trans["start_site_in_env,#{env}"] = I18n.t("client_management.start_site_in_env",{:env=>env}) end begin - if @thread.nil? && args.type == "exec_all" - @thread = Multithread.create(:key=>'execing_commands',:status=>{"infos"=>[],"status"=>"execing"}) + if args.type == "exec_all" + if @thread.nil? + @thread = Multithread.create(:key=>'execing_commands',:status=>{"infos"=>[],"status"=>"execing"}) + else + @thread.update(:status=>{"infos"=>[],"status"=>"execing"}) + end end site_servers.each do |site_server| ip = site_server.ip @@ -102,21 +113,26 @@ namespace :exec_commands do else sites = [@site_construct] end - if args.commands.include?("{{create_users}}") + commands = args.commands + if commands.class == String + commands = commands.split("////").select{|c| c != ""} + elsif commands.nil? + commands = [] + end + if commands.include?("{{create_users}}") commands = ['sudo -p "sudo password:" chmod 777 {{full_site_path}} -R', 'sudo -p "sudo password:" chmod 777 {{full_site_path}}/public -R', 'sudo -p "sudo password:" chmod 777 {{full_site_path}}/app/templates -R', 'sudo -p "sudo password:" useradd --home-dir {{full_site_path}}/app/templates {{site_name}} --no-create-home --badnames', 'sudo -p "sudo password:" bash -l -c \'echo -e "{{site_name}}\n{{site_name}}"|passwd {{site_name}}\''] - else - commands = args.commands.split("////").select{|c| c != ""} rescue [args.commands] end + @commands_i18n = args.commands_i18n # command 客製化翻譯 sites.each do |site_construct| @site_construct = site_construct @site_construct.update!(:infos=>[]) exec_ssh_command_by_sudo(ssh,"chmod 777 #{@site_construct.path}/#{@site_construct.site_name} -R") rails_env = @site_construct.rails_env.blank? ? "development" : @site_construct.rails_env - commands.each do |command| + commands.each_with_index do |command, idx| @command_i18n = command update_flag = 1 @command_relations.each do |k,v| @@ -126,8 +142,9 @@ namespace :exec_commands do command = command.gsub("{{#{k}}}",v) @command_i18n = @command_i18n.gsub("{{#{k}}}",@command_trans[k]) end - if command.include?('{{db_name}}') - @command_i18n = "create super manager" + if @commands_i18n + tmp = @commands_i18n[idx] + @command_i18n = tmp if tmp end command = command.gsub("{{rails_env}}",rails_env) command = command.gsub("{{full_site_path}}",@site_construct.full_site_path) @@ -136,8 +153,7 @@ namespace :exec_commands do @command_i18n = @command_i18n.gsub("{{rails_env}}",rails_env) @command_i18n = @command_i18n.gsub("{{full_site_path}}",@site_construct.full_site_path) @command_i18n = @command_i18n.gsub("{{site_name}}",@site_construct.site_name) - command = command.gsub(/'{1,3}/,"'\"'\"'") - puts ['command',command,"bash -l -c 'cd #{@site_construct.path}/#{@site_construct.site_name};#{command}'"] + command = command.gsub("'","'\"'\"'") exec_ssh_command_by_sudo_and_see_output(ssh,"bash -l -c 'cd #{@site_construct.path}/#{@site_construct.site_name};#{command}'", update_flag) @command_i18n = nil end @@ -147,6 +163,8 @@ namespace :exec_commands do end if !@thread.nil? @thread.update(:status=>@thread.status.merge({"status"=>"finish"})) + elsif @site_construct + @site_construct.update(:status =>"finish") end rescue => e if !@thread.nil?