mirror of
https://github.com/neocities/neocities.git
synced 2025-04-24 17:22:35 +02:00
Refactor redis proxy storage
This commit is contained in:
parent
0bd8557620
commit
34ac611d9b
2 changed files with 37 additions and 12 deletions
|
@ -372,6 +372,7 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
def username=(val)
|
def username=(val)
|
||||||
|
@redis_proxy_change = true
|
||||||
super val.downcase
|
super val.downcase
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -827,6 +828,7 @@ class Site < Sequel::Model
|
||||||
end
|
end
|
||||||
|
|
||||||
def after_save
|
def after_save
|
||||||
|
update_redis_proxy_record if @redis_proxy_change
|
||||||
save_tags
|
save_tags
|
||||||
super
|
super
|
||||||
end
|
end
|
||||||
|
@ -885,7 +887,42 @@ class Site < Sequel::Model
|
||||||
# super
|
# super
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
def ssl_installed?
|
||||||
|
!domain.blank? && !ssl_key.blank? && !ssl_cert.blank?
|
||||||
|
end
|
||||||
|
|
||||||
|
def update_redis_proxy_record
|
||||||
|
if ssl_installed?
|
||||||
|
$redis_proxy.mapped_hmset("d-#{values[:domain]}",
|
||||||
|
username: username,
|
||||||
|
ssl_cert: ssl_cert,
|
||||||
|
ssl_key: ssl_key
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
$redis_proxy.del "d-#{@old_domain}" if @old_domain
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def delete_redis_proxy_record
|
||||||
|
if !domain.blank?
|
||||||
|
$redis_proxy.del "d-#{domain}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def ssl_key=(val)
|
||||||
|
@redis_proxy_change = true
|
||||||
|
super val
|
||||||
|
end
|
||||||
|
|
||||||
|
def ssl_cert=(val)
|
||||||
|
@redis_proxy_change = true
|
||||||
|
super val
|
||||||
|
end
|
||||||
|
|
||||||
def domain=(domain)
|
def domain=(domain)
|
||||||
|
@old_domain = self.domain unless self.domain.blank?
|
||||||
|
@redis_proxy_change = true
|
||||||
super SimpleIDN.to_ascii(domain)
|
super SimpleIDN.to_ascii(domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1379,17 +1416,6 @@ class Site < Sequel::Model
|
||||||
"#{THUMBNAILS_URL_ROOT}/#{self.class.sharding_dir(values[:username])}/#{values[:username]}/#{path}.#{resolution}.#{ext}"
|
"#{THUMBNAILS_URL_ROOT}/#{self.class.sharding_dir(values[:username])}/#{values[:username]}/#{path}.#{resolution}.#{ext}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def ssl_installed?
|
|
||||||
domain && ssl_key && ssl_cert
|
|
||||||
end
|
|
||||||
|
|
||||||
def store_ssl_in_redis_proxy
|
|
||||||
return false unless ssl_installed?
|
|
||||||
$redis_proxy.hset "ssl-#{values[:domain]}", 'crt', OpenSSL::X509::Certificate.new(ssl_cert).to_der
|
|
||||||
$redis_proxy.hset "ssl-#{values[:domain]}", 'key', OpenSSL::PKey::RSA.new(ssl_key).to_der
|
|
||||||
true
|
|
||||||
end
|
|
||||||
|
|
||||||
def to_rss
|
def to_rss
|
||||||
RSS::Maker.make("atom") do |maker|
|
RSS::Maker.make("atom") do |maker|
|
||||||
maker.channel.title = title
|
maker.channel.title = title
|
||||||
|
|
|
@ -190,7 +190,6 @@ class LetsEncryptWorker
|
||||||
site.cert_updated_at = Time.now
|
site.cert_updated_at = Time.now
|
||||||
site.domain_fail_count = 0
|
site.domain_fail_count = 0
|
||||||
site.save_changes validate: false
|
site.save_changes validate: false
|
||||||
site.store_ssl_in_redis_proxy
|
|
||||||
|
|
||||||
# Refresh the cert periodically, current expire time is 90 days
|
# Refresh the cert periodically, current expire time is 90 days
|
||||||
# We're going for a cron task for this now, so this is commented out.
|
# We're going for a cron task for this now, so this is commented out.
|
||||||
|
|
Loading…
Add table
Reference in a new issue