Fixes 3
This commit is contained in:
@@ -301,6 +301,71 @@ class HestiaBunkerWebApi
|
||||
return response[:body] || {}
|
||||
end
|
||||
|
||||
|
||||
def set_alias(service_name, list_aliases)
|
||||
@extra_info = ""
|
||||
|
||||
# First get current service configuration to preserve existing settings
|
||||
get_service_response = api_call("GET", "/services/#{service_name}", {})
|
||||
|
||||
if get_service_response[:status] != 200
|
||||
raise BunkerWebApiError.new("Service '#{service_name}' not found")
|
||||
end
|
||||
|
||||
# Extract current variables from the service configuration
|
||||
current_vars = get_service_response[:body]["variables"] || {}
|
||||
|
||||
# Clean the list_aliases string according to the rules
|
||||
cleaned_aliases = list_aliases.to_s
|
||||
|
||||
# Replace commas (with or without space) with a single space
|
||||
cleaned_aliases.gsub!(/,\s?/, ' ')
|
||||
|
||||
# Replace multiple spaces with a single space
|
||||
cleaned_aliases.gsub!(/\s{2,}/, ' ')
|
||||
|
||||
# Strip leading/trailing whitespace
|
||||
cleaned_aliases.strip!
|
||||
|
||||
# Ensure the main service name appears first in the alias list
|
||||
aliases_array = cleaned_aliases.split(' ')
|
||||
unless aliases_array.include?(service_name)
|
||||
# If service_name not present, add it at the front
|
||||
aliases_array.unshift(service_name)
|
||||
else
|
||||
# If present but not first, reorder to make it first
|
||||
aliases_array.delete(service_name)
|
||||
aliases_array.unshift(service_name)
|
||||
end
|
||||
# Rebuild cleaned string
|
||||
cleaned_aliases = aliases_array.join(' ')
|
||||
|
||||
# Update alias settings
|
||||
updated_vars = {
|
||||
"SERVER_NAME" => cleaned_aliases
|
||||
}
|
||||
|
||||
# Merge with existing variables (keep non-SSL settings)
|
||||
final_vars = current_vars.merge(updated_vars)
|
||||
|
||||
service_body = {
|
||||
server_name: nil, # Not changing name
|
||||
is_draft: false, # Keep as online
|
||||
variables: final_vars
|
||||
}
|
||||
|
||||
response = api_call("PATCH", "/services/#{service_name}", {}, JSON.generate(service_body))
|
||||
|
||||
if response[:status] == 200
|
||||
puts "[INFO] SSL configuration updated for service '#{service_name}'"
|
||||
else
|
||||
raise BunkerWebApiError.new("Failed to update SSL configuration: status=#{response[:status]}, body=#{response[:raw_body]}")
|
||||
end
|
||||
|
||||
return response[:body] || {}
|
||||
end
|
||||
|
||||
|
||||
def delete_service_ssl(service_name)
|
||||
|
||||
@extra_info = ""
|
||||
|
||||
@@ -189,6 +189,22 @@ class BunkerwebWorker < Kernel::ModuleCoreWorker
|
||||
puts output
|
||||
ACTION_OK
|
||||
end
|
||||
when "alias"
|
||||
m_domain = args[1].strip unless args[1].nil?
|
||||
m_alias = args[2].strip unless args[1].nil?
|
||||
if m_domain.nil?
|
||||
log_return("Domain should be specified. #{args}")
|
||||
else
|
||||
|
||||
log("add alias to domain to bunkerweb protection")
|
||||
output = `/usr/local/hestia/bin/v-bunkerweb-module alias #{m_domain} "#{m_alias}" shell`
|
||||
exit_status = $?.exitstatus
|
||||
if exit_status != 0
|
||||
log_return("Command failed with status #{exit_status}")
|
||||
else
|
||||
ACTION_OK
|
||||
end
|
||||
end
|
||||
when "help"
|
||||
puts "#{$0} bunkerweb_module COMMAND [OPTIONS] [json|csv|plain]"
|
||||
puts "COMMANDS:"
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
require 'pathname'
|
||||
require 'fileutils'
|
||||
require 'digest'
|
||||
|
||||
class UpdateWorker < Kernel::ModuleCoreWorker
|
||||
MODULE_ID = "update_module"
|
||||
@@ -17,7 +18,6 @@ class UpdateWorker < Kernel::ModuleCoreWorker
|
||||
end
|
||||
|
||||
def file_changed?(new_file, old_file)
|
||||
require 'digest/sha256'
|
||||
return true unless File.exist?(old_file)
|
||||
new_hash = Digest::SHA256.file(new_file).hexdigest
|
||||
old_hash = Digest::SHA256.file(old_file).hexdigest
|
||||
@@ -80,6 +80,9 @@ class UpdateWorker < Kernel::ModuleCoreWorker
|
||||
result = []
|
||||
result = list.map do |new_dir, new_file, old_file|
|
||||
file_name = Pathname.new(new_file).relative_path_from(Pathname.new(new_dir)).to_s
|
||||
dir_name = File.basename(new_dir)
|
||||
relative_path = Pathname.new(new_file).relative_path_from(Pathname.new(new_dir)).to_s
|
||||
file_name = File.join(dir_name, relative_path)
|
||||
{
|
||||
"FILE_NAME" => file_name,
|
||||
"NEW_SIZE" => File.size(new_file),
|
||||
|
||||
Reference in New Issue
Block a user