client_management/app/models/site_construct.rb

65 lines
1.6 KiB
Ruby
Raw Normal View History

class SiteConstruct
include Mongoid::Document
include Mongoid::Timestamps
def self.server_types
SiteServer.all.map{|s| s.server_name}
end
SITE_TYPES = ["School","Gravity"]
field :server_type
field :site_name
field :domain_name
2021-01-19 04:48:03 +00:00
field :nginx_file
field :db_name
field :port, type: String, :default => "80"
field :path
field :site_type
field :school_name
field :user_id
field :constructed, type: Boolean, :default => false
field :status, type: String, :default => ""
field :infos, type: Array, :default => []
2021-01-19 04:48:03 +00:00
field :hidden, type: Boolean, :default => false
2021-02-23 06:18:25 +00:00
field :copy_id
2021-02-24 10:44:09 +00:00
field :cert_ver_added_text
field :cert_ver_file_content
field :cert_ver_location_path
after_initialize do |record|
if record.status.nil?
record.status = ""
record.save
end
if record.infos.nil?
record.infos = []
record.save
end
2021-01-19 04:48:03 +00:00
if record.nginx_file.nil?
record.nginx_file = "/etc/nginx/orbit_sites/"+record.site_name.to_s
record.save
end
if record.path.nil?
dir_path = ((record.site_type == "School" && !record.school_name.blank?) ? "school_sites/#{record.school_name}" : "orbit_sites")
record.path = "/home/rulingcom/#{dir_path}"
end
end
2021-02-21 03:59:36 +00:00
def get_site_name
return self.site_name.gsub(" ","\\ ")
end
2021-02-16 08:49:58 +00:00
def get_domain_name
scheme = ""
extra_port = ""
if self.port == "443"
scheme = "https://"
else
scheme = "http://"
if self.port != "80"
extra_port = ":#{self.port}"
end
end
return (scheme + self.domain_name + extra_port)
end
2021-02-17 16:59:11 +00:00
def site_server
SiteServer.where(server_name: self.server_type).first
end
end