2 # Use these commands to create the appropriate tables in MySQL
5 # context CHAR(20) DEFAULT 'default' NOT NULL,
6 # extension CHAR(20) NOT NULL,
7 # priority INT(2) DEFAULT '1' NOT NULL,
8 # application CHAR(20) NOT NULL,
11 # PRIMARY KEY(context, extension, priority)
14 #CREATE TABLE globals (
15 # variable CHAR(20) NOT NULL,
16 # value CHAR(50) NOT NULL,
17 # PRIMARY KEY(variable, value)
21 ################### BEGIN OF CONFIGURATION ####################
23 # the name of the extensions table
24 $table_name = "extensions";
25 # the name of the globals table
26 $global_table_name = "globals";
27 # the path to the extensions.conf file
28 # WARNING: this file will be substituted by the output of this program
29 $extensions_conf = "/etc/asterisk/extensions.conf";
30 # the name of the box the MySQL database is running on
31 $hostname = "localhost";
32 # the name of the database our tables are kept
34 # username to connect to the database
36 # password to connect to the database
39 ################### END OF CONFIGURATION #######################
41 open EXTEN, ">$extensions_conf" || die "Cannot create/overwrite extensions file: $extensions_conf\n";
43 $dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password");
44 $statement = "SELECT * from $global_table_name order by variable";
45 my $result = $dbh->selectall_arrayref($statement);
47 # check for errors after every single database call
48 print EXTEN "dbh->selectall_arrayref($statement) failed!\n";
49 print EXTEN "DBI::err=[$DBI::err]\n";
50 print EXTEN "DBI::errstr=[$DBI::errstr]\n";
53 my @resultSet = @{$result};
54 if ( $#resultSet > 0 ) {
55 print EXTEN "[globals]\n";
56 foreach $row (@{ $result }) {
57 my @result = @{ $row };
58 print EXTEN "$result[0] = $result[1]\n";
63 $statement = "SELECT context from $table_name group by context";
65 $result = $dbh->selectall_arrayref($statement);
67 # check for errors after every single database call
68 print EXTEN "dbh->selectall_arrayref($statement) failed!\n";
69 print EXTEN "DBI::err=[$DBI::err]\n";
70 print EXTEN "DBI::errstr=[$DBI::errstr]\n";
73 @resultSet = @{$result};
74 if ( $#resultSet == -1 ) {
75 print EXTEN "No extensions defined in $table_name\n";
79 foreach my $row ( @{ $result } ) {
80 my $context = @{ $row }[0];
81 print EXTEN "[$context]\n";
82 $statement = "SELECT * from $table_name where context='$context' order by extension, priority";
83 my $result = $dbh->selectall_arrayref($statement);
85 # check for errors after every single database call
86 print EXTEN "dbh->selectall_arrayref($statement) failed!\n";
87 print EXTEN "DBI::err=[$DBI::err]\n";
88 print EXTEN "DBI::errstr=[$DBI::errstr]\n";
92 my @resSet = @{$result};
93 if ( $#resSet == -1 ) {
94 print EXTEN "no results\n";
97 foreach my $row ( @{ $result } ) {
98 my @result = @{ $row };
99 print EXTEN "exten => $result[1],$result[2],$result[3]";
100 print EXTEN "($result[4])" if defined $result[4];
101 print EXTEN "\t" if not defined $result[4];
102 print EXTEN "\t; $result[5]" if defined $result[5];