2010-08-18 21:49:24 +08:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
#
|
|
|
|
# Written by Oron Peled <oron@actcom.co.il>
|
|
|
|
# Copyright (C) 2007, Xorcom
|
|
|
|
# This program is free software; you can redistribute and/or
|
|
|
|
# modify it under the same terms as Perl itself.
|
|
|
|
#
|
|
|
|
# $Id$
|
|
|
|
#
|
|
|
|
use strict;
|
|
|
|
use File::Basename;
|
|
|
|
BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); }
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
use Getopt::Long;
|
2010-08-18 21:49:24 +08:00
|
|
|
use Dahdi;
|
|
|
|
use Dahdi::Xpp;
|
|
|
|
use Dahdi::Config::Gen;
|
|
|
|
use Dahdi::Config::Params;
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
Getopt::Long::Configure ("bundling");
|
|
|
|
|
2010-08-18 21:49:24 +08:00
|
|
|
my $version = '1'; # Functionality version (integer)
|
|
|
|
my $revision = '$Revision$';
|
|
|
|
|
|
|
|
my %opts;
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
sub usage {
|
|
|
|
warn "Usage: $0 [options] <generators>\n";
|
|
|
|
warn " Options:\n";
|
|
|
|
warn " --line-mode=<E1|T1|J1> - Also generate span-types.conf with default line mode\n";
|
|
|
|
warn " -F|--freepbx - Modify configuration for Freepbx (skip FXS channels)\n";
|
|
|
|
warn " -v|--verbose - Be versbose, show generated files\n";
|
|
|
|
warn " -V|--version - Show version and exit\n";
|
|
|
|
warn " -h|--help - Show this message\n";
|
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2010-08-18 21:49:24 +08:00
|
|
|
sub set_defaults {
|
|
|
|
my $default_file = $ENV{GENCONF_PARAMETERS} || "/etc/dahdi/genconf_parameters";
|
|
|
|
my $params = Dahdi::Config::Params->new($default_file);
|
|
|
|
#$params->dump;
|
|
|
|
if($opts{v}) {
|
|
|
|
print "Default parameters from ", $params->{GENCONF_FILE}, "\n";
|
|
|
|
}
|
|
|
|
my $gconfig = Dahdi::Config::Gen->new($params);
|
|
|
|
#$gconfig->dump;
|
|
|
|
return $gconfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub spans_prep($@) {
|
|
|
|
my $gconfig = shift || die;
|
|
|
|
my @spans = @_;
|
|
|
|
foreach my $span (@spans) {
|
2011-06-16 17:35:32 +08:00
|
|
|
if($span->is_pri || $span->is_bri) {
|
2010-08-18 21:49:24 +08:00
|
|
|
$span->pri_set_fromconfig($gconfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
sub munge_spantypes {
|
|
|
|
if ($opts{'line-mode'}) {
|
|
|
|
print "Will generate span-types.conf with line-mode=$opts{'line-mode'}\n"
|
|
|
|
if $opts{'verbose'};
|
|
|
|
return "spantypes=line-mode=$opts{'line-mode'}";
|
|
|
|
} else {
|
|
|
|
print "Will generate span-types.conf\n" if $opts{'verbose'};
|
|
|
|
return "spantypes";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-18 21:49:24 +08:00
|
|
|
sub generator_list($) {
|
|
|
|
my $gconfig = shift || die;
|
|
|
|
my @genlist;
|
|
|
|
|
|
|
|
if (@ARGV) {
|
|
|
|
for my $gen (@ARGV) {
|
2014-01-21 02:10:56 +08:00
|
|
|
$gen = munge_spantypes() if $gen eq 'spantypes';
|
2010-08-18 21:49:24 +08:00
|
|
|
push @genlist, $gen;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
# No files given. Use the defaults.
|
2014-01-20 21:23:43 +08:00
|
|
|
@genlist = ('assignedspans', 'system', 'chandahdi');
|
2010-08-18 21:49:24 +08:00
|
|
|
if($gconfig->{'pri_connection_type'} eq 'R2') {
|
|
|
|
push @genlist, 'unicall';
|
|
|
|
}
|
2014-01-21 02:10:56 +08:00
|
|
|
push(@genlist, munge_spantypes()) if $opts{'line-mode'};
|
2010-08-18 21:49:24 +08:00
|
|
|
}
|
|
|
|
return @genlist;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub parse_genopts($) {
|
|
|
|
my $optstr = shift;
|
|
|
|
my %genopts;
|
|
|
|
|
|
|
|
$optstr = '' unless defined $optstr;
|
|
|
|
foreach my $o (split(/,/, $optstr)) {
|
|
|
|
my ($k, $v) = split(/=/, $o, 2);
|
|
|
|
$v = 1 unless defined $v and $v;
|
|
|
|
$genopts{$k} = $v;
|
|
|
|
}
|
|
|
|
return %genopts;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub generate_files($@) {
|
|
|
|
my $gconfig = shift || die;
|
|
|
|
my @spans = @_;
|
|
|
|
my @generators = generator_list($gconfig);
|
|
|
|
|
|
|
|
for my $gen (@generators) {
|
|
|
|
my ($name, $optstr) = split(/=/, $gen, 2);
|
|
|
|
die "Illegal name '$name'\n" unless $name =~ /^\w+$/;
|
|
|
|
$name =~ s/(.)(.*)/\u$1\L$2/;
|
|
|
|
my %genopts = parse_genopts($optstr);
|
|
|
|
$genopts{'freepbx'} = 'yes' if $opts{'F'};
|
|
|
|
if(defined $opts{'v'}) {
|
|
|
|
$genopts{'verbose'} = $opts{v};
|
|
|
|
}
|
|
|
|
$gconfig->run_generator($name, \%genopts, @spans);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
GetOptions(\%opts,
|
|
|
|
"line-mode=s",
|
|
|
|
"h|help",
|
|
|
|
"v|verbose",
|
|
|
|
"V|version",
|
|
|
|
"F|freepbx",
|
|
|
|
) or usage;
|
|
|
|
|
|
|
|
usage if $opts{h};
|
|
|
|
|
2010-08-18 21:49:24 +08:00
|
|
|
if($opts{'V'}) {
|
|
|
|
my $revstr = $revision;
|
|
|
|
$revstr =~ s/[^$]*\$[^:]+:\s*//;
|
|
|
|
$revstr =~ s/\s*\$.*//;
|
|
|
|
print "$0: version=$version revision=$revstr\n";
|
|
|
|
exit 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $gconfig = set_defaults;
|
|
|
|
my @spans = Dahdi::spans();
|
|
|
|
spans_prep($gconfig, @spans);
|
|
|
|
generate_files($gconfig, @spans);
|
|
|
|
|
|
|
|
__END__
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2011-09-09 18:59:39 +08:00
|
|
|
dahdi_genconf - Generate configuration for Dahdi channels.
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
dahdi_genconf [options] [generator...]
|
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
|
|
|
|
|
|
|
This script generate configuration files for Dahdi hardware.
|
|
|
|
It uses two information sources:
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item Hardware
|
|
|
|
|
2011-09-09 18:59:39 +08:00
|
|
|
The actual Dahdi hardware is automatically detected on the host.
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
=item /etc/dahdi/genconf_parameters
|
|
|
|
|
|
|
|
A configuration file that supplements the hardware information.
|
|
|
|
Its location may be overridden via the C<GENCONF_PARAMETERS> environment
|
|
|
|
variable.
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
The dahdi_genconf script can generate various kinds of configuration files
|
2011-09-09 18:59:39 +08:00
|
|
|
as specified by the generator arguments. Each generator is a perl class
|
2010-08-18 21:49:24 +08:00
|
|
|
in Dahdi::Config::Gen namespace. The generator names on the command line
|
|
|
|
are the class names in lowercase.
|
|
|
|
|
2014-01-09 08:14:03 +08:00
|
|
|
The following generators are currently implemented: system, modules, spantypes,
|
|
|
|
assignedspans, chandahdi, unicall, users.
|
|
|
|
|
2010-08-18 21:49:24 +08:00
|
|
|
For further documentation on each, please user perldoc on the relevant
|
|
|
|
class. E.g: C<perldoc Dahdi::Config::Gen::Chandahdi>
|
|
|
|
|
|
|
|
Each generator on the command line may be passed custom options by assigning
|
|
|
|
a comma separated list of options to the generator name. E.g:
|
|
|
|
|
|
|
|
dahdi_genconf system chandahdi=verbose unicall
|
|
|
|
|
|
|
|
=head2 Global options:
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
=item -V --version
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
Version -- print version string and exit.
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
=item -v --verbose
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
Verbose -- sets the C<'verbose'> option for all generators.
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
=item -F --freepbx
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
Freepbx -- sets the C<'freepbx'> option for all generators.
|
|
|
|
Currently, chandahdi is affected.
|
|
|
|
|
2014-01-21 02:10:56 +08:00
|
|
|
=item --line-mode=I<mode>
|
|
|
|
|
|
|
|
I<mode> may be E1, J1 or T1.
|
|
|
|
|
|
|
|
Enables the generator B<spantypes> and the option B<line-mode> to it.
|
|
|
|
(Equivalent to the option C<--line-mode> to C<dahdi_span_types>). This
|
|
|
|
will generate a C<span-types.conf> file with a single wildcard line
|
|
|
|
setting the line mode to I<mode>.
|
2010-08-18 21:49:24 +08:00
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
=head2 Implementation notes:
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
F<genconf_parameters> parsing is done via C<Dahdi::Config::Params>.
|
2011-09-09 18:59:39 +08:00
|
|
|
An object representing the parsed data is instantiated by:
|
2010-08-18 21:49:24 +08:00
|
|
|
C<Dahdi::Config::Params-E<gt>new()>.
|
|
|
|
The C<item()> method of this object contains all the hard coded
|
|
|
|
defaults of the configuration directives.
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
2011-09-09 18:59:39 +08:00
|
|
|
A configuration object is instantiated by C<Dahdi::Config::Gen-E<gt>new($params)>.
|
2010-08-18 21:49:24 +08:00
|
|
|
The mapping of configuration directives into semantic configuration is
|
|
|
|
done in the constructor.
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
A single generator is run via the the C<run_generator()> method of the
|
|
|
|
configuration object.
|
|
|
|
|
|
|
|
=back
|