if meetme.OPTIONS_COMMON['musiconhold'] in options: agi.set_variable('CHANNEL(musicclass)', meetme.get_option_by_flag('musiconhold', flag)) if meetme.OPTIONS_COMMON['enableexitcontext'] in options: exitcontext = meetme.get_option_by_flag('exitcontext', flag) else: exitcontext = "" if meetme.preprocess_subroutine: preprocess_subroutine = meetme.preprocess_subroutine else: preprocess_subroutine = "" agi.set_variable('MEETME_EXIT_CONTEXT', exitcontext) agi.set_variable( 'MEETME_RECORDINGFILE', MEETME_RECORDINGDIR + "meetme-%s-%s" % (meetme.confno, int(time.time()))) agi.set_variable('XIVO_REAL_NUMBER', meetme.number) agi.set_variable('XIVO_REAL_CONTEXT', meetme.context) agi.set_variable('XIVO_MEETMECONFNO', meetme.confno) agi.set_variable('XIVO_MEETMENAME', meetme.name) agi.set_variable('XIVO_MEETMENUMBER', meetme.number) agi.set_variable('XIVO_MEETMEPIN', pin) agi.set_variable('XIVO_MEETMEOPTIONS', options) agi.set_variable('XIVO_MEETMEPREPROCESS_SUBROUTINE', preprocess_subroutine) agid.register(incoming_meetme_set_features)
if srcnum in (None, ''): agi.dp_break("Unable to find srcnum, srcnum = %r" % srcnum) if not spooldir: agi.dp_break("Unable to fetch AST_SPOOL_DIR") mtime = time.time() + 5 filepath = "%s/%%s/%s-%s.call" % (spooldir, srcnum, int(mtime)) tmpfile = filepath % "tmp" realfile = filepath % "outgoing" f = open(tmpfile, 'w') f.write("Channel: Local/%s@%s\n" "MaxRetries: 0\n" "RetryTime: 30\n" "WaitTime: 30\n" "CallerID: %s\n" "Set: XIVO_DISACONTEXT=%s\n" "Context: xivo-callbackdisa\n" "Extension: s" % (srcnum, context, srcnum, context)) f.close() os.utime(tmpfile, (mtime, mtime)) os.chown(tmpfile, ASTERISK_UID, ASTERISK_GID) os.rename(tmpfile, realfile) agid.register(callback)
__license__ = """ Copyright (C) 2006-2010 Proformatique <*****@*****.**> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid from xivo_agid import objects def schedule(agi, cursor, args): try: sched = objects.Schedule(agi, cursor, int(args[0])) except (ValueError, LookupError), e: agi.dp_break(str(e)) agi.set_variable("XIVO_SCHEDULE_TIMERANGE", sched.timerange) sched.set_dial_actions() agid.register(schedule)
f.write( "Channel: Local/%s\n" "MaxRetries: %d\n" "RetryTime: %d\n" "WaitTime: %d\n" "CallerID: %s\n" "Context: %s\n" "Extension: %s\n" "Priority: 1\n" % (srcnum, max_retries, retry_time, wait_time, srcnum, context, dstnum)) f.close() os.utime(tmpfile, (mtime, mtime)) os.chown(tmpfile, ASTERISK_UID, ASTERISK_GID) os.rename(tmpfile, realfile) def setup(cursor): global max_retries global retry_time global wait_time config = ConfigParser.RawConfigParser() config.readfp(open(CONFIG_FILE)) max_retries = config.getint('general', 'max_retries') retry_time = config.getint('general', 'retry_time') wait_time = config.getint('general', 'wait_time') agid.register(callback_on_congestion, setup)
# -*- coding: utf-8 -*- # Copyright (C) 2006-2014 Avencall # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> from xivo_agid import agid from xivo_agid.handlers.userfeatures import UserFeatures def incoming_user_set_features(agi, cursor, args): userfeatures_handler = UserFeatures(agi, cursor, args) userfeatures_handler.execute() agid.register(incoming_user_set_features)
cursor, mailbox=args[0], context=context) except (ValueError, LookupError), e: agi.dp_break(str(e)) else: try: vmbox = objects.VMBox(agi, cursor, int(vmboxid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) if vmbox and vmbox.skipcheckpass: vmmain_options = "s" else: vmmain_options = "" if caller and caller.language: mbox_lang = caller.language elif vmbox and vmbox.language: mbox_lang = vmbox.language else: mbox_lang = '' agi.set_variable('XIVO_VMMAIN_OPTIONS', vmmain_options) agi.set_variable('XIVO_MAILBOX', vmbox.mailbox) agi.set_variable('XIVO_MAILBOX_CONTEXT', vmbox.context) agi.set_variable('XIVO_MAILBOX_LANGUAGE', mbox_lang) agid.register(vmbox_get_info)
if config.has_option("general", "lp"): LP_PATH = config.get("general", "lp") # 3. create backends backends = {} for backend_prefix, backend_factory in _BACKENDS_FACTORY: for section in filter(lambda s: s.startswith(backend_prefix), config.sections()): backend_factory_args = dict(config.items(section)) logger.debug("Creating backend, name %s, factory %s", section, backend_factory) backends[section] = backend_factory(**backend_factory_args) logger.debug("Created %s backends", len(backends)) # 4. creation destinations global DESTINATIONS DESTINATIONS = {} for section in filter(lambda s: s.startswith("dstnum_"), config.sections()): cur_destination = section[7:] # 6 == len("dstnum_") cur_backend_ids = map(lambda s: s.strip(), config.get(section, "dest").split(",")) cur_backends = map(lambda id_: backends[id_], cur_backend_ids) logger.debug('Creating destination, dstnum %s, backends %s', cur_destination, cur_backend_ids) DESTINATIONS[cur_destination] = cur_backends logger.debug("Created %s destinations", len(DESTINATIONS)) agid.register(handle_fax, setup_handle_fax)
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid from xivo_agid import objects def incoming_did_set_features(agi, cursor, args): exten_pattern = agi.get_variable('XIVO_EXTENPATTERN') context = agi.get_variable('XIVO_CONTEXT') did = objects.DID(agi, cursor, exten = exten_pattern, context = context) if did.preprocess_subroutine: preprocess_subroutine = did.preprocess_subroutine else: preprocess_subroutine = "" agi.set_variable('XIVO_REAL_NUMBER', did.exten) agi.set_variable('XIVO_REAL_CONTEXT', did.context) agi.set_variable('XIVO_FAXDETECT_ENABLE', did.faxdetectenable) agi.set_variable('XIVO_FAXDETECT_TIMEOUT', did.faxdetecttimeout) agi.set_variable('XIVO_FAXDETECT_EMAIL', did.faxdetectemail) agi.set_variable('XIVO_DIDPREPROCESS_SUBROUTINE', preprocess_subroutine) did.set_dial_actions() did.rewrite_cid() agid.register(incoming_did_set_features)
ringtype = CONFIG_PARSER.get(section, referer_origin_fwd) elif CONFIG_PARSER.has_option(section, referer_origin): ringtype = CONFIG_PARSER.get(section, referer_origin) elif forwarded == '1' and CONFIG_PARSER.has_option( section, origin_fwd): ringtype = CONFIG_PARSER.get(section, origin_fwd) elif forwarded == '1' and CONFIG_PARSER.has_option(section, 'forward'): ringtype = CONFIG_PARSER.get(section, 'forward') else: ringtype = CONFIG_PARSER.get(section, origin) phonetype = CONFIG_PARSER.get(section, 'phonetype') except (ConfigParser.NoOptionError, ValueError): agi.set_variable('XIVO_RINGTYPE', "") agi.verbose("Using the native phone ring tone") else: agi.set_variable('XIVO_RINGTYPE', ringtype) agi.set_variable('XIVO_PHONETYPE', phonetype) agi.verbose("Using ring tone %s" % (ringtype, )) def setup(cursor): global CONFIG_PARSER # This module is often called, keep this object alive. CONFIG_PARSER = ConfigParser.RawConfigParser() CONFIG_PARSER.readfp(open(CONFIG_FILE)) agid.register(getring, setup)
if callerid == 'anonymous': agi.appexec('SetCallerPres', 'prohib') if callrecord and objects.ExtenFeatures(agi, cursor).callrecord: # BUGBUG the context is missing in the filename TODO use ids callrecordfile = "user-%s-%s-%s.wav" % (srcnum, orig_dstnum, int(time.time())) else: callrecordfile = "" if outcall.preprocess_subroutine: preprocess_subroutine = outcall.preprocess_subroutine else: preprocess_subroutine = "" if outcall.hangupringtime: hangupringtime = outcall.hangupringtime else: hangupringtime = "" agi.set_variable('XIVO_OUTCALLID', outcall.id) agi.set_variable('XIVO_CALLOPTIONS', options) agi.set_variable('XIVO_CALLRECORDFILE', callrecordfile) agi.set_variable('XIVO_OUTCALLPREPROCESS_SUBROUTINE', preprocess_subroutine) agi.set_variable('XIVO_HANGUPRINGTIME', hangupringtime) agid.register(outgoing_user_set_features)
except (ValueError, LookupError), e: agi.dp_break(str(e)) if user.vmbox: vmbox = user.vmbox else: vmboxid = user.voicemailid if not vmbox: try: vmbox = objects.VMBox(agi, cursor, int(vmboxid), commentcond=False) except (ValueError, LookupError), e: agi.dp_break(str(e)) if vmbox.password != '': agi.appexec('Authenticate', vmbox.password) try: vmbox.toggle_enable() except objects.DBUpdateException, e: agi.verbose(str(e)) agi.set_variable('XIVO_VMBOXID', vmbox.id) agi.set_variable('XIVO_VMBOX_ENABLED', int(not vmbox.commented)) agid.register(vmbox_toggle_enabled)
return try: featureexten = extenfeatures.get_exten_by_name(feature) except LookupError, e: agi.verbose(str(e)) return xset = set() forwards = dict(extenfeatures.FEATURES['forwards']) if forwards.has_key(feature): try: xset.add( fkey_extension( ppfkexten, (user.id, featureexten, getattr(user, "dest%s" % forwards[feature], "")))) xset.add(fkey_extension(ppfkexten, (user.id, featureexten))) except ValueError, e: agi.verbose(str(e)) xset.add(fkey_extension(ppfkexten, (user.id, featureexten, dest))) for x in xset: agi.set_variable("DEVSTATE(Custom:%s)" % x, devstate) agid.register(phone_progfunckey_devstate)
Copyright (C) 2008-2010 Proformatique <*****@*****.**> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid from xivo_agid import objects def voicemenu(agi, cursor, args): try: vmenu = objects.VoiceMenu(agi, cursor, int(args[0])) except (ValueError, LookupError), e: agi.dp_break(str(e)) agi.set_variable("XIVO_VCMN_CONTEXT", "voicemenu-" + vmenu.name) agid.register(voicemenu)
tmpfile = filepath % "tmp" realfile = filepath % "outgoing" f = open(tmpfile, 'w') f.write("Channel: Local/%s\n" "MaxRetries: %d\n" "RetryTime: %d\n" "WaitTime: %d\n" "CallerID: %s\n" "Context: %s\n" "Extension: %s\n" "Priority: 1\n" % (srcnum, max_retries, retry_time, wait_time, srcnum, context, dstnum)) f.close() os.utime(tmpfile, (mtime, mtime)) os.chown(tmpfile, ASTERISK_UID, ASTERISK_GID) os.rename(tmpfile, realfile) def setup(cursor): global max_retries global retry_time global wait_time config = ConfigParser.RawConfigParser() config.readfp(open(CONFIG_FILE)) max_retries = config.getint('general', 'max_retries') retry_time = config.getint('general', 'retry_time') wait_time = config.getint('general', 'wait_time') agid.register(callback_on_congestion, setup)
agi.set_variable('XIVO_AGENTEXISTS', 1) agi.set_variable('XIVO_AGENTPASSWD', agent.passwd) agi.set_variable('_XIVO_AGENTID', agent.id) agi.set_variable('_XIVO_AGENTNUM', agent.number) agi.set_variable('_XIVO_AGENTOPTIONS', options) # get agent lang lang = agent.language if lang is None or len(lang) == 0: userid = agi.get_variable('XIVO_USERID') if userid: try: caller = objects.User(agi, cursor, int(userid)) lang = caller.language # get channel default lang if lang is None or len(lang) == 0: static = objects.Static(cursor, caller.protocol) lang = static.language except (ValueError, LookupError), e: pass if lang is None or len(lang) == 0: # setting default value lang = 'en_US' agi.set_variable('_XIVO_AGENTLANGUAGE', lang) agid.register(agent_get_options)
def _fetch_from_ws(url): while True: try: fobj = urllib2.urlopen(url, timeout=10) except urllib2.HTTPError: raise except urllib2.URLError as e: logger.warning('error while fetching url %s: %s', url, e) logger.warning('sleeping %s seconds before retrying', FETCH_WS_RETRY_INTERVAL) time.sleep(FETCH_WS_RETRY_INTERVAL) else: try: return json.load(fobj) finally: fobj.close() def _update_phonebook(): global _phonebook try: raw_phonebook = _fetch_from_ws(PHONEBOOK_URL) _phonebook = _convert_raw_phonebook_to_phonebook_dict(raw_phonebook) except ValueError: # empty phonebook _phonebook = {} agid.register(callerid_forphones, setup_callerid_forphones)
protocol, name = member.split('/', 1) user = objects.User(agi, cursor, name=name, protocol=protocol) except (ValueError, LookupError): continue if user.number: pickupmark.append("%s%%%s" % (user.number, user.context)) agi.set_variable('__PICKUPMARK', '&'.join(pickupmark)) if queue.preprocess_subroutine: preprocess_subroutine = queue.preprocess_subroutine else: preprocess_subroutine = "" if queue.timeout: timeout = queue.timeout else: timeout = "" agi.set_variable('XIVO_QUEUEPREPROCESS_SUBROUTINE', preprocess_subroutine) agi.set_variable('XIVO_QUEUETIMEOUT', timeout) queue.set_dial_actions() if referer == ("queue:%s" % queue.id) or referer.startswith("voicemenu:"): queue.rewrite_cid() agid.register(incoming_queue_set_features)
agi.set_variable('XIVO_PICKUPGROUP', ','.join(pickups)) def _set_wrapup_time(agi, queue): if queue.wrapuptime: agi.set_variable('__QUEUEWRAPUPTIME', queue.wrapuptime) def holdtime_announce(agi, cursor, args): queueid = agi.get_variable('XIVO_DSTID') try: queue = objects.Queue(agi, cursor, xid=int(queueid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) if queue.announce_holdtime != 1: return holdtime = agi.get_variable('QUEUEHOLDTIME') holdtime = max(1, (int(holdtime) + 59) / 60) agi.answer() agi.stream_file('queue-holdtime') agi.stream_file('queue-less-than') agi.say_number(str(holdtime)) agi.stream_file('queue-minutes') agid.register(incoming_queue_set_features) agid.register(holdtime_announce)
(at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid from xivo_agid import objects def fwdundoall(agi, cursor, args): userid = agi.get_variable('XIVO_USERID') try: user = objects.User(agi, cursor, int(userid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) try: user.disable_forwards() except objects.DBUpdateException, e: agi.verbose(str(e)) agid.register(fwdundoall)
if config.has_option("general", "mutt"): MUTT_PATH = config.get("general", "mutt") if config.has_option("general", "lp"): LP_PATH = config.get("general", "lp") # 3. create backends backends = {} for backend_prefix, backend_factory in _BACKENDS_FACTORY: for section in filter(lambda s: s.startswith(backend_prefix), config.sections()): backend_factory_args = dict(config.items(section)) logger.debug("Creating backend, name %s, factory %s", section, backend_factory) backends[section] = backend_factory(**backend_factory_args) logger.debug("Created %s backends", len(backends)) # 4. creation destinations global DESTINATIONS DESTINATIONS = {} for section in filter(lambda s: s.startswith("dstnum_"), config.sections()): cur_destination = section[7:] # 6 == len("dstnum_") cur_backend_ids = map(lambda s: s.strip(), config.get(section, "dest").split(",")) cur_backends = map(lambda id_: backends[id_], cur_backend_ids) logger.debug('Creating destination, dstnum %s, backends %s', cur_destination, cur_backend_ids) DESTINATIONS[cur_destination] = cur_backends logger.debug("Created %s destinations", len(DESTINATIONS)) agid.register(handle_fax, setup_handle_fax)
if xlen > 0 and args[0] != '': try: if xlen == 1: context = objects.User(agi, cursor, xid=int(userid)).context else: context = args[1] user = objects.User(agi, cursor, exten=args[0], context=context) except (ValueError, LookupError), e: agi.dp_break(str(e)) else: try: user = objects.User(agi, cursor, int(userid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) if not user.vmbox: agi.dp_break("User has no voicemail box (id: %d)" % user.id) if user.vmbox.skipcheckpass: vmmain_options = "s" else: vmmain_options = "" agi.set_variable('XIVO_VMMAIN_OPTIONS', vmmain_options) agi.set_variable('XIVO_MAILBOX', user.vmbox.mailbox) agi.set_variable('XIVO_MAILBOX_CONTEXT', user.vmbox.context) agid.register(user_get_vmbox)
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid from xivo_agid import objects def fwdundoall(agi, cursor, args): userid = agi.get_variable('XIVO_USERID') try: user = objects.User(agi, cursor, int(userid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) try: user.disable_forwards() except objects.DBUpdateException, e: agi.verbose(str(e)) agid.register(fwdundoall)
if add: callerid_num = add + callerid_num agi.set_callerid(callerid_num) return def setup(cursor): global config re_objs.clear() config = OrderedConf.OrderedRawConf(filename=RULES_FILE) for section in config: try: regexp = section.get('callerid') except ConfigParser.NoOptionError: log.error("option 'callerid' not found in section %r", section.get_name()) sys.exit(1) try: re_obj = re.compile(regexp) except re.error: log.error("invalid regexp %r in section %r", regexp, section.get_name()) sys.exit(1) re_objs[section.get_name()] = re_obj agid.register(in_callerid, setup)
def phone_get_features(agi, cursor, args): userid = agi.get_variable('XIVO_USERID') feature_list = objects.ExtenFeatures(agi, cursor) try: user = objects.User(agi, cursor, int(userid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) for fwd in feature_list.FEATURES['forwards']: fwdupper = fwd[1].upper() enable = 0 dest = "" if getattr(feature_list, fwd[0], 0) \ and getattr(user, "enable%s" % fwd[1], 0): enable = 1 dest = getattr(user, "dest%s" % fwd[1], "") agi.set_variable("XIVO_ENABLE%s" % fwdupper, enable) agi.set_variable("XIVO_DEST%s" % fwdupper, dest) for service in feature_list.FEATURES['services']: enable = bool(getattr(feature_list, service[0], 0) and getattr(user, service[1], 0)) agi.set_variable("XIVO_%s" % service[1].upper(), int(enable)) agid.register(phone_get_features)
user = None agi.verbose(str(e)) else: user = None try: handy_number = objects.HandyNumber(agi, cursor, exten=exten_pattern) except LookupError, e: agi.dp_break(str(e)) trunk = handy_number.trunk agi.set_variable('XIVO_INTERFACE', trunk.interface) agi.set_variable('XIVO_TRUNKEXTEN', dstnum) if trunk.intfsuffix: intfsuffix = trunk.intfsuffix else: intfsuffix = "" agi.set_variable('XIVO_TRUNKSUFFIX', intfsuffix) if user and user.outcallerid and user.outcallerid != 'default': objects.CallerID.set(agi, user.outcallerid) if user.outcallerid == 'anonymous': agi.appexec('SetCallerPres', 'prohib') agid.register(handynumbers)
protocol, name = member.split('/', 1) user = objects.User(agi, cursor, name=name, protocol=protocol) except (ValueError, LookupError): continue if user.number: pickupmark.append("%s%%%s" % (user.number, user.context)) agi.set_variable('__PICKUPMARK', '&'.join(pickupmark)) if group.preprocess_subroutine: preprocess_subroutine = group.preprocess_subroutine else: preprocess_subroutine = "" if group.timeout: timeout = group.timeout else: timeout = "" agi.set_variable('XIVO_GROUPPREPROCESS_SUBROUTINE', preprocess_subroutine) agi.set_variable('XIVO_GROUPTIMEOUT', timeout) group.set_dial_actions() if referer == ("group:%s" % group.id) or referer.startswith("voicemenu:"): group.rewrite_cid() agid.register(incoming_group_set_features)
def alarmclk_set(agi, cursor, args): userid = int(args[0]) raw_alarm_clock = args[1] try: hour, minute = _parse_inputted_alarm_clock(raw_alarm_clock) except ValueError, e: logger.warning('Invalid alarm clock input for user %s: %s', e, userid) agi.set_variable('XIVO_ALARMCLK_OK', '0') else: alarm_clock = '%s:%s' % (hour, minute) _update_alarmclock_webi(userid, alarm_clock) agi.set_variable('XIVO_ALARMCLK_OK', '1') def alarmclk_clear(agi, cursor, args): userid = int(args[0]) cur_alarmclock = _get_alarmclock_db(cursor, userid) if cur_alarmclock: _update_alarmclock_webi(userid, '') else: logger.info('No alarm clock set for user %s', userid) agid.register(alarmclk_pre_execute) agid.register(alarmclk_set) agid.register(alarmclk_clear)
xlen = len(args) if xlen > 0 and args[0] != '': try: context = agi.get_variable('XIVO_BASE_CONTEXT') if not context: agi.dp_break('Could not get the context of the caller') user = objects.User(agi, cursor, exten=args[0], context=context) except (ValueError, LookupError), e: agi.dp_break(str(e)) else: try: user = objects.User(agi, cursor, int(userid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) if not user.vmbox: agi.dp_break("User has no voicemail box (id: %d)" % user.id) if user.vmbox.skipcheckpass: vmmain_options = "s" else: vmmain_options = "" agi.set_variable('XIVO_VMMAIN_OPTIONS', vmmain_options) agi.set_variable('XIVO_MAILBOX', user.vmbox.mailbox) agi.set_variable('XIVO_MAILBOX_CONTEXT', user.vmbox.context) agid.register(user_get_vmbox)
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid from xivo_agid import objects def incoming_did_set_features(agi, cursor, args): exten_pattern = agi.get_variable('XIVO_EXTENPATTERN') context = agi.get_variable('XIVO_CONTEXT') did = objects.DID(agi, cursor, exten = exten_pattern, context = context) if did.preprocess_subroutine: preprocess_subroutine = did.preprocess_subroutine else: preprocess_subroutine = "" agi.set_variable('XIVO_REAL_NUMBER', did.exten) agi.set_variable('XIVO_REAL_CONTEXT', did.context) agi.set_variable('XIVO_DIDPREPROCESS_SUBROUTINE', preprocess_subroutine) # schedule agi.set_variable('XIVO_PATH' , 'incall') agi.set_variable('XIVO_PATH_ID', did.id) did.set_dial_actions() did.rewrite_cid() agid.register(incoming_did_set_features)
agi.set_variable('XIVO_CALLRECORDFILE', callrecordfile) agi.set_variable('XIVO_USERPREPROCESS_SUBROUTINE', preprocess_subroutine) agi.set_variable('XIVO_MOBILEPHONENUMBER', mobilephonenumber) agi.set_variable('XIVO_USERFIELD', userfield) # voicemail lang vmbox = None if len(mailbox) > 0: try: vmbox = objects.VMBox(agi, cursor, mailbox=mailbox, context=mailbox_context) except (ValueError, LookupError), e: agi.dp_break(str(e)) mbox_lang = '' if zone == 'intern' and caller and caller.language: mbox_lang = caller.language elif vmbox and vmbox.language: mbox_lang = vmbox.language elif user and user.language: mbox_lang = user.language agi.set_variable('XIVO_MAILBOX_LANGUAGE', mbox_lang) agid.register(incoming_user_set_features)
"SELECT ${columns} FROM callfiltermember " "WHERE callfilterid = %s " "AND type = %s " "AND typeval = %s " "AND bstype = %s", ('active', ), (bsf.id, "user", secretary.id, "secretary")) res = cursor.fetchone() if not res: agi.dp_break("Unable to find secretary (id = %d)" % secretary.id) new_state = int(not res['active']) cursor.query( "UPDATE callfiltermember " "SET active = %s " "WHERE callfilterid = %s " "AND type = %s " "AND typeval = %s " "AND bstype = %s", parameters=(new_state, bsf.id, "user", secretary.id, "secretary")) if cursor.rowcount != 1: agi.dp_break("Unable to perform the requested update") agi.set_variable('XIVO_BSFILTERENABLED', new_state) else: agi.dp_break("Unknown feature %r" % feature) agid.register(phone_set_feature)
userid = agi.get_variable('XIVO_USERID') feature_list = objects.ExtenFeatures(agi, cursor) try: user = objects.User(agi, cursor, int(userid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) for fwd in feature_list.FEATURES['forwards']: fwdupper = fwd[1].upper() enable = 0 dest = "" if getattr(feature_list, fwd[0], 0) \ and getattr(user, "enable%s" % fwd[1], 0): enable = 1 dest = getattr(user, "dest%s" % fwd[1], "") agi.set_variable("XIVO_ENABLE%s" % fwdupper, enable) agi.set_variable("XIVO_DEST%s" % fwdupper, dest) for service in feature_list.FEATURES['services']: enable = bool( getattr(feature_list, service[0], 0) and getattr(user, service[1], 0)) agi.set_variable("XIVO_%s" % service[1].upper(), int(enable)) agid.register(phone_get_features)
rightcallids = '(' + ','.join((str(el) for el in rightcallidset)) + ')' contextinclude = objects.Context(agi, cursor, context).include cursor.query( "SELECT ${columns} FROM rightcall " "INNER JOIN rightcallmember " "ON rightcall.id = rightcallmember.rightcallid " "INNER JOIN incall " "ON rightcallmember.typeval = incall.id " "WHERE rightcall.id IN " + rightcallids + " " "AND rightcallmember.type = 'incall' " "AND incall.exten = %s " "AND incall.context IN (" + ", ".join(["%s"] * len(contextinclude)) + ") " "AND rightcall.commented = 0", (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME), [exten_pattern] + contextinclude) res = cursor.fetchall() call_rights.apply_rules(agi, res) call_rights.allow(agi) def did_set_call_rights(agi, cursor, args): try: _did_set_call_rights(agi, cursor, args) except call_rights.RuleAppliedException: return agid.register(did_set_call_rights)
from xivo_agid import agid from xivo_agid import objects logger = logging.getLogger(__name__) def agent_get_options(agi, cursor, args): agi.set_variable('XIVO_AGENTEXISTS', 0) try: number = str(args[0]) if number.startswith('*'): agent = objects.Agent(agi, cursor, xid=number[1:]) else: agent = objects.Agent(agi, cursor, number=number) except (LookupError, IndexError) as e: agi.verbose(str(e)) return agi.set_variable('XIVO_AGENTEXISTS', 1) agi.set_variable('XIVO_AGENTPASSWD', agent.passwd) agi.set_variable('XIVO_AGENTID', agent.id) agi.set_variable('XIVO_AGENTNUM', agent.number) if agent.language: agi.set_variable('CHANNEL(language)', agent.language) agid.register(agent_get_options)
agi.set_variable('CALLERID(num)', "%s" % callerid_num) return def setup(cursor): global config re_objs.clear() config = OrderedConf.OrderedRawConf(filename=RULES_FILE) for section in config: try: regexp = section.get('callerid') except ConfigParser.NoOptionError: log.error("option 'callerid' not found in section %r", section.get_name()) sys.exit(1) try: re_obj = re.compile(regexp) except re.error: log.error("invalid regexp %r in section %r", regexp, section.get_name()) sys.exit(1) re_objs[section.get_name()] = re_obj agid.register(in_callerid, setup)
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid from xivo_agid import objects def voicemenu(agi, cursor, args): try: vmenu = objects.VoiceMenu(agi, cursor, int(args[0])) except (ValueError, LookupError), e: agi.dp_break(str(e)) agi.set_variable("XIVO_VCMN_CONTEXT", "voicemenu-" + vmenu.name) # schedule agi.set_variable('XIVO_PATH' , 'voicemenu') agi.set_variable('XIVO_PATH_ID', vmenu.id) agid.register(voicemenu)
# it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> import logging from xivo_agid import agid from xivo_agid.handlers import agent logger = logging.getLogger(__name__) def agent_logoff(agi, cursor, args): try: agent_id = int(args[0]) agent.logoff_agent(agi, agent_id) except Exception as e: logger.exception("Error while logging off agent") agi.dp_break(e) agid.register(agent_logoff)
# it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/> import logging from xivo_agid import agid from xivo_agid.handlers import agent logger = logging.getLogger(__name__) def agent_get_status(agi, cursor, args): try: agent_id = int(args[0]) agent.get_agent_status(agi, agent_id) except Exception as e: logger.exception("Error while logging off agent") agi.dp_break(e) agid.register(agent_get_status)
def callfilter(agi, cursor, args): callfiltermember_id = args[0] if not callfiltermember_id.isdigit(): agi.dp_break('This id "%s" is not a valid callfiltermember_id id.' % callfiltermember_id) caller_user_id = agi.get_variable(dialplan_variables.USERID) callfiltermember = callfilter_dao.get_by_callfiltermember_id(callfiltermember_id) if not callfiltermember: agi.dp_break('This callfilter does not exist.') bslist = callfilter_dao.get(callfiltermember.callfilterid) if not bslist: agi.dp_break('This callfilter has no member.') allow_ids = [] for bs in bslist: callfilter, callfiltermembers = bs allow_ids.append(callfiltermembers.typeval) if not caller_user_id or caller_user_id not in allow_ids: agi.dp_break('This user is not allowed to use this callfilter.') new_state = 0 if callfiltermember.active == 1 else 1 callfilter_dao.update_callfiltermember_state(callfiltermember_id, new_state) agi.set_variable('XIVO_BSFILTERENABLED', new_state) agid.register(callfilter)
exc_info=True) agi.dp_break(str(e)) else: try: vmboxid = int(agi.get_variable('XIVO_VMBOXID')) vmbox = objects.VMBox(agi, cursor, vmboxid) except (ValueError, LookupError), e: logger.error('Error while retrieving vmbox from vmboxid', exc_info=True) agi.dp_break(str(e)) if vmbox and vmbox.skipcheckpass: vmmain_options = "s" else: vmmain_options = "" if caller and caller.language: mbox_lang = caller.language elif vmbox and vmbox.language: mbox_lang = vmbox.language else: mbox_lang = '' agi.set_variable('XIVO_VMMAIN_OPTIONS', vmmain_options) agi.set_variable('XIVO_MAILBOX', vmbox.mailbox) agi.set_variable('XIVO_MAILBOX_CONTEXT', vmbox.context) agi.set_variable('XIVO_MAILBOX_LANGUAGE', mbox_lang) agid.register(vmbox_get_info)
agi.verbose("Invalid feature: %r" % feature) return try: featureexten = extenfeatures.get_exten_by_name(feature) except LookupError, e: agi.verbose(str(e)) return xset = set() forwards = dict(extenfeatures.FEATURES['forwards']) if feature in forwards: try: xset.add(fkey_extension(ppfkexten, (user.id, featureexten, getattr(user, "dest%s" % forwards[feature], "")))) except ValueError, e: agi.verbose(str(e)) else: xset.add(fkey_extension(ppfkexten, (user.id, featureexten, dest))) for x in xset: agi.set_variable("DEVICE_STATE(Custom:%s)" % x, devstate) agid.register(phone_progfunckey_devstate)
agi.dp_break(str(e)) else: try: user = objects.User(agi, cursor, int(userid)) except (ValueError, LookupError), e: agi.dp_break(str(e)) try: fklist = split_extension(args[0]) except ValueError, e: agi.dp_break(str(e)) if userid != fklist[0]: agi.dp_break("Wrong userid. (userid: %r, excepted: %r)" % (fklist[0], userid)) feature = "" try: extenfeatures = objects.ExtenFeatures(agi, cursor) feature = extenfeatures.get_name_by_exten(fklist[1]) except LookupError, e: feature = "" agi.verbose(str(e)) agi.set_variable('XIVO_PHONE_CONTEXT', user.context) agi.set_variable('XIVO_PHONE_PROGFUNCKEY', ''.join(fklist[1:])) agi.set_variable('XIVO_PHONE_PROGFUNCKEY_STATE', 'NOTHING') agi.set_variable('XIVO_PHONE_PROGFUNCKEY_FEATURE', feature) agid.register(phone_progfunckey)
agi.dp_break(str(e)) args[2] = str(args[2]) if args[2].startswith('*'): xid = args[2][1:] number = None context = None else: xid = None number = args[2] context = user.context try: if args[0] == 'group': obj = objects.Group(agi, cursor, xid, number, context) else: obj = objects.Queue(agi, cursor, xid, number, context) except LookupError, e: agi.dp_break(str(e)) agi.set_variable('XIVO_GROUPMEMBER_ID', obj.id) agi.set_variable('XIVO_GROUPMEMBER_NAME', obj.name) agi.set_variable('XIVO_GROUPMEMBER_NUMBER', obj.number) agi.set_variable('XIVO_GROUPMEMBER_ACTION', args[1]) agi.set_variable('XIVO_GROUPMEMBER_USER_INTERFACE', user.interface) agi.set_variable('XIVO_GROUPMEMBER_USER_SKILLS', 'user-%s' % user.skills) agid.register(groupmember)
"AND rightcall.commented = 0", (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME), groupids) res = cursor.fetchall() call_rights.apply_rules(agi, res) if outcallid: cursor.query("SELECT ${columns} FROM rightcall " "INNER JOIN rightcallmember " "ON rightcall.id = rightcallmember.rightcallid " "INNER JOIN outcall " "ON rightcallmember.typeval = outcall.id " "WHERE rightcall.id IN " + rightcallids + " " "AND rightcallmember.type = 'outcall' " "AND outcall.id = %s " "AND rightcall.commented = 0", (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME), outcallid) res = cursor.fetchall() call_rights.apply_rules(agi, res) call_rights.allow(agi) def user_set_call_rights(agi, cursor, args): try: _user_set_call_rights(agi, cursor, args) except call_rights.RuleAppliedException: return agid.register(user_set_call_rights)
try: protocol, name = member.split('/', 1) user = objects.User(agi, cursor, name=name, protocol=protocol) except (ValueError, LookupError): continue if user.number: pickupmark.append("%s%%%s" % (user.number, user.context)) agi.set_variable('__PICKUPMARK', '&'.join(pickupmark)) if queue.preprocess_subroutine: preprocess_subroutine = queue.preprocess_subroutine else: preprocess_subroutine = "" if queue.timeout: timeout = queue.timeout else: timeout = "" agi.set_variable('XIVO_QUEUEPREPROCESS_SUBROUTINE', preprocess_subroutine) agi.set_variable('XIVO_QUEUETIMEOUT', timeout) queue.set_dial_actions() if referer == ("queue:%s" % queue.id) or referer.startswith("voicemenu:"): queue.rewrite_cid() agid.register(incoming_queue_set_features)
raise ValueError("Invalid section name") if forwarded == '1' and CONFIG_PARSER.has_option(section, referer_origin_fwd): ringtype = CONFIG_PARSER.get(section, referer_origin_fwd) elif CONFIG_PARSER.has_option(section, referer_origin): ringtype = CONFIG_PARSER.get(section, referer_origin) elif forwarded == '1' and CONFIG_PARSER.has_option(section, origin_fwd): ringtype = CONFIG_PARSER.get(section, origin_fwd) elif forwarded == '1' and CONFIG_PARSER.has_option(section, 'forward'): ringtype = CONFIG_PARSER.get(section, 'forward') else: ringtype = CONFIG_PARSER.get(section, origin) phonetype = CONFIG_PARSER.get(section, 'phonetype') except (ConfigParser.NoOptionError, ValueError): agi.set_variable('XIVO_RINGTYPE', "") agi.verbose("Using the native phone ring tone") else: agi.set_variable('XIVO_RINGTYPE', ringtype) agi.set_variable('XIVO_PHONETYPE', phonetype) agi.verbose("Using ring tone %s" % (ringtype,)) def setup(cursor): global CONFIG_PARSER # This module is often called, keep this object alive. CONFIG_PARSER = ConfigParser.RawConfigParser() CONFIG_PARSER.readfp(open(CONFIG_FILE)) agid.register(getring, setup)
# -*- coding: UTF-8 -*- __license__ = """ Copyright (C) 2012 Avencall This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid def callerid_extend(agi, cursor, args): if 'agi_callington' in agi.env: agi.set_variable('XIVO_SRCTON', agi.env['agi_callington']) agid.register(callerid_extend)
rightcallidset = set((row['rightcallid'] for row in res if call_rights.extension_matches(srcnum, row['exten']))) if not rightcallidset: call_rights.allow(agi) rightcallids = '(' + ','.join((str(el) for el in rightcallidset)) + ')' cursor.query("SELECT ${columns} FROM rightcall " "INNER JOIN rightcallmember " "ON rightcall.id = rightcallmember.rightcallid " "INNER JOIN incall " "ON CAST(rightcallmember.typeval AS integer) = incall.id " "WHERE rightcall.id IN " + rightcallids + " " "AND rightcallmember.type = 'incall' " "AND incall.id = %s " "AND rightcall.commented = 0", (call_rights.RIGHTCALL_AUTHORIZATION_COLNAME, call_rights.RIGHTCALL_PASSWD_COLNAME), [incall_id]) res = cursor.fetchall() call_rights.apply_rules(agi, res) call_rights.allow(agi) def did_set_call_rights(agi, cursor, args): try: _did_set_call_rights(agi, cursor, args) except call_rights.RuleAppliedException: return agid.register(did_set_call_rights)
conn = httplib.HTTPConnection(Pgc['connect_ipv4'] + ':' + str(Pgc['connect_port'])) conn.request("POST", "/provisioning", cjson.encode(command), {"Content-Type": "application/json"}) response = conn.getresponse() response.read() # eat every data sent by the provisioning server conn.close() reason = response.reason status = response.status except Exception, xcept: reason = str(xcept) status = 500 agitb.handler() del xcept sys.exc_clear() if status != 200: send_error(agi, "Provisioning failure; %s" % reason, "prov-error") return def setup(cursor): # pylint: disable-msg=W0613 """ (re)load config """ xivo_config.LoadConfig(CONFIG_FILE) xivo_config.phone_classes_setup() agid.register(initconfig, setup)
agi.dp_break("Unknown MeetMe FLAG (flag: %r, id: %s, name: %s, confno: %s)" % (flag, meetme.id, meetme.name, meetme.confno)) if meetme.OPTIONS_COMMON['musiconhold'] in options: agi.set_variable('CHANNEL(musicclass)', meetme.get_option_by_flag('musiconhold', flag)) if meetme.OPTIONS_COMMON['enableexitcontext'] in options: exitcontext = meetme.get_option_by_flag('exitcontext', flag) else: exitcontext = "" if meetme.preprocess_subroutine: preprocess_subroutine = meetme.preprocess_subroutine else: preprocess_subroutine = "" agi.set_variable('MEETME_EXIT_CONTEXT', exitcontext) agi.set_variable('MEETME_RECORDINGFILE', MEETME_RECORDINGDIR + "meetme-%s-%s" % (meetme.confno, int(time.time()))) agi.set_variable('XIVO_REAL_NUMBER', meetme.confno) agi.set_variable('XIVO_REAL_CONTEXT', meetme.context) agi.set_variable('XIVO_MEETMECONFNO', meetme.confno) agi.set_variable('XIVO_MEETMENAME', meetme.name) agi.set_variable('XIVO_MEETMENUMBER', meetme.confno) agi.set_variable('XIVO_MEETMEPIN', pin) agi.set_variable('XIVO_MEETMEOPTIONS', options) agi.set_variable('XIVO_MEETMEPREPROCESS_SUBROUTINE', preprocess_subroutine) agid.register(incoming_meetme_set_features)
agi.set_variable('XIVO_REAL_CONTEXT', group.context) agi.set_variable('XIVO_GROUPNAME', group.name) agi.set_variable('XIVO_GROUPOPTIONS', options) agi.set_variable('XIVO_GROUPNEEDANSWER', needanswer) if group.preprocess_subroutine: preprocess_subroutine = group.preprocess_subroutine else: preprocess_subroutine = "" if group.timeout: timeout = group.timeout else: timeout = "" agi.set_variable('XIVO_GROUPPREPROCESS_SUBROUTINE', preprocess_subroutine) agi.set_variable('XIVO_GROUPTIMEOUT', timeout) group.set_dial_actions() if referer == ("group:%s" % group.id) or referer.startswith("voicemenu:"): group.rewrite_cid() # schedule path = agi.get_variable('XIVO_PATH') if path is None or len(path) == 0: agi.set_variable('XIVO_PATH' , 'group') agi.set_variable('XIVO_PATH_ID', group.id) agid.register(incoming_group_set_features)
except (ValueError, LookupError), e: user = None agi.verbose(str(e)) else: user = None try: handy_number = objects.HandyNumber(agi, cursor, exten=exten_pattern) except LookupError, e: agi.dp_break(str(e)) trunk = handy_number.trunk agi.set_variable('XIVO_INTERFACE', trunk.interface) agi.set_variable('XIVO_TRUNKEXTEN', dstnum) if trunk.intfsuffix: intfsuffix = trunk.intfsuffix else: intfsuffix = "" agi.set_variable('XIVO_TRUNKSUFFIX', intfsuffix) if user and user.outcallerid and user.outcallerid != 'default': objects.CallerID.set(agi, user.outcallerid) if user.outcallerid == 'anonymous': agi.appexec('SetCallerPres', 'prohib') agid.register(handynumbers)
__version__ = "$Revision$ $Date$" __license__ = """ Copyright (C) 2009-2010 Proformatique <*****@*****.**> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. """ from xivo_agid import agid def monitoring(agi, cursor, args): agi.send_command("Status: OK") agid.register(monitoring)
# . holdtime # set by QUEUE_VARIABLES(${XIVO_QUEUENAME}) # NOTE: why testing waitingcalls ? # once there are no more calls in queue, QUEUEHOLDTIME will NEVER be # updated. # Thus if we are over threshold, we can never go over. # So, once queue is empty, we accept new incoming call event if holdtime # is over threshold waitingcalls = agi.get_variable('XIVO_QUEUE_CALLS_COUNT') if waitingcalls == '': waitingcalls = 0 if event == 'none' and int(waitingcalls) > 0 and queue.waittime is not None: holdtime = agi.get_variable('QUEUEHOLDTIME') if int(holdtime) > queue.waittime: event = 'DIVERT_HOLDTIME' dialaction = 'qwaittime' # . calls/agents ratio if event == 'none' and queue.waitratio is not None: agents = agi.get_variable('XIVO_QUEUE_MEMBERS_COUNT') if int(agents) == 0 or \ (int(waitingcalls) + 1) / int(agents) > (queue.waitratio / 100): event = 'DIVERT_CA_RATIO' dialaction = 'qwaitratio' agi.set_variable('XIVO_DIVERT_EVENT', event) agi.set_variable('XIVO_FWD_TYPE', 'queue_' + dialaction) agid.register(check_diversion)