Skip to content

Commit

Permalink
Change around so config is loaded when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Sergeant committed Dec 3, 2013
1 parent e520a33 commit b2fb0e9
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions plugins/relay_force_routing.js
Expand Up @@ -2,30 +2,25 @@


// documentation via: haraka -h plugins/relay_force_routing // documentation via: haraka -h plugins/relay_force_routing


exports.register = function() { exports.hook_get_mx = function (next, hmail, domain) {
this.register_hook('get_mx', 'force_routing'); var domain_ini = this.config.get('relay_dest_domains.ini', 'ini');
this.domain_ini = this.config.get('relay_dest_domains.ini', 'ini'); var force_route = lookup_routing(domain_ini['domains'], domain);
};

exports.force_routing = function (next, hmail, domain) {
var force_route = lookup_routing(this, this.domain_ini['domains'], domain);
if (force_route != "NOTFOUND" ){ if (force_route != "NOTFOUND" ){
this.logdebug(this, 'using ' + force_route + ' for ' + domain); this.logdebug('using ' + force_route + ' for: ' + domain);
next(OK, force_route); next(OK, force_route);
} else { } else {
this.logdebug(this, 'using normal MX lookup' + ' for ' + domain); this.logdebug('using normal MX lookup for: ' + domain);
next(CONT); next(CONT);
} }
}; }


/** /**
* @return {string} * @return {string}
*/ */


function lookup_routing (plugin, domains_ini, domain) { function lookup_routing (domains_ini, domain) {
if (domain in domains_ini) { if (domain in domains_ini) {
var config = JSON.parse(domains_ini[domain]); var config = JSON.parse(domains_ini[domain]);
plugin.logdebug(plugin, 'found config for' + domain + ': ' + domains_ini['nexthop']);
return config['nexthop']; return config['nexthop'];
} }
return "NOTFOUND"; return "NOTFOUND";
Expand Down

0 comments on commit b2fb0e9

Please sign in to comment.