diff options
Diffstat (limited to 'xpp/utils/zapconf')
-rwxr-xr-x | xpp/utils/zapconf | 157 |
1 files changed, 151 insertions, 6 deletions
diff --git a/xpp/utils/zapconf b/xpp/utils/zapconf index e1a6537..7cf1378 100755 --- a/xpp/utils/zapconf +++ b/xpp/utils/zapconf @@ -107,6 +107,15 @@ sub map_zaptel_defaults { my $zapconf_file; my $zapata_file; +my $users_file; + +my %files = ( + zaptel => { file => \$zapconf_file, func => \&gen_zaptelconf }, + zapata => { file => \$zapata_file, func => \&gen_zapataconf }, + users => { file => \$users_file, func => \&gen_usersconf }, +); + +my @default_files = ("zaptel", "zapata"); my @spans = Zaptel::spans(); @@ -328,6 +337,121 @@ HEAD select $old; } +sub gen_users_channel($) { + my $chan = shift || die; + my $type = $chan->type; + my $num = $chan->num; + die "channel $num type $type is not an analog channel\n" if $chan->is_digital(); + my $exten = $base_exten + $num; + my $sig = $default_zapata_signalling{$type}; + + return unless grep { $_ eq $type} ( 'FXS', 'IN', 'OUT' ); + die "missing default_zapata_signalling for chan #$num type $type" unless $sig; + print << "EOF"; +[$exten] +callwaiting = yes +context = numberplan-custom-1 +fullname = New User +hasagent = yes +hasdirectory = no +hasiax = yes +hasmanager = no +hassip = yes +hasvoicemail = no +host = dynamic +mailbox = $exten +threewaycalling = yes +vmsecret = 1234 +zapchan = $num +registeriax = yes +registersip = yes +canreinvite = no +nat = no +dtmfmode = rfc2833 +disallow = all +allow = all + +EOF +} + +sub gen_usersconf($) { + my $file = shift || die; + rename "$file", "$file.bak" + or $! == 2 # ENOENT (No dependency on Errno.pm) + or die "Failed to backup old config: $!\n"; + open(F, ">$file") || die "$0: Failed to open $file: $!\n"; + my $old = select F; + print <<"HEAD"; +;! +;! Automatically generated configuration file +;! Filename: @{[basename($file)]} ($file) +;! Generator: $0 +;! Creation Date: @{[scalar(localtime)]} +;! +[general] +; +; Full name of a user +; +fullname = New User +; +; Starting point of allocation of extensions +; +userbase = @{[$base_exten+1]} +; +; Create voicemail mailbox and use use macro-stdexten +; +hasvoicemail = yes +; +; Set voicemail mailbox @{[$base_exten+1]} password to 1234 +; +vmsecret = 1234 +; +; Create SIP Peer +; +hassip = yes +; +; Create IAX friend +; +hasiax = yes +; +; Create H.323 friend +; +;hash323 = yes +; +; Create manager entry +; +hasmanager = no +; +; Remaining options are not specific to users.conf entries but are general. +; +callwaiting = yes +threewaycalling = yes +callwaitingcallerid = yes +transfer = yes +canpark = yes +cancallforward = yes +callreturn = yes +callgroup = 1 +pickupgroup = 1 +localextenlength = 4 + + +HEAD + foreach my $span (@spans) { + printf "; Span %d: %s %s\n", $span->num, $span->name, $span->description; + if($span->is_digital()) { + next; + } else { + foreach my $chan ($span->chans()) { + gen_users_channel($chan); + } + } + print "\n"; + } + close F; + select $old; +} + sub set_defaults { my $zaptel_boot_debian = $ENV{ZAPTEL_BOOT_DEBIAN} || "/etc/default/zaptel"; my $zaptel_boot_fedora = $ENV{ZAPTEL_BOOT_FEDORA} || "/etc/sysconfig/zaptel"; @@ -342,11 +466,26 @@ sub set_defaults { map_zaptel_defaults(%source_defaults); $zapconf_file = $ENV{ZAPCONF_FILE} || "/etc/zaptel.conf"; $zapata_file = $ENV{ZAPATA_FILE} || "/etc/asterisk/zapata-channels.conf"; + $users_file = $ENV{USERS_FILE} || "/etc/asterisk/users.conf"; } +sub parse_args { + return if @ARGV == 0; + @default_files = (); + for my $file (@ARGV) { + die "$0: Unknown file '$file'" unless defined $files{$file}; + push @default_files, $file; + } +} + +sub generate_files { + for my $file (@default_files) { + &{$files{$file}->{func}}(${$files{$file}->{file}}); + } +} set_defaults; -gen_zaptelconf $zapconf_file; -gen_zapataconf $zapata_file; +parse_args; +generate_files; __END__ @@ -356,23 +495,29 @@ zapconf - Generate configuration for zaptel channels. =head1 SYNOPSIS -zapconf +zapconf [FILES...] =head1 DESCRIPTION This script generate configuration files for Zaptel hardware. -Currently it generate two files: +Currently it can generate three files: zaptel, zapata and users (see below). +Without arguments, it generates only zaptel and zapata. =over 4 -=item /etc/zaptel.conf +=item zaptel - /etc/zaptel.conf Configuration for ztcfg(1). It's location may be overriden by the environment variable ZAPCONF_FILE. -=item /etc/asterisk/zapata-channels.conf +=item zapata - /etc/asterisk/zapata-channels.conf Configuration for asterisk(1). It should be included in the main /etc/asterisk/zapata.conf. It's location may be overriden by the environment variable ZAPATA_FILE. +=item users - /etc/asterisk/users.conf + +Configuration for asterisk(1) and AsteriskGUI. +It's location may be overriden by the environment variable USERS_FILE. + =back |