boot baremetal ok

main
stef 2024-04-21 02:06:03 +02:00
parent 9d9429ea13
commit 8d14553d4c
12 changed files with 76 additions and 49 deletions

View File

@ -280,4 +280,18 @@ root@autogen:/usr/src/autogen# rails generate devise User
insert app/models/user.rb
insert app/models/user.rb
route devise_for :users
```
# test save
```
{
_id: ObjectId('65aab0004d003d00837c11b1'),
login: 'stef',
updated_at: ISODate('2024-02-07T20:21:48.310Z'),
created_at: ISODate('2024-01-19T17:23:12.358Z'),
name: 'me',
sshpubkey: 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC14slyp/JGv9iqLH4D94x+7v4PB/ec0YbLUPexdBip6OJaflbmp3s25WJ+oyO6U78Ee0jZUZt0TapYozyNx9UksP9JhirwKeNJnQSzSX0RKc6kQffoCgWHZmnzuoalEzaE7XyH+K8wP+hKi052ak9yR7XWDp6CG3V1Qpyq80VD1XNUzEL2xkITGQ6KojxrOJ1O0A9ISRu1t85Ul2N0syIylE2Ukvns1/NkArhC2g8N8T5XxPq39AUH78A3I0/kHowIzW9BpPVwim0tJTLSVNnVqq1NPG+gi1XvrXKzO/jb4kT01tnMG9vKcYqdH4g0y01ADEcCgMo1jGAjwq6gPLqT imported-openssh-key',
encpassword: '$6$012345678$7Mu8dw7L8ye6pf8VYKGrTiHThM3LVnVnOkJNVz8DmVaK4YpAij7zbewaQ4/OYkClPHG1us0t7EshEI.dmayWs.'
}
```

View File

@ -1,7 +1,7 @@
services:
autogen:
container_name: autogen
hostname: autogen
zeninstall:
container_name: zeninstall
hostname: zeninstall
build: .
restart: always
labels:
@ -9,7 +9,7 @@ services:
- "traefik.docker.network=traefik"
- "traefik.http.routers.autoinstall.entrypoints=websecure"
- "traefik.http.routers.autoinstall.tls=true"
- "traefik.http.routers.autoinstall.rule=Host(`autoinstall.msi.stef.lan`)"
- "traefik.http.routers.autoinstall.rule=Host(`zenisntall.install.lan`)"
- "traefik.http.services.autoinstall.loadbalancer.server.port=3000"
stdin_open: true
tty: true

View File

@ -21,7 +21,9 @@ class AccountsController < ApplicationController
# POST /accounts or /accounts.json
def create
@account = Account.new(account_params.except(:password))
cmdline = "mkpasswd -m sha-512 -S 012345678 '#{account_params[:password]}'"
crypt = `#{cmdline}`.strip
@account = Account.new(account_params.except(:password).merge(encpassword: crypt))
respond_to do |format|
if @account.save
@ -67,7 +69,7 @@ class AccountsController < ApplicationController
def set_pass
# [IMPORTANT] Salt must be generated for prodution !
cmdline = "mkpasswd -m sha-512 -S 012345678 #{account_params[:password]}"
cmdline = "mkpasswd -m sha-512 -S 012345678 '#{account_params[:password]}'"
@account.encpassword = `#{cmdline}`.strip
account_params.delete(:password)

View File

@ -1,5 +1,5 @@
class EngineController < ApplicationController
before_action :set_host_by_uuid, only: %i[ generate_boot generate_install generate_postinstall generate_installed generate_metadata ]
before_action :set_host_by_uuid, only: %i[ generate_boot generate_install generate_postinstall generate_installed generate_metadata generate_file]
def generateglobal
gv=Utils::Globalvar.new
@ -35,10 +35,12 @@ class EngineController < ApplicationController
template = @host.installtemplate
@site = @host.site
host = @host
@template = @host.installtemplate
@host.update({status: "System Install"})
result = render inline: script, layout: false, content_type: 'text/plain'
@host.update({lastinstallgenerated: result})
else
log=Log.new({source: "#{sourceip}", crit: "info",message: "Request Install script"})
log.save()
end
end
@ -74,8 +76,20 @@ class EngineController < ApplicationController
@host = Host.find_by(uuid: params[:uuid])
script = Script.find_by({name: "metadata",stage: "config"})
result = render inline: script.content, layout: false, content_type: 'text/plain'
end
end
def generate_file
sourceip=request.headers['REMOTE_ADDR']
log=Log.new({source: "#{sourceip}", crit: "info",message: "Request #{params[:filename]}"})
log.save()
if @host
script = Script.find_by({name: params[:filename], stage: "ressource"})
@site = @host.site
@template = @host.installtemplate
host = @host
result = render inline: script.content, layout: false, content_type: 'text/plain'
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_host_by_uuid
@ -94,7 +108,7 @@ class EngineController < ApplicationController
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)
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)
end
end

View File

@ -134,6 +134,6 @@ class HostsController < ApplicationController
# 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,:luskkey)
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)
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)
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)
end

View File

@ -14,8 +14,9 @@ class Host
field :lastbootgenerated, type: String , default: ''
field :lastinstallgenerated, type: String , default: ''
field :lastpostinstallgenerated, type: String, default: ''
field :luskdisk, type: String, default: '/dev/sda3'
field :luskkey, type: String, default: '123456789123456789'
field :lusk_encrypt, type: Mongoid::Boolean, default: false
field :lusk_device, type: String, default: ''
field :lusk_key, type: String, default: 'a changer'
belongs_to :installtemplate , class_name: "Installtemplate", inverse_of: :hostreferences
belongs_to :site , class_name: "Site", inverse_of: :sitereferences
belongs_to :rootaccount , class_name: "Account", inverse_of: :rootref

View File

@ -12,6 +12,7 @@ class Site
field :fileserver_ip, type: String
field :fileserver_port, type: String
field :fileserver_basepath, type: String
field :nfsserver_path, type: String
field :timezone, type: String
field :apiurl, type: String
field :description, type: String

View File

@ -92,30 +92,21 @@
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Lusk Key</label>
<div class="field is-grouped">
<div class="control">
<%= form.label :lusk_encrypt, class: "checkbox" %>
<%= form.check_box :lusk_encrypt %>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :luskkey , { class: "input"} %>
</div>
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Lusk Disk</label>
</div>
<div class="field-body">
<div class="field">
<div class="control">
<%= form.text_field :luskdisk , { class: "input"} %>
</div>
</div>
<div class="control">
<%= form.label :lusk_device, class: "label is-small" %>
<%= form.text_field :lusk_device , { class: "input"} %>
</div>
<div class="control">
<%= form.label :lusk_key, class: "label is-small" %>
<%= form.text_field :lusk_key , { class: "input"} %>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Interface</label>
@ -128,7 +119,7 @@
</div>
</div>
</div>
<div class="field is-horizontal">
<div class="field-label is-small">
<label class="label">Template</label>
@ -169,8 +160,8 @@
<%= form.collection_select :mainaccount_id, Account.all, :id, :name %>
</div>
</div>
<div class="control">
<%= form.label :discover, class: "checkbox" %>
<%= form.check_box :discover %>
@ -185,9 +176,9 @@
</div>
</div>
<div class="control">
<button class="button is-link">Submit</button>
<button class="button is-link">Submit</button>
<%= link_to "Return", "/hosts", class: "button is-success" %>
</div>
<% end %>
<%= button_to " Destroy ", @host, method: :delete, class: "button is-danger" %>

View File

@ -12,7 +12,7 @@
<%= form.text_field :domain , { class: "input"} %>
</div>
</div>
<div class="field">
<label class="label">Gateway</label>
<div class="control">
@ -49,6 +49,13 @@
</div>
</div>
<div class="field">
<%= form.label :nfsserver_path, class: "label" %>
<div class="control">
<%= form.text_field :nfsserver_path , { class: "input"} %>
</div>
</div>
<div class="field is-grouped">
<div class="field">
@ -80,7 +87,7 @@
<%= form.text_field :fileserver_port , { class: "input"} %>
</div>
</div>
<div class="field">
<label class="label">File Server Basepath</label>
<div class="control">
@ -105,13 +112,9 @@
<%= form.text_field :timezone , { class: "input"} %>
</div>
</div>
<div class="control">
<button class="button is-link">Submit In</button>
<button class="button is-link">Submit In</button>
<%= link_to "Return to Site index", "/sites", class: "button is-success" %>
</div>
<% end %>

View File

@ -35,6 +35,6 @@ module Autogen
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")
config.hosts << "autoinstall.msi.stef.lan"
config.hosts << "zeninstall.install.lan"
end
end

View File

@ -29,6 +29,7 @@ Rails.application.routes.draw do
get '/api/host/install', to: "engine#generate_install"
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 '/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' }