Initial import from ejabberd-modules SVN

This commit is contained in:
Badlop 2013-04-15 12:03:14 +02:00
commit ee7d3c7030
615 changed files with 68838 additions and 0 deletions

60
README.txt Normal file
View File

@ -0,0 +1,60 @@
ejabberd-modules is a collaborative development area for ejabberd
modules developers and users.
For users
=========
You need to have Erlang installed.
To use an ejabberd module coming from this repository:
- Read the module specific README to see if special steps are needed
to deploy it.
- Run "./build.sh" or "build.bat" in the root (usually trunk
directory) of the wanted module.
- Copy generated .beam files from the ebin directory to the directory
where your ejabberd .beam files are.
- Use the configuration file examples provided in the conf dir to
update your ejabberd.cfg configuration file.
If during compilation of a module you get an error like:
{"init terminating in do_boot",{undef,[{make,all,[]},...
it means Erlang couldn't find its file make.beam
In Debian and other distributions you can try to install packages like:
erlang-dev erlang-nox erlang-tools
For developers
==============
The following organisation has been set-up for the development:
- Each module has its own SVN structure (trunk/branches/tags) to allow
independent versioning.
- Development and compilation of module should be possible without
ejabberd SVN, as long as developers check-out the ejabberd-dev
module. This module contains include file to make compilation
possible.
- The module directory structure is usually the following:
README.txt: Module description
LICENSE.txt: License for the module
Emakefile: Erlang makefile to build the module (preferred way, if no
dependencies on C code, as build will thus works on Windows)
doc/: Documentation dir
src/: Source directory
src/msgs/: Directory with translation files (pot, po and msg).
ebin/: empty (Target directory for the build).
conf/: Directory containing example configuration for your module.
build.sh: *nix build script.
build.bat: Windows build script.
- Module developers should put in the README if the module has
requirements or known incompatibilities with other modules (for
example, by modifying the same main ejabberd modules).

4
atom_pubsub/Emakefile Normal file
View File

@ -0,0 +1,4 @@
{'../ejabberd-dev/src/gen_mod', [{outdir, "../ejabberd-dev/ebin"},{i,"../ejabberd-dev/include"}]}.
{'src/atom_microblog', [{outdir, "ebin"},{i,"../ejabberd-dev/include"}]}.
{'src/atom_pubsub', [{outdir, "ebin"},{i,"../ejabberd-dev/include"}]}.
{'src/mod_couch', [{outdir, "ebin"},{i,"../ejabberd-dev/include"}]}.

116
atom_pubsub/README Normal file
View File

@ -0,0 +1,116 @@
atom_pubsub - the Atom PubSub tunnel
Author: Eric Cestari <eric@ohmforce.com> http://www.cestari.info/
Licensed under the same terms as ejabberd (GPL 2)
Requires: ejabberd trunk SVN r1561 or newer; or ejabberd 2.0.3 or newer
DESCRIPTION
-----------
The atom_pubsub module provides access to all PEP nodes via an AtomPub interface.
Also gives access to tune, mood and geoloc nodes if they exist.
urn:xmpp:microblog is not a XEP yet, but its latest incarnation can be found here :
http://www.xmpp.org/extensions/inbox/microblogging.html
AtomPub RFC : http://bitworking.org/projects/atom/rfc5023.html
For more information refer to:
http://www.cestari.info/2008/6/19/atom-pubsub-module-for-ejabberd
http://www.cestari.info/2008/9/12/atom_pubsub-dead-long-live-atom_microblog
INSTALL
-------
1. Compile the files executing: ./build.sh
2. Copy beam files from ebin/ into your ejabberd installation.
3. Edit ejabberd.cfg and add a request handler in ejabberd_http listener:
{listen, [
...
{8080, ejabberd_http, [
http_poll,
web_admin,
{request_handlers, [{["pep"], atom_microblog}, % Make sure it's "pep", or change it in atom_microblog.erl
{["pubsub"], atom_pubsub}]} % Make sure it's "pubsub", or change it in atom_pubsub.erl
]}
]}.
4. Restart ejabberd.
USAGE
-----
URL for the service document for a given user@domain is :
http://<server>:5280/pep/<domain>/<user>
The atom_pubsub module provides access to all nodes below the /home/server/user tree.
SVC document : http://<server>:5280/pubsub/<domain>/<user>
# Configuring your PEP nodes
For your PEP nodes to be published, you need to activate persistence.
Two ways:
A) For existing nodes :
<iq type='set'
id='config2'>
<pubsub xmlns='http://jabber.org/protocol/pubsub#owner'>
<configure node='http://jabber.org/protocol/tune'> <!-- for user-tune -->
<x xmlns='jabber:x:data' type='submit'>
<field var='FORM_TYPE' type='hidden'>
<value>http://jabber.org/protocol/pubsub#node_config</value>
</field>
<field var='pubsub#persist_items'><value>1</value></field>
<field var='pubsub#max_items'><value>1</value></field>
</x>
</configure>
</pubsub>
</iq>
B) for new nodes :
It's better to change src/mod_pubsub/node_pep.erl in the options() function:
{persist_items, true},
{max_items, 1},
All future PEP nodes will be published with those parameters by default.
# What you get
Full caching support with Etag, Conditional Get, etc.
Authentication is required for writing, updating via Atom. Use your full JID as username for authentication.
It expects the payload to be an atom entry, but does not enforce it.
However, it has to be well formed XML.
# Can I have it with OpenFire and Epeios ?
That's not possible. atom_microblog needs direct access to the pubsub structures.
WHAT'S NEXT?
------------
* Better understanding of Atom entries. have better links, implement reply-to
* Adding a local friend collection for personal use
* But that may be implemented in mod_pubsub/node_microblog.erl (it will arrive soon)
THANKS
------
* johnny_ for testing and giving feedback.
* badlop and C Romain from ProcessOne for feeding ejabberd with my patches, making this code work.

1
atom_pubsub/build.bat Normal file
View File

@ -0,0 +1 @@
erl -pa ../../ejabberd-dev/trunk/ebin -pa ebin -make

2
atom_pubsub/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
erl -pa ../ejabberd-dev/ebin -pz ebin -make

View File

@ -0,0 +1,367 @@
%%
% This module enables access to the PEP node "urn:xmpp:microblog" via
% an Atompub compliant interface.
%
%
-module(atom_microblog).
-author('eric@ohmforce.com').
-include("ejabberd.hrl").
-include("jlib.hrl").
-include("mod_pubsub/pubsub.hrl").
-include("web/ejabberd_http.hrl").
-export([process/2]).
process([Domain,User|_]=LocalPath, #request{auth = Auth} = Request)->
case get_auth(Auth) of
%%make sure user belongs to pubsub domain
{User, Domain} ->
out(Request, Request#request.method, LocalPath,User);
_ ->
out(Request, Request#request.method, LocalPath,undefined)
end;
process(_LocalPath, _Request)->
error(404).
get_host([Domain,User|_Rest])-> {User, Domain, []}.
get_collection([_Domain,_User, Node|_R])->
case lists:member(Node, ["mood", "geoloc", "tune"]) of
true -> "http://jabber.org/protocol/"++Node;
false -> Node
end;
get_collection(_)->error.
get_member([_Domain,_User, _Node, Member]=Uri)->
[get_host(Uri), get_collection(Uri), Member].
base_uri(#request{host=Host, port=Port}, Domain, User)->
"http://"++Host++":"++i2l(Port)++"/pep/"++Domain++"/"++ User.
collection_uri(R, Domain, User, Node)->
Clean=lists:last(string:tokens(Node, "/")),
base_uri(R, Domain, User)++"/"++Clean.
entry_uri(R, Domain, User, Node, Id)->
collection_uri(R, Domain, User, Node)++"/"++Id.
generate_etag(#pubsub_item{modification={_JID, {_, D2, D3}}})->integer_to_list(D3+D2).
out(_Args, 'POST', [_,_, _], undefined) ->error(401);
out(_Args, 'PUT', [_,_, _], undefined) ->error(401);
out(_Args, 'DELETE', [_,_, _], undefined) ->error(401);
%% Service document
out(Args, 'GET', [Domain, UserNode]=Uri, _User) ->
%%Collections = mnesia:dirty_match_object(#pubsub_node{nodeid={get_host(Uri), '_'},_ = '_'}),
case mod_pubsub:tree_action(get_host(Uri), get_nodes, [get_host(Uri)]) of
[] -> error(404);
Collections ->
?DEBUG("PEP nodes : ~p~n",[Collections]),
{200, [{"Content-Type", "application/atomsvc+xml"}], "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
++ xml:element_to_string(service(Args,Domain, UserNode, Collections))}
end;
%% Collection
out(Args, 'GET', [Domain, User, Node]=Uri, _User) ->
case mod_pubsub:tree_action(get_host(Uri), get_node, [get_host(Uri),get_collection(Uri)]) of
{error, _} -> error(404);
_ ->
Items = lists:sort(fun(X,Y)->
{_,DateX} = X#pubsub_item.modification,
{_,DateY} = Y#pubsub_item.modification,
DateX > DateY
end, mod_pubsub:get_items(
get_host(Uri),
get_collection(Uri), "")),
case Items of
[] -> ?DEBUG("Items : ~p ~n", [collection(get_collection(Uri),
collection_uri(Args,Domain,User,Node), calendar:now_to_universal_time(erlang:now()), User, "", [])]),
{200, [{"Content-Type", "application/atom+xml"}],
collection(get_collection(Uri),
collection_uri(Args,Domain,User,Node), calendar:now_to_universal_time(erlang:now()), User, "", [])};
_ ->
#pubsub_item{modification = {_JID,LastDate}} = LastItem = hd(Items),
Etag =generate_etag(LastItem),
IfNoneMatch=proplists:get_value('If-None-Match', Args#request.headers),
if IfNoneMatch==Etag
->
success(304);
true ->
XMLEntries= [item_to_entry(Args,Node,Entry)||Entry <- Items],
{200, [{"Content-Type", "application/atom+xml"},{"Etag", Etag}],
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
++ xml:element_to_string(
collection(get_collection(Uri), collection_uri(Args,Domain,User,Node),
calendar:now_to_universal_time(LastDate), User, "", XMLEntries))}
end
end
end;
%% Add new collection
out(_Args, 'POST', [_Domain, _User], _User)-> error(403);
out(Args, 'POST', [Domain,User, Node]=Uri, User) ->
%%FIXME Slug
Slug = case lists:keysearch("Slug",3,Args#request.headers) of
false -> uniqid(false) ;
{value, {_,_,_,_,Value}} -> Value
end,
Payload = xml_stream:parse_element(Args#request.data),
case mod_pubsub:publish_item(get_host(Uri),
Domain,
get_collection(Uri),
jlib:make_jid(User,Domain, ""),
Slug,
[Payload]) of
{result, []} ->
?DEBUG("Publishing to ~p~n",[entry_uri(Args, Domain,User, Node,Slug)]),
{201, [{"location", entry_uri(Args, Domain,User,Node,Slug)}], Payload};
{error, Error} ->
error(400, Error)
end;
out(_Args, 'POST', [_, _, _], _) ->
{status, 403};
%% Atom doc
out(Args, 'GET', [_Domain,_U, Node, _Member]=URI, _User) ->
Failure = fun(_Error)->error(404)end,
Success = fun(Item)->
Etag =generate_etag(Item),
IfNoneMatch=proplists:get_value('If-None-Match', Args#request.headers),
if IfNoneMatch==Etag
->
success(304);
true ->
{200, [{"Content-Type", "application/atom+xml"},{"Etag", Etag}], "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
++ xml:element_to_string(item_to_entry(Args, Node, Item))}
end
end,
get_item(URI, Failure, Success);
%% Update doc
out(Args, 'PUT', [Domain,User, _Node, Member]=Uri, User) ->
Payload = xml_stream:parse_element(Args#request.data),
Failure = fun(_Error)->error(404)end,
Success = fun(Item)->
Etag =generate_etag(Item),
IfMatch=proplists:get_value('If-Match', Args#request.headers),
if IfMatch==Etag
->
case mod_pubsub:publish_item(get_host(Uri),
Domain,
get_collection(Uri),
jlib:make_jid(User,Domain, ""),
Member,
[Payload]) of
{result, _Result} ->
{200, [{"Content-Type", "application/atom+xml"}],""};
{error, {xmlelement, "error", [{"code",Code},_],_}} ->
error(Code);
{error, _Error} ->
error(500)
end;
true ->
error(412) %% ressource has been modified since last get for this client.
end
end,
get_item(Uri, Failure, Success);
%%
out(_Args, 'PUT',_Url, _User) ->
error(401);
out(_Args, 'DELETE', [Domain,User, _Node, _Member]=Uri, User) ->
case mod_pubsub:delete_item(get_host(Uri),
get_collection(Uri),
jlib:make_jid(User,Domain, ""),
get_member(Uri)) of
{result, _Result} ->
success(200);
{error, {xmlelement, "error", [{"code",Code},_],_}} ->
error(Code);
{error, _Code1} ->
error(500)
end;
out(_Args, 'DELETE',_Url, _User) ->
error(401);
out(_, _, _, _) ->
error(403).
get_item(Uri, Failure, Success)->
case catch mod_pubsub:node_action(get_host(Uri),
get_collection(Uri),
get_item,
get_member(Uri)) of
{error, Reason} ->
Failure(Reason);
{result, Item} ->
Success(Item)
end.
item_to_entry(Args,Node,#pubsub_item{itemid={Id,_}, payload=Entry}=Item)->
[R | _]=xml:remove_cdata(Entry),
item_to_entry(Args, Node, Id, R, Item).
item_to_entry(Args,Node, Id,{xmlelement, "entry", Attrs, SubEl},
#pubsub_item{modification={_, Secs}, itemid={Id, {{User, Domain, []},_}}}) ->
Date = calendar:now_to_local_time(Secs),
SubEl2=[{xmlelement, "app:edited", [], [{xmlcdata, w3cdtf(Date)}]},
{xmlelement, "link",[{"rel", "edit"},
{"href", entry_uri(Args,Domain,User, Node, Id)}],[] },
{xmlelement, "id", [],[{xmlcdata, Id}]}
| SubEl],
{xmlelement, "entry", [{"xmlns:app","http://www.w3.org/2007/app"}|Attrs], SubEl2};
%% Don't do anything except adding xmlns
item_to_entry(_Args,Node, _Id, {xmlelement, Name, Attrs, Subels}=Element, _Item)->
case proplists:is_defined("xmlns",Attrs) of
true -> Element;
false -> {xmlelement, Name, [{"xmlns", Node}|Attrs], Subels}
end.
collection(Title, Link, Updated, Author, _Id, Entries)->
{xmlelement, "feed", [{"xmlns", "http://www.w3.org/2005/Atom"},
{"xmlns:app", "http://www.w3.org/2007/app"}], [
{xmlelement, "title", [],[{xmlcdata, Title}]},
{xmlelement, "updated", [],[{xmlcdata, w3cdtf(Updated)}]},
{xmlelement, "link", [{"href", Link}], []},
{xmlelement, "author", [], [
{xmlelement, "name", [], [{xmlcdata,Author}]}
]},
{xmlelement, "title", [],[{xmlcdata, Title}]} |
Entries
]}.
service(Args, Domain, User, Collections)->
{xmlelement, "service", [{"xmlns", "http://www.w3.org/2007/app"},
{"xmlns:atom", "http://www.w3.org/2005/Atom"},
{"xmlns:app", "http://www.w3.org/2007/app"}],[
{xmlelement, "workspace", [],[
{xmlelement, "atom:title", [],[{xmlcdata,"Feed for "++User++"@"++Domain}]} |
lists:map(fun(#pubsub_node{nodeid={_Server, Id}})->
{xmlelement, "collection", [{"href", collection_uri(Args,Domain,User, Id)}], [
{xmlelement, "atom:title", [], [{xmlcdata, Id}]}
]}
end, Collections)
]}
]}.
%%% lifted from ejabberd_web_admin
get_auth(Auth) ->
case Auth of
{SJID, P} ->
case jlib:string_to_jid(SJID) of
error ->
unauthorized;
#jid{user = U, server = S} ->
case ejabberd_auth:check_password(U, S, P) of
true ->
{U, S};
false ->
unauthorized
end
end;
_ ->
unauthorized
end.
%% simple output functions
error(404)->
{404, [], "Not Found"};
error(403)->
{403, [], "Forbidden"};
error(500)->
{500, [], "Internal server error"};
error(401)->
{401, [{"WWW-Authenticate", "basic realm=\"ejabberd\""}],"Unauthorized"};
error(Code)->
{Code, [], ""}.
success(200)->
{200, [], ""};
success(Code)->
{Code, [], ""}.
error(Code, Error) when is_list(Error) -> {Code, [], Error};
error(Code, {xmlelement, "error",_,_}=Error) -> {Code, [], xml:element_to_string(Error)};
error(Code, _Error) -> {Code, [], "Bad request"}.
% Code below is taken (with some modifications) from the yaws webserver, which
% is distributed under the folowing license:
%
% This software (the yaws webserver) is free software.
% Parts of this software is Copyright (c) Claes Wikstrom <klacke@hyber.org>
% Any use or misuse of the source code is hereby freely allowed.
%
% 1. Redistributions of source code must retain the above copyright
% notice as well as this list of conditions.
%
% 2. Redistributions in binary form must reproduce the above copyright
% notice as well as this list of conditions.
%%% Create W3CDTF (http://www.w3.org/TR/NOTE-datetime) formatted date
%%% w3cdtf(GregSecs) -> "YYYY-MM-DDThh:mm:ssTZD"
%%%
uniqid(false)->
{T1, T2, T3} = now(),
lists:flatten(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3]));
uniqid(Slug) ->
Slut = string:to_lower(Slug),
S = string:substr(Slut, 1, 9),
{_T1, T2, T3} = now(),
lists:flatten(io_lib:fwrite("~s-~.16B~.16B", [S, T2, T3])).
w3cdtf(Date) -> %1 Date = calendar:gregorian_seconds_to_datetime(GregSecs),
{{Y, Mo, D},{H, Mi, S}} = Date,
[UDate|_] = calendar:local_time_to_universal_time_dst(Date),
{DiffD,{DiffH,DiffMi,_}}=calendar:time_difference(UDate,Date),
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi).
%%% w3cdtf's helper function
w3cdtf_diff(Y, Mo, D, H, Mi, S, _DiffD, DiffH, DiffMi) when DiffH < 12, DiffH /= 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12, DiffD == 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "+" ++ add_zero(DiffH) ++ ":" ++
add_zero(DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12, DiffD /= 0, DiffMi /= 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "-" ++ add_zero(23-DiffH) ++
":" ++ add_zero(60-DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12, DiffD /= 0, DiffMi == 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "-" ++ add_zero(24-DiffH) ++
":" ++ add_zero(DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, _DiffD, DiffH, _DiffMi) when DiffH == 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "Z".
add_zero(I) when is_integer(I) -> add_zero(i2l(I));
add_zero([A]) -> [$0,A];
add_zero(L) when is_list(L) -> L.
i2l(I) when is_integer(I) -> integer_to_list(I);
i2l(L) when is_list(L) -> L.

View File

@ -0,0 +1,374 @@
%%
% This module enables access to the PEP node "urn:xmpp:microblog" via
% an Atompub compliant interface.
%
%
-module(atom_pubsub).
-author('eric@ohmforce.com').
-include("ejabberd.hrl").
-include("jlib.hrl").
-include("mod_pubsub/pubsub.hrl").
-include("web/ejabberd_http.hrl").
-export([process/2]).
process([Domain,User|_]=LocalPath, #request{auth = Auth} = Request)->
case get_auth(Auth) of
%%make sure user belongs to pubsub domain
{User, Domain} ->
out(Request, Request#request.method, LocalPath,User);
_ ->
out(Request, Request#request.method, LocalPath,undefined)
end;
process(_LocalPath, _Request)->
error(404).
get_host([Domain,_User|_Rest])-> "pubsub."++Domain.
get_root([Domain,User|_Rest]) -> ["home", Domain, User].
get_collection([Domain,User, Node|_Rest])->["home", Domain, User, Node].
get_item_name([_Domain,_User, _Node, Member]) -> Member.
collection_uri(R, Domain, User, Node) ->
case Node of
["home", Domain, User|_Rest]->
base_uri(R, Domain, User)++"/"++lists:last(Node);
_ -> base_uri(R, Domain, User)++"/"++Node
end.
entry_uri(R, Domain, User, Node, Id)->
collection_uri(R, Domain, User, Node)++"/"++Id.
get_member([_Domain,_User, _Node, Member]=Uri)->
[get_host(Uri), get_collection(Uri), Member].
base_uri(#request{host=Host, port=Port}, Domain, User)->
"http://"++Host++":"++i2l(Port)++"/pubsub/"++Domain++"/"++ User.
generate_etag(#pubsub_item{modification={_JID, {_, D2, D3}}})->integer_to_list(D3+D2).
out(_Args, 'POST', [_,_, _], undefined) ->error(401);
out(_Args, 'PUT', [_,_, _], undefined) ->error(401);
out(_Args, 'DELETE', [_,_, _], undefined) ->error(401);
%% Service document
out(Args, 'GET', [Domain, UserNode]=Uri, _User) ->
%%Collections = mnesia:dirty_match_object(#pubsub_node{nodeid={get_host(Uri), '_'},_ = '_'}),
case mod_pubsub:tree_action(get_host(Uri), get_subnodes, [get_host(Uri),get_root(Uri), "" ]) of
[] -> error(404);
Collections ->
{200, [{"Content-Type", "application/atomsvc+xml"}], "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
++ xml:element_to_string(service(Args,Domain, UserNode, Collections))}
end;
%% Collection
out(Args, 'GET', [Domain, User, Node]=Uri, _User) ->
case mod_pubsub:tree_action(get_host(Uri), get_node, [get_host(Uri),get_collection(Uri)]) of
{error, _} -> error(404);
_ ->
Items = lists:sort(fun(X,Y)->
{_,DateX} = X#pubsub_item.modification,
{_,DateY} = Y#pubsub_item.modification,
DateX > DateY
end, mod_pubsub:get_items(
get_host(Uri),
get_collection(Uri), "")),
case Items of
[] -> ?DEBUG("Items : ~p ~n", [collection(get_collection(Uri),
collection_uri(Args,Domain,User,Node), calendar:now_to_universal_time(erlang:now()), User, "", [])]),
{200, [{"Content-Type", "application/atom+xml"}],
collection(get_collection(Uri),
collection_uri(Args,Domain,User,Node), calendar:now_to_universal_time(erlang:now()), User, "", [])};
_ ->
#pubsub_item{modification = {_JID,LastDate}} = LastItem = hd(Items),
Etag =generate_etag(LastItem),
IfNoneMatch=proplists:get_value('If-None-Match', Args#request.headers),
if IfNoneMatch==Etag
->
success(304);
true ->
XMLEntries= [item_to_entry(Args,Node,Entry)||Entry <- Items],
{200, [{"Content-Type", "application/atom+xml"},{"Etag", Etag}],
"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
++ xml:element_to_string(
collection(get_collection(Uri), collection_uri(Args,Domain,User,Node),
calendar:now_to_universal_time(LastDate), User, "", XMLEntries))}
end
end
end;
%% Add new collection
out(_Args, 'POST', [_Domain, _User], _User)-> error(403);
out(Args, 'POST', [Domain,User, Node]=Uri, User) ->
%%FIXME Slug
Slug = case lists:keysearch("Slug",3,Args#request.headers) of
false -> uniqid(false) ;
{value, {_,_,_,_,Value}} -> Value
end,
Payload = xml_stream:parse_element(Args#request.data),
[FilteredPayload]=xml:remove_cdata([Payload]),
%FilteredPayload2 = case xml:get_subtag(FilteredPayload, "app:edited") ->
% {xmlelement, Name, Attrs, [{cdata, }]}
case mod_pubsub:publish_item(get_host(Uri),
Domain,
get_collection(Uri),
jlib:make_jid(User,Domain, ""),
Slug,
[FilteredPayload]) of
{result, []} ->
?DEBUG("Publishing to ~p~n",[entry_uri(Args, Domain,User, Node,Slug)]),
{201, [{"location", entry_uri(Args, Domain,User,Node,Slug)}], Payload};
{error, Error} ->
error(400, Error)
end;
out(_Args, 'POST', [_, _, _], _) ->
{status, 403};
%% Atom doc
out(Args, 'GET', [_Domain,_U, Node, _Member]=URI, _User) ->
Failure = fun(_Error)->error(404)end,
Success = fun(Item)->
Etag =generate_etag(Item),
IfNoneMatch=proplists:get_value('If-None-Match', Args#request.headers),
if IfNoneMatch==Etag
->
success(304);
true ->
{200, [{"Content-Type", "application/atom+xml"},{"Etag", Etag}], "<?xml version=\"1.0\" encoding=\"utf-8\"?>"
++ xml:element_to_string(item_to_entry(Args, Node, Item))}
end
end,
get_item(URI, Failure, Success);
%% Update doc
out(Args, 'PUT', [Domain,User, _Node, Member]=Uri, User) ->
Payload = xml_stream:parse_element(Args#request.data),
Failure = fun(_Error)->error(404)end,
Success = fun(Item)->
Etag =generate_etag(Item),
IfMatch=proplists:get_value('If-Match', Args#request.headers),
if IfMatch==Etag
->
case mod_pubsub:publish_item(get_host(Uri),
Domain,
get_collection(Uri),
jlib:make_jid(User,Domain, ""),
Member,
[Payload]) of
{result, _Result} ->
{200, [{"Content-Type", "application/atom+xml"}],""};
{error, {xmlelement, "error", [{"code","404"},_],_}} ->
error(404);
{error, _Error} ->
error(500)
end;
true ->
error(412) %% ressource has been modified since last get for this client.
end
end,
get_item(Uri, Failure, Success);
%%
out(_Args, 'PUT',_Url, _User) ->
error(401);
out(_Args, 'DELETE', [Domain,User, _Node, _Member]=Uri, User) ->
case mod_pubsub:delete_item(get_host(Uri),
get_collection(Uri),
jlib:make_jid(User,Domain, ""),
get_item_name(Uri)) of
{result, _Result} ->
success(200);
{error, {xmlelement, "error", [{"code","404"},_],_}} ->
error(404);
{error, _Code1} ->
error(500)
end;
out(_Args, 'DELETE',_Url, _User) ->
error(401);
out(_, _, _, _) ->
error(403).
get_item(Uri, Failure, Success)->
case catch mod_pubsub:node_action(get_host(Uri),
get_collection(Uri),
get_item,
get_member(Uri)) of
{error, Reason} ->
Failure(Reason);
{result, Item} ->
Success(Item)
end.
item_to_entry(Args,Node,#pubsub_item{itemid={Id,_}, payload=Entry}=Item)->
[R]=xml:remove_cdata(Entry),
item_to_entry(Args, Node, Id, R, Item).
item_to_entry(Args,Node, Id,{xmlelement, "entry", Attrs, SubEl},
#pubsub_item{modification={JID, Secs} }) ->
Date = calendar:now_to_local_time(Secs),
{User, Domain, _}=jlib:jid_tolower(JID),
SubEl2=[{xmlelement, "app:edited", [], [{xmlcdata, w3cdtf(Date)}]},
{xmlelement, "link",[{"rel", "edit"},
{"href", entry_uri(Args,Domain,User, Node, Id)}],[] },
{xmlelement, "id", [],[{xmlcdata, Id}]}
| SubEl],
{xmlelement, "entry", [{"xmlns:app","http://www.w3.org/2007/app"}|Attrs], SubEl2};
% Don't do anything except adding xmlns
item_to_entry(_Args,Node, _Id, {xmlelement, Name, Attrs, Subels}=Element, _Item)->
case proplists:is_defined("xmlns",Attrs) of
true -> Element;
false -> {xmlelement, Name, [{"xmlns", Node}|Attrs], Subels}
end.
collection(Title, Link, Updated, Author, _Id, Entries)->
{xmlelement, "feed", [{"xmlns", "http://www.w3.org/2005/Atom"},
{"xmlns:app", "http://www.w3.org/2007/app"}], [
{xmlelement, "title", [],[{xmlcdata, Title}]},
{xmlelement, "updated", [],[{xmlcdata, w3cdtf(Updated)}]},
{xmlelement, "link", [{"href", Link}], []},
{xmlelement, "author", [], [
{xmlelement, "name", [], [{xmlcdata,Author}]}
]},
{xmlelement, "title", [],[{xmlcdata, Title}]} |
Entries
]}.
service(Args, Domain, User, Collections)->
{xmlelement, "service", [{"xmlns", "http://www.w3.org/2007/app"},
{"xmlns:atom", "http://www.w3.org/2005/Atom"},
{"xmlns:app", "http://www.w3.org/2007/app"}],[
{xmlelement, "workspace", [],[
{xmlelement, "atom:title", [],[{xmlcdata,"Feed for "++User++"@"++Domain}]} |
lists:map(fun(#pubsub_node{nodeid={_Server, Id}, type=_Type})->
{xmlelement, "collection", [{"href", collection_uri(Args,Domain,User, Id)}], [
{xmlelement, "atom:title", [], [{xmlcdata, lists:last(Id)}]}
]}
end, Collections)
]}
]}.
%%% lifted from ejabberd_web_admin
get_auth(Auth) ->
case Auth of
{SJID, P} ->
case jlib:string_to_jid(SJID) of
error ->
unauthorized;
#jid{user = U, server = S} ->
case ejabberd_auth:check_password(U, S, P) of
true ->
{U, S};
false ->
unauthorized
end
end;
_ ->
unauthorized
end.
%% simple output functions
error(404)->
{404, [], "Not Found"};
error(403)->
{403, [], "Forbidden"};
error(500)->
{500, [], "Internal server error"};
error(401)->
{401, [{"WWW-Authenticate", "basic realm=\"ejabberd\""}],"Unauthorized"};
error(Code)->
{Code, [], ""}.
success(200)->
{200, [], ""};
success(Code)->
{Code, [], ""}.
error(Code, Error) when is_list(Error) -> {Code, [], Error};
error(Code, {xmlelement, "error",_,_}=Error) -> {Code, [], xml:element_to_string(Error)};
error(Code, _Error) -> {Code, [], "Bad request"}.
% Code below is taken (with some modifications) from the yaws webserver, which
% is distributed under the folowing license:
%
% This software (the yaws webserver) is free software.
% Parts of this software is Copyright (c) Claes Wikstrom <klacke@hyber.org>
% Any use or misuse of the source code is hereby freely allowed.
%
% 1. Redistributions of source code must retain the above copyright
% notice as well as this list of conditions.
%
% 2. Redistributions in binary form must reproduce the above copyright
% notice as well as this list of conditions.
%%% Create W3CDTF (http://www.w3.org/TR/NOTE-datetime) formatted date
%%% w3cdtf(GregSecs) -> "YYYY-MM-DDThh:mm:ssTZD"
%%%
uniqid(false)->
{T1, T2, T3} = now(),
lists:flatten(io_lib:fwrite("~.16B~.16B~.16B", [T1, T2, T3]));
uniqid(Slug) ->
Slut = string:to_lower(Slug),
S = string:substr(Slut, 1, 9),
{_T1, T2, T3} = now(),
lists:flatten(io_lib:fwrite("~s-~.16B~.16B", [S, T2, T3])).
w3cdtf(Date) -> %1 Date = calendar:gregorian_seconds_to_datetime(GregSecs),
{{Y, Mo, D},{H, Mi, S}} = Date,
[UDate|_] = calendar:local_time_to_universal_time_dst(Date),
{DiffD,{DiffH,DiffMi,_}}=calendar:time_difference(UDate,Date),
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi).
%%% w3cdtf's helper function
w3cdtf_diff(Y, Mo, D, H, Mi, S, _DiffD, DiffH, DiffMi) when DiffH < 12, DiffH /= 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "+" ++ add_zero(DiffH) ++ ":" ++ add_zero(DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12, DiffD == 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "+" ++ add_zero(DiffH) ++ ":" ++
add_zero(DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12, DiffD /= 0, DiffMi /= 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "-" ++ add_zero(23-DiffH) ++
":" ++ add_zero(60-DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, DiffD, DiffH, DiffMi) when DiffH > 12, DiffD /= 0, DiffMi == 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "-" ++ add_zero(24-DiffH) ++
":" ++ add_zero(DiffMi);
w3cdtf_diff(Y, Mo, D, H, Mi, S, _DiffD, DiffH, _DiffMi) when DiffH == 0 ->
i2l(Y) ++ "-" ++ add_zero(Mo) ++ "-" ++ add_zero(D) ++ "T" ++
add_zero(H) ++ ":" ++ add_zero(Mi) ++ ":" ++
add_zero(S) ++ "Z".
add_zero(I) when is_integer(I) -> add_zero(i2l(I));
add_zero([A]) -> [$0,A];
add_zero(L) when is_list(L) -> L.
i2l(I) when is_integer(I) -> integer_to_list(I);
i2l(L) when is_list(L) -> L.

View File

@ -0,0 +1,24 @@
%%%----------------------------------------------------------------------
%%% File : mod_couch.erl
%%% Author : Eric Cestari
%%% Purpose : Configures and starts ecouch client
%%% Created :
%%% Id : $Id$
%%%----------------------------------------------------------------------
-module(mod_couch).
-author('eric@ohmforce.com').
-vsn('0.2.0').
-behaviour(gen_mod).
-export([start/2, stop/1]).
start(Host, Opts) ->
Server = gen_mod:get_opt(server, Opts, {"127.0.0.1", "5984"}),
inets:start(),
application:set_env(ecouch, Server, {}),
application:start(ecouch).
stop(_Host) ->
application:stop(ecouch).

27
bfile/LICENCE Normal file
View File

@ -0,0 +1,27 @@
Copyright (c) 2006, Claes Wikstrom, klacke@hyber.org
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of "bfile" nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

23
bfile/Makefile Normal file
View File

@ -0,0 +1,23 @@
all:
(cd config;$(MAKE))
(cd src;$(MAKE))
-(cd c_src;$(MAKE) -k)
$(MAKE) appfile
clean:
(cd src;$(MAKE) clean)
(cd c_src;$(MAKE) clean)
(cd config; $(MAKE) clean)
install: all
(cd c_src; $(MAKE) install)
conf_clean:
(cd config; $(MAKE) clean)
appfile:
(cd src;$(MAKE) ../ebin/bfile.app)

28
bfile/README Normal file
View File

@ -0,0 +1,28 @@
An interface to fast FILE I/O
It's based on an old and hacked version
of the BSD FILE*
To install, type make; make install
and it shuld install itself as an app in your
erlang dir.
See the source src/bfile.erl for API
Here's an example shell session:
2> bfile:load_driver().
ok
4> {ok, Fd} = bfile:fopen("Makefile", "r").
{ok,{bfile,#Port<0.98>}}
5> bfile:fgets(Fd).
{line,<<10>>}
6> bfile:fgets(Fd).
{line,<<10>>}
7> bfile:fgets(Fd).
{line,<<97,108,108,58,32,10>>}
14> bfile:fread(Fd, 10000).
{ok,<<10,10,105,110,115,116,97,108,108,58,32,97,108,108,10,9,40,99,100,32,99,95,115,114,99,59,32,...>>}
15> bfile:fread(Fd, 10000).
eof

490
bfile/c_src/FILE_drv.c Normal file
View File

@ -0,0 +1,490 @@
/* Interface to stdio buffered FILE io */
/* author: klacke@kaja.klacke.net */
/* Created : 22 Nov 1999 by Claes Wikstrom <klacke@kaja.klacke.net> */
#include <string.h>
#define USE_STDIO
#ifdef WIN32
#define USE_STDIO
#include <windows.h>
#else
#include <errno.h>
#include <unistd.h>
#include <fcntl.h>
#include <ctype.h>
#endif
#include "erl_driver.h"
#ifndef ERL_DRV_NIL
#include "erl_driver_compat.h"
#endif
#ifdef USE_STDIO
# include <stdio.h>
#else
# define malloc(s) driver_alloc(s)
# define realloc(p, s) driver_realloc(p, s)
# define free(p) driver_free(p)
# define BINTERFACE static
# include "bbio.c"
# define FILE bFILE
# define clearerr bclearerr
# define fclose bfclose
# define feof bfeof
# define ferror bferror
# define fflush bfflush
# define fgets bfgets
# define fileno bfileno
# define fopen bfopen
# define fread bfread
# define fseek bfseek
# define ftell bftell
# define fwrite bfwrite
# define getc bgetc
# define ungetc bungetc
#endif
#define get_int32(s) ((((unsigned char*) (s))[0] << 24) | \
(((unsigned char*) (s))[1] << 16) | \
(((unsigned char*) (s))[2] << 8) | \
(((unsigned char*) (s))[3]))
#define put_int32(i, s) {((char*)(s))[0] = (char)((i) >> 24) & 0xff; \
((char*)(s))[1] = (char)((i) >> 16) & 0xff; \
((char*)(s))[2] = (char)((i) >> 8) & 0xff; \
((char*)(s))[3] = (char)((i) & 0xff);}
/* op codes */
#define XX_OPEN 'o'
#define XX_CLOSE 'c'
#define XX_READ 'r'
#define XX_WRITE 'w'
#define XX_SEEK 's'
#define XX_TELL 't'
#define XX_TRUNCATE 'T'
#define XX_FLUSH 'f'
#define XX_OEOF 'e'
#define XX_ERROR 'E'
#define XX_GETC 'g'
#define XX_GETS 'G'
#define XX_GETS2 '2'
#define XX_SET_LINEBUF_SIZE 'S'
#define XX_UNGETC 'u'
/* return codes */
#define XX_VALUE 'v'
#define XX_FLINE 'L'
#define XX_OK 'o'
#define XX_I32 'O'
#define XX_NOLINE 'N'
#define XX_FERROR 'E'
#define XX_REOF 'x'
#ifdef WIN32
#define XX_EINVAL WSAEINVAL
#else
#define XX_EINVAL EINVAL
#endif
static ErlDrvData FILE_start(ErlDrvPort port, char *buf);
static void FILE_stop(ErlDrvData drv_data);
static ErlDrvEntry FILE_driver_entry;
typedef struct _desc {
ErlDrvPort port;
FILE *fp;
int linebuf_size;
} Desc;
static ErlDrvData FILE_start(ErlDrvPort port, char *buf)
{
Desc *d = (Desc*) driver_alloc(sizeof (Desc));
if (d == NULL)
return (ErlDrvData) -1;
d->fp = NULL;
d->port = port;
d->linebuf_size = 255; /* default line size */
set_port_control_flags(port, PORT_CONTROL_FLAG_BINARY);
return (ErlDrvData) d;
}
static void FILE_stop(ErlDrvData drv_data)
{
Desc *d = (Desc*) drv_data;
if (d->fp)
fclose(d->fp);
driver_free(d);
}
static char *driver_error(ErlDrvPort port, int err)
{
char response[256]; /* Response buffer. */
char* s;
char* t;
ErlDrvBinary* bin;
bin = driver_alloc_binary(1);
bin->orig_bytes[0] = XX_FERROR;
response[0] = XX_FERROR;
for (s = erl_errno_id(err), t = bin->orig_bytes + 1; *s; s++, t++)
*t = tolower(*s);
return (char *)bin;
}
static char *driver_ret32(ErlDrvPort port, unsigned int r)
{
char ch = XX_I32;
ErlDrvBinary* bin;
bin = driver_alloc_binary(1);
bin->orig_bytes[0] = ch;
put_int32(r, bin->orig_bytes + 1);
return (char *)bin;
}
static char *driver_ok(ErlDrvPort port)
{
char ch = XX_OK;
ErlDrvBinary* bin;
bin = driver_alloc_binary(1);
bin->orig_bytes[0] = ch;
return (char *)bin;
}
static char *driver_eof(ErlDrvPort port)
{
char ch = XX_REOF;
ErlDrvBinary* bin;
bin = driver_alloc_binary(1);
bin->orig_bytes[0] = ch;
return (char *)bin;
}
static int FILE_control(ErlDrvData drv_data,
unsigned int command,
char *buf, int len,
char **rbuf, int rlen)
{
Desc *desc = (Desc*) drv_data;
ErlDrvBinary* bin;
switch (command) {
case XX_OPEN: {
char file[BUFSIZ]; /* should be FILENAME_MAX */
char flags[4]; /* at most someething like rb+ */
char* src;
char* dst;
char* src_end;
char* dst_end;
if (desc->fp != NULL) {
*rbuf = driver_error(desc->port, XX_EINVAL);
return 1;
}
/* play it safe ? */
src = buf;
src_end = buf + len;
/* get file name */
dst = file;
dst_end = dst + BUFSIZ; /* make room for a '\0' */
while((src < src_end) && (dst < dst_end) && (*src != '\0'))
*dst++ = *src++;
if ((src == src_end) || (dst == dst_end)) {
driver_error(desc->port, XX_EINVAL);
}
*dst = *src++;
/* get flags */
dst = flags;
dst_end = dst + 4;
while((src < src_end) && (dst < dst_end) && (*src != '\0'))
*dst++ = *src++;
if (dst == dst_end) {
*rbuf = driver_error(desc->port, XX_EINVAL);
return 1;
}
*dst = '\0';
if (src + 1 != src_end) {
*rbuf = driver_error(desc->port, XX_EINVAL);
return 1;
}
if ((desc->fp = fopen(file, flags))==NULL) {
*rbuf = driver_error(desc->port, errno);
return 1;
}
*rbuf = driver_ok(desc->port);
return 1;
break;
}
case XX_WRITE: {
if (fwrite(buf, 1, len, desc->fp) != len) {
*rbuf = driver_error(desc->port, errno);
return 1;
}
*rbuf = driver_ok(desc->port);
return 1;
break;
}
case XX_READ: {
char ch = XX_VALUE;
int rval;
int sz = get_int32(buf);
if ((bin = driver_alloc_binary(sz + 1)) == NULL) {
*rbuf = driver_error(desc->port, -1);
return 1;
}
bin->orig_bytes[0] = ch;
if ((rval = fread(bin->orig_bytes + 1, 1, sz, desc->fp)) != sz) {
if (feof(desc->fp)) {
if (rval == 0) {
driver_free_binary(bin);
*rbuf = driver_eof(desc->port);
return 1;
}
bin = driver_realloc_binary(bin, rval + 1);
*rbuf = (char *)bin;
return 1;
}
driver_free_binary(bin);
*rbuf = driver_error(desc->port, errno);
return 1;
}
*rbuf = (char *)bin;
return 1;
}
case XX_SEEK: {
int offs = get_int32(buf);
int w = (int) buf[4];
int whence;
switch (w) {
case 1: whence = SEEK_SET; break;
case 2: whence = SEEK_CUR; break;
case 3: whence = SEEK_END; break;
}
if ((w = fseek(desc->fp, offs, whence)) != 0) {
*rbuf = driver_error(desc->port, errno);
return 1;
}
*rbuf = driver_ok(desc->port);
return 1;
}
case XX_TELL: {
int offs;
if ((offs = ftell(desc->fp)) == -1) {
*rbuf = driver_error(desc->port, errno);
return 1;
}
*rbuf = driver_ret32(desc->port, offs);
return 1;
break;
}
case XX_TRUNCATE: {
int fno;
int offs;
/* is this really safe? */
if (fflush(desc->fp) != 0) {
*rbuf = driver_error(desc->port, errno);
return 1;
}
if ((offs = ftell(desc->fp)) == -1) {
*rbuf = driver_error(desc->port, errno);
return 1;
}
fno = fileno(desc->fp);
#ifdef WIN32
if (SetEndOfFile((HANDLE)fno) != 0) {
*rbuf = driver_error(desc->port, GetLastError());
return 1;
}
#else
if (ftruncate(fno, offs) == -1) {
*rbuf = driver_error(desc->port, errno);
return 1;
}
#endif
*rbuf = driver_ok(desc->port);
return 1;
}
case XX_FLUSH:
if (fflush(desc->fp) != 0)
*rbuf = driver_error(desc->port, errno);
else
*rbuf = driver_ok(desc->port);
return 1;
break;
case XX_OEOF:
if (feof(desc->fp))
*rbuf = driver_ret32(desc->port, 1);
else
*rbuf = driver_ret32(desc->port, 0);
return 1;
break;
case XX_ERROR:
if (ferror(desc->fp))
*rbuf = driver_ret32(desc->port, 1);
else
*rbuf = driver_ret32(desc->port,0);
return 1;
break;
case XX_GETC: {
int ch;
if ((ch = getc(desc->fp)) == EOF) {
if (feof(desc->fp)) {
*rbuf = driver_eof(desc->port);
return 1;
}
*rbuf = driver_error(desc->port, errno);
return 1;
}
*rbuf = driver_ret32(desc->port, ch);
return 1;
break;
}
case XX_SET_LINEBUF_SIZE: {
int sz = get_int32(buf);
desc->linebuf_size = sz;
*rbuf = driver_ok(desc->port);
return 1;
break;
}
case XX_GETS:
case XX_GETS2: {
int rval;
long cpos1, cpos2;
char header;
if ((bin = driver_alloc_binary(desc->linebuf_size + 1)) == NULL) {
*rbuf = driver_error(desc->port, -1);
return 1;
}
if ((cpos1 = ftell(desc->fp)) == -1) {
driver_free_binary(bin);
*rbuf = driver_error(desc->port, errno);
return 1;
}
if ((fgets(bin->orig_bytes + 1, desc->linebuf_size,
desc->fp)) == NULL) {
driver_free_binary(bin);
if (feof(desc->fp)) {
*rbuf = driver_eof(desc->port);
return 1;
}
*rbuf = driver_error(desc->port, errno);
return 1;
}
if ((cpos2 = ftell(desc->fp)) == -1) {
driver_free_binary(bin);
*rbuf = driver_error(desc->port, errno);
return 1;
}
rval = cpos2 - cpos1;
if (bin->orig_bytes[rval] == '\n' &&
bin->orig_bytes[rval + 1] == 0) {
header = XX_FLINE;
/* GETS keep newline, GETS2 remove newline */
rval = rval - (command == XX_GETS ? 0 : 1);
}
else
header = XX_NOLINE;
bin->orig_bytes[0] = header;
bin = driver_realloc_binary(bin, rval + 1);
*rbuf = (char *)bin;
return 1;
}
case XX_UNGETC: {
int ch = buf[0];
if (ungetc(ch, desc->fp) == EOF)
*rbuf = driver_error(desc->port, errno);
else
*rbuf = driver_ok(desc->port);
return 1;
break;
}
default:
#ifdef DEBUG
fprintf(stderr, "Unknown opcode %c\n\r", command);
#endif
*rbuf = driver_error(desc->port, XX_EINVAL);
return 1;
break;
}
}
static void FILE_finish()
{
#ifndef USE_STDIO
/*
* Make sure any remaining buffers are flushed (this is done on exit() by
* the normal stdio).
*/
bbio_cleanup();
#endif
}
/*
* Initialize and return a driver entry struct
*/
DRIVER_INIT(FILE_drv)
{
FILE_driver_entry.init = NULL; /* Not used */
FILE_driver_entry.start = FILE_start;
FILE_driver_entry.stop = FILE_stop;
FILE_driver_entry.output = NULL;
FILE_driver_entry.ready_input = NULL;
FILE_driver_entry.ready_output = NULL;
FILE_driver_entry.driver_name = "FILE_drv";
FILE_driver_entry.finish = FILE_finish;
FILE_driver_entry.outputv = NULL;
FILE_driver_entry.control = FILE_control;
return &FILE_driver_entry;
}

42
bfile/c_src/Makefile Normal file
View File

@ -0,0 +1,42 @@
include ../config/include.mk
## don't build this under win32 at all
ifdef WIN32
PRIV_FILES =
else
PRIV_FILES=../priv/FILE_drv.so
endif
CFLAGS += -I$(ERL_C_INCLUDE_DIR) -I../config -I.
#
# Targets
#
all: $(PRIV_FILES)
clean:
-rm -f $(PRIV_FILES) FILE_drv.o
install:
install -d $(ERLDIR)/lib/bfile
cp -r `pwd` $(ERLDIR)/lib/bfile
cp -r `pwd`/../ebin $(ERLDIR)/lib/bfile
cp -r `pwd`/../priv $(ERLDIR)/lib/bfile
../priv/FILE_drv.so: FILE_drv.o
$(LD_SHARED) -o $@ FILE_drv.o $(LIBS)
FILE_drv.o: FILE_drv.c
$(CC) -o $@ -c -fpic $(CFLAGS) -DDYNAMIC_DRIVER FILE_drv.c

21
bfile/config/Makefile Normal file
View File

@ -0,0 +1,21 @@
MK_INCLUDE=include.mk
CONFIG_H=config.h
all: config.status $(MK_INCLUDE) $(CONFIG_H)
config.status: configure
./configure
$(CONFIG_H) $(MK_INCLUDE): config.status include.mk.in config.h.in
./config.status
configure: configure.in
autoheader
autoconf
clean:
-rm -f config.cache config.log config.status configure \
$(MK_INCLUDE) $(CONFIG_H)
-rm -rf autom4te.cache

269
bfile/config/acconfig.h Normal file
View File

@ -0,0 +1,269 @@
#ifndef _CONFIG_H_
#define _CONFIG_H_
#ifndef WIN32
@TOP@
/*
* This file contains prototypes for config.h.in which autoheader
* could not figure by itself. I.e. if you write your own test which
* defines a macro you will probably have to put it here, but if you
* use any standard test AC_* it will be detected by autoheader.
*/
#undef WIN32
/* Define to a string defining your target. ($target in configure.in) */
#undef CPU_VENDOR_OS
/* Define to the full path of the ifconfig program */
#undef IFCONFIG
/* Define to the full path of the route program */
#undef ROUTE
/* Define to the full path of the arp program */
#undef ARP
/*
* These four below should definately be done away with!!
*/
/* Define if your target OS is a BSD derivative */
#undef BSD
/* Define if your target OS is Linux */
#undef LINUX
/* Define if your target OS is SunOS 5.x */
#undef SOLARIS
/* Define if your target OS is BSD/OS 4.x */
#undef BSDI
/*
* What are these???
*/
/* ? */
#undef USE_IFALIAS
/* Define if you wish to use the bpf interface */
#undef USE_BPF
/* Define if you wish to use the dlpi interface */
#undef USE_DLPI
/* ? */
#undef USE_SOCKET
/* Define if prototypes for malloc can be found in stdlib.h */
#undef STDLIB_MALLOC
/* Define if your include files defines a prototype for sys_errlist[] */
#undef HAVE_SYS_ERRLIST
/* This isn't used anywhere (that I could find) so I don't know what it means*/
#undef IFCONFIG_REQUIRES_DOWN_ADDRESS
/* Define if your OS have broken cmsg fields in the msghdr struct (Linux) */
#undef BROKEN_CMSG_FIELDS
/* Define if sockaddr structure has sa_len member */
#undef SA_LEN_IN_SOCKADDR
/*
* Provide a common way to refer to ints with specific size. (Is this
* used everywhere?) The names used are {u_,}int{8,16,32,64}_t unless
* they are defined in sys/types.h they are defined in ints.h using
* the BIT macros. e.g. if int8_t isn't defined in sys/types.h int8_t
* is typedef:ed to BIT8.
*
*/
/* Define to a basic signed type that is 8 bits in size */
#undef BIT8
/* Define to a basic signed type that is 16 bits in size */
#undef BIT16
/* Define to a basic signed type that is 32 bits in size */
#undef BIT32
/* Define to a basic signed type that is 64 bits in size */
#undef BIT64
/* Define if sys/types.h defines this type */
#undef HAVE_int8_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int8_t
/* Define if sys/types.h defines this type */
#undef HAVE_int16_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int16_t
/* Define if sys/types.h defines this type */
#undef HAVE_int32_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int32_t
/* Define if sys/types.h defines this type */
#undef HAVE_int64_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int64_t
/* */
#undef ETHER_HEADER_USES_ETHER_ADDR
/* */
#undef HAVE_DLIOCRAW
/* */
#undef HAVE_ETHERADDRL
/* */
#undef HAVE_ETHER_ADDR_LEN
/* */
#undef HAVE_MSGHDR_MSG_CONTROL
/* */
#undef HAVE_SIOCGARP
/* */
#undef HAVE_SIOCGIFCONF
/* */
#undef HAVE_SIOCGIFHWADDR
/* */
#undef HAVE_arpreq
/* */
#undef HAVE_caddr_t
/* */
#undef HAVE_ether_header
/* */
#undef HAVE_ethhdr
/* */
#undef HAVE_ifnet
/* */
#undef HAVE_in_addr
/* */
#undef HAVE_sockaddr
/* */
#undef HAVE_sockaddr_dl
/* */
#undef HAVE_sockaddr_in
/* */
#undef NEED_HAVE_sockaddr_dl
/*
* I have yet to figure out what all this need_* stuff is for, shouldn't
* it suffice with using have_* ???
*/
/* */
#undef NEED_LINUX_SOCKIOS_H
/* */
#undef NEED_NETINET_IF_ETHER_H
/* */
#undef NEED_NETINET_IN_H
/* */
#undef NEED_NET_ETHERNET_H
/* */
#undef NEED_NET_IF_ARP_H
/* */
#undef NEED_NET_IF_DL_H
/* */
#undef NEED_NET_IF_H
/* */
#undef NEED_SYS_BITYPES_H
/* */
#undef NEED_SYS_DLPI_H
/* */
#undef NEED_SYS_ETHERNET_H
/* */
#undef NEED_SYS_SOCKETIO_H
/* */
#undef NEED_SYS_SOCKET_H
/* */
#undef NEED_SYS_SOCKIO_H
/* */
#undef NEED_SYS_TYPES_H
/* if we have the openssl with engine support */
#undef HAVE_SSL_ENGINE
/* ... with Rainbow patches */
#undef HAVE_RAINBOW_PATCHES
/* ... with Rainbow's libswift */
#undef HAVE_SWIFT
/* ... with one of our HW checks */
#undef HAVE_LOCAL_ENGINE_SETUP
#undef HAVE_SSL_HW_CHECK
/* ... with patch to get cfg password from card */
#undef HAVE_ENGINE_GET_PASSWORD
/* ... with our buffer patches */
#undef HAVE_SSL_BUFFER_CB
/* */
#undef ISD_SYSTEM_VSN
/* eventpoll */
#undef HAVE_KPOLL
/* Have/use netfilter (a.k.a. iptables) */
#undef HAVE_NETFILTER
/* Non-standard support for "non-local connect()" in Linux 2.4 */
#undef HAVE_NONLOCAL_CONNECT
/* atomic asmebler op in asm/atomic.h ? */
#undef HAVE_ATOMIC_OPS
@BOTTOM@
#endif /* WIN32 */
#endif /* _CONFIG_H_ */

32
bfile/config/aclocal.m4 vendored Normal file
View File

@ -0,0 +1,32 @@
dnl ----------------------------------------------------------------------
dnl
dnl BT_MSG_CONTROL checks for msg_control member in msghdr and that
dnl the cmsg fields aren't broken...
dnl
AC_DEFUN(BT_MSG_CONTROL,
[
AC_CACHE_CHECK([for msg_control member in msghdr],
bt_cv_have_msghdr_msg_control,
[AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>],
[struct msghdr msg;
msg.msg_control;],
bt_cv_have_msghdr_msg_control=yes, bt_cv_have_msghdr_msg_control=no)])
if test $bt_cv_have_msghdr_msg_control = yes; then
AC_DEFINE(HAVE_MSGHDR_MSG_CONTROL)
fi
if test $bt_cv_have_msghdr_msg_control = yes; then
AC_MSG_CHECKING(for broken CMSG_FIELDS)
case "$target_os" in
linux*)
AC_DEFINE(BROKEN_CMSG_FIELDS)
AC_MSG_RESULT(yes)
;;
*)
AC_MSG_RESULT(no)
;;
esac
fi
])

1354
bfile/config/config.guess vendored Executable file

File diff suppressed because it is too large Load Diff

319
bfile/config/config.h.in Normal file
View File

@ -0,0 +1,319 @@
/* config.h.in. Generated from configure.in by autoheader. */
#ifndef _CONFIG_H_
#define _CONFIG_H_
#ifndef WIN32
/*
* This file contains prototypes for config.h.in which autoheader
* could not figure by itself. I.e. if you write your own test which
* defines a macro you will probably have to put it here, but if you
* use any standard test AC_* it will be detected by autoheader.
*/
#undef WIN32
/* Define to a string defining your target. ($target in configure.in) */
#undef CPU_VENDOR_OS
/* Define to the full path of the ifconfig program */
#undef IFCONFIG
/* Define to the full path of the route program */
#undef ROUTE
/* Define to the full path of the arp program */
#undef ARP
/*
* These four below should definately be done away with!!
*/
/* Define if your target OS is a BSD derivative */
#undef BSD
/* Define if your target OS is Linux */
#undef LINUX
/* Define if your target OS is SunOS 5.x */
#undef SOLARIS
/* Define if your target OS is BSD/OS 4.x */
#undef BSDI
/*
* What are these???
*/
/* ? */
#undef USE_IFALIAS
/* Define if you wish to use the bpf interface */
#undef USE_BPF
/* Define if you wish to use the dlpi interface */
#undef USE_DLPI
/* ? */
#undef USE_SOCKET
/* Define if prototypes for malloc can be found in stdlib.h */
#undef STDLIB_MALLOC
/* Define if your include files defines a prototype for sys_errlist[] */
#undef HAVE_SYS_ERRLIST
/* This isn't used anywhere (that I could find) so I don't know what it means*/
#undef IFCONFIG_REQUIRES_DOWN_ADDRESS
/* Define if your OS have broken cmsg fields in the msghdr struct (Linux) */
#undef BROKEN_CMSG_FIELDS
/* Define if sockaddr structure has sa_len member */
#undef SA_LEN_IN_SOCKADDR
/*
* Provide a common way to refer to ints with specific size. (Is this
* used everywhere?) The names used are {u_,}int{8,16,32,64}_t unless
* they are defined in sys/types.h they are defined in ints.h using
* the BIT macros. e.g. if int8_t isn't defined in sys/types.h int8_t
* is typedef:ed to BIT8.
*
*/
/* Define to a basic signed type that is 8 bits in size */
#undef BIT8
/* Define to a basic signed type that is 16 bits in size */
#undef BIT16
/* Define to a basic signed type that is 32 bits in size */
#undef BIT32
/* Define to a basic signed type that is 64 bits in size */
#undef BIT64
/* Define if sys/types.h defines this type */
#undef HAVE_int8_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int8_t
/* Define if sys/types.h defines this type */
#undef HAVE_int16_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int16_t
/* Define if sys/types.h defines this type */
#undef HAVE_int32_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int32_t
/* Define if sys/types.h defines this type */
#undef HAVE_int64_t
/* Define if sys/types.h defines this type */
#undef HAVE_u_int64_t
/* */
#undef ETHER_HEADER_USES_ETHER_ADDR
/* */
#undef HAVE_DLIOCRAW
/* */
#undef HAVE_ETHERADDRL
/* */
#undef HAVE_ETHER_ADDR_LEN
/* */
#undef HAVE_MSGHDR_MSG_CONTROL
/* */
#undef HAVE_SIOCGARP
/* */
#undef HAVE_SIOCGIFCONF
/* */
#undef HAVE_SIOCGIFHWADDR
/* */
#undef HAVE_arpreq
/* */
#undef HAVE_caddr_t
/* */
#undef HAVE_ether_header
/* */
#undef HAVE_ethhdr
/* */
#undef HAVE_ifnet
/* */
#undef HAVE_in_addr
/* */
#undef HAVE_sockaddr
/* */
#undef HAVE_sockaddr_dl
/* */
#undef HAVE_sockaddr_in
/* */
#undef NEED_HAVE_sockaddr_dl
/*
* I have yet to figure out what all this need_* stuff is for, shouldn't
* it suffice with using have_* ???
*/
/* */
#undef NEED_LINUX_SOCKIOS_H
/* */
#undef NEED_NETINET_IF_ETHER_H
/* */
#undef NEED_NETINET_IN_H
/* */
#undef NEED_NET_ETHERNET_H
/* */
#undef NEED_NET_IF_ARP_H
/* */
#undef NEED_NET_IF_DL_H
/* */
#undef NEED_NET_IF_H
/* */
#undef NEED_SYS_BITYPES_H
/* */
#undef NEED_SYS_DLPI_H
/* */
#undef NEED_SYS_ETHERNET_H
/* */
#undef NEED_SYS_SOCKETIO_H
/* */
#undef NEED_SYS_SOCKET_H
/* */
#undef NEED_SYS_SOCKIO_H
/* */
#undef NEED_SYS_TYPES_H
/* if we have the openssl with engine support */
#undef HAVE_SSL_ENGINE
/* ... with Rainbow patches */
#undef HAVE_RAINBOW_PATCHES
/* ... with Rainbow's libswift */
#undef HAVE_SWIFT
/* ... with one of our HW checks */
#undef HAVE_LOCAL_ENGINE_SETUP
#undef HAVE_SSL_HW_CHECK
/* ... with patch to get cfg password from card */
#undef HAVE_ENGINE_GET_PASSWORD
/* ... with our buffer patches */
#undef HAVE_SSL_BUFFER_CB
/* */
#undef ISD_SYSTEM_VSN
/* eventpoll */
#undef HAVE_KPOLL
/* Have/use netfilter (a.k.a. iptables) */
#undef HAVE_NETFILTER
/* Non-standard support for "non-local connect()" in Linux 2.4 */
#undef HAVE_NONLOCAL_CONNECT
/* atomic asmebler op in asm/atomic.h ? */
#undef HAVE_ATOMIC_OPS
/* Description */
#undef DARWIN
/* Define to 1 if you have the <inttypes.h> header file. */
#undef HAVE_INTTYPES_H
/* Define to 1 if you have the <malloc.h> header file. */
#undef HAVE_MALLOC_H
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H
/* Define to 1 if you have the <strings.h> header file. */
#undef HAVE_STRINGS_H
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
/* Define to 1 if you have the <sys/types.h> header file. */
#undef HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H
/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef PACKAGE_NAME
/* Define to the full name and version of this package. */
#undef PACKAGE_STRING
/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME
/* Define to the version of this package. */
#undef PACKAGE_VERSION
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
#endif /* WIN32 */
#endif /* _CONFIG_H_ */

1460
bfile/config/config.sub vendored Executable file

File diff suppressed because it is too large Load Diff

88
bfile/config/configure.in Normal file
View File

@ -0,0 +1,88 @@
AC_INIT
dnl work out who the cpu, vendor and OS are
AC_CANONICAL_SYSTEM
AC_DEFINE_UNQUOTED(CPU_VENDOR_OS, "$target")
dnl Programs
AC_PROG_CC
AC_PATH_PROG(ERL, erl)
AC_PATH_PROG(ERLC, erlc)
ERLBINDIR=`dirname $ERL` ; ERLBINDIR=`dirname $ERLBINDIR`/lib/erlang/bin
ERLDIR=`awk -F= '/ROOTDIR=/ { print [$]2; exit; }' $ERL`
AC_SUBST(ERL)
AC_SUBST(ERLC)
AC_SUBST(ERLBINDIR)
AC_SUBST(ERLDIR)
if test ! -d "$ERLDIR" ; then
AC_MSG_ERROR([Broken Erlang installation, $ERLDIR does not exist!])
fi
dnl C header files
AC_CONFIG_HEADER(config.h:config.h.in)
AC_CHECK_HEADERS(malloc.h)
BT_MSG_CONTROL
case "$target_os" in
*cygwin*)
:
dnl fix this later
;;
linux*)
AC_DEFINE(LINUX)
LD_SHARED="ld -shared"
;;
*bsd*)
AC_DEFINE(BSD)
LD_SHARED="ld -Bshareable"
;;
*solaris*)
AC_DEFINE(SOLARIS)
LD_SHARED="ld -G"
;;
*darwin*)
AC_DEFINE([DARWIN], [], [Description])
LD_SHARED="cc -bundle -flat_namespace -undefined suppress"
;;
*)
LD_SHARED="ld -shared"
;;
esac
AC_SUBST(LD_SHARED)
dnl libnsl and libsocket tests borrowed from ethereal's autoconf scheme.
dnl # msh@cis.ufl.edu says -lnsl (and -lsocket) are needed for his 386/AT,
dnl # to get the SysV transport functions.
dnl # chad@anasazi.com says the Pyramid MIS-ES running DC/OSx (SVR4)
dnl # needs -lnsl.
dnl # The nsl library prevents programs from opening the X display
dnl # on Irix 5.2, according to dickey@clark.net.
AC_CHECK_FUNC(gethostbyname, ,
AC_CHECK_LIB(nsl, gethostbyname, NSL_LIBS="-lnsl"))
AC_SUBST(NSL_LIBS)
dnl # lieder@skyler.mavd.honeywell.com says without -lsocket,
dnl # socket/setsockopt and other routines are undefined under SCO ODT
dnl # 2.0. But -lsocket is broken on IRIX 5.2 (and is not necessary
dnl # on later versions), says simon@lia.di.epfl.ch: it contains
dnl # gethostby* variants that don't use the nameserver (or something).
dnl # -lsocket must be given before -lnsl if both are needed.
dnl # We assume that if connect needs -lnsl, so does gethostbyname.
AC_CHECK_FUNC(connect, ,
AC_CHECK_LIB(socket, connect, SOCKET_LIBS="-lsocket",
AC_MSG_ERROR(Function 'socket' not found.), $NSL_LIBS))
AC_SUBST(SOCKET_LIBS)
dnl
dnl End.
AC_OUTPUT(include.mk)

View File

@ -0,0 +1,75 @@
## -*- makefile -*-
######################################################################
## C
CC := @CC@
CFLAGS := @CFLAGS@ @DEFS@
LD_SHARED := @LD_SHARED@
######################################################################
## Erlang
ERL = @ERL@
ERLC = @ERLC@
ERLDIR = @ERLDIR@
ERL_C_INCLUDE_DIR := $(ERLDIR)/usr/include
ERLC_FLAGS := -W
ifndef no_debug_info
ERLC_FLAGS += +debug_info
endif
ifdef debug
ERLC_FLAGS += -Ddebug
endif
EBIN_DIR := ../ebin
DOC_DIR := ../doc
EMULATOR := beam
ERL_SOURCES := $(wildcard *.erl)
ERL_HEADERS := $(wildcard *.hrl) $(wildcard ../include/*.hrl)
ERL_OBJECTS := $(ERL_SOURCES:%.erl=$(EBIN_DIR)/%.$(EMULATOR))
ERL_DOCUMENTS := $(ERL_SOURCES:%.erl=$(DOC_DIR)/%.html)
# Hmm, don't know if you are supposed to like this better... ;-)
APPSCRIPT = '$$vsn=shift; $$mods=""; while(@ARGV){ $$_=shift; s/^([A-Z].*)$$/\'\''$$1\'\''/; $$mods.=", " if $$mods; $$mods .= $$_; } while(<>) { s/%VSN%/$$vsn/; s/%MODULES%/$$mods/; print; }'
../ebin/%.app: %.app.src ../vsn.mk Makefile
perl -e $(APPSCRIPT) "$(VSN)" $(MODULES) < $< > $@
../ebin/%.appup: %.appup
cp $< $@
$(EBIN_DIR)/%.$(EMULATOR): %.erl
$(ERLC) $(ERLC_FLAGS) -o $(EBIN_DIR) $<
# generate documentation with edoc:
# this is still not the proper way to do it, but it works
# (see the wumpus application for an example)
$(DOC_DIR)/%.html: %.erl
${ERL} -noshell \
-pa ../../syntax_tools/ebin \
-pa ../../edoc/ebin \
-pa ../../xmerl/ebin \
-pa ../../ucs/ebin \
-run edoc file $< -run init stop
mv *.html $(DOC_DIR)
# C linking items
NSL_LIBS = @NSL_LIBS@
SOCKET_LIBS = @SOCKET_LIBS@
# Miscellaneous
GROFF = @GROFF@
PS2PDF = @PS2PDF@

250
bfile/config/install-sh Executable file
View File

@ -0,0 +1,250 @@
#!/bin/sh
#
# install - install a program, script, or datafile
# This comes from X11R5 (mit/util/scripts/install.sh).
#
# Copyright 1991 by the Massachusetts Institute of Technology
#
# Permission to use, copy, modify, distribute, and sell this software and its
# documentation for any purpose is hereby granted without fee, provided that
# the above copyright notice appear in all copies and that both that
# copyright notice and this permission notice appear in supporting
# documentation, and that the name of M.I.T. not be used in advertising or
# publicity pertaining to distribution of the software without specific,
# written prior permission. M.I.T. makes no representations about the
# suitability of this software for any purpose. It is provided "as is"
# without express or implied warranty.
#
# Calling this script install-sh is preferred over install.sh, to prevent
# `make' implicit rules from creating a file called install from it
# when there is no Makefile.
#
# This script is compatible with the BSD install script, but was written
# from scratch. It can only install one file at a time, a restriction
# shared with many OS's install programs.
# set DOITPROG to echo to test this script
# Don't use :- since 4.3BSD and earlier shells don't like it.
doit="${DOITPROG-}"
# put in absolute paths if you don't have them in your path; or use env. vars.
mvprog="${MVPROG-mv}"
cpprog="${CPPROG-cp}"
chmodprog="${CHMODPROG-chmod}"
chownprog="${CHOWNPROG-chown}"
chgrpprog="${CHGRPPROG-chgrp}"
stripprog="${STRIPPROG-strip}"
rmprog="${RMPROG-rm}"
mkdirprog="${MKDIRPROG-mkdir}"
transformbasename=""
transform_arg=""
instcmd="$mvprog"
chmodcmd="$chmodprog 0755"
chowncmd=""
chgrpcmd=""
stripcmd=""
rmcmd="$rmprog -f"
mvcmd="$mvprog"
src=""
dst=""
dir_arg=""
while [ x"$1" != x ]; do
case $1 in
-c) instcmd="$cpprog"
shift
continue;;
-d) dir_arg=true
shift
continue;;
-m) chmodcmd="$chmodprog $2"
shift
shift
continue;;
-o) chowncmd="$chownprog $2"
shift
shift
continue;;
-g) chgrpcmd="$chgrpprog $2"
shift
shift
continue;;
-s) stripcmd="$stripprog"
shift
continue;;
-t=*) transformarg=`echo $1 | sed 's/-t=//'`
shift
continue;;
-b=*) transformbasename=`echo $1 | sed 's/-b=//'`
shift
continue;;
*) if [ x"$src" = x ]
then
src=$1
else
# this colon is to work around a 386BSD /bin/sh bug
:
dst=$1
fi
shift
continue;;
esac
done
if [ x"$src" = x ]
then
echo "install: no input file specified"
exit 1
else
true
fi
if [ x"$dir_arg" != x ]; then
dst=$src
src=""
if [ -d $dst ]; then
instcmd=:
else
instcmd=mkdir
fi
else
# Waiting for this to be detected by the "$instcmd $src $dsttmp" command
# might cause directories to be created, which would be especially bad
# if $src (and thus $dsttmp) contains '*'.
if [ -f $src -o -d $src ]
then
true
else
echo "install: $src does not exist"
exit 1
fi
if [ x"$dst" = x ]
then
echo "install: no destination specified"
exit 1
else
true
fi
# If destination is a directory, append the input filename; if your system
# does not like double slashes in filenames, you may need to add some logic
if [ -d $dst ]
then
dst="$dst"/`basename $src`
else
true
fi
fi
## this sed command emulates the dirname command
dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'`
# Make sure that the destination directory exists.
# this part is taken from Noah Friedman's mkinstalldirs script
# Skip lots of stat calls in the usual case.
if [ ! -d "$dstdir" ]; then
defaultIFS='
'
IFS="${IFS-${defaultIFS}}"
oIFS="${IFS}"
# Some sh's can't handle IFS=/ for some reason.
IFS='%'
set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'`
IFS="${oIFS}"
pathcomp=''
while [ $# -ne 0 ] ; do
pathcomp="${pathcomp}${1}"
shift
if [ ! -d "${pathcomp}" ] ;
then
$mkdirprog "${pathcomp}"
else
true
fi
pathcomp="${pathcomp}/"
done
fi
if [ x"$dir_arg" != x ]
then
$doit $instcmd $dst &&
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi
else
# If we're going to rename the final executable, determine the name now.
if [ x"$transformarg" = x ]
then
dstfile=`basename $dst`
else
dstfile=`basename $dst $transformbasename |
sed $transformarg`$transformbasename
fi
# don't allow the sed command to completely eliminate the filename
if [ x"$dstfile" = x ]
then
dstfile=`basename $dst`
else
true
fi
# Make a temp file name in the proper directory.
dsttmp=$dstdir/#inst.$$#
# Move or copy the file name to the temp name
$doit $instcmd $src $dsttmp &&
trap "rm -f ${dsttmp}" 0 &&
# and set any options; do chmod last to preserve setuid bits
# If any of these fail, we abort the whole thing. If we want to
# ignore errors from any of these, just make sure not to ignore
# errors from the above "$doit $instcmd $src $dsttmp" command.
if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi &&
if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi &&
if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi &&
if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi &&
# Now rename the file to the real destination.
$doit $rmcmd -f $dstdir/$dstfile &&
$doit $mvcmd $dsttmp $dstdir/$dstfile
fi &&
exit 0

25
bfile/src/Makefile Normal file
View File

@ -0,0 +1,25 @@
include ../config/include.mk
include ../vsn.mk
VSN=$(FD_SERVER_VSN)
ifeq ($(TYPE),debug)
DEBUG_FLAGS = -Ddebug
else
DEBUG_FLAGS =
endif
MODULES=bfile
EBIN = ../ebin
EBIN_FILES = $(MODULES:%=$(EBIN)/%.$(EMULATOR)) $(EBIN)/bfile.app
all: $(EBIN_FILES)
debug:
$(MAKE) DEBUG=-DDEBUG
clean:
rm -rf $(EBIN_FILES)

7
bfile/src/bfile.app.src Normal file
View File

@ -0,0 +1,7 @@
{application,bfile,
[{description,"Fast FILE interface"},
{vsn,"%VSN%"},
{modules,[%MODULES%]},
{applications,[kernel,stdlib]},
{env, []},
{mod,{bfile,[]}}]}.

224
bfile/src/bfile.erl Normal file
View File

@ -0,0 +1,224 @@
%%%
%%% File : bfile.erl
%%% Author : Claes Wikstrom <klacke@kaja.klacke.net>
%%% Purpose : Interface to stdio buffered FILE io
%%% Created : 22 Nov 1999 by Claes Wikstrom <klacke@kaja.klacke.net>
%%%----------------------------------------------------------------------
-module(bfile).
-vsn("$Revision: 1.1 $ ").
-author('klacke@kaja.klacke.net').
-export([
load_driver/0,
fopen/2,
fclose/1,
fread/2,
fwrite/2,
feof/1,
ferror/1,
set_linebuf_size/2,
fseek/3,
ftell/1,
ftruncate/1,
fflush/1,
frewind/1,
fgetc/1,
fungetc/2,
fgets/1,
gets/1,
pwrite/3,
pread/3
]).
%% Opcodes
-define(OPEN, $o).
-define(CLOSE, $c).
-define(READ, $r).
-define(WRITE, $w).
-define(SEEK, $s).
-define(TELL, $t).
-define(TRUNCATE, $T).
-define(FLUSH, $f).
-define(OEOF, $e).
-define(ERROR, $E).
-define(GETC, $g).
-define(GETS, $G).
-define(GETS2, $2).
-define(SET_LINEBUF_SIZE, $S).
-define(UNGETC, $u).
%% ret codes
-define(VALUE, $v).
-define(FLINE, $L).
-define(OK, $o).
-define(I32, $O).
-define(NOLINE,$N).
-define(FERROR, $E).
-define(REOF, $x).
-define(int32(X),
[((X) bsr 24) band 16#ff, ((X) bsr 16) band 16#ff,
((X) bsr 8) band 16#ff, (X) band 16#ff]).
%% Bytes to unsigned
-define(u32(X3,X2,X1,X0),
(((X3) bsl 24) bor ((X2) bsl 16) bor ((X1) bsl 8) bor (X0))).
%% Bytes to signed
-define(i32(X3,X2,X1,X0),
(?u32(X3,X2,X1,X0) -
(if (X3) > 127 -> 16#100000000; true -> 0 end))).
load_driver() ->
Dir = filename:join([filename:dirname(code:which(bfile)),"..", "priv"]),
erl_ddll:load_driver(Dir, "FILE_drv").
%% Flags = "r" | "w" | ... etc, see fopen(3)
%% Ret: {ok, Fd} | {error, Reason}
fopen(Fname, Flags) ->
P = open_port({spawn, 'FILE_drv'}, [binary]),
Res = erlang_port_control(P, ?OPEN, [Fname, 0, Flags, 0]),
case decode(Res) of
ok ->
{ok, {bfile, P}};
Err ->
unlink(P),
exit(P, die),
Err
end.
%% void()
fclose({bfile, Fd}) ->
unlink(Fd),
catch erlang:port_close(Fd).
%% {ok, #Bin} | {error, Reason} | eof
fread({bfile, Fd}, Sz) ->
Res = erlang_port_control(Fd, ?READ, ?int32(Sz)),
decode(Res).
%% ok | {error, Reason}
fwrite({bfile, Fd}, IoList) ->
Res = erlang_port_control(Fd, ?WRITE, IoList),
decode(Res).
%% ok | {error, Reason}
pwrite(BFd, Pos, IoList) ->
case fseek(BFd, Pos, seek_set) of
ok ->
fwrite(BFd, IoList);
Error ->
Error
end.
%% {ok, #Bin} | {error, Reason} | eof
pread(BFd, Pos, Sz) ->
case fseek(BFd, Pos, seek_set) of
ok ->
fread(BFd, Sz);
Error ->
Error
end.
%% bool
feof({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?OEOF, []),
bool(decode(Res)).
%% bool
ferror({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?ERROR, []),
bool(decode(Res)).
%% void()
set_linebuf_size({bfile, Fd}, Sz) ->
Res = erlang_port_control(Fd, ?SET_LINEBUF_SIZE, ?int32(Sz)),
decode(Res).
%% Whence == seek_set | seek_cur || seek_end
%% ok | {error, Reason}
fseek({bfile, Fd}, Offs, Whence) ->
Res = erlang_port_control(Fd, ?SEEK, [?int32(Offs), whence_enc(Whence)]),
decode(Res).
%% {ok, Int} | {error, Reason}
ftell({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?TELL, []),
decode(Res).
%% ok | {error, Reason}
ftruncate({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?TRUNCATE, []),
decode(Res).
%% ok | {error, Reason}
fflush({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?FLUSH, []),
decode(Res).
%% ok | {error, Reason}
frewind(BFd) ->
fseek(BFd, 0, seek_set).
%% {ok, Char} | {error, Reason} | eof
fgetc({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?GETC, []),
decode(Res).
%% ok | {error, Reason}
fungetc({bfile, Fd}, Char) ->
Res = erlang_port_control(Fd, ?UNGETC, [Char]),
decode(Res).
%% {line, #Bin} | {noline, #Bin} | {error, Reason} | eof
%% including newline
fgets({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?GETS, []),
decode(Res).
%% {line, #Bin} | {noline, #Bin} | {error, Reason} | eof
%% not including newline
gets({bfile, Fd}) ->
Res = erlang_port_control(Fd, ?GETS2, []),
decode(Res).
whence_enc(seek_set) ->
1;
whence_enc(seek_cur) ->
2;
whence_enc(seek_end) ->
3.
bool({ok, 1}) ->
true;
bool({ok, 0}) ->
false.
decode(Res) ->
case Res of
<<?VALUE, Bin/binary>> ->
{ok, Bin};
<<?FLINE, Bin/binary>> ->
{line, Bin};
<<?OK>> ->
ok;
<<?I32, X1, X2, X3, X4>> ->
{ok, ?i32(X1, X2, X3, X4)};
<<?NOLINE, Bin/binary>> ->
{noline, Bin};
<<?FERROR, Err/binary>> ->
{error, list_to_atom(binary_to_list(Err))};
<<?REOF>> ->
eof
end.
erlang_port_control(P, C, Data) ->
erlang:port_control(P, C, Data).

19
bfile/tests/read.erl Normal file
View File

@ -0,0 +1,19 @@
-module(read).
-export([start/1, start/2]).
scan_file(F, Readsize, Total) ->
Rd = bfile:fread(F, Readsize),
case Rd of
{ok, Bin} -> scan_file(F, Readsize, size(Bin)+Total);
eof -> Total
end.
scan_file(F, Readsize) -> scan_file(F, Readsize, 0).
start(File, Readsize) ->
bfile:load_driver(),
{ok, F} = bfile:fopen(File, "r"),
T = scan_file(F, Readsize),
io:format("read ~p bytes~n", [T]),
bfile:fclose(F).
start(File) ->
start(File, 512*1024).

18
bfile/tests/readold.erl Normal file
View File

@ -0,0 +1,18 @@
-module(readold).
-export([start/1, start/2]).
scan_file(F, Readsize, Total) ->
Rd = file:read(F, Readsize),
case Rd of
{ok, Bin} -> scan_file(F, Readsize, size(Bin)+Total);
eof -> Total
end.
scan_file(F, Readsize) -> scan_file(F, Readsize, 0).
start(File, Readsize) ->
{ok, F} = file:open(File, [raw, binary, read]),
T = scan_file(F, Readsize),
io:format("read ~p bytes~n", [T]),
file:close(F).
start(File) ->
start(File, 512*1024).

17
bfile/tests/write.erl Normal file
View File

@ -0,0 +1,17 @@
-module(write).
-export([start/2, start/3]).
dump_file(F, Data, 0) ->
ok;
dump_file(F, Data, N) ->
bfile:fwrite(F, Data),
dump_file(F, Data, N - 1).
start(File, Data, N) ->
bfile:load_driver(),
{ok, F} = bfile:fopen(File, "w"),
dump_file(F, Data, N),
bfile:fclose(F).
start(File, N) ->
Data = list_to_binary(lists:duplicate(1000000, 10)),
start(File, Data, N).

16
bfile/tests/writeold.erl Normal file
View File

@ -0,0 +1,16 @@
-module(writeold).
-export([start/2, start/3]).
dump_file(F, Data, 0) ->
ok;
dump_file(F, Data, N) ->
file:write(F, Data),
dump_file(F, Data, N - 1).
start(File, Data, N) ->
{ok, F} = file:open(File, [raw, binary, write]),
dump_file(F, Data, N),
file:close(F).
start(File, N) ->
Data = list_to_binary(lists:duplicate(1000000, 10)),
start(File, Data, N).

1
bfile/vsn.mk Normal file
View File

@ -0,0 +1 @@
BFILE_VSN=1.0

381
dns/src/dns.erl Normal file
View File

@ -0,0 +1,381 @@
%%%-------------------------------------------------------------------
%% @copyright Process One 2008-2009
%% @author Geoff Cant <geoff.cant@process-one.net>
%% @author Geoff Cant <nem@erlang.geek.nz>
%% @version {@vsn}, {@date} {@time}
%% @doc DNS Lookup and utility functions.
%%
%% Provides a programmer-friendly API for a number of undocumented OTP
%% dns lookup, resolution, caching and configuration functions.
%%
%% Also provides utility functions for performing lookups while
%% bypassing local resolver caching, finding closest parent zones,
%% parsing `resolv.conf' files, simplifying #dns_rec{} answers and more.
%% @end
%%%-------------------------------------------------------------------
-module(dns).
-include_lib("eunit/include/eunit.hrl").
%% API
-export([lookup/2
,lookup/3
,lookup/4
,lookup/5
,lookup/7
,lookup_cache/3
,cache_lookup/1
,simplify/1]).
-export([find_soa/1
,nameservers/1
,nameservers/2
,nameserver_address/1
,direct_lookup/3
,info/2
,to_proplist/1
,parse_resolv/1
,domain_exists/1
,expand_options/1
,resolvers/0
]).
-include_lib("kernel/src/inet_dns.hrl").
-include_lib("kernel/include/inet.hrl").
%% @type query_class() = in.
%% An atom with the name of a DNS query class. `in' is the only class
%% used (and probably tested) in the OTP lookup code.
%% @type query_type() = a | cname | soa | mx | ns | srv | any.
%% An atom with the name of a DNS query type. This list is not
%% exhaustive.
%% @type simple_rr() = {Name::string(), query_type(), RRdata::term(), [simple_rr_info()]}.
%% A simplified version of #dns_rr{} resource records.
%% @type simple_rr_info() = {ttl, TimeToLive::integer()} | {class, query_class()}.
%% @type ip_address() = {integer(),integer(),integer(),integer()}.
%% @type address() = ip_address() | {ip_address(), port_no()} |
%% string() | #dns_rr{}.
%% @type port_no() = integer().
%% @type resolver() = {ip_address(), port_no()}.
%% @type query_options() = [query_option()].
%% A proplist of configuration options for lookup behaviour.
%% @type query_option() = {read_cache, bool()} |
%% {write_cache, bool()} |
%% {timeout, TimeOut::integer()} |
%% {servers, [address()]} |
%% {class, query_class()} |
%% defaults | read_cached.
%% <ul>
%% <li>`read_cache' - if `true' (default: `false'), return results from the `inet_db' cache
%% before making a query over the network.</li>
%% <li>`write_cache' - if `true' (default: `false'), write successful query result RRs to
%% the `inet_db' cache</li>
%% <li>`timeout' - number of milliseconds (default: 5000) to wait for a response from a
%% nameserver.</li>
%% <li>`servers' - a list of nameservers to query for the RRs. Defaults
%% to `inet_db:res_option(nameserver)' which is usually the nameservers
%% specified in '/etc/resolv.conf'</li>
%% <li>`class' - record class to query for (default: `in').</li>
%% <li>`defaults' - shorthand for
%% <code>
%% [{servers, dns:resolvers()},
%% {read_cache, false}, {write_cache, false},
%% {timeout, timer:seconds(5)}, {class, in}]
%% </code>
%% </li>
%% <li>`read_cached' - shorthand for
%% <code>
%% [{servers, dns:resolvers()},
%% {read_cache, true}, {write_cache, false},
%% {timeout, timer:seconds(5)}, {class, in}]
%% </code>
%% </li>
%% </ul>
%%====================================================================
%% RR lookup API
%%====================================================================
%% @spec lookup(Name::string(), query_type()) -> #dns_res{}
%% @doc Query for a DNS record of Type for Name. Uses reasonable default
%% options for class (`in') timeouts (5s), caching (no caching) and
%% nameservers (`inet_db' defaults).
%% @end
%% @equiv lookup(Name, Type, [defaults])
lookup(Name, Type)
when is_list(Name), is_atom(Type) ->
lookup(Name, Type, [defaults]).
%% @spec lookup(Name::string(), query_type(), query_options()) -> #dns_res{}
%% @doc Query for a DNS record of Type for Name. Takes a variety of
%% query options.
%% @end
lookup(Name, Type, Options)
when is_list(Name), is_atom(Type),
is_list(Options) ->
lookup2(Name, Type, expand_options(Options)).
%% @private
lookup2(Name, Type, Options) ->
Timeout = proplists:get_value(timeout, Options, timer:seconds(5)),
Servers = [nameserver_address(R)
|| R <- proplists:get_value(servers, Options, resolvers())],
Class = proplists:get_value(class, Options, in),
ReadCache = proplists:get_value(read_cache, Options, false),
WriteCache = proplists:get_value(write_cache, Options, false),
lookup(Name, Class, Type, Servers, Timeout, ReadCache, WriteCache).
%% @spec lookup(Name::string(), query_type(),
%% NameServers, Timeout::integer()) -> #dns_res{}
%% where NameServers = [resolver()]
%% @doc Query the given Nameservers for a DNS record of Type (class `in') for
%% Name. Takes a Timeout in milliseconds. Doesn't read or write the
%% `inet_db' RR cache.
%% @equiv lookup(Name, in, Type, Servers, Timeout, false, false)
lookup(Name, Type, Servers, Timeout)
when is_list(Name), is_atom(Type),
is_list(Servers), is_integer(Timeout) ->
lookup(Name, in, Type, Servers, Timeout).
%% @spec lookup(Name::string(), query_class(), query_type(),
%% [resolver()], Timeout::integer()) -> #dns_res{}
%% @doc Query the given Nameservers for a DNS record of Class, Type for
%% Name. Takes a Timeout in milliseconds. Doesn't read or write the
%% `inet_db' RR cache.
%% @equiv lookup(Name, Class, Type, Servers, Timeout, false, false)
lookup(Name, Class, Type, Servers, Timeout)
when is_list(Name), is_atom(Class), is_atom(Type),
is_list(Servers), is_integer(Timeout) ->
lookup(Name, Class, Type, Servers, Timeout, false, false).
%% @spec lookup(Name::string(), class(), query_type(),
%% Servers::[address()], Timeout::integer(),
%% ReadCache::bool(), WriteCache::bool()) -> #dns_res{}
%% @doc Query the given Nameservers for a DNS record of Class, Type for
%% Name. Takes a Timeout in milliseconds. Returns results from the
%% `inet_db' RR cache if available and ReadCache is `true'. Writes
%% successful query answers to the cache if WriteCache is `true'.
%% @end
%% Query inet_db cache.
lookup(Name, Class = in, Type, Servers, Timeout,
_ReadCache = true, WriteCache) ->
case lookup_cache(Class, Name, Type) of
{ok, Answer} -> {ok, Answer};
{error, nxdomain} ->
lookup(Name, Class, Type, Servers, Timeout, false, WriteCache)
end;
%% Perform DNS lookup and write results to inet_db cache
lookup(Name, Class, Type, Servers, Timeout,
_ReadCache, _WriteCache = true) ->
case lookup(Name, Class, Type, Servers, Timeout, false, false) of
{ok, Rec} -> cache_lookup(Rec), Rec;
Else -> Else
end;
%% Lookup via DNS
lookup(Name, Class, Type, Servers, Timeout,
_ReadCache = false, _WriteCache = false) ->
inet_res:nnslookup(Name, Class, Type, Servers, Timeout).
%% @private
%% Process options list
expand_options(Opts) ->
proplists:expand(option_expansions(), Opts).
%% @private
option_expansions() ->
[{defaults, [{servers, resolvers()},
{timeout, timer:seconds(5)},
{read_cache, false},
{write_cache, false}]}
,{read_cached, [{servers, resolvers()},
{timeout, timer:seconds(5)},
{read_cache, true},
{write_cache, false}]}
].
%% @spec simplify(Result) -> {error, Reason::term()} | [simple_rr()]
%% where Result = {ok, #dns_rec{}} | {error, Reason::term()}
%% @doc Simplify the records returned from lookup to fixed-format
%% tuples instead of records.
%% @end
simplify({ok, #dns_rec{anlist=A}}) ->
{ok, [{Name, Type, Data, [{ttl, TTL},{class,Class}]}
|| #dns_rr{domain=Name,class=Class,
type=Type,data=Data,
ttl=TTL} <- A]};
simplify(E) -> E.
%%====================================================================
%% Cache API
%%====================================================================
%% @spec lookup_cache(query_class(), Name::string(), query_type()) ->
%% {ok, #dns_rec{}} | {error, Reason::term()}
%% @doc Query `inet_db' RR cache. Converts the `inet_db' `#hostent{}' respone
%% into a fake `#dns_rec{}'.
lookup_cache(Class, Name, Type) ->
case inet_db:getbyname(Name, Type) of
{ok, #hostent{h_addr_list=Answers}} ->
%% Convert hostents to fake dns records
RRs = [#dns_rr{domain=Name, class=Class,
type=Type, ttl=cached,
data=D}
|| D <- Answers],
{ok, #dns_rec{header=cached, anlist=RRs}};
Else -> Else
end.
%% @spec cache_lookup(#dns_rec{}) -> ok
%% @doc Store dns answer resource records in inet_db cache
cache_lookup(#dns_rec{anlist=RRs}) ->
lists:foreach(fun inet_db:add_rr/1, RRs),
ok.
%%====================================================================
%% Utility API
%%====================================================================
%% @spec resolvers() -> [resolver()]
%% @doc Returns a list of name servers that can be used as recursive
%% resolvers. Resolvers taken from the `inet_db' `namserver' setting.
resolvers() ->
inet_db:res_option(nameserver).
%% @spec find_soa(Name::string()) -> {ok, {SoaName::string(), #dns_rr{}}} |
%% {error, Reason::term()}
%% @doc Recursively climb the ancestry of a domain name to find the
%% most specific SOA. (Closest domain delegation/authority)
%% Given `foo.bar.baz.com' would try `foo.bar.baz.com' then `bar.baz.com'
%% then `baz.com' and so on.
find_soa(Name) ->
Components = string:tokens(Name, "."),
find_soa2(Components).
%% @private
find_soa2([]) ->
{error, nxdomain};
find_soa2(Components) ->
Name = string:join(Components,"."),
case lookup(Name, soa) of
{ok, #dns_rec{anlist=[RR = #dns_rr{domain=Name,type=soa}]}} ->
{ok, {Name, RR}};
{error, nxdomain} ->
find_soa2(tl(Components));
Else -> Else
end.
%% @spec domain_exists(DomainName::string()) -> bool()
%% @doc Returns `true' if a name exists and has an SOA record.
domain_exists(Name) ->
case lookup(Name, soa) of
{ok, #dns_rec{anlist=[#dns_rr{domain=Name,type=soa}]}} ->
true;
{error, nxdomain} ->
false;
Else -> erlang:error(Else)
end.
%% @spec parse_resolv(FileName::string()) -> [ip_address()]
%% @doc Returns a list of nameservers from a POSIX style `resolv.conf' file.
parse_resolv(File) ->
{ok, Rs} = inet_parse:resolv(File),
[NS || {nameserver,NS} <- Rs].
%% @spec nameservers(Domain::string()) -> [resolver()]
%% @equiv nameservers(Domain, [read_cached])
nameservers(Domain) -> nameservers(Domain, [read_cached]).
%% @spec nameservers(Domain::string(), query_options()) -> [resolver()]
%% @doc Retrieve the names and addresses of the authoritative
%% nameservers for Domain. Will perform one NS lookup if the
%% resolving nameserver returns the address records for the queried
%% records, otherwise will perform 1 + N lookups (N = number of NS
%% records for Domain). Takes a list of query option that will be used
%% for NS lookups.
nameservers(Domain, Options) ->
case lookup(Domain, ns, Options) of
E = {error, _} -> E;
{ok, #dns_rec{anlist=RRs, arlist=AR}} ->
Names = [Name
|| #dns_rr{data=Name,type=ns,domain=D} <- RRs,
D =:= Domain],
Additional = [Addr || #dns_rr{data=Addr,type=a,domain=Name} <- AR,
lists:member(Name, Names)],
if length(Additional) > 0 ->
[nameserver_address(Addr) || Addr <- Additional];
true ->
[nameserver_address(RR) || RR <- RRs]
end
end.
%% @spec nameserver_address(address()) -> resolver() | error
%% @doc
%% Convert a variety of nameserver address specifications into a
%% host-port tuple for use with `gen_udp' and `inet_res'.
%% @end
%% @todo Should take/respect query options instead of calling inet:getaddr/2.
nameserver_address(IP = {_, _, _, _}) -> {IP,53};
nameserver_address(Addr = {{_, _, _, _}, _}) -> Addr;
nameserver_address(Name) when is_list(Name) ->
case inet:getaddr(Name, inet) of
{ok, IP} -> {IP, 53};
_ -> error
end;
nameserver_address(#dns_rr{data=Name,type=ns}) ->
nameserver_address(Name).
%% @spec direct_lookup(Name::string(), query_type(), Domain::string())
%% -> #dns_res{}
%% @doc Lookup the given Name/Type against the authoritative NSs for
%% Domain. This will bypass nxdomain caching and should result in
%% quicker recognition of changed/added records.
%% This is mainly intended for checking if people have setup a set of
%% DNS records correctly (say for a white-label hosting service).
direct_lookup(Name, Type, Domain) ->
Servers = [{A,53} || {_NS, A} <- nameservers(Domain)],
lookup(Name, Type, [{servers, Servers}]).
%%====================================================================
%% inet record manipulation and access API
%%====================================================================
%% @private
info(Field, Rec) ->
Fields = fields(Rec),
FieldIdx = lists:zip(Fields, lists:seq(2,length(Fields)+1)),
element(proplists:get_value(Field,FieldIdx), Rec).
%% @private
fields(#dns_rec{}) -> fields(dns_rec);
fields(dns_rec) -> record_info(fields, dns_rec);
fields(#dns_rr{}) -> fields(dns_rr);
fields(dns_rr) -> record_info(fields, dns_rr).
%% @private
to_proplist(R) ->
Keys = fields(R),
Values = tl(tuple_to_list(R)),
lists:zip(Keys,Values).
%%====================================================================
%% Unit Tests
%%====================================================================
%% @todo Add more unit tests.
%% @private
nameserver_address_test_() ->
T = [{{1,2,3,4}, {{1,2,3,4},53}},
{{{1,2,3,4},53}, {{1,2,3,4},53}},
{#dns_rr{data={1,2,3,4},type=ns}, {{1,2,3,4},53}},
{"localhost", {{127,0,0,1},53}},
{#dns_rr{data="localhost",type=ns}, {{127,0,0,1},53}}],
[ ?_assertMatch(C when C =:= B, nameserver_address(A))
|| {A,B} <- T].

5
ejabberd-dev/README.txt Normal file
View File

@ -0,0 +1,5 @@
ejabberd-dev is an helper module containing include files from the ejabberd
project.
This should allow to develop or build ejabberd modules without a complete
development version of ejabberd (for example with a binary version of ejabberd).

View File

@ -0,0 +1,36 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-record(adhoc_request, {lang,
node,
sessionid,
action,
xdata,
others}).
-record(adhoc_response, {lang,
node,
sessionid,
status,
defaultaction = "",
actions = [],
notes = [],
elements = []}).

View File

@ -0,0 +1,64 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
%% This macro returns a string of the ejabberd version running, e.g. "2.3.4"
%% If the ejabberd application description isn't loaded, returns atom: undefined
-define(VERSION, element(2, application:get_key(ejabberd,vsn))).
-define(MYHOSTS, ejabberd_config:get_global_option(hosts)).
-define(MYNAME, hd(ejabberd_config:get_global_option(hosts))).
-define(MYLANG, ejabberd_config:get_global_option(language)).
-define(MSGS_DIR, "msgs").
-define(CONFIG_PATH, "ejabberd.cfg").
-define(LOG_PATH, "ejabberd.log").
-define(EJABBERD_URI, "http://www.process-one.net/en/ejabberd/").
-define(S2STIMEOUT, 600000).
%%-define(DBGFSM, true).
-record(scram, {storedkey, serverkey, salt, iterationcount}).
-define(SCRAM_DEFAULT_ITERATION_COUNT, 4096).
%% ---------------------------------
%% Logging mechanism
%% Print in standard output
-define(PRINT(Format, Args),
io:format(Format, Args)).
-define(DEBUG(Format, Args),
ejabberd_logger:debug_msg(?MODULE,?LINE,Format, Args)).
-define(INFO_MSG(Format, Args),
ejabberd_logger:info_msg(?MODULE,?LINE,Format, Args)).
-define(WARNING_MSG(Format, Args),
ejabberd_logger:warning_msg(?MODULE,?LINE,Format, Args)).
-define(ERROR_MSG(Format, Args),
ejabberd_logger:error_msg(?MODULE,?LINE,Format, Args)).
-define(CRITICAL_MSG(Format, Args),
ejabberd_logger:critical_msg(?MODULE,?LINE,Format, Args)).

View File

@ -0,0 +1,52 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-record(ejabberd_commands, {name, tags = [],
desc = "", longdesc = "",
module, function,
args = [], result = rescode}).
%% @type ejabberd_commands() = #ejabberd_commands{
%% name = atom(),
%% tags = [atom()],
%% desc = string(),
%% longdesc = string(),
%% module = atom(),
%% function = atom(),
%% args = [aterm()],
%% result = rterm()
%% }.
%% desc: Description of the command
%% args: Describe the accepted arguments.
%% This way the function that calls the command can format the
%% arguments before calling.
%% @type atype() = integer | string | {tuple, [aterm()]} | {list, aterm()}.
%% Allowed types for arguments are integer, string, tuple and list.
%% @type rtype() = integer | string | atom | {tuple, [rterm()]} | {list, rterm()} | rescode | restuple.
%% A rtype is either an atom or a tuple with two elements.
%% @type aterm() = {Name::atom(), Type::atype()}.
%% An argument term is a tuple with the term name and the term type.
%% @type rterm() = {Name::atom(), Type::rtype()}.
%% A result term is a tuple with the term name and the term type.

View File

@ -0,0 +1,28 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-record(config, {key, value}).
-record(local_config, {key, value}).
-record(state, {opts = [],
hosts = [],
override_local = false,
override_global = false,
override_acls = false}).

View File

@ -0,0 +1,25 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-define(STATUS_SUCCESS, 0).
-define(STATUS_ERROR, 1).
-define(STATUS_USAGE, 2).
-define(STATUS_BADRPC, 3).

View File

@ -0,0 +1,336 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-define(NS_DISCO_ITEMS, "http://jabber.org/protocol/disco#items").
-define(NS_DISCO_INFO, "http://jabber.org/protocol/disco#info").
-define(NS_VCARD, "vcard-temp").
-define(NS_VCARD_UPDATE, "vcard-temp:x:update").
-define(NS_AUTH, "jabber:iq:auth").
-define(NS_AUTH_ERROR, "jabber:iq:auth:error").
-define(NS_REGISTER, "jabber:iq:register").
-define(NS_SEARCH, "jabber:iq:search").
-define(NS_ROSTER, "jabber:iq:roster").
-define(NS_ROSTER_VER, "urn:xmpp:features:rosterver").
-define(NS_PRIVACY, "jabber:iq:privacy").
-define(NS_BLOCKING, "urn:xmpp:blocking").
-define(NS_PRIVATE, "jabber:iq:private").
-define(NS_VERSION, "jabber:iq:version").
-define(NS_TIME90, "jabber:iq:time"). % TODO: Remove once XEP-0090 is Obsolete
-define(NS_TIME, "urn:xmpp:time").
-define(NS_LAST, "jabber:iq:last").
-define(NS_XDATA, "jabber:x:data").
-define(NS_IQDATA, "jabber:iq:data").
-define(NS_DELAY91, "jabber:x:delay"). % TODO: Remove once XEP-0091 is Obsolete
-define(NS_DELAY, "urn:xmpp:delay").
-define(NS_EXPIRE, "jabber:x:expire").
-define(NS_EVENT, "jabber:x:event").
-define(NS_CHATSTATES, "http://jabber.org/protocol/chatstates").
-define(NS_XCONFERENCE, "jabber:x:conference").
-define(NS_STATS, "http://jabber.org/protocol/stats").
-define(NS_MUC, "http://jabber.org/protocol/muc").
-define(NS_MUC_USER, "http://jabber.org/protocol/muc#user").
-define(NS_MUC_ADMIN, "http://jabber.org/protocol/muc#admin").
-define(NS_MUC_OWNER, "http://jabber.org/protocol/muc#owner").
-define(NS_MUC_UNIQUE, "http://jabber.org/protocol/muc#unique").
-define(NS_PUBSUB, "http://jabber.org/protocol/pubsub").
-define(NS_PUBSUB_EVENT, "http://jabber.org/protocol/pubsub#event").
-define(NS_PUBSUB_OWNER, "http://jabber.org/protocol/pubsub#owner").
-define(NS_PUBSUB_NMI, "http://jabber.org/protocol/pubsub#node-meta-info").
-define(NS_PUBSUB_ERRORS,"http://jabber.org/protocol/pubsub#errors").
-define(NS_PUBSUB_NODE_CONFIG, "http://jabber.org/protocol/pubsub#node_config").
-define(NS_PUBSUB_SUB_OPTIONS, "http://jabber.org/protocol/pubsub#subscribe_options").
-define(NS_PUBSUB_SUB_AUTH, "http://jabber.org/protocol/pubsub#subscribe_authorization").
-define(NS_PUBSUB_GET_PENDING, "http://jabber.org/protocol/pubsub#get-pending").
-define(NS_COMMANDS, "http://jabber.org/protocol/commands").
-define(NS_BYTESTREAMS, "http://jabber.org/protocol/bytestreams").
-define(NS_ADMIN, "http://jabber.org/protocol/admin").
-define(NS_SERVERINFO, "http://jabber.org/network/serverinfo").
-define(NS_RSM, "http://jabber.org/protocol/rsm").
-define(NS_EJABBERD_CONFIG, "ejabberd:config").
-define(NS_STREAM, "http://etherx.jabber.org/streams").
-define(NS_STANZAS, "urn:ietf:params:xml:ns:xmpp-stanzas").
-define(NS_STREAMS, "urn:ietf:params:xml:ns:xmpp-streams").
-define(NS_TLS, "urn:ietf:params:xml:ns:xmpp-tls").
-define(NS_SASL, "urn:ietf:params:xml:ns:xmpp-sasl").
-define(NS_SESSION, "urn:ietf:params:xml:ns:xmpp-session").
-define(NS_BIND, "urn:ietf:params:xml:ns:xmpp-bind").
-define(NS_FEATURE_IQAUTH, "http://jabber.org/features/iq-auth").
-define(NS_FEATURE_IQREGISTER, "http://jabber.org/features/iq-register").
-define(NS_FEATURE_COMPRESS, "http://jabber.org/features/compress").
-define(NS_FEATURE_MSGOFFLINE, "msgoffline").
-define(NS_COMPRESS, "http://jabber.org/protocol/compress").
-define(NS_CAPS, "http://jabber.org/protocol/caps").
-define(NS_SHIM, "http://jabber.org/protocol/shim").
-define(NS_ADDRESS, "http://jabber.org/protocol/address").
%% CAPTCHA related NSes.
-define(NS_OOB, "jabber:x:oob").
-define(NS_CAPTCHA, "urn:xmpp:captcha").
-define(NS_MEDIA, "urn:xmpp:media-element").
-define(NS_BOB, "urn:xmpp:bob").
% TODO: remove "code" attribute (currently it used for backward-compatibility)
-define(STANZA_ERROR(Code, Type, Condition),
{xmlelement, "error",
[{"code", Code}, {"type", Type}],
[{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []}]}).
-define(ERR_BAD_FORMAT,
?STANZA_ERROR("406", "modify", "bad-format")).
-define(ERR_BAD_REQUEST,
?STANZA_ERROR("400", "modify", "bad-request")).
-define(ERR_CONFLICT,
?STANZA_ERROR("409", "cancel", "conflict")).
-define(ERR_FEATURE_NOT_IMPLEMENTED,
?STANZA_ERROR("501", "cancel", "feature-not-implemented")).
-define(ERR_FORBIDDEN,
?STANZA_ERROR("403", "auth", "forbidden")).
-define(ERR_GONE,
?STANZA_ERROR("302", "modify", "gone")).
-define(ERR_INTERNAL_SERVER_ERROR,
?STANZA_ERROR("500", "wait", "internal-server-error")).
-define(ERR_ITEM_NOT_FOUND,
?STANZA_ERROR("404", "cancel", "item-not-found")).
-define(ERR_JID_MALFORMED,
?STANZA_ERROR("400", "modify", "jid-malformed")).
-define(ERR_NOT_ACCEPTABLE,
?STANZA_ERROR("406", "modify", "not-acceptable")).
-define(ERR_NOT_ALLOWED,
?STANZA_ERROR("405", "cancel", "not-allowed")).
-define(ERR_NOT_AUTHORIZED,
?STANZA_ERROR("401", "auth", "not-authorized")).
-define(ERR_PAYMENT_REQUIRED,
?STANZA_ERROR("402", "auth", "payment-required")).
-define(ERR_RECIPIENT_UNAVAILABLE,
?STANZA_ERROR("404", "wait", "recipient-unavailable")).
-define(ERR_REDIRECT,
?STANZA_ERROR("302", "modify", "redirect")).
-define(ERR_REGISTRATION_REQUIRED,
?STANZA_ERROR("407", "auth", "registration-required")).
-define(ERR_REMOTE_SERVER_NOT_FOUND,
?STANZA_ERROR("404", "cancel", "remote-server-not-found")).
-define(ERR_REMOTE_SERVER_TIMEOUT,
?STANZA_ERROR("504", "wait", "remote-server-timeout")).
-define(ERR_RESOURCE_CONSTRAINT,
?STANZA_ERROR("500", "wait", "resource-constraint")).
-define(ERR_SERVICE_UNAVAILABLE,
?STANZA_ERROR("503", "cancel", "service-unavailable")).
-define(ERR_SUBSCRIPTION_REQUIRED,
?STANZA_ERROR("407", "auth", "subscription-required")).
-define(ERR_UNEXPECTED_REQUEST,
?STANZA_ERROR("400", "wait", "unexpected-request")).
-define(ERR_UNEXPECTED_REQUEST_CANCEL,
?STANZA_ERROR("401", "cancel", "unexpected-request")).
%-define(ERR_,
% ?STANZA_ERROR("", "", "")).
-define(STANZA_ERRORT(Code, Type, Condition, Lang, Text),
{xmlelement, "error",
[{"code", Code}, {"type", Type}],
[{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []},
{xmlelement, "text", [{"xmlns", ?NS_STANZAS}],
[{xmlcdata, translate:translate(Lang, Text)}]}]}).
-define(ERRT_BAD_FORMAT(Lang, Text),
?STANZA_ERRORT("406", "modify", "bad-format", Lang, Text)).
-define(ERRT_BAD_REQUEST(Lang, Text),
?STANZA_ERRORT("400", "modify", "bad-request", Lang, Text)).
-define(ERRT_CONFLICT(Lang, Text),
?STANZA_ERRORT("409", "cancel", "conflict", Lang, Text)).
-define(ERRT_FEATURE_NOT_IMPLEMENTED(Lang, Text),
?STANZA_ERRORT("501", "cancel", "feature-not-implemented", Lang, Text)).
-define(ERRT_FORBIDDEN(Lang, Text),
?STANZA_ERRORT("403", "auth", "forbidden", Lang, Text)).
-define(ERRT_GONE(Lang, Text),
?STANZA_ERRORT("302", "modify", "gone", Lang, Text)).
-define(ERRT_INTERNAL_SERVER_ERROR(Lang, Text),
?STANZA_ERRORT("500", "wait", "internal-server-error", Lang, Text)).
-define(ERRT_ITEM_NOT_FOUND(Lang, Text),
?STANZA_ERRORT("404", "cancel", "item-not-found", Lang, Text)).
-define(ERRT_JID_MALFORMED(Lang, Text),
?STANZA_ERRORT("400", "modify", "jid-malformed", Lang, Text)).
-define(ERRT_NOT_ACCEPTABLE(Lang, Text),
?STANZA_ERRORT("406", "modify", "not-acceptable", Lang, Text)).
-define(ERRT_NOT_ALLOWED(Lang, Text),
?STANZA_ERRORT("405", "cancel", "not-allowed", Lang, Text)).
-define(ERRT_NOT_AUTHORIZED(Lang, Text),
?STANZA_ERRORT("401", "auth", "not-authorized", Lang, Text)).
-define(ERRT_PAYMENT_REQUIRED(Lang, Text),
?STANZA_ERRORT("402", "auth", "payment-required", Lang, Text)).
-define(ERRT_RECIPIENT_UNAVAILABLE(Lang, Text),
?STANZA_ERRORT("404", "wait", "recipient-unavailable", Lang, Text)).
-define(ERRT_REDIRECT(Lang, Text),
?STANZA_ERRORT("302", "modify", "redirect", Lang, Text)).
-define(ERRT_REGISTRATION_REQUIRED(Lang, Text),
?STANZA_ERRORT("407", "auth", "registration-required", Lang, Text)).
-define(ERRT_REMOTE_SERVER_NOT_FOUND(Lang, Text),
?STANZA_ERRORT("404", "cancel", "remote-server-not-found", Lang, Text)).
-define(ERRT_REMOTE_SERVER_TIMEOUT(Lang, Text),
?STANZA_ERRORT("504", "wait", "remote-server-timeout", Lang, Text)).
-define(ERRT_RESOURCE_CONSTRAINT(Lang, Text),
?STANZA_ERRORT("500", "wait", "resource-constraint", Lang, Text)).
-define(ERRT_SERVICE_UNAVAILABLE(Lang, Text),
?STANZA_ERRORT("503", "cancel", "service-unavailable", Lang, Text)).
-define(ERRT_SUBSCRIPTION_REQUIRED(Lang, Text),
?STANZA_ERRORT("407", "auth", "subscription-required", Lang, Text)).
-define(ERRT_UNEXPECTED_REQUEST(Lang, Text),
?STANZA_ERRORT("400", "wait", "unexpected-request", Lang, Text)).
% Auth stanza errors
-define(ERR_AUTH_NO_RESOURCE_PROVIDED(Lang),
?ERRT_NOT_ACCEPTABLE(Lang, "No resource provided")).
-define(ERR_AUTH_BAD_RESOURCE_FORMAT(Lang),
?ERRT_NOT_ACCEPTABLE(Lang, "Illegal resource format")).
-define(ERR_AUTH_RESOURCE_CONFLICT(Lang),
?ERRT_CONFLICT(Lang, "Resource conflict")).
-define(STREAM_ERROR(Condition),
{xmlelement, "stream:error",
[],
[{xmlelement, Condition, [{"xmlns", ?NS_STREAMS}], []}]}).
-define(SERR_BAD_FORMAT,
?STREAM_ERROR("bad-format")).
-define(SERR_BAD_NAMESPACE_PREFIX,
?STREAM_ERROR("bad-namespace-prefix")).
-define(SERR_CONFLICT,
?STREAM_ERROR("conflict")).
-define(SERR_CONNECTION_TIMEOUT,
?STREAM_ERROR("connection-timeout")).
-define(SERR_HOST_GONE,
?STREAM_ERROR("host-gone")).
-define(SERR_HOST_UNKNOWN,
?STREAM_ERROR("host-unknown")).
-define(SERR_IMPROPER_ADDRESSING,
?STREAM_ERROR("improper-addressing")).
-define(SERR_INTERNAL_SERVER_ERROR,
?STREAM_ERROR("internal-server-error")).
-define(SERR_INVALID_FROM,
?STREAM_ERROR("invalid-from")).
-define(SERR_INVALID_ID,
?STREAM_ERROR("invalid-id")).
-define(SERR_INVALID_NAMESPACE,
?STREAM_ERROR("invalid-namespace")).
-define(SERR_INVALID_XML,
?STREAM_ERROR("invalid-xml")).
-define(SERR_NOT_AUTHORIZED,
?STREAM_ERROR("not-authorized")).
-define(SERR_POLICY_VIOLATION,
?STREAM_ERROR("policy-violation")).
-define(SERR_REMOTE_CONNECTION_FAILED,
?STREAM_ERROR("remote-connection-failed")).
-define(SERR_RESOURSE_CONSTRAINT,
?STREAM_ERROR("resource-constraint")).
-define(SERR_RESTRICTED_XML,
?STREAM_ERROR("restricted-xml")).
% TODO: include hostname or IP
-define(SERR_SEE_OTHER_HOST,
?STREAM_ERROR("see-other-host")).
-define(SERR_SYSTEM_SHUTDOWN,
?STREAM_ERROR("system-shutdown")).
-define(SERR_UNSUPPORTED_ENCODING,
?STREAM_ERROR("unsupported-encoding")).
-define(SERR_UNSUPPORTED_STANZA_TYPE,
?STREAM_ERROR("unsupported-stanza-type")).
-define(SERR_UNSUPPORTED_VERSION,
?STREAM_ERROR("unsupported-version")).
-define(SERR_XML_NOT_WELL_FORMED,
?STREAM_ERROR("xml-not-well-formed")).
%-define(SERR_,
% ?STREAM_ERROR("")).
-define(STREAM_ERRORT(Condition, Lang, Text),
{xmlelement, "stream:error",
[],
[{xmlelement, Condition, [{"xmlns", ?NS_STREAMS}], []},
{xmlelement, "text", [{"xml:lang", Lang}, {"xmlns", ?NS_STREAMS}],
[{xmlcdata, translate:translate(Lang, Text)}]}]}).
-define(SERRT_BAD_FORMAT(Lang, Text),
?STREAM_ERRORT("bad-format", Lang, Text)).
-define(SERRT_BAD_NAMESPACE_PREFIX(Lang, Text),
?STREAM_ERRORT("bad-namespace-prefix", Lang, Text)).
-define(SERRT_CONFLICT(Lang, Text),
?STREAM_ERRORT("conflict", Lang, Text)).
-define(SERRT_CONNECTION_TIMEOUT(Lang, Text),
?STREAM_ERRORT("connection-timeout", Lang, Text)).
-define(SERRT_HOST_GONE(Lang, Text),
?STREAM_ERRORT("host-gone", Lang, Text)).
-define(SERRT_HOST_UNKNOWN(Lang, Text),
?STREAM_ERRORT("host-unknown", Lang, Text)).
-define(SERRT_IMPROPER_ADDRESSING(Lang, Text),
?STREAM_ERRORT("improper-addressing", Lang, Text)).
-define(SERRT_INTERNAL_SERVER_ERROR(Lang, Text),
?STREAM_ERRORT("internal-server-error", Lang, Text)).
-define(SERRT_INVALID_FROM(Lang, Text),
?STREAM_ERRORT("invalid-from", Lang, Text)).
-define(SERRT_INVALID_ID(Lang, Text),
?STREAM_ERRORT("invalid-id", Lang, Text)).
-define(SERRT_INVALID_NAMESPACE(Lang, Text),
?STREAM_ERRORT("invalid-namespace", Lang, Text)).
-define(SERRT_INVALID_XML(Lang, Text),
?STREAM_ERRORT("invalid-xml", Lang, Text)).
-define(SERRT_NOT_AUTHORIZED(Lang, Text),
?STREAM_ERRORT("not-authorized", Lang, Text)).
-define(SERRT_POLICY_VIOLATION(Lang, Text),
?STREAM_ERRORT("policy-violation", Lang, Text)).
-define(SERRT_REMOTE_CONNECTION_FAILED(Lang, Text),
?STREAM_ERRORT("remote-connection-failed", Lang, Text)).
-define(SERRT_RESOURSE_CONSTRAINT(Lang, Text),
?STREAM_ERRORT("resource-constraint", Lang, Text)).
-define(SERRT_RESTRICTED_XML(Lang, Text),
?STREAM_ERRORT("restricted-xml", Lang, Text)).
% TODO: include hostname or IP
-define(SERRT_SEE_OTHER_HOST(Lang, Text),
?STREAM_ERRORT("see-other-host", Lang, Text)).
-define(SERRT_SYSTEM_SHUTDOWN(Lang, Text),
?STREAM_ERRORT("system-shutdown", Lang, Text)).
-define(SERRT_UNSUPPORTED_ENCODING(Lang, Text),
?STREAM_ERRORT("unsupported-encoding", Lang, Text)).
-define(SERRT_UNSUPPORTED_STANZA_TYPE(Lang, Text),
?STREAM_ERRORT("unsupported-stanza-type", Lang, Text)).
-define(SERRT_UNSUPPORTED_VERSION(Lang, Text),
?STREAM_ERRORT("unsupported-version", Lang, Text)).
-define(SERRT_XML_NOT_WELL_FORMED(Lang, Text),
?STREAM_ERRORT("xml-not-well-formed", Lang, Text)).
%-define(SERRT_(Lang, Text),
% ?STREAM_ERRORT("", Lang, Text)).
-record(jid, {user, server, resource,
luser, lserver, lresource}).
-record(iq, {id = "",
type,
xmlns = "",
lang = "",
sub_el}).
-record(rsm_in, {max, direction, id, index}).
-record(rsm_out, {count, index, first, last}).

View File

@ -0,0 +1,90 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-define(MAX_USERS_DEFAULT, 200).
-define(SETS, gb_sets).
-define(DICT, dict).
-record(lqueue, {queue, len, max}).
-record(config, {title = "",
description = "",
allow_change_subj = true,
allow_query_users = true,
allow_private_messages = true,
allow_private_messages_from_visitors = anyone,
allow_visitor_status = true,
allow_visitor_nickchange = true,
public = true,
public_list = true,
persistent = false,
moderated = true,
captcha_protected = false,
members_by_default = true,
members_only = false,
allow_user_invites = false,
password_protected = false,
password = "",
anonymous = true,
allow_voice_requests = true,
voice_request_min_interval = 1800,
max_users = ?MAX_USERS_DEFAULT,
logging = false,
captcha_whitelist = ?SETS:empty()
}).
-record(user, {jid,
nick,
role,
last_presence}).
-record(activity, {message_time = 0,
presence_time = 0,
message_shaper,
presence_shaper,
message,
presence}).
-record(state, {room,
host,
server_host,
mod,
access,
jid,
config = #config{},
users = ?DICT:new(),
last_voice_request_time = treap:empty(),
robots = ?DICT:new(),
nicks = ?DICT:new(),
affiliations = ?DICT:new(),
history,
subject = "",
subject_author = "",
just_created = false,
activity = treap:empty(),
room_shaper,
room_queue = queue:new()}).
-record(muc_online_users, {us,
resource,
room,
host}).

View File

@ -0,0 +1,193 @@
%%% ====================================================================
%%% ``The contents of this file are subject to the Erlang Public License,
%%% Version 1.1, (the "License"); you may not use this file except in
%%% compliance with the License. You should have received a copy of the
%%% Erlang Public License along with this software. If not, it can be
%%% retrieved via the world wide web at http://www.erlang.org/.
%%%
%%% Software distributed under the License is distributed on an "AS IS"
%%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
%%% the License for the specific language governing rights and limitations
%%% under the License.
%%%
%%% The Initial Developer of the Original Code is ProcessOne.
%%% Portions created by ProcessOne are Copyright 2006-2011, ProcessOne
%%% All Rights Reserved.''
%%% This software is copyright 2006-2011, ProcessOne.
%%%
%%%
%%% copyright 2006-2011 ProcessOne
%%%
%%% This file contains pubsub types definition.
%%% ====================================================================
%% -------------------------------
%% Pubsub constants
-define(ERR_EXTENDED(E,C), mod_pubsub:extended_error(E,C)).
%% The actual limit can be configured with mod_pubsub's option max_items_node
-define(MAXITEMS, 10).
%% this is currently a hard limit.
%% Would be nice to have it configurable.
-define(MAX_PAYLOAD_SIZE, 60000).
%% -------------------------------
%% Pubsub types
%% @type hostPubsub() = string().
%% <p><tt>hostPubsub</tt> is the name of the PubSub service. For example, it can be
%% <tt>"pubsub.localhost"</tt>.</p>
%% @type hostPEP() = {User, Server, Resource}
%% User = string()
%% Server = string()
%% Resource = [].
%% <p>For example, it can be :
%% ```{"bob", "example.org", []}'''.</p>
%% @type host() = hostPubsub() | hostPEP().
%% @type nodeId() = binary().
%% <p>A node is defined by a list of its ancestors. The last element is the name
%% of the current node. For example:
%% ```<<"/home/localhost/user">>'''</p>
%% @type nodeIdx() = integer().
%% @type itemId() = string().
%% @type subId() = string().
%% @type payload() = [#xmlelement{} | #xmlcdata{}].
%% @type stanzaError() = #xmlelement{}.
%% Example:
%% ```{xmlelement, "error",
%% [{"code", Code}, {"type", Type}],
%% [{xmlelement, Condition, [{"xmlns", ?NS_STANZAS}], []}]}'''
%% @type pubsubIQResponse() = #xmlelement{}.
%% Example:
%% ```{xmlelement, "pubsub",
%% [{"xmlns", ?NS_PUBSUB_EVENT}],
%% [{xmlelement, "affiliations", [],
%% []}]}'''
%% @type nodeOption() = {Option, Value}
%% Option = atom()
%% Value = term().
%% Example:
%% ```{deliver_payloads, true}'''
%% @type nodeType() = string().
%% <p>The <tt>nodeType</tt> is a string containing the name of the PubSub
%% plugin to use to manage a given node. For example, it can be
%% <tt>"flat"</tt>, <tt>"hometree"</tt> or <tt>"blog"</tt>.</p>
%% @type jid() = {jid, User, Server, Resource, LUser, LServer, LResource}
%% User = string()
%% Server = string()
%% Resource = string()
%% LUser = string()
%% LServer = string()
%% LResource = string().
%% @type ljid() = {User, Server, Resource}
%% User = string()
%% Server = string()
%% Resource = string().
%% @type affiliation() = 'none' | 'owner' | 'publisher' | 'publish-only' | 'member' | 'outcast'.
%% @type subscription() = 'none' | 'pending' | 'unconfigured' | 'subscribed'.
%% @type accessModel() = 'open' | 'presence' | 'roster' | 'authorize' | 'whitelist'.
%% @type pubsubIndex() = {pubsub_index, Index, Last, Free}
%% Index = atom()
%% Last = integer()
%% Free = [integer()].
%% internal pubsub index table
-record(pubsub_index,
{
index,
last,
free
}).
%% @type pubsubNode() = {pubsub_node, NodeId, Id, Parents, Type, Owners, Options}
%% NodeId = {host() | ljid(), nodeId()}
%% Id = nodeIdx()
%% Parents = [nodeId()]
%% Type = nodeType()
%% Owners = [ljid()]
%% Options = [nodeOption()].
%% <p>This is the format of the <tt>nodes</tt> table. The type of the table
%% is: <tt>set</tt>,<tt>ram/disc</tt>.</p>
%% <p>The <tt>Parents</tt> and <tt>type</tt> fields are indexed.</p>
%% <tt>id</tt> can be anything you want.
-record(pubsub_node,
{
nodeid,
id,
parents = [],
type = "flat",
owners = [],
options = []
}).
%% @type pubsubState() = {pubsub_state, StateId, Items, Affiliation, Subscriptions}
%% StateId = {ljid(), nodeIdx()}
%% Items = [itemId()]
%% Affiliation = affiliation()
%% Subscriptions = [{subscription(), subId()}].
%% <p>This is the format of the <tt>affiliations</tt> table. The type of the
%% table is: <tt>set</tt>,<tt>ram/disc</tt>.</p>
-record(pubsub_state,
{
stateid,
items = [],
affiliation = 'none',
subscriptions = []
}).
%% @type pubsubItem() = {pubsub_item, ItemId, Creation, Modification, Payload}
%% ItemId = {itemId(), nodeIdx()}
%% Creation = {now(), ljid()}
%% Modification = {now(), ljid()}
%% Payload = payload().
%% <p>This is the format of the <tt>published items</tt> table. The type of the
%% table is: <tt>set</tt>,<tt>disc</tt>,<tt>fragmented</tt>.</p>
-record(pubsub_item,
{
itemid,
creation = {'unknown','unknown'},
modification = {'unknown','unknown'},
payload = []
}).
%% @type pubsubSubscription() = {pubsub_subscription, SubId, Options}
%% SubId = subId()
%% Options = [nodeOption()].
%% <p>This is the format of the <tt>subscriptions</tt> table. The type of the
%% table is: <tt>set</tt>,<tt>ram/disc</tt>.</p>
-record(pubsub_subscription,
{
subid,
options
}).
%% @type pubsubLastItem() = {pubsub_last_item, NodeId, ItemId, Creation, Payload}
%% NodeId = nodeIdx()
%% ItemId = itemId()
%% Creation = {now(),ljid()}
%% Payload = payload().
%% <p>This is the format of the <tt>last items</tt> table. it stores last item payload
%% for every node</p>
-record(pubsub_last_item,
{
nodeid,
itemid,
creation,
payload
}).

View File

@ -0,0 +1,33 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-record(roster, {usj,
us,
jid,
name = "",
subscription = none,
ask = none,
groups = [],
askmessage = [],
xs = []}).
-record(roster_version, {us,
version}).

View File

@ -0,0 +1,34 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-record(request, {method,
path,
q = [],
us,
auth,
lang = "",
data = "",
ip,
host, % string()
port, % integer()
tp, % transfer protocol = http | https
headers
}).

View File

@ -0,0 +1,76 @@
%%%----------------------------------------------------------------------
%%%
%%% ejabberd, Copyright (C) 2002-2012 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-define(X(Name), {xmlelement, Name, [], []}).
-define(XA(Name, Attrs), {xmlelement, Name, Attrs, []}).
-define(XE(Name, Els), {xmlelement, Name, [], Els}).
-define(XAE(Name, Attrs, Els), {xmlelement, Name, Attrs, Els}).
-define(C(Text), {xmlcdata, Text}).
-define(XC(Name, Text), ?XE(Name, [?C(Text)])).
-define(XAC(Name, Attrs, Text), ?XAE(Name, Attrs, [?C(Text)])).
-define(T(Text), translate:translate(Lang, Text)).
-define(CT(Text), ?C(?T(Text))).
-define(XCT(Name, Text), ?XC(Name, ?T(Text))).
-define(XACT(Name, Attrs, Text), ?XAC(Name, Attrs, ?T(Text))).
-define(LI(Els), ?XE("li", Els)).
-define(A(URL, Els), ?XAE("a", [{"href", URL}], Els)).
-define(AC(URL, Text), ?A(URL, [?C(Text)])).
-define(ACT(URL, Text), ?AC(URL, ?T(Text))).
-define(P, ?X("p")).
-define(BR, ?X("br")).
-define(INPUT(Type, Name, Value),
?XA("input", [{"type", Type},
{"name", Name},
{"value", Value}])).
-define(INPUTT(Type, Name, Value), ?INPUT(Type, Name, ?T(Value))).
-define(INPUTS(Type, Name, Value, Size),
?XA("input", [{"type", Type},
{"name", Name},
{"value", Value},
{"size", Size}])).
-define(INPUTST(Type, Name, Value, Size), ?INPUT(Type, Name, ?T(Value), Size)).
-define(ACLINPUT(Text), ?XE("td", [?INPUT("text", "value" ++ ID, Text)])).
-define(TEXTAREA(Name, Rows, Cols, Value),
?XAC("textarea", [{"name", Name},
{"rows", Rows},
{"cols", Cols}],
Value)).
%% Build an xmlelement for result
-define(XRES(Text), ?XAC("p", [{"class", "result"}], Text)).
-define(XREST(Text), ?XRES(?T(Text))).
%% Guide Link
-define(GL(Ref, Title),
?XAE("div",
[{"class", "guidelink"}],
[?XAE("a",
[{"href", "/admin/doc/guide.html#"++ Ref},
{"target", "_blank"}],
[?C("[Guide: " ++ Title ++ "]")])
])).
%% h1 with a Guide Link
-define(H1GL(Name, Ref, Title), [?XC("h1", Name), ?GL(Ref, Title)]).

View File

@ -0,0 +1,236 @@
%%%----------------------------------------------------------------------
%%% File : gen_mod.erl
%%% Author : Alexey Shchepin <alexey@process-one.net>
%%% Purpose :
%%% Created : 24 Jan 2003 by Alexey Shchepin <alexey@process-one.net>
%%%
%%%
%%% ejabberd, Copyright (C) 2002-2008 ProcessOne
%%%
%%% This program is free software; you can redistribute it and/or
%%% modify it under the terms of the GNU General Public License as
%%% published by the Free Software Foundation; either version 2 of the
%%% License, or (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
%%% General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
%%% 02111-1307 USA
%%%
%%%----------------------------------------------------------------------
-module(gen_mod).
-author('alexey@process-one.net').
-export([start/0,
start_module/3,
stop_module/2,
stop_module_keep_config/2,
get_opt/2,
get_opt/3,
get_opt_host/3,
get_module_opt/4,
get_module_opt_host/3,
loaded_modules/1,
loaded_modules_with_opts/1,
get_hosts/2,
get_module_proc/2,
is_loaded/2]).
-export([behaviour_info/1]).
-include("ejabberd.hrl").
-record(ejabberd_module, {module_host, opts}).
behaviour_info(callbacks) ->
[{start, 2},
{stop, 1}];
behaviour_info(_Other) ->
undefined.
start() ->
ets:new(ejabberd_modules, [named_table,
public,
{keypos, #ejabberd_module.module_host}]),
ok.
start_module(Host, Module, Opts) ->
set_module_opts_mnesia(Host, Module, Opts),
ets:insert(ejabberd_modules,
#ejabberd_module{module_host = {Module, Host},
opts = Opts}),
case catch Module:start(Host, Opts) of
{'EXIT', Reason} ->
del_module_mnesia(Host, Module),
ets:delete(ejabberd_modules, {Module, Host}),
?ERROR_MSG("~p", [Reason]);
_ ->
ok
end.
%% @doc Stop the module in a host, and forget its configuration.
stop_module(Host, Module) ->
case stop_module_keep_config(Host, Module) of
error ->
error;
ok ->
del_module_mnesia(Host, Module)
end.
%% @doc Stop the module in a host, but keep its configuration.
%% As the module configuration is kept in the Mnesia local_config table,
%% when ejabberd is restarted the module will be started again.
%% This function is useful when ejabberd is being stopped
%% and it stops all modules.
stop_module_keep_config(Host, Module) ->
case catch Module:stop(Host) of
{'EXIT', Reason} ->
?ERROR_MSG("~p", [Reason]),
error;
{wait, ProcList} when is_list(ProcList) ->
lists:foreach(fun wait_for_process/1, ProcList),
ets:delete(ejabberd_modules, {Module, Host}),
ok;
{wait, Process} ->
wait_for_process(Process),
ets:delete(ejabberd_modules, {Module, Host}),
ok;
_ ->
ets:delete(ejabberd_modules, {Module, Host}),
ok
end.
wait_for_process(Process) ->
MonitorReference = erlang:monitor(process, Process),
wait_for_stop(Process, MonitorReference).
wait_for_stop(Process, MonitorReference) ->
receive
{'DOWN', MonitorReference, _Type, _Object, _Info} ->
ok
after 5000 ->
catch exit(whereis(Process), kill),
wait_for_stop1(MonitorReference)
end.
wait_for_stop1(MonitorReference) ->
receive
{'DOWN', MonitorReference, _Type, _Object, _Info} ->
ok
after 5000 ->
ok
end.
get_opt(Opt, Opts) ->
case lists:keysearch(Opt, 1, Opts) of
false ->
% TODO: replace with more appropriate function
throw({undefined_option, Opt});
{value, {_, Val}} ->
Val
end.
get_opt(Opt, Opts, Default) ->
case lists:keysearch(Opt, 1, Opts) of
false ->
Default;
{value, {_, Val}} ->
Val
end.
get_module_opt(global, Module, Opt, Default) ->
Hosts = ?MYHOSTS,
[Value | Values] = lists:map(
fun(Host) ->
get_module_opt(Host, Module, Opt, Default)
end,
Hosts),
Same_all = lists:all(
fun(Other_value) ->
Other_value == Value
end,
Values),
case Same_all of
true -> Value;
false -> Default
end;
get_module_opt(Host, Module, Opt, Default) ->
OptsList = ets:lookup(ejabberd_modules, {Module, Host}),
case OptsList of
[] ->
Default;
[#ejabberd_module{opts = Opts} | _] ->
get_opt(Opt, Opts, Default)
end.
get_module_opt_host(Host, Module, Default) ->
Val = get_module_opt(Host, Module, host, Default),
element(2, regexp:gsub(Val, "@HOST@", Host)).
get_opt_host(Host, Opts, Default) ->
Val = get_opt(host, Opts, Default),
element(2, regexp:gsub(Val, "@HOST@", Host)).
loaded_modules(Host) ->
ets:select(ejabberd_modules,
[{#ejabberd_module{_ = '_', module_host = {'$1', Host}},
[],
['$1']}]).
loaded_modules_with_opts(Host) ->
ets:select(ejabberd_modules,
[{#ejabberd_module{_ = '_', module_host = {'$1', Host},
opts = '$2'},
[],
[{{'$1', '$2'}}]}]).
set_module_opts_mnesia(Host, Module, Opts) ->
Modules = case ejabberd_config:get_local_option({modules, Host}) of
undefined ->
[];
Ls ->
Ls
end,
Modules1 = lists:keydelete(Module, 1, Modules),
Modules2 = [{Module, Opts} | Modules1],
ejabberd_config:add_local_option({modules, Host}, Modules2).
del_module_mnesia(Host, Module) ->
Modules = case ejabberd_config:get_local_option({modules, Host}) of
undefined ->
[];
Ls ->
Ls
end,
Modules1 = lists:keydelete(Module, 1, Modules),
ejabberd_config:add_local_option({modules, Host}, Modules1).
get_hosts(Opts, Prefix) ->
case catch gen_mod:get_opt(hosts, Opts) of
{'EXIT', _Error1} ->
case catch gen_mod:get_opt(host, Opts) of
{'EXIT', _Error2} ->
[Prefix ++ Host || Host <- ?MYHOSTS];
Host ->
[Host]
end;
Hosts ->
Hosts
end.
get_module_proc(Host, {frontend, Base}) ->
get_module_proc("frontend_" ++ Host, Base);
get_module_proc(Host, Base) ->
list_to_atom(atom_to_list(Base) ++ "_" ++ Host).
is_loaded(Host, Module) ->
ets:member(ejabberd_modules, {Module, Host}).

Binary file not shown.

View File

@ -0,0 +1,30 @@
{
IBClasses = (
{
CLASS = NSPreferencePane;
LANGUAGE = ObjC;
OUTLETS = {
"_firstKeyView" = id;
"_initialKeyView" = id;
"_lastKeyView" = id;
"_window" = id;
};
SUPERCLASS = NSObject;
},
{
ACTIONS = {automaticStartAction = id; startStopAction = id; };
CLASS = ejabberdController;
LANGUAGE = ObjC;
OUTLETS = {
actionProgress = NSProgressIndicator;
automaticBox = NSButton;
imagestarted = NSImageView;
imagestopped = NSImageView;
startStopButton = NSButton;
status = NSTextField;
};
SUPERCLASS = NSObject;
}
);
IBVersion = 1;
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IBDocumentLocation</key>
<string>32 22 356 240 0 0 1680 1028 </string>
<key>IBFramework Version</key>
<string>446.1</string>
<key>IBOldestOS</key>
<integer>2</integer>
<key>IBSystem Version</key>
<string>8S2167</string>
</dict>
</plist>

Binary file not shown.

30
ejabberdPrefs/Info.plist Normal file
View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>ejabberd</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.apple.prefpanel</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleSignature</key>
<string>process-one</string>
<key>CFBundleVersion</key>
<string>2.0.3</string>
<key>NSMainNibFile</key>
<string>ejabberdPref</string>
<key>NSPrefPaneIconFile</key>
<string>ejabberdPref.tiff</string>
<key>NSPrefPaneIconLabel</key>
<string>ejabberd</string>
<key>NSPrincipalClass</key>
<string>ejabberdPref</string>
</dict>
</plist>

18
ejabberdPrefs/LICENSE Normal file
View File

@ -0,0 +1,18 @@
ejabberd's prefPane Licence
Except as described below, all of the source code to prefPane is
available under the Mozilla Public Licence (MPL).
The complete text of the Mozilla Public License can be found in
the MPL file in the same directory as this file or consulted at
http://www.mozilla.org/MPL/MPL-1.1.html.
Exceptions
The following portions are not available under the above
terms:
* Image files containing the trademarks and logos of
ProcessOne, which may not be reproduced without
permission. (Copyright ©2001-2009 ProcessOne. All Rights
Reserved.)

470
ejabberdPrefs/MPL Normal file
View File

@ -0,0 +1,470 @@
MOZILLA PUBLIC LICENSE
Version 1.1
---------------
1. Definitions.
1.0.1. "Commercial Use" means distribution or otherwise making the
Covered Code available to a third party.
1.1. "Contributor" means each entity that creates or contributes to
the creation of Modifications.
1.2. "Contributor Version" means the combination of the Original
Code, prior Modifications used by a Contributor, and the Modifications
made by that particular Contributor.
1.3. "Covered Code" means the Original Code or Modifications or the
combination of the Original Code and Modifications, in each case
including portions thereof.
1.4. "Electronic Distribution Mechanism" means a mechanism generally
accepted in the software development community for the electronic
transfer of data.
1.5. "Executable" means Covered Code in any form other than Source
Code.
1.6. "Initial Developer" means the individual or entity identified
as the Initial Developer in the Source Code notice required by Exhibit
A.
1.7. "Larger Work" means a work which combines Covered Code or
portions thereof with code not governed by the terms of this License.
1.8. "License" means this document.
1.8.1. "Licensable" means having the right to grant, to the maximum
extent possible, whether at the time of the initial grant or
subsequently acquired, any and all of the rights conveyed herein.
1.9. "Modifications" means any addition to or deletion from the
substance or structure of either the Original Code or any previous
Modifications. When Covered Code is released as a series of files, a
Modification is:
A. Any addition to or deletion from the contents of a file
containing Original Code or previous Modifications.
B. Any new file that contains any part of the Original Code or
previous Modifications.
1.10. "Original Code" means Source Code of computer software code
which is described in the Source Code notice required by Exhibit A as
Original Code, and which, at the time of its release under this
License is not already Covered Code governed by this License.
1.10.1. "Patent Claims" means any patent claim(s), now owned or
hereafter acquired, including without limitation, method, process,
and apparatus claims, in any patent Licensable by grantor.
1.11. "Source Code" means the preferred form of the Covered Code for
making modifications to it, including all modules it contains, plus
any associated interface definition files, scripts used to control
compilation and installation of an Executable, or source code
differential comparisons against either the Original Code or another
well known, available Covered Code of the Contributor's choice. The
Source Code can be in a compressed or archival form, provided the
appropriate decompression or de-archiving software is widely available
for no charge.
1.12. "You" (or "Your") means an individual or a legal entity
exercising rights under, and complying with all of the terms of, this
License or a future version of this License issued under Section 6.1.
For legal entities, "You" includes any entity which controls, is
controlled by, or is under common control with You. For purposes of
this definition, "control" means (a) the power, direct or indirect,
to cause the direction or management of such entity, whether by
contract or otherwise, or (b) ownership of more than fifty percent
(50%) of the outstanding shares or beneficial ownership of such
entity.
2. Source Code License.
2.1. The Initial Developer Grant.
The Initial Developer hereby grants You a world-wide, royalty-free,
non-exclusive license, subject to third party intellectual property
claims:
(a) under intellectual property rights (other than patent or
trademark) Licensable by Initial Developer to use, reproduce,
modify, display, perform, sublicense and distribute the Original
Code (or portions thereof) with or without Modifications, and/or
as part of a Larger Work; and
(b) under Patents Claims infringed by the making, using or
selling of Original Code, to make, have made, use, practice,
sell, and offer for sale, and/or otherwise dispose of the
Original Code (or portions thereof).
(c) the licenses granted in this Section 2.1(a) and (b) are
effective on the date Initial Developer first distributes
Original Code under the terms of this License.
(d) Notwithstanding Section 2.1(b) above, no patent license is
granted: 1) for code that You delete from the Original Code; 2)
separate from the Original Code; or 3) for infringements caused
by: i) the modification of the Original Code or ii) the
combination of the Original Code with other software or devices.
2.2. Contributor Grant.
Subject to third party intellectual property claims, each Contributor
hereby grants You a world-wide, royalty-free, non-exclusive license
(a) under intellectual property rights (other than patent or
trademark) Licensable by Contributor, to use, reproduce, modify,
display, perform, sublicense and distribute the Modifications
created by such Contributor (or portions thereof) either on an
unmodified basis, with other Modifications, as Covered Code
and/or as part of a Larger Work; and
(b) under Patent Claims infringed by the making, using, or
selling of Modifications made by that Contributor either alone
and/or in combination with its Contributor Version (or portions
of such combination), to make, use, sell, offer for sale, have
made, and/or otherwise dispose of: 1) Modifications made by that
Contributor (or portions thereof); and 2) the combination of
Modifications made by that Contributor with its Contributor
Version (or portions of such combination).
(c) the licenses granted in Sections 2.2(a) and 2.2(b) are
effective on the date Contributor first makes Commercial Use of
the Covered Code.
(d) Notwithstanding Section 2.2(b) above, no patent license is
granted: 1) for any code that Contributor has deleted from the
Contributor Version; 2) separate from the Contributor Version;
3) for infringements caused by: i) third party modifications of
Contributor Version or ii) the combination of Modifications made
by that Contributor with other software (except as part of the
Contributor Version) or other devices; or 4) under Patent Claims
infringed by Covered Code in the absence of Modifications made by
that Contributor.
3. Distribution Obligations.
3.1. Application of License.
The Modifications which You create or to which You contribute are
governed by the terms of this License, including without limitation
Section 2.2. The Source Code version of Covered Code may be
distributed only under the terms of this License or a future version
of this License released under Section 6.1, and You must include a
copy of this License with every copy of the Source Code You
distribute. You may not offer or impose any terms on any Source Code
version that alters or restricts the applicable version of this
License or the recipients' rights hereunder. However, You may include
an additional document offering the additional rights described in
Section 3.5.
3.2. Availability of Source Code.
Any Modification which You create or to which You contribute must be
made available in Source Code form under the terms of this License
either on the same media as an Executable version or via an accepted
Electronic Distribution Mechanism to anyone to whom you made an
Executable version available; and if made available via Electronic
Distribution Mechanism, must remain available for at least twelve (12)
months after the date it initially became available, or at least six
(6) months after a subsequent version of that particular Modification
has been made available to such recipients. You are responsible for
ensuring that the Source Code version remains available even if the
Electronic Distribution Mechanism is maintained by a third party.
3.3. Description of Modifications.
You must cause all Covered Code to which You contribute to contain a
file documenting the changes You made to create that Covered Code and
the date of any change. You must include a prominent statement that
the Modification is derived, directly or indirectly, from Original
Code provided by the Initial Developer and including the name of the
Initial Developer in (a) the Source Code, and (b) in any notice in an
Executable version or related documentation in which You describe the
origin or ownership of the Covered Code.
3.4. Intellectual Property Matters
(a) Third Party Claims.
If Contributor has knowledge that a license under a third party's
intellectual property rights is required to exercise the rights
granted by such Contributor under Sections 2.1 or 2.2,
Contributor must include a text file with the Source Code
distribution titled "LEGAL" which describes the claim and the
party making the claim in sufficient detail that a recipient will
know whom to contact. If Contributor obtains such knowledge after
the Modification is made available as described in Section 3.2,
Contributor shall promptly modify the LEGAL file in all copies
Contributor makes available thereafter and shall take other steps
(such as notifying appropriate mailing lists or newsgroups)
reasonably calculated to inform those who received the Covered
Code that new knowledge has been obtained.
(b) Contributor APIs.
If Contributor's Modifications include an application programming
interface and Contributor has knowledge of patent licenses which
are reasonably necessary to implement that API, Contributor must
also include this information in the LEGAL file.
(c) Representations.
Contributor represents that, except as disclosed pursuant to
Section 3.4(a) above, Contributor believes that Contributor's
Modifications are Contributor's original creation(s) and/or
Contributor has sufficient rights to grant the rights conveyed by
this License.
3.5. Required Notices.
You must duplicate the notice in Exhibit A in each file of the Source
Code. If it is not possible to put such notice in a particular Source
Code file due to its structure, then You must include such notice in a
location (such as a relevant directory) where a user would be likely
to look for such a notice. If You created one or more Modification(s)
You may add your name as a Contributor to the notice described in
Exhibit A. You must also duplicate this License in any documentation
for the Source Code where You describe recipients' rights or ownership
rights relating to Covered Code. You may choose to offer, and to
charge a fee for, warranty, support, indemnity or liability
obligations to one or more recipients of Covered Code. However, You
may do so only on Your own behalf, and not on behalf of the Initial
Developer or any Contributor. You must make it absolutely clear than
any such warranty, support, indemnity or liability obligation is
offered by You alone, and You hereby agree to indemnify the Initial
Developer and every Contributor for any liability incurred by the
Initial Developer or such Contributor as a result of warranty,
support, indemnity or liability terms You offer.
3.6. Distribution of Executable Versions.
You may distribute Covered Code in Executable form only if the
requirements of Section 3.1-3.5 have been met for that Covered Code,
and if You include a notice stating that the Source Code version of
the Covered Code is available under the terms of this License,
including a description of how and where You have fulfilled the
obligations of Section 3.2. The notice must be conspicuously included
in any notice in an Executable version, related documentation or
collateral in which You describe recipients' rights relating to the
Covered Code. You may distribute the Executable version of Covered
Code or ownership rights under a license of Your choice, which may
contain terms different from this License, provided that You are in
compliance with the terms of this License and that the license for the
Executable version does not attempt to limit or alter the recipient's
rights in the Source Code version from the rights set forth in this
License. If You distribute the Executable version under a different
license You must make it absolutely clear that any terms which differ
from this License are offered by You alone, not by the Initial
Developer or any Contributor. You hereby agree to indemnify the
Initial Developer and every Contributor for any liability incurred by
the Initial Developer or such Contributor as a result of any such
terms You offer.
3.7. Larger Works.
You may create a Larger Work by combining Covered Code with other code
not governed by the terms of this License and distribute the Larger
Work as a single product. In such a case, You must make sure the
requirements of this License are fulfilled for the Covered Code.
4. Inability to Comply Due to Statute or Regulation.
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Code due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description
must be included in the LEGAL file described in Section 3.4 and must
be included with all distributions of the Source Code. Except to the
extent prohibited by statute or regulation, such description must be
sufficiently detailed for a recipient of ordinary skill to be able to
understand it.
5. Application of this License.
This License applies to code to which the Initial Developer has
attached the notice in Exhibit A and to related Covered Code.
6. Versions of the License.
6.1. New Versions.
Netscape Communications Corporation ("Netscape") may publish revised
and/or new versions of the License from time to time. Each version
will be given a distinguishing version number.
6.2. Effect of New Versions.
Once Covered Code has been published under a particular version of the
License, You may always continue to use it under the terms of that
version. You may also choose to use such Covered Code under the terms
of any subsequent version of the License published by Netscape. No one
other than Netscape has the right to modify the terms applicable to
Covered Code created under this License.
6.3. Derivative Works.
If You create or use a modified version of this License (which you may
only do in order to apply it to code which is not already Covered Code
governed by this License), You must (a) rename Your license so that
the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
"MPL", "NPL" or any confusingly similar phrase do not appear in your
license (except to note that your license differs from this License)
and (b) otherwise make it clear that Your version of the license
contains terms which differ from the Mozilla Public License and
Netscape Public License. (Filling in the name of the Initial
Developer, Original Code or Contributor in the notice described in
Exhibit A shall not of themselves be deemed to be modifications of
this License.)
7. DISCLAIMER OF WARRANTY.
COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
8. TERMINATION.
8.1. This License and the rights granted hereunder will terminate
automatically if You fail to comply with terms herein and fail to cure
such breach within 30 days of becoming aware of the breach. All
sublicenses to the Covered Code which are properly granted shall
survive any termination of this License. Provisions which, by their
nature, must remain in effect beyond the termination of this License
shall survive.
8.2. If You initiate litigation by asserting a patent infringement
claim (excluding declatory judgment actions) against Initial Developer
or a Contributor (the Initial Developer or Contributor against whom
You file such action is referred to as "Participant") alleging that:
(a) such Participant's Contributor Version directly or indirectly
infringes any patent, then any and all rights granted by such
Participant to You under Sections 2.1 and/or 2.2 of this License
shall, upon 60 days notice from Participant terminate prospectively,
unless if within 60 days after receipt of notice You either: (i)
agree in writing to pay Participant a mutually agreeable reasonable
royalty for Your past and future use of Modifications made by such
Participant, or (ii) withdraw Your litigation claim with respect to
the Contributor Version against such Participant. If within 60 days
of notice, a reasonable royalty and payment arrangement are not
mutually agreed upon in writing by the parties or the litigation claim
is not withdrawn, the rights granted by Participant to You under
Sections 2.1 and/or 2.2 automatically terminate at the expiration of
the 60 day notice period specified above.
(b) any software, hardware, or device, other than such Participant's
Contributor Version, directly or indirectly infringes any patent, then
any rights granted to You by such Participant under Sections 2.1(b)
and 2.2(b) are revoked effective as of the date You first made, used,
sold, distributed, or had made, Modifications made by that
Participant.
8.3. If You assert a patent infringement claim against Participant
alleging that such Participant's Contributor Version directly or
indirectly infringes any patent where such claim is resolved (such as
by license or settlement) prior to the initiation of patent
infringement litigation, then the reasonable value of the licenses
granted by such Participant under Sections 2.1 or 2.2 shall be taken
into account in determining the amount or value of any payment or
license.
8.4. In the event of termination under Sections 8.1 or 8.2 above,
all end user license agreements (excluding distributors and resellers)
which have been validly granted by You or any distributor hereunder
prior to termination shall survive termination.
9. LIMITATION OF LIABILITY.
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
10. U.S. GOVERNMENT END USERS.
The Covered Code is a "commercial item," as that term is defined in
48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
software" and "commercial computer software documentation," as such
terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
all U.S. Government End Users acquire Covered Code with only those
rights set forth herein.
11. MISCELLANEOUS.
This License represents the complete agreement concerning subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. This License shall be governed by
California law provisions (except to the extent applicable law, if
any, provides otherwise), excluding its conflict-of-law provisions.
With respect to disputes in which at least one party is a citizen of,
or an entity chartered or registered to do business in the United
States of America, any litigation relating to this License shall be
subject to the jurisdiction of the Federal Courts of the Northern
District of California, with venue lying in Santa Clara County,
California, with the losing party responsible for costs, including
without limitation, court costs and reasonable attorneys' fees and
expenses. The application of the United Nations Convention on
Contracts for the International Sale of Goods is expressly excluded.
Any law or regulation which provides that the language of a contract
shall be construed against the drafter shall not apply to this
License.
12. RESPONSIBILITY FOR CLAIMS.
As between Initial Developer and the Contributors, each party is
responsible for claims and damages arising, directly or indirectly,
out of its utilization of rights under this License and You agree to
work with Initial Developer and Contributors to distribute such
responsibility on an equitable basis. Nothing herein is intended or
shall be deemed to constitute any admission of liability.
13. MULTIPLE-LICENSED CODE.
Initial Developer may designate portions of the Covered Code as
"Multiple-Licensed". "Multiple-Licensed" means that the Initial
Developer permits you to utilize portions of the Covered Code under
Your choice of the NPL or the alternative licenses, if any, specified
by the Initial Developer in the file described in Exhibit A.
EXHIBIT A -Mozilla Public License.
``The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
The Original Code is ______________________________________.
The Initial Developer of the Original Code is ________________________.
Portions created by ______________________ are Copyright (C) ______
_______________________. All Rights Reserved.
Contributor(s): ______________________________________.
Alternatively, the contents of this file may be used under the terms
of the _____ license (the "[___] License"), in which case the
provisions of [______] License are applicable instead of those
above. If you wish to allow use of your version of this file only
under the terms of the [____] License and not to allow others to use
your version of this file under the MPL, indicate your decision by
deleting the provisions above and replace them with the notice and
other provisions required by the [___] License. If you do not delete
the provisions above, a recipient may use your version of this file
under either the MPL or the [___] License."
[NOTE: The text of this Exhibit A may differ slightly from the text of
the notices in the Source Code files of the Original Code. You should
use the text of this Exhibit A rather than the text found in the
Original Code Source Code for Your Modifications.]

1
ejabberdPrefs/config.txt Normal file
View File

@ -0,0 +1 @@
/Applications/ejabberd-2.0.3

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>ejabberd.etc.rc.command</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/ejabberd-2.0.3/bin/ejabberdctl</string>
<string>start</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>

View File

@ -0,0 +1,439 @@
// !$*UTF8*$!
{
archiveVersion = 1;
classes = {
};
objectVersion = 42;
objects = {
/* Begin PBXBuildFile section */
837D1CC80B635DA9003F99C1 /* ejabberd.plist in Resources */ = {isa = PBXBuildFile; fileRef = 837D1CC70B635DA9003F99C1 /* ejabberd.plist */; };
837F6DD209F777FF00914317 /* ejabberdController.h in Headers */ = {isa = PBXBuildFile; fileRef = 837F6DD009F777FF00914317 /* ejabberdController.h */; };
837F6DD309F777FF00914317 /* ejabberdController.m in Sources */ = {isa = PBXBuildFile; fileRef = 837F6DD109F777FF00914317 /* ejabberdController.m */; };
837F6DDD09F7E55000914317 /* logo_ejabberd.png in Resources */ = {isa = PBXBuildFile; fileRef = 837F6DDB09F7E55000914317 /* logo_ejabberd.png */; };
837F6DDF09F7E6FD00914317 /* logo_ejabberd.png in Resources */ = {isa = PBXBuildFile; fileRef = 837F6DDE09F7E6FD00914317 /* logo_ejabberd.png */; };
837F6DE409F7E8BF00914317 /* instance_started.png in Resources */ = {isa = PBXBuildFile; fileRef = 837F6DE209F7E8BF00914317 /* instance_started.png */; };
837F6DE509F7E8BF00914317 /* instance_stopped.png in Resources */ = {isa = PBXBuildFile; fileRef = 837F6DE309F7E8BF00914317 /* instance_stopped.png */; };
837F6DEE09F8D41200914317 /* config.txt in Resources */ = {isa = PBXBuildFile; fileRef = 837F6DED09F8D41200914317 /* config.txt */; };
8D202CEA0486D31800D8A456 /* ejabberd_Prefix.pch in Headers */ = {isa = PBXBuildFile; fileRef = 32DBCFA20370C41700C91783 /* ejabberd_Prefix.pch */; };
8D202CEB0486D31800D8A456 /* ejabberdPref.h in Headers */ = {isa = PBXBuildFile; fileRef = F506C03C013D9D7901CA16C8 /* ejabberdPref.h */; };
8D202CED0486D31800D8A456 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C167DFE841241C02AAC07 /* InfoPlist.strings */; };
8D202CEE0486D31800D8A456 /* ejabberdPref.tiff in Resources */ = {isa = PBXBuildFile; fileRef = F506C040013D9D8001CA16C8 /* ejabberdPref.tiff */; };
8D202CEF0486D31800D8A456 /* ejabberdPref.nib in Resources */ = {isa = PBXBuildFile; fileRef = F506C042013D9D8C01CA16C8 /* ejabberdPref.nib */; };
8D202CF10486D31800D8A456 /* ejabberdPref.m in Sources */ = {isa = PBXBuildFile; fileRef = F506C03D013D9D7901CA16C8 /* ejabberdPref.m */; };
8D202CF30486D31800D8A456 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */; };
8D202CF40486D31800D8A456 /* PreferencePanes.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F506C035013D953901CA16C8 /* PreferencePanes.framework */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
089C1672FE841209C02AAC07 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
089C167EFE841241C02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
089C167FFE841241C02AAC07 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
32DBCFA20370C41700C91783 /* ejabberd_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ejabberd_Prefix.pch; sourceTree = "<group>"; };
837D1CC70B635DA9003F99C1 /* ejabberd.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = ejabberd.plist; sourceTree = "<group>"; };
837F6DD009F777FF00914317 /* ejabberdController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ejabberdController.h; sourceTree = "<group>"; };
837F6DD109F777FF00914317 /* ejabberdController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ejabberdController.m; sourceTree = "<group>"; };
837F6DDB09F7E55000914317 /* logo_ejabberd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo_ejabberd.png; sourceTree = "<group>"; };
837F6DDE09F7E6FD00914317 /* logo_ejabberd.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = logo_ejabberd.png; sourceTree = "<group>"; };
837F6DE209F7E8BF00914317 /* instance_started.png */ = {isa = PBXFileReference; explicitFileType = image.png; path = instance_started.png; sourceTree = "<group>"; };
837F6DE309F7E8BF00914317 /* instance_stopped.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = instance_stopped.png; sourceTree = "<group>"; };
837F6DED09F8D41200914317 /* config.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = config.txt; sourceTree = "<group>"; };
8D202CF70486D31800D8A456 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
8D202CF80486D31800D8A456 /* ejabberd.prefPane */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ejabberd.prefPane; sourceTree = BUILT_PRODUCTS_DIR; };
F506C035013D953901CA16C8 /* PreferencePanes.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PreferencePanes.framework; path = /System/Library/Frameworks/PreferencePanes.framework; sourceTree = "<absolute>"; };
F506C03C013D9D7901CA16C8 /* ejabberdPref.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ejabberdPref.h; sourceTree = "<group>"; };
F506C03D013D9D7901CA16C8 /* ejabberdPref.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ejabberdPref.m; sourceTree = "<group>"; };
F506C040013D9D8001CA16C8 /* ejabberdPref.tiff */ = {isa = PBXFileReference; lastKnownFileType = image.tiff; path = ejabberdPref.tiff; sourceTree = "<group>"; };
F506C043013D9D8C01CA16C8 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/ejabberdPref.nib; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
8D202CF20486D31800D8A456 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
8D202CF30486D31800D8A456 /* Cocoa.framework in Frameworks */,
8D202CF40486D31800D8A456 /* PreferencePanes.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
089C166AFE841209C02AAC07 /* ejabberd */ = {
isa = PBXGroup;
children = (
08FB77AFFE84173DC02AAC07 /* Classes */,
32DBCFA10370C40200C91783 /* Other Sources */,
089C167CFE841241C02AAC07 /* Resources */,
089C1671FE841209C02AAC07 /* Frameworks and Libraries */,
19C28FB8FE9D52D311CA2CBB /* Products */,
);
name = ejabberd;
sourceTree = "<group>";
};
089C1671FE841209C02AAC07 /* Frameworks and Libraries */ = {
isa = PBXGroup;
children = (
1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */,
1058C7AEFEA557BF11CA2CBB /* Other Frameworks */,
);
name = "Frameworks and Libraries";
sourceTree = "<group>";
};
089C167CFE841241C02AAC07 /* Resources */ = {
isa = PBXGroup;
children = (
837F6DE209F7E8BF00914317 /* instance_started.png */,
837F6DE309F7E8BF00914317 /* instance_stopped.png */,
8D202CF70486D31800D8A456 /* Info.plist */,
089C167DFE841241C02AAC07 /* InfoPlist.strings */,
F506C040013D9D8001CA16C8 /* ejabberdPref.tiff */,
F506C042013D9D8C01CA16C8 /* ejabberdPref.nib */,
837F6DDB09F7E55000914317 /* logo_ejabberd.png */,
837F6DDE09F7E6FD00914317 /* logo_ejabberd.png */,
837F6DED09F8D41200914317 /* config.txt */,
);
name = Resources;
sourceTree = "<group>";
};
08FB77AFFE84173DC02AAC07 /* Classes */ = {
isa = PBXGroup;
children = (
F506C03C013D9D7901CA16C8 /* ejabberdPref.h */,
F506C03D013D9D7901CA16C8 /* ejabberdPref.m */,
);
name = Classes;
sourceTree = "<group>";
};
1058C7ACFEA557BF11CA2CBB /* Linked Frameworks */ = {
isa = PBXGroup;
children = (
1058C7ADFEA557BF11CA2CBB /* Cocoa.framework */,
F506C035013D953901CA16C8 /* PreferencePanes.framework */,
);
name = "Linked Frameworks";
sourceTree = "<group>";
};
1058C7AEFEA557BF11CA2CBB /* Other Frameworks */ = {
isa = PBXGroup;
children = (
089C1672FE841209C02AAC07 /* Foundation.framework */,
089C167FFE841241C02AAC07 /* AppKit.framework */,
);
name = "Other Frameworks";
sourceTree = "<group>";
};
19C28FB8FE9D52D311CA2CBB /* Products */ = {
isa = PBXGroup;
children = (
8D202CF80486D31800D8A456 /* ejabberd.prefPane */,
);
name = Products;
sourceTree = "<group>";
};
32DBCFA10370C40200C91783 /* Other Sources */ = {
isa = PBXGroup;
children = (
837D1CC70B635DA9003F99C1 /* ejabberd.plist */,
837F6DD009F777FF00914317 /* ejabberdController.h */,
837F6DD109F777FF00914317 /* ejabberdController.m */,
32DBCFA20370C41700C91783 /* ejabberd_Prefix.pch */,
);
name = "Other Sources";
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXHeadersBuildPhase section */
8D202CE90486D31800D8A456 /* Headers */ = {
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
8D202CEA0486D31800D8A456 /* ejabberd_Prefix.pch in Headers */,
8D202CEB0486D31800D8A456 /* ejabberdPref.h in Headers */,
837F6DD209F777FF00914317 /* ejabberdController.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXHeadersBuildPhase section */
/* Begin PBXNativeTarget section */
8D202CE80486D31800D8A456 /* ejabberd */ = {
isa = PBXNativeTarget;
buildConfigurationList = 83231E620B57EBEA006434E8 /* Build configuration list for PBXNativeTarget "ejabberd" */;
buildPhases = (
8D202CE90486D31800D8A456 /* Headers */,
8D202CEC0486D31800D8A456 /* Resources */,
8D202CF00486D31800D8A456 /* Sources */,
8D202CF20486D31800D8A456 /* Frameworks */,
8D202CF50486D31800D8A456 /* Rez */,
);
buildRules = (
);
dependencies = (
);
name = ejabberd;
productInstallPath = "$(HOME)/Library/PreferencePanes";
productName = ejabberd;
productReference = 8D202CF80486D31800D8A456 /* ejabberd.prefPane */;
productType = "com.apple.product-type.bundle";
};
/* End PBXNativeTarget section */
/* Begin PBXProject section */
089C1669FE841209C02AAC07 /* Project object */ = {
isa = PBXProject;
buildConfigurationList = 83231E660B57EBEA006434E8 /* Build configuration list for PBXProject "ejabberd" */;
hasScannedForEncodings = 1;
mainGroup = 089C166AFE841209C02AAC07 /* ejabberd */;
projectDirPath = "";
targets = (
8D202CE80486D31800D8A456 /* ejabberd */,
);
};
/* End PBXProject section */
/* Begin PBXResourcesBuildPhase section */
8D202CEC0486D31800D8A456 /* Resources */ = {
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D202CED0486D31800D8A456 /* InfoPlist.strings in Resources */,
8D202CEE0486D31800D8A456 /* ejabberdPref.tiff in Resources */,
8D202CEF0486D31800D8A456 /* ejabberdPref.nib in Resources */,
837F6DDD09F7E55000914317 /* logo_ejabberd.png in Resources */,
837F6DDF09F7E6FD00914317 /* logo_ejabberd.png in Resources */,
837F6DE409F7E8BF00914317 /* instance_started.png in Resources */,
837F6DE509F7E8BF00914317 /* instance_stopped.png in Resources */,
837F6DEE09F8D41200914317 /* config.txt in Resources */,
837D1CC80B635DA9003F99C1 /* ejabberd.plist in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXResourcesBuildPhase section */
/* Begin PBXRezBuildPhase section */
8D202CF50486D31800D8A456 /* Rez */ = {
isa = PBXRezBuildPhase;
buildActionMask = 2147483647;
files = (
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXRezBuildPhase section */
/* Begin PBXSourcesBuildPhase section */
8D202CF00486D31800D8A456 /* Sources */ = {
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
8D202CF10486D31800D8A456 /* ejabberdPref.m in Sources */,
837F6DD309F777FF00914317 /* ejabberdController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */
/* Begin PBXVariantGroup section */
089C167DFE841241C02AAC07 /* InfoPlist.strings */ = {
isa = PBXVariantGroup;
children = (
089C167EFE841241C02AAC07 /* English */,
);
name = InfoPlist.strings;
sourceTree = "<group>";
};
F506C042013D9D8C01CA16C8 /* ejabberdPref.nib */ = {
isa = PBXVariantGroup;
children = (
F506C043013D9D8C01CA16C8 /* English */,
);
name = ejabberdPref.nib;
sourceTree = "<group>";
};
/* End PBXVariantGroup section */
/* Begin XCBuildConfiguration section */
83231E630B57EBEA006434E8 /* Development */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
COPY_PHASE_STRIP = NO;
DEBUGGING_SYMBOLS = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_DYNAMIC_NO_PIC = NO;
GCC_ENABLE_FIX_AND_CONTINUE = YES;
GCC_ENABLE_TRIGRAPHS = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ejabberd_Prefix.pch;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
GCC_WARN_UNKNOWN_PRAGMAS = NO;
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/PreferencePanes";
LIBRARY_SEARCH_PATHS = "";
LIBRARY_STYLE = Bundle;
OPTIMIZATION_CFLAGS = "-O0";
OTHER_CFLAGS = "";
OTHER_LDFLAGS = (
"-bundle",
"-twolevel_namespace",
);
OTHER_REZFLAGS = "";
PRODUCT_NAME = ejabberd;
SECTORDER_FLAGS = "";
WARNING_CFLAGS = (
"-Wmost",
"-Wno-four-char-constants",
"-Wno-unknown-pragmas",
);
WRAPPER_EXTENSION = prefPane;
ZERO_LINK = YES;
};
name = Development;
};
83231E640B57EBEA006434E8 /* Deployment */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
COPY_PHASE_STRIP = YES;
FRAMEWORK_SEARCH_PATHS = "";
GCC_ENABLE_FIX_AND_CONTINUE = NO;
GCC_ENABLE_TRIGRAPHS = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ejabberd_Prefix.pch;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
GCC_WARN_UNKNOWN_PRAGMAS = NO;
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/PreferencePanes";
LIBRARY_SEARCH_PATHS = "";
LIBRARY_STYLE = Bundle;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = (
"-bundle",
"-twolevel_namespace",
);
OTHER_REZFLAGS = "";
PRODUCT_NAME = ejabberd;
SECTORDER_FLAGS = "";
WARNING_CFLAGS = (
"-Wmost",
"-Wno-four-char-constants",
"-Wno-unknown-pragmas",
);
WRAPPER_EXTENSION = prefPane;
ZERO_LINK = NO;
};
name = Deployment;
};
83231E650B57EBEA006434E8 /* Default */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
FRAMEWORK_SEARCH_PATHS = "";
GCC_ENABLE_TRIGRAPHS = NO;
GCC_GENERATE_DEBUGGING_SYMBOLS = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
GCC_PREFIX_HEADER = ejabberd_Prefix.pch;
GCC_WARN_ABOUT_MISSING_PROTOTYPES = NO;
GCC_WARN_FOUR_CHARACTER_CONSTANTS = NO;
GCC_WARN_UNKNOWN_PRAGMAS = NO;
HEADER_SEARCH_PATHS = "";
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = "$(HOME)/Library/PreferencePanes";
LIBRARY_SEARCH_PATHS = "";
LIBRARY_STYLE = Bundle;
OTHER_CFLAGS = "";
OTHER_LDFLAGS = (
"-bundle",
"-twolevel_namespace",
);
OTHER_REZFLAGS = "";
PRODUCT_NAME = ejabberd;
SECTORDER_FLAGS = "";
WARNING_CFLAGS = (
"-Wmost",
"-Wno-four-char-constants",
"-Wno-unknown-pragmas",
);
WRAPPER_EXTENSION = prefPane;
};
name = Default;
};
83231E670B57EBEA006434E8 /* Development */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Development;
};
83231E680B57EBEA006434E8 /* Deployment */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Deployment;
};
83231E690B57EBEA006434E8 /* Default */ = {
isa = XCBuildConfiguration;
buildSettings = {
ARCHS = (
ppc,
i386,
);
SDKROOT = /Developer/SDKs/MacOSX10.4u.sdk;
};
name = Default;
};
/* End XCBuildConfiguration section */
/* Begin XCConfigurationList section */
83231E620B57EBEA006434E8 /* Build configuration list for PBXNativeTarget "ejabberd" */ = {
isa = XCConfigurationList;
buildConfigurations = (
83231E630B57EBEA006434E8 /* Development */,
83231E640B57EBEA006434E8 /* Deployment */,
83231E650B57EBEA006434E8 /* Default */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Deployment;
};
83231E660B57EBEA006434E8 /* Build configuration list for PBXProject "ejabberd" */ = {
isa = XCConfigurationList;
buildConfigurations = (
83231E670B57EBEA006434E8 /* Development */,
83231E680B57EBEA006434E8 /* Deployment */,
83231E690B57EBEA006434E8 /* Default */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Deployment;
};
/* End XCConfigurationList section */
};
rootObject = 089C1669FE841209C02AAC07 /* Project object */;
}

View File

@ -0,0 +1,34 @@
//
// ejabberdController.h
// ejabberd preference pane
//
// Created on Wed Apr 19 2006.
// Copyright (c) 2006-2009 ProcessOne.
//
#import <Cocoa/Cocoa.h>
@interface ejabberdController : NSObject
{
IBOutlet NSTextField *status;
//IBOutlet NSImageView *image;
IBOutlet NSImageView *imagestarted;
IBOutlet NSImageView *imagestopped;
IBOutlet NSProgressIndicator *actionProgress;
IBOutlet NSButton *startStopButton;
IBOutlet NSButton *automaticBox;
BOOL started;
char startscript[128];
char stopscript[128];
char statusscript[128];
char waitstartedscript[128];
char waitstoppedscript[128];
}
- (void)setStarted:(BOOL)flag;
- (BOOL)isStarted;
- (void)getRunningStatus;
- (void)waitRunningStatus;
- (void)updateRunningStatus;
- (IBAction)startStopAction:(id)sender;
- (IBAction)automaticStartAction:(id)sender;
@end

View File

@ -0,0 +1,125 @@
//
// ejabberdController.m
// ejabberd preference pane
//
// Created on Wed Apr 19 2006.
// Copyright (c) 2006-2009 ProcessOne.
//
#import "ejabberdController.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@implementation ejabberdController
- (id) init
{
if((self = [super init])) {
[self performSelector:@selector(getRunningStatus) withObject:self afterDelay:0.5];
/*
[automaticBox setState:1];
[automaticBox setNeedsDisplay];
NSDictionary *defaultDefaults = [[NSDictionary alloc] initWithContentsOfFile:
[bundle pathForResource:@"ejabberdPath" ofType:@"plist"]];
[[EjabberdPreferences preferences] registerDefaults:defaultDefaults];
[defaultDefaults release];
*/
//TODO: This is very dirty code. need rewrite by MacOS/ObjC coder.
FILE *file;
char conf[255];
strcpy(conf, getenv("HOME"));
strcat(conf, "/Library/PreferencePanes/ejabberd.prefPane/Contents/Resources/config.txt");
file = fopen(conf,"r");
char path[255], *ptr;
memset(path, 0, 128);
fgets(path, 127, file);
for(ptr=path; *ptr; ptr++)
{
if(*ptr==10) *ptr=0;
if(*ptr==13) *ptr=0;
}
fclose(file);
sprintf(startscript, "%s/bin/ejabberdctl start", path);
sprintf(stopscript, "%s/bin/ejabberdctl stop", path);
sprintf(statusscript, "%s/bin/ejabberdctl status", path);
sprintf(waitstartedscript, "%s/bin/ejabberdctl started", path);
sprintf(waitstoppedscript, "%s/bin/ejabberdctl stopped", path);
}
return self;
}
- (void) setStarted:(BOOL)flag
{
started = flag;
}
- (BOOL) isStarted
{
return started;
}
- (void) getRunningStatus
{
[actionProgress startAnimation:self];
started = (system(statusscript) == 0);
[self updateRunningStatus];
}
- (void) waitRunningStatus
{
[actionProgress startAnimation:self];
system(started?waitstartedscript:waitstoppedscript);
[self getRunningStatus];
}
- (void) updateRunningStatus
{
//[startStopButton setTitle:isStarted
// ? NSLocalizedStringFromTableInBundle(@"Stop ejabberd",nil,bundle,@"")
// : NSLocalizedStringFromTableInBundle(@"Start ejabberd",nil,bundle,@"")];
if(started)
{
[startStopButton setTitle:@"Stop ejabberd"];
[status setStringValue:@"ejabberd is started."];
[imagestarted setHidden:NO];
[imagestopped setHidden:YES];
} else {
[startStopButton setTitle:@"Start ejabberd"];
[status setStringValue:@"ejabberd is stopped."];
[imagestarted setHidden:YES];
[imagestopped setHidden:NO];
}
[actionProgress stopAnimation:self];
}
-(IBAction)startStopAction:(id)sender
{
[actionProgress startAnimation:self];
if(started)
{
[status setStringValue:@"Stopping ejabberd..."];
started = !(system(stopscript) == 0);
} else {
[status setStringValue:@"Starting ejabberd..."];
started = (system(startscript) == 0);
}
[self performSelector:@selector(waitRunningStatus) withObject:self afterDelay:0.5];
}
-(IBAction)automaticStartAction:(id)sender
{
//TODO: implement autostart
if([automaticBox state])
{
system("mkdir -p ~/Library/LaunchDaemons");
system("cp /Library/PreferencePanes/ejabberd.prefPane/Contents/Resources/ejabberd.plist ~/Library/LaunchDaemons");
system("launchctl load ~/Library/LaunchDaemons/ejabberd.plist");
} else {
system("launchctl unload ~/Library/LaunchDaemons/ejabberd.plist");
system("rm ~/Library/LaunchDaemons/ejabberd.plist");
}
}
@end

View File

@ -0,0 +1,19 @@
//
// ejabberdPref.h
// ejabberd preference pane
//
// Created on Wed Apr 19 2006.
// Copyright (c) 2006-2009 ProcessOne.
//
#import <PreferencePanes/PreferencePanes.h>
@interface ejabberdPref : NSPreferencePane
{
}
- (void) mainViewDidLoad;
@end

View File

@ -0,0 +1,19 @@
//
// ejabberdPref.m
// ejabberd preference pane
//
// Created on Wed Apr 19 2006.
// Copyright (c) 2006-2009 ProcessOne.
//
#import "ejabberdPref.h"
@implementation ejabberdPref
- (void) mainViewDidLoad
{
//ejabberdPref->ejabberdController
}
@end

Binary file not shown.

View File

@ -0,0 +1,8 @@
//
// Prefix header for all source files of the 'ejabberd' target in the 'ejabberd' project.
//
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildVersion</key>
<string>54</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>ProjectName</key>
<string>PreferencePaneTemplate</string>
<key>SourceVersion</key>
<string>120000</string>
</dict>
</plist>

343
ejabberd_xmlrpc/COPYING Normal file
View File

@ -0,0 +1,343 @@
As a special exception, the authors give permission to link this program
with the OpenSSL library and distribute the resulting binary.
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

130
ejabberd_xmlrpc/ChangeLog Normal file
View File

@ -0,0 +1,130 @@
2009-09-11 Badlop <badlop@process-one.net>
* src/ejabberd_xmlrpc.erl: Update to work with ejabberd 2.1.0
2009-04-28 Badlop <badlop@process-one.net>
* src/ejabberd_xmlrpc.erl: Improve handling of errors in arguments
2009-04-17 Badlop <badlop@process-one.net>
* src/ejabberd_xmlrpc.erl: Change access_commands to use the new
AccessCommands feature of ejabberd. Syntax is similar (EJAB-910)
2009-03-02 Badlop <badlop@process-one.net>
* src/ejabberd_xmlrpc.erl: Replace the listener option 'access'
with the much more powerful 'access_commands', that allows to
grant selective permission to execute commands with certain
arguments
* README.txt: Likewise
2009-02-24 Badlop <badlop@process-one.net>
* src/ejabberd_xmlrpc.erl: Update to work with recent ejabberd
trunk SVN (thanks to Artem Yurov)
* README.txt: Likewise
2008-10-21 Badlop <badlop@process-one.net>
* README.txt: Updated PHP example
2008-10-12 Badlop <badlop@process-one.net>
* src/ejabberd_xmlrpc.erl: Major rewrite of mod_xmlrpc to be an
ejabberd independent listener, and to be a frontend of ejabberd
commands (EJAB-694)
2008-08-31 Badlop <badlop@process-one.net>
* README.txt: Added Java example client and fixed the PHP
example (thanks to Calder)
2008-07-24 Badlop <badlop@process-one.net>
* src/mod_xmlrpc.erl: Fixed typo in get_roster
2008-07-08 Badlop <badlop@process-one.net>
* src/mod_xmlrpc.erl: Detect if mod_roster or mod_roster_odbc is
enabled. New call send_message (thanks to Darren Ferguson)
* README.txt: Likewise
2008-05-20 Badlop <badlop@process-one.net>
* src/mod_xmlrpc.erl: New call get_roster; works only with
mod_roster_odbc
* README.txt: Likewise
2008-05-19 Badlop <badlop@process-one.net>
* src/mod_xmlrpc.erl: New function check_account (thanks to
Zbyszek Żółkiewski)
* README.txt: Likewise
2008-05-18 Badlop <badlop@process-one.net>
* README.txt: Added example client in PHP (thanks to Zbyszek
Żółkiewski)
* src/mod_xmlrpc.erl: Convert from DOS to Unix line format
* README.txt: Likewise
* ChangeLog: Likewise
2008-05-16 Badlop <badlop@process-one.net>
* src/mod_xmlrpc.erl: New calls muc_room_change_option and
muc_room_set_affiliation. Improved calls add_rosteritem and
delete_rosteritem: they push the changed roster item to connected
resources (thanks to Darren Ferguson). New call check_password.
* README.txt: Likewise
2008-05-06 Badlop <badlop@process-one.net>
* src/mod_xmlrpc.erl: Added new calls delete_account,
delete_rosteritem, create_muc_room and destroy_muc_room (thanks to
Darren Ferguson)
* README.txt: Likewise
2008-02-29 Badlop <badlop@process-one.net>
* src/mod_xmlrpc.erl: Added module options: maxsessions, timeout
* README.txt: Likewise
2007-08-24 Badlop <badlop@ono.com>
* README.txt: Removed requirement of Xmerl 0.20, since it is
included in Erlang/OTP. Instead, require updated XMLRPC-Erlang.
2007-08-21 Badlop <badlop@ono.com>
* README.txt: New Ruby example (thanks to Diddek). Patched xmlrpc
Erlang library for Ruby compatibility (thanks to Cstar).
* mod_xmlrpc/*: Initial commit.
Old Changelog:
0.2.4 - 7 November 2006
* Fixed a bug that required clients to provide attributes in a fixed order
0.2.3 - 22 September 2006
* New feature: bind to a specific IP address, requires the patched XML-RPC-Erlang-1.13-IP (thanks to Zeank)
0.2.2 - 15 August 2006
* Fixed small bug on resource_num (thanks to Flipkick)
0.2.1 - 20 July 2006
* Fixed small bug on add_rosteritem (thanks to Leonexis)
0.2.0 - 16 April 2006
* Added two new calls: num_resources and resouce_num
* Added support for vhosts
0.1.2 - 28 December 2005
* Now compatible with ejabberd 1.0.0
* The XMLRPC server is started only once, not once for every virtual host
* Added comments for handlers. Every available handler must be explained
0.1.0 - 4 April 2005
* Initial version

View File

@ -0,0 +1,2 @@
{'../ejabberd-dev/src/gen_mod', [{outdir, "../ejabberd-dev/ebin"},{i,"../ejabberd-dev/include"}]}.
{'src/ejabberd_xmlrpc', [{outdir, "ebin"},{i,"../ejabberd-dev/include"}]}.

499
ejabberd_xmlrpc/README.txt Normal file
View File

@ -0,0 +1,499 @@
ejabberd_xmlrpc - XML-RPC server
Homepage: http://www.ejabberd.im/ejabberd_xmlrpc
Author: Badlop
DESCRIPTION
-----------
ejabberd_xmlrpc is an ejabberd listener that starts a XML-RPC server
and waits for external calls.
ejabberd_xmlrpc implements some example calls that can be used to test
during the development of a new XML-RPC client. But most
importantly, ejabberd_xmlrpc is also a frontend to execute ejabberd
commands. This way a XML-RPC client can execute any ejabberd command.
This allows external programs written in any language like websites or
administrative tools to communicate with ejabberd to get information
or to make changes without the need to know ejabberd internals. One
example usage is a corporate site in PHP that creates a Jabber user
every time a new user is created on the website.
Some benefits of interfacing with the Jabber server by XML-RPC instead
of modifying directly the database are:
- external programs are more simple and easy to develop and debug
- can communicate with a server in a different machine, and even on Internet
REQUIREMENTS
------------
ejabberd 2.1.0 or higher
XMLRPC-Erlang 1.13 with IP, Ruby and Xmerl 1.x patches
Optional: mod_admin_extra implements many ejabberd commands for general server administration
Optional: mod_muc_admin implements ejabberd commands for MUC administration
CONFIGURE EJABBERD
------------------
1. You need to get and install XMLRPC-Erlang.
You can download XMLRPC-Erlang binary files from
http://www.ejabberd.im/ejabberd_xmlrpc
or compile it yourself:
wget http://www.ejabberd.im/files/contributions/xmlrpc-1.13-ipr2.tgz
tar -xzvf xmlrpc-1.13-ipr2.tgz
cd xmlrpc-1.13/src
make
cd ../../
Then you can copy the *.beam files to ejabberd ebin directory,
or add an option like this to the ejabberd start script:
$ erl -pa '/home/jabber/xmlrpc-1.13/ebin' ...
2. Configure ejabberd to start this listener at startup:
edit ejabberd.cfg and add on the 'listen' section:
{listen, [
{4560, ejabberd_xmlrpc, []},
...
]}.
3. Start ejabberd.
4. Verify that ejabberd is listening in that port:
$ netstat -n -l | grep 4560
tcp 0 0 0.0.0.0:4560 0.0.0.0:* LISTEN
5. If there is any problem, check ejabberd.log and sasl.log files
CONFIGURE
---------
The listener allow several configurable options:
{maxsessions, Integer}
Number of concurrent connections allowed.
Default: 10
{timeout, Integer}
Timeout of the connections, expressed in milliseconds.
Default: 5000
{access_commands, AccessCommands}
This option allows to define a list of access restrictions.
If this option is present, then XML-RPC calls must include as
first argument a struct with a user, server and password of an
account in ejabberd that has privileges in Access.
If the option is not present, such struct must not be provided.
The default value is to not define any restriction: []
When one or several access restrictions are defined and the
XML-RPC call provides authentication for an account, each
restriction is verified until one matches completely:
the account matches the Access rule,
the command name is listed in CommandNames,
and the provided arguments do not contradict Arguments.
There is more information about AccessCommands in the ejabberd Guide.
Example configuration: XML-RPC calls can execute any command, with any
argument, and no authentication information must be provided:
{listen, [
{4560, ejabberd_xmlrpc, [{maxsessions, 10}, {timeout, 5000}]},
...
]}.
In this case authentication information must be provided, but it is
enough that the account exists and the password is valid to execute
any command:
{listen, [
{4560, ejabberd_xmlrpc, [{maxsessions, 10}, {timeout, 5000},
{access_commands, [{all, all, []}]}]},
...
]}.
In this example the local Jabber account xmlrpc-robot@jabber.example.org
can execute any command with no argument restriction:
{acl, xmlrpcbot, {user, "xmlrpc-robot", "jabber.example.org"}}.
{access, xmlrpcaccess, [{allow, xmlrpcbot}]}.
{listen, [
{4560, ejabberd_xmlrpc, [{maxsessions, 10}, {timeout, 5000},
{access_commands, [{xmlrpcaccess, all, []}]}]},
...
]}.
Finally, in this complex example the listener only listens in port
4560 of IP address 127.0.0.1, and several access restrictions are
defined (the corresponding ACL and ACCESS are not shown):
{listen, [
{{4560, "127.0.0.1"}, ejabberd_xmlrpc, [
{access_commands, [
%% This bot can execute any command:
{xmlrpc_bot, all, []},
%% This bot can execute any command,
%% but if a 'host' argument is provided, it must be "example.org":
{xmlrpc_bot_all_example, all, [{host, "example.org"}]},
%% This bot can only execute the command 'dump'. No argument restriction:
{xmlrpc_bot_backups, [dump], []}
%% This bot can only execute the command 'register',
%% and if argument 'host' is provided, it must be "example.org":
{xmlrpc_bot_reg_example, [register], [{host, "example.org"}]},
%% This bot can execute the commands 'register' and 'unregister',
%% if argument host is provided, it must be "test.org":
{xmlrpc_bot_reg_test, [register, unregister], [{host, "test.org"}]}
]}
]},
...
]}.
USAGE
-----
You can send calls to http://host:4560/
Call: Arguments: Returns:
-- debug
echothis String String
echothisnew struct[{sentence, String}] struct[{repeated, String}]
multhis struct[{a, Integer}, {b, Integer}] Integer
multhisnew struct[{a, Integer}, {b, Integer}] struct[{mu, Integer}]
-- statistics
tellme_title String String
tellme_value String String
tellme String struct[{title, String}, {value. String}]
With ejabberd_xmlrpc you can execute any ejabberd command with a XML-RPC call.
1. Get a list of available ejabberd commands, for example:
$ ejabberdctl help
Available commands in this ejabberd node:
connected_users List all established sessions
connected_users_number Get the number of established sessions
delete_expired_messages Delete expired offline messages from database
delete_old_messages days Delete offline messages older than DAYS
dump file Dump the database to text file
register user host password Register a user
registered_users host List all registered users in HOST
reopen_log Reopen the log files
restart Restart ejabberd
restore file Restore the database from backup file
status Get ejabberd status
stop Stop ejabberd
unregister user host Unregister a user
user_resources user host List user's connected resources
2. When you found the command you want to call, get some additional
help of the arguments and result:
$ ejabberdctl help user_resources
Command Name: user_resources
Arguments: user::string
host::string
Returns: resources::[ resource::string ]
Tags: session
Description: List user's connected resources
3. You can try to execute the command in the shell for the account testuser@localhost:
$ ejabberdctl user_resources testuser localhost
Home
Psi
4. Now implement the proper XML-RPC call in your XML-RPC client.
This example will use the Erlang library:
$ erl
1> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, user_resources, [{struct, [{user, "testuser"}, {host, "localhost"}]}]}).
{ok,{response,[{struct,[{resources,{array,[{struct,[{resource,"Home"}]},
{struct,[{resource,"Psi"}]}]}}]}]}}
5. Note: if ejabberd_xmlrpc has the option 'access_commands'
configured with some access restriction (see the example
configurations provided above), the XML-RPC must include first an
argument providing information of a valid account. For example:
1> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, user_resources, [
{struct, [{user, "adminuser"}, {server, "localhost"}, {password, "aeiou"}]},
{struct, [{user, "testuser"}, {host, "localhost"}]} ]}).
Arguments in XML-RPC calls can be provided in any order;
This module will sort the arguments before calling the ejabberd command.
If auth is provided in the call when ejabberd_xmlrpc does not require it,
the call will return the error: -112 Unknown call
EXAMPLE IN PHP
--------------
This is an XML-RPC client in PHP, thanks to Zbyszek Żółkiewski and Calder.
It requires "allow_url_fopen = On" in your php.ini.
-------
<?
$param=array("user"=>"testuser", "host"=>"localhost");
$request = xmlrpc_encode_request('user_resources', $param, (array('encoding' => 'utf-8')));
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "User-Agent: XMLRPC::Client mod_xmlrpc\r\n" .
"Content-Type: text/xml\r\n" .
"Content-Length: ".strlen($request),
'content' => $request
)));
$file = file_get_contents("http://127.0.0.1:4560/RPC2", false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
trigger_error("xmlrpc: $response[faultString] ($response[faultCode])");
} else {
print_r($response);
}
?>
-------
The response, following the example would be like this:
-------
$ php5 call.php
Array
(
[resources] => Array
(
[0] => Array
(
[resource] => Home
)
[1] => Array
(
[resource] => Psi
)
)
)
-------
If you configured the option access_commands, you have to provide authentication
information by replacing the first lime with something like this:
-------
$param_auth=array("user"=>"analloweduser", "server"=>"localhost", "password"=>"MyPasS997");
$param_comm=array("user"=>"testuser", "host"=>"localhost");
$param=array($param_auth, $param_comm);
-------
**** WARNING: all the remaining text was written for mod_xmlrpc and
is NOT valid for ejabberd_xmlrpc ****
TEST
----
- You can easily try the XML-RPC server starting a new Erlang Virtual Machine
and making calls to ejabberd's XML-RPC:
1. Start Erlang with this option:
$ erl -pa '/home/jabber/xmlrpc-1.13/ebin'
2. Now on the Erlang console, write commands and check the results:
1> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echothis, [800]}).
{ok,{response,[800]}}
2> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echothis, ["blot cloc 557.889 kg"]}).
{ok,{response,["blot cloc 557.889 kg"]}}
3> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, multhis, [{struct,[{a, 83}, {b, 689}]}]}).
{ok,{response,[57187]}}
4> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, register,
[{struct, [{user, "ggeo"}, {host, "example.com"}, {password, "gogo11"}]}]}).
{ok,{response,[0]}}
5> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, register,
[{struct, [{user, "ggeo"}, {host, "example.com"}, {password, "gogo11"}]}]}).
{ok,{response,[409]}}
6> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, muc_room_change_option,
[{struct, [{name, "test"}, {service, "conference.localhost"},
{option, "title"}, {value, "Test Room"}]}]}).
7> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, muc_room_set_affiliation,
[{struct, [{name, "test"}, {service, "conference.example.com"},
{jid, "ex@example.com"}, {affiliation, "member"}]}]}).
8> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, muc_room_set_affiliation,
[{struct, [{name, "test"}, {service, "conference.example.com"},
{jid, "ex@example.com"}, {affiliation, "none"}]}]}).
- Some possible XML-RPC error messages:
+ Client: connection refused: wrong IP, wrong port, the server is not started...
2> xmlrpc:call({127, 0, 0, 1}, 44444, "/", {call, echothis, [800]}).
{error,econnrefused}
+ Client: bad value: a800 is a string, so it must be put into ""
7> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echothis, [a800]}).
{error,{bad_value,a800}}
+ Server: unknown call: you sent a call that the server does not implement
3> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, bububu, [800]}).
{ok,{response,{fault,-1,"Unknown call: {call,bububu,[800]}"}}}
EXAMPLE IN PYTHON
-----------------
This is an example XML-RPC client in Python, thanks to Diddek:
-------
import xmlrpclib
server_url = 'http://127.0.0.1:4560';
server = xmlrpclib.Server(server_url);
params = {}
params["user"] = "ggeo"
params["host"] = "localhost"
params["password"] = "gogo11"
result = server.register(params)
print result
-------
This Python example shows how to provide authentication in the call, thanks to Muelli:
-------
import xmlrpclib
server_url = 'http://127.0.0.1:4560'
server = xmlrpclib.ServerProxy(server_url)
EJABBERD_XMLRPC_LOGIN = {'user': 'adminuser', 'server': 'localhost', 'password': 'aeiou'}
def ejabberdctl(command, data):
fn = getattr(server, command)
return fn(EJABBERD_XMLRPC_LOGIN, data)
result = ejabberdctl('register', {'user':'ggeo', 'host':'localhost', 'password':'gogo11'})
print result
-------
EXAMPLE IN RUBY
---------------
This is an example XML-RPC client in Ruby, thanks to Diddek:
-------
require 'xmlrpc/client'
host = "172.16.29.6:4560"
timeout = 3000000
client = XMLRPC::Client.new2("http://#{host}", "#{host}", timeout)
result = client.call("echothis", "800")
puts result
-------
EXAMPLE IN JAVA
---------------
This is an XML-RPC client in Java, thanks to Calder.
It requires Apache XML-RPC available at http://ws.apache.org/xmlrpc/
-------
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.apache.xmlrpc.client.XmlRpcClient;
import org.apache.xmlrpc.client.XmlRpcClientConfigImpl;
public class Test {
public static void main(String[] args) {
try {
XmlRpcClientConfigImpl config = new XmlRpcClientConfigImpl();
config.setServerURL(new URL("http://127.0.0.1:4560/RPC2"));
XmlRpcClient client = new XmlRpcClient();
client.setConfig(config);
/* Command string */
String command = "check_password";
/* Parameters as struct */
Map struct = new HashMap();
struct.put("user", "test1");
struct.put("host", "localhost");
struct.put("password", "test");
Object[] params = new Object[]{struct};
Integer result = (Integer) client.execute(command, params);
System.out.println(result);
} catch (Exception e) {
System.out.println(e);
}
}
}
-------
EXAMPLE IN C#
-------------
This is an XML-RPC client in C#, thanks to Mitchel Constantin.
-------
// Copyright: 2010 Weavver, Inc.
// Author: Mitchel Constantin <mythicalbox@weavver.com>
// License: Public Domain (Limited to this file)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CookComputing.XmlRpc;
namespace Weavver.Vendors.ProcessOne
{
public struct send_message_chat
{
public string from;
public string to;
public string body;
}
public struct status {}
public class ejabberdRPC
{
[XmlRpcUrl("http://205.134.225.18:4560/RPC2")]
public interface IStateName : IXmlRpcProxy
{
[XmlRpcMethod("send_message_chat")]
object SendMessageChat(send_message_chat message);
[XmlRpcMethod("status")]
object Status(status s);
}
public CookComputing.XmlRpc.XmlRpcStruct SendMessageChat(send_message_chat message)
{
IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
proxy.KeepAlive = false;
return (CookComputing.XmlRpc.XmlRpcStruct) proxy.SendMessageChat(message);
}
public CookComputing.XmlRpc.XmlRpcStruct Status(status status)
{
IStateName proxy = XmlRpcProxyGen.Create<IStateName>();
proxy.KeepAlive = false;
return (CookComputing.XmlRpc.XmlRpcStruct) proxy.Status(status);
}
}
}
-------

View File

@ -0,0 +1 @@
erl -pa ../../ejabberd-dev/trunk/ebin -pa ebin -make

2
ejabberd_xmlrpc/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
erl -pa ../ejabberd-dev/ebin -pz ebin -make

View File

@ -0,0 +1,467 @@
%%%----------------------------------------------------------------------
%%% File : ejabberd_xmlrpc.erl
%%% Author : Badlop <badlop@process-one.net>
%%% Purpose : XML-RPC server that frontends ejabberd commands
%%% Created : 21 Aug 2007 by Badlop <badlop@ono.com>
%%% Id : $Id: ejabberd_xmlrpc.erl 595 2008-05-20 11:39:31Z badlop $
%%%----------------------------------------------------------------------
%%% TODO: Implement a command in ejabberdctl 'help COMMAND LANGUAGE' that shows
%%% a coding example to call that command in a specific language (python, php).
%%% TODO: Remove support for plaintext password
%%% TODO: commands strings should be strings without ~n
-module(ejabberd_xmlrpc).
-author('badlop@process-one.net').
-export([
start_listener/2,
handler/2,
socket_type/0
]).
-include("ejabberd.hrl").
-include("mod_roster.hrl").
-include("jlib.hrl").
-record(state, {access_commands, auth = noauth, get_auth}).
%% Test:
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, take_integer, [{struct, [{thisinteger, 5}]}]}).
%% {ok,{response,[{struct,[{zero,0}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_string, [{struct, [{thisstring, "abcd"}]}]}).
%% {ok,{response,[{struct,[{thatstring,"abcd"}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, tell_tuple_3integer, [{struct, [{thisstring, "abcd"}]}]}).
%% {ok,{response,
%% [{struct,
%% [{thattuple,
%% {array,
%% [{struct,[{first,123}]},
%% {struct,[{second,456}]},
%% {struct,[{third,789}]}]}}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, pow, [{struct, [{base, 5}, {exponent, 7}]}]}).
%% {ok,{response,[{struct,[{pow,78125}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, seq, [{struct, [{from, 3}, {to, 7}]}]}).
%% {ok,{response,[{array,[{struct,[{intermediate,3}]},
%% {struct,[{intermediate,4}]},
%% {struct,[{intermediate,5}]},
%% {struct,[{intermediate,6}]},
%% {struct,[{intermediate,7}]}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, substrs, [{struct, [{word, "abcd"}]}]}).
%% NO:
%% {ok,{response,[{array,[{struct,[{miniword,"a"}]},
%% {struct,[{miniword,"ab"}]},
%% {struct,[{miniword,"abc"}]},
%% {struct,[{miniword,"abcd"}]}]}]}}
%% {ok,{response,
%% [{struct,
%% [{substrings,
%% {array,
%% [{struct,[{miniword,"a"}]},
%% {struct,[{miniword,"ab"}]},
%% {struct,[{miniword,"abc"}]},
%% {struct,[{miniword,"abcd"}]}]}}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, splitjid, [{struct, [{jid, "abcd@localhost/work"}]}]}).
%% {ok,{response,
%% [{struct,
%% [{jidparts,
%% {array,
%% [{struct,[{user,"abcd"}]},
%% {struct,[{server,"localhost"}]},
%% {struct,[{resource,"work"}]}]}}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_integer_string, [{struct, [{thisstring, "abc"}, {thisinteger, 55}]}]}).
%% {ok,{response,
%% [{struct,
%% [{thistuple,
%% {array,
%% [{struct,[{thisinteger,55}]},
%% {struct,[{thisstring,"abc"}]}]}}]}]}}
%%
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_list_integer, [{struct, [{thislist, {array, [{struct, [{thisinteger, 55}, {thisinteger, 4567}]}]}}]}]}).
%% {ok,{response,
%% [{struct,
%% [{thatlist,
%% {array,
%% [{struct,[{thatinteger,55}]},
%% {struct,[{thatinteger,4567}]}]}}]}]}}
%%
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_integer_list_string, [{struct, [{thisinteger, 123456}, {thislist, {array, [{struct, [{thisstring, "abc"}, {thisstring, "bobo baba"}]}]}}]}]}).
%% {ok,
%% {response,
%% [{struct,
%% [{thistuple,
%% {array,
%% [{struct,[{thatinteger,123456}]},
%% {struct,
%% [{thatlist,
%% {array,
%% [{struct,[{thatstring,"abc"}]},
%% {struct,[{thatstring,"bobo baba"}]}]}}]}]}}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, take_tuple_2integer, [{struct, [{thistuple, {array, [{struct, [{thisinteger1, 55}, {thisinteger2, 4567}]}]}}]}]}).
%% {ok,{response,[{struct,[{zero,0}]}]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_isatils, [{struct,
%% [{thisinteger, 123456990},
%% {thisstring, "This is ISATILS"},
%% {thisatom, "test_isatils"},
%% {thistuple, {array, [{struct, [
%% {listlen, 2},
%% {thislist, {array, [{struct, [
%% {contentstring, "word1"},
%% {contentstring, "word 2"}
%% ]}]}}
%% ]}]}}
%% ]}]}).
%% {ok,{response,
%% [{struct,
%% [{results,
%% {array,
%% [{struct,[{thatinteger,123456990}]},
%% {struct,[{thatstring,"This is ISATILS"}]},
%% {struct,[{thatatom,"test_isatils"}]},
%% {struct,
%% [{thattuple,
%% {array,
%% [{struct,[{listlen,123456990}]},
%% {struct,[{thatlist,...}]}]}}]}]}}]}]}}
%% ecommand doesn't exist:
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_integer_string2, [{struct, [{thisstring, "abc"}]}]}).
%% {ok,{response,{fault,-1, "Unknown call: {call,echo_integer_string2,[{struct,[{thisstring,\"abc\"}]}]}"}}}
%%
%% Duplicated argument:
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_integer_string, [{struct, [{thisstring, "abc"}, {thisinteger, 44}, {thisinteger, 55}]}]}).
%% {ok,{response,{fault,-104, "Error -104\nAttribute 'thisinteger' duplicated:\n[{thisstring,\"abc\"},{thisinteger,44},{thisinteger,55}]"}}}
%%
%% Missing argument:
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echo_integer_string, [{struct, [{thisstring, "abc"}]}]}).
%% {ok,{response,{fault,-106, "Error -106\nRequired attribute 'thisinteger' not found:\n[{thisstring,\"abc\"}]"}}}
%%
%% Duplicated tuple element:
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, take_tuple_2integer, [{struct, [{thistuple, {array, [{struct, [{thisinteger1, 55}, {thisinteger1, 66}, {thisinteger2, 4567}]}]}}]}]}).
%% {ok,{response,{fault,-104, "Error -104\nAttribute 'thisinteger1' defined multiple times:\n[{thisinteger1,55},{thisinteger1,66},{thisinteger2,4567}]"}}}
%%
%% Missing element in tuple:
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, take_tuple_2integer, [{struct, [{thistuple, {array, [{struct, [{thisinteger1, 55}, {thisintegerc, 66}, {thisinteger, 4567}]}]}}]}]}).
%% {ok,{response,{fault,-106, "Error -106\nRequired attribute 'thisinteger2' not found:\n[{thisintegerc,66},{thisinteger,4567}]"}}}
%%
%% The ecommand crashed:
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, this_crashes, [{struct, []}]}).
%% {ok,{response,{fault,-100, "Error -100\nA problem 'error' occurred executing the command this_crashes with arguments []: badarith"}}}
%% -----------------------------
%% Listener interface
%% -----------------------------
start_listener({Port, Ip, tcp = _TranportProtocol}, Opts) ->
%% get options
MaxSessions = gen_mod:get_opt(maxsessions, Opts, 10),
Timeout = gen_mod:get_opt(timeout, Opts, 5000),
AccessCommands = gen_mod:get_opt(access_commands, Opts, []),
GetAuth = case [ACom || {Ac, _, _} = ACom <- AccessCommands, Ac /= all] of
[] -> false;
_ -> true
end,
%% start the XML-RPC server
Handler = {?MODULE, handler},
State = #state{access_commands = AccessCommands, get_auth = GetAuth},
xmlrpc:start_link(Ip, Port, MaxSessions, Timeout, Handler, State).
socket_type() ->
independent.
%% -----------------------------
%% Access verification
%% -----------------------------
%% @spec (AuthList) -> {User, Server, Password}
%% where
%% AuthList = [{user, string()}, {server, string()}, {password, string()}]
%% It may throw: {error, missing_auth_arguments, Attr}
get_auth(AuthList) ->
%% Check AuthList contains all the required data
[User, Server, Password] =
try get_attrs([user, server, password], AuthList) of
[U, S, P] -> [U, S, P]
catch
exit:{attribute_not_found, Attr, _} ->
throw({error, missing_auth_arguments, Attr})
end,
{User, Server, Password}.
%% -----------------------------
%% Handlers
%% -----------------------------
%% Call: Arguments: Returns:
%% .............................
%% Access verification
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echothis, [152]}).
%% {ok,{response,{fault,-103, "Error -103\nRequired authentication: {call,echothis,[152]}"}}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echothis, [{struct, [{user, "badlop"}, {server, "localhost"}, {password, "ada"}]}, 152]}).
%% {ok,{response,{fault,-103,
%% "Error -103\nAuthentication non valid: [{user,\"badlop\"},\n
%% {server,\"localhost\"},\n
%% {password,\"ada\"}]"}}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echothis, [{struct, [{user, "badlop"}, {server, "localhost"}, {password, "ada90ada"}]}, 152]}).
%% {ok,{response,[152]}}
%%
%% xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, echothis, [{struct, [{user, "badlop"}, {server, "localhost"}, {password, "79C1574A43BC995F2B145A299EF97277"}]}, 152]}).
%% {ok,{response,[152]}}
handler(#state{get_auth = true, auth = noauth} = State, {call, Method, [{struct, AuthList} | Arguments] = AllArgs}) ->
try get_auth(AuthList) of
Auth ->
handler(State#state{get_auth = false, auth = Auth}, {call, Method, Arguments})
catch
{error, missing_auth_arguments, _Attr} ->
handler(State#state{get_auth = false, auth = noauth}, {call, Method, AllArgs})
end;
%% .............................
%% Debug
%% echothis String String
handler(_State, {call, echothis, [A]}) ->
{false, {response, [A]}};
%% echothisnew struct[{sentence, String}] struct[{repeated, String}]
handler(_State, {call, echothisnew, [{struct, [{sentence, A}]}]}) ->
{false, {response, [{struct, [{repeated, A}]}]}};
%% multhis struct[{a, Integer}, {b, Integer}] Integer
handler(_State, {call, multhis, [{struct, [{a, A}, {b, B}]}]}) ->
{false, {response, [A*B]}};
%% multhisnew struct[{a, Integer}, {b, Integer}] struct[{mu, Integer}]
handler(_State, {call, multhisnew, [{struct, [{a, A}, {b, B}]}]}) ->
{false, {response, [{struct, [{mu, A*B}]}]}};
%% .............................
%% Statistics
%% tellme_title String String
handler(_State, {call, tellme_title, [A]}) ->
{false, {response, [get_title(A)]}};
%% tellme_value String String
handler(_State, {call, tellme_value, [A]}) ->
N = node(),
{false, {response, [get_value(N, A)]}};
%% tellme String struct[{title, String}, {value. String}]
handler(_State, {call, tellme, [A]}) ->
N = node(),
T = {title, get_title(A)},
V = {value, get_value(N, A)},
R = {struct, [T, V]},
{false, {response, [R]}};
%% .............................
%% ejabberd commands
handler(State, {call, Command, []}) ->
%% The XMLRPC request may not contain a struct parameter,
%% but our internal functions need such struct, even if it's empty
%% So let's add it and do a recursive call:
handler(State, {call, Command, [{struct, []}]});
handler(State, {call, Command, [{struct, AttrL}]} = Payload) ->
case ejabberd_commands:get_command_format(Command) of
{error, command_unknown} ->
build_fault_response(-112, "Unknown call: ~p", [Payload]);
{ArgsF, ResultF} ->
try_do_command(State#state.access_commands, State#state.auth, Command, AttrL, ArgsF, ResultF)
end;
%% If no other guard matches
handler(_State, Payload) ->
build_fault_response(-112, "Unknown call: ~p", [Payload]).
%% -----------------------------
%% Command
%% -----------------------------
try_do_command(AccessCommands, Auth, Command, AttrL, ArgsF, ResultF) ->
try do_command(AccessCommands, Auth, Command, AttrL, ArgsF, ResultF) of
{command_result, ResultFormatted} ->
{false, {response, [ResultFormatted]}}
catch
exit:{duplicated_attribute, ExitAt, ExitAtL} ->
build_fault_response(-114, "Attribute '~p' duplicated:~n~p", [ExitAt, ExitAtL]);
exit:{attribute_not_found, ExitAt, ExitAtL} ->
build_fault_response(-116, "Required attribute '~p' not found:~n~p", [ExitAt, ExitAtL]);
exit:{additional_unused_args, ExitAtL} ->
build_fault_response(-120, "The call provided additional unused arguments:~n~p", [ExitAtL]);
throw:Why ->
build_fault_response(-118, "A problem '~p' occurred executing the command ~p with arguments~n~p", [Why, Command, AttrL])
end.
build_fault_response(Code, ParseString, ParseArgs) ->
FaultString = "Error " ++ integer_to_list(Code) ++ "\n" ++
lists:flatten(io_lib:format(ParseString, ParseArgs)),
?WARNING_MSG(FaultString, []), %% Show Warning message in ejabberd log file
{false, {response, {fault, Code, FaultString}}}.
do_command(AccessCommands, Auth, Command, AttrL, ArgsF, ResultF) ->
ArgsFormatted = format_args(AttrL, ArgsF),
Result = ejabberd_commands:execute_command(AccessCommands, Auth, Command, ArgsFormatted),
ResultFormatted = format_result(Result, ResultF),
{command_result, ResultFormatted}.
%%-----------------------------
%% Format arguments
%%-----------------------------
get_attrs(Attribute_names, L) ->
[get_attr(A, L) || A <- Attribute_names].
get_attr(A, L) ->
case lists:keysearch(A, 1, L) of
{value, {A, Value}} -> Value;
false ->
%% Report the error and then force a crash
exit({attribute_not_found, A, L})
end.
%% Get an element from a list and delete it.
%% The element must be defined once and only once,
%% otherwise the function crashes on purpose.
get_elem_delete(A, L) ->
case proplists:get_all_values(A, L) of
[Value] ->
{Value, proplists:delete(A, L)};
[_, _ | _] ->
%% Crash reporting the error
exit({duplicated_attribute, A, L});
[] ->
%% Report the error and then force a crash
exit({attribute_not_found, A, L})
end.
format_args(Args, ArgsFormat) ->
{ArgsRemaining, R} =
lists:foldl(
fun({ArgName, ArgFormat}, {Args1, Res}) ->
{ArgValue, Args2} = get_elem_delete(ArgName, Args1),
Formatted = format_arg(ArgValue, ArgFormat),
{Args2, Res ++ [Formatted]}
end,
{Args, []},
ArgsFormat),
case ArgsRemaining of
[] -> R;
L when is_list(L) ->
exit({additional_unused_args, L})
end.
format_arg({array, [{struct, Elements}]}, {list, {ElementDefName, ElementDefFormat}})
when is_list(Elements) ->
lists:map(
fun({ElementName, ElementValue}) ->
true = (ElementDefName == ElementName),
format_arg(ElementValue, ElementDefFormat)
end,
Elements);
format_arg({array, [{struct, Elements}]}, {tuple, ElementsDef})
when is_list(Elements) ->
FormattedList = format_args(Elements, ElementsDef),
list_to_tuple(FormattedList);
format_arg({array, Elements}, {list, ElementsDef})
when is_list(Elements) and is_atom(ElementsDef) ->
[format_arg(Element, ElementsDef) || Element <- Elements];
format_arg(Arg, integer)
when is_integer(Arg) ->
Arg;
format_arg(Arg, string)
when is_list(Arg) ->
Arg.
%% -----------------------------
%% Result
%% -----------------------------
format_result({error, Error}, _) ->
throw({error, Error});
format_result(String, string) ->
lists:flatten(String);
format_result(Atom, {Name, atom}) ->
{struct, [{Name, atom_to_list(Atom)}]};
format_result(Int, {Name, integer}) ->
{struct, [{Name, Int}]};
format_result(String, {Name, string}) ->
{struct, [{Name, lists:flatten(String)}]};
format_result(Code, {Name, rescode}) ->
{struct, [{Name, make_status(Code)}]};
format_result({Code, Text}, {Name, restuple}) ->
{struct, [{Name, make_status(Code)},
{text, lists:flatten(Text)}]};
%% Result is a list of something: [something()]
format_result(Elements, {Name, {list, ElementsDef}}) ->
FormattedList = lists:map(
fun(Element) ->
format_result(Element, ElementsDef)
end,
Elements),
{struct, [{Name, {array, FormattedList}}]};
%% Result is a tuple with several elements: {something1(), something2(), ...}
format_result(ElementsTuple, {Name, {tuple, ElementsDef}}) ->
ElementsList = tuple_to_list(ElementsTuple),
ElementsAndDef = lists:zip(ElementsList, ElementsDef),
FormattedList = lists:map(
fun({Element, ElementDef}) ->
format_result(Element, ElementDef)
end,
ElementsAndDef),
{struct, [{Name, {array, FormattedList}}]}.
%% TODO: should be struct instead of array?
make_status(ok) -> 0;
make_status(true) -> 0;
make_status(false) -> 1;
make_status(error) -> 1;
make_status(_) -> 1.
%% -----------------------------
%% Internal
%% -----------------------------
get_title(A) -> mod_statsdx:get_title(A).
get_value(N, A) -> mod_statsdx:get(N, [A]).

27
extract-mod-translations.sh Executable file
View File

@ -0,0 +1,27 @@
MODULES=`pwd`
# Put here the path to ejabberd source
EJADIR=$MODULES/../git/ejabberd/
# TODO: Support extraction of multiple modules
#MODULE=mod_webpresence
MODULE=mod_register_web
RUNDIR=$MODULES/$MODULE/trunk/
PREPARESCRIPT=$EJADIR/contrib/extract_translations/prepare-translation.sh
# 1. Create the directory $MODULE/msgs/
# 2. Create the $MODULE.pot
#$PREPARESCRIPT -rundir $RUNDIR -ejadir $EJADIR -project $MODULE -src2pot
# 3. Create a language
# cp $MODULE.pot $LANG.$MODULE.po
# echo "" > $LANG.$MODULE.msg
# 3.b Convert msg to po. But it doesn't work! :(
#$PREPARESCRIPT -rundir $RUNDIR -ejadir $EJADIR -project $MODULE -srcmsg2po we
# 4. Update strings
$PREPARESCRIPT -rundir $RUNDIR -ejadir $EJADIR -project $MODULE -updateall

1
ircd/Emakefile Normal file
View File

@ -0,0 +1 @@
{'src/ejabberd_ircd', [{outdir, "ebin"},{i,"../ejabberd-dev/include"}]}.

83
ircd/README.txt Normal file
View File

@ -0,0 +1,83 @@
ircd - IRC-to-XMPP interface
Author:
Magnus Henoch
xmpp:legoscia@jabber.cd.chalmers.se,
mailto:henoch@dtek.chalmers.se
Homepage:
http://www.dtek.chalmers.se/~henoch/text/ejabberd-ircd.html
Requirements:
ejabberd trunk SVN 1631 or newer
DESCRIPTION
===========
This is an IRC server frontend to ejabberd. It supports a subset of
the IRC protocol, allowing IRC users to use a subset of Jabber MUC
functions. Users log in with their username and password, just as if
they were Jabber users. Therefore, configuring the IRC interface to
use an anonymous authentication backend is probably what users expect.
Channel names are translated to MUC rooms on a particular MUC service.
The most obvious missing functions in this module are operator actions
and a command to list channels.
CONFIGURATION
=============
Something like this should be inserted in the "listen" section of the
configuration file:
{listen, [
...
{6667, ejabberd_ircd, [{access, c2s},
{host, "example.org"},
{muc_host, "conference.example.org"},
{encoding, "utf-8"},
{mappings,
[{"#esperanto", "esperanto@conference.jabber.org"}]} ]},
...
]}.
Configurable module options:
access: ACL matching users allowed to use the IRC backend.
host: hostname part of the JIDs of IRC users.
muc_host: MUC service hosting IRC "channels".
encoding: encoding that IRC users are expected to use.
mappings: optional list of mappings from channel names to MUC rooms
on other MUC services.
AUTHENTICATION
==============
The IRC client needs to login in ejabberd. If the 'internal' auth
method is enabled, then the IRC client must provide the username and
password of an existing Jabber account.
If you want to allow an IRC client to join in MUC rooms without
requiring authentication, you can enable anonyous authentication in
ejabberd.
Note that this module doesn't do SASL ANONYMOUS authentication. This
means that to use anonymous authentication, the "anonymous_protocol"
option needs to be either "login_anon" or "both".
For example, you can define a new Jabber virtual host used only for
anonymous authentication by ejabberd_ircd:
{hosts, ["example.org", "anonymous.example.org"]}.
{host_config, "anonymous.example.org",
[{auth_method, anonymous},
{anonymous_protocol, both}]}.
{listen, [
...
{6667, ejabberd_ircd, [{access, c2s},
{host, "anonymous.example.org"},
{muc_host, "conference.example.org"},
{encoding, "utf-8"} ]},
...
]}.

1
ircd/build.bat Normal file
View File

@ -0,0 +1 @@
erl -pa ../../ejabberd-dev/trunk/ebin -pa ebin -make

2
ircd/build.sh Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
erl -pa ../ejabberd-dev/ebin -pz ebin -make

885
ircd/src/ejabberd_ircd.erl Normal file
View File

@ -0,0 +1,885 @@
-module(ejabberd_ircd).
-author('henoch@dtek.chalmers.se').
-update_info({update, 0}).
-behaviour(gen_fsm).
%% External exports
-export([start/2,
start_link/2,
socket_type/0]).
%% gen_fsm callbacks
-export([init/1,
wait_for_nick/2,
wait_for_cmd/2,
handle_event/3,
handle_sync_event/4,
code_change/4,
handle_info/3,
terminate/3
]).
%-define(ejabberd_debug, true).
-include("ejabberd.hrl").
-include("jlib.hrl").
-define(DICT, dict).
-record(state, {socket,
sockmod,
access,
encoding,
shaper,
host,
muc_host,
sid = none,
pass = "",
nick = none,
user = none,
%% joining is a mapping from room JIDs to nicknames
%% received but not yet forwarded
joining = ?DICT:new(),
joined = ?DICT:new(),
%% mapping certain channels to certain rooms
channels_to_jids = ?DICT:new(),
jids_to_channels = ?DICT:new()
}).
-record(channel, {participants = [],
topic = ""}).
-record(line, {prefix, command, params}).
%-define(DBGFSM, true).
-ifdef(DBGFSM).
-define(FSMOPTS, [{debug, [trace]}]).
-else.
-define(FSMOPTS, []).
-endif.
%%%----------------------------------------------------------------------
%%% API
%%%----------------------------------------------------------------------
start(SockData, Opts) ->
supervisor:start_child(ejabberd_ircd_sup, [SockData, Opts]).
start_link(SockData, Opts) ->
gen_fsm:start_link(ejabberd_ircd, [SockData, Opts], ?FSMOPTS).
socket_type() ->
raw.
%%%----------------------------------------------------------------------
%%% Callback functions from gen_fsm
%%%----------------------------------------------------------------------
%%----------------------------------------------------------------------
%% Func: init/1
%% Returns: {ok, StateName, StateData} |
%% {ok, StateName, StateData, Timeout} |
%% ignore |
%% {stop, StopReason}
%%----------------------------------------------------------------------
init([{SockMod, Socket}, Opts]) ->
iconv:start(),
Access = case lists:keysearch(access, 1, Opts) of
{value, {_, A}} -> A;
_ -> all
end,
Shaper = case lists:keysearch(shaper, 1, Opts) of
{value, {_, S}} -> S;
_ -> none
end,
Host = case lists:keysearch(host, 1, Opts) of
{value, {_, H}} -> H;
_ -> ?MYNAME
end,
MucHost = case lists:keysearch(muc_host, 1, Opts) of
{value, {_, M}} -> M;
_ -> "conference." ++ ?MYNAME
end,
Encoding = case lists:keysearch(encoding, 1, Opts) of
{value, {_, E}} -> E;
_ -> "utf-8"
end,
ChannelMappings = case lists:keysearch(mappings, 1, Opts) of
{value, {_, C}} -> C;
_ -> []
end,
{ChannelToJid, JidToChannel} =
lists:foldl(fun({Channel, Room}, {CToJ, JToC}) ->
RoomJID = jlib:string_to_jid(Room),
BareChannel = case Channel of
[$#|R] -> R;
_ -> Channel
end,
{?DICT:store(BareChannel, RoomJID, CToJ),
?DICT:store(RoomJID, BareChannel, JToC)}
end, {?DICT:new(), ?DICT:new()},
ChannelMappings),
inet:setopts(Socket, [list, {packet, line}, {active, true}]),
%%_ReceiverPid = start_ircd_receiver(Socket, SockMod),
{ok, wait_for_nick, #state{socket = Socket,
sockmod = SockMod,
access = Access,
encoding = Encoding,
shaper = Shaper,
host = Host,
muc_host = MucHost,
channels_to_jids = ChannelToJid,
jids_to_channels = JidToChannel
}}.
handle_info({tcp, _Socket, Line}, StateName, StateData) ->
DecodedLine = iconv:convert(StateData#state.encoding, "utf-8", Line),
Parsed = parse_line(DecodedLine),
?MODULE:StateName({line, Parsed}, StateData);
handle_info({tcp_closed, _}, _StateName, StateData) ->
{stop, normal, StateData};
handle_info({route, _, _, _} = Event, StateName, StateData) ->
?MODULE:StateName(Event, StateData);
handle_info(Info, StateName, StateData) ->
?ERROR_MSG("Unexpected info: ~p", [Info]),
{next_state, StateName, StateData}.
handle_sync_event(Event, _From, StateName, StateData) ->
?ERROR_MSG("Unexpected sync event: ~p", [Event]),
Reply = ok,
{reply, Reply, StateName, StateData}.
handle_event(_Event, StateName, StateData) ->
{next_state, StateName, StateData}.
code_change(_OldVsn, StateName, StateData, _Extra) ->
{ok, StateName, StateData}.
terminate(_Reason, _StateName, #state{socket = Socket, sockmod = SockMod,
sid = SID, host = Host, nick = Nick,
joined = JoinedDict} = State) ->
?INFO_MSG("closing IRC connection for ~p", [Nick]),
case SID of
none ->
ok;
_ ->
Packet = {xmlelement, "presence",
[{"type", "unavailable"}], []},
FromJID = user_jid(State),
?DICT:map(fun(ChannelJID, _ChannelData) ->
ejabberd_router:route(FromJID, ChannelJID, Packet)
end, JoinedDict),
ejabberd_sm:close_session_unset_presence(SID, Nick, Host, "irc", "Logged out")
end,
gen_tcp = SockMod,
ok = gen_tcp:close(Socket),
ok.
wait_for_nick({line, #line{command = "PASS", params = Params}}, State) ->
?DEBUG("in wait_for_nick", []),
Pass = hd(Params),
?DEBUG("got password", []),
{next_state, wait_for_nick, State#state{pass = Pass}};
wait_for_nick({line, #line{command = "NICK", params = Params}}, State) ->
?DEBUG("in wait_for_nick", []),
Nick = hd(Params),
Pass = State#state.pass,
Server = State#state.host,
JID = jlib:make_jid(Nick, Server, "irc"),
case JID of
error ->
?DEBUG("invalid nick '~p'", [Nick]),
send_reply('ERR_ERRONEUSNICKNAME', [Nick, "Erroneous nickname"], State),
{next_state, wait_for_nick, State};
_ ->
case acl:match_rule(Server, State#state.access, JID) of
deny ->
?DEBUG("access denied for '~p'", [Nick]),
send_reply('ERR_NICKCOLLISION', [Nick, "Nickname collision"], State),
{next_state, wait_for_nick, State};
allow ->
case ejabberd_auth:check_password(Nick, Server, Pass) of
false ->
?DEBUG("auth failed for '~p'", [Nick]),
send_reply('ERR_NICKCOLLISION', [Nick, "Authentication failed"], State),
{next_state, wait_for_nick, State};
true ->
?DEBUG("good nickname '~p'", [Nick]),
SID = {now(), self()},
ejabberd_sm:open_session(
SID, Nick, Server, "irc", peerip(gen_tcp, State#state.socket)),
ejabberd_sm:set_presence(SID, Nick, Server, "irc",
3, "undefined",
[{'ip', peerip(gen_tcp, State#state.socket)}, {'conn','c2s'}, {'state',"+"}]),
send_text_command("", "001", [Nick, "IRC interface of ejabberd server "++Server], State),
send_reply('RPL_MOTDSTART', [Nick, "- "++Server++" Message of the day - "], State),
send_reply('RPL_MOTD', [Nick, "- This is the IRC interface of the ejabberd server "++Server++"."], State),
send_reply('RPL_MOTD', [Nick, "- Your full JID is "++Nick++"@"++Server++"/irc."], State),
send_reply('RPL_MOTD', [Nick, "- Channel #whatever corresponds to MUC room whatever@"++State#state.muc_host++"."], State),
send_reply('RPL_MOTD', [Nick, "- This IRC interface is quite immature. You will probably find bugs."], State),
send_reply('RPL_MOTD', [Nick, "- Have a good time!"], State),
send_reply('RPL_ENDOFMOTD', [Nick, "End of /MOTD command"], State),
{next_state, wait_for_cmd, State#state{nick = Nick, sid = SID, pass = ""}}
end
end
end;
wait_for_nick(Event, State) ->
?DEBUG("in wait_for_nick", []),
?INFO_MSG("unexpected event ~p", [Event]),
{next_state, wait_for_nick, State}.
peerip(SockMod, Socket) ->
IP = case SockMod of
gen_tcp -> inet:peername(Socket);
_ -> SockMod:peername(Socket)
end,
case IP of
{ok, IPOK} -> IPOK;
_ -> undefined
end.
wait_for_cmd({line, #line{command = "USER", params = [_Username, _Hostname, _Servername, _Realname]}}, State) ->
%% Yeah, like we care.
{next_state, wait_for_cmd, State};
wait_for_cmd({line, #line{command = "JOIN", params = Params}}, State) ->
{ChannelsString, KeysString} =
case Params of
[C, K] ->
{C, K};
[C] ->
{C, []}
end,
Channels = string:tokens(ChannelsString, ","),
Keys = string:tokens(KeysString, ","),
NewState = join_channels(Channels, Keys, State),
{next_state, wait_for_cmd, NewState};
%% USERHOST command
wait_for_cmd({line, #line{command = "USERHOST", params = Params}}, State) ->
case Params of
[] ->
send_reply('ERR_NEEDMOREPARAMS', ["USERHOST", "Not enough parameters"], State);
UserParams ->
Users = lists:sublist(string:tokens(UserParams, " "), 5), %% RFC 1459 specifies 5 items max
lists:foreach(
fun(UserSubList) ->
User = lists:last(UserSubList),
case ejabberd_sm:get_user_info(User, State#state.host, "irc") of
offline ->
send_reply('RPL_USERHOST',[State#state.nick, User++" offline"], State);
[_Node, _Conn, Ip] ->
{_,{{IP1,IP2,IP3,IP4}, _}} = Ip,
send_reply('RPL_USERHOST',[State#state.nick, User ++ "=+" ++ integer_to_list(IP1) ++ "." ++
integer_to_list(IP2) ++ "." ++ integer_to_list(IP3) ++ "." ++ integer_to_list(IP4)], State)
end
end, Users)
end,
{next_state, wait_for_cmd, State};
wait_for_cmd({line, #line{command = "PART", params = [ChannelsString | MaybeMessage]}}, State) ->
Message = case MaybeMessage of
[] -> nothing;
[M] -> M
end,
Channels = string:tokens(ChannelsString, ","),
NewState = part_channels(Channels, State, Message),
{next_state, wait_for_cmd, NewState};
wait_for_cmd({line, #line{command = "PRIVMSG", params = [To, Text]}}, State) ->
Recipients = string:tokens(To, ","),
FromJID = user_jid(State),
lists:foreach(
fun(Rcpt) ->
case Rcpt of
[$# | Roomname] ->
Packet = {xmlelement, "message",
[{"type", "groupchat"}],
[{xmlelement, "body", [],
filter_cdata(translate_action(Text))}]},
ToJID = channel_to_jid(Roomname, State),
ejabberd_router:route(FromJID, ToJID, Packet);
_ ->
case string:tokens(Rcpt, "#") of
[Nick, Channel] ->
Packet = {xmlelement, "message",
[{"type", "chat"}],
[{xmlelement, "body", [],
filter_cdata(translate_action(Text))}]},
ToJID = channel_nick_to_jid(Nick, Channel, State),
ejabberd_router:route(FromJID, ToJID, Packet);
_ ->
send_text_command(Rcpt, "NOTICE", [State#state.nick,
"Your message to "++
Rcpt++
" was dropped. "
"Try sending it to "++Rcpt++
"#somechannel."], State)
end
end
end, Recipients),
{next_state, wait_for_cmd, State};
wait_for_cmd({line, #line{command = "PING", params = Params}}, State) ->
{Token, Whom} =
case Params of
[A] ->
{A, ""};
[A, B] ->
{A, B}
end,
if Whom == ""; Whom == State#state.host ->
%% Ping to us
send_command("", "PONG", [State#state.host, Token], State);
true ->
%% Ping to someone else
?DEBUG("ignoring ping to ~s", [Whom]),
ok
end,
{next_state, wait_for_cmd, State};
wait_for_cmd({line, #line{command = "TOPIC", params = Params}}, State) ->
case Params of
[Channel] ->
%% user asks for topic
case ?DICT:find(channel_to_jid(Channel, State),
State#state.joined) of
{ok, #channel{topic = Topic}} ->
case Topic of
"" ->
send_reply('RPL_NOTOPIC', ["No topic is set"], State);
_ ->
send_reply('RPL_TOPIC', [Topic], State)
end;
_ ->
send_reply('ERR_NOTONCHANNEL', ["You're not on that channel"], State)
end;
[Channel, NewTopic] ->
Packet =
{xmlelement, "message",
[{"type", "groupchat"}],
[{xmlelement, "subject", [], filter_cdata(NewTopic)}]},
FromJID = user_jid(State),
ToJID = channel_to_jid(Channel, State),
ejabberd_router:route(FromJID, ToJID, Packet)
end,
{next_state, wait_for_cmd, State};
wait_for_cmd({line, #line{command = "MODE", params = [ModeOf | Params]}}, State) ->
case ModeOf of
[$# | Channel] ->
ChannelJid = channel_to_jid(Channel, State),
Joined = ?DICT:find(ChannelJid, State#state.joined),
case Joined of
{ok, _ChannelData} ->
case Params of
[] ->
%% This is where we could mirror some advanced MUC
%% properties.
%%send_reply('RPL_CHANNELMODEIS', [Channel, Modes], State);
send_reply('ERR_NOCHANMODES', [Channel], State);
["b"] ->
send_reply('RPL_ENDOFBANLIST', [Channel, "Ban list not available"], State);
_ ->
send_reply('ERR_UNKNOWNCOMMAND', ["MODE", io_lib:format("MODE ~p not understood", [Params])], State)
end;
_ ->
send_reply('ERR_NOTONCHANNEL', [Channel, "You're not on that channel"], State)
end;
Nick ->
if Nick == State#state.nick ->
case Params of
[] ->
send_reply('RPL_UMODEIS', [], State);
[Flags|_] ->
send_reply('ERR_UMODEUNKNOWNFLAG', [Flags, "No MODE flags supported"], State)
end;
true ->
send_reply('ERR_USERSDONTMATCH', ["Can't change mode for other users"], State)
end
end,
{next_state, wait_for_cmd, State};
wait_for_cmd({line, #line{command = "QUIT"}}, State) ->
%% quit message is ignored for now
{stop, normal, State};
wait_for_cmd({line, #line{command = Unknown, params = Params} = Line}, State) ->
?INFO_MSG("Unknown command: ~p", [Line]),
send_reply('ERR_UNKNOWNCOMMAND', [Unknown, "Unknown command or arity: " ++
Unknown ++ "/" ++ integer_to_list(length(Params))], State),
{next_state, wait_for_cmd, State};
wait_for_cmd({route, From, _To, {xmlelement, "presence", Attrs, Els} = El}, State) ->
Type = xml:get_attr_s("type", Attrs),
FromRoom = jlib:jid_remove_resource(From),
FromNick = From#jid.resource,
Channel = jid_to_channel(From, State),
MyNick = State#state.nick,
IRCSender = make_irc_sender(FromNick, FromRoom, State),
Joining = ?DICT:find(FromRoom, State#state.joining),
Joined = ?DICT:find(FromRoom, State#state.joined),
case {Joining, Joined, Type} of
{{ok, BufferedNicks}, _, ""} ->
case BufferedNicks of
[] ->
%% If this is the first presence, tell the
%% client that it's joining.
send_command(make_irc_sender(MyNick, FromRoom, State),
"JOIN", [Channel], State);
_ ->
ok
end,
NewRole = case find_el("x", ?NS_MUC_USER, Els) of
nothing ->
"";
XMucEl ->
xml:get_path_s(XMucEl, [{elem, "item"}, {attr, "role"}])
end,
NewBufferedNicks = [{FromNick, NewRole} | BufferedNicks],
?DEBUG("~s is present in ~s. we now have ~p.",
[FromNick, Channel, NewBufferedNicks]),
%% We receive our own presence last. XXX: there
%% are some status codes here. See XEP-0045,
%% section 7.1.3.
NewState =
case FromNick of
MyNick ->
send_reply('RPL_NAMREPLY',
[MyNick, "=",
Channel,
lists:append(
lists:map(
fun({Nick, Role}) ->
case Role of
"moderator" ->
"@";
"participant" ->
"+";
_ ->
""
end ++ Nick ++ " "
end, NewBufferedNicks))],
State),
send_reply('RPL_ENDOFNAMES',
[Channel,
"End of /NAMES list"],
State),
NewJoiningDict = ?DICT:erase(FromRoom, State#state.joining),
ChannelData = #channel{participants = NewBufferedNicks},
NewJoinedDict = ?DICT:store(FromRoom, ChannelData, State#state.joined),
State#state{joining = NewJoiningDict,
joined = NewJoinedDict};
_ ->
NewJoining = ?DICT:store(FromRoom, NewBufferedNicks, State#state.joining),
State#state{joining = NewJoining}
end,
{next_state, wait_for_cmd, NewState};
{{ok, _BufferedNicks}, _, "error"} ->
NewState =
case FromNick of
MyNick ->
%% we couldn't join the room
{ReplyCode, ErrorDescription} =
case xml:get_subtag(El, "error") of
{xmlelement, _, _, _} = ErrorEl ->
{ErrorName, ErrorText} = parse_error(ErrorEl),
{case ErrorName of
"forbidden" -> 'ERR_INVITEONLYCHAN';
_ -> 'ERR_NOSUCHCHANNEL'
end,
if is_list(ErrorText) ->
ErrorName ++ ": " ++ ErrorText;
true ->
ErrorName
end};
_ ->
{'ERR_NOSUCHCHANNEL', "Unknown error"}
end,
send_reply(ReplyCode, [Channel, ErrorDescription], State),
NewJoiningDict = ?DICT:erase(FromRoom, State#state.joining),
State#state{joining = NewJoiningDict};
_ ->
?ERROR_MSG("ignoring presence of type ~s from ~s while joining room",
[Type, jlib:jid_to_string(From)]),
State
end,
{next_state, wait_for_cmd, NewState};
%% Presence in a channel we have already joined
{_, {ok, _}, ""} ->
%% Someone enters
send_command(IRCSender, "JOIN", [Channel], State),
{next_state, wait_for_cmd, State};
{_, {ok, _}, _} ->
%% Someone leaves
send_command(IRCSender, "PART", [Channel], State),
{next_state, wait_for_cmd, State};
_ ->
?INFO_MSG("unexpected presence from ~s", [jlib:jid_to_string(From)]),
{next_state, wait_for_cmd, State}
end;
wait_for_cmd({route, From, _To, {xmlelement, "message", Attrs, Els} = El}, State) ->
Type = xml:get_attr_s("type", Attrs),
case Type of
"groupchat" ->
ChannelJID = jlib:jid_remove_resource(From),
case ?DICT:find(ChannelJID, State#state.joined) of
{ok, #channel{} = ChannelData} ->
FromChannel = jid_to_channel(From, State),
FromNick = From#jid.resource,
Subject = xml:get_path_s(El, [{elem, "subject"}, cdata]),
Body = xml:get_path_s(El, [{elem, "body"}, cdata]),
XDelay = lists:any(fun({xmlelement, "x", XAttrs, _}) ->
xml:get_attr_s("xmlns", XAttrs) == ?NS_DELAY;
(_) ->
false
end, Els),
if
Subject /= "" ->
CleanSubject = lists:map(fun($\n) ->
$\ ;
(C) -> C
end, Subject),
send_text_command(make_irc_sender(From, State),
"TOPIC", [FromChannel, CleanSubject], State),
NewChannelData = ChannelData#channel{topic = CleanSubject},
NewState = State#state{joined = ?DICT:store(jlib:jid_remove_resource(From), NewChannelData, State#state.joined)},
{next_state, wait_for_cmd, NewState};
not XDelay, FromNick == State#state.nick ->
%% there is no message echo in IRC.
%% we let the backlog through, though.
{next_state, wait_for_cmd, State};
true ->
BodyLines = string:tokens(Body, "\n"),
lists:foreach(
fun(Line) ->
Line1 =
case Line of
[$/, $m, $e, $ | Action] ->
[1]++"ACTION "++Action++[1];
_ ->
Line
end,
send_text_command(make_irc_sender(From, State),
"PRIVMSG", [FromChannel, Line1], State)
end, BodyLines),
{next_state, wait_for_cmd, State}
end;
error ->
?ERROR_MSG("got message from ~s without having joined it",
[jlib:jid_to_string(ChannelJID)]),
{next_state, wait_for_cmd, State}
end;
"error" ->
MucHost = State#state.muc_host,
ErrorFrom =
case From of
#jid{lserver = MucHost,
luser = Room,
lresource = ""} ->
[$#|Room];
#jid{lserver = MucHost,
luser = Room,
lresource = Nick} ->
Nick++"#"++Room;
#jid{} ->
%% ???
jlib:jid_to_string(From)
end,
%% I think this should cover all possible combinations of
%% XMPP and non-XMPP error messages...
ErrorText =
error_to_string(xml:get_subtag(El, "error")),
send_text_command("", "NOTICE", [State#state.nick,
"Message to "++ErrorFrom++" bounced: "++
ErrorText], State),
{next_state, wait_for_cmd, State};
_ ->
ChannelJID = jlib:jid_remove_resource(From),
case ?DICT:find(ChannelJID, State#state.joined) of
{ok, #channel{}} ->
FromNick = From#jid.lresource++jid_to_channel(From, State),
Body = xml:get_path_s(El, [{elem, "body"}, cdata]),
BodyLines = string:tokens(Body, "\n"),
lists:foreach(
fun(Line) ->
Line1 =
case Line of
[$/, $m, $e, $ | Action] ->
[1]++"ACTION "++Action++[1];
_ ->
Line
end,
send_text_command(FromNick, "PRIVMSG", [State#state.nick, Line1], State)
end, BodyLines),
{next_state, wait_for_cmd, State};
_ ->
?INFO_MSG("unexpected message from ~s", [jlib:jid_to_string(From)]),
{next_state, wait_for_cmd, State}
end
end;
wait_for_cmd(Event, State) ->
?INFO_MSG("unexpected event ~p", [Event]),
{next_state, wait_for_cmd, State}.
join_channels([], _, State) ->
State;
join_channels(Channels, [], State) ->
join_channels(Channels, [none], State);
join_channels([Channel | Channels], [Key | Keys],
#state{nick = Nick} = State) ->
Packet =
{xmlelement, "presence", [],
[{xmlelement, "x", [{"xmlns", ?NS_MUC}],
case Key of
none ->
[];
_ ->
[{xmlelement, "password", [], filter_cdata(Key)}]
end}]},
From = user_jid(State),
To = channel_nick_to_jid(Nick, Channel, State),
Room = jlib:jid_remove_resource(To),
ejabberd_router:route(From, To, Packet),
NewState = State#state{joining = ?DICT:store(Room, [], State#state.joining)},
join_channels(Channels, Keys, NewState).
part_channels([], State, _Message) ->
State;
part_channels([Channel | Channels], State, Message) ->
Packet =
{xmlelement, "presence",
[{"type", "unavailable"}],
case Message of
nothing -> [];
_ -> [{xmlelement, "status", [],
[{xmlcdata, Message}]}]
end},
From = user_jid(State),
To = channel_nick_to_jid(State#state.nick, Channel, State),
ejabberd_router:route(From, To, Packet),
RoomJID = channel_to_jid(Channel, State),
NewState = State#state{joined = ?DICT:erase(RoomJID, State#state.joined)},
part_channels(Channels, NewState, Message).
parse_line(Line) ->
{Line1, LastParam} =
case string:str(Line, " :") of
0 ->
{Line, []};
Index ->
{string:substr(Line, 1, Index - 1),
[string:substr(Line, Index + 2) -- "\r\n"]}
end,
Tokens = string:tokens(Line1, " \r\n"),
{Prefix, Tokens1} =
case Line1 of
[$: | _] ->
{hd(Tokens), tl(Tokens)};
_ ->
{none, Tokens}
end,
[Command | Params] = Tokens1,
UCCommand = upcase(Command),
#line{prefix = Prefix, command = UCCommand, params = Params ++ LastParam}.
upcase([]) ->
[];
upcase([C|String]) ->
[if $a =< C, C =< $z ->
C - ($a - $A);
true ->
C
end | upcase(String)].
%% sender
send_line(Line, #state{sockmod = SockMod, socket = Socket, encoding = Encoding}) ->
?DEBUG("sending ~s", [Line]),
gen_tcp = SockMod,
EncodedLine = iconv:convert("utf-8", Encoding, Line),
ok = gen_tcp:send(Socket, [EncodedLine, 13, 10]).
send_command(Sender, Command, Params, State) ->
send_command(Sender, Command, Params, State, false).
%% Some IRC software require commands with text to have the text
%% quoted, even it's not if not necessary.
send_text_command(Sender, Command, Params, State) ->
send_command(Sender, Command, Params, State, true).
send_command(Sender, Command, Params, State, AlwaysQuote) ->
Prefix = case Sender of
"" ->
[$: | State#state.host];
_ ->
[$: | Sender]
end,
ParamString = make_param_string(Params, AlwaysQuote),
send_line(Prefix ++ " " ++ Command ++ ParamString, State).
send_reply(Reply, Params, State) ->
Number = case Reply of
'ERR_UNKNOWNCOMMAND' ->
"421";
'ERR_ERRONEUSNICKNAME' ->
"432";
'ERR_NICKCOLLISION' ->
"436";
'ERR_NOTONCHANNEL' ->
"442";
'ERR_NOCHANMODES' ->
"477";
'ERR_UMODEUNKNOWNFLAG' ->
"501";
'ERR_USERSDONTMATCH' ->
"502";
'RPL_UMODEIS' ->
"221";
'RPL_CHANNELMODEIS' ->
"324";
'RPL_NAMREPLY' ->
"353";
'RPL_ENDOFNAMES' ->
"366";
'RPL_BANLIST' ->
"367";
'RPL_ENDOFBANLIST' ->
"368";
'RPL_NOTOPIC' ->
"331";
'RPL_TOPIC' ->
"332";
'RPL_MOTD' ->
"372";
'RPL_MOTDSTART' ->
"375";
'RPL_ENDOFMOTD' ->
"376"
end,
send_text_command("", Number, Params, State).
make_param_string([], _) -> "";
make_param_string([LastParam], AlwaysQuote) ->
case {AlwaysQuote, LastParam, lists:member($\ , LastParam)} of
{true, _, _} ->
" :" ++ LastParam;
{_, _, true} ->
" :" ++ LastParam;
{_, [$:|_], _} ->
" :" ++ LastParam;
{_, _, _} ->
" " ++ LastParam
end;
make_param_string([Param | Params], AlwaysQuote) ->
case lists:member($\ , Param) of
false ->
" " ++ Param ++ make_param_string(Params, AlwaysQuote)
end.
find_el(Name, NS, [{xmlelement, N, Attrs, _} = El|Els]) ->
XMLNS = xml:get_attr_s("xmlns", Attrs),
case {Name, NS} of
{N, XMLNS} ->
El;
_ ->
find_el(Name, NS, Els)
end;
find_el(_, _, []) ->
nothing.
channel_to_jid([$#|Channel], State) ->
channel_to_jid(Channel, State);
channel_to_jid(Channel, #state{muc_host = MucHost,
channels_to_jids = ChannelsToJids}) ->
case ?DICT:find(Channel, ChannelsToJids) of
{ok, RoomJID} -> RoomJID;
_ -> jlib:make_jid(Channel, MucHost, "")
end.
channel_nick_to_jid(Nick, [$#|Channel], State) ->
channel_nick_to_jid(Nick, Channel, State);
channel_nick_to_jid(Nick, Channel, #state{muc_host = MucHost,
channels_to_jids = ChannelsToJids}) ->
case ?DICT:find(Channel, ChannelsToJids) of
{ok, RoomJID} -> jlib:jid_replace_resource(RoomJID, Nick);
_ -> jlib:make_jid(Channel, MucHost, Nick)
end.
jid_to_channel(#jid{user = Room} = RoomJID,
#state{jids_to_channels = JidsToChannels}) ->
case ?DICT:find(jlib:jid_remove_resource(RoomJID), JidsToChannels) of
{ok, Channel} -> [$#|Channel];
_ -> [$#|Room]
end.
make_irc_sender(Nick, #jid{luser = Room} = RoomJID,
#state{jids_to_channels = JidsToChannels}) ->
case ?DICT:find(jlib:jid_remove_resource(RoomJID), JidsToChannels) of
{ok, Channel} -> Nick++"!"++Nick++"@"++Channel;
_ -> Nick++"!"++Nick++"@"++Room
end.
make_irc_sender(#jid{lresource = Nick} = JID, State) ->
make_irc_sender(Nick, JID, State).
user_jid(#state{nick = Nick, host = Host}) ->
jlib:make_jid(Nick, Host, "irc").
filter_cdata(Msg) ->
[{xmlcdata, filter_message(Msg)}].
filter_message(Msg) ->
lists:filter(
fun(C) ->
if (C < 32) and
%% Add color support, but break XML: (see https://support.process-one.net/browse/EJAB-1097 )
%% (C /= 3) and
(C /= 9) and
(C /= 10) and
(C /= 13) ->
false;
true -> true
end
end, Msg).
translate_action(Msg) ->
case Msg of
[1, $A, $C, $T, $I, $O, $N, $ | Action] ->
"/me "++Action;
_ ->
Msg
end.
parse_error({xmlelement, "error", _ErrorAttrs, ErrorEls} = ErrorEl) ->
ErrorTextEl = xml:get_subtag(ErrorEl, "text"),
ErrorName =
case ErrorEls -- [ErrorTextEl] of
[{xmlelement, ErrorReason, _, _}] ->
ErrorReason;
_ ->
"unknown error"
end,
ErrorText =
case ErrorTextEl of
{xmlelement, _, _, _} ->
xml:get_tag_cdata(ErrorTextEl);
_ ->
nothing
end,
{ErrorName, ErrorText}.
error_to_string({xmlelement, "error", _ErrorAttrs, _ErrorEls} = ErrorEl) ->
case parse_error(ErrorEl) of
{ErrorName, ErrorText} when is_list(ErrorText) ->
ErrorName ++ ": " ++ ErrorText;
{ErrorName, _} ->
ErrorName
end;
error_to_string(_) ->
"unknown error".

339
jorge/COPYING Normal file
View File

@ -0,0 +1,339 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Lesser General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

44
jorge/README Normal file
View File

@ -0,0 +1,44 @@
iJorge by Zbyszek Zolkiewski (C) 2009 VERSION 1.5-RC1
About.
Jorge is set of php scripts that are front-end for Oleg Palij mod_logdb.
Licensing.
Jorge is distributed by GPL License provided in COPYING file as well in parts in all source files.
Jorge uses jQuery library and some plugins, please read license info at http://docs.jquery.com/Licensing
Bug reporting:
If you found any bug or have any improvement idea you can contact me at (email/xmpp): zbyszek@jabster.pl
Patches are most welcome.
Requirements:
- working ejabberd 2.x (or higher) with mod_logdb (compatibile version is bundled with Jorge)
- mod_xmlrpc - revision 772
- mysql5 server
- any http server supporting PHP (5.2.x or higher) with gd, mcrypt and xmlrpc support
Client Requirements:
- Jorge is tested and compatibile with: Firefox 2.x, Firefox 3.x, Opera 9.x, Apple Safri 3.x,4.x and Google Chrome (IE7 and IE8+ may work but it is not recomended due to IE standards violations, IE6 is not supported at all)
- Web-browser _must_ have enabled javascript as Jorge strongly relay on jQuery and other js related scripts
- Cookies must be enabled
Installing:
- setup XML-RPC facility (mod_xmlrpc, available at http://svn.process-one.net/ejabberd-modules/mod_xmlrpc/trunk/ - Use rev772!)
- copy Jorge files into your http server (sugested vhost over SSL connection).
- set up database for Jorge (install/jorge.sql), see README inside install dir
- copy config.php.inc to config.php and edit file - READ CAREFULLY
- that's it!
Archive usage:
We can say that 1 milion messeges collected by the server consume approx. 65 Megabytes. Depending on number of users that use your server and
how many will activate logging, you must compute db partitions.
NO WARRANTY
THE PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT WITHOUT ANY WARRANTY. IT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
!!!SECURITY NOTICE!!!
Before use check if you set registered_globals to off. It is *required* for security reasons!
Jorge is compatibile out of the box with: mod_security2 and php-hardened (suhosin) and easy to chroot.
It is strongly recomended to use encrypted sessions.
If you are using Hardened_PHP or Suhosin alter get.max_value_length to some greater value f.e 1024.

679
jorge/calendar_view.php Normal file
View File

@ -0,0 +1,679 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
/This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
require_once("headers.php");
require_once("upper.php");
if ($_GET['a']) {
$jump_link = "&amp;a=".$_GET['a'];
}
$html->set_overview('<h2>'.$cal_head[$lang].'</h2><small>'.$cal_notice[$lang].'. <a href="main.php?set_pref=1&amp;v=1'.$jump_link.'"><u>'.$change_view[$lang].'</u></a></small><br><br>');
if (isset($_GET['left'])) {
if ($enc->decrypt_url($_GET['left']) === true) {
$left = $enc->tslice;
}
else {
unset($left);
}
}
if (isset($_GET['right'])) {
if ($enc->decrypt_url($_GET['right']) === true) {
$right = $enc->tslice;
}
else {
unset($left);
}
}
$e_string = $_GET['a'];
$resource_id = $_GET['b'];
$start = $_GET['start'];
$jump_to = $_POST['jump_box'];
if ($jump_to!="") {
$mo=$jump_to;
}
if ($mo === "jump") {
unset($mo);
}
if ($enc->decrypt_url($e_string) === true) {
$tslice = $enc->tslice;
$talker = $enc->peer_name_id;
$server = $enc->peer_server_id;
$action = $enc->action;
$lnk = $enc->lnk;
// reencode string:
$e_string = $enc->crypt_url("tslice=$tslice&peer_name_id=$talker&peer_server_id=$server");
}
// avoid unnessesary validation, actualy...
if ($tslice) {
if (validate_date($tslice) === false) {
debug(DEBUG,"Date validation failed: $tslice");
unset ($tslice);
unset($e_string);
unset($talker);
unset($left);
unset($right);
unset($mo);
unset($action);
}
else{
debug(DEBUG,"Date set to: $tslice");
}
}
// some validation things...
if ($start) {
if ((validate_start($start))!==true) {
$start="0";
}
}
// set idx
if ($_GET['idx']) {
$idx = $_GET['idx'];
if ($enc->decrypt_url($idx) === true) {
if($db->set_ext_index($enc->single) !== true) {
unset($idx);
unset($action);
}
$idx = $enc->single;
}
else{
unset($idx);
unset($action);
}
}
// undo delete
if ($action === "undelete") {
if ($db->move_chat_from_trash($talker,$server,$tslice,$lnk,$idx) === true) {
$html->status_message($undo_info[$lang],"message");
}
else {
unset($talker);
$html->alert_message($oper_fail[$lang],"message");
}
}
if ($action === "delete") {
if ($db->move_chat_to_trash($talker,$server,$tslice,$lnk) === true) {
$undo = $enc->crypt_url("tslice=$tslice&peer_name_id=$talker&peer_server_id=$server&lnk=$lnk&action=undelete");
unset($talker);
$idx = $enc->crypt_url("single=".$db->get_last_idx()."");
$html->status_message('<center><div style="background-color: #fad163; text-align: center; width: 240pt;">'.$del_moved[$lang]
.'<a href="'.$view_type.'?a='.$undo.'&amp;idx='.$idx.'"> <span style="color: blue; font-weight: bold;"><u>Undo</u></span></a></div></center>');
}
else {
$html->alert_message($oper_fail[$lang],"message");
unset($talker);
}
}
// check few condition, what we're doing...
if ($tslice!="") {
list($y,$m,$selected) = split("-", $tslice);
$mo="$y-$m";
}
else {
if (isset($left)) {
$mo=$left;
}
if (isset($right)) {
$mo=$right;
}
}
if (!isset($mo)) {
$mo = date("Y-n");
}
// validate mo if fail, silently fallback to current date
if (validate_date($mo."-1") === false) {
unset ($tslice);
unset ($e_string);
unset ($talker);
$mo = date("Y-m");
}
// master div
$html->set_body('<div>');
// calendar div
if ($talker) {
$float="left;";
}
else {
$float="none;";
}
// select list
$db->get_user_stats_drop_down();
$ch_mo = $db->result;
// check if user have some chats
if (count($ch_mo)!=0) {
$html->set_body('<div style="text-align: center; width: 200px; float: '.$float.'">
<form id="t_jump" action="calendar_view.php" method="post" name="t_jump">
<select style="text-align: center; border: 0px; background-color: #6daae7; color:#fff; font-size: x-small;" name="jump_box" size="0" onchange="javascript:document.t_jump.submit();">
<option value="jump">'.$jump_to_l[$lang].'</option>
');
foreach($ch_mo as $result) {
list($s_y,$s_m) = split("-",$result[at_send]);
$sym="$s_y-$s_m";
if ($jump_to!="" AND $sym==$mo) {
$sel_box="selected";
}
else {
$sel_box="";
}
$html->set_body('<option value="'.$sym.'" '.$sel_box.'>'.verbose_date($result[at],$months_names,$weekdays,false,true).'</option>');
}
$html->set_body('</select></form>');
// now generate calendar
$db->get_user_stats_calendar($mo);
$result_for_days = $db->result;
$i=0;
// days
foreach($result_for_days as $result) {
$i++;
$days[$i] = str_replace("-","",$result[days]);
}
list($y,$m) = split("-", $mo);
$html->set_body(calendar($db,$user_id,$xmpp_host,$y,$m,$days,TOKEN,$url_key,$left,$right,$selected,$lang,$view_type,1,$null_a=0,$null_b=0,$cal_days,$enc,$months_names,$weekdays));
unset($days);
}
else {
$html->status_message($no_archives[$lang]);
}
// if we got day, lets display chats from that day but only if there are some
if ($tslice) {
$db->get_user_chats($tslice);
$result = $db->result;
if (count($result)>0) {
$display_conversations = true;
}
else{
$display_conversations = false;
}
}
if ($display_conversations === true) {
// we need to sort list by nickname so we need to combine 2 results: roster and mod_logdb chatlist:
foreach($result as $sort_me) {
$roster_name = query_nick_name($ejabberd_roster,$sort_me[username],$sort_me[server_name]);
$arr_key++;
if (!$roster_name) {
// split contact into 2 arrays: one with full jids, second without names - transports, agents..
$sorted_spec[$arr_key] = array(
"roster_name"=>$roster_name,
"username"=>$sort_me[username],
"server_name"=>$sort_me[server_name],
"todaytalk"=>$sort_me[todaytalk],
"server"=>$sort_me[server],
"lcount"=>$sort_me[lcount]
);
}
else {
$sorted_list[$arr_key] = array(
"roster_name"=>$roster_name,
"username"=>$sort_me[username],
"server_name"=>$sort_me[server_name],
"todaytalk"=>$sort_me[todaytalk],
"server"=>$sort_me[server],
"lcount"=>$sort_me[lcount]
);
}
}
// sort and split two lists: normal contacts and special contacts.
asort($sorted_list);
if (!$show_spec) {
$show_spec="1";
}
if ($sorted_spec AND $show_spec === "1") {
if ($sorted_list) {
$sorted_list = array_merge($sorted_list,$sorted_spec);
}
else{
$sorted_list = $sorted_spec;
}
}
$html->set_body('<td valign="top" style="padding-top: 15px;">
<table width="200" border="0" cellpadding="0" cellspacing="0" class="calbck_con">
<tr>
<td><img src="img/cal_corn_11.png" width="15" height="7"></td>
<td style="background-image: url(img/cal_bck_top.gif);"></td>
<td><img src="img/cal_corn_12.png" width="14" height="7"></td>
</tr>
<tr>
<td width="15" height="226" valign="top" class="calbckleft"><img src="img/cal_bck_left.png" width="15" height="116"></td>
<td width="100%" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" class="calhead">'.$chat_list_l[$lang].'</td>
</tr>
<tr><td height="5"></td></tr>
<tr align="center" class="caldays">
<td><div style="vertical-align: middle; overflow: auto; height: 210; border-left: 0px; border-bottom: 0px; padding:0px; margin: 0px;">
');
// select chatters
foreach ($sorted_list as $entry) {
$user_name = $entry[username];
$server_name = $entry[server_name];
if ($talker==$entry["todaytalk"] AND $server==$entry[server]) {
$bold_b="<font color=\"#ffcc00\"><b>";
$bold_e="</b></font>";
$mrk=1;
}
else {
$bold_b="";
$bold_e="";
$mrk=0;
}
$nickname = $entry[roster_name];
if (!$nickname) {
$calday_class="caldays4";
$nickname = $not_in_r[$lang];
$spec_con = '<br><span style="text-indent: 10px; font-size: smaller;">(<i>'.htmlspecialchars($server_name).'</i>)</span>';
unset($malpa);
}
else {
$calday_class="caldays3";
unset($spec_con);
$malpa = "@";
}
if ($mrk==1) {
$db->get_next_prev_day($entry[todaytalk],$entry[server],$tslice,"p");
$previous_t = $db->result->at;
$to_base_prev = $enc->crypt_url("tslice=$previous_t&peer_name_id=$entry[todaytalk]&peer_server_id=$entry[server]");
$db->get_next_prev_day($entry[todaytalk],$entry[server],$tslice,"n");
$next_t = $db->result->at;
$to_base_next = $enc->crypt_url("tslice=$next_t&peer_name_id=$entry[todaytalk]&peer_server_id=$entry[server]");
}
$to_base2 = $enc->crypt_url("tslice=$tslice&peer_name_id=$entry[todaytalk]&peer_server_id=$entry[server]");
if ($mrk==1 AND $previous_t != NULL) {
$html->set_body('<a class="nav_np" id="pretty" title="'.$jump_to_prev[$lang].': '.$previous_t.'" href="calendar_view.php?a='.$to_base_prev.'"><<< </a>');
}
$html->set_body('<a class="'.$calday_class.'" id="pretty" href="?a='.$to_base2.'" title="JabberID:;'.htmlspecialchars($user_name).$malpa.htmlspecialchars($server_name).';---;
<b>'.$chat_lines[$lang].$entry[lcount].'</b>">'.$bold_b.cut_nick($nickname).$bold_e.'</a>');
if ($mrk==1 AND $next_t != NULL) {
$html->set_body('<a class="nav_np" id="pretty" title="'.$jump_to_next[$lang].': '.$next_t.'" href="calendar_view.php?a='.$to_base_next.'"> >>></a>');
}
if ($spec_con) {
$html->set_body($bold_b.$spec_con.$bold_e);
}
$html->set_body('<br>');
}
$html->set_body('
</div></td></tr>
</table>
</td>
<td width="14" valign="top" class="calbckright"><img src="img/cal_bck_right.png" width="14" height="116"></td>
</tr>
<tr>
<td><img src="img/cal_corn_21.png" width="15" height="16"></td>
<td style="background-image: url(img/cal_bck_bot.png);"></td>
<td><img src="img/cal_corn_22.png" width="14" height="16"></td>
</tr>
</table>
');
}
$html->set_body('</div><div>');
// Chat thread:
if ($talker) {
$html->set_body('<td valign="top"><table border="0" class="ff"><tr>');
if (!$start) {
$start="0";
}
$db->get_num_lines($tslice,$talker,$server);
$nume = $db->result->cnt;
if ($start>$nume) {
$start=$nume-$num_lines_bro;
}
$db->get_user_name($talker);
$talker_name = $db->result->username;
$db->get_server_name($server);
$server_name = $db->result->server_name;
$nickname = query_nick_name($ejabberd_roster,$talker_name,$server_name);
if ($nickname === "") {
$nickname=$not_in_r[$lang];
$spec_mark = true;
}
else {
$spec_mark = false;
}
$predefined = $enc->crypt_url("jid=$talker_name@$server_name");
$html->set_body('<table id="maincontent" border="0" cellspacing="0" class="ff">
<tr><td colspan="4"><div id="fav_result"></div>
</td></tr>
');
if ($_GET['loc']) {
$loc_id=$_GET['loc'];
if ($loc_id=="2") {
$back_link_message=$chat_map_back[$lang];
$back_link="chat_map.php?chat_map=$predefined";
}
elseif($loc_id=="3") {
$back_link_message=$fav_back[$lang];
$back_link="favorites.php";
}
elseif($loc_id=="4") {
$back_link_message=$myl_back[$lang];
$back_link="my_links.php";
}
$html->set_body('<tr><td colspan="2" class="message"><a href="'.$back_link.'">'.$back_link_message.'</a></td><td></td></tr>');
}
if ($resource_id) {
$db->get_resource_name($resource_id);
$res_display = $db->result->resource_name;
$html->set_body('<tr><td colspan="4"><div style="background-color: #fad163; text-align: center; font-weight: bold;">'.$resource_warn[$lang].cut_nick(htmlspecialchars($res_display)).'. '
.$resource_discard[$lang].'<a class="export" href="?a='.$e_string.'">'.$resource_discard2[$lang].'</a></div></td></tr>');
}
$action_link = $enc->crypt_url("tslice=$tslice&peer_name_id=$talker&peer_server_id=$server&lnk=$e_string&action=delete");
$sess->set('export_nickname',$nickname); // pass to export
$html->set_body('
<tr class="header">
<td><b> '.$time_t[$lang].' </b></td><td><b> '.$user_t[$lang].' </b></td><td><b> '.$thread[$lang].'</b></td>
<td align="right" style="padding-right: 5px; font-weight: normal;">
');
// check favorite
$db->check_favorite($talker,$server,$tslice);
if ($db->result->cnt < 1) {
$html->set_body('
<form style="margin-bottom: 0;" action="favorites.php" method="post">
<input type="hidden" name="a" value="'.$_GET[a].'">
<input type="hidden" name="init" value="1">
<input class="fav" type="submit" value="'.$fav_add[$lang].'">
</form>
');
}
else {
$html->set_body('
<form style="margin-bottom: 0;" action="favorites.php" method="post">
<input type="hidden" name="a" value="'.$_GET[a].'">
<input type="hidden" name="init" value="1">
<i>'.$fav_favorited[$lang].'</i>
</form>
');
}
$html->set_body('<a id="pretty" title="'.$tip_export[$lang].'" class="menu_chat" href="export.php?a='.$e_string.'">'.$export_link[$lang].'</a>&nbsp; | &nbsp;'.$all_for_u[$lang].'
<a id="pretty" title="'.$all_for_u_m2_d[$lang].'" class="menu_chat" href="chat_map.php?chat_map='.$predefined.'"><u>'.$all_for_u_m2[$lang].'</u></a>
&nbsp;<small>|</small>&nbsp;
<a id="pretty" title="'.$all_for_u_m_d[$lang].'" class="menu_chat" href="search_v2.php?b='.$predefined.'"><u>'.$all_for_u_m[$lang].'</u></a>
&nbsp; | &nbsp;
<a id="pretty" title="'.$tip_delete[$lang].'" class="menu_chat" href="calendar_view.php?a='.$action_link.'">'.$del_t[$lang].'</a>
</td></tr>
<tr class="spacer"><td colspan="7"></td></tr>
<tbody id="searchfield">
');
if($db->get_user_chat($tslice,$talker,$server,$resource_id,$start,$num_lines_bro) === false) {
$html->alert_message($oper_fail[$lang]);
}
// processing messages. this should be handled as separate message_processor, so that tree view and calendar view can share the same code withoud redundancy. To be done in 2.0
$result = $db->result;
// some strings to pass to message_processor
$lang_pack = array(
$cont_chat_p[$lang],
$message_type_message[$lang],
$message_type_error[$lang],
$message_type_headline[$lang],
$resource_only[$lang],
$muc_message[$lang],
$my_links_save[$lang],
$verb_h[$lang],
$in_min[$lang],
$cont_chat[$lang]
);
// Sent all data to parsing function (message processor)
if (message_processor($tslice,$server_name,$start,$nickname,$result,$db,$html,$enc,TOKEN,$split_line,$lang_pack,$lang,$spec_mark,$e_string,$to_base_prev,$to_base_next) !== true) {
$html->alert_message($oper_fail[$lang]);
$html->destroy_content();
}
// limiting code
$html->set_body('<tr class="spacer"><td colspan="7"></td></tr><tr class="foot"><td style="text-align: center;" colspan="9">');
for($i=0;$i < $nume;$i=$i+$num_lines_bro){
if ($i!=$start) {
if ($resource_id) {
$add_res="&amp;b=$resource_id";
}
else {
$add_res="";
}
$html->set_body('<a class="menu_chat" href="?a='.$e_string.$add_res.'&amp;start='.$i.'"> <b>['.$i.']</b> </font></a>');
}
else {
$html->set_body('<span style="color: #fff;">-'.$i.'-</span> ');
}
}
$html->set_body('</td></tr>');
// limiting code - end
if (($nume-$start)>40) {
$html->set_body('<tr><td colspan="6" style="text-align: right; padding-right: 5px;"><a href="#top"><small>'.$back_t[$lang].'</small></a></td></tr>');
}
$html->set_body('</table></tr></table></td>');
}
$html->set_body('</div></div>');
require_once("footer.php");
?>

152
jorge/chat_map.php Normal file
View File

@ -0,0 +1,152 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
require_once("headers.php");
require_once("upper.php");
$html->set_overview('<h2>'.$chat_map[$lang].'</h2>'.'<small>'.$chat_select[$lang].'</small>');
if ($_POST['chat_map']) {
$con_map = $enc->decrypt_url($_POST['chat_map']);
}
elseif ($_GET['chat_map']) {
$con_map = $enc->decrypt_url($_GET['chat_map']);
}
if($con_map === true) {
$con_map = $enc->jid;
}
else{
unset($con_map);
}
// prepare roster object
$ejabberd_roster->sort_by_nick("az");
$roster_chat = $ejabberd_roster->get_roster();
$html->set_body('<br><br><br>
<form id="c_map_form" action="chat_map.php" method="post" name="chat_map_form">
<p>'.$filter_tip[$lang].'</p>
<span style="padding-right: 20px">'.$chat_m_select[$lang].'</span>
<select id="c_map" style="text-align: center; border: 0px; background-color: #6daae7; color:#fff; font-size: x-small;" name="chat_map" size="0" onchange="javascript:document.chat_map_form.submit();">
<option value="null">'.$chat_c_list[$lang].'</option>
');
while (array_keys($roster_chat)) {
$jid = key($roster_chat);
$roster_item = array_shift($roster_chat);
$name = $roster_item[nick];
$grp = $roster_item[group];
if ($con_map==$jid) {
$selected="selected";
}
else {
$selected="";
}
$html->set_body('<option '.$selected.' value=\''.$enc->crypt_url("jid=$jid").'\'>'.htmlspecialchars($name).' ('.htmlspecialchars($grp).')</option>');
}
$html->set_body('</select></form>');
if ($con_map AND $_POST['chat_map'] != "null") {
// split username and server name
list($name_peer,$server_peer) = split("@",$con_map);
// get the id's of user and server
$db->get_user_id($name_peer);
$peer_name_id = $db->result->user_id;
$db->get_server_id($server_peer);
$peer_server_id = $db->result->server_id;
if ($peer_name_id !== null AND $peer_server_id !== null) {
//first get the months
$db->get_chat_map($peer_name_id,$peer_server_id);
$result1 = $db->result;
$cc_cmp = count($result1);
foreach ($result1 as $row_m) {
// hack for proper date parsing
list($y,$m) = split("-",$row_m[at]);
$mo="$y-$m";
// now get the days in with user was talking
$db->get_chat_map_specyfic($peer_name_id,$peer_server_id,$mo);
$result2 = $db->result;
foreach($result2 as $row_day) {
// now scan day for chats, yep thats weak, but as long as we dont have right stats table this will work...
$i++;
list($y,$m,$d) = split("-",$row_day[at]);
$days[$i] = $d;
}
if (count($days)>=1) {
$html->set_body('<table cellpadding="0" cellspacing="0" style="display:inline;"><tr><td style="width:200px; border: 0px; text-align:center;">');
$html->set_body(calendar($db,$user_id,$xmpp_host,$y,$m,$days,TOKEN,$url_key,$left,$right,$selected,$lang,$view_type,2,$peer_name_id,$peer_server_id,$cal_days,$enc,$months_names,$weekdays));
$html->set_body('</td></tr></table>');
unset($days);
}
else {
$score++;
}
$i=0;
}
}
else {
$cc_cmp = $score;
}
if ($score==$cc_cmp) {
$html->set_body('<span style="text-align: center;"><h2>'.$chat_no_chats[$lang].'</h2></span>');
}
}
$html->set_body('<br><small><i>*-'.$ff_notice[$lang].'</i></small>');
require_once("footer.php");
?>

3096
jorge/class.db.php Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,257 @@
<?
/*
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
/*##################################################
PHP XML-RPC clss for mod_xmlrpc
-------------------------------
Author: Zbyszek Zolkiewski (zbyszek@jabster.pl)
TEST VERSION, NOT ALL CALLS INCLUDED! THERE IS NO DOCUMENTATION YET.
$ejabberd_rpc = new rpc_connector("IP_OF_RPC_SERVER","RPC_PORT","XMPP_HOST","OPTIONAL_USERNAME","OPTIONAL_PASSWORD","OPTIONAL_NEWPASS");
if no username is provided on object creation, you can set it via:
$ejabberd_rpc->set_user("username","password","optional-new_password");
this is usefull especialy for scripts like bulk account creation/deletion etc...
Method: Returned values:
crete_account() true|false|exist
delete_account() true|false
auth() true|false
check_account() true|flase
change_password() true|false
get_roster() Array()
test_rpc() String
Example of authentication:
try {
if($ejabberd_rpc->auth() === true) {
print "Auth OK";
}
else {
print "Unknown account or bad password";
}
}
catch(Exception $e) {
echo "Exception: ".$e->getMessage();
echo ", Code: ".$e->getCode();
}
*/##################################################
class rpc_connector {
protected $rpc_server;
protected $rpc_port;
protected $username;
protected $password;
protected $newpass;
protected $vhost;
protected $parms;
protected $method;
public function __construct($rpc_server,$rpc_port,$vhost,$username = null,$password = null,$newpass = null) {
$this->setData($rpc_server,$rpc_port,$vhost,$username,$password,$newpass);
}
protected function setData($rpc_server, $rpc_port, $vhost, $username, $password,$newpass) {
$this->rpc_server = $rpc_server;
$this->rpc_port = $rpc_port;
$this->vhost = $vhost;
$this->username = $username;
$this->password = $this->clean_password($password);
$this->newpass = $this->clean_password($newpass);
}
public function set_user($username,$password,$newpass = null) {
$this->username = $username;
$this->password = $this->clean_password($password);
$this->newpass = $this->clean_password($newpass);
}
protected function commit_rpc() {
$request = xmlrpc_encode_request($this->method,$this->parms);
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => "Content-Type: text/xml; charset=utf-8\r\n" .
"User-Agent: XMLRPC::Client JorgeRPCclient",
'content' => $request
)));
$file = file_get_contents("http://$this->rpc_server".":"."$this->rpc_port", false, $context);
$response = xmlrpc_decode($file,"utf8");
if (xmlrpc_is_fault($response)) {
throw new Exception("XML-RPC Call Failed. Unrecoverable condition",0);
} else {
return $response;
}
}
protected function is_value($value) {
if($value === null) {
return false;
}
elseif($value==""){
return false;
}
else{
return true;
}
}
protected function clean_password($password) {
if (get_magic_quotes_gpc() === 1) {
return stripslashes($password);
}
return $password;
}
public function auth() {
$this->method = "check_password";
$this->parms = array("user"=>"$this->username","host"=>"$this->vhost","password"=>"$this->password");
if ($this->commit_rpc() === 0 ) {
return true;
}
else{
return false;
}
}
public function create_account() {
if ($this->is_value($this->username) === false OR $this->is_value($this->password) === false) { return false; }
$this->method = "create_account";
$this->parms = array("user"=>"$this->username","host"=>"$this->vhost","password"=>"$this->password");
$call = $this->commit_rpc();
if ($call === 0) {
return true;
}
elseif($call === 409) {
return "exist";
}
elseif($call === 1) {
return false;
}
}
public function check_account() {
if ($this->is_value($this->username) === false) { return false; }
$this->method = "check_account";
$this->parms = array("user"=>"$this->username","host"=>"$this->vhost");
if ($this->commit_rpc() === 1) {
return false;
}
else{
return true;
}
}
public function change_password() {
if ($this->is_value($this->newpass) === false OR $this->is_value($this->username) === false) { return false; }
$this->method = "change_password";
$this->parms = array("user"=>"$this->username","host"=>"$this->vhost","newpass"=>"$this->newpass");
if ($this->commit_rpc() === 0) {
$this->password = $this->newpass;
return true;
}
else{
return false;
}
}
public function get_roster() {
$this->method = "get_roster";
$this->parms = array("user"=>"$this->username","server"=>"$this->vhost");
return $this->commit_rpc();
}
public function delete_account() {
if ($this->is_value($this->password) === false OR $this->is_value($this->username) === false) { return false; }
$this->method = "delete_account";
$this->parms = array("user"=>"$this->username","host"=>"$this->vhost","password"=>"$this->password");
$this->commit_rpc();
if ($this->check_account() === false) {
return true;
}
else {
return false;
}
}
public function online_users() {
$this->method = "online_users";
$this->parms = "null";
return $this->commit_rpc();
}
public function test_rpc() {
$this->method = "echothis";
$this->parms = "If you can read this then RPC is working...";
return $this->commit_rpc();
}
}
?>

358
jorge/class.helper.php Normal file
View File

@ -0,0 +1,358 @@
<?
/*
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
###########################################################################
Helper classes for Jorge. Performs various operations.
*/
Class url_crypt Extends parser {
private $td;
public function __construct($key) {
$td = mcrypt_module_open('des', '', 'ecb', '');
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$this->td = $td;
}
public function __destruct() {
mcrypt_generic_deinit($this->td);
mcrypt_module_close($this->td);
}
public function crypt_url($url) {
return str_replace("+", "kezyt2s0", $this->url_encrypt($url));
}
public function decrypt_url($url) {
$url = str_replace("kezyt2s0", "+",$url);
return $this->decode_string($this->url_decrypt(base64_decode($url)));
}
private function url_encrypt($url) {
$prepared_string = "begin&".$url;
$integrity = md5($prepared_string);
$url = "integrity=$integrity&".$prepared_string;
$td = $this->td;
$c_t = mcrypt_generic($td, $url);
return base64_encode($c_t);
}
private function url_decrypt($url) {
$td = $this->td;
$p_t = mdecrypt_generic($td, $url);
return trim($p_t);
}
}
Class parser {
public $tslice = null;
public $peer_name_id = null;
public $peer_name = null;
public $peer_server_id = null;
public $peer_server = null;
public $jid = null;
public $ismylink = null;
public $linktag = null;
public $strt = null;
public $lnk = null;
public $action = null;
public $search_phase = null;
public $offset_arch = null;
public $offset_day = null;
public $tag_count = null;
public $time_start = null;
public $time_end = null;
public $single = null;
protected function decode_string($url) {
parse_str($url);
$reconstructed = strstr($url,"begin");
settype($integrity,"string");
if ($integrity === md5($reconstructed)) {
if (isset($tslice)) {
$this->tslice = $tslice;
}
if (isset($peer_name_id)) {
$this->peer_name_id = $peer_name_id;
}
if (isset($peer_server_id)) {
$this->peer_server_id = $peer_server_id;
}
if (isset($jid)) {
$this->jid = $jid;
}
if (isset($lnk)) {
$this->lnk = $lnk;
}
if (isset($ismylink)) {
$this->ismylink = $ismylink;
}
if (isset($linktag)) {
$this->linktag = $linktag;
}
if (isset($strt)) {
$this->strt = $strt;
}
if (isset($action)) {
$this->action = $action;
}
if (isset($peer_name)) {
$this->peer_name = $peer_name;
}
if (isset($peer_server)) {
$this->peer_server = $peer_server;
}
if (isset($search_phase)) {
$this->search_phase = $search_phase;
}
if (isset($offset_arch)) {
$this->offset_arch = $offset_arch;
}
if (isset($offset_day)) {
$this->offset_day = $offset_day;
}
if (isset($tag_count)) {
$this->tag_count = $tag_count;
}
if (isset($time_start)) {
$this->time_start = $time_start;
}
if (isset($time_end)) {
$this->time_end = $time_end;
}
if (isset($single)) {
$this->single = $single;
}
return true;
}
else {
return false;
}
return false;
}
}
Class render_html {
protected $html_head = array();
protected $html_menu = array();
protected $html_over;
protected $html_main = array();
protected $html_body = array();
protected $html_foot = array();
private $head_items = integer;
private $menu_items = integer;
private $main_items = integer;
private $body_items = integer;
private $foot_itesm = integer;
public function system_message($html) {
$this->html_main = array("sys_message"=>$this->render_system($html));
return;
}
public function status_message($html) {
$this->html_main = array("status_message"=>$this->render_status($html));
return;
}
public function alert_message($html) {
$this->html_main = array("alert_message"=>$this->render_alert($html));
return;
}
public function headers($html) {
if ($this->head_items === 0) {
$this->html_head = array("0"=>$html);
$this->head_items = 1;
}
else{
$this->head_items = $this->head_items + 1;
$this->html_head = $this->html_head += array($this->head_items=>$html);
}
return;
}
public function menu($html) {
if ($this->menu_items === 0) {
$this->html_menu = array("0"=>$html);
$this->menu_items = 1;
}
else{
$this->menu_items = $this->menu_items + 1;
$this->html_menu = $this->html_menu += array($this->menu_items=>$html);
}
return;
}
public function set_overview($html) {
$this->html_over = $html;
return;
}
public function set_body($html) {
if ($this->body_items === 0) {
$this->html_body = array("0"=>$html);
$this->body_items = 1;
}
else{
$this->body_items = $this->body_items + 1;
$this->html_body = $this->html_body += array($this->body_items=>$html);
}
return;
}
public function foot($html) {
if ($this->foot_items === 0) {
$this->html_foot = array("0"=>$html);
$this->foot_items = 1;
}
else{
$this->foot_items = $this->foot_items + 1;
$this->html_foot = $this->html_foot += array($this->foot_items=>$html);
}
return;
}
public function commit_render() {
$html_head = $this->html_head;
$html_menu = $this->html_menu;
$html_over = $this->html_over;
$html_main = $this->html_main;
$html_body = $this->html_body;
$html_foot = $this->html_foot;
for ($z=0;$z<=$this->head_items;$z++) {
$out .= $html_head[$z];
}
$out .= $html_main[sys_message];
for ($z=0;$z<=$this->menu_items;$z++) {
$out .= $html_menu[$z];
}
$out .= $html_over;
$out .= $html_main[alert_message];
$out .= $html_main[status_message];
for ($z=0;$z<=$this->body_items;$z++) {
$out .= $html_body[$z];
}
for ($z=0;$z<=$this->foot_items;$z++) {
$out .= $html_foot[$z];
}
echo $out;
return;
}
public function destroy_content() {
$this->html_body = array();
return;
}
protected function render_alert($message, $class = "message") {
return '<center><div class="'.$class.'">'.$message.'</div><br></center>';
}
protected function render_status($message, $class = "message") {
return '<center><div class="'.$class.'">'.$message.'</div><br></center>';
}
protected function render_system($message, $class = null) {
return '<center><div class="system">'.$message.'</div><br></center>';
}
}
?>

147
jorge/class.roster.php Normal file
View File

@ -0,0 +1,147 @@
<?
/*
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/*
Known issue:
Roster index have unique key set on JabberID so if user have same jid in 2 or more groups only first is included in index. As this is quite rare situation i consider it as minor bug and will be fixed later.
*/
class roster {
protected $roster_item;
protected $roster;
public function add_item($jid,$nick,$group) {
$new_item[$jid] = array("nick"=>$nick,"group"=>$group);
if ($this->roster) {
$this->roster = $this->roster += $new_item;
}
else {
$this->roster = $new_item;
}
}
public function get_roster() {
return $this->roster;
}
public function get_nick($jid) {
$roster = $this->roster;
$nick = $roster[$jid][nick];
return htmlspecialchars($nick);
}
public function get_group($jid) {
$roster = $this->roster;
$group = $roster[$jid][group];
return htmlspecialchars($group);
}
public function get_nick_group($jid) {
$roster = $this->roster;
$result = array($roster[$jid][nick],$roster[$jid][group]);
return $result;
}
public function sort_by_jid($dir) {
$arr = $this->roster;
if ($dir==="az") {
ksort($arr);
}
elseif($dir==="za") {
krsort($arr);
}
else{
return false;
}
$this->roster = $arr;
}
public function sort_by_nick($dir) {
$this->sort_roster($dir,"nick");
}
public function sort_by_group($dir) {
$this->sort_roster($dir,"group");
}
public function sort_by_nick_group() {
$arr = $this->roster;
array_multisort($this->prepare_multisort("group"),SORT_ASC, $this->prepare_multisort("nick"),SORT_ASC,$arr);
$this->roster = $arr;
}
protected function sort_roster($dir,$field) {
$arr = $this->roster;
if ($dir ==="az") {
array_multisort($this->prepare_multisort("$field"),SORT_ASC,$arr);
}
elseif($dir==="za") {
array_multisort($this->prepare_multisort("$field"),SORT_DESC,$arr);
}
else{
return false;
}
$this->roster = $arr;
}
protected function prepare_multisort($val) {
$arr = $this->roster;
foreach ($arr as $key => $row) {
$field[$key] = $row[$val];
}
$ret = array_map('strtolower', $field);
return $ret;
}
}
?>

68
jorge/class.sessions.php Normal file
View File

@ -0,0 +1,68 @@
<?php
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if (__FILE__==$_SERVER['SCRIPT_FILENAME']) {
header("Location: index.php?act=logout");
exit;
}
class session {
public $id;
function session ($lifetime=10800) { // czas ?ycia sesji
@session_start();
}
function unregister($name) {
unset($HTTP_SESSION_VARS[$name]);
}
function is_registered($name) {
if (isset($_SESSION[$name])) return true;
else return false;
}
function get($name) {
return $_SESSION[$name];
}
function set($name,$value) {
$_SESSION[$name]=$value;
}
// zwraca id sesji uzytkownika
function id() {
return(@session_id());
}
// ubija sesje - logout
function finish() {
//$id_session = $this->id();
@session_unset();
@session_destroy();
}
}
?>

99
jorge/config.php.inc Normal file
View File

@ -0,0 +1,99 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// Print debuging information (true|false). Do NOT set as true on producion servers!
define("DEBUG", false);
define("SQL_DEBUG",false); // sql debug
// Language support. Add your language below. DO NOT change IDs after jorge usage as this IDs are held in jorge_pref table.
$language_support = array(
"Polski"=> array ("pol","1"),
"English"=> array("eng", "2")
);
// Define default language. Should be the name from language_support array.
define(default_language, "English");
// vhost and RPC settings
// RPC port:
$rpc_port="4666";
// vhost settings, format "xmpp.server.com"=>array of RPC servers (WARNING! Do not mistake vhost and RPC servers as this is crutial for authentication!)
$vhosts = array(
"jabber.example.com"=>
array("10.0.0.1","10.0.0.2"),
"jabber.example.eu"=>
array("10.0.0.3","10.0.0.4")
);
// array of admins for domain
$vhosts_admins = array(
"jabber.example.com"=> array("admin1","admin2","admin3"),
"jabber.example.eu"=> array("admin10","admin20")
);
// MySQL database where mod_logdb is running on:
define("MYSQL_USER", ""); // username
define("MYSQL_PASS", ""); // password
define("MYSQL_NAME",""); // db name
define("MYSQL_HOST", ""); // host ip
// Since version 1.5 Jorge is using reCAPTCHA code. Before running Jorge please go to: http://recaptcha.net/ and setup your account and get private key and public key:
define("CAPTCHA_PRIVATE","");
define("CAPTCHA_PUBLIC","");
// secret key for scrambling URLs. Put here some random data (32 chars):
define("ENC_KEY","PleaseChangeMe");
// Turn SSL redirection in PHP
define("SSL_REDIRECT", "false");
// number of chat lines in browser (default: 300)
$num_lines_bro = "300";
// number of search results (default: 100)
$num_search_results = "100";
// splitting line. Value in seconds. Default 900s = 15 minutes
$split_line="900";
// links
$links='<a class="foot" href="http://www.jabster.pl" target="_blank">jabster.pl</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a class="foot" href="http://poczta.jabster.pl" target="_blank">poczta</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a class="foot" href="http://kalendarz.jabster.pl" target="_blank">kalendarz</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a class="foot" href="http://docs.jabster.pl" target="_blank">dokumenty</a>
';
// copyright
$copy = "jabster.pl &copy; 2009";
// custom logo
$brand_logo = "logo_jabster.png";
?>

191
jorge/contacts.php Normal file
View File

@ -0,0 +1,191 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
require_once("headers.php");
require_once("upper.php");
$html->set_overview('<h2>'.$con_head[$lang].'</h2><small>'.$con_notice[$lang].'</small>');
if ($_POST) {
while (array_keys($_POST)) {
$jid = base64_decode(str_replace("kezyt2s0", "+", key($_POST)));
$val = array_shift($_POST);
if ($val=="n") {
$do_not_log_list .=$jid."\n";
}
}
if ($db->update_log_list($do_not_log_list) === true) {
$html->status_message($con_saved[$lang]);
}
else {
$html->alert_message($oper_fail[$lang]);
}
}
// sorting options
$get_sort = $_GET['sort'];
$get_dir = $_GET['o'];
// validate
if (!ctype_digit($get_sort) AND !ctype_digit($get_dir)) { unset($get_sort); unset($get_dir); }
if ($get_dir === "1") {
$dir = "za";
$get_dir = "2";
}
elseif($get_dir === "2"){
$dir = "az";
$get_dir = "1";
}
else{
$dir = "az";
$get_dir = "2";
}
if ($get_sort === "1") {
$ejabberd_roster->sort_by_jid($dir);
}
elseif($get_sort === "2") {
$ejabberd_roster->sort_by_nick($dir);
}
elseif($get_sort === "3") {
$ejabberd_roster->sort_by_group($dir);
}
else{
$ejabberd_roster->sort_by_nick_group();
}
$roster_con = $ejabberd_roster->get_roster();
if ($roster_con) {
$db->get_log_list();
$do_notlog_list = $db->result;
$html->set_body('<center><form action="contacts.php" method="post"><table id="maincontent" border="0" class="ff" cellspacing="0">');
if ($get_sort) {
$html->set_body('<tr><td colspan="5" style="text-align: right; font-size: x-small;"><a href="contacts.php">'.$reset_sort[$lang].'</a></td></tr>');
}
$html->set_body('<tr class="header">
<td><a href="?sort=2&o='.$get_dir.'"><span style="color: white;">'.$con_tab2[$lang].'&nbsp;&#8593;&#8595;</span></a></td>
<td><a href="?sort=1&o='.$get_dir.'"><span style="color: white;">'.$con_tab3[$lang].'&nbsp;&#8593;&#8595;</span></a></td>
<td style="text-align: center;"><a href="?sort=3&o='.$get_dir.'"><span style="color: white;">'.$con_tab6[$lang].'&nbsp;&#8593;&#8595;</span></a></td>
<td>'.$show_chats[$lang].':</td>
<td style="padding-left: 10px;">'.$con_tab4[$lang].'</td>
</tr>
<tr class="spacer"><td colspan="5"></td></tr>
<tbody id="searchfield">
');
while (array_keys($roster_con)) {
$jid = key($roster_con);
$roster_item = array_shift($roster_con);
$nick = $roster_item[nick];
$grp = $roster_item[group];
$predefined = $enc->crypt_url("jid=$jid");
$prepared_jid=str_replace("+", "kezyt2s0", base64_encode($jid));
if ($col=="e0e9f7") {
$col="e8eef7";
}
else {
$col="e0e9f7";
}
if (in_array($jid,$do_notlog_list) === true) {
$selected="selected";
}
else {
$selected="";
}
if ($selected!="") {
$col="b7b7b7";
}
$html->set_body('
<tr bgcolor="'.$col.'" onMouseOver="this.bgColor=\'c3d9ff\';" onMouseOut="this.bgColor=\'#'.$col.'\';">
<td style="padding-left:7px"><b>'.cut_nick(htmlspecialchars($nick)).'</b></td>
<td>(<i>'.htmlspecialchars($jid).'</i>)</td>
<td style="text-align: center;">'.cut_nick(htmlspecialchars($grp)).'</td>
<td style="text-align: center;"><a href="chat_map.php?chat_map='.$predefined.'"><u>'.$show_chat_as_map[$lang].'</u></a>|
<a href="search_v2.php?b='.$predefined.'"><u>'.$show_chat_stream[$lang].'</u></a></td>
<td style="text-align: center;">
<select class="cc2" name="'.$prepared_jid.'">
<option value="y">'.$con_tab_act_y[$lang].'</option>
<option value="n" '.$selected.' >'.$con_tab_act_n[$lang].'</option>
</select></td></tr>
');
}
$html->set_body('<tr class="spacer"><td colspan="5"></td></tr>
</tbody>
<tr class="foot"><td colspan="5" style="text-align: center;">
<input class="submit" type="submit" value="'.$con_tab_submit[$lang].'"></td></tr>
</table></form></center>
');
}
else {
$html->status_message('<p align="center"><b>'.$no_contacts[$lang].'</b></p>');
}
require_once("footer.php");
?>

208
jorge/export.php Normal file
View File

@ -0,0 +1,208 @@
<?php
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
// Suppress all errors
error_reporting(E_NONE);
require("func.php");
require("class.sessions.php");
require("class.ejabberd_xmlrpc.php");
require("class.db.php");
require("class.roster.php");
require("class.helper.php");
require("config.php");
ob_start();
// init session
$sess = new session;
// Select language
if ($sess->get('language')) {
// Validate language setting in session
if (is_language_supported($sess->get('language'),$language_support) === true) {
require('lang/'.$sess->get('language').'.php');
}
else{
// In case of invalid session, overwrite value
require('lang/'.$language_support[default_language][0].'.php');
$sess->set('language',$language_support[default_language][0]);
}
}
else{
// If no lang in sess, set it anyway...
require('lang/'.$language_support[default_language][0].'.php');
$sess->set('language',$language_support[default_language][0]);
}
// language
$lang = $sess->get('language');
define(XMPP_HOST,$sess->get('vhost'));
$xmpp_host = str_replace(".","_", XMPP_HOST);
$rpc_host = check_rpc_server($vhosts[XMPP_HOST],$rpc_port);
// in case no RPC servers are available stop jorge
if ($rpc_host===false) {
print "<br><center><b>Currently service is unavailable. Please try again later.</b></center>";
exit;
}
// connect to xmpp server
$ejabberd_rpc = new rpc_connector("$rpc_host","$rpc_port",XMPP_HOST);
// initialize encryption system
$enc = new url_crypt(ENC_KEY);
// authenticate
if (check_registered_user($sess,$ejabberd_rpc,$enc) !== true) {
header("Location: index.php?act=logout");
exit;
}
// create database object
$db = new db_manager(MYSQL_HOST,MYSQL_NAME,MYSQL_USER,MYSQL_PASS,"mysql","$xmpp_host");
// set user data
define(TOKEN,$sess->get('uid_l'));
$db->get_user_id(TOKEN);
define(USER_ID, $db->result->user_id);
if (!ctype_digit(USER_ID)) {
// exit on unexpected results
exit;
}
else{
$db->set_user_id(USER_ID);
}
// get parameters
$e_string=$_GET['a'];
if ($enc->decrypt_url($e_string) === true) {
$tslice = $enc->tslice;
$talker = $enc->peer_name_id;
$server = $enc->peer_server_id;
}
else {
// if validation of link fail, exit
header('Location: index.php');
exit;
}
$db->get_user_name($talker);
$user_name = $db->result->username;
$db->get_server_name($server);
$server_name = $db->result->server_name;
$nickname = $sess->get('export_nickname');
$db->get_own_name();
if ($db->result->own_name) {
$own_name = $db->result->own_name;
}
else{
$own_name = false;
}
// get chat
$db->get_user_chat($tslice,$talker,$server,$resource_id = null,$start = null,10000);
$result = $db->result;
// set headers
header("Cache-Control: public, must-revalidate");
header("Pragma: hack"); // this is WEIRD - it is needed to work with Internet Explorer :O
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"Jorge_chat_$nickname-$tslice.txt\"");
$data="$export_head1[$lang]$nickname ($user_name@$server_name) $export_head2[$lang] $tslice:\n";
foreach ($result as $results) {
if ($results["direction"] == "from")
{
$out=$nickname;
$tt=$tt+1;
$aa=0;
}
else
{
if ($own_name !== false) {
$out = $own_name;
}
else{
$out = TOKEN;
}
$aa=$aa+1;
$tt=0;
}
if ($aa<2 AND $tt<2) {
$data .= "\n(".trim(strstr($results[ts], ' ')).") $out\n";
$here="1";
}
else
{
$data .=""; $here="0";
}
$data .=" $results[body]\n";
}
$data .="\n\n______\nChat exported by Jorge";
echo $data;
ob_end_flush();
// log event
$db->set_logger("8","1", "JID: $user_name@$server_name, Date: $tslice");
$sess->unregister('export_nickname');
?>

BIN
jorge/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

178
jorge/favorites.php Normal file
View File

@ -0,0 +1,178 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
require_once("headers.php");
require_once("upper.php");
$init = $_POST[init];
// header
$html->set_overview('<h2>'.$fav_main[$lang].'</h2><small>'.$fav_desc[$lang].'</small>');
// add to favorites
if ($init == "1") {
if ($enc->decrypt_url($_POST[a]) === true) {
$tslice = $enc->tslice;
$peer_name_id = $enc->peer_name_id;
$peer_server_id = $enc->peer_server_id;
$db->get_user_name($peer_name_id);
$user_name = $db->result->username;
$db->get_server_name($peer_server_id);
$server_name = $db->result->server_name;
$nick_name = query_nick_name($ejabberd_roster,$user_name, $server_name);
if (!$nick_name) {
$nick_name = $not_in_r[$lang];
unset($malpa);
}
else{
$malpa = "@";
}
$html->set_body('
<center>'.$fav_add[$lang].':<br>
<table class="ff" border="0" cellspacing="0">
<tr class="main_row_b"><td style="text-align: center;">'.$fav_chat[$lang].'<b>'.cut_nick($nick_name).'</b> (<i>'.$user_name.$malpa.$server_name.'</i>)</td></tr>
<form style="margin-bottom: 0;" action="favorites.php" method="post">
<tr><td colspan="3" align="center">
<textarea class="ccc" name="desc" rows="4">'.$my_links_optional[$lang].'</textarea>
</td></tr>
<tr><td colspan="3" align="center">
<input type="hidden" name="favorite" value="'.$_POST[a].'">
<input name="trigger" class="red" type="submit" value="'.$my_links_commit[$lang].'">
<input class="red" type="button" value="'.$my_links_cancel[$lang].'" onClick="parent.location=\''.$view_type.'?a='.$_POST[a].'\'">
</td></tr>
</form></table>
<hr size="1" noshade="noshade">
</center>');
}
}
// process request
if ($_POST[favorite]) {
if ($enc->decrypt_url($_POST[favorite]) === true) {
if ($db->set_favorites($enc->peer_name_id,$enc->peer_server_id,$peer_resource_id,$enc->tslice,$_POST[desc]) === true) {
$html->status_message($fav_success[$lang]);
}
else{
$html->alert_message($fav_error[$lang]);
}
}
}
// delete favorites
if ($_GET[del] == "t") {
if ($db->delete_favorites_id($_GET[link_id]) === true) {
$html->status_message($fav_removed[$lang]);
}
else{
$html->alert_message($oper_fail[$lang]);
}
}
// get favorites
$db->get_favorites();
if (count($db->result)>0) {
$html->set_body('
<center><table id="maincontent" class="ff" cellspacing="0">
<tr class="header"><td>'.$fav_when[$lang].'</td><td>'.$fav_contact[$lang].'</td><td>'.$fav_comment[$lang].'</td></tr>
<tr class="spacer" height="1px"><td colspan="4"></td></tr>
<tbody id="searchfield">
');
$fav_list = $db->result;
foreach ($fav_list as $row) {
$db->get_user_name($row[peer_name_id]);
$user_name = $db->result->username;
$db->get_server_name($row[peer_server_id]);
$server_name = $db->result->server_name;
$nickname = query_nick_name($ejabberd_roster,$user_name,$server_name);
$to_base = $enc->crypt_url("tslice=$row[tslice]&peer_name_id=$row[peer_name_id]&peer_server_id=$row[peer_server_id]");
if (!$row[comment] OR $row[comment] == $my_links_optional[$lang]) {
$comment = $fav_nocomm[$lang];
}
else{
$comment = htmlspecialchars($row[comment]);
$comment = str_replace("\n","<br>",$comment);
$comment = wordwrap($comment,30,"<br>",true);
}
if (!$nickname) {
$nickname = $not_in_r[$lang];
unset($malpa);
}
else {
$malpa = "@";
}
$html->set_body('
<tr style="cursor: pointer;" bgcolor="#e8eef7" onMouseOver="this.bgColor=\'c3d9ff\';" onMouseOut="this.bgColor=\'#e8eef7\';">
<td onclick="window.location=\''.$view_type.'?a='.$to_base.'&loc=3\';" style="padding-left: 10px; padding-right: 10px">'.verbose_date($row[tslice],$months_names,$weekdays).'</td>
<td onclick="window.location=\''.$view_type.'?a='.$to_base.'&loc=3\';" style="padding-left: 10px; padding-right: 10px">
<b>'.htmlspecialchars(cut_nick($nickname)).'</b> (<i>'.htmlspecialchars($user_name).$malpa.htmlspecialchars($server_name).'</i>)
</td>
<td onclick="window.location=\''.$view_type.'?a='.$to_base.'&loc=3\';" style="padding-left: 10px; padding-right: 10px;">'.$comment.'</td>
<td style="text-align: center;"><a href="favorites.php?del=t&link_id='.$row[link_id].'" onClick="if (!confirm(\''.$del_conf_my_link[$lang].'\')) return false;">&nbsp;'.$fav_remove[$lang].'&nbsp;</td>
</tr>
');
}
$html->set_body('</tbody><tr class="spacer"><td colspan="4"></td></tr><tr class="foot"><td colspan="4" height="15"></td></tr></table></center>');
}
else {
$html->status_message('<center><div class="message" style="width: 450px;">'.$fav_empty[$lang].'</div></center>');
}
require_once("footer.php");
?>

126
jorge/footer.php Normal file
View File

@ -0,0 +1,126 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if (__FILE__==$_SERVER['SCRIPT_FILENAME']) {
header("Location: index.php?act=logout");
exit;
}
$location=$_SERVER['PHP_SELF'];
if ($location=="footer.php") {
header('Location: index.php?act=logout');
exit;
}
if (!preg_match("/index.php/i",$location)) {
$html->foot('<br><div align="right" style="clear: left;"><a href="http://dev.jabbim.cz/jorge/newticket" target="_blank">'.$quest1[$lang].'</a></div>');
}
$html->foot('
<br><div style="background-image: url(img/bell-down.png); height: 3px; background-repeat:repeat-x;"></div>
<div align="center">'.$links.'</div><br>
<div align="center" style="color: gray;">'.$copy.'</div>
<p style="font-size: xx-small; text-align: right;">v1.5-RC1</p><br>
');
// footer for admins...
$time_end = getmicrotime();
$time = substr($time_end - $time_start, 0, 10);
if (TOKEN==ADMIN_NAME) {
$html->foot('<small>'.$admin_site_gen[$lang].$time.'s.</small>');
};
// execude following code only when user is logged in
if (!preg_match("/index.php/i",$location) AND !preg_match("/not_enabled.php/i",$location)) {
$html->foot('
<script type="text/javascript">
$(document).ready(function() {
function format(mail) {
return mail.name + " &lt;" + mail.jid + "&gt";
}
$("#t_search").autocomplete([');
$ejabberd_roster->sort_by_jid("az");
$roster_auto = $ejabberd_roster->get_roster();
while(array_keys($roster_auto)) {
$jid = htmlspecialchars(key($roster_auto));
$nic = htmlspecialchars($roster_auto[$jid][nick]);
array_shift($roster_auto);
$html->foot('{ name: "'.$nic.'", jid:"'.$jid.'" },');
}
$html->foot('],
{
minChars: 1,
parse: function(data) {
return $.map(eval(data), function(row) {
return {
data: row,
value: row.name,
result: row.name + " <" + row.jid + ">"
}
});
},
formatItem:function(row, i, max, term) {
return row.name.replace(new RegExp("(" + term + ")", "gi"), "<strong>$1</strong>") + "<br><span style=\'font-size: 80%;\'>JabberID: &lt;" + row.jid + "&gt;</span>";
},
formatResult: function(row) {
return "from:" + row.jid;
},
multiple: false,
max: 10,
cacheLength: 200,
matchSubset: true,
selectFirst: true,
matchContains: true
}
).result(function(e, item) {
$("#content").append("<p>selected " + format(item) + "</p>");
});
});
</script>
');
}
$html->foot('</body></html>');
// render html output
$html->commit_render();
ob_end_flush();
?>

932
jorge/func.php Normal file
View File

@ -0,0 +1,932 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if (__FILE__==$_SERVER['SCRIPT_FILENAME']) {
header("Location: index.php?act=logout");
exit;
}
function get_user_agent($_SERVER) {
if (preg_match("/Macintosh/i",$_SERVER['HTTP_USER_AGENT'])) {
return true;
}
else{
return false;
}
return false;
}
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function query_nick_name($ejabberd_roster,$talker, $server="") {
$nickname = $ejabberd_roster->get_nick("$talker"."@"."$server");
if ($nickname=="") {
$nickname=$talker;
}
return $nickname;
}
function validate_date($tslice) {
list($ye, $mo, $da) = split("-", $tslice);
return checkdate($mo,$da,$ye);
}
function check_registered_user ($sess,$ejabberd_rpc,$enc) {
if (!$sess->is_registered('uid_l') OR !$sess->is_registered('uid_p')) {
return false;
}
else {
if ($enc->decrypt_url($sess->get('uid_p')) === true) {
$uid_p = $enc->single;
}
else {
return false;
}
$ejabberd_rpc->set_user($sess->get('uid_l'),$uid_p);
if ($ejabberd_rpc->auth() === true) {
return true;
}
else {
return false;
}
}
return false;
}
function is_query_from($query) {
list($from,$talker,$query_p) = split(":",$query);
$from=trim($from);
if ($from=="from") {
$qquery[from] = "t";
$qquery[talker] = trim($talker);
$qquery[talker] = str_replace("//","@",$qquery[talker]); // hack for parametrized search
if ($query_p) {
$qquery[query] = $query_p;
$qquery[words] = "t";
return $qquery;
}
else {
$qquery[words] = "f";
return $qquery;
}
}
else {
// normal search
return "f";
}
}
function verbose_date($raw_date,$months_names = null,$weekdays = null,$t = false,$y = false) {
// English calendar arrays. Here we convert names from english calendar to other language. Make sure your locale in php work with default set to english.
$english_months = array("January","February", "March", "April", "May","June","July","August","September","October", "November","December");
$english_days = array("Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday");
// Various formats
if ($t === true) {
return str_replace($english_days,$weekdays,strftime("%e.%m (%A)",strtotime("$raw_date")));
}
elseif($y === true) {
return str_replace($english_months,$months_names,strftime("%B %Y", strtotime("$raw_date")));
}
else{
return str_replace($english_months,$months_names,strftime("%e %B %Y", strtotime("$raw_date")));
}
}
function validate_start($start) {
if (!ctype_digit($start)) {
return false;
}
if (fmod($start,10)=="0") {
return true;
}
else {
return false;
}
}
function db_size() {
$result = mysql_query("show table status");
$size = 0;
while($row = mysql_fetch_array($result)) {
$size += $row["Data_length"];
}
$size = round(($size/1024)/1024, 1);
return $size;
}
function verbose_split_line($in_minutes,$verb_h,$in_min) {
if ($in_minutes>60) {
return $verb_h;
}
elseif ($in_minutes<60) {
return $in_minutes." ".$in_min;
}
}
function cut_nick($nick) {
if (strlen($nick)> 25) {
$nick=substr($nick,0,25)."...";
}
return $nick;
}
function new_parse_url($text) {
$text = ereg_replace("([[:alpha:]]+://www|[[:alpha:]]+://)[^<>[:space:]]+[[:alnum:]/]",
"<a class=\"clickl\" href=\"\\0\" target=\"_blank\">\\0</a>", $text);
// disabled for now
#$text = ereg_replace("[^://]?www[^<>[:space:]]+[[:alnum:]/]",
# "<a class=\"clickl\" href=\"http://\\0\" target=\"_blank\">\\0</a>", $text);
return $text;
}
function calendar($db,$user_id,$xmpp_host,$y,$m,$days,$token,$url_key,$left,$right,$selected,$lang,$view_type,$c_type,$name_peer=0,$server_peer=0,$cal_days=0,$enc=null,$months_names,$weekdays) {
$days=$days;
$month = $m;
$year = $y;
//create arrays for the calendar
$months_days = array("31","28","31","30","31","30","31","31",
"30","31","30","31");
$days_array = array("Mon","Tue","Wed","Thu","Fri","Sat","Sun");
//removes the 0 from start of month - can't find array key with 0
if(strlen($month)==1){
$month= str_replace("0","",$month);
}
else{
$month=$month;
}
//reset month to the array key match (array starts at 0)
$month= $month-1;
//find the days in the month
$days_in_month = $months_days[$month];
//$m is used to find month
$m = $month+1;
//find the first day of the month
$time = date("M D Y H:i:s", mktime(0, 0, 0, $m, 1, $year));
$first_day = explode(" ",$time);
$time = $first_day[1];
//create the links to next and previous months
$next = $month+2;
$x = $year;
//if month is 13 then new year
if($next==13){
$next=1;
$x = $x+1;
}
$prev = $month;
$y = $year;
//if month is 0, then previous year
if($prev==0){
$prev=12;
$y=$y-1;
}
$calendar = "";
//Build the calendar with css
//links to next and previous month only for browser
if ($c_type=="1") {
// encode links
$link_left = $enc->crypt_url("tslice=$y-$prev");
$link_right = $enc->crypt_url("tslice=$x-$next");
// check if we have chats in prev and next mo
$db->is_left_or_right("$y-$prev");
$i_left = $db->result;
$db->is_left_or_right("$x-$next");
$i_right = $db->result;
}
else {
$i_left=0;
$i_right=0;
}
$calendar .='
<table width="200" border="0" cellpadding="0" cellspacing="0" class="calbck">
<tr>
<td><img src="img/cal_corn_11.png" width="15" height="7" alt="cal_img"></td>
<td style="background-image: url(img/cal_bck_top.gif);"></td>
<td><img src="img/cal_corn_12.png" width="14" height="7" alt="cal_img"></td>
</tr>
<tr>
<td width="15" valign="top" class="calbckleft"><img src="img/cal_bck_left.png" width="15" height="116" alt="cal_img">
</td>
<td width="100%" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="15" align="center" class="caldays">
';
if ($i_left!=0) { $calendar.='<a href="?left='.$link_left.'"><<<</a>'; }
$verb_date = "$year-$m-1";
$calendar.='
&nbsp;</td>
<td colspan="5" align="center" class="calhead">'.verbose_date($verb_date,$months_names,$weekdays,false,true).'</td>
<td align="center" class="caldays">&nbsp;
';
if ($i_right!=0) { $calendar.='<a href="?right='.$link_right.'">>>></a>'; }
$calendar.='
</td>
</tr>
<tr align="center" class="calweek">
<td width="14%" height="15">'.$cal_days[$lang][1].'</td>
<td width="14%">'.$cal_days[$lang][2].'</td>
<td width="14%">'.$cal_days[$lang][3].'</td>
<td width="14%">'.$cal_days[$lang][4].'</td>
<td width="14%">'.$cal_days[$lang][5].'</td>
<td width="14%">'.$cal_days[$lang][6].'</td>
<td width="14%">'.$cal_days[$lang][7].'</td>
</tr>
';
//checks for leap years and add 1 to February
if(($year % 4 =="") && ($month==1)){
$days_in_month=$days_in_month+1;
}
else{
$days_in_month=$days_in_month;
}
$new_time="";
//find how many blank spaces at beginning of the month
foreach($days_array as $key=>$value){
if($value == $time){
$new_time .= $key+1;
}
else{
$new_time .="";
}
}
//loop through the days in the month
$c=0;
for($k=1;$k<($days_in_month+$new_time);$k++){
$c++;
if ($c==1) { $calendar.='<tr align="center" class="caldays">'; }
//blank space
if($k<$new_time){
$calendar.='<td height="15">&nbsp;</td>
';
continue;
}
//start the actual days
$n = $k-$new_time+1;
if(in_array($n,$days)){
if ($c_type=="1") {
$to_base = $enc->crypt_url("tslice=$year-$m-$n");
$loc_orign="";
}
elseif($c_type=="2") {
$to_base = $enc->crypt_url("tslice=$year-$m-$n&peer_name_id=$name_peer&peer_server_id=$server_peer");
$loc_orign="&amp;loc=2";
}
if ($selected==$n) { $bgcolor = 'bgcolor="#6daae7"'; } else { $bgcolor=""; }
$calendar .= '<td height="15" '.$bgcolor.' onclick="window.location=\''.$view_type.'?a='.$to_base.$loc_orign.'\'"><b><a class="caldays2" href="'.$view_type.'?a='.$to_base.$loc_orign.'">'.$n.'</a></b></td>
';
}
else{
$calendar .= '<td height="15">'.$n.'</td>
';
}
if ($c==7) { $calendar.='</tr>'; $c=0; }
}
$calendar .= '
</table>
</td>
<td width="14" valign="top" class="calbckright"><img src="img/cal_bck_right.png" width="14" height="116" alt="cal_img"></td>
</tr>
<tr>
<td><img src="img/cal_corn_21.png" width="15" height="16" alt="cal_img"></td>
<td style="background-image: url(img/cal_bck_bot.png);"></td>
<td><img src="img/cal_corn_22.png" width="14" height="16" alt="cal_img"></td>
</tr>
</table>
';
return($calendar);
}
function check_thread($db,$peer_name_id,$peer_server_id,$at,$xmpp_host,$dir=NULL) {
#adjust this hours as needed, we assume if chat is +/- 1 hour on the edge of day, then chat is related
if ($dir=="1") {
$day="+1 day";
$bhour="00:00:00";
$ehour="00:30:00";
}
elseif($dir=="2"){
$day="-1 day";
$bhour="23:30:00";
$ehour="23:59:59";
}
$get_date = date("Y-n-j", strtotime($day, strtotime(date("$at"))));
$db->check_thread($get_date,$peer_name_id,$peer_server_id,$bhour,$ehour);
if ($db->result > 0) {
return true;
}
else{
return false;
}
return false;
}
function check_rpc_server($rpc_arr,$rpc_port) {
foreach($rpc_arr as $rpc_host) {
// assume if response time is greater then 1 second RPC server is down
$fp=fsockopen("$rpc_host", $rpc_port, $errno, $errstr, 1);
if ($fp!=false) {
return $rpc_host;
}
}
return false;
}
function debug($debug=false,$string) {
if ($debug===true) {
print "<small>".htmlspecialchars($string)."</small><br>";
}
return;
}
function message_processor($tslice,$server_name,$start,$nickname,$result_messages,$db,$html,$enc,$token,$split_line,$lang_pack,$lang,$spec_mark,$e_string,$to_base_prev,$to_base_next) {
/*
This function perform message processing for message archives
tslice - date of chat
server_name - name of server
start - from what point of time of day should chat be displayed
nickname - peer nickname
result_messages - array of messages to be parsed
db - database object
html - html object
enc - encryption object
token - owner name
split_line - config option
lang_pack - array of translations
lang - language pack
spec_mark - marker used to distinguish what we are doing
e_string - url
*/
// Check if user have set up OwnName
$db->get_own_name();
if ($db->result->own_name) {
$own_name = $db->result->own_name;
}
else{
$own_name = false;
}
// Main loop
foreach($result_messages as $entry) {
// always get resource_id if message is type of groupchat
if ($entry[type] !== "groupchat") {
if ($resource_last !== $entry[peer_resource_id]) {
if ($db->get_resource_name($entry[peer_resource_id]) === false) {
return false;
}
$resource = $db->result->resource_name;
}
}
else{
if ($db->get_resource_name($entry[peer_resource_id]) === false) {
return false;
}
$resource = $db->result->resource_name;
}
$resource_last = $entry[peer_resource_id];
$licz++;
// marking messages
if ($entry["type"] === "chat" OR $entry["type"] == "") {
if ($entry["direction"] === "to") {
$col="main_row_a";
}
else {
$col="main_row_b";
}
}
elseif($entry["type"] === "error") {
$col="main_row_error";
}
elseif($entry["type"] === "normal") {
$col="main_row_message";
}
elseif($entry["type"] === "headline") {
$col="main_row_headline";
}
$ts = strstr($entry["ts"], ' ');
// time calc
$pass_to_next = $entry["ts"];
$new_d = $entry["ts"];
$time_diff = abs((strtotime("$old_d") - strtotime(date("$new_d"))));
$old_d = $pass_to_next;
// end time calc
if ($time_diff>$split_line AND $licz>1) {
$in_minutes = round(($time_diff/60),0);
$html->set_body('<tr class="splitl">
<td colspan="7" style="font-size: 10px;"><i>'.verbose_split_line($in_minutes,$lang_pack[7],$lang_pack[8]).'</i>
<hr size="1" noshade="noshade" style="color: #cccccc;"></td></tr>
');
}
// check if chat is continuation from previous day (work only for calendar view)
if ($to_base_prev !== NULL) {
if ($ts_mark!="1" AND substr($ts, 0 , strpos($ts, ":")) == 00 ) {
if ( check_thread($db,$talker,$server,$tslice,$xmpp_host,2) === true) {
$html->set_body('<tr><td colspan="6" style="text-align: left; padding-left: 5px;" class="message"><a href="calendar_view.php?a='.$to_base_prev.'">'.$lang_pack[0].'</a></td></tr>');
}
// check only first line
$ts_mark="1";
}
}
// run code only if type is not groupchat
if ($entry["type"] !== "groupchat") {
// setting subject
if ($col==="main_row_message" OR $col==="main_row_headline") {
if ($entry["subject"]) {
$subject = ": ".$entry["subject"];
}
else{
unset($subject);
}
}
// add line in case of special message
if ($col==="main_row_message") {
$html->set_body('<tr class="main_row_message"><td colspan="7" class="main_row_special">'.$lang_pack[1].' '.htmlspecialchars($subject).'</td></tr>');
}
if ($col==="main_row_error") {
$html->set_body('<tr class="main_row_error"><td colspan="7" class="main_row_special">'.$lang_pack[2].'</td></tr>');
}
if ($col==="main_row_headline") {
$html->set_body('<tr class="main_row_headline"><td colspan="7" class="main_row_special">'.$lang_pack[3].' '.htmlspecialchars($subject).'</td></tr>');
}
}
// calculate chat direction, whether to display nick...
if ($entry["direction"] == "from") {
$out=$nickname;
$tt=$tt+1;
$aa=0;
}
else{
$out = $token;
$aa=$aa+1;
$tt=0;
}
// timestamp, beginning of the chatline
if ($entry["type"] !== "groupchat") {
$html->set_body('<tr class="'.$col.'"><td class="time_chat" style="padding-left: 10px; padding-right: 10px;";>'.$ts.'</td>');
}
else{
if ($out!==$token) {
// colorize
if ($resource_group === $resource OR !$resource_group) {
if (!$col) {
$col = "main_row_group_to";
}
$col=$col;
}
else{
if($col === "main_row_group_from") {
$col="main_row_group_to";
}
else{
$col="main_row_group_from";
}
}
$html->set_body('<tr class="'.$col.'"><td class="time_chat" style="padding-left: 10px; padding-right: 10px;";>'.$ts.'</td>');
}
}
// different bahaviour for groupchat and other messages
if ($entry["type"] !== "groupchat") {
if ($aa<2 AND $tt<2) {
$html->set_body('<td style="padding-left: 5px; padding-right: 10px; nowrap="nowrap">');
if ($out === TOKEN) {
// display of Own Name
if ($own_name !== false) {
$html->set_body(cut_nick(htmlspecialchars($own_name)));
}
else{
$html->set_body(cut_nick(htmlspecialchars($out)));
}
}
else{
$html->set_body(cut_nick(htmlspecialchars($out)));
}
$html->set_body('<a name="'.$licz.'"></a>');
if ($out !== $token) {
if ($spec_mark === false) {
$html->set_body('
<br><div style="text-align: left; padding-left: 5px;">
<a class="export" id="pretty" title="'.$lang_pack[4].'" href="?a='.$e_string.'&amp;b='.$entry[peer_resource_id].'">
<small><i>'.cut_nick(htmlspecialchars($resource)).'</i></small></a></div>
');
}
else{
$html->set_body('<br><div style="text-align: left; padding-left: 5px;">
<small><i>'.cut_nick(htmlspecialchars($server_name)).'</i></small></div>
');
}
}
$html->set_body('</td>');
$here = "1";
}
else {
$html->set_body('<td style="text-align: right; padding-right: 5px">-</td>');
$here = "0";
}
}
else{
// do not display own chats sent to MUC. Here resource is actualy nickname as MUC standard specify
if ($out !== $token) {
if ($resource_group !== $resource) {
// if message is sent without resource, that must be channel message, advise user.
if ($resource === "") {
$resource = $lang_pack[5];
}
$html->set_body('<td style="padding-left: 5px; padding-right: 10px; nowrap="nowrap"><small>MUC: <i>'.cut_nick($out).'</i></small><a name="'.$licz.'"></a>
<br><div style="text-align: left; padding-left: 5px;">'.cut_nick(htmlspecialchars($resource)).'</div></td>
');
$here = "1";
$resource_group = $resource;
}
else{
$html->set_body('<td style="text-align: right; padding-right: 5px">-</td>');
$here = "0";
}
}
else{
$here = "0";
}
}
// process body part, do not show chat if message is type of groupchat
// this is sadly funny i write this 'if' and i dont know what exacly it do :/
if ($out !== $token OR $entry["type"] !== "groupchat") {
// prepare body
$new_s = htmlspecialchars($entry["body"]);
$to_r = array("\n");
$t_ro = array("<br>");
$new_s = str_replace($to_r,$t_ro,$new_s);
$new_s = wordwrap($new_s,107,"<br>",true);
$new_s = new_parse_url($new_s);
$html->set_body('<td width="800" colspan="3">'.$new_s.'</td>');
// generate mylink only on selected lines
if ($here==="1") {
$lnk = $enc->crypt_url("tslice=$tslice&peer_name_id=$entry[peer_name_id]&peer_server_id=$entry[peer_server_id]");
$to_base2 = $enc->crypt_url("tslice=$tslice&peer_name_id=$entry[peer_name_id]&peer_server_id=$entry[peer_server_id]&ismylink=1&linktag=$licz&lnk=$lnk&strt=$start");
$html->set_body('<td colspan="2" style="padding-left: 2px; font-size: 9px;"><a style="color: #1466bc" href="my_links.php?a='.$to_base2.'">'.$lang_pack[6].'</a></td>');
}
else {
$html->set_body('<td></td>');
}
if ($t=2) { $c=1; $t=0; } // WTF!?
$html->set_body('</tr>');
}
}
$html->set_body('</tbody>');
// Check thread. Work only for calendar view.
if ($to_base_next !== NULL) {
if (substr($ts, 0 , strpos($ts, ":")) == 23 AND date("Y-n-j") !== $tslice) {
if ( check_thread($db,$talker,$server,$tslice,$xmpp_host,1) === true) {
$html->set_body('<tr><td colspan="6" style="text-align: right; padding-right: 5px;" class="message"><a href="calendar_view.php?a='.$to_base_next.'">'.$lang_pack[9].'</a></td></tr>');
}
}
}
return true;
}
function is_language_supported($l_query,$language_support,$l_key = 0, $return_val = false) {
while (array_keys($language_support)) {
$lang_key = key($language_support);
if ($l_query === $language_support[$lang_key][$l_key]) {
if ($return_val === true) {
return $language_support[$lang_key][0];
}
else {
return true;
}
}
array_shift($language_support);
}
return false;
}
?>

371
jorge/headers.php Normal file
View File

@ -0,0 +1,371 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
if (__FILE__==$_SERVER['SCRIPT_FILENAME']) {
header("Location: index.php?act=logout");
exit;
}
// turn on buffering
ob_start();
// send headers
header("content-type: text/html; charset=utf-8");
// error reporting to off
error_reporting(E_NONE);
require_once("func.php"); // functions
require_once("class.sessions.php"); // sessions handling
require_once("class.ejabberd_xmlrpc.php"); // rpc class
require_once("class.db.php"); // db_manager
require_once("class.roster.php"); // roster
require_once("class.helper.php"); // helper
require_once("config.php"); // read configuration
# SSL redirection if set to true in config.
if (SSL_REDIRECT === "true") {
if($_SERVER['HTTPS'] != 'on') {
$url = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header('Location: '.$url);
ob_end_flush();
exit;
}
}
$sess = new session;
// Language support. Well thats the hard way...
$language_found = false;
if ($_GET['lng_sw']) {
debug(DEBUG,"Setting language");
$c_language = is_language_supported($_GET['lng_sw'],$language_support,1,true);
if ($c_language !== false) {
setcookie("jorge_language",$c_language,time()+2592000);
$sess->set('language',$c_language);
debug(DEBUG,"Language found, loading file: $c_language.php");
require("lang/".$c_language.".php");
$language_found = true;
}
else{
setcookie("jorge_language",$language_support[default_language][0],time()+2592000);
$sess->set('language',$language_support[default_language][0]);
debug(DEBUG,"Language not found in selection, using defaults");
require('lang/'.$language_support[default_language][0].'.php');
}
}
// get client addr
$rem_adre = $_SERVER['REMOTE_ADDR'];
// something for mac users
$mac_user = get_user_agent($_SERVER);
// location
$location=$_SERVER['PHP_SELF'];
// init html helper
$html = new render_html();
if (!preg_match("/index.php/i",$location)) {
if ($sess->get('vhost') === null) {
header("Location: index.php?act=logout");
}
if (array_key_exists($sess->get('vhost'), $vhosts) === false) {
header("Location: index.php?act=logout");
}
define(XMPP_HOST,$sess->get('vhost'));
$rpc_host = check_rpc_server($vhosts[XMPP_HOST],$rpc_port);
debug(DEBUG,"Active RPC host: $rpc_host");
// in case no RPC servers are available stop jorge
if ($rpc_host===false) {
print "<br><center><b>Currently service is unavailable. Please try again later.</b><br>
<a href=\"index.php?act=logout\">Please logout</a>
</center>";
exit;
}
// create rpc object
$ejabberd_rpc = new rpc_connector("$rpc_host","$rpc_port",XMPP_HOST);
$xmpp_host = str_replace(".","_", XMPP_HOST);
}
else{
// check if selected host exist in configuration
if (array_key_exists($_POST['vhost'], $vhosts) === true) {
$rpc_host = check_rpc_server($vhosts[$_POST['vhost']],$rpc_port);
debug(DEBUG,"Selecting RPC server during login: $rpc_host");
if ($rpc_host === false) {
print "<br><center><b>Currently service is unavailable. Please try again later.<br>
<a href=\"index.php?act=logout\">Please logout</a>
</b></center>";
exit;
}
else {
define(XMPP_HOST,$_POST['vhost']);
$ejabberd_rpc = new rpc_connector("$rpc_host","$rpc_port",XMPP_HOST);
$xmpp_host = str_replace(".","_", XMPP_HOST);
}
}
else{
unset($_POST['inpLogin']);
unset($_POST['inpPass']);
// Try to recreate db object...
if ($_GET['act'] === "logout") {
if ($sess->get('vhost')!="") {
$xmpp_host = str_replace(".","_", $sess->get('vhost'));
}
}
}
}
// create db_manager object
$db = new db_manager(MYSQL_HOST,MYSQL_NAME,MYSQL_USER,MYSQL_PASS,"mysql","$xmpp_host");
$db->set_debug(SQL_DEBUG);
// create encryption object
$enc = new url_crypt(ENC_KEY);
// username (token)
define(TOKEN,$sess->get('uid_l'));
//debug
debug(DEBUG,"User session:".TOKEN);
// authentication checks. Ensure if session data is not altered... (only when we are inside Jorge)
if (!preg_match("/index.php/i",$location)) {
if (check_registered_user($sess,$ejabberd_rpc,$enc) !== true) {
header("Location: index.php?act=logout");
exit;
}
// Load language file based on current session
debug(DEBUG,"Selecting initial language after authentication");
if ($sess->get('language')) {
// Validate language setting in session
if (is_language_supported($sess->get('language'),$language_support) === true) {
debug(DEBUG,"Language selection ok.");
require('lang/'.$sess->get('language').'.php');
}
else{
debug(DEBUG,"Language in session was altered! Overwritting value...");
require('lang/'.$language_support[default_language][0].'.php');
$sess->set('language',$language_support[default_language][0]);
}
}
// we need user_id but only if we are not in not_enabled mode:
if(!preg_match("/not_enabled.php/i",$_SERVER['PHP_SELF'])) {
$db->get_user_id(TOKEN);
$user_id = $db->result->user_id;
// create user_id instance
$db->set_user_id($user_id);
}
}
// check if user have admin rights
if (in_array(TOKEN, $vhosts_admins[XMPP_HOST]) === true) {
define(ADMIN_NAME,TOKEN);
}
// run only for admins
if (TOKEN === ADMIN_NAME) {
$time_start=getmicrotime();
}
// If language not set or not found in cookie, set default language
if (preg_match("/index.php/i",$location) OR preg_match("/not_enabled.php/i",$location)) {
// Set defaults only if language was not selected
if ($language_found !== true) {
if (is_language_supported($_COOKIE["jorge_language"],$language_support) === true) {
debug(DEBUG,"Setting language according to cookie");
require('lang/'.$_COOKIE["jorge_language"].'.php');
$sess->set('language',$_COOKIE["jorge_language"]);
}
else {
debug(DEBUG,"Language cookie not found, using defaults");
require('lang/'.$language_support[default_language][0].'.php');
$sess->set('language',$language_support[default_language][0]);
}
}
}
// Get language from session
$lang=$sess->get('language');
$html->headers('
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="pragma" content="no-cache">
<meta name="Author" content="Zbyszek Zolkiewski at jabster.pl">
<meta name="Keywords" content="jorge message archiving ejabberd mod_logdb erlang">
<meta name="Description" content="Jorge">
<link rel="shortcut icon" href="favicon.ico">
<link rel="stylesheet" href="style.css" type="text/css">
<link rel="stylesheet" href="jquery.autocomplete.css" type="text/css">
<link rel="alternate" type="application/rss+xml" title="Project Jorge ChangeLog" href="https://jorge.jabster.pl/changelog.xml">
');
if (preg_match("/main.php/i",$location)) {
$html->headers('
<link rel="stylesheet" href="simpletree.css" type="text/css" />
<script type="text/javascript" src="lib/simpletreemenu.js">
/***********************************************
* Simple Tree Menu - Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
');
}
$html->headers('
<script type="text/javascript" src="lib/jquery.pack.js"></script>
<script type="text/javascript" src="lib/jquery.bgiframe.min.js"></script>
<script type="text/javascript" src="lib/jquery.tooltip.js"></script>
<script type="text/javascript" src="lib/jquery.quicksearch.js"></script>
<script type="text/javascript" src="lib/jquery.autocomplete.pack.js"></script>
');
// prevent loading includes as long as user is not admin.
if (TOKEN==ADMIN_NAME) {
$html->headers('<script language="javascript" type="text/javascript" src="lib/jquery.flot.pack.js"></script>');
}
$html->headers('
<title>Jorge Beta</title>
<script type="text/javascript">
$(function() {
$(\'table#maincontent tbody#searchfield tr\').quicksearch({
stripeRowClass: [\'odd\', \'even\'],
position: \'before\',
attached: \'#maincontent\',
labelText: \'QuickFilter:\',
loaderText: \'\',
inputClass: \'c_map_class\',
delay: 30
});
$(\'select#c_map option\').quicksearch({
stripeRowClass: [\'odd\', \'even\'],
position: \'before\',
inputText: \''.$filter_form_tip[$lang].'\',
inputClass: \'c_map_class\',
attached: \'#c_map_form\',
labelText: \''.$filter_form[$lang].':\',
delay: 30
});
$(\'img\').Tooltip();
$(\'a, tr, td\').Tooltip({
extraClass: "fancy",
showBody: ";",
showURL: false,
track: true,
fixPNG: true
});
});
</script>
</head>
<body style="background-image: url(img/bak2b.png); background-repeat:repeat-x; background-color: #edf5fa;">
<noscript>
<center><div style="background-color: #fad163; text-align: center; font-weight: bold; width: 500pt;">'.$no_script[$lang].'</div></center><br>
</noscript>
<script language="JavaScript1.2" type="text/javascript">
function smackzk() {
window.open(\'http://slimster.org/web\',\'\',
\'location=no,toolbar=no,menubar=no,scrollbars=no,resizable, height=375,width=715\');
}
</script>
');
?>

29
jorge/help.php Normal file
View File

@ -0,0 +1,29 @@
<?
/*
Jorge - frontend for mod_logdb - ejabberd server-side message archive module.
Copyright (C) 2009 Zbigniew Zolkiewski
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
require_once("headers.php");
require_once("upper.php");
$html->set_body('<h2>'.$help_but[$lang].'</h2><small>'.$help_notice[$lang].'</small>'.$help_search_tips[$lang].$help_my_links_note[$lang].$help_advanced_tips[$lang]);
require_once("footer.php");
?>

BIN
jorge/img/apple-logo.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
jorge/img/bak2a.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 251 B

BIN
jorge/img/bak2b.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

BIN
jorge/img/bar_bg.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 213 B

BIN
jorge/img/bar_new.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Some files were not shown because too many files have changed in this diff Show More