2 # Retrieves the sip user/peer entries from the database
3 # Use these commands to create the appropriate tables in MySQL
5 #CREATE TABLE sip (id INT(11) DEFAULT -1 NOT NULL,keyword VARCHAR(20) NOT NULL,data VARCHAR(50) NOT NULL, flags INT(1) DEFAULT 0 NOT NULL,PRIMARY KEY (id,keyword));
7 # if flags = 1 then the records are not included in the output file
10 ################### BEGIN OF CONFIGURATION ####################
12 # the name of the extensions table
14 # the path to the extensions.conf file
15 # WARNING: this file will be substituted by the output of this program
16 $sip_conf = "/etc/asterisk/sip_additional.conf";
17 # the name of the box the MySQL database is running on
18 $hostname = "localhost";
19 # the name of the database our tables are kept
21 # username to connect to the database
23 # password to connect to the database
26 ################### END OF CONFIGURATION #######################
30 open EXTEN
, ">$sip_conf" || die "Cannot create/overwrite extensions file: $sip_conf\n";
32 $dbh = DBI
->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password");
33 $statement = "SELECT keyword,data from $table_name where id=0 and keyword <> 'account' and flags <> 1";
34 my $result = $dbh->selectall_arrayref($statement);
36 # check for errors after every single database call
37 print "dbh->selectall_arrayref($statement) failed!\n";
38 print "DBI::err=[$DBI::err]\n";
39 print "DBI::errstr=[$DBI::errstr]\n";
42 my @resultSet = @
{$result};
43 if ( $#resultSet > -1 ) {
44 foreach $row (@
{ $result }) {
45 my @result = @
{ $row };
46 $additional .= $result[0]."=".$result[1]."\n";
50 $statement = "SELECT data,id from $table_name where keyword='account' and flags <> 1 group by data";
52 $result = $dbh->selectall_arrayref($statement);
54 # check for errors after every single database call
55 print "dbh->selectall_arrayref($statement) failed!\n";
56 print "DBI::err=[$DBI::err]\n";
57 print "DBI::errstr=[$DBI::errstr]\n";
60 @resultSet = @
{$result};
61 if ( $#resultSet == -1 ) {
62 print "No sip accounts defined in $table_name\n";
66 foreach my $row ( @
{ $result } ) {
67 my $account = @
{ $row }[0];
68 my $id = @
{ $row }[1];
69 print EXTEN
"[$account]\n";
70 $statement = "SELECT keyword,data from $table_name where id=$id and keyword <> 'account' and flags <> 1 order by keyword";
71 my $result = $dbh->selectall_arrayref($statement);
73 # check for errors after every single database call
74 print "dbh->selectall_arrayref($statement) failed!\n";
75 print "DBI::err=[$DBI::err]\n";
76 print "DBI::errstr=[$DBI::errstr]\n";
80 my @resSet = @
{$result};
81 if ( $#resSet == -1 ) {
85 foreach my $row ( @
{ $result } ) {
86 my @result = @
{ $row };
87 print EXTEN
"$result[0]=$result[1]\n";
89 print EXTEN
"$additional\n";