Skip to content

Commit ef5ad76

Browse files
committed
Move all /repos routes out into app/repos.rb
1 parent 385d057 commit ef5ad76

File tree

2 files changed

+131
-81
lines changed

2 files changed

+131
-81
lines changed

app.rb

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
require_relative 'config/sidekiq'
3232

3333
# ronin libraries
34-
require 'ronin/repos'
3534
require 'ronin/payloads'
3635
require 'ronin/exploits'
3736
require 'ronin/support/encoding'
3837

3938
# param validations
40-
require 'ronin/app/validations/install_repo_params'
4139
require 'ronin/app/validations/import_params'
4240
require 'ronin/app/validations/http_params'
4341

@@ -50,11 +48,6 @@
5048
require 'ronin/app/helpers/text'
5149

5250
# worker classes
53-
require_relative 'workers/install_repo'
54-
require_relative 'workers/update_repo'
55-
require_relative 'workers/update_repos'
56-
require_relative 'workers/remove_repo'
57-
require_relative 'workers/purge_repos'
5851
require_relative 'workers/import'
5952

6053
require 'ronin/app/version'
@@ -97,80 +90,6 @@ class App < Sinatra::Base
9790
erb :index
9891
end
9992

100-
get '/repos' do
101-
@repos = Ronin::Repos.cache_dir
102-
103-
erb :"repos/index"
104-
end
105-
106-
get '/repos/install' do
107-
erb :"repos/install"
108-
end
109-
110-
post '/repos/install' do
111-
result = Validations::InstallRepoParams.call(params)
112-
113-
if result.success?
114-
Workers::InstallRepo.perform_async(result[:uri],result[:name])
115-
116-
flash[:success] = "Installing repo at #{result[:uri]}"
117-
redirect '/repos'
118-
else
119-
@errors = result.errors
120-
121-
flash[:danger] = 'Failed to install repo!'
122-
halt 400, erb(:"repos/install")
123-
end
124-
end
125-
126-
post '/repos/update' do
127-
Workers::UpdateRepos.perform_async
128-
129-
flash[:success] = 'All repos will be updated'
130-
redirect '/repos'
131-
end
132-
133-
delete '/repos' do
134-
Workers::PurgeRepos.perform_async
135-
136-
flash[:success] = 'All repos will be purged'
137-
redirect '/repos'
138-
end
139-
140-
get '/repos/:name' do
141-
@repos = Ronin::Repos.cache_dir
142-
143-
begin
144-
@repo = @repos[params[:name]]
145-
146-
erb :"repos/show"
147-
rescue Ronin::Repos::RepositoryNotFound
148-
halt 404
149-
end
150-
end
151-
152-
post '/repos/:name/update' do
153-
@repo = Ronin::Repos.cache_dir[params[:name]]
154-
155-
Workers::UpdateRepo.perform_async(@repo.name)
156-
157-
flash[:success] = "Repo #{@repo.name} enqueued for update"
158-
redirect "/repos/#{params[:name]}"
159-
rescue Ronin::Repos::RepositoryNotFound
160-
halt 404
161-
end
162-
163-
delete '/repos/:name' do
164-
@repo = Ronin::Repos.cache_dir[params[:name]]
165-
166-
Workers::RemoveRepo.perform_async(@repo.name)
167-
168-
flash[:success] = "Repo #{@repo.name} enqueued for removal"
169-
redirect '/repos'
170-
rescue Ronin::Repos::RepositoryNotFound
171-
halt 404
172-
end
173-
17493
get '/payloads' do
17594
@payloads = Ronin::Payloads.list_files
17695

@@ -395,3 +314,4 @@ def pagy_get_vars(collection, vars)
395314

396315
require './app/db'
397316
require './app/scanning'
317+
require './app/repos'

app/repos.rb

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
# frozen_string_literal: true
2+
#
3+
# ronin-app - a local web app for Ronin.
4+
#
5+
# Copyright (C) 2023-2024 Hal Brodigan (postmodern.mod3@gmail.com)
6+
#
7+
# ronin-app is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU Affero General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# ronin-app is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU Affero General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Affero General Public License
18+
# along with ronin-app. If not, see <http://www.gnu.org/licenses/>.
19+
#
20+
21+
# ronin libraries
22+
require 'ronin/repos'
23+
24+
# param validations
25+
require 'ronin/app/validations/install_repo_params'
26+
27+
# worker classes
28+
require_relative '../workers/install_repo'
29+
require_relative '../workers/update_repo'
30+
require_relative '../workers/update_repos'
31+
require_relative '../workers/remove_repo'
32+
require_relative '../workers/purge_repos'
33+
34+
#
35+
# App class containing routes for repos.
36+
#
37+
class App < Sinatra::Base
38+
39+
include Ronin::App
40+
include Pagy::Backend
41+
42+
configure do
43+
enable :sessions
44+
register Sinatra::Flash
45+
helpers Sinatra::ContentFor
46+
helpers Helpers::HTML
47+
end
48+
49+
configure :development do
50+
register Sinatra::Reloader
51+
end
52+
53+
helpers do
54+
include Pagy::Frontend
55+
end
56+
57+
get '/repos' do
58+
@repos = Ronin::Repos.cache_dir
59+
60+
erb :"repos/index"
61+
end
62+
63+
get '/repos/install' do
64+
erb :"repos/install"
65+
end
66+
67+
post '/repos/install' do
68+
result = Validations::InstallRepoParams.call(params)
69+
70+
if result.success?
71+
Workers::InstallRepo.perform_async(result[:uri],result[:name])
72+
73+
flash[:success] = "Installing repo at #{result[:uri]}"
74+
redirect '/repos'
75+
else
76+
@errors = result.errors
77+
78+
flash[:danger] = 'Failed to install repo!'
79+
halt 400, erb(:"repos/install")
80+
end
81+
end
82+
83+
post '/repos/update' do
84+
Workers::UpdateRepos.perform_async
85+
86+
flash[:success] = 'All repos will be updated'
87+
redirect '/repos'
88+
end
89+
90+
delete '/repos' do
91+
Workers::PurgeRepos.perform_async
92+
93+
flash[:success] = 'All repos will be purged'
94+
redirect '/repos'
95+
end
96+
97+
get '/repos/:name' do
98+
@repos = Ronin::Repos.cache_dir
99+
100+
begin
101+
@repo = @repos[params[:name]]
102+
103+
erb :"repos/show"
104+
rescue Ronin::Repos::RepositoryNotFound
105+
halt 404
106+
end
107+
end
108+
109+
post '/repos/:name/update' do
110+
@repo = Ronin::Repos.cache_dir[params[:name]]
111+
112+
Workers::UpdateRepo.perform_async(@repo.name)
113+
114+
flash[:success] = "Repo #{@repo.name} enqueued for update"
115+
redirect "/repos/#{params[:name]}"
116+
rescue Ronin::Repos::RepositoryNotFound
117+
halt 404
118+
end
119+
120+
delete '/repos/:name' do
121+
@repo = Ronin::Repos.cache_dir[params[:name]]
122+
123+
Workers::RemoveRepo.perform_async(@repo.name)
124+
125+
flash[:success] = "Repo #{@repo.name} enqueued for removal"
126+
redirect '/repos'
127+
rescue Ronin::Repos::RepositoryNotFound
128+
halt 404
129+
end
130+
end

0 commit comments

Comments
 (0)