From 0f93df5dc457e853883e012104931da9d3ce6e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Tue, 7 May 2024 23:46:25 +0800 Subject: [PATCH] Fix bug. --- app/controllers/admin/plow_controller.rb | 6 +++--- app/models/site_cert.rb | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/controllers/admin/plow_controller.rb b/app/controllers/admin/plow_controller.rb index 302c256..1d48622 100644 --- a/app/controllers/admin/plow_controller.rb +++ b/app/controllers/admin/plow_controller.rb @@ -8,12 +8,12 @@ class Admin::PlowController < ApplicationController skip_before_action :verify_authenticity_token def index - reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: '/' do |config| + reverse_proxy "unix://#{SocketFile}", path: '/' do |config| end end def show path = request.env['ORIGINAL_FULLPATH']#.gsub("/admin/plow", "") - reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: path do |config| + reverse_proxy "unix://#{SocketFile}", path: path do |config| end end def setting @@ -25,7 +25,7 @@ class Admin::PlowController < ApplicationController def save_setting @setting.update_attributes(params[:plow_setting].permit!) if File.exist?(SocketFile) - if @plow_pid + if @plow_pid != 0 Process.kill(:INT, @plow_pid) end `rm #{SocketFile}` diff --git a/app/models/site_cert.rb b/app/models/site_cert.rb index f382943..81260b6 100644 --- a/app/models/site_cert.rb +++ b/app/models/site_cert.rb @@ -1,4 +1,5 @@ class SiteCert + require 'fileutils' include Mongoid::Document include Mongoid::Timestamps mount_uploader :cert_file, AssetUploader #Public key @@ -35,13 +36,12 @@ class SiteCert org_cert_file_name = self.cert_file.file.file.to_s cert_file_name = org_cert_file_name.sub(/.cer$/, '.crt') if org_cert_file_name != cert_file_name - if File.open(org_cert_file_name, 'r').read().match(/\A\s*---/) - new_sf = CarrierWave::SanitizedFile.new(self.cert_file.file.move_to(cert_file_name)) + if File.read(org_cert_file_name).match(/\A\s*---/) + FileUtils.cp(org_cert_file_name, cert_file_name) else `openssl x509 --inform DER -in #{org_cert_file_name} --out #{cert_file_name}` - new_sf = CarrierWave::SanitizedFile.new(cert_file_name) end - self.cert_file.cache!(new_sf) + self.cert_file.retrieve_from_store!(File.basename(cert_file_name)) end cert_file_md5 = `openssl x509 -noout -modulus -in #{cert_file_name} | openssl md5` private_key_md5 = `openssl rsa -noout -modulus -in #{self.private_key.file.file} | openssl md5`