All pastes #37462 Raw Edit

dandy

public text v1 · immutable
#37462 ·published 2006-01-19 19:14 UTC
rendered paste body
require 'socket'class HostController < ApplicationController  layout "lsd", :except => [:ks]  def index    list    render :action => 'list'  end  def list    @host_pages, @hosts = paginate :hosts, :per_page => 20, :order => "hostname"  end  def show    @host = Host.find(params[:id])  end  def new		@host = Host.new    @arches = Arch.find(:all)    @displays = Display.find(:all)		@tier = [1,2,3]		@runlevel = [3,5]		@xdmcp = ['true', 'false']  end  def create		@host = Host.new    @display = (params[:host][:display_id] != "") ? (Display.find(params[:host][:display_id])) : nil    @host.display = @display    @host.arch = params[:host][:arch]    @host.tier = params[:host][:tier]    @host.xdmcp = params[:host][:xdmcp]    @host.runlevel = params[:host][:runlevel]    @host.nis_domain = params[:host][:nis_domain]    @host.hostname = params[:host][:hostname]    @host.netgroups = params[:host][:netgroups]		@host.comment = params[:host][:comment]		@host.owner = params[:host][:owner]		@host.stash = params[:host][:stash]    if @host.save      flash[:notice] = 'Host was successfully created.'      redirect_to :action => 'list'    else#    flash[:notice] = 'There was an error creating the host'      new      render :action => 'new'    end  end  def edit    @host = Host.find(params[:id])    @arches = Arch.find(:all)    @displays = Display.find(:all)		@tier = [1,2,3]		@runlevel = [3,5]		@xdmcp = ['true', 'false']  end  def update    @host = Host.find(params[:id])    @display = (params[:host][:display_id] != '') ? (Display.find(params[:host][:display_id])) : nil    @host.display = @display    @host.arch = params[:host][:arch]    @host.tier = params[:host][:tier]    @host.xdmcp = params[:host][:xdmcp]    @host.runlevel = params[:host][:runlevel]    @host.nis_domain = params[:host][:nis_domain]    @host.hostname = params[:host][:hostname]    @host.netgroups = params[:host][:netgroups]		@host.comment = params[:host][:comment]		@host.owner = params[:host][:owner]		@host.stash = params[:host][:stash]    if @host.save      flash[:notice] = 'Host was successfully updated.'      redirect_to :action => 'show', :id => @host    else#     flash[:notice] = 'There was an error updating the host'      edit      render :action => 'edit'    end  end  def destroy    Host.find(params[:id]).destroy    redirect_to :action => 'list'  end  def ks		file_time = Time.now.strftime("_%Y-%m-%d_%H:%M.out")    headers['Content-Type'] = 'text/plain'    addr = Socket.gethostbyname(request.remote_ip())		@hostname = Socket.gethostbyaddr(addr[3], addr[2])[0]		if params[:name]			@hostname = params[:name]		end		@save_file = "/disk/trump/ks_output/" + @hostname + file_time    @host = Host.find(:first, :conditions => [ "hostname = ?", @hostname])    @date = Time.now()    if @host.netgroups?      @netgroups = @host.netgroups.split(',')    else      @netgroups = nil    end    @src_server = "chernabog.cat.pdx.edu";    @src_dir = "/disk/linuxstash1/#{@product}/#{@version}/os/#{@host.arch}";    @conf_server = "ks.cat.pdx.edu";    @conf_dir = "/disk/config/htks";#@root_pass = `mkpasswd`.strip#@crypt_pass = `openssl passwd -1 %s` 		fd = File::open(@save_file, "w")		fd.puts render_to_string :action => "ks"		fd.close_write		render :action => 'centos_ks'#		if @host.product == 'centos'#			render :action => 'centos_ks'#		elsif @host.product == 'ubuntu'#			render :action => 'ubuntu_ks'#		end#		flash[:notice] = 'Host was successfully created.'#		redirect_to :action => 'list'  end	def centos_ks		blah = "testing"	end	def ubuntu_ks		blah = "not testing"	endend