Commit 040cc6e2 authored by Cool Fire's avatar Cool Fire

Finished hashdb search interface

parent d4f498f2
Pipeline #1915 passed with stages
in 4 minutes
......@@ -88,7 +88,7 @@ ul ul {
margin-bottom: 0;
}
b,
strong {
font-weight: bolder;
}
......@@ -492,6 +492,32 @@ fieldset:disabled a.btn {
box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.5);
}
.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
.alert-primary {
color: #004085;
background-color: #cce5ff;
border-color: #b8daff;
}
.alert-success {
color: #155724;
background-color: #d4edda;
border-color: #c3e6cb;
}
.alert-danger {
color: #721c24;
background-color: #f8d7da;
border-color: #f5c6cb;
}
@-webkit-keyframes progress-bar-stripes {
from {
background-position: 1rem 0;
......@@ -686,7 +712,7 @@ ul ul {
margin-bottom: 0;
}
b,
strong {
font-weight: bolder;
}
......@@ -1101,6 +1127,32 @@ fieldset:disabled a.btn {
box-shadow: 0 0 0 0.2rem rgba(85, 115, 146, 0.5);
}
.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
.alert-primary {
color: #1d2f42;
background-color: #d7dee5;
border-color: #c7d1db;
}
.alert-success {
color: #006249;
background-color: #ccf2e8;
border-color: #b8ecdf;
}
.alert-danger {
color: #78281f;
background-color: #fadbd8;
border-color: #f8cdc8;
}
@-webkit-keyframes progress-bar-stripes {
from {
background-position: 0.625rem 0;
......@@ -1201,6 +1253,28 @@ fieldset:disabled a.btn {
background-color: #fff !important;
}
}
.alert {
border: none;
color: #fff;
}
.alert a {
color: #fff;
text-decoration: underline;
}
.alert-primary {
background-color: #375a7f;
}
.alert-success {
background-color: #00bc8c;
}
.alert-danger {
background-color: #E74C3C;
}
@font-face {
font-family: 'Lato';
font-display: swap;
......
......@@ -88,7 +88,7 @@ ul ul {
margin-bottom: 0;
}
b,
strong {
font-weight: bolder;
}
......@@ -492,6 +492,32 @@ fieldset:disabled a.btn {
box-shadow: 0 0 0 0.2rem rgba(38, 143, 255, 0.5);
}
.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
.alert-primary {
color: #004085;
background-color: #cce5ff;
border-color: #b8daff;
}
.alert-success {
color: #155724;
background-color: #d4edda;
border-color: #c3e6cb;
}
.alert-danger {
color: #721c24;
background-color: #f8d7da;
border-color: #f5c6cb;
}
@-webkit-keyframes progress-bar-stripes {
from {
background-position: 1rem 0;
......
......@@ -96,7 +96,7 @@ ul ul {
margin-bottom: 0;
}
b,
strong {
font-weight: bolder;
}
......@@ -511,6 +511,32 @@ fieldset:disabled a.btn {
box-shadow: 0 0 0 0.2rem rgba(85, 115, 146, 0.5);
}
.alert {
position: relative;
padding: 0.75rem 1.25rem;
margin-bottom: 1rem;
border: 1px solid transparent;
border-radius: 0.25rem;
}
.alert-primary {
color: #1d2f42;
background-color: #d7dee5;
border-color: #c7d1db;
}
.alert-success {
color: #006249;
background-color: #ccf2e8;
border-color: #b8ecdf;
}
.alert-danger {
color: #78281f;
background-color: #fadbd8;
border-color: #f8cdc8;
}
@-webkit-keyframes progress-bar-stripes {
from {
background-position: 0.625rem 0;
......@@ -611,3 +637,25 @@ fieldset:disabled a.btn {
background-color: #fff !important;
}
}
.alert {
border: none;
color: #fff;
}
.alert a {
color: #fff;
text-decoration: underline;
}
.alert-primary {
background-color: #375a7f;
}
.alert-success {
background-color: #00bc8c;
}
.alert-danger {
background-color: #E74C3C;
}
......@@ -3,7 +3,7 @@
# Helper class to generate common page sections
class Insomnia247Nl < Sinatra::Base
helpers do
def make_page(title, content)
def make_page(title, content, cache = true)
menu = make_menu
meta = getmeta(title)
content = erb :base, locals: {
......@@ -12,7 +12,7 @@ class Insomnia247Nl < Sinatra::Base
menu: menu,
content: content
}
cache_set(title, content)
cache_set(title, content) if cache
content
end
......
This diff is collapsed.
......@@ -7,7 +7,47 @@ class Insomnia247Nl < Sinatra::Base
page = cache_get(title)
return page unless page.nil?
content = erb :hashdb
content = erb :hashdb, locals: { message: nil }
make_page(title, content)
end
post '/hashdb' do
title = 'Hash database search'
unless params.key? 'hash'
content = erb :hashdb, locals: { message: 'No hash submitted', type: 'danger' }
return make_page(title, content, false)
end
result = check_hash(params['hash'])
content = erb :hashdb, locals: { message: result[0], type: result[1] }
make_page(title, content, false)
end
private
def check_hash(hash)
return ['No hash submitted', 'danger'] if hash.empty?
type = { 32 => 'md5', 40 => 'sha1', 64 => 'sha256' }[hash.length]
return ['Unsupported hash type', 'danger'] if type.nil?
return ['Unsupported hash type', 'danger'] if /^[0-9a-f]+$/.match(hash).nil?
search_hashdb(hash, type)
end
def search_hashdb(hash, type)
require 'net/http'
uri = URI.parse("https://hashdb.insomnia247.nl/v1/#{type}/#{hash}")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri.request_uri)
response = http.request(request)
result = JSON.parse(response.body)
return ['The hash was not found our databas.', 'primary'] unless result['found']
["Hash found!<br />Result;<br /><pre>#{result['result']}</pre>", 'success']
end
end
......@@ -5,6 +5,11 @@
<fieldset>
<div class="form-group row">
<div class="col-sm-10">
<% unless message.nil? %>
<div class="alert alert-<%= type %>">
<%= message %>
</div>
<% end %>
<input type="text" class="form-control" id="hash" name="hash">
</div>
</div>
......
This file only exists to ensure the following CSS classes are included since they are always dynamically generated
<div class="alert-danger">a</div>
<div class="alert-success">b</div>
<div class="alert-primary">c</div>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment