diff --git a/app.rb b/app.rb index ae416b6..09ab729 100644 --- a/app.rb +++ b/app.rb @@ -341,6 +341,47 @@ class App < Sinatra::Base end end + { + mac_addresses: Ronin::DB::MACAddress, + ip_addresses: Ronin::DB::IPAddress, + host_names: Ronin::DB::HostName, + ports: Ronin::DB::Port, + services: Ronin::DB::Service, + open_ports: Ronin::DB::OpenPort, + credentials: Ronin::DB::Credential, + urls: Ronin::DB::URL, + user_names: Ronin::DB::UserName, + email_addresses: Ronin::DB::EmailAddress, + passwords: Ronin::DB::Password, + advisories: Ronin::DB::Advisory + }.each do |name, model| + post "/db/#{name}/:id/notes" do + @record = model.find(params[:id]) + + if @record + if @record.notes.create!(body: params[:body]) + flash[:success] = "Note added successfully." + else + flash[:danger] = "Failed to create Note." + end + + redirect "/db/#{name}/#{params[:id]}" + else + halt 404 + end + end + + delete "/db/#{name}/:id/notes/:note_id" do + @record = model.find(params[:id]) + + if @record + @record.notes.destroy(params[:note_id]) + else + halt 404 + end + end + end + get '/db/asns' do @asns = Ronin::DB::ASN.all diff --git a/public/javascript/notes.js b/public/javascript/notes.js new file mode 100644 index 0000000..183a320 --- /dev/null +++ b/public/javascript/notes.js @@ -0,0 +1,28 @@ +const Notes = { + init() { + (document.querySelectorAll('.delete-note') || []).forEach(button => { + button.addEventListener('click', () => { + const noteId = button.getAttribute('data-note-id'); + Notes.delete(noteId, button) + }); + }); + }, + + delete(noteId, button) { + fetch(`${document.location}/notes/${noteId}`, { + method: 'DELETE' + }) + .then(response => { + if (response.ok) { + button.parentElement.parentElement.remove(); + } else { + console.error('Failed to delete note'); + } + }) + .catch(error => { + console.error('Error:', error); + }); + } +}; + +ready(Notes.init); diff --git a/views/_notes.erb b/views/_notes.erb new file mode 100644 index 0000000..5d74126 --- /dev/null +++ b/views/_notes.erb @@ -0,0 +1,33 @@ + + +<% unless notes.empty? %> +

Notes

+ <% notes.each do |note| %> +
+
+
+

<%= note.body %>

+ Created at: <%= note.created_at %> +
+
+ +
+
+
+ <% end %> +<% end %> + +
+
method="POST"> +
+
+ +
+
+

+ +

+
+
+
+
diff --git a/views/db/advisories/show.erb b/views/db/advisories/show.erb index d1eebf3..768f468 100644 --- a/views/db/advisories/show.erb +++ b/views/db/advisories/show.erb @@ -98,3 +98,5 @@ + +<%= partial(:notes, notes: @advisory.notes) %> diff --git a/views/db/credentials/show.erb b/views/db/credentials/show.erb index 1ed28c2..582dd4f 100644 --- a/views/db/credentials/show.erb +++ b/views/db/credentials/show.erb @@ -44,3 +44,5 @@ + +<%= partial(:notes, notes: @credential.notes) %> diff --git a/views/db/email_addresses/show.erb b/views/db/email_addresses/show.erb index 62f2d2c..3e2a1e5 100644 --- a/views/db/email_addresses/show.erb +++ b/views/db/email_addresses/show.erb @@ -36,3 +36,6 @@ + + +<%= partial(:notes, notes: @email_address.notes) %> diff --git a/views/db/host_names/show.erb b/views/db/host_names/show.erb index e01ea8e..7bd1aa9 100644 --- a/views/db/host_names/show.erb +++ b/views/db/host_names/show.erb @@ -45,3 +45,5 @@ + +<%= partial(:notes, notes: @host_name.notes) %> diff --git a/views/db/ip_addresses/show.erb b/views/db/ip_addresses/show.erb index db9cac8..143d4fe 100644 --- a/views/db/ip_addresses/show.erb +++ b/views/db/ip_addresses/show.erb @@ -91,3 +91,5 @@ + +<%= partial(:notes, notes: @ip_address.notes) %> diff --git a/views/db/mac_addresses/show.erb b/views/db/mac_addresses/show.erb index 9c746f9..e5ccea2 100644 --- a/views/db/mac_addresses/show.erb +++ b/views/db/mac_addresses/show.erb @@ -54,3 +54,6 @@ + +<%= partial(:notes, notes: @mac_address.notes) %> + diff --git a/views/db/open_ports/show.erb b/views/db/open_ports/show.erb index 724d3ea..6801d0b 100644 --- a/views/db/open_ports/show.erb +++ b/views/db/open_ports/show.erb @@ -79,3 +79,6 @@ + + +<%= partial(:notes, notes: @open_port.notes) %> diff --git a/views/db/passwords/show.erb b/views/db/passwords/show.erb index b27fc09..6f57785 100644 --- a/views/db/passwords/show.erb +++ b/views/db/passwords/show.erb @@ -44,3 +44,6 @@ + + +<%= partial(:notes, notes: @password.notes) %> diff --git a/views/db/ports/show.erb b/views/db/ports/show.erb index c198263..f8cafe7 100644 --- a/views/db/ports/show.erb +++ b/views/db/ports/show.erb @@ -62,3 +62,6 @@ + +<%= partial(:notes, notes: @port.notes) %> + diff --git a/views/db/services/show.erb b/views/db/services/show.erb index de31030..4598362 100644 --- a/views/db/services/show.erb +++ b/views/db/services/show.erb @@ -57,3 +57,6 @@ + +<%= partial(:notes, notes: @service.notes) %> + diff --git a/views/db/urls/show.erb b/views/db/urls/show.erb index 0586250..48426d8 100644 --- a/views/db/urls/show.erb +++ b/views/db/urls/show.erb @@ -96,3 +96,5 @@ + +<%= partial(:notes, notes: @url.notes) %> diff --git a/views/db/user_names/show.erb b/views/db/user_names/show.erb index 7275ae7..5c2b12b 100644 --- a/views/db/user_names/show.erb +++ b/views/db/user_names/show.erb @@ -41,3 +41,5 @@ + +<%= partial(:notes, notes: @user_name.notes) %>