root/freepbx/branches/2.2/amp_conf/bin/retrieve_queues_conf_from_mysql.pl

Revision 3919, 4.2 kB (checked in by p_lindheimer, 6 years ago)

#1881 create sip_registrations.conf, change hardcoded paths in all the retrieve_conf* scripts, add amportalconf= option to retrieve_conf to use other than /etc/amportal.conf

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
Line 
1 #!/usr/bin/perl -w
2
3 # if flags = 1 then the records are not included in the output file
4
5 use FindBin;
6 push @INC, "$FindBin::Bin";
7
8 use DBI;
9 require "retrieve_parse_amportal_conf.pl";
10
11 ################### BEGIN OF CONFIGURATION ####################
12
13 if (scalar @ARGV == 2)
14 {
15   $amportalconf = $ARGV[0];
16   # WARNING: this file will be substituted by the output of this program
17   $queues_conf = $ARGV[1]."/queues_additional.conf";
18 } else
19 {
20   $amportalconf = "/etc/amportal.conf";
21   # WARNING: this file will be substituted by the output of this program
22   $queues_conf = "/etc/asterisk/queues_additional.conf";
23 }
24
25 # the name of the extensions table
26 $table_name = "queues";
27 # the path to the extensions.conf file
28 # WARNING: this file will be substituted by the output of this program
29
30 # cool hack by Julien BLACHE <jblache@debian.org>
31 $ampconf = parse_amportal_conf( $amportalconf );
32 # username to connect to the database
33 $username = $ampconf->{"AMPDBUSER"};
34 # password to connect to the database
35 $password = $ampconf->{"AMPDBPASS"};
36 # the name of the database our tables are kept
37 $database = $ampconf->{"AMPDBNAME"};
38 # the name of the box the MySQL database is running on
39 $hostname = $ampconf->{"AMPDBHOST"};
40
41 # the engine to be used for the SQL queries,
42 # if none supplied, backfall to mysql
43 $db_engine = "mysql";
44 if (exists($ampconf->{"AMPDBENGINE"})){
45   $db_engine = $ampconf->{"AMPDBENGINE"};
46 }
47
48 ################### END OF CONFIGURATION #######################
49
50 $warning_banner = "; do not edit this file, this is an auto-generated file by freepbx
51 ; all modifications must be done from the web gui
52 ";
53
54
55 if ( $db_engine eq "mysql" ) {
56   $dbh = DBI->connect("dbi:mysql:dbname=$database;host=$hostname", "$username", "$password");
57 }
58 elsif ( $db_engine eq "pgsql" ) {
59   $dbh = DBI->connect("dbi:pgsql:dbname=$database;host=$hostname", "$username", "$password");
60 }
61 elsif ( $db_engine eq "sqlite" ) {
62   if (!exists($ampconf->{"AMPDBFILE"})) {
63     print "No AMPDBFILE set in /etc/amportal.conf\n";
64     exit;
65   }
66  
67   my $db_file = $ampconf->{"AMPDBFILE"};
68   $dbh = DBI->connect("dbi:SQLite2:dbname=$db_file","","");
69 }
70 elsif ( $db_engine eq "sqlite3" ) {
71   if (!exists($ampconf->{"AMPDBFILE"})) {
72     print "No AMPDBFILE set in /etc/amportal.conf\n";
73     exit;
74   }
75  
76   my $db_file = $ampconf->{"AMPDBFILE"};
77   $dbh = DBI->connect("dbi:SQLite:dbname=$db_file","","");
78 }
79
80 $statement = "SELECT keyword,data from $table_name where id='-1' and keyword <> 'account'";
81 my $result = $dbh->selectall_arrayref($statement);
82 unless ($result) {
83   # check for errors after every single database call
84   print "dbh->selectall_arrayref($statement) failed!\n";
85   print "DBI::err=[$DBI::err]\n";
86   print "DBI::errstr=[$DBI::errstr]\n";
87   exit;
88 }
89
90 open( EXTEN, ">$queues_conf" ) or die "Cannot create/overwrite extensions file: $queues_conf (!$)\n";
91 print EXTEN $warning_banner;
92
93 $additional = "";
94 my @resultSet = @{$result};
95 if ( $#resultSet > -1 ) {
96   foreach $row (@{ $result }) {
97     my @result = @{ $row };
98     $additional .= $result[0]."=".$result[1]."\n";
99   }
100 }
101
102 $statement = "SELECT data,id from $table_name where keyword='account' group by data";
103
104 $result = $dbh->selectall_arrayref($statement);
105 unless ($result) {
106   # check for errors after every single database call
107   print "dbh->selectall_arrayref($statement) failed!\n";
108   print "DBI::err=[$DBI::err]\n";
109   print "DBI::errstr=[$DBI::errstr]\n";
110 }
111
112 @resultSet = @{$result};
113 if ( $#resultSet == -1 ) {
114   print "No queues defined in $table_name\n";
115   exit;
116 }
117
118 foreach my $row ( @{ $result } ) {
119   my $account = @{ $row }[0];
120   my $id = @{ $row }[1];
121   print EXTEN "[$account]\n";
122   $statement = "SELECT keyword,data from $table_name where id='$id' and keyword <> 'account' and keyword <> 'rtone' order by flags";
123   my $result = $dbh->selectall_arrayref($statement);
124   unless ($result) {
125     # check for errors after every single database call
126     print "dbh->selectall_arrayref($statement) failed!\n";
127     print "DBI::err=[$DBI::err]\n";
128     print "DBI::errstr=[$DBI::errstr]\n";
129     exit;
130   }
131
132   my @resSet = @{$result};
133   if ( $#resSet == -1 ) {         
134     print "no results\n";
135     exit;
136   }
137  
138   foreach my $row ( @{ $result } ) {
139     my @result = @{ $row };
140     print EXTEN "$result[0]=$result[1]\n";
141   }                                           
142
143   print EXTEN "$additional\n";
144 }
145
146 exit 0;
147
148
Note: See TracBrowser for help on using the browser.