Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit with already working tcpflow port

  • Loading branch information...
commit e513c66cebe56d16e13c79c8648af274e1866e5d 0 parents
@hukl authored
1  .gitignore
@@ -0,0 +1 @@
+*.beam
8 Gemfile
@@ -0,0 +1,8 @@
+source 'http://rubygems.org'
+
+group :development, :test do
+ gem 'guard-shell'
+ gem 'rb-fsevent'
+ gem 'growl'
+ gem 'rake'
+end
38 Guardfile
@@ -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
12 Rakefile
@@ -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'
0  apps/fis/deps/.gitkeep
No changes.
0  apps/fis/ebin/.gitkeep
No changes.
0  apps/fis/include/.gitkeep
No changes.
0  apps/fis/priv/.gitkeep
No changes.
9 apps/fis/rebar.config
@@ -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]}.
0  apps/fis/src/.gitkeep
No changes.
13 apps/fis/src/fis.app.src
@@ -0,0 +1,13 @@
+{application, fis,
+ [
+ {description, ""},
+ {vsn, "0.0.1"},
+ {registered, []},
+ {applications, [
+ kernel,
+ stdlib,
+ sasl
+ ]},
+ {mod, {fis, []}},
+ {env, []}
+ ]}.
16 apps/fis/src/fis_app.erl
@@ -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.
31 apps/fis/src/fis_sup.erl
@@ -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}}.
70 apps/fis/src/fis_tcpflow.erl
@@ -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
+%% ===================================================================
+
+
+
0  apps/fis/test/.gitkeep
No changes.
0  deps/.gitkeep
No changes.
6 rebar.config
@@ -0,0 +1,6 @@
+{sub_dirs, ["apps/fis", "rel"]}.
+
+% {erl_opts, [warnings_as_errors, debug_info]}.
+{erl_opts, [debug_info]}.
+
+{require_otp_vsn, "R15"}.
0  rel/.gitkeep
No changes.
Please sign in to comment.
Something went wrong with that request. Please try again.