Asterisk-config

 view release on metacpan or  search on metacpan

examples/Asteriskgui.pm  view on Meta::CPAN

package Dahdi::Config::Gen::Asteriskgui;
use strict;

use Asterisk::config;
use Dahdi::Config::Gen qw(is_true);

sub new($$$) {
	my $pack = shift || die;
	my $gconfig = shift || die;
	my $genopts = shift || die;
	my $users_file = $ENV{USERS_CONF_FILE} || "/etc/asterisk/users.conf";
	my $ext_file = $ENV{EXTENSIONS_FILE} || "/etc/asterisk/extensions.conf";
	my $self = {
			USERS_FILE	=> $users_file,
			EXT_FILE	=> $ext_file,
			GCONFIG		=> $gconfig,
			GENOPTS		=> $genopts,
		};
	$self->{USERS} = new Asterisk::config(file => $self->{USERS_FILE});
	$self->{EXT}   = new Asterisk::config(file => $self->{EXT_FILE});
	bless $self, $pack;
	return $self;
}

# A digital trunk for a single span
sub gen_digital_trunk($$) {
	my $self = shift || die;
	my $span = shift || die;
	my $gconfig = $self->{GCONFIG};
	my $num = $span->num() || die;
	my $bchan_range = Dahdi::Config::Gen::bchan_range($span);
	my $sect_name = "span_dahdi_$num";
	my $context = "DID_$sect_name";
	die "Span #$num is analog" unless $span->is_digital();
	if($span->is_pri && $gconfig->{'pri_connection_type'} eq 'R2') {
		return;

examples/Asteriskgui.pm  view on Meta::CPAN

			"hassip = no",
			"hasregisteriax = no",
			"hasregistersip = no",
			"trunkstyle = analog",
			"dahdichan = $ports",
		]
	);
}

# A user for a single FXS port
sub gen_channel($$) {
	my $self = shift || die;
	my $chan = shift || die;
	my $gconfig = $self->{GCONFIG};
	my $type = $chan->type;
	my $num = $chan->num;
	my $full_name = "$type $num";
	my $sect_name = "chan_dahdi_$num";
	die "channel $num type $type is not an analog channel\n" if $chan->span->is_digital();
	my $exten = $self->{EXTEN}++;
	my $sig = $gconfig->{'chan_dahdi_signalling'}{$type};

examples/Asteriskgui.pm  view on Meta::CPAN

			"dahdichan = $num",
		],
	);
}

# Add instructions to remove existing relevant sections.
# Note that this function only adds the instructions to the commit_list.
# Requests will only actually be performed on on the save_file()-s in
# the end. Thus even after this function, the sections we "remove" still
# exist in fetch requests.
sub remove_old_sections($) {
	my $self = shift || die;
	my @user_del_sect = grep /^((chan|span_dahdi_)|trunk_analog$)/, 
		@{$self->{USERS}->fetch_sections_list()};
	foreach (@user_del_sect) {
		$self->{USERS}->assign_delsection(section=>$_);
	}

	my @ext_del_sect = grep /^DID_(span_dahdi_|trunk_analog)/, 
		@{$self->{EXT}->fetch_sections_list()};
	foreach (@ext_del_sect) {
		$self->{EXT}->assign_delsection(section=>$_);
	}
}

sub generate($) {
	my $self = shift || die;
	my @spans = @_;
	my $gconfig = $self->{GCONFIG};
	my $genopts = $self->{GENOPTS};
	$self->{EXTEN} = $self->{GCONFIG}->{'base_exten'};
	#$gconfig->dump;

	my @fxo_ports = ();
	warn "Empty configuration -- no spans\n" unless @spans;
	$self->remove_old_sections();



( run in 0.709 second using v1.01-cache-2.11-cpan-65fba6d93b7 )