diff --git a/README.MD b/README.MD index bab557c..1bbd4e4 100644 --- a/README.MD +++ b/README.MD @@ -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.' +} ``` \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 12d1f29..ffd64cd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 diff --git a/src/autogen/app/controllers/accounts_controller.rb b/src/autogen/app/controllers/accounts_controller.rb index e58bbfc..265eaa2 100644 --- a/src/autogen/app/controllers/accounts_controller.rb +++ b/src/autogen/app/controllers/accounts_controller.rb @@ -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) diff --git a/src/autogen/app/controllers/engine_controller.rb b/src/autogen/app/controllers/engine_controller.rb index 061741a..1b4639f 100644 --- a/src/autogen/app/controllers/engine_controller.rb +++ b/src/autogen/app/controllers/engine_controller.rb @@ -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 diff --git a/src/autogen/app/controllers/hosts_controller.rb b/src/autogen/app/controllers/hosts_controller.rb index 98cd73d..01652aa 100644 --- a/src/autogen/app/controllers/hosts_controller.rb +++ b/src/autogen/app/controllers/hosts_controller.rb @@ -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 diff --git a/src/autogen/app/controllers/sites_controller.rb b/src/autogen/app/controllers/sites_controller.rb index edfafb8..1314025 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) + 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 diff --git a/src/autogen/app/models/host.rb b/src/autogen/app/models/host.rb index 4c7fab6..0ecbfb4 100644 --- a/src/autogen/app/models/host.rb +++ b/src/autogen/app/models/host.rb @@ -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 diff --git a/src/autogen/app/models/site.rb b/src/autogen/app/models/site.rb index ad0bc48..cf4ebe0 100644 --- a/src/autogen/app/models/site.rb +++ b/src/autogen/app/models/site.rb @@ -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 diff --git a/src/autogen/app/views/hosts/_form.html.erb b/src/autogen/app/views/hosts/_form.html.erb index 5ecddd7..aa288e6 100644 --- a/src/autogen/app/views/hosts/_form.html.erb +++ b/src/autogen/app/views/hosts/_form.html.erb @@ -92,30 +92,21 @@ -