Advertisement
Guest User

Untitled

a guest
Aug 6th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.57 KB | None | 0 0
  1. #!/usr/local/bin/env ruby
  2.  
  3. # Require the files that requires all the other files and the initialize the constants
  4.  
  5. require_relative '../email/lib/lists/require/require'
  6. require_relative '../email/lib/lists/require/constants'
  7.  
  8. # Optparse to append the flags into the OPTIONS constant
  9.  
  10. OptionParser.new do |opts|
  11. opts.on('--tutorial', 'First time with the program..? Run this and find out how to use it') { |o| OPTIONS[:tutorial] = o }
  12. opts.on('--help', 'Generate the help page') { |o| OPTIONS[:help] = o }
  13. opts.on('-t INPUT[=INPUT]', '--type INPUT[=INPUT]', 'Specify the type of email to be generated') { |o| OPTIONS[:type] = o }
  14. opts.on('--example', 'Gives an example of a generic email that was created using this program') { |o| OPTIONS[:example] = o }
  15. opts.on('--version', 'Displays the version number of the program') { |o| OPTIONS[:version] = o }
  16. opts.on('--test', 'Run the test modules.') { |o| OPTIONS[:test] = o }
  17. end.parse!
  18.  
  19. def help_page
  20. puts
  21. puts "e[44mruby gen_email.rb -[t] <Type-of-email> --[help|tutorial|test|example|version]e[0m"
  22. `notepad.exe readme.md` unless File.read('./lib/tools/read.txt').chomp == 'true'
  23. end
  24.  
  25. # Most of these are used for information gathering and are called in other modules, such as the email templates module.
  26. # They are just basic questions and might be moved to their own module to save lines.
  27.  
  28. def res_group
  29. FORMAT.prompt('Enter resolution group').split.map(&:capitalize).join(' ')
  30. end
  31.  
  32. def users_name
  33. FORMAT.prompt('Enter users full name').split.map(&:capitalize).join(' ')
  34. end
  35.  
  36. def cap_name(name)
  37. name.split.map{ |i| i.capitalize }.join(' ')
  38. end
  39.  
  40. def summary
  41. FORMAT.prompt('Enter summary of issue')
  42. end
  43.  
  44. def poc_name
  45. FORMAT.prompt('Enter POC name').downcase
  46. end
  47.  
  48. def dev_domain
  49. FORMAT.prompt('Enter domain name')
  50. end
  51.  
  52. def dev_server
  53. FORMAT.prompt('Enter server name')
  54. end
  55.  
  56. def request_cancel
  57. print "e[36mEnter ticket num to cancel:e[0m INC00000"
  58. cancel = STDIN.gets.chomp
  59. verify_digits(cancel)
  60. end
  61.  
  62. # Verify that the digits are correctly entered, it will not allow more then 7 digits entered at a time.
  63.  
  64. def verify_digits(int)
  65. begin
  66. if !(int[/^d{7}$/])
  67. raise TicketNumError
  68. else
  69. int
  70. end
  71. rescue TicketNumError
  72. '<Invalid ticket number>'
  73. end
  74. end
  75.  
  76. def num
  77. print "e[36mEnter ticket num:e[0m INC00000"
  78. num = STDIN.gets.chomp
  79. verify_digits(num)
  80. end
  81.  
  82. # Verify that the timestamp is in the same format as the Remedy systems timestamp format. This will save the user
  83. # a lot of trouble by making them input the correct timestamp before they send the email.
  84.  
  85. def verify_timestamp(stamp)
  86. begin
  87. if !(stamp[/^d{1,2}/d{1,2}/d{4} d{1,2}:d{1,2}:d{1,2} [AP]Mz/])
  88. FORMAT.warning('Invalid format of timestamp example: 06/07/2016 5:30:23 AM')
  89. raise TimeStampFormatError
  90. else
  91. stamp
  92. end
  93. rescue TimeStampFormatError
  94. timestamp
  95. end
  96. end
  97.  
  98. def timestamp
  99. print "e[36mEnter timestamp for removal: e[0m"
  100. ts = STDIN.gets.chomp.upcase
  101. verify_timestamp(ts)
  102. end
  103.  
  104. def body
  105. FORMAT.prompt('Enter what will happen or what you did')
  106. end
  107.  
  108. def res
  109. FORMAT.prompt('Enter resolution')
  110. end
  111.  
  112. def account
  113. FORMAT.prompt('Enter users account')
  114. end
  115.  
  116. def user_id
  117. FORMAT.prompt('Enter username')
  118. end
  119.  
  120. def agency
  121. FORMAT.prompt('Enter users agency')
  122. end
  123.  
  124. def phone_num
  125. FORMAT.prompt('Enter users phone number')
  126. end
  127.  
  128. def check_date
  129. SKIPDAY.date
  130. end
  131.  
  132. def header
  133. CHECKTIME.check_time
  134. end
  135.  
  136. def get_user
  137. user = Etc.getlogin
  138. @esd_user = user.split('_').first.capitalize + ' ' + user.split('_').last[0].upcase
  139. end
  140.  
  141. def copy(email)
  142. clip = ClipBrd::CopyToClipboard.new
  143. File.open('./lib/tools/tmp/email_to_copy', 'w') { |s| s.puts(email) }
  144. clip.copy_to_clipbrd
  145. FORMAT.info('Copied to clipboard press CNTRL-V to paste')
  146. end
  147.  
  148. def advocate_agency
  149. print "e[36mEnter agency:e[0m "
  150. STDIN.gets.chomp.upcase
  151. end
  152.  
  153. # Gets the advocates and POC's from YAML files located inside of the lib/list dir. The YAML files contains every
  154. # advocate for every agency and every POC inbox, email, and phone number.
  155.  
  156. def get_advocate
  157. res = advocate_agency
  158. file = YAML.load_file('lib/lists/advocate_list.yml')
  159. begin
  160. if file['agencies'][res] == nil
  161. raise InvalidPocError
  162. else
  163. file['agencies'][res]
  164. end
  165. rescue InvalidPocError
  166. 'Invalid POC'
  167. end
  168. end
  169.  
  170. def get_poc_inbox(name)
  171.  
  172. data = [POC_INBOX['poc_inbox'][name.downcase]].flatten
  173.  
  174. if data.count == 1
  175. POC_INBOX['poc_inbox'][name]
  176. else
  177. FORMAT.warning("Multiple inbox's found for #{cap_name(name)}")
  178. data.each.with_index(1) do |str, i|
  179. FORMAT.info("#{i}. #{str}")
  180. end
  181. FORMAT.warning("One of the above inbox's is the correct inbox for this ticket.")
  182. '<PASTE INBOX HERE>'
  183. end
  184. end
  185.  
  186. def get_poc_num(name)
  187. data = POC_NUM['poc_phone'][name]
  188. begin
  189. if data.kind_of?(String)
  190. data
  191. else
  192. raise InvalidPocError
  193. end
  194. rescue InvalidPocError
  195. "** POC #{name} does not have a number listed **"
  196. end
  197. end
  198.  
  199. def get_poc_email(name)
  200. data = POC_EMAIL['poc_email'][name]
  201. begin
  202. if data.kind_of?(String)
  203. data
  204. else
  205. raise InvalidPocError
  206. end
  207. rescue InvalidPocError
  208. "** POC #{name} does not have an email listed **"
  209. end
  210. end
  211.  
  212. # Figure out the email type, by finding the flag argument and comparing it against a regex to validate what the user
  213. # wants to do. For example: ruby gen_email.rb -t generic <= Will create a generic email to be sent, and copy it to the
  214. # users clipboard.
  215.  
  216. def gather_intel
  217. case OPTIONS[:type]
  218. when /osha/
  219. FORMAT.info('Creating OSHA Regional email..')
  220. EMAILS.osha_reg
  221. when /pend/
  222. FORMAT.info('Creating 6 day hold pending email..')
  223. EMAILS.pend
  224. when /60/
  225. FORMAT.info('Creating 60 day hold account deletion email..')
  226. EMAILS.sixty_day
  227. when /generic/
  228. FORMAT.info('Creating generic email..')
  229. EMAILS.generic
  230. when /resolve/
  231. FORMAT.info('Creating resolution ticket..')
  232. EMAILS.resolve
  233. when /esc/
  234. FORMAT.info('Creating escalation ticket..')
  235. EMAILS.assign
  236. when /pii/
  237. FORMAT.info('Creating request to remove personal info..')
  238. EMAILS.remove_pii
  239. when /vip/
  240. FORMAT.info('Creating VIP user email..')
  241. EMAILS.vip_user
  242. when /inop/
  243. FORMAT.info('Creating INOP user email..')
  244. EMAILS.in_op_user
  245. when /dev/
  246. begin
  247. if OPTIONS[:type].to_s.include?('dev=unlock')
  248. message = 'unlock'
  249. elsif OPTIONS[:type].to_s.include?('dev=reset')
  250. message = 'password reset'
  251. else
  252. raise InvalidDevRequestError
  253. end
  254. FORMAT.info("Creating dev account #{message} email")
  255. EMAILS.dev_account(OPTIONS[:type])
  256. rescue InvalidDevRequestError
  257. FORMAT.err("#{OPTIONS[:type].to_s.split('=').last} is not a valid dev email, please try again..")
  258. end
  259. when /cancel/
  260. FORMAT.info('Creating cancellation request..')
  261. EMAILS.cancel_ticket
  262. else
  263. raise InvalidOptionError
  264. end
  265. end
  266.  
  267. # Where all the big decisions are made, after the program has appended into the OPTIONS constant it will then look at
  268. # the info called here. If nothing is given it will default to the help page method
  269.  
  270. begin
  271. case
  272. when OPTIONS[:type]
  273. README.check_if_read
  274. gather_intel
  275. when OPTIONS[:example]
  276. puts "e[36m#{EMAILS.examples_page}e[0m"
  277. when OPTIONS[:version]
  278. puts VERSION.version
  279. when OPTIONS[:test]
  280. TESTRUN.run_test
  281. when OPTIONS[:tutorial]
  282. TUT.flag_choices
  283. else
  284. puts help_page
  285. end
  286. rescue => e
  287. FORMAT.err("Program failed due to #{e}")
  288. FORMAT.err("ERROR => #{e.backtrace.join}")
  289. FORMAT.info('To report this issue, fill out the text file called Issues.txt in the /lib/text_files directory.')
  290. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement