2017-11-30 09:00:26 +00:00
|
|
|
class Admin::SitePanelController < OrbitAdminController
|
2017-11-30 10:49:21 +00:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
|
|
|
@app_title = "client_management"
|
|
|
|
end
|
|
|
|
|
2017-11-30 09:00:26 +00:00
|
|
|
def index
|
|
|
|
@site_construct = SiteConstruct.new
|
2020-04-24 14:38:28 +00:00
|
|
|
@module_app = ModuleApp.where(:title=>@app_title).first
|
|
|
|
end
|
|
|
|
def server_manager
|
|
|
|
@module_app = ModuleApp.where(:title=>@app_title).first
|
|
|
|
@categories = @module_app.categories
|
|
|
|
@tags = []
|
|
|
|
@filter_fields = filter_fields(@categories,@tags)
|
|
|
|
@site_servers = SiteServer.all.with_categories(filters("category")).with_status(filters("status"))
|
|
|
|
@site_servers = search_data(@site_servers,[:server_name,:ip]).page(params[:page].to_i).per(10)
|
|
|
|
if request.xhr?
|
|
|
|
render :partial => "server_manager_index"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
def edit_server_info
|
|
|
|
@module_app = ModuleApp.where(:title=>@app_title).first
|
|
|
|
if params[:type] == 'update'
|
|
|
|
@site_server = SiteServer.find(params[:id]) rescue nil
|
|
|
|
if @site_server.present?
|
|
|
|
@site_server.update_attributes(site_server_params)
|
|
|
|
else
|
|
|
|
@site_server = SiteServer.create(site_server_params)
|
|
|
|
end
|
|
|
|
redirect_to admin_site_panel_server_manager_path
|
|
|
|
elsif params[:type] == 'create'
|
|
|
|
@site_server = SiteServer.new
|
|
|
|
elsif params[:type] == 'delete'
|
|
|
|
SiteServer.find(params[:id]).destroy
|
|
|
|
redirect_to admin_site_panel_server_manager_path
|
|
|
|
else
|
|
|
|
@site_server = SiteServer.find(params[:id])
|
|
|
|
end
|
2017-11-30 09:00:26 +00:00
|
|
|
end
|
|
|
|
def create
|
|
|
|
site_construct = SiteConstruct.new(site_construct_params)
|
2017-11-30 09:59:06 +00:00
|
|
|
site_construct.user_id = current_user.id.to_s
|
2020-04-24 14:38:28 +00:00
|
|
|
site_construct.status = "creating"
|
2017-11-30 09:00:26 +00:00
|
|
|
site_construct.save
|
2020-04-24 14:38:28 +00:00
|
|
|
git_user = "chiu"
|
|
|
|
git_password = "orbit_is_great_1"
|
|
|
|
git_url = "http://gitlab.tp.rulingcom.com/orbit_chiu1/orbit4-5.git"
|
|
|
|
site_server = SiteServer.where(:server_name=>site_construct.server_type).first
|
|
|
|
ip = site_server.ip
|
|
|
|
user = site_server.account
|
|
|
|
password = site_server.password
|
|
|
|
site_name = site_construct.site_name
|
|
|
|
domain_name = site_construct.domain_name
|
|
|
|
port = site_construct.port
|
|
|
|
db_name = site_construct.db_name
|
|
|
|
path = site_construct.path
|
|
|
|
site_construct_id = site_construct.id.to_s
|
|
|
|
Thread.new do
|
|
|
|
system("rake create_site:create_site[#{git_user},#{git_password},#{git_url},#{ip},#{user},#{password},#{site_name},#{domain_name},#{port},#{db_name},#{path},#{site_construct_id}]")
|
|
|
|
end
|
|
|
|
redirect_to "#{admin_site_panel_sites_list_path}?id=#{site_construct_id}"
|
|
|
|
end
|
|
|
|
def create_site
|
|
|
|
site_construct = SiteConstruct.find(params[:id])
|
|
|
|
site_construct.user_id = current_user.id.to_s
|
|
|
|
git_user = "chiu"
|
|
|
|
git_password = "orbit_is_great_1"
|
|
|
|
git_url = "http://gitlab.tp.rulingcom.com/orbit_chiu1/orbit4-5.git"
|
|
|
|
site_server = SiteServer.where(:server_name=>site_construct.server_type).first
|
|
|
|
ip = site_server.ip
|
|
|
|
user = site_server.account
|
|
|
|
password = site_server.password
|
|
|
|
site_name = site_construct.site_name
|
|
|
|
domain_name = site_construct.domain_name
|
|
|
|
port = site_construct.port
|
|
|
|
db_name = site_construct.db_name
|
|
|
|
path = site_construct.path
|
|
|
|
site_construct_id = params[:id]
|
|
|
|
Thread.new do
|
|
|
|
puts site_construct_id
|
|
|
|
system("rake create_site:create_site['#{git_user}','#{git_password}','#{git_url}','#{ip}','#{user}','#{password}','#{site_name}','#{domain_name}','#{port}','#{db_name}','#{path}','#{site_construct_id}']")
|
|
|
|
end
|
|
|
|
render :json =>{"success"=>true}
|
|
|
|
end
|
|
|
|
def sites_list
|
|
|
|
@sites = SiteConstruct.all.desc(:id)
|
|
|
|
end
|
|
|
|
def site_infos
|
|
|
|
site_construct = SiteConstruct.where(:id=>params[:id]).first
|
|
|
|
if site_construct.nil?
|
|
|
|
render :json => {:status=>"creating",:infos=>[]}
|
|
|
|
else
|
|
|
|
render :json => {:status=>site_construct.status,:infos=>site_construct.infos}
|
|
|
|
end
|
2017-11-30 09:00:26 +00:00
|
|
|
end
|
|
|
|
private
|
|
|
|
|
|
|
|
def site_construct_params
|
|
|
|
params.require(:site_construct).permit!
|
|
|
|
end
|
2020-04-24 14:38:28 +00:00
|
|
|
def site_server_params
|
|
|
|
params.require(:site_server).permit!
|
|
|
|
end
|
2017-11-30 09:00:26 +00:00
|
|
|
end
|