parent
91f906b1ba
commit
5d5986e4dc
@ -0,0 +1,7 @@
|
||||
exports.Config = {directory: {
|
||||
dialString: "{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}",
|
||||
vmEnabled: true,
|
||||
userContext: "default",
|
||||
userGroup: "default",
|
||||
baseExtension: 10000
|
||||
}};
|
@ -0,0 +1,154 @@
|
||||
var sys = require("sys"),
|
||||
colors = require("colors"),
|
||||
http = require("http"),
|
||||
util = require("util"),
|
||||
querystring = require("querystring"),
|
||||
events = require("events"),
|
||||
hash = require("../modules/node-hash/lib/hash"),
|
||||
dateFormat = require("../modules/date.js").dateFormat,
|
||||
url = require("url"),
|
||||
colors = require("colors"),
|
||||
Configs = require("../configs.js");
|
||||
|
||||
var httpServer = function(responders) {
|
||||
var self = this;
|
||||
this.httpd = null;
|
||||
this.responders = responders;
|
||||
|
||||
events.EventEmitter.call(this);
|
||||
};
|
||||
|
||||
sys.inherits(httpServer, events.EventEmitter);
|
||||
exports.httpServer = httpServer;
|
||||
|
||||
httpServer.prototype.init = function() {
|
||||
var self = this;
|
||||
|
||||
self.httpd = http.createServer(function(request, response) {
|
||||
self.handlerResponse(request, response);
|
||||
})
|
||||
.addListener("error", function(error) {
|
||||
console.log("httpd crapped out");
|
||||
console.log(error);
|
||||
|
||||
self.emit("httpd:error", self);
|
||||
});
|
||||
|
||||
self.httpd.listen(Configs.httpd.port);
|
||||
|
||||
self.emit("httpd:binded", self);
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
httpServer.prototype.deinit = function() {
|
||||
var self = this;
|
||||
|
||||
self.httpd.close();
|
||||
};
|
||||
|
||||
httpServer.prototype.getResponder = function(decodedBody) {
|
||||
var self = this,
|
||||
responder = null,
|
||||
handler = null,
|
||||
selectorLen = 0;
|
||||
|
||||
|
||||
try {
|
||||
if (typeof decodedBody["section"] === "undefined") {
|
||||
throw "Invalid Request";
|
||||
}
|
||||
|
||||
if (typeof self.responders[decodedBody["section"].toLowerCase()] === "undefined") {
|
||||
throw "Invalid Bidings";
|
||||
} else {
|
||||
var bindings = decodedBody["section"].toLowerCase();
|
||||
}
|
||||
|
||||
for (entryName in self.responders[bindings]) {
|
||||
var entry = self.responders[decodedBody["section"]][entryName];
|
||||
|
||||
if (typeof entry.selector === "undefined") {
|
||||
continue;
|
||||
} else {
|
||||
for (handlerName in entry.selector) {
|
||||
if (Object.keys(entry.selector[handlerName]).length > selectorLen) {
|
||||
var ii = 0;
|
||||
for (selectorKey in entry.selector[handlerName]) {
|
||||
var match = false;
|
||||
switch (typeof entry.selector[handlerName][selectorKey]) {
|
||||
case "string":
|
||||
match = (decodedBody[selectorKey] === entry.selector[handlerName][selectorKey]);
|
||||
break;
|
||||
|
||||
case "boolean":
|
||||
match = (
|
||||
(entry.selector[handlerName][selectorKey] === true && decodedBody[selectorKey].length !== 0)
|
||||
|| (entry.selector[handlerName][selectorKey] === false && decodedBody[selectorKey].length === 0)
|
||||
);
|
||||
break;
|
||||
|
||||
case "object":
|
||||
case "function":
|
||||
if (entry.selector[handlerName][selectorKey] instanceof RegExp) {
|
||||
match = entry.selector[handlerName][selectorKey].test(decodedBody[selectorKey]);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if (match === true) {
|
||||
if (++ii === Object.keys(entry.selector[handlerName]).length) {
|
||||
selectorLen = Object.keys(entry.selector[handlerName]).length;
|
||||
responder = entry;
|
||||
handler = handlerName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log("Invalid request... " + err);
|
||||
}
|
||||
|
||||
console.log(util.inspect(decodedBody));
|
||||
if (responder !== null) {
|
||||
console.log(util.inspect(responder));
|
||||
return [responder, handler];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
httpServer.prototype.handlerResponse = function(request, response) {
|
||||
var self = this,
|
||||
fullBody = "";
|
||||
|
||||
request.on('data', function(chunk) {
|
||||
// append the current chunk of data to the fullBody variable
|
||||
fullBody += chunk.toString();
|
||||
});
|
||||
|
||||
request.on('end', function() {
|
||||
// parse the received body data
|
||||
var decodedBody = querystring.parse(fullBody);
|
||||
var responder = null;
|
||||
|
||||
if ((responder = self.getResponder(decodedBody)) !== null) {
|
||||
var cbReturn = function(responseData) {
|
||||
if (typeof responseData !== "undefined" && responseData !== null && responseData.length > 0) {
|
||||
response.writeHead(200, "OK", {'Content-Type': 'text/xml'});
|
||||
response.write(responseData, "ascii");
|
||||
}
|
||||
|
||||
response.end();
|
||||
};
|
||||
|
||||
responder[0][responder[1]](cbReturn, decodedBody);
|
||||
} else {
|
||||
response.end();
|
||||
}
|
||||
});
|
||||
};
|
@ -0,0 +1,46 @@
|
||||
var sys = require("sys"),
|
||||
ltx = require("../../modules/ltx/lib/index"),
|
||||
Configs = require("../../configs.js"),
|
||||
LDAPClient = require("../../modules/node-ldapsearch/build/default/ldap.node");
|
||||
|
||||
var followMe = function(parent) {
|
||||
this.selector = {
|
||||
"follow": {"Call-Direction": "inbound", "variable_direction": "inbound", "Caller-Context": "default", "Caller-Destination-Number": /^[1-6]{1}[0-9]{3,6}$/}
|
||||
};
|
||||
|
||||
this.follow = function(cbReturn, decodedBody) {
|
||||
var searchFilter = "(&("+ Configs.ldap.userKey +"="+ decodedBody["Caller-Destination-Number"] +")(mobile=*))";
|
||||
var searchUri = Configs.ldap.uri + Configs.ldap.users + searchFilter;
|
||||
|
||||
LDAPClient.Search(searchUri, function(error, result) {
|
||||
if (typeof error !== "undefined") {
|
||||
cbReturn(null);
|
||||
} else if (typeof result[0] !== "undefined") {
|
||||
var response = new ltx.Element("document", {"type":"freeswitch/xml"})
|
||||
.c("section", {"name":"dialplan", "description": "LDAP Follow Me"})
|
||||
.c("context", {"name":"default"})
|
||||
.c("extension", {"name":"inbound_ldap_lookup"})
|
||||
.c("condition", {"field":"destination_number", "expression":"/^"+ decodedBody["Caller-Destination-Number"] +"$/"})
|
||||
.c("action", {"application": "set", "data": "hangup_after_bridge=true"}).up()
|
||||
.c("action", {"application": "set", "data": "continue_on_fail=true"}).up()
|
||||
.c("action", {"application": "set", "data": "ignore_early_media=true"}).up()
|
||||
.c("action", {"application": "set", "data": "call_timeout=15"}).up()
|
||||
.c("action", {"application": "bridge", "data": "sofia/$${domain}/"+ decodedBody["Caller-Destination-Number"]}).up()
|
||||
.c("action", {"application": "set", "data": "call_timeout=15"}).up()
|
||||
.c("action", {"application": "bridge", "data": "sofia/gateway/"+ Configs.gatewayName +"/"+ result[0]["mobile"][0]}).up()
|
||||
.c("action", {"application": "answer"}).up()
|
||||
.c("action", {"application": "sleep", "data": "1000"}).up()
|
||||
.c("action", {"application": "voicemail", "data": "default $${domain} "+ decodedBody["Caller-Destination-Number"]}).up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up();
|
||||
|
||||
|
||||
cbReturn(response.toString());
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
exports.Responder = [followMe];
|
@ -0,0 +1,38 @@
|
||||
var sys = require("sys"),
|
||||
ltx = require("../../modules/ltx/lib/index"),
|
||||
Configs = require("../../configs.js"),
|
||||
LDAPClient = require("../../modules/node-ldapsearch/build/default/ldap.node");
|
||||
|
||||
var inboundLookup = function(parent) {
|
||||
this.selector = {
|
||||
"lookup": {"Call-Direction": "inbound", "variable_direction": "inbound", "Caller-Context": "public"}
|
||||
};
|
||||
|
||||
this.lookup = function(cbReturn, decodedBody) {
|
||||
var searchFilter = "(mobile="+ decodedBody["Caller-ANI"] +")";
|
||||
var searchUri = Configs.ldap.uri + Configs.ldap.users + searchFilter;
|
||||
|
||||
LDAPClient.Search(searchUri, function(error, result) {
|
||||
if (typeof error !== "undefined") {
|
||||
cbReturn(null);
|
||||
} else if (typeof result[0] !== "undefined") {
|
||||
var response = new ltx.Element("document", {"type":"freeswitch/xml"})
|
||||
.c("section", {"name":"dialplan", "description": "Inbound LDAP Lookup"})
|
||||
.c("context", {"name":"public"})
|
||||
.c("extension", {"name":"inbound_ldap_lookup"})
|
||||
.c("condition", {"field":"ani", "expression":"/^"+ decodedBody["Caller-ANI"] +"$/"})
|
||||
.c("action", {"application": "set", "data": "effective_caller_id_name="+ result[0]["givenName"][0]}).up()
|
||||
.c("action", {"application": "export", "data": "alert_info=Bellcore-r5"}).up()
|
||||
.c("action", {"application": "transfer", "data": Configs.inboundDestination}).up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up();
|
||||
|
||||
cbReturn(response.toString());
|
||||
}
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
exports.Responder = [inboundLookup];
|
@ -0,0 +1,135 @@
|
||||
var sys = require("sys"),
|
||||
ltx = require("../../modules/ltx/lib/index"),
|
||||
Configs = require("../../configs.js"),
|
||||
LDAPClient = require("../../modules/node-ldapsearch/build/default/ldap.node");
|
||||
|
||||
var ldap = function(parent) {
|
||||
this.selector = {
|
||||
"startup": {"tag_name": false, "Event-Name": "REQUEST_PARAMS"},
|
||||
"auth": {"tag_name": "domain", "Event-Name": "REQUEST_PARAMS", "action": "sip_auth", "Event-Calling-Function": "sofia_reg_parse_auth", "user": /^[1-9]{1}[0-9]{3,6}$/},
|
||||
"mailbox": {"tag_name": "domain", "Event-Name": "GENERAL", "Event-Calling-Function": /^(resolve_id|voicemail_check_main)$/, "user": /^[1-9]{1}[0-9]{3,6}$/},
|
||||
"user": {"tag_name": "domain", "Event-Name": "REQUEST_PARAMS", "action": "user_call", "Event-Calling-Function": "user_outgoing_channel", "user": /^[1-9]{1}[0-9]{3,6}$/}
|
||||
};
|
||||
|
||||
this.startup = function(cbReturn, decodedBody) {
|
||||
var response = new ltx.Element("document", {"type":"freeswitch/xml"})
|
||||
.c("section", {"name":"directory", "description":"Dynamic User Directory"})
|
||||
.c("domain", {"name":"$${domain}"})
|
||||
.c("params")
|
||||
.c("param", {"name":"dial-string", "value": "{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"}).up()
|
||||
.up()
|
||||
.up()
|
||||
.up();
|
||||
|
||||
cbReturn(response.toString());
|
||||
};
|
||||
|
||||
this.auth = function(cbReturn, decodedBody) {
|
||||
var searchFilter = "("+ Configs.ldap.userKey +"="+ decodedBody["user"] +")";
|
||||
var searchUri = Configs.ldap.uri + Configs.ldap.users + searchFilter;
|
||||
|
||||
LDAPClient.Search(searchUri, function(error, result) {
|
||||
if (typeof error !== "undefined") {
|
||||
cbReturn(null);
|
||||
} else if (typeof result[0] !== "undefined") {
|
||||
var response = new ltx.Element("document", {"type":"freeswitch/xml"})
|
||||
.c("section", {"name":"directory", "description":"Dynamic User Directory"})
|
||||
.c("domain", {"name":"$${domain}"})
|
||||
.c("params")
|
||||
.c("param", {"name":"dial-string", "value": "{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"}).up()
|
||||
.up()
|
||||
.c("groups")
|
||||
.c("group", {"name":"default"})
|
||||
.c("users")
|
||||
.c("user", {"id":decodedBody["user"]})
|
||||
.c("params")
|
||||
.c("param", {"name":"password", "value":result[0][Configs.ldap.sipPassword][0]}).up()
|
||||
.c("param", {"name":"vm-password", "value":result[0][Configs.ldap.vmPassword][0]}).up()
|
||||
.c("param", {"name":"vm-enabled", "value":"true"}).up()
|
||||
.up()
|
||||
.c("variables")
|
||||
.c("variable", {"name":"toll_allow", "value":""}).up()
|
||||
.c("variable", {"name":"accountcode", "value":decodedBody["user"]}).up()
|
||||
.c("variable", {"name":"user_context", "value":"default"}).up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up();
|
||||
|
||||
cbReturn(response.toString());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.mailbox = function(cbReturn, decodedBody) {
|
||||
var searchFilter = "("+ Configs.ldap.userKey +"="+ decodedBody["user"] +")";
|
||||
var searchUri = Configs.ldap.uri + Configs.ldap.users + searchFilter;
|
||||
|
||||
LDAPClient.Search(searchUri, function(error, result) {
|
||||
if (typeof error !== "undefined") {
|
||||
cbReturn(null);
|
||||
} else if (typeof result[0] !== "undefined") {
|
||||
|
||||
var response = new ltx.Element("document", {"type":"freeswitch/xml"})
|
||||
.c("section", {"name":"directory", "description":"Dynamic User Directory"})
|
||||
.c("domain", {"name":"$${domain}"})
|
||||
.c("params")
|
||||
.c("param", {"name":"dial-string", "value": "{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"}).up()
|
||||
.up()
|
||||
.c("groups")
|
||||
.c("group", {"name":"default"})
|
||||
.c("users")
|
||||
.c("user", {"id":decodedBody["user"]})
|
||||
.c("params")
|
||||
.c("param", {"name":"password", "value":result[0][Configs.ldap.sipPassword][0]}).up()
|
||||
.c("param", {"name":"vm-password", "value":result[0][Configs.ldap.vmPassword][0]}).up()
|
||||
.c("param", {"name":"vm-enabled", "value":"true"}).up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up();
|
||||
|
||||
cbReturn(response.toString());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
this.user = function(cbReturn, decodedBody) {
|
||||
var searchFilter = "("+ Configs.ldap.userKey +"="+ decodedBody["user"] +")";
|
||||
var searchUri = Configs.ldap.uri + Configs.ldap.users + searchFilter;
|
||||
|
||||
LDAPClient.Search(searchUri, function(error, result) {
|
||||
if (typeof error !== "undefined") {
|
||||
cbReturn(null);
|
||||
} else if (typeof result[0] !== "undefined") {
|
||||
|
||||
var response = new ltx.Element("document", {"type":"freeswitch/xml"})
|
||||
.c("section", {"name":"directory", "description":"Dynamic User Directory"})
|
||||
.c("domain", {"name":"$${domain}"})
|
||||
.c("params")
|
||||
.c("param", {"name":"dial-string", "value": "{presence_id=${dialed_user}@${dialed_domain}}${sofia_contact(${dialed_user}@${dialed_domain})}"}).up()
|
||||
.up()
|
||||
.c("groups")
|
||||
.c("group", {"name":"default"})
|
||||
.c("users")
|
||||
.c("user", {"id":decodedBody["user"]}).up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up()
|
||||
.up();
|
||||
|
||||
cbReturn(response.toString());
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
exports.Responder = [ldap];
|
Loading…
Reference in new issue