From 69488086da5da1913ae67a8689410b1c03bef049 Mon Sep 17 00:00:00 2001 From: stef Date: Tue, 23 Apr 2024 01:11:19 +0200 Subject: [PATCH] Configuration Debian ok --- .../app/controllers/engine_controller.rb | 24 ++++++-- .../app/controllers/hosts_controller.rb | 7 ++- .../app/controllers/sites_controller.rb | 2 +- src/autogen/app/models/host.rb | 6 +- src/autogen/app/models/site.rb | 1 + src/autogen/app/views/hosts/_form.html.erb | 60 +++++++++++++++++-- src/autogen/app/views/sites/_form.html.erb | 7 +++ src/autogen/config/routes.rb | 1 + 8 files changed, 95 insertions(+), 13 deletions(-) diff --git a/src/autogen/app/controllers/engine_controller.rb b/src/autogen/app/controllers/engine_controller.rb index 1b4639f..42f3a54 100644 --- a/src/autogen/app/controllers/engine_controller.rb +++ b/src/autogen/app/controllers/engine_controller.rb @@ -12,7 +12,7 @@ class EngineController < ApplicationController log=Log.new({source: "#{sourceip}", crit: "info",message: "#{@host.uuid} Request boot script"}) log.save() @host.mac = params[:mac] - @host.installip = params[:installip] + @host.install_ip = params[:install_ip] boot_script = @host.installtemplate.boot.content template = @host.installtemplate @site = @host.site @@ -34,6 +34,7 @@ class EngineController < ApplicationController script = @host.installtemplate.install.content template = @host.installtemplate @site = @host.site + @template = @host.installtemplate host = @host @host.update({status: "System Install"}) result = render inline: script, layout: false, content_type: 'text/plain' @@ -65,13 +66,25 @@ class EngineController < ApplicationController sourceip=request.headers['REMOTE_ADDR'] log=Log.new({source: "#{sourceip}", crit: "info",message: "#{@host.uuid} Install Finished."}) log.save() - if @host.update({status: "Installation Finish", installed: true, toinstall: false, interface: params[:interface],ip: params[:installip]}) + if @host.update({status: "Installation Finish", installed: true, toinstall: false, interface: params[:interface],ip: params[:install_ip]}) render plain: "ok" else render json: @host.errors end end + def update_info + @host = Host.find_by(uuid: params[:uuid]) + sourceip=request.headers['REMOTE_ADDR'] + log=Log.new({source: "#{sourceip}", crit: "info",message: "#{@host.uuid} update info."}) + log.save() + if @host.update({interface: params[:interface],ip: params[:ip], hostname: params[:hostname], access_ip: "#{sourceip}"}) + render plain: "ok" + else + render json: @host.errors + end + end + def generate_metadata @host = Host.find_by(uuid: params[:uuid]) script = Script.find_by({name: "metadata",stage: "config"}) @@ -102,13 +115,16 @@ class EngineController < ApplicationController @template = Installtemplate.find_by(name:"default") @site = Site.find_by(name:"default") @account = Account.find_by(name:"default") - @host = Host.new(hostname: "New host detected",uuid: params["uuid"], installip: params["installip"], installtemplate: @template,site: @site, mac: params["mac"], status: "discover", discover: true,installed: false, toinstall: false,rootaccount: @account, mainaccount: @account) + # Generate random lusk key + random_string=SecureRandom.urlsafe_base64(24) + # Create new host + @host = Host.new(hostname: "New host detected",uuid: params["uuid"], install_ip: params["ip"], installtemplate: @template,site: @site, mac: params["mac"], status: "discover", discover: true,installed: false, toinstall: false,rootaccount: @account, mainaccount: @account, product: params["product"], serial: params["serial"], lusk_key: random_string) @host.save! end end # Only allow a list of trusted parameters through. def host_params - params.require(:host).permit(:uuid, :hostname, :ip, :status, :mac, :discover, :installed, :interface , :installtemplate, :site , :installtemplate_id, :site_id, :rootaccount_id, :mainaccount_id,:toinstall, :installip, :filename) + params.require(:host).permit(:uuid, :hostname, :ip, :status, :mac, :discover, :installed, :interface , :installtemplate, :site , :installtemplate_id, :site_id, :rootaccount_id, :mainaccount_id,:toinstall, :install_ip, :filename, :access_ip, :product, :serial) end end diff --git a/src/autogen/app/controllers/hosts_controller.rb b/src/autogen/app/controllers/hosts_controller.rb index 01652aa..b58dd0c 100644 --- a/src/autogen/app/controllers/hosts_controller.rb +++ b/src/autogen/app/controllers/hosts_controller.rb @@ -66,7 +66,7 @@ class HostsController < ApplicationController if @host @host.mac = params[:mac] - @host.installip = params[:installip] + @host.install_ip = params[:install_ip] boot_script = @host.installtemplate.boot.content template = @host.installtemplate @site = @host.site @@ -127,13 +127,14 @@ class HostsController < ApplicationController @template = Installtemplate.find_by(name:"default") @site = Site.find_by(name:"default") @account = Account.find_by(name:"default") - @host = Host.new(hostname: "New host detected",uuid: params["uuid"], installip: params["installip"], installtemplate: @template,site: @site, mac: params["mac"], status: "discover", discover: true,installed: false, toinstall: false,rootuser: @account, mainuser: @account) + + @host = Host.new(hostname: "New host detected",uuid: params["uuid"], install_ip: params["install_ip"], installtemplate: @template,site: @site, mac: params["mac"], status: "discover", discover: true,installed: false, toinstall: false,rootuser: @account, mainuser: @account) @host.save! end end # Only allow a list of trusted parameters through. def host_params - params.require(:host).permit(:uuid, :hostname, :ip, :status, :mac, :discover, :installed, :interface , :installtemplate, :site , :installtemplate_id, :site_id, :rootaccount_id, :mainaccount_id,:toinstall, :installip,:lusk_key,:lusk_device, :lusk_encrypt) + params.require(:host).permit(:uuid, :hostname, :ip, :install_ip,:access_ip,:status, :mac, :discover, :installed, :interface , :installtemplate, :site , :installtemplate_id, :site_id, :rootaccount_id, :mainaccount_id,:toinstall, :lusk_key,:lusk_device, :lusk_encrypt, :host_device) end end diff --git a/src/autogen/app/controllers/sites_controller.rb b/src/autogen/app/controllers/sites_controller.rb index 1314025..923bddb 100644 --- a/src/autogen/app/controllers/sites_controller.rb +++ b/src/autogen/app/controllers/sites_controller.rb @@ -66,7 +66,7 @@ class SitesController < ApplicationController # Only allow a list of trusted parameters through. def site_params - params.require(:site).permit(:name, :domain, :gateway, :nameserver, :network, :netmask, :server_ip, :server_port, :fileserver_ip, :fileserver_port,:fileserver_basepath, :timezone, :apiurl, :cfenginehub, :nfsserver_path) + params.require(:site).permit(:name, :domain, :gateway, :nameserver, :network, :netmask, :server_ip, :server_port, :fileserver_ip, :fileserver_port,:fileserver_basepath, :timezone, :apiurl, :cfenginehub, :nfsserver_path, :country) end diff --git a/src/autogen/app/models/host.rb b/src/autogen/app/models/host.rb index 0ecbfb4..872198b 100644 --- a/src/autogen/app/models/host.rb +++ b/src/autogen/app/models/host.rb @@ -3,14 +3,18 @@ class Host include Mongoid::Timestamps field :uuid, type: String field :hostname, type: String + field :product, type: String + field :serial, type: String field :ip, type: String - field :installip, type: String + field :access_ip, type: String + field :install_ip, type: String field :status, type: String field :mac, type: String field :discover, type: Mongoid::Boolean field :installed, type: Mongoid::Boolean field :toinstall, type: Mongoid::Boolean field :interface, type: String + field :host_device, type: String , default: '' field :lastbootgenerated, type: String , default: '' field :lastinstallgenerated, type: String , default: '' field :lastpostinstallgenerated, type: String, default: '' diff --git a/src/autogen/app/models/site.rb b/src/autogen/app/models/site.rb index cf4ebe0..0f35ca5 100644 --- a/src/autogen/app/models/site.rb +++ b/src/autogen/app/models/site.rb @@ -13,6 +13,7 @@ class Site field :fileserver_port, type: String field :fileserver_basepath, type: String field :nfsserver_path, type: String + field :country, type: String field :timezone, type: String field :apiurl, type: String field :description, type: String diff --git a/src/autogen/app/views/hosts/_form.html.erb b/src/autogen/app/views/hosts/_form.html.erb index aa288e6..44c3a29 100644 --- a/src/autogen/app/views/hosts/_form.html.erb +++ b/src/autogen/app/views/hosts/_form.html.erb @@ -27,6 +27,32 @@ +
+
+ +
+
+
+
+ <%= form.text_field :product , { class: "input" , disabled: true } %> +
+
+
+
+ +
+
+ +
+
+
+
+ <%= form.text_field :serial , { class: "input" , disabled: true } %> +
+
+
+
+
@@ -40,6 +66,7 @@
+
@@ -47,7 +74,21 @@
- <%= form.text_field :ip , { class: "input"} %> + <%= form.text_field :ip , { class: "input"} %> +
+
+
+
+ + +
+
+ +
+
+
+
+ <%= form.text_field :access_ip , { class: "input" , disabled: true } %>
@@ -55,12 +96,12 @@
- +
- <%= form.text_field :installip , { class: "input"} %> + <%= form.text_field :install_ip , { class: "input"} %>
@@ -91,7 +132,18 @@
- +
+
+ +
+
+
+
+ <%= form.text_field :host_device , { class: "input"} %> +
+
+
+
<%= form.label :lusk_encrypt, class: "checkbox" %> diff --git a/src/autogen/app/views/sites/_form.html.erb b/src/autogen/app/views/sites/_form.html.erb index af35c50..2980ec2 100644 --- a/src/autogen/app/views/sites/_form.html.erb +++ b/src/autogen/app/views/sites/_form.html.erb @@ -106,6 +106,13 @@ <%= link_to "Goto cfengine hub", "http://#{@site.cfenginehub}", class: "button is-info", :target => "_blank" %> <% end -%> +
+ <%= form.label :country, class: "label" %> +
+ <%= form.text_field :country , { class: "input"} %> +
+
+
<%= form.label :timezone, class: "label" %>
diff --git a/src/autogen/config/routes.rb b/src/autogen/config/routes.rb index d60e951..12cc7d3 100644 --- a/src/autogen/config/routes.rb +++ b/src/autogen/config/routes.rb @@ -30,6 +30,7 @@ Rails.application.routes.draw do get '/api/host/postinstall', to: "engine#generate_postinstall" get '/api/host/installed', to: "engine#generate_installed", defaults: { format: 'text' } get '/api/host/getfile', to: "engine#generate_file", defaults: { format: 'text' } + get '/api/host/update_info', to: "engine#update_info", defaults: { format: 'text' } get '/engine/global', to: "engine#generateglobal", defaults: { format: 'text' } get '/api/host/cloudinit/:uuid/user-data', to: "engine#generate_install", defaults: { format: 'text' } get '/api/host/cloudinit/:uuid/meta-data', to: "engine#generate_metadata", defaults: { format: 'text' }