#!/usr/bin/perl # # FreeSWITCH SIP Setup Assistant v1.0 # Brian K. West # # use Data::Dumper; use File::Copy; my $PREFIX = "/usr/local/freeswitch"; my $providers = { "1" => "FWD", "2" => "SP", "3" => "IS", "4" => "AL", "5" => "SB", "6" => "VU" }; my $FWD = { "type" => "network", "register" => "true", "fields" => [number, password, extension], "domain" => "pulver.com", "dialprefix" => "1-393" }; my $SIPHONE = { "type" => "network", "register" => "true", "fields" => [username, password, extension], "domain" => "sipphone.com", "dialprefix" => "1-747, 1-222" }; my $IDEASIP = { "type" => "network", "register" => "true", "fields" => [username, password, extension], "domain" => "ideasip.com", "dialprefix" => "1-101" }; my $VOIPUSER = { "type" => "network", "register" => "true", "fields" => [username, password, extension], "domain" => "voipuser.org" }; my $ASTERLINK = { "type" => "pstn", "register" => "true", "fields" => [username, password, extension], "domain" => "asterlink.com", }; my $SIPBROKER = { "type" => "peer", "domain" => "sipbroker.com", "dialprefix" => "*XXX" }; my $TEMPLATES = { "FWD" => $FWD, "SP" => $SIPPHONE, "IS" => $IDEASIP, "AL" => $ASTERLINK, "SB" => $SIPBROKER, "VU" => $VOIPUSER }; print "\n" x 60; &welcome; sub welcome { print <; chomp($i); if ($i =~ m/X|x/) { print "Thanks you!\n"; exit; } elsif ($i > 6) { print "Invalid Choice\n"; &welcome; } else { if (exists($providers->{$i})) { configure_sip_provider($providers->{$i}); } }; &welcome; } sub configure_sip_provider($) { my $provider = shift; my $template = $TEMPLATES->{$provider}; my $config; my $check = 1; foreach $field (@{$template->{fields}}) { print "\nPlease your $template->{domain} $field: "; $tmp = "$provider" . uc($field); $i = ; chomp($i); $config->{$tmp} = $i; } while($check) { $check = &are_you_sure; }; if ($template->{type} eq "network" || $template->{type} eq "pstn") { do_config($provider, $config); } if ($template->{dialprefix}) { enable_extension($provider, $config); } print "\n\n\nConfiguration Complete!!!\n\n\n\n\n"; sleep(2); &welcome; } sub enable_extension($$) { my $provider = shift; my $config = shift; my $todo = $TEMPLATES->{$provider}; copy("$PREFIX/conf/dialplan/extensions/$todo->{domain}.noload", "$PREFIX/conf/dialplan/extensions/$todo->{domain}.xml"); print "\nExtension prefix $todo->{dialprefix} enabled for dialing $todo->{domain}...\n"; } sub do_config($$) { my $provider = shift; my $config = shift; my $todo = $TEMPLATES->{$provider}; open(TEMPLATE, "<$PREFIX/conf/directory/default/$todo->{domain}.noload"); @lines =