Skip to content

Commit

Permalink
add Delete and Delete All buttons for db records
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzi authored and postmodern committed Jan 21, 2024
1 parent 6a2eb40 commit a2ed7d2
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 2 deletions.
1 change: 1 addition & 0 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class App < Sinatra::Base

configure do
enable :sessions
enable :method_override
register Sinatra::Flash
helpers Sinatra::ContentFor
helpers Helpers::HTML
Expand Down
52 changes: 52 additions & 0 deletions app/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,56 @@ class App < Sinatra::Base
halt 404
end
end

{
host_names: Ronin::DB::HostName,
asns: Ronin::DB::ASN,
ip_addresses: Ronin::DB::IPAddress,
mac_addresses: Ronin::DB::MACAddress,
open_ports: Ronin::DB::OpenPort,
ports: Ronin::DB::Port,
services: Ronin::DB::Service,
urls: Ronin::DB::URL,
url_schemes: Ronin::DB::URLScheme,
url_query_param_names: Ronin::DB::URLQueryParamName,
email_addresses: Ronin::DB::EmailAddress,
user_names: Ronin::DB::UserName,
passwords: Ronin::DB::Password,
credentials: Ronin::DB::Credential,
advisories: Ronin::DB::Advisory,
softwares: Ronin::DB::Software,
software_vendors: Ronin::DB::SoftwareVendor,
oses: Ronin::DB::OS,
vulns: Ronin::DB::WebVuln,
phone_numbers: Ronin::DB::PhoneNumber,
street_addresses: Ronin::DB::StreetAddress,
organizations: Ronin::DB::Organization,
people: Ronin::DB::Person
}.each do |name, model|
delete "/db/#{name}" do
if model.destroy_all
flash[:success] = "Records deleted successfully."
else
flash[:danger] = "Failed to delete records."
end

redirect "/db/#{name}"
end

delete "/db/#{name}/:id" do
@record = model.find(params[:id])

if @record
if @record.destroy
flash[:success] = "Record deleted successfully."

redirect "/db/#{name}"
else
flash[:danger] = "Failed to delete record."
end
else
halt 404
end
end
end
end
4 changes: 4 additions & 0 deletions views/_delete.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<form action="/db/<%=hattr path %>/<%=hattr record.id %>" method="post">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="button is-danger">Delete</button>
</form>
4 changes: 4 additions & 0 deletions views/_delete_all.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<form action="/db/<%=hattr path %>" method="post">
<input type="hidden" name="_method" value="DELETE">
<button type="submit" class="button is-danger">Delete All</button>
</form>
5 changes: 4 additions & 1 deletion views/db/urls/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</nav>
<% end %>

<h1>URLs</h1>
<div class="is-flex is-justify-content-space-between">
<h1>URLs</h1>
<%= partial(:delete_all, path: "urls") %>
</div>

<% @urls.each do |url| %>
<p><a href="/db/urls/<%=h url.id %>"><%=h url %></a></p>
Expand Down
6 changes: 5 additions & 1 deletion views/db/urls/show.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
</nav>
<% end %>

<h1>URL: <%=h @url %></h1>

<div class="is-flex is-justify-content-space-between">
<h1>URL: <%=h @url %></h1>
<%= partial(:delete, record: @url, path: "urls") %>
</div>

<table class="table">
<tbody>
Expand Down

0 comments on commit a2ed7d2

Please sign in to comment.