Fix mod_cron to work with ejabberd git master

This commit is contained in:
Badlop 2015-01-28 13:55:56 +01:00
parent b7a7d9ae16
commit 44f709ba38
2 changed files with 24 additions and 24 deletions

View File

@ -3,7 +3,7 @@
http://www.ejabberd.im/mod_cron http://www.ejabberd.im/mod_cron
Author: Badlop Author: Badlop
Requirements: ejabberd trunk SVN 1635 or newer Requirements: ejabberd git master
This module allows advanced ejabberd administrators to schedule commands for This module allows advanced ejabberd administrators to schedule commands for
@ -19,11 +19,12 @@ ejabberd log file.
BASIC CONFIGURATION BASIC CONFIGURATION
=================== ===================
Add the module to your ejabberd.cfg, on the modules section: Add the module to the modules configuration.
As it requires complex configuration, add this to the ejabberd.yml file:
include_config_file: "/etc/ejabberd/additional.cfg"
And this to additional.cfg:
{modules, [ {modules, [
...
{mod_cron, []}, {mod_cron, []},
...
]}. ]}.

View File

@ -36,7 +36,7 @@ start(Host, Opts) ->
ejabberd_commands:register_commands(commands()), ejabberd_commands:register_commands(commands()),
ejabberd_hooks:add(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50), ejabberd_hooks:add(webadmin_menu_host, Host, ?MODULE, web_menu_host, 50),
ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, web_page_host, 50), ejabberd_hooks:add(webadmin_page_host, Host, ?MODULE, web_page_host, 50),
Tasks = gen_mod:get_opt(tasks, Opts, []), Tasks = gen_mod:get_opt(tasks, Opts, fun(A) -> A end, []),
catch ets:new(cron_tasks, [ordered_set, named_table, public, {keypos, 2}]), catch ets:new(cron_tasks, [ordered_set, named_table, public, {keypos, 2}]),
[add_task(Host, Task) || Task <- Tasks]. [add_task(Host, Task) || Task <- Tasks].
@ -128,7 +128,7 @@ commands() ->
#ejabberd_commands{name = cron_list, tags = [cron], #ejabberd_commands{name = cron_list, tags = [cron],
desc = "List tasks scheduled in a host", desc = "List tasks scheduled in a host",
module = ?MODULE, function = cron_list, module = ?MODULE, function = cron_list,
args = [{host, string}], args = [{host, binary}],
result = {tasks, {list, {task, {tuple, [{id, integer}, {task, string}]}}}}}, result = {tasks, {list, {task, {tuple, [{id, integer}, {task, string}]}}}}},
#ejabberd_commands{name = cron_del, tags = [cron], #ejabberd_commands{name = cron_del, tags = [cron],
desc = "Delete this task from the schedule", desc = "Delete this task from the schedule",
@ -141,8 +141,7 @@ cron_list(Host) ->
Tasks = get_tasks(Host), Tasks = get_tasks(Host),
[{T#task.taskid, io_lib:format("~p", [T#task.task])} || T <- Tasks]. [{T#task.taskid, io_lib:format("~p", [T#task.task])} || T <- Tasks].
cron_del(TaskId_string) -> cron_del(TaskId) ->
TaskId = list_to_integer(TaskId_string),
delete_taskid(TaskId), delete_taskid(TaskId),
ok. ok.
@ -152,14 +151,14 @@ cron_del(TaskId_string) ->
%% --------------------- %% ---------------------
web_menu_host(Acc, _Host, Lang) -> web_menu_host(Acc, _Host, Lang) ->
[{"cron", ?T("Cron Tasks")} | Acc]. [{<<"cron">>, ?T(<<"Cron Tasks">>)} | Acc].
web_page_host(_, Host, web_page_host(_, Host,
#request{path = ["cron"], #request{path = [<<"cron">>],
lang = Lang} = _Request) -> lang = Lang} = _Request) ->
Tasks = get_tasks(Host), Tasks = get_tasks(Host),
Tasks_table = make_tasks_table(Tasks, Lang), Tasks_table = make_tasks_table(Tasks, Lang),
Res = [?XC("h1", "Cron Tasks")] ++ Tasks_table, Res = [?XC(<<"h1">>, <<"Cron Tasks">>)] ++ Tasks_table,
{stop, Res}; {stop, Res};
web_page_host(Acc, _, _) -> Acc. web_page_host(Acc, _, _) -> Acc.
@ -167,17 +166,17 @@ make_tasks_table(Tasks, Lang) ->
TList = lists:map( TList = lists:map(
fun(T) -> fun(T) ->
{Time_num, Time_unit, Mod, Fun, Args} = T#task.task, {Time_num, Time_unit, Mod, Fun, Args} = T#task.task,
?XE("tr", ?XE(<<"tr">>,
[?XC("td", integer_to_list(Time_num) ++" " ++ atom_to_list(Time_unit)), [?XC(<<"td">>, list_to_binary(integer_to_list(Time_num) ++" " ++ atom_to_list(Time_unit))),
?XC("td", atom_to_list(Mod)), ?XC(<<"td">>, list_to_binary(atom_to_list(Mod))),
?XC("td", atom_to_list(Fun)), ?XC(<<"td">>, list_to_binary(atom_to_list(Fun))),
?XC("td", io_lib:format("~p", [Args]))]) ?XC(<<"td">>, list_to_binary(io_lib:format("~p", [Args])))])
end, Tasks), end, Tasks),
[?XE("table", [?XE(<<"table">>,
[?XE("thead", [?XE(<<"thead">>,
[?XE("tr", [?XE(<<"tr">>,
[?XCT("td", "Periodicity"), [?XCT(<<"td">>, <<"Periodicity">>),
?XCT("td", "Module"), ?XCT(<<"td">>, <<"Module">>),
?XCT("td", "Function"), ?XCT(<<"td">>, <<"Function">>),
?XCT("td", "Arguments")])]), ?XCT(<<"td">>, <<"Arguments">>)])]),
?XE("tbody", TList)])]. ?XE(<<"tbody">>, TList)])].