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 @@ +