Added update module
This commit is contained in:
@@ -189,11 +189,12 @@ class HestiaBunkerWebApi
|
||||
variables = {
|
||||
"USE_TEMPLATE" => options[:use_template] || "high",
|
||||
"USE_REVERSE_PROXY" => options[:reverse_proxy_host].nil? ? "no" : "yes",
|
||||
"LIMIT_REQ_RATE" => options[:limit_req_rate] || "10r/s",
|
||||
}
|
||||
|
||||
# SSL configuration - only if USE_SSL != "no"
|
||||
ssl_enabled = options[:ssl] && options[:ssl] != "no"
|
||||
variables["USE_SSL"] = ssl_enabled ? "yes" : "no"
|
||||
variables["USE_CUSTOM_SSL"] = ssl_enabled ? "yes" : "no"
|
||||
|
||||
if ssl_enabled
|
||||
unless options[:certificate_path] && options[:key_path]
|
||||
@@ -201,8 +202,8 @@ class HestiaBunkerWebApi
|
||||
end
|
||||
|
||||
# Set certificate paths in variables
|
||||
variables["SSL_CERTIFICATE_FILE_PATH"] = options[:certificate_path]
|
||||
variables["SSL_KEY_FILE_PATH"] = options[:key_path]
|
||||
variables["CUSTOM_SSL_CERT"] = options[:certificate_path]
|
||||
variables["CUSTOM_SSL_KEY"] = options[:key_path]
|
||||
|
||||
variables["LISTEN_HTTPS_PORT"] = (options[:https_port] || "443").to_s
|
||||
variables["USE_REVERSE_PROXY_SSL"] = options[:reverse_proxy_ssl] || "yes"
|
||||
@@ -216,7 +217,7 @@ class HestiaBunkerWebApi
|
||||
# Reverse proxy configuration if specified
|
||||
if options[:reverse_proxy_host]
|
||||
variables["REVERSE_PROXY_HOST"] = options[:reverse_proxy_host]
|
||||
variables["REVERSE_PROXY_URL"] = options[:reverse_proxy_url] || "~ ^/(.*)$"
|
||||
variables["REVERSE_PROXY_URL"] = options[:reverse_proxy_url] || "~ ^(?!/challenge)(.*)$"
|
||||
|
||||
# Real IP settings for reverse proxy
|
||||
unless options[:real_ip_from].nil?
|
||||
@@ -273,9 +274,9 @@ class HestiaBunkerWebApi
|
||||
|
||||
# Update SSL settings
|
||||
updated_vars = {
|
||||
"USE_SSL" => "yes",
|
||||
"SSL_CERTIFICATE_FILE_PATH" => certificate_path,
|
||||
"SSL_KEY_FILE_PATH" => key_path,
|
||||
"USE_CUSTOM_SSL" => "yes",
|
||||
"CUSTOM_SSL_CERT" => certificate_path,
|
||||
"CUSTOM_SSL_KEY" => key_path,
|
||||
"LISTEN_HTTPS_PORT" => (https_port || "443").to_s,
|
||||
"USE_REVERSE_PROXY_SSL" => "yes"
|
||||
}
|
||||
@@ -300,6 +301,47 @@ class HestiaBunkerWebApi
|
||||
return response[:body] || {}
|
||||
end
|
||||
|
||||
def delete_service_ssl(service_name)
|
||||
|
||||
@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"] || {}
|
||||
|
||||
# Update SSL settings
|
||||
updated_vars = {
|
||||
"USE_CUSTOM_SSL" => "no",
|
||||
"CUSTOM_SSL_CERT" => "",
|
||||
"CUSTOM_SSL_KEY" => ""
|
||||
}
|
||||
|
||||
# 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(service_name)
|
||||
# Delete a service by its name.
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user