Does this script make sense?
1# ani_filter.tcl
2# Script Version 1.0(1)
3#------------------------------------------------------------------
4# October 2002, Niels Brunsgaard
5#
6# Copyright (c) 1998-2002 by cisco Systems, Inc.
7# All rights reserved.
8#------------------------------------------------------------------
9#
10# This tcl script filters calls based on ANI. If there is a match # against a pe-configured list of numbers it changes the DNIS # to a configurable value #
11#
12
13proc init { } {
14 global param
15}
16
17proc act_Setup { } {
18
19 leg setupack leg_incoming
20
21 set num [infotag get leg_dnis]
22 set new_dnis ""
23 }
24
25 # fixnum num
26# num - the phone number you want to fix
27# takes num, decides if it's local or long distance and adds/removes a leading 1 as required
28# returns the new phone number with or without the 1
29proc fixnum {num} {
30
31# a list of all local prefixes
32# if a match isn't found in this list it is assumed the number is long distance
33# these must all be 6 characters long or you will need to change the code
34set local [list \
35281208 \
36832922 \
37832964 \
38832967 \
39832969 \
40 ];
41
42
43# if the number is < 10 digits don't change it
44if { [ string length $num ] < 10 } {
45 return $num;
46}
47
48# get the first two digits
49set ftd [ string range $num 0 1 ];
50
51#if the first two digits are 90 don't change it (meant for international 011 calls)
52if { $ftd == 90 } {
53 return $num;
54}
55
56# if first two digits are 91 we drop the 1 regardless, we want to work the first 6 digits, starting with the area code
57if { $ftd == 91 } {
58 set num [ string range $num 2 [ string length $num ] ];
59}
60
61# get first 6 digits, and see if they're in the list of local numbers
62set snum [ string range $num 0 5 ];
63set islocal [ lsearch $local $snum ];
64
65# if they're not local add the 91 at the start
66if { $islocal == -1 } {
67 set num "91$num";
68}
69
70# return the number with the 1 added/removed as required
71return $num;
72
73}
74 puts "Final dnis $num"
75 leg proceeding leg_incoming
76 leg setup $num callInfo leg_incoming
77}
78
79proc act_CallSetupDone { } {
80 global beep
81
82 set status [infotag get evt_status]
83
84 puts "Entering act_CallSetupDone"
85 if { $status != "ls_000"} {
86 puts "Call [infotag get con_all] got event $status while placing an outgoing call"
87 call close
88 }
89}
90
91proc act_Cleanup { } {
92 puts "Entering act_Cleanup"
93 call close
94}
95
96proc act_Abort { } {
97 puts "Unexpected event - entering act_Abort"
98 call close
99}
100
101init
102
103#----------------------------------
104# State Machine
105#----------------------------------
106 set TopFSM(any_state,ev_disconnected) "act_Abort,same_state"
107 set TopFSM(CALL_INIT,ev_setup_indication) "act_Setup,PLACECALL"
108 set TopFSM(PLACECALL,ev_setup_done) "act_CallSetupDone,CALLACTIVE"
109 set TopFSM(CALLACTIVE,ev_disconnected) "act_Cleanup,CALLDISCONNECTED"
110 set TopFSM(CALLDISCONNECTED,ev_disconnect_done) "act_Cleanup,same_state"
111
112 fsm define TopFSM CALL_INIT