snacktime wrote:

Here is a quick script that will parse extensions.conf, any files
included via #include, and print out the sql commands to put them into
mysql.

I'll add on routines to do the same for sip, iax, and voicemail when I
get the chance.

Chris

It seems I use the script wrong:

vpbx:/etc/asterisk # ./extensions-mysql extensions.conf
USE asterisk;
Can't call method "close" on an undefined value at ./extensions-mysql line 72.

extensions-mysql:

-----------------------------------------------------------------------------
#!/usr/bin/perl

# Copyright (c) 2005 Chris Ochs

# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without restriction,
# including without limitation the rights to use, copy, modify, merge,
# publish, distribute, sublicense, and/or sell copies of the Software,
# and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
# ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

use IO::File;
$path = "/etc/asterisk";
my $database = "asterisk";
my $table = "extensions";
my $context;
$file = $ARGV[0];

if(!-e "$path/$file" || $file eq '') {
 print "File does not exist\n";
 exit;
}

print "USE $database;\n";

&parse_config($file);


sub parse_config {
 my ($file) = @_;
 my $fh = IO::File->new("$path/$file");
 while ($line = <$fh>) {
    chomp $line;
    if ($line =~/^\[(.*)\]$/) {
       $context = $1;
    }elsif ($line =~/(^[\s]{0,9}#include[\s]{0,9}.*$)/) {
       my $file_include = $1;
       $file_include =~s/#include[\s]{0,9}//g;
       $file_include =~s/\s//g;
       &parse_config($file_include);
    }elsif ($line
=~/(^[\s]{0,9}exten[\s]{0,9}=>[\s]{0,9})([_.XN0-9a-zA-Z]{0,20}),([_.XN0-9a-zA-Z]{0,20}),(.*)/)
{
       my (undef,$exten,$priority,$action) = ($1,$2,$3,$4);
       my ($app,$appdata);
       if ($action =~/(^[a-zA-Z]{0,32})\((.*)\)/) {
          ($app,$appdata) = ($1,$2);
       }elsif($action =~/(^[a-zA-Z]{0,32}),(.*)/) {
          ($app,$appdata) = ($1,$2);
       }else{
          $app = $action;
          $appdata = '';
       }
       $appdata =~s/,/\|/g;
       print "INSERT INTO extensions
(context,exten,priority,app,appdata) VALUES ('$context', '$exten',
'$priority', '$app', '$appdata');\n";
    }
 }
 $fh->close;
}
_______________________________________________
Asterisk-Users mailing list
Asterisk-Users@lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users





--
Ronald Wiplinger  (CEO of ELMIT)
http://www.elmit.com    +886 (0) 939--77-55-16  or FWD 511208
- I'm a SpamCon Foundation Member, #694, Verify it at http://www.spamcon.org

PS: Spam prevention!
Our system is protected with a spam prevention program. If you send us an e-mail, our system will send you a confirmation message back. Just reply to this confirmation message please. After receiving this confirmation message, our system will send the hold message (one) and all future messages (after the received confirmation message) to me without asking you again.


_______________________________________________
Asterisk-Users mailing list
Asterisk-Users@lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-users
To UNSUBSCRIBE or update options visit:
  http://lists.digium.com/mailman/listinfo/asterisk-users

Reply via email to