Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
initial commit with already working tcpflow port
- Loading branch information
0 parents
commit e513c66
Showing
18 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.beam |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
source 'http://rubygems.org' | ||
|
||
group :development, :test do | ||
gem 'guard-shell' | ||
gem 'rb-fsevent' | ||
gem 'growl' | ||
gem 'rake' | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# # -*- encoding : utf-8 -*- | ||
|
||
# automatically run the eunit tests | ||
|
||
def run_eunit_all | ||
cmd = "./rebar eunit skip_deps=true" | ||
puts "Executing #{cmd}" | ||
puts `#{cmd}` | ||
if $? == 0 | ||
Growl.notify_ok "eunit: all tests passed." | ||
else | ||
Growl.notify_error "eunit: tests failed." | ||
end | ||
end | ||
|
||
def run_eunit(app, src, suite) | ||
if File.exist?(File.join(File.dirname(__FILE__), app, 'test', "#{suite}_tests.erl")) | ||
cmd = "./rebar eunit skip_deps=true suite=#{suite}" | ||
puts "Executing #{cmd}" | ||
puts `#{cmd}` | ||
if $? == 0 | ||
Growl.notify_ok "#{suite}: eunit passed." | ||
else | ||
Growl.notify_error "#{suite}: eunit failed." | ||
end | ||
else | ||
puts "No tests for #{suite.inspect}" | ||
Growl.notify_warning "No tests for #{suite}!" | ||
end | ||
end | ||
|
||
def run_spec | ||
end | ||
|
||
guard 'shell' do | ||
watch(%r{(apps/.*?)(src|test)/([^.].*?)(_tests)?.erl}) {|m| run_eunit(m[1], m[2], m[3]) } | ||
watch(%r{apps/(.*?)/include/([^.].*).hrl}) {|m| run_eunit_all } | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -*- encoding : utf-8 -*- | ||
|
||
require 'rubygems' | ||
require 'bundler' | ||
begin | ||
Bundler.setup(:default, :development) | ||
rescue Bundler::BundlerError => e | ||
$stderr.puts e.message | ||
$stderr.puts "Run `bundle install` to install missing gems" | ||
exit e.status_code | ||
end | ||
require 'rake' |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
% {erl_opts, [warnings_as_errors, debug_info]}. | ||
{erl_opts, [debug_info]}. | ||
{require_otp_vsn, "R15"}. | ||
{deps, [ | ||
{misultin, "0.9-dev", {git, "git://github.com/ostinelli/misultin.git", {tag, "5143979e41"}}} | ||
]}. | ||
{clean_files, ["ebin/*.beam"]}. | ||
|
||
{xref_checks, [undefined_function_calls]}. |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{application, fis, | ||
[ | ||
{description, ""}, | ||
{vsn, "0.0.1"}, | ||
{registered, []}, | ||
{applications, [ | ||
kernel, | ||
stdlib, | ||
sasl | ||
]}, | ||
{mod, {fis, []}}, | ||
{env, []} | ||
]}. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-module(fis_app). | ||
|
||
-behaviour(application). | ||
|
||
%% Application callbacks | ||
-export([start/2, stop/1]). | ||
|
||
%% =================================================================== | ||
%% Application callbacks | ||
%% =================================================================== | ||
|
||
start(_StartType, _StartArgs) -> | ||
fis_sup:start_link(). | ||
|
||
stop(_State) -> | ||
ok. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
-module(fis_sup). | ||
|
||
-behaviour(supervisor). | ||
|
||
%% API functions | ||
-export([start_link/0]). | ||
|
||
%% Supervisor callbacks | ||
-export([init/1]). | ||
|
||
%% Helper macro for declaring children of supervisor | ||
-define(CHILD(I, Type), {I, {I, start_link, []}, permanent, 5000, Type, [I]}). | ||
|
||
%% =================================================================== | ||
%% API functions | ||
%% =================================================================== | ||
|
||
start_link() -> | ||
supervisor:start_link({local, ?MODULE}, ?MODULE, []). | ||
|
||
%% =================================================================== | ||
%% Supervisor callbacks | ||
%% =================================================================== | ||
|
||
init([]) -> | ||
Children = [], | ||
|
||
RestartStrategy = {one_for_one, 0, 1}, | ||
|
||
{ok, {RestartStrategy, Children}}. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
|
||
-module(fis_tcpflow). | ||
-behavior(gen_server). | ||
|
||
% Managment API | ||
-export([start/0, start_link/0, stop/0]). | ||
|
||
% gen_server callbacks | ||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, | ||
code_change/3]). | ||
|
||
% Public API | ||
-export([]). | ||
|
||
% Record which holds the Port | ||
-record(state, { port, regex }). | ||
|
||
%% =================================================================== | ||
%% Management API | ||
%% =================================================================== | ||
|
||
start() -> | ||
gen_server:start( {local, ?MODULE}, ?MODULE, [], []). | ||
|
||
start_link() -> | ||
gen_server:start_link( {local, ?MODULE}, ?MODULE, [], []). | ||
|
||
stop() -> gen_server:cast(?MODULE, stop). | ||
|
||
%% =================================================================== | ||
%% gen_server callbacks | ||
%% =================================================================== | ||
|
||
init([]) -> | ||
Cmd = "tcpflow -i en1 -c -s -b 1024 dst port 80", | ||
Port = open_port({spawn, Cmd}, [stream, use_stdio, exit_status, binary]), | ||
|
||
{ ok, Regex } = re:compile("GET\\s(.*\\.ico).+\\r\\nHost\\:\\s?(.+)\\b"), | ||
{ ok, #state{ port = Port, regex = Regex } }. | ||
|
||
handle_call( _Msg, _From, State ) -> | ||
{ reply, ok, State }. | ||
|
||
handle_cast( stop, State ) -> | ||
{ stop, normal, State }; | ||
|
||
handle_cast( _Msg, State ) -> | ||
{ noreply, normal, State }. | ||
|
||
code_change(_OldVsn, State, _Extra) -> | ||
{ ok, State }. | ||
|
||
handle_info( Info, State ) -> | ||
{_, {data, Data}} = Info, | ||
case re:run( Data, State#state.regex, [global,{capture,[1,2],list}] ) of | ||
{match, [[Path,Host]]} -> | ||
error_logger:info_msg("Host: ~p~nPath: ~p~n", [Host, Path]); | ||
_ -> ok | ||
end, | ||
{ noreply, State }. | ||
|
||
terminate( _Reason, _State ) -> | ||
whatever. | ||
|
||
%% =================================================================== | ||
%% Public API | ||
%% =================================================================== | ||
|
||
|
||
|
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{sub_dirs, ["apps/fis", "rel"]}. | ||
|
||
% {erl_opts, [warnings_as_errors, debug_info]}. | ||
{erl_opts, [debug_info]}. | ||
|
||
{require_otp_vsn, "R15"}. |
Empty file.