Configuration Debian ok

main
stef 2024-04-23 01:11:19 +02:00
parent 8d14553d4c
commit 69488086da
8 changed files with 95 additions and 13 deletions

View File

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

View File

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

View File

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

View File

@ -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: ''

View File

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

View File

@ -27,6 +27,32 @@
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">product</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :product , { class: "input" , disabled: true } %>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">serial</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :serial , { class: "input" , disabled: true } %>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Hostname</label>
@ -40,6 +66,7 @@
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">ip</label>
@ -47,7 +74,21 @@
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :ip , { class: "input"} %>
<%= form.text_field :ip , { class: "input"} %>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Access ip</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :access_ip , { class: "input" , disabled: true } %>
</div>
</div>
</div>
@ -55,12 +96,12 @@
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Installing IP</label>
<label class="label">install_ip</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :installip , { class: "input"} %>
<%= form.text_field :install_ip , { class: "input"} %>
</div>
</div>
</div>
@ -91,7 +132,18 @@
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">host_device</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :host_device , { class: "input"} %>
</div>
</div>
</div>
</div>
<div class="field is-grouped">
<div class="control">
<%= form.label :lusk_encrypt, class: "checkbox" %>

View File

@ -106,6 +106,13 @@
<%= link_to "Goto cfengine hub", "http://#{@site.cfenginehub}", class: "button is-info", :target => "_blank" %>
<% end -%>
<div class="field">
<%= form.label :country, class: "label" %>
<div class="control">
<%= form.text_field :country , { class: "input"} %>
</div>
</div>
<div class="field">
<%= form.label :timezone, class: "label" %>
<div class="control">

View File

@ -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' }