This commit is contained in:
邱博亞 2024-05-09 21:12:04 +08:00
parent 7a275f7ed6
commit 783927c59b
2 changed files with 23 additions and 43 deletions

View File

@ -147,12 +147,14 @@ namespace :create_site do
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))
File.open(cert_file_store_path,'w+'){|f| f.write(crt_file_content)}
site_cert["cert_file"] = File.basename(cert_file_store_path)
site_cert.cert_file.retrieve_from_store!(File.basename(cert_file_store_path))
private_key_store_path = "public/#{site_cert.cert_file.store_dir}/#{File.basename(private_key_path)}"
private_key_store_path = "public/#{site_cert.private_key.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")
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)}
site_cert.private_key.retrieve_from_store!(File.basename(private_key_path))
site_cert["private_key"] = File.basename(private_key_store_path)
site_cert.private_key.retrieve_from_store!(File.basename(private_key_store_path))
site_cert.source_paths = [crt_file_path,private_key_path]
site_cert.is_certbot = private_key_path.include?("letsencrypt")
site_cert.save

View File

@ -262,57 +262,35 @@ namespace :exec_commands do
channel.send_data "#{@password}\n"
else
print data_str unless @no_stdout
data_str.gsub!("\r\n", "\n")
rm_idx = data_str.index("\r")
if rm_idx.nil?
@remove_last_line = false
else
@remove_last_line = (outputs.count > 0 && data_str[0...rm_idx].exclude?("\n"))
end
data_str.gsub!(/.*\r/, '')
data_str.gsub!(/\r\n/, "\n")
next if data_str.length == 0
if data_str.include?("\n") || outputs.empty?
output_lines = data_str.split("\n")
first_output = output_lines[0]
if first_output
if @remove_last_line
outputs = outputs[1..-1]
outputs = [] if outputs.nil?
end
if outputs.count != 0
outputs[-1] += first_output
else
outputs << first_output
output_lines = data_str.split("\n", -1)
first_output = output_lines[0]
if first_output
if outputs.count != 0
outputs[-1] += first_output
@remove_last_line = false
outputs[-1] = outputs[-1].sub(/(.+)\r(.+)/) do |s|
@remove_last_line = true
first_output = $2
end
else
outputs << first_output
end
if update_outputs
update_thread_infos_for_exec(first_output,true) if @flag
update_infos_for_exec(first_output,true)
end
@remove_last_line = false
new_arr = output_lines[1..-1]
new_arr = [] if new_arr.nil?
if data_str[-1] == "\n"
new_arr << ""
new_arr = new_arr.map do |output_line|
output_line = output_line.sub(/(.+)\r(.+)/, '\2')
end
outputs += new_arr
if update_outputs
if first_output
update_thread_infos_for_exec(first_output,true) if @flag
update_infos_for_exec(first_output,true)
end
update_thread_infos_for_exec(new_arr,false,true) if @flag
update_infos_for_exec(new_arr,false,true)
end
else
if @remove_last_line
outputs = outputs[1..-1]
outputs = [] if outputs.nil?
end
if outputs.count == 0
outputs.push(data_str)
else
outputs[-1] += (data_str rescue "")
end
if update_outputs
update_thread_infos_for_exec(data_str,true) if @flag
update_infos_for_exec(data_str,true)
end
end
end
end