Fix bug.
This commit is contained in:
parent
3234c94ea6
commit
7a275f7ed6
|
@ -8,12 +8,12 @@ class Admin::PlowController < ApplicationController
|
||||||
skip_before_action :verify_authenticity_token
|
skip_before_action :verify_authenticity_token
|
||||||
|
|
||||||
def index
|
def index
|
||||||
reverse_proxy "unix://#{Rails.root}/tmp/plow.sock", path: '/' do |config|
|
reverse_proxy "unix://#{SocketFile}", path: '/' do |config|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def show
|
def show
|
||||||
path = request.env['ORIGINAL_FULLPATH']#.gsub("/admin/plow", "")
|
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
|
||||||
end
|
end
|
||||||
def setting
|
def setting
|
||||||
|
@ -25,7 +25,7 @@ class Admin::PlowController < ApplicationController
|
||||||
def save_setting
|
def save_setting
|
||||||
@setting.update_attributes(params[:plow_setting].permit!)
|
@setting.update_attributes(params[:plow_setting].permit!)
|
||||||
if File.exist?(SocketFile)
|
if File.exist?(SocketFile)
|
||||||
if @plow_pid
|
if @plow_pid != 0
|
||||||
Process.kill(:INT, @plow_pid)
|
Process.kill(:INT, @plow_pid)
|
||||||
end
|
end
|
||||||
`rm #{SocketFile}`
|
`rm #{SocketFile}`
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
class SiteCert
|
class SiteCert
|
||||||
|
require 'fileutils'
|
||||||
include Mongoid::Document
|
include Mongoid::Document
|
||||||
include Mongoid::Timestamps
|
include Mongoid::Timestamps
|
||||||
mount_uploader :cert_file, AssetUploader #Public key
|
mount_uploader :cert_file, AssetUploader #Public key
|
||||||
|
@ -35,13 +36,12 @@ class SiteCert
|
||||||
org_cert_file_name = self.cert_file.file.file.to_s
|
org_cert_file_name = self.cert_file.file.file.to_s
|
||||||
cert_file_name = org_cert_file_name.sub(/.cer$/, '.crt')
|
cert_file_name = org_cert_file_name.sub(/.cer$/, '.crt')
|
||||||
if org_cert_file_name != cert_file_name
|
if org_cert_file_name != cert_file_name
|
||||||
if File.open(org_cert_file_name, 'r').read().match(/\A\s*---/)
|
if File.read(org_cert_file_name).match(/\A\s*---/)
|
||||||
new_sf = CarrierWave::SanitizedFile.new(self.cert_file.file.move_to(cert_file_name))
|
FileUtils.cp(org_cert_file_name, cert_file_name)
|
||||||
else
|
else
|
||||||
`openssl x509 --inform DER -in #{org_cert_file_name} --out #{cert_file_name}`
|
`openssl x509 --inform DER -in #{org_cert_file_name} --out #{cert_file_name}`
|
||||||
new_sf = CarrierWave::SanitizedFile.new(cert_file_name)
|
|
||||||
end
|
end
|
||||||
self.cert_file.cache!(new_sf)
|
self.cert_file.retrieve_from_store!(File.basename(cert_file_name))
|
||||||
end
|
end
|
||||||
cert_file_md5 = `openssl x509 -noout -modulus -in #{cert_file_name} | openssl md5`
|
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`
|
private_key_md5 = `openssl rsa -noout -modulus -in #{self.private_key.file.file} | openssl md5`
|
||||||
|
|
|
@ -58,16 +58,16 @@ namespace :create_site do
|
||||||
site_cert = SiteCert.new if site_cert.nil?
|
site_cert = SiteCert.new if site_cert.nil?
|
||||||
end
|
end
|
||||||
if true #site_cert.source_paths.count == 0
|
if true #site_cert.source_paths.count == 0
|
||||||
site_cert["cert_file"] = File.basename(crt_file_path)
|
cert_file_store_path = "public/#{site_cert.cert_file.store_dir}/#{File.basename(crt_file_path)}"
|
||||||
cert_file_store_path = site_cert.cert_file.file.file
|
|
||||||
crt_file_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{crt_file_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
crt_file_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{crt_file_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
||||||
FileUtils.mkdir_p(File.dirname(cert_file_store_path)) unless Dir.exist?(File.dirname(cert_file_store_path))
|
FileUtils.mkdir_p(File.dirname(cert_file_store_path)) unless Dir.exist?(File.dirname(cert_file_store_path))
|
||||||
File.open(site_cert.cert_file.file.file,'w+'){|f| f.write(crt_file_content)}
|
File.open(cert_file_store_path,'w+'){|f| f.write(crt_file_content)}
|
||||||
site_cert["private_key"] = File.basename(private_key_path)
|
site_cert.cert_file.retrieve_from_store!(File.basename(cert_file_store_path))
|
||||||
private_key_store_path = site_cert.private_key.file.file
|
private_key_store_path = "public/#{site_cert.cert_file.store_dir}/#{File.basename(private_key_path)}"
|
||||||
private_key_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{private_key_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
private_key_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{private_key_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
||||||
FileUtils.mkdir_p(File.dirname(private_key_store_path)) unless Dir.exist?(File.dirname(private_key_path))
|
FileUtils.mkdir_p(File.dirname(private_key_store_path)) unless Dir.exist?(File.dirname(private_key_path))
|
||||||
File.open(site_cert.private_key.file.file,'w+'){|f| f.write(private_key_content)}
|
File.open(private_key_store_path,'w+'){|f| f.write(private_key_content)}
|
||||||
|
site_cert.private_key.retrieve_from_store!(File.basename(private_key_path))
|
||||||
site_cert.source_paths = [crt_file_path,private_key_path]
|
site_cert.source_paths = [crt_file_path,private_key_path]
|
||||||
site_cert.is_certbot = private_key_path.include?("letsencrypt")
|
site_cert.is_certbot = private_key_path.include?("letsencrypt")
|
||||||
site_cert.save
|
site_cert.save
|
||||||
|
|
|
@ -143,16 +143,16 @@ namespace :create_site do
|
||||||
site_cert = SiteCert.new if site_cert.nil?
|
site_cert = SiteCert.new if site_cert.nil?
|
||||||
end
|
end
|
||||||
if true #site_cert.source_paths.count == 0
|
if true #site_cert.source_paths.count == 0
|
||||||
site_cert["cert_file"] = File.basename(crt_file_path)
|
cert_file_store_path = "public/#{site_cert.cert_file.store_dir}/#{File.basename(crt_file_path)}"
|
||||||
cert_file_store_path = site_cert.cert_file.file.file
|
|
||||||
crt_file_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{crt_file_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
crt_file_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{crt_file_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
||||||
FileUtils.mkdir_p(File.dirname(cert_file_store_path)) unless Dir.exist?(File.dirname(cert_file_store_path))
|
FileUtils.mkdir_p(File.dirname(cert_file_store_path)) unless Dir.exist?(File.dirname(cert_file_store_path))
|
||||||
File.open(cert_file_store_path,'w+'){|f| f.write(crt_file_content)}
|
File.open(cert_file_store_path,'w+'){|f| f.write(crt_file_content)}
|
||||||
site_cert["private_key"] = File.basename(private_key_path)
|
site_cert.cert_file.retrieve_from_store!(File.basename(cert_file_store_path))
|
||||||
private_key_store_path = site_cert.private_key.file.file
|
private_key_store_path = "public/#{site_cert.cert_file.store_dir}/#{File.basename(private_key_path)}"
|
||||||
private_key_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{private_key_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
private_key_content = exec_ssh_command_by_sudo_and_see_output(ssh,"cat #{private_key_path}",false).select{|s| s.present?}.join("\n").strip.split(/(\r\n|\n)/).select{|s| s.present?}.join("\n")
|
||||||
FileUtils.mkdir_p(File.dirname(private_key_store_path)) unless Dir.exist?(File.dirname(private_key_store_path))
|
FileUtils.mkdir_p(File.dirname(private_key_store_path)) unless Dir.exist?(File.dirname(private_key_store_path))
|
||||||
File.open(private_key_store_path,'w+'){|f| f.write(private_key_content)}
|
File.open(private_key_store_path,'w+'){|f| f.write(private_key_content)}
|
||||||
|
site_cert.private_key.retrieve_from_store!(File.basename(private_key_path))
|
||||||
site_cert.source_paths = [crt_file_path,private_key_path]
|
site_cert.source_paths = [crt_file_path,private_key_path]
|
||||||
site_cert.is_certbot = private_key_path.include?("letsencrypt")
|
site_cert.is_certbot = private_key_path.include?("letsencrypt")
|
||||||
site_cert.save
|
site_cert.save
|
||||||
|
|
Loading…
Reference in New Issue