Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =begin
- This is BackupWorkstation.rb
- =end
- #!/usr/bin/env ruby
- require 'sqlite3'
- require "Hardware.rb"
- require "UserInfo"
- #require 'require'
- class BackupWorkstation < Hardware
- attr_accessor :ip_address, :hard_drive_size, :ram
- Table = String.new('backup_workstation')
- Db = SQLite3::Database.new('Customer_IP_Address_List.s3db')
- @ip_address = String.new #Primary IP address of the Backup Workstation
- @alt_comm = String.new #Alternative Communication
- @ram = String.new #Amount of Ram in BU Workstation
- @hard_drive_size = String.new #Size of the HDD
- #@burner = Burner.new #Burner Object (attached or integrated)
- @protocol = String.new("VNC") #Protocol to communicate with BU Wkstn
- @prot_user = UserInfo.new(@protocol,'<None>','mobile')
- @port = String.new #Port to use with Protocol
- #@my_user = UserInfo.new()
- def initialize(customer_number = 0)
- super("Backup Workstation",get_brand(customer_number),
- get_model(customer_number),get_serial(customer_number),
- get_notes(customer_number))
- set_ip(customer_number)
- set_hdd(customer_number)
- set_other_com(customer_number)
- set_ram(customer_number)
- set_prot(customer_number)
- set_port(customer_number)
- set_user_name(customer_number)
- set_password(customer_number)
- end
- def db_query (customer, column_name)
- my_stmnt = 'SELECT "' + column_name + '" WHERE "number"= "' + customer + '"'
- Db.execute(my_stmnt) do |row|
- if row.length == 1
- return(row[0])
- else
- return("")
- end
- end
- end
- def set_ip (customer)
- @ip_address = db_query(customer, 'eth0')
- end
- def get_brand (customer)
- return(db_query(customer, 'brand'))
- end
- def get_model (customer)
- return(db_query(customer, 'model'))
- end
- def get_serial (customer)
- return(db_query(customer, 'serial_num'))
- end
- def get_notes (customer)
- return(db_query(customer, 'notes'))
- end
- def set_hdd (customer)
- @hard_drive_size = db_query(customer, 'hdd_size')
- end
- def set_ram (customer)
- @ram = db_query(customer, 'ram_size')
- end
- def set_other_com (customer)
- @alt_com = db_query(customer, 'other_comm')
- end
- def get_notes (customer)
- return(db_query(customer,'notes'))
- end
- def set_prot (customer)
- @protocol = db_query(customer, 'protocol')
- end
- def set_port (customer)
- @port = db_query(customer, 'port')
- end
- def set_password (customer)
- $my_user.user_password= (db_query(customer, 'password'))
- end
- def set_user_name (customer)
- $my_user = UserInfo.new
- $my_user.user_name= (db_query(customer, 'user_name'))
- end
- def set_prot_user (customer)
- @prot_user.user_name= (db_query(customer, 'user_prot'))
- end
- def set_prot_pass (customer)
- @prot_user.user_password= (db_query(customer, 'pass_prot'))
- end
- def build_row (label, value)
- if value.to_s != ""
- label = sprintf("%1$*2$s",label.to_s + ":",25)
- return(label + value.to_s + "/n")
- else
- return('')
- end
- end
- def to_s_b
- myOutput = String.new
- myOutput = "Backup Workstation Information/n"
- myOutput = myOutput + build_row("IP",@ip_address)
- myOutput = myOutput + build_row("Protocol",@protocol)
- myOutput = myOutput + build_row("Protocol User",@prot_user.user_name)
- myOutput = myOutput + build_row("Protocol Password",@prot_user.user_password)
- myOutput = myOutput + build_row("Other Communication",@alt_comm)
- myOutput = myOutput + "/n"
- myOutput = myOutput + build_row("System User Name",$my_user.user_name)
- myOutput = myOutput + build_row("System Password",$my_user.user_password)
- myOutput = myOutput + "/n"
- myOutput = myOutput + build_row("System RAM (MB)",@ram)
- myOutput = myOutput + build_row("Hard Drive Capacity (GB)",@hard_drive_size)
- return(myOutput)
- end
- private :set_prot_pass, :set_prot_user, :set_password, :set_user_name,
- :set_port, :get_notes, :set_other_com, :set_ram, :set_hdd, :set_ip,
- :get_model, :get_serial, :get_brand, :set_prot, :db_query, :set_prot_pass
- end
- mybu = BackupWorkstation.new('3')
- print(mybu.to_s_b)
- =begin
- This is Hardware.rb
- =end
- #!/usr/bin/env ruby
- #require 'require.rb'
- class Hardware #< Shoes #Inherit from Shoes
- @name = String.new #holds the name of the Hardware
- @brand = String.new #holds the brand of Hardware
- @model = String.new("Default") #holds the model of Hardware
- @serial = String.new #holds the serial number of Hardware
- @output_string = String.new #holds output of to_s override
- @notes = String.new #hold the notes of various Hardware
- def initialize (name ="Default",brand = "", model = "Default", serial = "",
- notes = "")
- @name = name
- @brand = brand
- @model = model
- @serial = serial
- @notes = notes
- end
- def make_row (description, value)
- if value != ""
- @output_string = output_string + (description.to_s + value.to_s) + "\n"
- end
- end
- def to_s
- make_row("Brand: \t",@brand)
- make_row("Model: \t",@model)
- make_row("Serial: \t",@serial)
- return(@output_string)
- end
- end
- =begin
- This is UserInfo.rb
- =end
- #!/usr/bin/env ruby
- #require 'sqlite3'
- class UserInfo
- attr_writer :user_name
- attr_reader :user_name
- attr_accessor :user_password
- attr_accessor :use_with
- @use_with = String.new #specifies what the user_name and
- #password belong to
- @user_name = String.new #User Name (duh)
- @user_password = String.new #Passworh (um, duh!)
- def initialize (with = "<None>", name = "mvadmin", pw = "mobile")
- @use_with = with
- @user_name = name
- @user_password = pw
- end
- def user_name= (value)
- @user_name = value
- end
- def user_name
- return(@user_name)
- end
- end
Add Comment
Please, Sign In to add comment