This commit is contained in:
BoHung Chiu 2022-11-14 12:46:26 +08:00
parent c4be16f884
commit e94b273e90
8 changed files with 269 additions and 173 deletions

View File

@ -450,7 +450,7 @@ class Admin::SitePanelController < OrbitAdminController
member_data.created_at = time; member_data.created_at = time;
member_data.updated_at = time; member_data.updated_at = time;
if (member){ if (member){
member_data._id = member._id; delete member_data[\"uid\"];
member = db.member_profiles.update(member_query, {$set: member_data}); member = db.member_profiles.update(member_query, {$set: member_data});
}else{ }else{
member = db.member_profiles.insertOne(member_data); member = db.member_profiles.insertOne(member_data);

View File

@ -49,7 +49,7 @@
<div class="controls" id="root_domain_group"> <div class="controls" id="root_domain_group">
<div class="root_domain_group"> <div class="root_domain_group">
<%= select_tag :root_domain, <%= 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" %> :class => "root_domain" %>
</div> </div>
<%= button_tag 'add root domain',:type => 'button', :id => 'add_root_domain',class: 'btn btn-info',:style => 'margin-top: 1em;' %> <%= button_tag 'add root domain',:type => 'button', :id => 'add_root_domain',class: 'btn btn-info',:style => 'margin-top: 1em;' %>
@ -84,7 +84,7 @@
<div class="controls"> <div class="controls">
<div class="domain_group"> <div class="domain_group">
<input type="text" onchange="change_domain_input(this)" oninput="replace_domain_input(this)"> <input type="text" onchange="change_domain_input(this)" oninput="replace_domain_input(this)">
<span class="root_domain_text"><%= SiteServer.first.domain_names[0] %></span> <span class="root_domain_text"><%= SiteServer.first.domain_names[0] rescue nil %></span>
<%= hidden_field_tag nil,nil, :class => "domain_name",:id=>nil %> <%= hidden_field_tag nil,nil, :class => "domain_name",:id=>nil %>
</div> </div>
<%= f.hidden_field :domain_name %> <%= f.hidden_field :domain_name %>

View File

@ -63,12 +63,13 @@
</td> </td>
<td> <td>
<% if site_server.need_update_site_ids.count != 0 %> <% if site_server.need_update_site_ids.count != 0 %>
<a class="btn btn-primary update_nginx_settings" href="#" data-key="<%=site_server.server_name%>" style="background: blueviolet;"><%=t("client_management.update_nginx_settings")%></a> <a class="btn btn-primary update_nginx_settings" href="javascript:void(0)" data-key="<%=site_server.server_name%>" style="background: blueviolet;"><%=t("client_management.update_nginx_settings")%></a>
<% end %> <% end %>
<a class="btn btn-primary" href = "<%= admin_site_panel_edit_server_info_path+"?id=#{site_server.id.to_s}" %>"><%=t(:edit)%></a> <a class="btn btn-info" href = "<%= admin_site_panel_edit_server_info_path+"?id=#{site_server.id.to_s}" %>"><%=t(:edit)%></a>
<a class="btn btn-danger" href = "#" onclick="if(window.confirm('Do you really want to delete <%=site_server.server_name%>?')) { window.location.href = '<%= admin_site_panel_edit_server_info_path+"?id=#{site_server.id.to_s}&type=delete" %>';}"><%=t(:remove)%></a> <a class="btn btn-danger" href = "#" onclick="if(window.confirm('Do you really want to delete <%=site_server.server_name%>?')) { window.location.href = '<%= admin_site_panel_edit_server_info_path+"?id=#{site_server.id.to_s}&type=delete" %>';}"><%=t(:remove)%></a>
<a class="btn btn-primary" href = "<%= admin_site_panel_sites_list_path+"?server_name=#{site_server.server_name}" %>"><%= t('client_management.see_sites') %></a> <a class="btn btn-primary" href = "<%= admin_site_panel_sites_list_path+"?server_name=#{site_server.server_name}" %>"><%= t('client_management.see_sites') %></a>
<a class="btn btn-primary detect_sites" href="#" data-key="<%=site_server.server_name%>">Detect sites</a> <a class="btn btn-success" href = "<%= backup_setting_admin_site_panel_path(site_server) %>"><%= t('client_management.backup_setting') %></a>
<a class="btn btn-dark btn-inverse detect_sites" href="javascript:void(0)" data-key="<%=site_server.server_name%>">Detect sites</a>
</td> </td>
</tr> </tr>
<% end %> <% end %>
@ -76,11 +77,11 @@
</table> </table>
<div class="bottomnav clearfix"> <div class="bottomnav clearfix">
<div class="pagination pagination-centered"><%=paginate(@site_servers)%></div> <div class="pagination pagination-centered"><%=paginate(@site_servers)%></div>
<a class="btn btn-primary pull-right see_infos" href="#" data-key="detect_sites">See detect infos</a> <a class="btn btn-dark btn-inverse pull-right see_infos" href="javascript:void(0)" data-key="detect_sites">See detect infos</a>
<a class="btn btn-primary pull-right see_infos" href="#" data-key="execing_commands">See exec infos</a> <a class="btn btn-primary pull-right see_infos" href="javascript:void(0)" data-key="execing_commands">See exec infos</a>
<a class="btn btn-primary pull-right" href="<%=admin_site_panel_edit_server_info_path+"?type=create"%>"><%=t(:add)%></a> <a class="btn btn-primary pull-right" href="<%=admin_site_panel_edit_server_info_path+"?type=create"%>"><%=t(:add)%></a>
<a class="btn btn-primary pull-right detect_sites" href="#">Detect sites</a> <a class="btn btn-dark btn-inverse pull-right detect_sites" href="javascript:void(0)">Detect sites</a>
<a id="exec_commands" class="btn btn-primary pull-right" href="#">Exec commands</a> <a id="exec_commands" class="btn btn-primary pull-right" href="javascript:void(0)">Exec commands</a>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
$(document).on("change", "input[data-key=\"{{create_super_manager}}\"]", function() { $(document).on("change", "input[data-key=\"{{create_super_manager}}\"]", function() {
@ -93,6 +94,7 @@
var close_info = false; var close_info = false;
var timeout_id; var timeout_id;
var status_relation = {"starting":"<span style=\"color: skyblue;\">starting</span>","execing":"<span style=\"color: skyblue;\">execing</span>","detecting":"<span style=\"color: skyblue;\">detecting</span>","error":"<span style=\"color: red;\">error</span>","finish": "<span style=\"color: darkseagreen;\">finish</span>","closed":"<span style=\"color: red;\">closed</span>"}; var status_relation = {"starting":"<span style=\"color: skyblue;\">starting</span>","execing":"<span style=\"color: skyblue;\">execing</span>","detecting":"<span style=\"color: skyblue;\">detecting</span>","error":"<span style=\"color: red;\">error</span>","finish": "<span style=\"color: darkseagreen;\">finish</span>","closed":"<span style=\"color: red;\">closed</span>"};
var need_close_info = false;
function show_exec_commands_block(server_names){ function show_exec_commands_block(server_names){
if($("#exec-commands-dialog-confirm").length == 0){ if($("#exec-commands-dialog-confirm").length == 0){
var built_in_commands = "<hr style='clear: both;'/><div><ul class='no_list_style'>" var built_in_commands = "<hr style='clear: both;'/><div><ul class='no_list_style'>"
@ -105,7 +107,7 @@
$("#main-wrap").before("<div id='exec-commands-dialog-confirm' title='Commands to Exec'>"+ $("#main-wrap").before("<div id='exec-commands-dialog-confirm' title='Commands to Exec'>"+
"<div style='clear:both;'></div><div id='server_names_block'></div>"+ "<div style='clear:both;'></div><div id='server_names_block'></div>"+
built_in_commands+ built_in_commands+
"<div style=\"display: none;\" id=\"super_manager_div\"><input type=\"text\" placeholder=\"account\" name=\"account\"><br><input type=\"password\" placeholder=\"password\" name=\"password\"></div>"+"<textarea style='height: 200px;width: 100%;' id='commands_area'></textarea>"+ "<div style=\"display: none;\" id=\"super_manager_div\"><input type=\"text\" placeholder=\"account\" name=\"account\"><br><input type=\"password\" placeholder=\"password\" name=\"password\" minlength=\"8\"></div>"+"<textarea style='height: 200px;width: 100%;' id='commands_area'></textarea>"+
"</div>"); "</div>");
}; };
$( "#exec-commands-dialog-confirm" ).dialog({ $( "#exec-commands-dialog-confirm" ).dialog({
@ -138,7 +140,6 @@
var $els = $(".server_name_checkbox"); var $els = $(".server_name_checkbox");
for(var i = 0; i < $els.length; i++){ for(var i = 0; i < $els.length; i++){
if($els.eq(i).prop("checked")){ if($els.eq(i).prop("checked")){
console.log($els.eq(i));
server_names.push($("label[for='"+$els.eq(i).attr('id')+"']").text().trim()); server_names.push($("label[for='"+$els.eq(i).attr('id')+"']").text().trim());
} }
} }
@ -165,8 +166,18 @@
} }
$("#info_texts").html(status_text+"<div style='clear:both;'></div>"+infos.join("\n")); $("#info_texts").html(status_text+"<div style='clear:both;'></div>"+infos.join("\n"));
msg_end.scrollIntoView(); msg_end.scrollIntoView();
if(need_close_info && status != 'execing'){
close_info = true;
window.setTimeout(function(){
window.location.reload();
},1000);
}else{
if(status == 'execing'){
need_close_info = true;
}
timeout_id = window.setTimeout(see_infos(key),1000); timeout_id = window.setTimeout(see_infos(key),1000);
} }
}
}) })
}else{ }else{
window.clearTimeout(timeout_id); window.clearTimeout(timeout_id);

View File

@ -38,28 +38,30 @@
<td><%=site.display_port%></td> <td><%=site.display_port%></td>
<td class="site_status"><%= (site.status.blank? ? "not yet create" : status_relation[site.status]) %></td> <td class="site_status"><%= (site.status.blank? ? "not yet create" : status_relation[site.status]) %></td>
<td> <td>
<a href="#" title="<%=t("client_management.see_logs_for_site",{:site=>site.domain_name})%>" class="btn btn-primary see_infos" data-id="<%=site.id.to_s%>"><%=t('client_management.see_logs')%></a> <a href="javascript:void(0)" title="<%=t("client_management.see_logs_for_site",{:site=>site.domain_name})%>" class="btn btn-primary see_infos" data-id="<%=site.id.to_s%>"><%=t('client_management.see_logs')%></a>
<% if site.status.blank? || (site.status == 'creating' && (time_now - site.updated_at > 60)) %> <% if site.status.blank? || (site.status == 'creating' && (time_now - site.updated_at > 60)) %>
<a href="#" title="create <%=site.domain_name%>" class="btn btn-primary create_site" data-id="<%=site.id.to_s%>"><%=t('client_management.create_site')%></a> <a href="javascript:void(0)" title="create <%=site.domain_name%>" class="btn btn-primary create_site" data-id="<%=site.id.to_s%>"><%=t('client_management.create_site')%></a>
<% elsif site.status == "error" || site.status == "finish" %> <% elsif site.status == "error" || site.status == "finish" %>
<a href="#" title="recreate <%=site.domain_name%>" class="btn btn-primary recreate_site" data-id="<%=site.id.to_s%>"><%=t('client_management.recreate_site')%></a> <% if site.created_at > Time.now - 3.day %>
<a href="#" title="<%=t("client_management.delete_site_for_site",{:site=>site.domain_name})%>" class="btn btn-primary delete_site" data-id="<%=site.id.to_s%>"><%=t('client_management.delete_site')%></a> <a href="javascript:void(0)" title="recreate <%=site.domain_name%>" class="btn btn-primary recreate_site" data-id="<%=site.id.to_s%>"><%=t('client_management.recreate_site')%></a>
<a href="#" title="<%=t("client_management.close_site_for_site",{:site=>site.domain_name})%>" class="btn btn-primary close_site" data-id="<%=site.id.to_s%>"><%=t('client_management.close_site')%></a> <% end %>
<a href="#" title="Restart <%=site.domain_name%>" class="btn btn-primary open_site" data-id="<%=site.id.to_s%>"><%=t('client_management.restart_site')%></a> <a href="javascript:void(0)" title="<%=t("client_management.delete_site_for_site",{:site=>site.domain_name})%>" class="btn btn-primary delete_site" data-id="<%=site.id.to_s%>"><%=t('client_management.delete_site')%></a>
<a href="javascript:void(0)" title="<%=t("client_management.close_site_for_site",{:site=>site.domain_name})%>" class="btn btn-danger close_site" data-id="<%=site.id.to_s%>"><%=t('client_management.close_site')%></a>
<a href="javascript:void(0)" title="Restart <%=site.domain_name%>" class="btn btn-primary open_site btn-success" data-id="<%=site.id.to_s%>"><%=t('client_management.restart_site')%></a>
<% elsif site.status == "closed" %> <% elsif site.status == "closed" %>
<a href="#" title="<%=t("client_management.delete_site_for_site",{:site=>site.domain_name})%>" class="btn btn-primary delete_site" data-id="<%=site.id.to_s%>"><%=t('client_management.delete_site')%></a> <a href="javascript:void(0)" title="<%=t("client_management.delete_site_for_site",{:site=>site.domain_name})%>" class="btn btn-primary delete_site" data-id="<%=site.id.to_s%>"><%=t('client_management.delete_site')%></a>
<a href="#" title="<%=t("client_management.start_site_for_site",{:site=>site.domain_name})%>" class="btn btn-primary open_site" data-id="<%=site.id.to_s%>"><%=t('client_management.start_site')%></a> <a href="javascript:void(0)" title="<%=t("client_management.start_site_for_site",{:site=>site.domain_name})%>" class="btn btn-success open_site" data-id="<%=site.id.to_s%>"><%=t('client_management.start_site')%></a>
<% end%> <% end%>
<% if site.status.present? %> <% if site.status.present? %>
<% if site.rails_env == "production" %> <% if site.rails_env == "production" %>
<a href="#" title="<%=t("client_management.switch_to_development")%>" class="btn btn-primary open_site" data-id="<%=site.id.to_s%>" data-env="development"><%=t('client_management.switch_to_development')%></a> <a href="javascript:void(0)" title="<%=t("client_management.switch_to_development")%>" class="btn btn-primary open_site btn-success" data-id="<%=site.id.to_s%>" data-env="development"><%=t('client_management.switch_to_development')%></a>
<% else %> <% else %>
<a href="#" title="<%=t("client_management.switch_to_production")%>" class="btn btn-primary open_site" data-id="<%=site.id.to_s%>" data-env="production"><%=t('client_management.switch_to_production')%></a> <a href="javascript:void(0)" title="<%=t("client_management.switch_to_production")%>" class="btn btn-primary open_site btn-success" data-id="<%=site.id.to_s%>" data-env="production"><%=t('client_management.switch_to_production')%></a>
<% end %> <% end %>
<% end %> <% end %>
<a href="#" title="<%=t("client_management.exec_commands_on_site",{:site=>site.domain_name})%>" class="btn btn-primary exec_commands" data-id="<%=site.id.to_s%>"><%=t('client_management.exec_commands')%></a> <a href="javascript:void(0)" title="<%=t("client_management.exec_commands_on_site",{:site=>site.domain_name})%>" class="btn btn-primary exec_commands" data-id="<%=site.id.to_s%>"><%=t('client_management.exec_commands')%></a>
<a href="<%=admin_site_panel_edit_site_path+"?id=#{site.id}&type=detail"%>" title="<%=t("client_management.see_detail_for_site",{:site=>site.domain_name})%>" class="btn btn-primary see_detail" data-id="<%=site.id.to_s%>"><%=t('client_management.detail')%></a> <a href="<%=admin_site_panel_edit_site_path+"?id=#{site.id}&type=detail"%>" title="<%=t("client_management.see_detail_for_site",{:site=>site.domain_name})%>" class="btn btn-info see_detail" data-id="<%=site.id.to_s%>"><%=t('client_management.detail')%></a>
<a href="<%=admin_site_panel_edit_site_path+"?id=#{site.id}&type=delete_from_list"%>" title="<%=t("client_management.delete_from_list_for_site",{:site=>site.domain_name})%>" class="btn btn-primary" data-id="<%=site.id.to_s%>"><%=t('client_management.delete_from_list')%></a> <a href="<%=admin_site_panel_edit_site_path+"?id=#{site.id}&type=delete_from_list"%>" title="<%=t("client_management.delete_from_list_for_site",{:site=>site.domain_name})%>" class="btn btn-danger" data-id="<%=site.id.to_s%>"><%=t('client_management.delete_from_list')%></a>
<% if site.status == "finish" || site.status == "closed" %> <% if site.status == "finish" || site.status == "closed" %>
<a href="<%=admin_site_panel_path+"?copy_id=#{site.id}"%>" title="<%=t('client_management.copy_site_hint')%>" class="btn btn-primary"><%=t('client_management.copy_site')%></a> <a href="<%=admin_site_panel_path+"?copy_id=#{site.id}"%>" title="<%=t('client_management.copy_site_hint')%>" class="btn btn-primary"><%=t('client_management.copy_site')%></a>
<a data-id="<%= site.id %>" title="<%=t('client_management.edit_cert_setting')%>" class="btn btn-primary open-cert-form"><%=t('client_management.edit_cert_setting')%></a> <a data-id="<%= site.id %>" title="<%=t('client_management.edit_cert_setting')%>" class="btn btn-primary open-cert-form"><%=t('client_management.edit_cert_setting')%></a>
@ -80,6 +82,7 @@
<% end %> <% end %>
<% if site.status != "" %> <% if site.status != "" %>
<a data-id="<%= site.id %>" title="<%=t('client_management.https_setting')%>" class="btn btn-primary https_setting"><%=t('client_management.https_setting')%></a> <a data-id="<%= site.id %>" title="<%=t('client_management.https_setting')%>" class="btn btn-primary https_setting"><%=t('client_management.https_setting')%></a>
<a title="<%=t('client_management.super_manager_management')%>" class="btn btn-primary super_manager_management" href="<%=super_manager_management_for_site_admin_site_panel_path(:id=>site.id) %>"><%=t('client_management.super_manager_management')%></a>
<% end %> <% end %>
</td> </td>
</tr> </tr>
@ -91,6 +94,10 @@
<a class="btn btn-primary pull-right" href="<%=admin_site_panel_path%>" title="Create new web"><%=t(:add)%></a> <a class="btn btn-primary pull-right" href="<%=admin_site_panel_path%>" title="Create new web"><%=t(:add)%></a>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">
var close_info = false;
var timeout_id;
var status_relation = {"creating":"<span style=\"color: skyblue;\">creating</span>","error":"<span style=\"color: red;\">error</span>","finish": "<span style=\"color: darkseagreen;\">finish</span>","closed":"<span style=\"color: red;\">closed</span>"};
var need_close_info = false;
$(document).on("change", "input[data-key=\"{{create_super_manager}}\"]", function() { $(document).on("change", "input[data-key=\"{{create_super_manager}}\"]", function() {
if ($(this).prop('checked')){ if ($(this).prop('checked')){
$('#super_manager_div').show() $('#super_manager_div').show()
@ -99,9 +106,6 @@
} }
}); });
$(document).ready(function(){ $(document).ready(function(){
var close_info = false;
var timeout_id;
var status_relation = {"creating":"<span style=\"color: skyblue;\">creating</span>","error":"<span style=\"color: red;\">error</span>","finish": "<span style=\"color: darkseagreen;\">finish</span>","closed":"<span style=\"color: red;\">closed</span>"};
function see_infos(id){ function see_infos(id){
if(!close_info){ if(!close_info){
var request = $.post("<%=admin_site_panel_site_infos_path%>",{"id":id}); var request = $.post("<%=admin_site_panel_site_infos_path%>",{"id":id});
@ -135,14 +139,24 @@
}); });
if(new_params_text[new_params_text.length -1] == "&") if(new_params_text[new_params_text.length -1] == "&")
new_params_text = new_params_text.substr(0,new_params_text.length - 1) new_params_text = new_params_text.substr(0,new_params_text.length - 1)
if(params["id"] == id || window.refresh_flag){ if(params["id"] == id || window.refresh_flag || need_close_info){
close_info = true; close_info = true;
console.log(new_params_text); window.setTimeout(function(){
console.log(window.location.href) var current_location_search = window.location.search;
if(current_location_search == ''){
current_location_search = '?';
}
if(new_params_text == current_location_search){
window.location.reload();
}else{
window.location.search = new_params_text; window.location.search = new_params_text;
} }
}, 1000);
}
}else if(status == "changing"){ }else if(status == "changing"){
window.refresh_flag = true window.refresh_flag = true
}else{
need_close_info = true;
} }
$(".see_infos[data-id="+id+"]").parent().siblings(".site_status").html(status_text); $(".see_infos[data-id="+id+"]").parent().siblings(".site_status").html(status_text);
//msg_end.scrollIntoView(); //msg_end.scrollIntoView();
@ -159,7 +173,7 @@
close_info = true; close_info = true;
window.clearTimeout(timeout_id); window.clearTimeout(timeout_id);
close_info = false; close_info = false;
var id = $(item).data("id"); var id = item.data("id");
if($("#dialog-confirm").length == 0){ if($("#dialog-confirm").length == 0){
$("#main-wrap").before("<div id='dialog-confirm' title='site infos'>"+ $("#main-wrap").before("<div id='dialog-confirm' title='site infos'>"+
"<div style='clear:both;'></div><div id='info_texts'>"+see_infos(id)+"</div><div id='msg_end' style='height:0px; overflow:hidden'></div>"+ "<div style='clear:both;'></div><div id='info_texts'>"+see_infos(id)+"</div><div id='msg_end' style='height:0px; overflow:hidden'></div>"+
@ -180,13 +194,13 @@
} }
}); });
} }
$('.see_infos').click(function(){show_infos_dialog(this);}); $('.see_infos').click(function(){show_infos_dialog($(this));});
$('.create_site').click(function(){ $('.create_site').click(function(){
close_info = true; close_info = true;
window.clearTimeout(timeout_id); window.clearTimeout(timeout_id);
close_info = false; close_info = false;
var id = $(this).attr("data-id"); var item = $(this);
var item = this; var id = item.attr("data-id");
$.post("<%= admin_site_panel_create_site_path %>",{'id': id}).done(function(){ $.post("<%= admin_site_panel_create_site_path %>",{'id': id}).done(function(){
show_infos_dialog(item); show_infos_dialog(item);
}).fail(function() { }).fail(function() {
@ -196,21 +210,64 @@
$('.recreate_site').click(function(){ $('.recreate_site').click(function(){
if(window.confirm("Do you really want to recreate this site?")){ if(window.confirm("Do you really want to recreate this site?")){
if(window.confirm("Do you really want to recreate this site?")){ if(window.confirm("Do you really want to recreate this site?")){
var _this = $(this);
if($("#dialog-confirm").length == 0){
$("#main-wrap").before("<div id='dialog-confirm' title='site infos'>"+
"<div style='clear:both;'></div><div id='info_texts'>"+"Do you really want to "+$(this).attr('title')+"?</div>"+"<input id=\"confirm_input\"/ placeholder=\"<%= t('client_management.please_input_confirm_recreate') %>\" style=\"width: 17em;\">"+"<div id='msg_end' style='height:0px; overflow:hidden'></div>"+
"</div>");
}else{
$("#info_texts").html("Do you really want to "+_this.attr('title')+".");
if($('#confirm_input').length == 0){
$('#info_texts').after("<input id=\"confirm_input\"/ placeholder=\"<%= t('client_management.please_input_confirm_recreate') %>\" style=\"width: 17em;\">");
}else{
$('#confirm_input').css('display','block');
$('#confirm_input').val('');
}
}
$( "#dialog-confirm" ).dialog({
resizable: true,
minHeight: 200,
maxHeight: 400,
modal: true,
width: '80%',
open: function(){
$('#confirm_input').blur();
},
close: function(){
$('#confirm_input').css('display','none');
$( this ).dialog( "close" );
},
buttons: {
"<%= t('client_management.confirm') %>": function(){
if($('#confirm_input').val().match(/<%= t('client_management.confirm_recreate') %>/gi)){
$('#confirm_input').val('');
$('#confirm_input').css('display','none');
close_info = true; close_info = true;
window.clearTimeout(timeout_id); window.clearTimeout(timeout_id);
close_info = false; close_info = false;
var id = $(this).attr("data-id"); var id =_this.attr("data-id");
var item = this; var item = _this;
$.post("<%= admin_site_panel_create_site_path %>",{'id': id}).done(function(){ $.post("<%= admin_site_panel_create_site_path %>",{'id': id}).done(function(){
show_infos_dialog(item); show_infos_dialog(item);
}).fail(function() { }).fail(function() {
window.location.reload(); window.location.reload();
}) })
}else{
alert("<%= t('client_management.please_input_confirm_recreate').html_safe %>");
$('#confirm_input').focus();
}
},
"<%= t('client_management.cancel') %>": function(){
$('#confirm_input').css('display','none');
$( this ).dialog( "close" );
}
}
});
} }
} }
}); });
$('.delete_site').click(function(){ $('.delete_site').click(function(){
var item = this; var item = $(this);
if(window.confirm("Do you really want to delete this site?")){ if(window.confirm("Do you really want to delete this site?")){
if(window.confirm("Do you really want to delete this site?")){ if(window.confirm("Do you really want to delete this site?")){
if($("#dialog-confirm").length == 0){ if($("#dialog-confirm").length == 0){
@ -219,9 +276,13 @@
"</div>"); "</div>");
}else{ }else{
$("#info_texts").html("Do you really want to "+$(this).attr('title')+"."); $("#info_texts").html("Do you really want to "+$(this).attr('title')+".");
if($('#confirm_input').length == 0){
$('#info_texts').after("<input id=\"confirm_input\"/ placeholder=\"<%= t('client_management.please_input_confirm_recreate') %>\" style=\"width: 17em;\">");
}else{
$('#confirm_input').css('display','block'); $('#confirm_input').css('display','block');
$('#confirm_input').val(''); $('#confirm_input').val('');
} }
}
$( "#dialog-confirm" ).dialog({ $( "#dialog-confirm" ).dialog({
resizable: true, resizable: true,
minHeight: 200, minHeight: 200,
@ -238,8 +299,9 @@
buttons: { buttons: {
"<%= t('client_management.confirm') %>": function(){ "<%= t('client_management.confirm') %>": function(){
if($('#confirm_input').val().match(/<%= t('client_management.confirm_delete') %>/gi)){ if($('#confirm_input').val().match(/<%= t('client_management.confirm_delete') %>/gi)){
$('#confirm_input').val('');
$('#confirm_input').css('display','none'); $('#confirm_input').css('display','none');
$.post("<%=admin_site_panel_edit_site_path%>",{'id':$(item).attr("data-id"),'type':'delete'}).done(function(data){ $.post("<%=admin_site_panel_edit_site_path%>",{'id':item.attr("data-id"),'type':'delete'}).done(function(data){
show_infos_dialog(item); show_infos_dialog(item);
item.remove(); item.remove();
}); });
@ -258,8 +320,8 @@
} }
}); });
$(".https_setting").click(function(){ $(".https_setting").click(function(){
var id = $(this).data("id"); var item = $(this);
var item = this; var id = item.data("id");
if($("#https_setting-dialog-confirm").length == 0){ if($("#https_setting-dialog-confirm").length == 0){
$("#main-wrap").before("<div id='https_setting-dialog-confirm' title='<%=t("client_management.https_setting")%>'>" $("#main-wrap").before("<div id='https_setting-dialog-confirm' title='<%=t("client_management.https_setting")%>'>"
+"<div id='https_setting_area'></div>"+ +"<div id='https_setting_area'></div>"+
@ -291,15 +353,15 @@
}) })
}) })
$('.close_site').click(function(){ $('.close_site').click(function(){
var item = this; var item = $(this);
$.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'close'}).done(function(){ $.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'close'}).done(function(){
show_infos_dialog(item); show_infos_dialog(item);
item.remove(); item.remove();
}); });
}); });
$('.open_site').click(function(){ $('.open_site').click(function(){
var item = this; var item = $(this);
var env = $(this).data("env"); var env = item.data("env");
if( env == undefined ) if( env == undefined )
env = ""; env = "";
$.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'open','env': env}).done(function(){ $.post("<%=admin_site_panel_edit_site_path%>",{'id':$(this).attr("data-id"),'type':'open','env': env}).done(function(){
@ -322,7 +384,7 @@
$("#main-wrap").before("<div id='exec-commands-dialog-confirm' title='Commands to Exec'>" + $("#main-wrap").before("<div id='exec-commands-dialog-confirm' title='Commands to Exec'>" +
"<div style='clear:both;'></div>"+ "<div style='clear:both;'></div>"+
built_in_commands+ built_in_commands+
"<div style=\"display: none;\" id=\"super_manager_div\"><input type=\"text\" placeholder=\"account\" name=\"account\"><br><input type=\"password\" placeholder=\"password\" name=\"password\"></div>"+ "<div style=\"display: none;\" id=\"super_manager_div\"><input type=\"text\" placeholder=\"account\" name=\"account\"><br><input type=\"password\" placeholder=\"password\" name=\"password\" minlength=\"8\"></div>"+
"<textarea style='height: 200px;width: 100%;' id='commands_area' data-id='"+id+"'></textarea>"+ "<textarea style='height: 200px;width: 100%;' id='commands_area' data-id='"+id+"'></textarea>"+
"</div>"); "</div>");
}else{ }else{
@ -349,8 +411,6 @@
commands += built_in_commands_selected.join("////"); commands += built_in_commands_selected.join("////");
commands += $('#commands_area').val().replace(/(\r\n|\n)/g,"////"); commands += $('#commands_area').val().replace(/(\r\n|\n)/g,"////");
var id = $('#commands_area').attr('data-id'); var id = $('#commands_area').attr('data-id');
console.log(id);
console.log(commands);
$.post("<%=admin_site_panel_edit_site_path%>",{'id':id,'commands':commands,'account': $('input[name="account"]').val(),'password': $('input[name="password"]').val()}).done(function(){ $.post("<%=admin_site_panel_edit_site_path%>",{'id':id,'commands':commands,'account': $('input[name="account"]').val(),'password': $('input[name="password"]').val()}).done(function(){
show_infos_dialog($('.see_infos[data-id="'+id+'"]').eq(0)); show_infos_dialog($('.see_infos[data-id="'+id+'"]').eq(0));
}); });
@ -386,7 +446,10 @@
}) })
</script> </script>
<style type="text/css"> <style type="text/css">
.delete_site{ .delete_site, .recreate_site{
background: #7d1a23; background: #7d1a23;
} }
.delete_site:hover, .delete_site:focus, .recreate_site:hover, .recreate_site:focus{
background: #eb1d30;
}
</style> </style>

View File

@ -61,7 +61,7 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted" for="active_server"><%= t("client_management.active") %></label> <label class="control-label muted" for="active_server"><%= t("client_management.active") %></label>
<div class="controls"> <div class="controls">
<%= f.check_box :active,:id=>"active_server" %> <%= f.check_box :active,:id=>"active_server",:title=>t("client_management.active") %>
</div> </div>
</div> </div>
<% end %> <% end %>

View File

@ -108,8 +108,10 @@ en:
server_manager: Server Manager server_manager: Server Manager
confirm: Confirm confirm: Confirm
cancel: Cancel cancel: Cancel
please_input_confirm_delete: "Please input 'Confirm delete' to here." please_input_confirm_recreate: "Please input 'Confirm Recreate' to here."
confirm_delete: Confirm delete please_input_confirm_delete: "Please input 'Confirm Delete' to here."
confirm_recreate: Confirm Recreate
confirm_delete: Confirm Delete
action: Action action: Action
see_logs: See logs see_logs: See logs
see_logs_for_site: "see infos for %{site}" see_logs_for_site: "see infos for %{site}"
@ -126,7 +128,7 @@ en:
exec_commands_on_site: "Exec commands on %{site}" exec_commands_on_site: "Exec commands on %{site}"
copy_site: Copy site copy_site: Copy site
copy_site_hint: Copy site to another 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: Delete from list
delete_from_list_for_site: "Delete %{site} from list" delete_from_list_for_site: "Delete %{site} from list"
detail: See details detail: See details

View File

@ -21,12 +21,12 @@ zh_tw:
domain_hint: "*僅能匹配一層的網址" domain_hint: "*僅能匹配一層的網址"
redirect_to_default_domain_name: 跳轉到預設的domain name redirect_to_default_domain_name: 跳轉到預設的domain name
default_domain_names: 預設的domain names default_domain_names: 預設的domain names
disable: 關閉 disable: 停用
enable: enable:
option: option:
'0': 預設 '0': 預設
'1': 關閉 '1': 停用
'2': '2':
alreay_install: 已安裝 alreay_install: 已安裝
not_install: 未安裝 not_install: 未安裝
active: 啟用 active: 啟用
@ -108,7 +108,9 @@ zh_tw:
server_manager: 伺服器管理 server_manager: 伺服器管理
confirm: Confirm confirm: Confirm
cancel: Cancel cancel: Cancel
please_input_confirm_recreate: "請輸入'確認重新架站'。"
please_input_confirm_delete: "請輸入'確認刪除'。" please_input_confirm_delete: "請輸入'確認刪除'。"
confirm_recreate: 確認重新架站
confirm_delete: 確認刪除 confirm_delete: 確認刪除
action: 動作 action: 動作
see_logs: 查看log see_logs: 查看log
@ -126,7 +128,7 @@ zh_tw:
exec_commands_on_site: "在%{site}上執行指令" exec_commands_on_site: "在%{site}上執行指令"
copy_site: 複製網站 copy_site: 複製網站
copy_site_hint: 將該網站的資料複製到新的網站 copy_site_hint: 將該網站的資料複製到新的網站
edit_cert_setting: 更改憑證設定 edit_cert_setting: 更改憑證CSR設定
delete_from_list: 從列表上刪除 delete_from_list: 從列表上刪除
delete_from_list_for_site: "將%{site}從列表上移除(暫時隱藏)" delete_from_list_for_site: "將%{site}從列表上移除(暫時隱藏)"
detail: 查看設定 detail: 查看設定

View File

@ -4,22 +4,29 @@ require 'json'
require 'base64' require 'base64'
namespace :exec_commands do namespace :exec_commands do
desc "Exec commands Script" 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? if args.base64_args.present?
tmp = JSON.parse(Base64.decode64(args.base64_args)) rescue {} tmp = JSON.parse(Base64.decode64(args.base64_args)) rescue {}
args = Rake::TaskArguments.new(tmp.keys, tmp.values) args = Rake::TaskArguments.new(tmp.keys, tmp.values)
end end
@type = args.type @type = args.type
if !args.site_construct_id.blank? if args.site_construct_id.present?
@site_construct = SiteConstruct.find(args.site_construct_id) @site_construct = SiteConstruct.find(args.site_construct_id)
site_server = SiteServer.where(:server_name=>@site_construct.server_type).first site_server = SiteServer.where(:server_name=>@site_construct.server_type).first
site_servers = [site_server] site_servers = [site_server]
@site_construct.update(:status=>"execing",:infos=>[""])
else else
@site_construct = nil @site_construct = nil
site_servers = SiteServer.where(:server_name.in=>args.server_name.split("////")).to_a site_servers = SiteServer.where(:server_name.in=>args.server_name.split("////")).to_a
end end
if args.type == "exec_all" 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 @thread = Multithread.where(:key=>'execing_commands').first
else else
@thread = nil @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}) @command_trans["start_site_in_env,#{env}"] = I18n.t("client_management.start_site_in_env",{:env=>env})
end end
begin begin
if @thread.nil? && args.type == "exec_all" if args.type == "exec_all"
if @thread.nil?
@thread = Multithread.create(:key=>'execing_commands',:status=>{"infos"=>[],"status"=>"execing"}) @thread = Multithread.create(:key=>'execing_commands',:status=>{"infos"=>[],"status"=>"execing"})
else
@thread.update(:status=>{"infos"=>[],"status"=>"execing"})
end
end end
site_servers.each do |site_server| site_servers.each do |site_server|
ip = site_server.ip ip = site_server.ip
@ -102,21 +113,26 @@ namespace :exec_commands do
else else
sites = [@site_construct] sites = [@site_construct]
end 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', 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}}/public -R',
'sudo -p "sudo password:" chmod 777 {{full_site_path}}/app/templates -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:" 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}}\''] '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 end
@commands_i18n = args.commands_i18n # command 客製化翻譯
sites.each do |site_construct| sites.each do |site_construct|
@site_construct = site_construct @site_construct = site_construct
@site_construct.update!(:infos=>[]) @site_construct.update!(:infos=>[])
exec_ssh_command_by_sudo(ssh,"chmod 777 #{@site_construct.path}/#{@site_construct.site_name} -R") 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 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 @command_i18n = command
update_flag = 1 update_flag = 1
@command_relations.each do |k,v| @command_relations.each do |k,v|
@ -126,8 +142,9 @@ namespace :exec_commands do
command = command.gsub("{{#{k}}}",v) command = command.gsub("{{#{k}}}",v)
@command_i18n = @command_i18n.gsub("{{#{k}}}",@command_trans[k]) @command_i18n = @command_i18n.gsub("{{#{k}}}",@command_trans[k])
end end
if command.include?('{{db_name}}') if @commands_i18n
@command_i18n = "create super manager" tmp = @commands_i18n[idx]
@command_i18n = tmp if tmp
end end
command = command.gsub("{{rails_env}}",rails_env) command = command.gsub("{{rails_env}}",rails_env)
command = command.gsub("{{full_site_path}}",@site_construct.full_site_path) 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("{{rails_env}}",rails_env)
@command_i18n = @command_i18n.gsub("{{full_site_path}}",@site_construct.full_site_path) @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_i18n = @command_i18n.gsub("{{site_name}}",@site_construct.site_name)
command = command.gsub(/'{1,3}/,"'\"'\"'") command = command.gsub("'","'\"'\"'")
puts ['command',command,"bash -l -c 'cd #{@site_construct.path}/#{@site_construct.site_name};#{command}'"]
exec_ssh_command_by_sudo_and_see_output(ssh,"bash -l -c 'cd #{@site_construct.path}/#{@site_construct.site_name};#{command}'", update_flag) 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 @command_i18n = nil
end end
@ -147,6 +163,8 @@ namespace :exec_commands do
end end
if !@thread.nil? if !@thread.nil?
@thread.update(:status=>@thread.status.merge({"status"=>"finish"})) @thread.update(:status=>@thread.status.merge({"status"=>"finish"}))
elsif @site_construct
@site_construct.update(:status =>"finish")
end end
rescue => e rescue => e
if !@thread.nil? if !@thread.nil?