Guest User

Untitled

a guest
Jul 13th, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.03 KB | None | 0 0
  1. =begin
  2.  
  3. This is BackupWorkstation.rb
  4.  
  5. =end
  6. #!/usr/bin/env ruby
  7.  
  8. require 'sqlite3'
  9. require "Hardware.rb"
  10. require "UserInfo"
  11. #require 'require'
  12.  
  13. class BackupWorkstation < Hardware
  14.  
  15. attr_accessor :ip_address, :hard_drive_size, :ram
  16.  
  17.  
  18. Table = String.new('backup_workstation')
  19. Db = SQLite3::Database.new('Customer_IP_Address_List.s3db')
  20.  
  21. @ip_address = String.new #Primary IP address of the Backup Workstation
  22. @alt_comm = String.new #Alternative Communication
  23. @ram = String.new #Amount of Ram in BU Workstation
  24. @hard_drive_size = String.new #Size of the HDD
  25. #@burner = Burner.new #Burner Object (attached or integrated)
  26. @protocol = String.new("VNC") #Protocol to communicate with BU Wkstn
  27. @prot_user = UserInfo.new(@protocol,'<None>','mobile')
  28. @port = String.new #Port to use with Protocol
  29. #@my_user = UserInfo.new()
  30.  
  31. def initialize(customer_number = 0)
  32. super("Backup Workstation",get_brand(customer_number),
  33. get_model(customer_number),get_serial(customer_number),
  34. get_notes(customer_number))
  35. set_ip(customer_number)
  36. set_hdd(customer_number)
  37. set_other_com(customer_number)
  38. set_ram(customer_number)
  39. set_prot(customer_number)
  40. set_port(customer_number)
  41. set_user_name(customer_number)
  42. set_password(customer_number)
  43.  
  44. end
  45.  
  46. def db_query (customer, column_name)
  47. my_stmnt = 'SELECT "' + column_name + '" WHERE "number"= "' + customer + '"'
  48. Db.execute(my_stmnt) do |row|
  49. if row.length == 1
  50. return(row[0])
  51. else
  52. return("")
  53. end
  54. end
  55. end
  56.  
  57. def set_ip (customer)
  58. @ip_address = db_query(customer, 'eth0')
  59. end
  60.  
  61. def get_brand (customer)
  62. return(db_query(customer, 'brand'))
  63. end
  64.  
  65. def get_model (customer)
  66. return(db_query(customer, 'model'))
  67. end
  68.  
  69. def get_serial (customer)
  70. return(db_query(customer, 'serial_num'))
  71. end
  72.  
  73. def get_notes (customer)
  74. return(db_query(customer, 'notes'))
  75. end
  76.  
  77. def set_hdd (customer)
  78. @hard_drive_size = db_query(customer, 'hdd_size')
  79. end
  80.  
  81. def set_ram (customer)
  82. @ram = db_query(customer, 'ram_size')
  83. end
  84.  
  85. def set_other_com (customer)
  86. @alt_com = db_query(customer, 'other_comm')
  87. end
  88.  
  89. def get_notes (customer)
  90. return(db_query(customer,'notes'))
  91. end
  92.  
  93. def set_prot (customer)
  94. @protocol = db_query(customer, 'protocol')
  95. end
  96.  
  97. def set_port (customer)
  98. @port = db_query(customer, 'port')
  99. end
  100.  
  101. def set_password (customer)
  102. $my_user.user_password= (db_query(customer, 'password'))
  103. end
  104.  
  105. def set_user_name (customer)
  106. $my_user = UserInfo.new
  107. $my_user.user_name= (db_query(customer, 'user_name'))
  108. end
  109.  
  110. def set_prot_user (customer)
  111. @prot_user.user_name= (db_query(customer, 'user_prot'))
  112. end
  113.  
  114. def set_prot_pass (customer)
  115. @prot_user.user_password= (db_query(customer, 'pass_prot'))
  116. end
  117.  
  118. def build_row (label, value)
  119. if value.to_s != ""
  120. label = sprintf("%1$*2$s",label.to_s + ":",25)
  121. return(label + value.to_s + "/n")
  122. else
  123. return('')
  124. end
  125. end
  126.  
  127.  
  128. def to_s_b
  129. myOutput = String.new
  130. myOutput = "Backup Workstation Information/n"
  131. myOutput = myOutput + build_row("IP",@ip_address)
  132. myOutput = myOutput + build_row("Protocol",@protocol)
  133. myOutput = myOutput + build_row("Protocol User",@prot_user.user_name)
  134. myOutput = myOutput + build_row("Protocol Password",@prot_user.user_password)
  135. myOutput = myOutput + build_row("Other Communication",@alt_comm)
  136. myOutput = myOutput + "/n"
  137. myOutput = myOutput + build_row("System User Name",$my_user.user_name)
  138. myOutput = myOutput + build_row("System Password",$my_user.user_password)
  139. myOutput = myOutput + "/n"
  140. myOutput = myOutput + build_row("System RAM (MB)",@ram)
  141. myOutput = myOutput + build_row("Hard Drive Capacity (GB)",@hard_drive_size)
  142. return(myOutput)
  143. end
  144.  
  145.  
  146. private :set_prot_pass, :set_prot_user, :set_password, :set_user_name,
  147. :set_port, :get_notes, :set_other_com, :set_ram, :set_hdd, :set_ip,
  148. :get_model, :get_serial, :get_brand, :set_prot, :db_query, :set_prot_pass
  149.  
  150.  
  151.  
  152.  
  153. end
  154.  
  155. mybu = BackupWorkstation.new('3')
  156. print(mybu.to_s_b)
  157.  
  158. =begin
  159.  
  160. This is Hardware.rb
  161.  
  162. =end
  163. #!/usr/bin/env ruby
  164.  
  165. #require 'require.rb'
  166.  
  167. class Hardware #< Shoes #Inherit from Shoes
  168.  
  169. @name = String.new #holds the name of the Hardware
  170. @brand = String.new #holds the brand of Hardware
  171. @model = String.new("Default") #holds the model of Hardware
  172. @serial = String.new #holds the serial number of Hardware
  173. @output_string = String.new #holds output of to_s override
  174. @notes = String.new #hold the notes of various Hardware
  175.  
  176. def initialize (name ="Default",brand = "", model = "Default", serial = "",
  177. notes = "")
  178. @name = name
  179. @brand = brand
  180. @model = model
  181. @serial = serial
  182. @notes = notes
  183. end
  184.  
  185. def make_row (description, value)
  186. if value != ""
  187. @output_string = output_string + (description.to_s + value.to_s) + "\n"
  188. end
  189. end
  190.  
  191. def to_s
  192. make_row("Brand: \t",@brand)
  193. make_row("Model: \t",@model)
  194. make_row("Serial: \t",@serial)
  195. return(@output_string)
  196. end
  197.  
  198. end
  199.  
  200. =begin
  201.  
  202. This is UserInfo.rb
  203.  
  204. =end
  205. #!/usr/bin/env ruby
  206.  
  207. #require 'sqlite3'
  208.  
  209. class UserInfo
  210.  
  211. attr_writer :user_name
  212. attr_reader :user_name
  213. attr_accessor :user_password
  214. attr_accessor :use_with
  215.  
  216. @use_with = String.new #specifies what the user_name and
  217. #password belong to
  218. @user_name = String.new #User Name (duh)
  219. @user_password = String.new #Passworh (um, duh!)
  220.  
  221. def initialize (with = "<None>", name = "mvadmin", pw = "mobile")
  222. @use_with = with
  223. @user_name = name
  224. @user_password = pw
  225. end
  226.  
  227. def user_name= (value)
  228. @user_name = value
  229. end
  230.  
  231. def user_name
  232. return(@user_name)
  233. end
  234.  
  235. end
Add Comment
Please, Sign In to add comment