Added API for bunkerweb

This commit is contained in:
Alexey Berezhok
2026-04-27 00:47:57 +03:00
parent 4b023ea671
commit 592b954a9f
9 changed files with 1286 additions and 11 deletions

View File

@@ -0,0 +1,124 @@
#!/opt/brepo/ruby33/bin/ruby
class BunkerwebWorker < Kernel::ModuleCoreWorker
MODULE_ID = "bunkerweb_module"
def info
{
ID: 5,
NAME: MODULE_ID,
DESCR: "Bunkerweb enabling",
REQ: "",
CONF: "yes",
}
end
def command(args)
return log_return("Not enough arguments. Needed command") if args.length < 1
log_file = get_log
m_command = args[0].strip
case m_command
when "add"
m_domain = args[1].strip unless args[1].nil?
if m_domain.nil?
log_return("Domain should be specified. #{args}")
else
log("add domain to bunkerweb protection")
output = `/usr/local/hestia/bin/v-bunkerweb-module add #{m_domain} shell`
exit_status = $?.exitstatus
if exit_status != 0
log_return("Command failed with status #{exit_status}")
else
ACTION_OK
end
end
when "delete"
m_domain = args[1].strip unless args[1].nil?
if m_domain.nil?
log_return("Domain should be specified. #{args}")
else
log("add domain to bunkerweb protection")
output = `/usr/local/hestia/bin/v-bunkerweb-module delete #{m_domain} shell`
exit_status = $?.exitstatus
if exit_status != 0
log_return("Command failed with status #{exit_status}")
else
ACTION_OK
end
end
when "addssl"
m_domain = args[1].strip unless args[1].nil?
m_ssl_cert = args[2].strip unless args[2].nil?
m_ssl_key = args[3].strip unless args[3].nil?
if m_domain.nil? || m_ssl_cert.nil? || m_ssl_key.nil? || m_ssl_cert.empty? || m_ssl_key.empty?
log_return("Domain, SSL cert and SSL key must be specified. #{args}")
else
log("add ssl cert to bunkerweb protection")
output = `/usr/local/hestia/bin/v-bunkerweb-module addssl #{m_domain} #{m_ssl_cert} #{m_ssl_key} shell`
exit_status = $?.exitstatus
if exit_status != 0
log_return("Command failed with status #{exit_status}")
else
ACTION_OK
end
end
when "updssl"
m_domain = args[1].strip unless args[1].nil?
m_ssl_cert = args[2].strip unless args[2].nil?
m_ssl_key = args[3].strip unless args[3].nil?
if m_domain.nil? || m_ssl_cert.nil? || m_ssl_key.nil? || m_ssl_cert.empty? || m_ssl_key.empty?
log_return("Domain, SSL cert and SSL key must be specified. #{args}")
else
log("add ssl cert to bunkerweb protection")
output = `/usr/local/hestia/bin/v-bunkerweb-module updssl #{m_domain} #{m_ssl_cert} #{m_ssl_key} shell`
exit_status = $?.exitstatus
if exit_status != 0
log_return("Command failed with status #{exit_status}")
else
ACTION_OK
end
end
when "list"
format = (args[1].nil? ? "shell" : args[1].strip)
log("list of services")
output = `/usr/local/hestia/bin/v-bunkerweb-module list #{format}`
exit_status = $?.exitstatus
if exit_status != 0
log_return("Command failed with status #{exit_status}")
else
puts output
ACTION_OK
end
when "help"
puts "#{$0} bunkerweb_module COMMAND [OPTIONS] [json|csv|plain]"
puts "COMMANDS:"
puts " add - add domain to bunkerweb"
puts " delete - delete domain from bunkerweb"
puts " addssl [path_to_cert] [path_to_key] - add existsing certificate to bunkerweb domain"
puts " updssl [path_to_cert] [path_to_key] - update existsing certificate to bunkerweb domain"
puts " help - help"
ACTION_OK
else
log_return("Unknown command. #{args}")
end
end
implements IPluginInterface
end
module BunkerwebModule
def get_object
Proc.new { BunkerwebWorker.new }
end
module_function :get_object
end
class Kernel::PluginConfiguration
include BunkerwebModule
@@loaded_plugins[BunkerwebWorker::MODULE_ID] = BunkerwebModule.get_object
end

View File

@@ -49,7 +49,7 @@
# Конфигурируем Nginx для Passenger
- name: Create passenger.conf
ansible.builtin.copy:
dest: /etc/nginx/conf.d/passenger.conf
dest: /usr/local/hestia/nginx-system/etc/nginx/conf.d/passenger.conf
content: |
passenger_root /usr/share/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/ruby;
@@ -59,11 +59,11 @@
passenger_env_var PASSENGER_DOWNLOAD_NATIVE_SUPPORT_BINARY 0;
- name: Create passenger_includer.conf
ansible.builtin.copy:
dest: /etc/nginx/conf.d/main/passenger.conf
dest: /usr/local/hestia/nginx-system/etc/nginx/conf.d/main/passenger.conf
content: |
load_module modules/ngx_http_passenger_module.so;
# Перезапускаем Nginx
- name: Restart nginx service
ansible.builtin.service:
name: nginx
name: nginx-system
state: restarted

View File

@@ -25,14 +25,14 @@
# Удаляем конфигурационные файлы Nginx
- name: Remove passenger.conf
ansible.builtin.file:
path: /etc/nginx/conf.d/passenger.conf
path: /usr/local/hestia/nginx-system/etc/nginx/conf.d/passenger.conf
state: absent
- name: Remove passenger_includer.conf
ansible.builtin.file:
path: /etc/nginx/conf.d/main/passenger.conf
path: /usr/local/hestia/nginx-system/etc/nginx/conf.d/main/passenger.conf
state: absent
# Перезапускаем Nginx (необязательно, но полезно)
- name: Restart nginx service
ansible.builtin.service:
name: nginx
name: nginx-system
state: restarted

View File

@@ -1,6 +1,6 @@
#!/opt/brepo/ruby33/bin/ruby
class EmptyWorker < Kernel::ModuleCoreWorker
class PHPWorker < Kernel::ModuleCoreWorker
MODULE_ID = "php_brepo_modules"
def info
@@ -241,16 +241,16 @@ class EmptyWorker < Kernel::ModuleCoreWorker
implements IPluginInterface
end
module EmptyModule
module PHPModule
def get_object
Proc.new { EmptyWorker.new }
Proc.new { PHPWorker.new }
end
module_function :get_object
end
class Kernel::PluginConfiguration
include EmptyModule
include PHPModule
@@loaded_plugins[EmptyWorker::MODULE_ID] = EmptyModule.get_object
@@loaded_plugins[PHPWorker::MODULE_ID] = PHPModule.get_object
end