mod_admin_web/admin_web/mod_admin_web.lua
author Florian Zeitz <florob@babelmonkeys.de>
Fri, 24 Dec 2010 01:59:28 +0100
changeset 295 e373de5907aa
parent 292 a9e69088e678
child 301 b241c79a0eb7
permissions -rw-r--r--
mod_admin_web: Only create the node once when loading onto multiple hosts
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     1
-- Copyright (C) 2010 Florian Zeitz
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     2
--
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     3
-- This file is MIT/X11 licensed. Please see the
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     4
-- COPYING file in the source package for more information.
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     5
--
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     6
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     7
-- <session xmlns="http://prosody.im/streams/s2s" jid="example.com">
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     8
--   <encrypted/>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
     9
--   <compressed/>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    10
--   <in/> / <out/>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    11
-- </session>
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    12
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    13
local stanza = require "util.stanza";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    14
local uuid_generate = require "util.uuid".generate;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    15
local httpserver = require "net.httpserver";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    16
local lfs = require "lfs";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    17
local open = io.open;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    18
local stat = lfs.attributes;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    19
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    20
local host = module:get_host();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    21
local service = config.get("*", "core", "webadmin_pubsub_host") or ("pubsub." .. host);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    22
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    23
local http_base = (prosody.paths.plugins or "./plugins/") .. "admin_web/www_files";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    24
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    25
local xmlns_sessions = "http://prosody.im/streams/s2s";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    26
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    27
local response_400 = { status = "400 Bad Request", body = "<h1>Bad Request</h1>Sorry, we didn't understand your request :(" };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    28
local response_403 = { status = "403 Forbidden", body = "<h1>Forbidden</h1>You don't have permission to view the contents of this directory :(" };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    29
local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    30
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    31
local mime_map = {
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    32
	html = "text/html";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    33
	xml = "text/xml";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    34
	js = "text/javascript";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    35
	css = "text/css";
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    36
};
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    37
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    38
local idmap = {};
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    39
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    40
function add_host(session, type)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    41
	local name = (type == "out" and session.to_host) or (type == "in" and session.from_host);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    42
	local id = idmap[name.."_"..type];
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    43
	if not id then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    44
		id = uuid_generate();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    45
		idmap[name.."_"..type] = id;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    46
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    47
	local item = stanza.stanza("item", { id = id }):tag("session", {xmlns = xmlns_sessions, jid = name})
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    48
		:tag(type):up();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    49
	if session.secure then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    50
		item:tag("encrypted"):up();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    51
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    52
	if session.compressed then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    53
		item:tag("compressed"):up();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    54
	end
292
a9e69088e678 mod_adhoc_web: Put pubsubHost into js from lua. Compat with util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 288
diff changeset
    55
	hosts[service].modules.pubsub.service:publish(xmlns_sessions, service, id, item);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    56
	module:log("debug", "Added host " .. name .. " s2s" .. type);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    57
end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    58
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    59
function del_host(session, type)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    60
	local name = (type == "out" and session.to_host) or (type == "in" and session.from_host);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    61
	local id = idmap[name.."_"..type];
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    62
	if id then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    63
		local notifier = stanza.stanza("retract", { id = id });
292
a9e69088e678 mod_adhoc_web: Put pubsubHost into js from lua. Compat with util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 288
diff changeset
    64
		hosts[service].modules.pubsub.service:retract(xmlns_sessions, service, id, notifier);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    65
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    66
end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    67
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    68
local function preprocess_path(path)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    69
	if path:sub(1,1) ~= "/" then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    70
		path = "/"..path;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    71
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    72
	local level = 0;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    73
	for component in path:gmatch("([^/]+)/") do
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    74
		if component == ".." then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    75
			level = level - 1;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    76
		elseif component ~= "." then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    77
			level = level + 1;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    78
		end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    79
		if level < 0 then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    80
			return nil;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    81
		end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    82
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    83
	return path;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    84
end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    85
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    86
function serve_file(path)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    87
	local full_path = http_base..path;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    88
	if stat(full_path, "mode") == "directory" then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    89
		if stat(full_path.."/index.html", "mode") == "file" then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    90
			return serve_file(path.."/index.html");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    91
		end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    92
		return response_403;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    93
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    94
	local f, err = open(full_path, "rb");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    95
	if not f then return response_404; end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    96
	local data = f:read("*a");
292
a9e69088e678 mod_adhoc_web: Put pubsubHost into js from lua. Compat with util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 288
diff changeset
    97
	data = data:gsub("%%PUBSUBHOST%%", service);
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    98
	f:close();
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
    99
	if not data then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   100
		return response_403;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   101
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   102
	local ext = path:match("%.([^.]*)$");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   103
	local mime = mime_map[ext]; -- Content-Type should be nil when not known
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   104
	return {
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   105
		headers = { ["Content-Type"] = mime; };
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   106
		body = data;
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   107
	};
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   108
end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   109
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   110
local function handle_file_request(method, body, request)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   111
	local path = preprocess_path(request.url.path);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   112
	if not path then return response_400; end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   113
	path = path:gsub("^/[^/]+", ""); -- Strip /admin/
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   114
	return serve_file(path);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   115
end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   116
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   117
function module.load()
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   118
	local host_session = prosody.hosts[host];
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   119
	local http_conf = config.get("*", "core", "webadmin_http_ports");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   120
295
e373de5907aa mod_admin_web: Only create the node once when loading onto multiple hosts
Florian Zeitz <florob@babelmonkeys.de>
parents: 292
diff changeset
   121
	if not select(2, hosts[service].modules.pubsub.service:get_nodes(service))[xmlns_sessions] then
e373de5907aa mod_admin_web: Only create the node once when loading onto multiple hosts
Florian Zeitz <florob@babelmonkeys.de>
parents: 292
diff changeset
   122
		local ok, errmsg = hosts[service].modules.pubsub.service:create(xmlns_sessions, service);
e373de5907aa mod_admin_web: Only create the node once when loading onto multiple hosts
Florian Zeitz <florob@babelmonkeys.de>
parents: 292
diff changeset
   123
		if not ok then
e373de5907aa mod_admin_web: Only create the node once when loading onto multiple hosts
Florian Zeitz <florob@babelmonkeys.de>
parents: 292
diff changeset
   124
			error("Could not create node: " .. tostring(errmsg));
e373de5907aa mod_admin_web: Only create the node once when loading onto multiple hosts
Florian Zeitz <florob@babelmonkeys.de>
parents: 292
diff changeset
   125
		end
292
a9e69088e678 mod_adhoc_web: Put pubsubHost into js from lua. Compat with util.pubsub changes
Florian Zeitz <florob@babelmonkeys.de>
parents: 288
diff changeset
   126
	end
288
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   127
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   128
	for remotehost, session in pairs(host_session.s2sout) do
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   129
		if session.type ~= "s2sout_unauthed" then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   130
			add_host(session, "out");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   131
		end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   132
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   133
	for session in pairs(incoming_s2s) do
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   134
		if session.to_host == host then
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   135
			add_host(session, "in");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   136
		end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   137
	end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   138
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   139
	httpserver.new_from_config(http_conf, handle_file_request, { base = "admin" });
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   140
end
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   141
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   142
module:hook("s2sout-established", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   143
	add_host(event.session, "out");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   144
end);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   145
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   146
module:hook("s2sin-established", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   147
	add_host(event.session, "in");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   148
end);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   149
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   150
module:hook("s2sout-destroyed", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   151
	del_host(event.session, "out");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   152
end);
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   153
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   154
module:hook("s2sin-destroyed", function(event)
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   155
	del_host(event.session, "in");
9233d7ee3c09 mod_admin_web: Initial PoC commit
Florian Zeitz <florob@babelmonkeys.de>
parents:
diff changeset
   156
end);