Class: HackerNote::GitbookBuilder
- Inherits:
-
Object
- Object
- HackerNote::GitbookBuilder
- Defined in:
- lib/hackernote/gitbook_builder.rb
Overview
for all gitbook related work (build gitbook files, targets files, project readme, etc)
Instance Method Summary collapse
-
#build(project_name, target_list) ⇒ Object
Builder wrapper.
-
#build_gitbook_files ⇒ Object
build gitbook’s main files such as book.json, SUMMARY.md and README.md.
-
#build_project_readme ⇒ Object
README.md generator.
-
#build_target_notes ⇒ Object
build_target_notes builds the content of notes file.
-
#build_targets_files ⇒ Object
build_targets_files builds project related files.
-
#create_summary_record(file_path) ⇒ Object
Create summary records @see #build_targets_files.
-
#general_fixes ⇒ Object
general fixes.
-
#set_env ⇒ Object
set environment requirements.
-
#set_project_dir ⇒ Object
set the project main directory @see #set_env.
-
#set_targets_list ⇒ Object
check targets list, @see #set_env if file read each line as a target, if file not exists, consider the given name as a target.
Instance Method Details
#build(project_name, target_list) ⇒ Object
Builder wrapper
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/hackernote/gitbook_builder.rb', line 9 def build(project_name, target_list) @project_name = project_name @target_list = target_list puts '[+] '.bold + 'Gitbook Setup:'.bold.underline set_env build_gitbook_files build_targets_files build_project_readme general_fixes end |
#build_gitbook_files ⇒ Object
build gitbook’s main files such as book.json, SUMMARY.md and README.md
57 58 59 60 61 62 63 |
# File 'lib/hackernote/gitbook_builder.rb', line 57 def build_gitbook_files puts '[-] '.bold + "Creating gitbook's main files.'" prj_files = %w[book.json SUMMARY.md README.md] prj_files.each do |file| File.write(file, "# #{file.split('.').first.capitalize}\n\n") end end |
#build_project_readme ⇒ Object
README.md generator
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/hackernote/gitbook_builder.rb', line 134 def build_project_readme readme = <<~README # #{@project_name} ## Customer Requests and Concerns 1. No DoS Attacks 2. Automated scan should be gentle at production time 3. ABCDEFG | Timeline | Date | | :--- | :--- | | Project Testing Start | 1/1/2030 | | Project Testing End | 1/1/2030 | ## Applications progress | Host/IP | # of issues | Progress % | Issues | Notes | misc. | | :--- | :--- | :--- | :--- | :--- | :--- | #{@list_of_targets.map {|host| "|#{host} | | | | | |" }.join("\n")} ### Point Of Contact | Name | email | Mobile number | Job title/Role | | :--- | :--- | :--- | :--- | | Firstname Lastname | [email protected] | 0550000000 | | ### Source IP Addresses log This list has to be regularly update! | Engineer 1 | Engineer 2 | | :--- | :--- | | x.x.x.x | y.y.y.y | | x.x.x.x | y.y.y.y | | x.x.x.x | y.y.y.y | ## Scope **Approach:** **IP ranges** **Domains** **Credentials** ## Clean up | Host | URL/Files | Description | | :--- | :--- | :--- | | | | README File.write('README.md', readme) end |
#build_target_notes ⇒ Object
build_target_notes builds the content of notes file
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/hackernote/gitbook_builder.rb', line 101 def build_target_notes <<~NOTES ## To Be Checked ## To Be Deleted * Users * user1 * user2 * Files/Directories/URL * filepath1 * filepath1 NOTES end |
#build_targets_files ⇒ Object
build_targets_files builds project related files
@example:
targetX/
scanning_and_enumeration.md
critical.md
high.md
medium.md
low.md
informational.md
notes.md
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/hackernote/gitbook_builder.rb', line 76 def build_targets_files puts '[-] '.bold + "Creating targets' files and directories." target_main_files = %W[scanning_and_enumeration.md critical.md high.md medium.md low.md informational.md notes.md] @list_of_targets.each do |target| target = fix_project_naming(target) target_files = target_main_files.dup target_files.unshift "#{target}.md" Dir.mkdir(target) create_summary_record(target) target_files.each do |t_file| file_path = File.join(target, t_file) heading1 = t_file.split('.md').first.capitalize # Each file's title File.write(file_path, "# #{heading1}\n\n") open(file_path, 'a') do |file| file.puts "# #{heading1}\n\n" file.puts build_target_notes if heading1.include? 'Notes' end create_summary_record(file_path.to_s) unless heading1 =~ /#{target}/i end end end |
#create_summary_record(file_path) ⇒ Object
Create summary records @see #build_targets_files
119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/hackernote/gitbook_builder.rb', line 119 def create_summary_record(file_path) record = File.open('SUMMARY.md', 'a+') path = File.split file_path title = path.last.split('.md').first.capitalize path.delete_if {|p| p == '.'} align = "#{' ' * path.index(path.last)}* " file_path = "#{file_path}/#{file_path}.md" if File.directory? file_path the_record = "#{align}[#{title}](#{file_path})" record.puts the_record record.close print "\r#{the_record}".cls_upline sleep 0.1 end |
#general_fixes ⇒ Object
general fixes
186 187 188 189 190 191 |
# File 'lib/hackernote/gitbook_builder.rb', line 186 def general_fixes # fix for book.json File.write('book.json', '{ }') # Create 'files' directory, general place for project related files and scripts Dir.mkdir 'files' end |
#set_env ⇒ Object
set environment requirements
22 23 24 25 26 |
# File 'lib/hackernote/gitbook_builder.rb', line 22 def set_env set_project_dir set_targets_list Dir.chdir @project_path end |
#set_project_dir ⇒ Object
set the project main directory @see #set_env
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hackernote/gitbook_builder.rb', line 29 def set_project_dir @project_path = Pathname.new(@project_name).basename if Dir.exist?(@project_path) rename = "#{@project_path}_#{Time.now.to_i}" puts '[-] '.bold + "Renaming Existing directory '#{@project_path}' to '#{rename}'" FileUtils.mv(@project_path, rename) end puts '[-] '.bold + "Creating #{@project_name} directory" Dir.mkdir @project_name end |
#set_targets_list ⇒ Object
check targets list, @see #set_env if file read each line as a target, if file not exists, consider the given name as a target
47 48 49 50 51 52 53 54 |
# File 'lib/hackernote/gitbook_builder.rb', line 47 def set_targets_list if File.file? @target_list @list_of_targets = File.open(@target_list).each_line(chomp: true).map(&:strip).reject(&:nil?).reject(&:empty?) else puts "[!] ".yellow + "No targets list file, assuming '#{@target_list}' as a target name." @list_of_targets = [@target_list] end end |