rbrindley: branch rbrindley/astman_revamp r4596 - /team/rbrindley/astman_reva...
SVN commits to the Asterisk-GUI project
asterisk-gui-commits at lists.digium.com
Tue Mar 10 14:28:29 CDT 2009
Author: rbrindley
Date: Tue Mar 10 14:28:26 2009
New Revision: 4596
URL: http://svn.digium.com/svn-view/asterisk-gui?view=rev&rev=4596
Log:
- implemented pbx.trunks.add, replacing: astgui_managetrunks.{addAnalogTrunk, addIAXTrunk, addSIPTrunk}
Modified:
team/rbrindley/astman_revamp/config/js/pbx2.js
Modified: team/rbrindley/astman_revamp/config/js/pbx2.js
URL: http://svn.digium.com/svn-view/asterisk-gui/team/rbrindley/astman_revamp/config/js/pbx2.js?view=diff&rev=4596&r1=4595&r2=4596
==============================================================================
--- team/rbrindley/astman_revamp/config/js/pbx2.js (original)
+++ team/rbrindley/astman_revamp/config/js/pbx2.js Tue Mar 10 14:28:26 2009
@@ -182,6 +182,138 @@
};
/**
+ * Add a trunk.
+ * @param type type of trunk.
+ * @param trunk trunk object.
+ * @param callback the callback function
+ * @param basis IAX/SIP, basis of trunk addition.
+ * @return boolean on success.
+ */
+pbx.trunks.add = function(type, trunk, callback, basis) {
+ var chans;
+ var ct = '';
+ var group = '';
+ var name = trunk.username;
+
+ /* The first thing we must do is verify required vars and
+ * do some general prep work depending on type */
+ switch(type) {
+ case 'analog':
+ if (!trunk.hasOwnProperty('zapchan') && !trunk.hasOwnProperty('dahdichan')) {
+ top.log.error('pbx.trunks.add: required variable zapchan/dahdichan not found.');
+ return false;
+ }
+
+ chans = trunk.zapchan || trunk.dahdichan;
+ delete trunk.zapchan;
+ delete trunk.dahdichan;
+
+ name = astgui_managetrunks.misc.nextAvailableTrunk_x();
+ group = astgui_managetrunks.misc.nextAvailableGroup();
+
+ trunk.signalling = '';
+ trunk.channel = '';
+ var zap_channels = ASTGUI.miscFunctions.chanStringtoArray(chans);
+ zap_channels.each(function(ch) {
+ var ls = ASTGUI.cloneObject(sessionData.PORTS_SIGNALLING.ls);
+ var sg = (ls.contains(ch)) ? 'fxs_ls' : 'fxs_ks';
+ });
+
+ break;
+ case 'iax':
+ case 'sip':
+ if (!trunk.hasOwnProperty('host')) {
+ top.log.error('pbx.trunks.add: required variable host not found.');
+ return false;
+ }
+
+ if (basis === 'GUIAssigned') {
+ name = astgui_managetrunks.misc.nextAvailableTrunk_x();
+ } else if (basic === 'FromProvider') {
+ name = trunk.trunkname;
+ }
+ break;
+ default:
+ break;
+ }
+
+ if (name === '') {
+ top.log.error('pbx.trunks.add: expected name to be defined.');
+ return false;
+ }
+ ct = ASTGUI.contexts.TrunkDIDPrefix + name;
+
+ /* Now, lets set some defaults for the essentials */
+ trunk.allow = 'all';
+ trunk.context = ct || '';
+ trunk.disallow = 'all';
+ trunk.group = group || null;
+ //DahdiChannelString ???
+ trunk.hasexten = 'no';
+ trunk.hasiax = trunk.hasiax || 'no';
+ trunk.hassip = trunk.hassip || 'no';
+ trunk.registeriax = trunk.hasiax || 'no'; /* same conditions as hasiax */
+ trunk.registersip = (trunk.host === 'dynamic' && trunk.hassip) ? 'no' : 'yes';
+ trunk.trunkname = (trunk.trunkname) ? trunk.trunkname.guiMetaData() : '';
+ trunk.trunkstyle = (type === 'analog') ? type.guiMetaData() : 'voip'.guiMetaData();
+
+ /* Initializing astman interactions */
+ var users_conf = new listOfActions();
+ users_conf.filename('users.conf');
+
+ users_conf.new_action('delcat', name, '', ''); /* for good measure :) */
+ users_conf.new_action('newcat', name, '', '');
+
+ /* now, lets iterate thru and append to the trunk context! */
+ for (var v in trunk) {
+ if (!trunk.hasOwnProperty(v)) {
+ continue;
+ }
+
+ sessionData.pbxinfo.trunks[type][name][v] = trunk[v];
+ users_conf.new_action('append', name, v, trunk[v]);
+ }
+
+ var resp = users_conf.callActions();
+
+ /* Not good! an error!! */
+ if (!resp.contains('Response: Success')) {
+ top.log.error('pbx.trunks.add: error adding trunk to users.conf');
+ top.log.error(resp);
+ delete sessionData.pbxinfo.trunks[type][name];
+ return false;
+ }
+
+ /* users.conf changes down, now to add to extensions.conf */
+ var ext_conf = new listOfSynActions('extensions.conf');
+
+ ext_conf.new_action('delcat', ct, '', ''); /* for good measure :) 2.0 */
+ ext_conf.new_action('newcat', ct, '', '');
+ ext_conf.new_action('delcat', ct + ASTGUI.contexts.TrunkDefaultSuffix, '' ,'');
+ ext_conf.new_action('newcat', ct + ASTGUI.contexts.TrunkDefaultSuffix, '', '');
+ ext_conf.new_action('append', ct, 'include', ct + ASTGUI.contexts.TrunkDefaultSuffix);
+ ext_conf.new_action('update', 'globals', trunk, this.technology[type] + '/' + name);
+
+ resp = '';
+ resp = ext_conf.callActions();
+
+ /* Not good! an error!! */
+ if (!resp.contains('Response: Success')) {
+ top.log.error('pbx.trunks.add: error adding trunk to extensions.conf');
+ top.log.error(resp);
+
+ users_conf.clearActions();
+ users_conf.new_action('delcat', name, '', '');
+ users_conf.callActions(); /* Not going to bother catching errors */
+
+ delete sessionData.pbxinfo.trunks[type][name];
+ return false;
+ }
+
+ callback();
+};
+
+/**
* Get Trunk Details.
* @param trunk
* @return an object with the trunk details, or null.
More information about the asterisk-gui-commits
mailing list