Software /
code /
prosody
Annotate
core/hostmanager.lua @ 1770:3e17002221eb
mod_httpserver: Backport from trunk more thorough validation of URLs prior to processing
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 11 Sep 2009 03:12:09 +0100 |
parent | 1614:951ed38ad64f |
child | 1848:0033359aeb70 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
1 -- Prosody IM |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
4 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1467
diff
changeset
|
8 |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local hosts = hosts; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local configmanager = require "core.configmanager"; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local eventmanager = require "core.eventmanager"; |
1188 | 13 local events_new = require "util.events".new; |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 |
575
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
15 local log = require "util.logger".init("hostmanager"); |
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
16 |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 local pairs = pairs; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 module "hostmanager" |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
1095
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
21 local hosts_loaded_once; |
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
22 |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 local function load_enabled_hosts(config) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 local defined_hosts = config or configmanager.getconfig(); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 for host, host_config in pairs(defined_hosts) do |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 if host ~= "*" and (host_config.core.enabled == nil or host_config.core.enabled) then |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 activate(host, host_config); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 end |
749
1359492f45d7
hostmanager: Fire event when all hosts are loaded from config
Matthew Wild <mwild1@gmail.com>
parents:
575
diff
changeset
|
31 eventmanager.fire_event("hosts-activated", defined_hosts); |
1095
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
32 hosts_loaded_once = true; |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 eventmanager.add_event_hook("server-starting", load_enabled_hosts); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 function activate(host, host_config) |
1467
fc420e9585c2
hostmanager: Add disallow_s2s to config, defaults to false unless anonymous_login is enabled, then defaults to true
Matthew Wild <mwild1@gmail.com>
parents:
1188
diff
changeset
|
38 hosts[host] = {type = "local", connected = true, sessions = {}, |
fc420e9585c2
hostmanager: Add disallow_s2s to config, defaults to false unless anonymous_login is enabled, then defaults to true
Matthew Wild <mwild1@gmail.com>
parents:
1188
diff
changeset
|
39 host = host, s2sout = {}, events = events_new(), |
fc420e9585c2
hostmanager: Add disallow_s2s to config, defaults to false unless anonymous_login is enabled, then defaults to true
Matthew Wild <mwild1@gmail.com>
parents:
1188
diff
changeset
|
40 disallow_s2s = configmanager.get(host, "core", "disallow_s2s") |
fc420e9585c2
hostmanager: Add disallow_s2s to config, defaults to false unless anonymous_login is enabled, then defaults to true
Matthew Wild <mwild1@gmail.com>
parents:
1188
diff
changeset
|
41 or (configmanager.get(host, "core", "anonymous_login") |
fc420e9585c2
hostmanager: Add disallow_s2s to config, defaults to false unless anonymous_login is enabled, then defaults to true
Matthew Wild <mwild1@gmail.com>
parents:
1188
diff
changeset
|
42 and (configmanager.get(host, "core", "disallow_s2s") ~= false)) |
fc420e9585c2
hostmanager: Add disallow_s2s to config, defaults to false unless anonymous_login is enabled, then defaults to true
Matthew Wild <mwild1@gmail.com>
parents:
1188
diff
changeset
|
43 }; |
1614
951ed38ad64f
hostmanager: Warn when user puts port configuration under vhost section
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
44 for option_name in pairs(host_config.core) do |
951ed38ad64f
hostmanager: Warn when user puts port configuration under vhost section
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
45 if option_name:match("_ports$") then |
951ed38ad64f
hostmanager: Warn when user puts port configuration under vhost section
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
46 log("warn", "%s: Option '%s' has no effect for virtual hosts - put it in global Host \"*\" instead", host, option_name); |
951ed38ad64f
hostmanager: Warn when user puts port configuration under vhost section
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
47 end |
951ed38ad64f
hostmanager: Warn when user puts port configuration under vhost section
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
48 end |
1095
cad4205f4925
hostmanager: Reduce log output at startup to 'debug'
Matthew Wild <mwild1@gmail.com>
parents:
749
diff
changeset
|
49 log((hosts_loaded_once and "info") or "debug", "Activated host: %s", host); |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 eventmanager.fire_event("host-activated", host, host_config); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 function deactivate(host) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 local host_session = hosts[host]; |
575
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
55 log("info", "Deactivating host: %s", host); |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 eventmanager.fire_event("host-deactivating", host, host_session); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 -- Disconnect local users, s2s connections |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 for user, session_list in pairs(host_session.sessions) do |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 for resource, session in pairs(session_list) do |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 session:close("host-gone"); |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 -- Components? |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 hosts[host] = nil; |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 eventmanager.fire_event("host-deactivated", host); |
575
428c951d0a33
Log in hostmanager when a vhost is activated/deactivated
Matthew Wild <mwild1@gmail.com>
parents:
569
diff
changeset
|
68 log("info", "Deactivated host: %s", host); |
569
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 function getconfig(name) |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 end |
5216efe6088b
Add hostmanager, and eventmanager
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 |