Fixes 3
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
# www.domain.tld type will be automatically assigned to the domain unless
|
||||
# "none" is transmited as argument. If ip have associated dns name, this
|
||||
# domain will also get the alias domain-tpl.$ipname. An alias with the ip
|
||||
# name is useful during the site testing while dns isn't moved to server yet.
|
||||
# name is useful during the site testing while dns isn't moved to server yaliet.
|
||||
|
||||
#----------------------------------------------------------#
|
||||
# Variables & Functions #
|
||||
@@ -255,6 +255,9 @@ check_result $? "Proxy restart failed" > /dev/null
|
||||
module_state=$($BIN/v-ext-modules state bunkerweb_module json | jq -r '.[0].STATE')
|
||||
if [ "$module_state" = "enabled" ]; then
|
||||
$BIN/v-ext-modules-run bunkerweb_module add "$domain"
|
||||
if [ -n "%$ALIAS" ]; then
|
||||
$BIN/v-ext-modules-run bunkerweb_module alias "$domain" "$ALIAS"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Logging
|
||||
|
||||
@@ -108,6 +108,12 @@ check_result $? "Web restart failed" > /dev/null
|
||||
$BIN/v-restart-proxy "$restart"
|
||||
check_result $? "Proxy restart failed" > /dev/null
|
||||
|
||||
# Execute bunkerweb_module if it's enabled
|
||||
module_state=$($BIN/v-ext-modules state bunkerweb_module json | jq -r '.[0].STATE')
|
||||
if [ "$module_state" = "enabled" ]; then
|
||||
$BIN/v-ext-modules-run bunkerweb_module alias "$domain" "$ALIAS"
|
||||
fi
|
||||
|
||||
$BIN/v-log-action "$user" "Info" "Web" "Added new web domain alias (Alias: $aliases, Domain: $domain)."
|
||||
log_event "$OK" "$ARGUMENTS"
|
||||
|
||||
|
||||
@@ -94,6 +94,42 @@ when :add
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
when :alias
|
||||
|
||||
v_domain = ARGV[1].strip
|
||||
v_alias = ARGV[2].strip
|
||||
v_format = ARGV[3] unless ARGV[3].nil?
|
||||
|
||||
if v_domain.nil? || v_domain == ""
|
||||
hestia_print_error_message_to_cli "domain should not be empty"
|
||||
log_event E_ARGS, $ARGUMENTS
|
||||
exit 1
|
||||
else
|
||||
|
||||
begin
|
||||
api = HestiaBunkerWebApi.new("http://127.0.0.1:8888")
|
||||
existing_services = api.list_services()
|
||||
if existing_services.nil?
|
||||
result_arr = []
|
||||
else
|
||||
if existing_services["services"]
|
||||
if existing_services["services"].any? { |s| s["id"] == v_domain }
|
||||
hestia_print_error_message_to_cli "domain already exists"
|
||||
log_event E_EXISTS, $ARGUMENTS
|
||||
exit 1
|
||||
end
|
||||
result_arr = existing_services["services"]
|
||||
else
|
||||
result_arr = []
|
||||
end
|
||||
end
|
||||
api.set_alias(v_domain, v_alias)
|
||||
rescue BunkerWebApiError => e
|
||||
hestia_print_error_message_to_cli "[ERROR] Ошибка API: #{e.message}"
|
||||
log_event E_INVALID, $ARGUMENTS
|
||||
exit 1
|
||||
end
|
||||
end
|
||||
when :delete
|
||||
|
||||
v_domain = ARGV[1].strip
|
||||
|
||||
@@ -92,6 +92,12 @@ check_result $? "Web restart failed" > /dev/null
|
||||
$BIN/v-restart-proxy "$restart"
|
||||
check_result $? "Proxy restart failed" > /dev/null
|
||||
|
||||
# Execute bunkerweb_module if it's enabled
|
||||
module_state=$($BIN/v-ext-modules state bunkerweb_module json | jq -r '.[0].STATE')
|
||||
if [ "$module_state" = "enabled" ]; then
|
||||
$BIN/v-ext-modules-run bunkerweb_module alias "$domain" "$ALIAS"
|
||||
fi
|
||||
|
||||
# Logging
|
||||
$BIN/v-log-action "$user" "Info" "Web" "Deleted web domain alias (Alias: $dom_alias, Domain: $domain)."
|
||||
log_event "$OK" "$ARGUMENTS"
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -17,11 +17,11 @@ exec(
|
||||
$output,
|
||||
$return_var,
|
||||
);
|
||||
$check_passenger_enabled = json_decode(implode("", $output), true);
|
||||
$check_bunkerweb_enabled = json_decode(implode("", $output), true);
|
||||
if (
|
||||
$return_var != 0 ||
|
||||
empty($check_passenger_enabled) ||
|
||||
$check_passenger_enabled[0]["STATE"] != "enabled"
|
||||
empty($check_bunkerweb_enabled) ||
|
||||
$check_bunkerweb_enabled[0]["STATE"] != "enabled"
|
||||
) {
|
||||
header("Location: /list/extmodules/");
|
||||
exit();
|
||||
|
||||
64
web/extm/update_module/edit/index.php
Normal file
64
web/extm/update_module/edit/index.php
Normal file
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
use function Hestiacp\quoteshellarg\quoteshellarg;
|
||||
|
||||
$TAB = "EXTMODULES";
|
||||
|
||||
// Main include
|
||||
include $_SERVER["DOCUMENT_ROOT"] . "/inc/main.php";
|
||||
|
||||
// Check user
|
||||
if ($_SESSION["userContext"] != "admin") {
|
||||
header("Location: /list/user");
|
||||
exit();
|
||||
}
|
||||
|
||||
exec(
|
||||
HESTIA_CMD . "v-ext-modules state update_module json",
|
||||
$output,
|
||||
$return_var,
|
||||
);
|
||||
$check_update_enabled = json_decode(implode("", $output), true);
|
||||
if (
|
||||
$return_var != 0 ||
|
||||
empty($check_update_enabled) ||
|
||||
$check_update_enabled[0]["STATE"] != "enabled"
|
||||
) {
|
||||
header("Location: /list/extmodules/");
|
||||
exit();
|
||||
}
|
||||
unset($output);
|
||||
|
||||
$error_message = "";
|
||||
|
||||
if (isset($_GET["action"]) && $_GET["action"] === "update") {
|
||||
exec(
|
||||
HESTIA_CMD . "v-ext-modules-run update_module synctemplates",
|
||||
$output,
|
||||
$return_var,
|
||||
);
|
||||
if ($return_var != 0) {
|
||||
$error_message = $output;
|
||||
}
|
||||
unset($output);
|
||||
}
|
||||
|
||||
// Data
|
||||
exec(
|
||||
HESTIA_CMD . "v-ext-modules-run update_module listsynctemplates json",
|
||||
$output,
|
||||
$return_var,
|
||||
);
|
||||
$synctemplates_list = [];
|
||||
if ($return_var == 0) {
|
||||
$synctemplates_list = json_decode(implode("", $output), true);
|
||||
} else {
|
||||
$error_message = implode("<br/>\n", $output);
|
||||
}
|
||||
|
||||
unset($output);
|
||||
|
||||
// Render page
|
||||
render_page($user, $TAB, "extmodules/extmodules_update_module");
|
||||
|
||||
// Back uri
|
||||
$_SESSION["back"] = $_SERVER["REQUEST_URI"];
|
||||
63
web/templates/pages/extmodules/extmodules_update_module.php
Normal file
63
web/templates/pages/extmodules/extmodules_update_module.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<!-- Begin toolbar -->
|
||||
<div class="toolbar">
|
||||
<div class="toolbar-inner">
|
||||
<div class="toolbar-buttons">
|
||||
<a class="button button-secondary button-back js-button-back" href="/list/extmodules/">
|
||||
<i class="fas fa-arrow-left icon-blue"></i><?= _("Back") ?>
|
||||
</a>
|
||||
<a class="button button-secondary button-back js-button-back" href="/extm/update_module/edit/?action=update">
|
||||
<i class="fas fa-refresh icon-green"></i><?= _("Update files") ?>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End toolbar -->
|
||||
|
||||
<div class="container">
|
||||
|
||||
<?php if (!empty($error_message)) { ?>
|
||||
<div class="u-text-center inline-alert inline-alert-danger u-mb20" role="alert">
|
||||
<i class="fas fa-circle-exclamation"></i>
|
||||
<p><?= $error_message ?></p>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<h1 class="u-text-center u-mt20 u-pr30 u-mb20 u-pl30">
|
||||
<?= _("List of web templates need to update") ?>
|
||||
</h1>
|
||||
|
||||
<div class="units-table js-units-container">
|
||||
<div class="units-table-header">
|
||||
<div class="units-table-cell u-text-center"><?= _("File name") ?></div>
|
||||
<div class="units-table-cell u-text-center"><?= _("Old file size") ?></div>
|
||||
<div class="units-table-cell u-text-center"><?= _("New file size") ?></div>
|
||||
</div>
|
||||
|
||||
<?php foreach ($synctemplates_list as $key => $value) { ?>
|
||||
<div class="units-table-row js-unit">
|
||||
<div class="units-table-cell u-text-center">
|
||||
<span class="u-hide-desktop"><?= _("File name") ?>:</span>
|
||||
<?php echo $synctemplates_list[$key]["FILE_NAME"]; ?>
|
||||
</div>
|
||||
<div class="units-table-cell u-text-center">
|
||||
<span class="u-hide-desktop"><?= _("Old file size") ?>:</span>
|
||||
<?php echo $synctemplates_list[$key]["OLD_SIZE"]; ?>
|
||||
</div>
|
||||
<div class="units-table-cell u-text-center">
|
||||
<span class="u-hide-desktop"><?= _("New file size") ?>:</span>
|
||||
<?php echo $synctemplates_list[$key]["NEW_SIZE"]; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<footer class="app-footer">
|
||||
<div class="container app-footer-inner">
|
||||
<p>
|
||||
<?= _("Update templates list") ?>.
|
||||
</p>
|
||||
</div>
|
||||
</footer>
|
||||
Reference in New Issue
Block a user