commit afa76c93067c66cdb60e220b997c2c99350c9490 Author: moparisthebest Date: Sat Nov 21 00:01:54 2015 -0500 Initial Commit diff --git a/README.markdown b/README.markdown new file mode 100644 index 0000000..ecc2732 --- /dev/null +++ b/README.markdown @@ -0,0 +1,57 @@ +--- +summary: Point alias accounts or domains to correct XMPP user +... + +Introduction +============ + +This module allows you to set up aliases that alert people who try to +contact them or add them to their roster what your actual JID is. This +is useful for changing JIDs, or just in the case where you own both +example.com and example.net, and want people who contact you@example.com +to be alerted to contact you at you@example.net instead. + +This type of aliasing is well supported in the email world, but very hard +to handle with XMPP, this module sidesteps all the hard problems by just +sending the user a helpful message, requiring humans to decide what they +actually want to do. + +This doesn't require any special support on other clients or servers, +just the ability to recieve messages. + +Configuration +============= + +Add the module to the `modules_enabled` list. + + modules_enabled = { + ... + "alias"; + } + +Then set up your list of aliases, aliases can be full or bare JIDs, +or hosts: + + aliases = { + ["old@example.net"] = "new@example.net"; + ["you@example.com"] = "you@example.net"; + ["conference.example.com"] = "conference.example.net"; + } + +You can also set up a custom response, by default it is: + + alias_response = "User $alias can be contacted at $target"; + +A script named mod_alias_postfixadmin.sh is included in this directory to +generate the aliases array directly from a postfixadmin MySQL database. +Instructions for use are included in the script. + +Compatibility +============= + + ------- -------------- + trunk Works + 0.10 Works + 0.9 Unknown + 0.8 Unknown + ------- -------------- diff --git a/mod_alias.lua b/mod_alias.lua new file mode 100644 index 0000000..5486513 --- /dev/null +++ b/mod_alias.lua @@ -0,0 +1,43 @@ +-- Copyright (C) 2015 Travis Burtrum +-- This file is MIT/X11 licensed. + +-- set like so in prosody config, works on full or bare jids, or hosts: +--aliases = { +-- ["old@example.net"] = "new@example.net"; +-- ["you@example.com"] = "you@example.net"; +-- ["conference.example.com"] = "conference.example.net"; +--} + +local aliases = module:get_option("aliases", {}); +local alias_response = module:get_option("alias_response", "User $alias can be contacted at $target"); + +local st = require "util.stanza"; + +function handle_alias(event) + + if event.stanza.attr.type ~= "error" then + local alias = event.stanza.attr.to; + local target = aliases[alias]; + if target then + local replacements = { + alias = alias, + target = target + }; + local error_message = alias_response:gsub("%$([%w_]+)", function (v) + return replacements[v] or nil; + end); + local message = st.message{ type = "chat", from = alias, to = event.stanza.attr.from }:tag("body"):text(error_message); + module:send(message); + return event.origin.send(st.error_reply(event.stanza, "cancel", "gone", error_message)); + end + end + +end + +module:hook("message/bare", handle_alias, 300); +module:hook("message/full", handle_alias, 300); +module:hook("message/host", handle_alias, 300); + +module:hook("presence/bare", handle_alias, 300); +module:hook("presence/full", handle_alias, 300); +module:hook("presence/host", handle_alias, 300); diff --git a/mod_alias_postfixadmin.sh b/mod_alias_postfixadmin.sh new file mode 100755 index 0000000..ea9f358 --- /dev/null +++ b/mod_alias_postfixadmin.sh @@ -0,0 +1,20 @@ +#!/bin/sh +# Copyright (C) 2015 Travis Burtrum +# This file is MIT/X11 licensed. + +# run like ./mod_alias_postfixadmin.sh "mysql -N -upostfixadmin -ppostfixadmin postfixadmin" > /etc/prosody/aliases.cfg.lua +# then put: +# Include "aliases.cfg.lua" +# in prosody.cfg.lua + +mysql="$1" + +echo "-- alias plugin, generated by mod_alias_postfixadmin.sh" +echo "aliases = {" + +echo "SELECT concat('["'"'"', address, '"'"'"] = "'"'"', goto, '"'"'";') FROM alias WHERE address != goto; +SELECT concat('["'"'"', address, '"'"'"] = "'"'"', goto, '"'"'";') FROM ( + select replace(address, concat('@', target_domain), concat('@', alias_domain)) as address, goto FROM alias JOIN alias_domain ON alias_domain.target_domain = SUBSTRING(alias.address, locate('@',alias.address) + 1, length(alias.address)) +) a WHERE a.address != a.goto;" | $mysql | sort | uniq + +echo "}"