cors-ui 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +28 -0
- data/Rakefile +8 -0
- data/app/assets/images/cors/ui/braket-cors.svg +43 -0
- data/app/assets/images/cors/ui/flat-cors.svg +52 -0
- data/app/assets/stylesheets/cors/ui/application.css +15 -0
- data/app/assets/stylesheets/cors/ui/tailwind.css +176011 -0
- data/app/controllers/cors/ui/application_controller.rb +6 -0
- data/app/controllers/cors/ui/dashboard_controller.rb +10 -0
- data/app/controllers/cors/ui/home_controller.rb +6 -0
- data/app/controllers/cors/ui/pages_controller.rb +13 -0
- data/app/helpers/cors/ui/application_helper.rb +6 -0
- data/app/jobs/cors/ui/application_job.rb +6 -0
- data/app/mailers/cors/ui/application_mailer.rb +8 -0
- data/app/models/cors/ui/application_record.rb +7 -0
- data/app/views/cors/ui/dashboard/index.html.erb +219 -0
- data/app/views/cors/ui/home/index.html.erb +15 -0
- data/app/views/cors/ui/pages/about.html.erb +17 -0
- data/app/views/cors/ui/pages/index.html.erb +37 -0
- data/app/views/layouts/cors/ui/_footer.html.erb +10 -0
- data/app/views/layouts/cors/ui/_navbar.html.erb +32 -0
- data/app/views/layouts/cors/ui/application.html.erb +19 -0
- data/config/routes.rb +5 -0
- data/lib/cors/ui/cors_config_reader.rb +61 -0
- data/lib/cors/ui/engine.rb +9 -0
- data/lib/cors/ui/version.rb +5 -0
- data/lib/cors/ui.rb +8 -0
- data/lib/tasks/cors/ui_tasks.rake +4 -0
- metadata +104 -0
@@ -0,0 +1,219 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
<div class="container mx-auto p-4">
|
4
|
+
<h1 class="text-2xl text-red-500 font-bold mb-4">CORS Configuration Dashboard</h1>
|
5
|
+
|
6
|
+
<!-- Last Updated and Summary Cards -->
|
7
|
+
<div class="mb-6">
|
8
|
+
<div class="text-sm text-gray-600 mb-4">
|
9
|
+
Last updated: <%= @last_updated.strftime("%H:%M:%S") %>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
|
13
|
+
<div class="bg-white shadow-md rounded-lg p-4">
|
14
|
+
<h3 class="text-lg font-semibold text-gray-700">Total Resources</h3>
|
15
|
+
<p class="text-2xl font-bold text-blue-600">
|
16
|
+
<%= pluralize(@cors_configs.size, 'Resource') %>
|
17
|
+
</p>
|
18
|
+
</div>
|
19
|
+
<div class="bg-white shadow-md rounded-lg p-4">
|
20
|
+
<h3 class="text-lg font-semibold text-gray-700">Total Origins</h3>
|
21
|
+
<p class="text-2xl font-bold text-green-600">
|
22
|
+
<%#= @cors_configs.sum { |c| c[:origins].size } %>
|
23
|
+
<%= pluralize(@cors_configs.sum { |c| c[:origins].size }, 'Origin') %>
|
24
|
+
</p>
|
25
|
+
</div>
|
26
|
+
<div class="bg-white shadow-md rounded-lg p-4">
|
27
|
+
<h3 class="text-lg font-semibold text-gray-700">Total Methods</h3>
|
28
|
+
<p class="text-2xl font-bold text-purple-600">
|
29
|
+
<%= @cors_configs.sum { |c| c[:methods] == :any ? 1 : c[:methods].size } %>
|
30
|
+
</p>
|
31
|
+
</div>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<!-- CORS Configurations -->
|
36
|
+
<% if @cors_configs.empty? %>
|
37
|
+
<div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4" role="alert">
|
38
|
+
<p class="font-bold">No CORS configurations found</p>
|
39
|
+
</div>
|
40
|
+
<% else %>
|
41
|
+
<div class="space-y-4">
|
42
|
+
<% @cors_configs.each_with_index do |config, index| %>
|
43
|
+
<div class="bg-white shadow-md rounded-lg overflow-hidden">
|
44
|
+
<div class="p-4 border-b border-gray-200">
|
45
|
+
<h2 class="text-lg font-semibold">
|
46
|
+
Resource: <code class="ml-2 text-sm bg-gray-100 p-1 rounded"><%= config[:path] %></code>
|
47
|
+
</h2>
|
48
|
+
</div>
|
49
|
+
|
50
|
+
<div class="p-4">
|
51
|
+
<!-- Origins -->
|
52
|
+
<div class="mb-4">
|
53
|
+
<!-- <h3 class="text-md font-semibold mb-2">Allowed Origins</h3>-->
|
54
|
+
<% if config[:origins].any? %>
|
55
|
+
<div class="relative overflow-x-auto shadow-md sm:rounded-lg">
|
56
|
+
<table class="w-full text-sm text-left rtl:text-right text-gray-500 dark:text-gray-400">
|
57
|
+
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
58
|
+
<tr>
|
59
|
+
<th scope="col" class="px-6 py-3">Origin</th>
|
60
|
+
<th scope="col" class="px-6 py-3">Type</th>
|
61
|
+
<th scope="col" class="px-6 py-3">Security</th>
|
62
|
+
<th scope="col" class="px-6 py-3">
|
63
|
+
<span class="sr-only">Edit</span>
|
64
|
+
</th>
|
65
|
+
</tr>
|
66
|
+
</thead>
|
67
|
+
<tbody>
|
68
|
+
<% config[:origins].each do |origin| %>
|
69
|
+
<tr class="bg-white border-b dark:bg-gray-800 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-600">
|
70
|
+
<td class="px-6 py-4 font-medium text-gray-900 whitespace-nowrap dark:text-white">
|
71
|
+
<code><%= origin %></code>
|
72
|
+
</td>
|
73
|
+
<td class="px-6 py-4">
|
74
|
+
<%= origin == '*' ? 'Wildcard' : 'Specific' %>
|
75
|
+
</td>
|
76
|
+
<td class="px-6 py-4">
|
77
|
+
<% if origin == '*' %>
|
78
|
+
<span class="text-red-600 dark:text-red-400">High Risk</span>
|
79
|
+
<% else %>
|
80
|
+
<span class="text-green-600 dark:text-green-400">Controlled</span>
|
81
|
+
<% end %>
|
82
|
+
</td>
|
83
|
+
<td class="px-6 py-4 text-right">
|
84
|
+
<a href="#" class="font-medium text-blue-600 dark:text-blue-500 hover:underline">Edit</a>
|
85
|
+
</td>
|
86
|
+
</tr>
|
87
|
+
<% end %>
|
88
|
+
</tbody>
|
89
|
+
</table>
|
90
|
+
</div>
|
91
|
+
<% else %>
|
92
|
+
<div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4" role="alert">
|
93
|
+
<p class="font-bold">No origins configured</p>
|
94
|
+
</div>
|
95
|
+
<% end %>
|
96
|
+
|
97
|
+
<%# if config[:origins].any? %>
|
98
|
+
<!-- <div class="bg-gray-50 p-3 rounded-lg">-->
|
99
|
+
<%# config[:origins].each do |origin| %>
|
100
|
+
<!-- <div class="text-sm text-gray-700"><code><%#= origin %></code></div>-->
|
101
|
+
<%# end %>
|
102
|
+
<!-- </div>-->
|
103
|
+
<%# else %>
|
104
|
+
<!-- <div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4" role="alert">-->
|
105
|
+
<!-- <p class="font-bold">No origins configured</p>-->
|
106
|
+
<!-- </div>-->
|
107
|
+
<%# end %>
|
108
|
+
</div>
|
109
|
+
|
110
|
+
<!-- Methods -->
|
111
|
+
<div class="mb-4">
|
112
|
+
<h3 class="text-md font-semibold mb-2">Allowed Methods</h3>
|
113
|
+
<% if config[:methods] == :any %>
|
114
|
+
<span class="inline-block bg-blue-100 text-blue-800 text-sm font-semibold px-2.5 py-0.5 rounded">ANY</span>
|
115
|
+
<% elsif config[:methods].any? %>
|
116
|
+
<div class="flex flex-wrap gap-2">
|
117
|
+
<% config[:methods].each do |method| %>
|
118
|
+
<span class="inline-block bg-red-500 text-white text-sm font-semibold px-2.5 py-0.5 rounded">
|
119
|
+
<%= method.upcase %>
|
120
|
+
</span>
|
121
|
+
<% end %>
|
122
|
+
</div>
|
123
|
+
<% else %>
|
124
|
+
<div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4" role="alert">
|
125
|
+
<p class="font-bold">No methods configured</p>
|
126
|
+
</div>
|
127
|
+
<% end %>
|
128
|
+
</div>
|
129
|
+
|
130
|
+
<!-- Headers -->
|
131
|
+
<div class="mb-4">
|
132
|
+
<h3 class="text-md font-semibold mb-2">Allowed Headers</h3>
|
133
|
+
<% if config[:headers] == :any %>
|
134
|
+
<span class="inline-block bg-blue-100 text-blue-800 text-sm font-semibold px-2.5 py-0.5 rounded">ANY</span>
|
135
|
+
<% elsif config[:headers].any? %>
|
136
|
+
<div class="bg-gray-50 p-3 rounded-lg">
|
137
|
+
<% config[:headers].each do |header| %>
|
138
|
+
<div class="text-sm text-gray-700"><code><%= header %></code></div>
|
139
|
+
<% end %>
|
140
|
+
</div>
|
141
|
+
<% else %>
|
142
|
+
<div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4" role="alert">
|
143
|
+
<p class="font-bold">No headers configured</p>
|
144
|
+
</div>
|
145
|
+
<% end %>
|
146
|
+
</div>
|
147
|
+
|
148
|
+
<!-- Exposed Headers -->
|
149
|
+
<div class="mb-4">
|
150
|
+
<h3 class="text-md font-semibold mb-2">Exposed Headers</h3>
|
151
|
+
<% if config[:expose] == :any %>
|
152
|
+
<span class="inline-block bg-blue-100 text-blue-800 text-sm font-semibold px-2.5 py-0.5 rounded">ANY</span>
|
153
|
+
<% elsif config[:expose].any? %>
|
154
|
+
<div class="bg-gray-50 p-3 rounded-lg">
|
155
|
+
<% config[:expose].each do |header| %>
|
156
|
+
<div class="text-sm text-gray-700"><code><%= header %></code></div>
|
157
|
+
<% end %>
|
158
|
+
</div>
|
159
|
+
<% else %>
|
160
|
+
<div class="bg-yellow-100 border-l-4 border-yellow-500 text-yellow-700 p-4" role="alert">
|
161
|
+
<p class="font-bold">No headers exposed</p>
|
162
|
+
</div>
|
163
|
+
<% end %>
|
164
|
+
</div>
|
165
|
+
|
166
|
+
<!-- Additional Configuration -->
|
167
|
+
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
168
|
+
<!-- Max Age -->
|
169
|
+
<div>
|
170
|
+
<h3 class="text-md font-semibold mb-2">Max Age</h3>
|
171
|
+
<div class="bg-gray-50 p-3 rounded-lg">
|
172
|
+
<div class="text-sm text-gray-700">
|
173
|
+
<%= config[:max_age] || "Not set" %>
|
174
|
+
</div>
|
175
|
+
</div>
|
176
|
+
</div>
|
177
|
+
|
178
|
+
<!-- Credentials -->
|
179
|
+
<div>
|
180
|
+
<h3 class="text-md font-semibold mb-2">Credentials</h3>
|
181
|
+
<div class="bg-gray-50 p-3 rounded-lg">
|
182
|
+
<div class="text-sm text-gray-700">
|
183
|
+
<%= config[:credentials] ? "Allowed" : "Not allowed" %>
|
184
|
+
</div>
|
185
|
+
</div>
|
186
|
+
</div>
|
187
|
+
|
188
|
+
<!-- Public Resource -->
|
189
|
+
<div>
|
190
|
+
<h3 class="text-md font-semibold mb-2">Public Resource</h3>
|
191
|
+
<div class="bg-gray-50 p-3 rounded-lg">
|
192
|
+
<div class="text-sm text-gray-700">
|
193
|
+
<%= config[:public] ? "Yes" : "No" %>
|
194
|
+
</div>
|
195
|
+
</div>
|
196
|
+
</div>
|
197
|
+
|
198
|
+
<!-- Conditional Logic -->
|
199
|
+
<div>
|
200
|
+
<h3 class="text-md font-semibold mb-2">Condition</h3>
|
201
|
+
<div class="bg-gray-50 p-3 rounded-lg">
|
202
|
+
<div class="text-sm text-gray-700">
|
203
|
+
<%= config[:if_condition] %>
|
204
|
+
</div>
|
205
|
+
</div>
|
206
|
+
</div>
|
207
|
+
</div>
|
208
|
+
</div>
|
209
|
+
</div>
|
210
|
+
<% end %>
|
211
|
+
</div>
|
212
|
+
<% end %>
|
213
|
+
</div>
|
214
|
+
|
215
|
+
|
216
|
+
<br>
|
217
|
+
<br>
|
218
|
+
<br>
|
219
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<div class="cors-content">
|
2
|
+
<h1 class="text-2xl font-bold mb-4">CORS in Ruby on Rails</h1>
|
3
|
+
<p class="text-gray-700 mb-4">
|
4
|
+
Cross-Origin Resource Sharing (CORS) is a security feature that restricts cross-origin HTTP requests.
|
5
|
+
In Rails, you can configure CORS using the <code>rack-cors</code> gem to define allowed origins, methods, and headers.
|
6
|
+
</p>
|
7
|
+
<div class="bg-blue-100 p-4 rounded-lg">
|
8
|
+
<h2 class="text-xl font-semibold mb-2">Key Configuration:</h2>
|
9
|
+
<ul class="list-disc list-inside">
|
10
|
+
<li>Origins: Specify domains allowed to access your API</li>
|
11
|
+
<li>Methods: Define permitted HTTP methods (GET, POST, etc.)</li>
|
12
|
+
<li>Headers: Control which headers are allowed</li>
|
13
|
+
</ul>
|
14
|
+
</div>
|
15
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
<div class="container mx-auto p-4">
|
4
|
+
<h1 class="text-3xl font-bold text-red-500 mb-4">About Cors UI</h1>
|
5
|
+
<p class="text-gray-700 leading-relaxed">
|
6
|
+
This engine was created to simplify CORS configuration management in Ruby on Rails applications.
|
7
|
+
It provides an intuitive interface for developers to view and update CORS settings.
|
8
|
+
<br>
|
9
|
+
<br>
|
10
|
+
<a href="https://github.com/andresyebra/cors-ui/"
|
11
|
+
class="text-blue-600 hover:text-blue-800 underline"
|
12
|
+
target="_blank">
|
13
|
+
Contribute Here!!
|
14
|
+
</a>
|
15
|
+
</p>
|
16
|
+
|
17
|
+
</div>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
<div class="container mx-auto p-4">
|
2
|
+
<h1 class="text-3xl font-bold text-red-500 mb-4">CORS in Ruby on Rails</h1>
|
3
|
+
<p class="text-gray-700 leading-relaxed">
|
4
|
+
Cross-Origin Resource Sharing (CORS) is a security feature that restricts cross-origin HTTP requests.
|
5
|
+
In Rails, you can configure CORS using the <code class="bg-gray-100 px-1 py-0.5 rounded">rack-cors</code> gem
|
6
|
+
to define allowed origins, methods, and headers.
|
7
|
+
</p>
|
8
|
+
|
9
|
+
<!-- Key Features Section -->
|
10
|
+
<div class="mt-6 p-5 bg-blue-50 border-l-4 border-blue-500 rounded-lg">
|
11
|
+
<h2 class="text-xl font-semibold text-blue-800 mb-2">Key Configuration:</h2>
|
12
|
+
<ul class="list-disc list-inside text-gray-700">
|
13
|
+
<li><span class="font-medium">Origins:</span> Specify domains allowed to access your API</li>
|
14
|
+
<li><span class="font-medium">Methods:</span> Define permitted HTTP methods (GET, POST, etc.)</li>
|
15
|
+
<li><span class="font-medium">Headers:</span> Control which headers are allowed</li>
|
16
|
+
</ul>
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<!-- CORS Security Warning -->
|
20
|
+
<div class="mt-6 p-5 bg-red-50 border-l-4 border-red-500 rounded-lg text-red-800">
|
21
|
+
<div class="flex items-start">
|
22
|
+
<svg class="w-5 h-5 text-red-600 mt-1.5 mr-2" xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 20 20">
|
23
|
+
<path d="M10 .5a9.5 9.5 0 1 0 9.5 9.5A9.51 9.51 0 0 0 10 .5ZM9.5 4a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3ZM12 15H8a1 1 0 0 1 0-2h1v-3H8a1 1 0 0 1 0-2h2a1 1 0 0 1 1 1v4h1a1 1 0 0 1 0 2Z"/>
|
24
|
+
</svg>
|
25
|
+
<div>
|
26
|
+
<h3 class="font-medium">Important CORS Security Considerations:</h3>
|
27
|
+
<ul class="mt-2 list-disc list-inside text-sm">
|
28
|
+
<li>Avoid using wildcard (*) origins in production</li>
|
29
|
+
<li>Limit allowed HTTP methods to only what's necessary</li>
|
30
|
+
<li>Always specify explicit headers instead of using wildcards</li>
|
31
|
+
<li>Set appropriate max-age for preflight responses</li>
|
32
|
+
<li>Only enable credentials when absolutely necessary</li>
|
33
|
+
</ul>
|
34
|
+
</div>
|
35
|
+
</div>
|
36
|
+
</div>
|
37
|
+
</div>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<footer class="fixed bottom-0 left-0 z-20 w-full p-4 bg-white border-t border-gray-200 shadow-sm md:flex md:items-center md:justify-between md:p-6 dark:bg-gray-800 dark:border-gray-600">
|
2
|
+
<span class="text-sm text-gray-500 sm:text-center dark:text-gray-400"><%= Date.today.year %>
|
3
|
+
<a href="https://github.com/andresyebra/cors-ui/" class="hover:underline">Cors UI</a>
|
4
|
+
</span>
|
5
|
+
<ul class="flex flex-wrap items-center mt-3 text-sm font-medium text-gray-500 dark:text-gray-400 sm:mt-0">
|
6
|
+
<li>
|
7
|
+
<a href="https://github.com/andresyebra/cors-ui/" class="hover:underline">GitHub</a>
|
8
|
+
</li>
|
9
|
+
</ul>
|
10
|
+
</footer>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<nav class="border-gray-200 bg-gray-50 dark:bg-gray-800 dark:border-gray-700">
|
2
|
+
<div class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4">
|
3
|
+
<a href="<%= root_path %>" class="flex items-center space-x-3 rtl:space-x-reverse">
|
4
|
+
<%= image_tag "cors/ui/braket-cors.svg", class: "h-12", alt: "Cors UI" %>
|
5
|
+
</a>
|
6
|
+
<button data-collapse-toggle="navbar-solid-bg" type="button" class="inline-flex items-center p-2 w-10 h-10 justify-center text-sm text-gray-500 rounded-lg md:hidden hover:bg-gray-100 focus:outline-none focus:ring-2 focus:ring-gray-200 dark:text-gray-400 dark:hover:bg-gray-700 dark:focus:ring-gray-600" aria-controls="navbar-solid-bg" aria-expanded="false">
|
7
|
+
<span class="sr-only">Open main menu</span>
|
8
|
+
<svg class="w-5 h-5" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 17 14">
|
9
|
+
<path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M1 1h15M1 7h15M1 13h15"/>
|
10
|
+
</svg>
|
11
|
+
</button>
|
12
|
+
<div class="hidden w-full md:block md:w-auto" id="navbar-solid-bg">
|
13
|
+
<ul class="flex flex-col font-medium mt-4 rounded-lg bg-gray-50 md:space-x-8 rtl:space-x-reverse md:flex-row md:mt-0 md:border-0 md:bg-transparent dark:bg-gray-800 md:dark:bg-transparent dark:border-gray-700">
|
14
|
+
<li>
|
15
|
+
<%= link_to root_path, class: "block py-2 px-3 md:p-0 #{current_page?(root_path) ? 'text-white bg-blue-700 rounded md:bg-transparent md:text-blue-700 dark:text-white' : 'text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent'}" do %>
|
16
|
+
Home
|
17
|
+
<% end %>
|
18
|
+
</li>
|
19
|
+
<li>
|
20
|
+
<%= link_to cors_ui.dashboard_path, class: "block py-2 px-3 md:p-0 #{current_page?(cors_ui.dashboard_path) ? 'text-white bg-blue-700 rounded md:bg-transparent md:text-blue-700 dark:text-white' : 'text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent'}" do %>
|
21
|
+
Dashboard
|
22
|
+
<% end %>
|
23
|
+
</li>
|
24
|
+
<li>
|
25
|
+
<%= link_to cors_ui.about_path, class: "block py-2 px-3 md:p-0 #{current_page?(cors_ui.about_path) ? 'text-white bg-blue-700 rounded md:bg-transparent md:text-blue-700 dark:text-white' : 'text-gray-900 rounded hover:bg-gray-100 md:hover:bg-transparent md:border-0 md:hover:text-blue-700 dark:text-white md:dark:hover:text-blue-500 dark:hover:bg-gray-700 dark:hover:text-white md:dark:hover:bg-transparent'}" do %>
|
26
|
+
About
|
27
|
+
<% end %>
|
28
|
+
</li>
|
29
|
+
</ul>
|
30
|
+
</div>
|
31
|
+
</div>
|
32
|
+
</nav>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Cors::Ui</title>
|
5
|
+
<%= csrf_meta_tags %>
|
6
|
+
<%= csp_meta_tag %>
|
7
|
+
<%= stylesheet_link_tag "cors/ui/application", media: "all" %>
|
8
|
+
<%= stylesheet_link_tag "cors/ui/tailwind", media: "all" %>
|
9
|
+
</head>
|
10
|
+
<body>
|
11
|
+
<%= render "layouts/cors/ui/navbar" %>
|
12
|
+
|
13
|
+
<div class="container mx-auto p-4">
|
14
|
+
<%= yield %>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<%= render "layouts/cors/ui/footer" %>
|
18
|
+
</body>
|
19
|
+
</html>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
module Cors
|
2
|
+
module Ui
|
3
|
+
module CorsConfigReader
|
4
|
+
def self.fetch_all_resources
|
5
|
+
cors_middleware = Rails.application.config.middleware.detect do |m|
|
6
|
+
m.klass == Rack::Cors
|
7
|
+
end
|
8
|
+
|
9
|
+
return [] unless cors_middleware
|
10
|
+
|
11
|
+
middleware_instance = cors_middleware.build(Rails.application)
|
12
|
+
all_resources_blocks = middleware_instance.instance_variable_get(:@all_resources)
|
13
|
+
|
14
|
+
configs = []
|
15
|
+
|
16
|
+
all_resources_blocks.each do |resources_block|
|
17
|
+
# Extract common settings from the allow block
|
18
|
+
origins = resources_block.instance_variable_get(:@origins)
|
19
|
+
public_resources = resources_block.instance_variable_get(:@public_resources)
|
20
|
+
resources_block.instance_variable_get(:@resources).each do |resource|
|
21
|
+
# byebug
|
22
|
+
configs << {
|
23
|
+
origins: process_origins(origins),
|
24
|
+
path: resource.instance_variable_get(:@path),
|
25
|
+
methods: process_value(resource.instance_variable_get(:@methods)),
|
26
|
+
headers: process_value(resource.instance_variable_get(:@headers)),
|
27
|
+
expose: process_value(resource.instance_variable_get(:@expose)).present? ? process_value(resource.instance_variable_get(:@expose)) : "None",
|
28
|
+
max_age: resource.instance_variable_get(:@max_age),
|
29
|
+
credentials: resource.instance_variable_get(:@credentials),
|
30
|
+
if_condition: resource.instance_variable_get(:@if_proc).present? ? "Custom Condition" : "None",
|
31
|
+
public: public_resources || resource.instance_variable_get(:@public_resource)
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
configs
|
37
|
+
rescue => e
|
38
|
+
Rails.logger.error "Error fetching CORS config: #{e.message}"
|
39
|
+
[]
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def self.process_value(value)
|
45
|
+
case value
|
46
|
+
when :any then :any
|
47
|
+
when Array then value.map(&:to_s)
|
48
|
+
else [value.to_s]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.process_origins(origins)
|
53
|
+
case origins
|
54
|
+
when Array then origins.map { |o| o.is_a?(Regexp) ? o.inspect : o }
|
55
|
+
when String then [origins]
|
56
|
+
else [origins.to_s]
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/cors/ui.rb
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cors-ui
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andres Yebra
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 7.0.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 7.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rack-cors
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
description: A simple UI for controlling the CORS settings that ship with Rack CORS
|
42
|
+
Middleware.
|
43
|
+
email:
|
44
|
+
- andres.yebracervantes@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- MIT-LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- app/assets/images/cors/ui/braket-cors.svg
|
53
|
+
- app/assets/images/cors/ui/flat-cors.svg
|
54
|
+
- app/assets/stylesheets/cors/ui/application.css
|
55
|
+
- app/assets/stylesheets/cors/ui/tailwind.css
|
56
|
+
- app/controllers/cors/ui/application_controller.rb
|
57
|
+
- app/controllers/cors/ui/dashboard_controller.rb
|
58
|
+
- app/controllers/cors/ui/home_controller.rb
|
59
|
+
- app/controllers/cors/ui/pages_controller.rb
|
60
|
+
- app/helpers/cors/ui/application_helper.rb
|
61
|
+
- app/jobs/cors/ui/application_job.rb
|
62
|
+
- app/mailers/cors/ui/application_mailer.rb
|
63
|
+
- app/models/cors/ui/application_record.rb
|
64
|
+
- app/views/cors/ui/dashboard/index.html.erb
|
65
|
+
- app/views/cors/ui/home/index.html.erb
|
66
|
+
- app/views/cors/ui/pages/about.html.erb
|
67
|
+
- app/views/cors/ui/pages/index.html.erb
|
68
|
+
- app/views/layouts/cors/ui/_footer.html.erb
|
69
|
+
- app/views/layouts/cors/ui/_navbar.html.erb
|
70
|
+
- app/views/layouts/cors/ui/application.html.erb
|
71
|
+
- config/routes.rb
|
72
|
+
- lib/cors/ui.rb
|
73
|
+
- lib/cors/ui/cors_config_reader.rb
|
74
|
+
- lib/cors/ui/engine.rb
|
75
|
+
- lib/cors/ui/version.rb
|
76
|
+
- lib/tasks/cors/ui_tasks.rake
|
77
|
+
homepage: https://github.com/andresyebra/cors-ui
|
78
|
+
licenses:
|
79
|
+
- MIT
|
80
|
+
metadata:
|
81
|
+
allowed_push_host: https://rubygems.org
|
82
|
+
homepage_uri: https://github.com/andresyebra/cors-ui
|
83
|
+
source_code_uri: https://github.com/andresyebra/cors-ui
|
84
|
+
changelog_uri: https://github.com/andresyebra/cors-ui/CHANGELOG.md
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
requirements: []
|
100
|
+
rubygems_version: 3.4.1
|
101
|
+
signing_key:
|
102
|
+
specification_version: 4
|
103
|
+
summary: A simple UI for controlling the CORS.
|
104
|
+
test_files: []
|