diff options
-rw-r--r-- | plugins/mod_httpserver.lua | 4 | ||||
-rw-r--r-- | prosody.cfg.lua.dist | 30 | ||||
-rwxr-xr-x | prosodyctl | 25 | ||||
-rw-r--r-- | util-src/signal.c | 2 | ||||
-rw-r--r-- | util/events.lua | 8 | ||||
-rw-r--r-- | util/sasl_cyrus.lua | 23 |
6 files changed, 62 insertions, 30 deletions
diff --git a/plugins/mod_httpserver.lua b/plugins/mod_httpserver.lua index 1cdcc787..07c7f315 100644 --- a/plugins/mod_httpserver.lua +++ b/plugins/mod_httpserver.lua @@ -15,6 +15,7 @@ local t_concat = table.concat; local http_base = config.get("*", "core", "http_path") or "www_files"; local response_400 = { status = "400 Bad Request", body = "<h1>Bad Request</h1>Sorry, we didn't understand your request :(" }; +local response_403 = { status = "403 Forbidden", body = "<h1>Forbidden</h1>You don't have permission to view the contents of this directory :(" }; local response_404 = { status = "404 Not Found", body = "<h1>Page Not Found</h1>Sorry, we couldn't find what you were looking for :(" }; -- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?) @@ -51,6 +52,9 @@ function serve_file(path) if not f then return response_404; end local data = f:read("*a"); f:close(); + if not data then + return response_403; + end local ext = path:match("%.([^.]*)$"); local mime = mime_map[ext]; -- Content-Type should be nil when not known return { diff --git a/prosody.cfg.lua.dist b/prosody.cfg.lua.dist index d660a9bd..de07d7c5 100644 --- a/prosody.cfg.lua.dist +++ b/prosody.cfg.lua.dist @@ -1,38 +1,38 @@ --- Prosody Example Configuration File +-- Prosody Example Configuration File -- --- If it wasn't already obvious, -- starts a comment, and all +-- If it wasn't already obvious, -- starts a comment, and all -- text after it on a line is ignored by Prosody. -- --- The config is split into sections, a global section, and one --- for each defined host that we serve. You can add as many host +-- The config is split into sections, a global section, and one +-- for each defined host that we serve. You can add as many host -- sections as you like. -- --- Lists are written { "like", "this", "one" } --- Lists can also be of { 1, 2, 3 } numbers, and other things. +-- Lists are written { "like", "this", "one" } +-- Lists can also be of { 1, 2, 3 } numbers, and other things. -- Either commas, or semi-colons; may be used -- as seperators. -- --- A table is a list of values, except each value has a name. An +-- A table is a list of values, except each value has a name. An -- example table would be: -- -- ssl = { key = "keyfile.key", certificate = "certificate.cert" } -- --- Whitespace (that is tabs, spaces, line breaks) is mostly insignificant, so --- can +-- Whitespace (that is tabs, spaces, line breaks) is mostly insignificant, so +-- can -- be placed anywhere that you deem fitting. -- -- Tip: You can check that the syntax of this file is correct when you have finished -- by running: luac -p prosody.cfg.lua --- If there are any errors, it will let you know what and where they are, otherwise it +-- If there are any errors, it will let you know what and where they are, otherwise it -- will keep quiet. -- --- The only thing left to do is rename this file to remove the .dist ending, and fill in the +-- The only thing left to do is rename this file to remove the .dist ending, and fill in the -- blanks. Good luck, and happy Jabbering! -- Server-wide settings go in this section Host "*" - -- This is a (by default, empty) list of accounts that are admins + -- This is a (by default, empty) list of accounts that are admins -- for the server. Note that you must create the accounts separately -- (see http://prosody.im/doc/creating_accounts for info) -- Example: admins = { "user1@example.com", "user2@example.net" } @@ -63,7 +63,7 @@ Host "*" -- Other specific functionality --"posix"; -- POSIX functionality, sends server to background, enables syslog, etc. - --"console"; -- telnet to port 5582 (needs console_enabled = true) + --"console"; -- Opens admin telnet interface on localhost port 5582 --"bosh"; -- Enable BOSH clients, aka "Jabber over HTTP" --"httpserver"; -- Serve static files from a directory over HTTP }; @@ -83,7 +83,7 @@ Host "*" -- These are the SSL/TLS-related settings. If you don't want -- to use SSL/TLS, you may comment or remove this - ssl = { + ssl = { key = "certs/localhost.key"; certificate = "certs/localhost.cert"; } @@ -101,7 +101,7 @@ Host "example.com" -- set in the global section (if any). -- Note that old-style SSL on port 5223 only supports one certificate, and will always -- use the global one. - ssl = { + ssl = { key = "certs/example.com.key"; certificate = "certs/example.com.crt"; } @@ -137,18 +137,33 @@ function show_usage(usage, desc) end local function getchar(n) - os.execute("stty raw -echo"); - local ok, char = pcall(io.read, n or 1); - os.execute("stty sane"); + local stty_ret = os.execute("stty raw -echo 2>/dev/null"); + local ok, char; + if stty_ret == 0 then + ok, char = pcall(io.read, n or 1); + os.execute("stty sane"); + else + ok, char = pcall(io.read, "*l"); + if ok then + char = char:sub(1, n or 1); + end + end if ok then return char; end end local function getpass() - os.execute("stty -echo"); + local stty_ret = os.execute("stty -echo 2>/dev/null"); + if stty_ret ~= 0 then + io.write("\027[08m"); -- ANSI 'hidden' text attribute + end local ok, pass = pcall(io.read, "*l"); - os.execute("stty sane"); + if stty_ret == 0 then + os.execute("stty sane"); + else + io.write("\027[00m"); + end io.write("\n"); if ok then return pass; diff --git a/util-src/signal.c b/util-src/signal.c index 30975508..447c1c16 100644 --- a/util-src/signal.c +++ b/util-src/signal.c @@ -1,5 +1,5 @@ /* - * lsignal.h -- Signal Handler Library for Lua + * signal.c -- Signal Handler Library for Lua * * Version: 1.000 * diff --git a/util/events.lua b/util/events.lua index a1edd496..ef8fc30a 100644 --- a/util/events.lua +++ b/util/events.lua @@ -47,13 +47,13 @@ function new() _rebuild_index(event); end end; - local function add_plugin(plugin) - for event, handler in pairs(plugin) do + local function add_handlers(handlers) + for event, handler in pairs(handlers) do add_handler(event, handler); end end; - local function remove_plugin(plugin) - for event, handler in pairs(plugin) do + local function remove_handlers(handlers) + for event, handler in pairs(handlers) do remove_handler(event, handler); end end; diff --git a/util/sasl_cyrus.lua b/util/sasl_cyrus.lua index 7e689f62..b42bee07 100644 --- a/util/sasl_cyrus.lua +++ b/util/sasl_cyrus.lua @@ -31,12 +31,25 @@ module "sasl_cyrus" local method = {}; method.__index = method; - -pcall(cyrussasl.server_init, "prosody") +local initialized = false; + +local function init(service_name) + if not initialized then + local st, errmsg = pcall(cyrussasl.server_init, service_name); + if st then + initialized = true; + else + log("error", "Failed to initialize CyrusSASL: %s", errmsg); + end + end +end -- create a new SASL object which can be used to authenticate clients function new(realm, service_name) local sasl_i = {}; + + init(service_name); + sasl_i.realm = realm; sasl_i.service_name = service_name; sasl_i.cyrus = cyrussasl.server_new(service_name, nil, nil, nil, nil) @@ -64,17 +77,17 @@ end function method:mechanisms() local mechanisms = {} local cyrus_mechs = cyrussasl.listmech(self.cyrus, nil, "", " ", "") - for w in s_gmatch(cyrus_mechs, "%a+") do + for w in s_gmatch(cyrus_mechs, "[^ ]+") do mechanisms[w] = true; end - self.mechanisms = mechanisms + self.mechs = mechanisms return array.collect(keys(mechanisms)); end -- select a mechanism to use function method:select(mechanism) self.mechanism = mechanism; - return self.mechanisms[mechanism]; + return self.mechs[mechanism]; end -- feed new messages to process into the library |