Permalink
Browse files

Fix build

  • Loading branch information...
1 parent 632d47a commit 2f1e81269c34a41f7fdcd6e51c88ead7ad88d04e Evan Miller committed Jul 16, 2011
View
@@ -1,11 +1,12 @@
ERL=erl
+APP=cb_admin
all:
- $(ERL) -pa /Users/emiller/src/ChicagoBoss/ebin -eval 'boss_load:load_all_modules_and_emit_app_file("ebin", chicagoboss_admin)' -s init stop -noshell
+ $(ERL) -pa /Users/emiller/src/ChicagoBoss/ebin -eval 'boss_load:load_all_modules_and_emit_app_file($(APP), "ebin")' -s init stop -noshell
clean:
rm -fv ebin/*.beam
- rm -fv ebin/chicagoboss_admin.app
+ rm -fv ebin/$(APP).app
update_po:
$(ERL) -pa ebin -pa ../ChicagoBoss/ebin -eval 'boss_load:load_models("ebin")' -eval 'boss_lang:update_po()' -s init stop -noshell
View
@@ -1,5 +1,5 @@
[{boss, [
- {applications, [{ chicagoboss_admin, "/" }]},
+ {applications, [{ cb_admin, "/" }]},
{db_host, "localhost"},
{db_port, 1978},
{db_adapter, mock},
@@ -1,4 +1,4 @@
-{application, chicagoboss_admin, [
+{application, cb_admin, [
{description, "Chicago Boss Admin Interface"},
{vsn, "0.1.0"},
{modules, []},
@@ -1,4 +1,4 @@
--module(admin_controller, [Req, SessionID]).
+-module(cb_admin_index_controller, [Req, SessionID]).
-compile(export_all).
-default_action(index).
@@ -7,14 +7,14 @@ before_("splash") ->
before_("access_denied") ->
ok;
before_(_) ->
- admin_lib:require_ip_address(Req).
+ cb_admin_lib:require_ip_address(Req).
index('GET', [], Authorization) ->
[{loaded, ModulesLoaded}, _, _, _, _, _] = application:info(),
ConfigValues = [ [{Key, Value}] || {Key, Value} <- application:get_all_env()],
SystemValues = [ {otp_release, erlang:system_info(system_version)},
{processors, erlang:system_info(logical_processors_online)},
- {uptime, admin_lib:uptime()},
+ {uptime, cb_admin_lib:uptime()},
{node, erlang:node()}
],
{ok, [ {index_section, true}, {modules_loaded, ModulesLoaded},
@@ -1,9 +1,9 @@
--module(lang_controller, [Req, SessionID]).
+-module(cb_admin_lang_controller, [Req, SessionID]).
-compile(export_all).
-default_action(show).
before_(_) ->
- admin_lib:require_ip_address(Req).
+ cb_admin_lib:require_ip_address(Req).
show('GET', [], Auth) ->
Applications = boss_web:get_all_applications(),
@@ -42,9 +42,9 @@ edit('POST', [App, Lang|Fmt], Auth) ->
"" ->
case WithBlanks of
undefined -> ok;
- _ -> admin_lib:lang_write_to_file(IODevice, Original, Translation, BlockIdentifier)
+ _ -> cb_admin_lang_lib:lang_write_to_file(IODevice, Original, Translation, BlockIdentifier)
end;
- _ -> admin_lib:lang_write_to_file(IODevice, Original, Translation, BlockIdentifier)
+ _ -> cb_admin_lang_lib:lang_write_to_file(IODevice, Original, Translation, BlockIdentifier)
end
end, Req:deep_post_param(["messages"])),
file:close(IODevice),
@@ -1,4 +1,4 @@
--module(model_controller, [Req, SessionID]).
+-module(cb_admin_model_controller, [Req, SessionID]).
-compile(export_all).
-default_action(model).
@@ -10,7 +10,7 @@ heartbeat('POST', [WatchName], Authorization) ->
watch('POST', [], Authorization) ->
TopicString = Req:post_param("topic_string"),
- {ok, WatchId} = boss_news:watch(TopicString, fun admin_lib:push_update/3, "admin"++SessionID, 60),
+ {ok, WatchId} = boss_news:watch(TopicString, fun cb_admin_lib:push_update/3, "admin"++SessionID, 60),
{json, [{watch_id, WatchId}]}.
events('GET', [Since], Authorization) ->
@@ -59,9 +59,9 @@ csv('GET', [ModelName], Authorization) ->
RecordLines = lists:map(fun(Record) ->
[lists:foldr(fun
({_Key, Val}, []) ->
- [admin_lib:encode_csv_value(Val)];
+ [cb_admin_model_lib:encode_csv_value(Val)];
({_Key, Val}, Acc) ->
- [admin_lib:encode_csv_value(Val), ","|Acc]
+ [cb_admin_model_lib:encode_csv_value(Val), ","|Acc]
end, [], Record:attributes()), "\n"]
end, Records),
{output, [FirstLine, RecordLines], [{"Content-Type", "text/csv"},
@@ -76,7 +76,7 @@ upload('POST', [ModelName], Authorization) ->
DummyRecord = boss_record_lib:dummy_record(Module),
[{uploaded_file, FileName, Location, Length}] = Req:post_files(),
{ok, FileBytes} = file:read_file(Location),
- [Head|Rest] = admin_lib:parse_csv(FileBytes),
+ [Head|Rest] = cb_admin_model_lib:parse_csv(FileBytes),
RecordsToSave = lists:map(fun(Line) ->
{_, Record} = lists:foldl(fun(Val, {Counter, Acc}) ->
AttrName = lists:nth(Counter, Head),
@@ -1,9 +1,9 @@
--module(routes_controller, [Req, SessionID]).
+-module(cb_admin_routes_controller, [Req, SessionID]).
-compile(export_all).
-default_action(index).
before_(_) ->
- admin_lib:require_ip_address(Req).
+ cb_admin_lib:require_ip_address(Req).
index('GET', [], Authorization) ->
{ok, [ {routes_section, true}, {all_routes, boss_web:get_all_routes()} ]}.
@@ -1,4 +1,4 @@
--module(upgrade_controller, [Req, SessionID]).
+-module(cb_admin_upgrade_controller, [Req, SessionID]).
-compile(export_all).
-default_action(upgrade).
View
@@ -1,115 +0,0 @@
--module(admin_lib).
-
--export([push_update/3, uptime/0, mask_ipv4_address/2, encode_csv_value/1, parse_csv/1]).
--export([require_ip_address/1, lang_write_to_file/4]).
-
-push_update(updated, {Record, Attr, OldVal, NewVal}, Channel) ->
- boss_mq:push(Channel, [{ev, updated}, {data, [{id, Record:id()}, {attr, Attr}, {val, NewVal}]}]).
-
-uptime() ->
- {UpTime, _} = erlang:statistics(wall_clock),
- {D, {H, M, S}} = calendar:seconds_to_daystime(UpTime div 1000),
- lists:flatten(io_lib:format("~p days, ~p hours, ~p minutes and ~p seconds", [D,H,M,S])).
-
-mask_ipv4_address({I1, I2, I3, I4}, MaskInt) ->
- ((I1 bsl 24 + I2 bsl 16 + I3 bsl 8 + I4) band ((1 bsl 32) - (1 bsl (32 - MaskInt)))).
-
-encode_csv_value(Val) when is_binary(Val) ->
- encode_csv_value(binary_to_list(Val));
-encode_csv_value(Val) when is_atom(Val) ->
- encode_csv_value(atom_to_list(Val));
-encode_csv_value({_, _, _} = Val) ->
- encode_csv_value(erlydtl_filters:date(calendar:now_to_datetime(Val), "F d, Y H:i:s"));
-encode_csv_value({{_, _, _}, {_, _, _}} = Val) ->
- encode_csv_value(erlydtl_filters:date(Val, "F d, Y H:i:s"));
-encode_csv_value(Val) ->
- encode_csv_value(Val, []).
-
-encode_csv_value([], Acc) ->
- [$"|lists:reverse([$"|Acc])];
-encode_csv_value([$"|T], Acc) ->
- encode_csv_value(T, [$", $" | Acc]);
-encode_csv_value([H|T], Acc) ->
- encode_csv_value(T, [H|Acc]).
-
-
-% Taken from http://blog.vmoroz.com/2011/01/csv-in-erlang.html
-parse_csv(Data) when is_binary(Data) -> parse_csv(binary_to_list(Data));
-parse_csv(Data) -> parse(Data, [], [], []).
-
-parse([$\r|Data], Field, Fields, Lines) -> parse_r(Data, Field, Fields, Lines);
-parse([$\n|Data], Field, Fields, Lines) -> parse(Data, [], [], [[Field|Fields]|Lines]);
-parse([$,|Data], Field, Fields, Lines) -> parse(Data, [], [Field|Fields], Lines);
-parse([$"|Data], [], Fields, Lines) -> parse_q(Data, [], Fields, Lines);
-parse([C|Data], Field, Fields, Lines) -> parse(Data, [C|Field], Fields, Lines);
-parse([], [], [], Lines) -> lists:reverse(
- [lists:reverse(
- [lists:reverse(F) || F <- L]
- ) || L <- Lines]
- );
-parse([], Field, Fields, Lines) -> parse([], [], [], [[Field|Fields]|Lines]).
-
-parse_r([$\n|_] = Data, Field, Fields, Lines) -> parse(Data, Field, Fields, Lines).
-
-parse_q([$"|Data], Field, Fields, Lines) -> parse_qq(Data, Field, Fields, Lines);
-parse_q([C|Data], Field, Fields, Lines) -> parse_q(Data, [C|Field], Fields, Lines).
-
-parse_qq([$"|Data], Field, Fields, Lines) -> parse_q(Data, [$"|Field], Fields, Lines);
-parse_qq([C|_] = Data, Field, Fields, Lines)
- when C == $,; C == $\r; C == $\n -> parse(Data, Field, Fields, Lines);
-parse_qq([], Field, Fields, Lines) -> parse([], Field, Fields, Lines).
-
-require_ip_address(Req) ->
- ClientIp = case Req:header(x_forwarded_for) of
- undefined -> Req:peer_ip();
- IP -> IP
- end,
- Authorized = lists:foldr(fun
- (IPBlock, false) ->
- case string:tokens(IPBlock, "/") of
- [IPAddress] ->
- IPAddress =:= string:join(lists:map(fun erlang:integer_to_list/1,
- tuple_to_list(ClientIp)), ".");
- [IPAddress, Mask] ->
- MaskInt = list_to_integer(Mask),
- IPAddressTuple = list_to_tuple(lists:map(fun erlang:list_to_integer/1, string:tokens(IPAddress, "."))),
- admin_lib:mask_ipv4_address(ClientIp, MaskInt) =:= admin_lib:mask_ipv4_address(IPAddressTuple, MaskInt)
- end;
- (_, true) ->
- true
- end, false, boss_env:get_env(admin_ip_blocks, ["192.168.0.0/16", "127.0.0.1", "10.0.0.0/16"])),
- case Authorized of
- true ->
- {ok, local};
- _ ->
- {redirect, [{controller, "admin"}, {action, "access_denied"}]}
- end.
-
-lang_write_to_file(IODevice, Original, Translation, BlockIdentifier) ->
- OriginalEncoded = unicode:characters_to_list(boss_lang:escape_quotes(Original)),
- TranslationEncoded = unicode:characters_to_list(boss_lang:escape_quotes(Translation)),
- case BlockIdentifier of
- undefined ->
- file:write(IODevice, io_lib:format("\nmsgid \"~ts\"\n",[list_to_binary(OriginalEncoded)])),
- file:write(IODevice, io_lib:format("\msgstr \"~ts\"\n",[list_to_binary(TranslationEncoded)]));
- Identifier ->
- file:write(IODevice, io_lib:format("\n#. ~ts\n",[list_to_binary(Identifier)])),
- file:write(IODevice, io_lib:format("msgid \"~s\"\n", [""])),
- {ok, OriginalTokens} = regexp:split(OriginalEncoded,"\r\n"),
- lang_write_multiline_to_file(IODevice, OriginalTokens),
- file:write(IODevice, io_lib:format("\msgstr \"~s\"\n", [""])),
- {ok, TranslationTokens} = regexp:split(TranslationEncoded,"\r\n"),
- lang_write_multiline_to_file(IODevice, TranslationTokens)
- end.
-
-lang_write_multiline_to_file(IODevice, []) -> ok;
-lang_write_multiline_to_file(IODevice, [Token|Rest]) ->
- ParsedToken = case Token of
- [] -> "";
- _ -> Token
- end,
- case Rest of
- [] -> file:write(IODevice, io_lib:format("\"~ts\"\n", [list_to_binary(ParsedToken)]));
- _ -> file:write(IODevice, io_lib:format("\"~ts~c~c\"\n", [list_to_binary(ParsedToken), 92, 110]))
- end,
- lang_write_multiline_to_file(IODevice, Rest).
@@ -0,0 +1,31 @@
+-module(cb_admin_lang_lib).
+-export([lang_write_to_file/4]).
+
+lang_write_to_file(IODevice, Original, Translation, BlockIdentifier) ->
+ OriginalEncoded = unicode:characters_to_list(boss_lang:escape_quotes(Original)),
+ TranslationEncoded = unicode:characters_to_list(boss_lang:escape_quotes(Translation)),
+ case BlockIdentifier of
+ undefined ->
+ file:write(IODevice, io_lib:format("\nmsgid \"~ts\"\n",[list_to_binary(OriginalEncoded)])),
+ file:write(IODevice, io_lib:format("\msgstr \"~ts\"\n",[list_to_binary(TranslationEncoded)]));
+ Identifier ->
+ file:write(IODevice, io_lib:format("\n#. ~ts\n",[list_to_binary(Identifier)])),
+ file:write(IODevice, io_lib:format("msgid \"~s\"\n", [""])),
+ {ok, OriginalTokens} = regexp:split(OriginalEncoded,"\r\n"),
+ lang_write_multiline_to_file(IODevice, OriginalTokens),
+ file:write(IODevice, io_lib:format("\msgstr \"~s\"\n", [""])),
+ {ok, TranslationTokens} = regexp:split(TranslationEncoded,"\r\n"),
+ lang_write_multiline_to_file(IODevice, TranslationTokens)
+ end.
+
+lang_write_multiline_to_file(IODevice, []) -> ok;
+lang_write_multiline_to_file(IODevice, [Token|Rest]) ->
+ ParsedToken = case Token of
+ [] -> "";
+ _ -> Token
+ end,
+ case Rest of
+ [] -> file:write(IODevice, io_lib:format("\"~ts\"\n", [list_to_binary(ParsedToken)]));
+ _ -> file:write(IODevice, io_lib:format("\"~ts~c~c\"\n", [list_to_binary(ParsedToken), 92, 110]))
+ end,
+ lang_write_multiline_to_file(IODevice, Rest).
View
@@ -0,0 +1,40 @@
+-module(cb_admin_lib).
+
+-export([push_update/3, uptime/0, mask_ipv4_address/2, require_ip_address/1]).
+
+push_update(updated, {Record, Attr, OldVal, NewVal}, Channel) ->
+ boss_mq:push(Channel, [{ev, updated}, {data, [{id, Record:id()}, {attr, Attr}, {val, NewVal}]}]).
+
+uptime() ->
+ {UpTime, _} = erlang:statistics(wall_clock),
+ {D, {H, M, S}} = calendar:seconds_to_daystime(UpTime div 1000),
+ lists:flatten(io_lib:format("~p days, ~p hours, ~p minutes and ~p seconds", [D,H,M,S])).
+
+mask_ipv4_address({I1, I2, I3, I4}, MaskInt) ->
+ ((I1 bsl 24 + I2 bsl 16 + I3 bsl 8 + I4) band ((1 bsl 32) - (1 bsl (32 - MaskInt)))).
+
+require_ip_address(Req) ->
+ ClientIp = case Req:header(x_forwarded_for) of
+ undefined -> Req:peer_ip();
+ IP -> IP
+ end,
+ Authorized = lists:foldr(fun
+ (IPBlock, false) ->
+ case string:tokens(IPBlock, "/") of
+ [IPAddress] ->
+ IPAddress =:= string:join(lists:map(fun erlang:integer_to_list/1,
+ tuple_to_list(ClientIp)), ".");
+ [IPAddress, Mask] ->
+ MaskInt = list_to_integer(Mask),
+ IPAddressTuple = list_to_tuple(lists:map(fun erlang:list_to_integer/1, string:tokens(IPAddress, "."))),
+ admin_lib:mask_ipv4_address(ClientIp, MaskInt) =:= admin_lib:mask_ipv4_address(IPAddressTuple, MaskInt)
+ end;
+ (_, true) ->
+ true
+ end, false, boss_env:get_env(admin_ip_blocks, ["192.168.0.0/16", "127.0.0.1", "10.0.0.0/16"])),
+ case Authorized of
+ true ->
+ {ok, local};
+ _ ->
+ {redirect, [{controller, "admin"}, {action, "access_denied"}]}
+ end.
@@ -0,0 +1,48 @@
+-module(cb_admin_model_lib).
+-export([encode_csv_value/1, parse_csv/1]).
+
+encode_csv_value(Val) when is_binary(Val) ->
+ encode_csv_value(binary_to_list(Val));
+encode_csv_value(Val) when is_atom(Val) ->
+ encode_csv_value(atom_to_list(Val));
+encode_csv_value({_, _, _} = Val) ->
+ encode_csv_value(erlydtl_filters:date(calendar:now_to_datetime(Val), "F d, Y H:i:s"));
+encode_csv_value({{_, _, _}, {_, _, _}} = Val) ->
+ encode_csv_value(erlydtl_filters:date(Val, "F d, Y H:i:s"));
+encode_csv_value(Val) ->
+ encode_csv_value(Val, []).
+
+encode_csv_value([], Acc) ->
+ [$"|lists:reverse([$"|Acc])];
+encode_csv_value([$"|T], Acc) ->
+ encode_csv_value(T, [$", $" | Acc]);
+encode_csv_value([H|T], Acc) ->
+ encode_csv_value(T, [H|Acc]).
+
+
+% Taken from http://blog.vmoroz.com/2011/01/csv-in-erlang.html
+parse_csv(Data) when is_binary(Data) -> parse_csv(binary_to_list(Data));
+parse_csv(Data) -> parse(Data, [], [], []).
+
+parse([$\r|Data], Field, Fields, Lines) -> parse_r(Data, Field, Fields, Lines);
+parse([$\n|Data], Field, Fields, Lines) -> parse(Data, [], [], [[Field|Fields]|Lines]);
+parse([$,|Data], Field, Fields, Lines) -> parse(Data, [], [Field|Fields], Lines);
+parse([$"|Data], [], Fields, Lines) -> parse_q(Data, [], Fields, Lines);
+parse([C|Data], Field, Fields, Lines) -> parse(Data, [C|Field], Fields, Lines);
+parse([], [], [], Lines) -> lists:reverse(
+ [lists:reverse(
+ [lists:reverse(F) || F <- L]
+ ) || L <- Lines]
+ );
+parse([], Field, Fields, Lines) -> parse([], [], [], [[Field|Fields]|Lines]).
+
+parse_r([$\n|_] = Data, Field, Fields, Lines) -> parse(Data, Field, Fields, Lines).
+
+parse_q([$"|Data], Field, Fields, Lines) -> parse_qq(Data, Field, Fields, Lines);
+parse_q([C|Data], Field, Fields, Lines) -> parse_q(Data, [C|Field], Fields, Lines).
+
+parse_qq([$"|Data], Field, Fields, Lines) -> parse_q(Data, [$"|Field], Fields, Lines);
+parse_qq([C|_] = Data, Field, Fields, Lines)
+ when C == $,; C == $\r; C == $\n -> parse(Data, Field, Fields, Lines);
+parse_qq([], Field, Fields, Lines) -> parse([], Field, Fields, Lines).
+
@@ -1,4 +1,4 @@
--module(incoming_mail_controller).
+-module(cb_admin_incoming_mail_controller).
-compile(export_all).
authorize_(User, DomainName, IPAddress) ->
@@ -1,4 +1,4 @@
--module(outgoing_mail_controller).
+-module(cb_admin_outgoing_mail_controller).
-compile(export_all).
%% See http://www.chicagoboss.org/api-mail-controller.html for what should go in here
View
@@ -3,6 +3,6 @@ cd `dirname $0`
exec erl -pa $PWD/ebin \
-pa /Users/emiller/src/ChicagoBoss/ebin \
-pa /Users/emiller/src/ChicagoBoss/deps/*/ebin \
- -boss developing_app chicagoboss_admin \
+ -boss developing_app cb_admin \
-boot start_sasl -config boss -s reloader -s boss \
-sname wildbill

0 comments on commit 2f1e812

Please sign in to comment.