2020-04-24 14:38:28 +00:00
|
|
|
class SiteServer
|
|
|
|
include Mongoid::Document
|
|
|
|
include Mongoid::Timestamps
|
|
|
|
include OrbitCategory::Categorizable
|
|
|
|
include OrbitTag::Taggable
|
|
|
|
include OrbitModel::Status
|
|
|
|
field :server_name , type: String ,default: ''
|
2021-10-08 12:04:38 +00:00
|
|
|
field :enable_redirect_default_domain, type: Boolean, default: false
|
|
|
|
field :default_domain_names, type: Array, default: []
|
2020-04-24 14:38:28 +00:00
|
|
|
field :domain_name , type: String ,default: ''
|
2021-01-28 03:10:41 +00:00
|
|
|
field :domain_names, type: Array, default: []
|
2020-04-24 14:38:28 +00:00
|
|
|
field :ip , type: String ,default: ''
|
|
|
|
field :account , type: String ,default: ''
|
|
|
|
field :password , type: String ,default: ''
|
|
|
|
field :active , type: Boolean ,default: true
|
2021-08-11 08:16:14 +00:00
|
|
|
field :has_certbot, type: Boolean , default: false
|
2021-10-08 12:04:38 +00:00
|
|
|
field :need_update_site_ids, type: Array, default: []
|
2021-01-28 03:10:41 +00:00
|
|
|
def domain_names
|
|
|
|
if self.domain_name != ''
|
|
|
|
[self.domain_name]
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
2021-10-08 12:04:38 +00:00
|
|
|
def site_constructs
|
|
|
|
SiteConstruct.where(server_type: self.server_name)
|
|
|
|
end
|
2021-01-28 03:10:41 +00:00
|
|
|
before_save do
|
|
|
|
if self.domain_name != '' && self.domain_names.length !=0
|
|
|
|
self.domain_name = ''
|
|
|
|
end
|
2021-10-08 12:04:38 +00:00
|
|
|
tmp_site_constructs = site_constructs
|
|
|
|
need_change = false
|
|
|
|
if self.enable_redirect_default_domain_changed?
|
|
|
|
tmp_site_constructs = tmp_site_constructs.where(:enable_redirect_default_domain.in=>[nil,0])
|
|
|
|
need_change = true
|
|
|
|
end
|
|
|
|
if (need_change || (!need_change && self.enable_redirect_default_domain))
|
|
|
|
if self.default_domain_names_changed?
|
|
|
|
check_domains = []
|
2021-11-18 01:39:01 +00:00
|
|
|
removed_default_domains = self.default_domain_names_was.to_a - self.default_domain_names
|
|
|
|
add_default_domains = self.default_domain_names - self.default_domain_names_was.to_a
|
2021-10-08 12:04:38 +00:00
|
|
|
check_domains += removed_default_domains
|
|
|
|
check_domains += add_default_domains
|
|
|
|
check_domains = check_domains.map{|domain| Regexp.new("(\\A|\\s)"+domain.gsub(".","\\.").gsub("*","[^.]*") + "($|\\s)")}
|
|
|
|
tmp_site_constructs = tmp_site_constructs.where(:domain_name.in=>check_domains)
|
|
|
|
need_change = true
|
|
|
|
elsif need_change
|
|
|
|
check_domains = self.default_domain_names
|
|
|
|
check_domains = check_domains.map{|domain| Regexp.new("(\\A|\\s)"+domain.gsub(".","\\.").gsub("*","[^.]*") + "($|\\s)")}
|
|
|
|
tmp_site_constructs = tmp_site_constructs.where(:domain_name.in=>check_domains)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if need_change
|
|
|
|
self.need_update_site_ids += tmp_site_constructs.pluck(:id)
|
|
|
|
self.need_update_site_ids = self.need_update_site_ids.uniq
|
|
|
|
end
|
2021-01-28 03:10:41 +00:00
|
|
|
end
|
2020-04-24 14:38:28 +00:00
|
|
|
end
|