This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
get '/' do | |
"My first Sinatra Application!" | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<!-- Head --> | |
<head> | |
<title>Custom Parser Application</title> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> | |
<meta name="description" content="a log analysis tool"> | |
<meta charset="UTF-8"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Custom jumbotron background --> | |
<style type="text/css"> | |
.jumbotron { | |
background: url('http://i.imgur.com/h9pSRfe.png') no-repeat center center; | |
background-size: cover; | |
padding: 50px; | |
} | |
</style> | |
<!-- Index page jumbotron --> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'chartkick' | |
get '/' do | |
erb :index | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'tilt/erubis' | |
require 'chartkick' | |
require 'time' | |
class CustomLogParser | |
# CustomLogParser code... | |
end | |
parser = CustomLogParser.new(:file => 'sample.log') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="col-xs-12"> | |
<h1>Attack Timeline</h1> | |
<hr> | |
<% if @timeline %> | |
<%= timeline(@timeline, height: "1200px")%> | |
<% else %> | |
<p>No data...</p> | |
<% end %> | |
</div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="col-xs-12"> | |
<h1>Attack Timeline</h1> | |
<hr> | |
<form action='/timeline' method='post' enctype='multipart/form-data'> | |
<div class="form-group"> | |
<div class="input-group input-group-lg"> | |
<span class="input-group-addon"> | |
<i class="glyphicon glyphicon-screenshot"></i> | |
</span> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomLogParser | |
# ... previous code for CustomLogParser | |
def single_timeline(ip) | |
info = Hash.new(0) | |
@data.each do |d| | |
next unless d[:ip] == ip | |
time = d[:time].strftime("%B %m, %Y") | |
info[time] += 1 | |
end | |
info |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomLogParser | |
# ... previous code for CustomLogParser | |
def piechart | |
ip_counts = Hash.new(0) | |
@data.each { |d| ip_counts[d[:ip]] += 1 } | |
ip_counts | |
end | |
end | |
# ... previous code for app.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container"> | |
<div class="col-xs-12"> | |
<h1>A Pie made of IP Addresses</h1> | |
<hr> | |
<form action='/timeline' method='post' enctype='multipart/form-data'> | |
<div class="form-group"> | |
<div class="input-group input-group-lg"> | |
<span class="input-group-addon"> | |
<i class="glyphicon glyphicon-screenshot"></i> | |
</span> |