Following is the js i am using to select route and bridge the call....<br><br><br>use("ODBC");<br><br>var DSN = "myodbc";<br>var DB_USER = "neo";<br>var DB_PASS = ".....";<br>
<br>var sql;<br><br>var prefix1;<br>var ip1;<br>var no2;<br><br>var bridge_str;<br><br>if(argv[0]=="")<br>exit();<br><br><br>if(argv[1]=="")<br>exit();<br><br><br>ip1 =argv[0].split("@")[1];<br>
<br><br>var no1=argv[1];<br><br>var sql = "SELECT id,prefix,name FROM internal_auth where substring('"+no1+"',1,length(prefix))=prefix and ip='" + ip1 +"' and active=1;";<br><br>
var authName="";<br><br>var db = new ODBC(DSN, DB_USER, DB_PASS);<br><br>db.connect();<br><br>db.query(sql);<br><br>if(db.nextRow()) {<br><br> var row = db.getData();<br> <br> if (row["id"] == "" ) {<br>
console_log("Err", "auth failed(0001)\t" + no1 + "\targ[0]=>" + argv[0] + "\targ[1]=>" + argv[1] + "\n"); <br> db.close();<br> exit();<br> }<br>
<br> prefix1=row["prefix"]; authName=row["name"];<br> <br>}else{<br> console_log("Err", "auth failed(0001)\t" + no1 + "\targ[0]=>" + argv[0] + "\targ[1]=>" + argv[1] + "\n"); <br>
db.close();<br> exit();<br> <br>}<br><br><br>no2=no1.substring(prefix1.length, no1.length);<br><br>sql = "SELECT ec.* FROM auth_routes_carriers arc,external_carriers ec, codes c where arc.external_carriers_id = <a href="http://ec.id">ec.id</a> and arc.code_id = <a href="http://c.id">c.id</a> and substring('"+no2+"',1,length(c.code))=c.code and ec.active=1 order by arc.priority asc";<br>
<br>db.connect();<br><br>db.query(sql);<br><br>var carriersName="";<br><br>bridge_str='';<br><br>while(db.nextRow()) {<br><br> var row = db.getData();<br> <br> if (row["id"] != "" ) {<br>
bridge_str = row["gateway"]+row["prefix"]+no2+"\@"+row["ip"]; <br> carriersName = row["name"];<br> break; <br> }<br><br>}<br><br>db.close();<br>
<br>if(bridge_str != ''){<br> if(session.ready()) session.execute("bridge", bridge_str); <br>}<br>else {<br> console_log("Err", "external carrier not found.\t" + no2 + "\targ[0]=>" + argv[0] + "\targ[1]=>" + argv[1] + "\n"); <br>
exit();<br>}<br><br><br>exit();<br><br><br><br>