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") 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["cert_file"] = File.basename(cert_file_store_path)
site_cert.cert_file.retrieve_from_store!(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") 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["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.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

View File

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