~cyrenity/zivios/devel

« back to all changes in this revision

Viewing changes to application/modules/asterisk/scripts/asterisk/bin/addsip

  • Committer: Faraz Khan
  • Date: 2008-09-15 13:29:33 UTC
  • Revision ID: fkhan@zivios.org-20080915132933-d27jml5l29xw4gsr
Initial release to bazaar, code in sync with 0.5.0-release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
#
 
3
# Copyright (c) 2008 Zivios, LLC.
 
4
#
 
5
# This file is part of Zivios.
 
6
#
 
7
# Zivios is free software: you can redistribute it and/or modify
 
8
# it under the terms of the GNU General Public License as published by
 
9
# the Free Software Foundation, either version 3 of the License, or
 
10
# (at your option) any later version.
 
11
#
 
12
# Zivios is distributed in the hope that it will be useful,
 
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
# GNU General Public License for more details.
 
16
#
 
17
# You should have received a copy of the GNU General Public License
 
18
# along with Zivios.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
# @package              Zivios
 
21
# @copyright    Copyright (c) 2008 Zivios, LLC. (http://www.zivios.org)
 
22
# @license              http://www.zivios.org/legal/license
 
23
# @version              $Id: addattendant 1019 2008-09-08 07:26:34Z gmustafa $
 
24
#
 
25
use lib "/opt/zivios/asterisk/lib";
 
26
use Asterisk::config;
 
27
use Getopt::Long;
 
28
 
 
29
 
 
30
##args from cmd line
 
31
GetOptions ("name:s"            => \$name,
 
32
                        "secret=s"              => \$secret,
 
33
                        "authuser:s"    => \$authuser,
 
34
                        "exten:s"               => \$exten,
 
35
                        "username:s"    => \$username,
 
36
                        "fromdomain:s"  => \$fromdomain,
 
37
                        "fromuser:s"    => \$fromuser,
 
38
                        "type=s"                => \$type,
 
39
                        "callerid:s"    => \$callerid,
 
40
                        "host=s"                => \$host,
 
41
                        "port=s"                => \$port,
 
42
                        "context:s"             => \$context,
 
43
                        "mailbox:s"             => \$mailbox,
 
44
                        "allow=s"               => \$allowc,
 
45
                        "insecure:s"    => \$insecure,
 
46
                        "canreinvite:s" => \$canreinvite,
 
47
                        "nat:s"                 => \$nat,
 
48
                        "qualify:s"             => \$qualify,
 
49
                        "expiry:s"              => \$expiry,
 
50
                        "dtmfmode:s"    => \$dtmfmode,
 
51
                        "auth:s"                => \$auth,
 
52
                        "callgroup:i"   => \$callgroup,
 
53
                        "pickupgroup:i" => \$pickupgroup,
 
54
                        "trunk"                 => \$trunk,
 
55
                        "register"              => \$register);  
 
56
##
 
57
 
 
58
@allow = split(' ',$allowc);
 
59
 
 
60
my $rc = new Asterisk::config(file=>'/etc/asterisk/sip.conf',keep_resource_array=>0);
 
61
 
 
62
$rc->assign_addsection(section=>$username);
 
63
$rc->assign_append(point=>'foot',section=>$username,data=>"secret=$secret");
 
64
$rc->assign_append(point=>'foot',section=>$username,data=>"type=$type");
 
65
$rc->assign_append(point=>'foot',section=>$username,data=>"host=$host");
 
66
$rc->assign_append(point=>'foot',section=>$username,data=>"context=$context");
 
67
$rc->assign_append(point=>'foot',section=>$username,data=>"disallow=all");
 
68
foreach (@allow) {
 
69
     $rc->assign_append(point=>'foot',section=>$username,data=>"allow=$_");
 
70
}
 
71
if ($callgroup ne "")   { $rc->assign_append(point=>'foot',section=>$username,data=>"callgroup=$callgroup");                                            }
 
72
if ($port ne "")                { $rc->assign_append(point=>'foot',section=>$username,data=>"port=$port");                                                                      }
 
73
if ($pickupgroup ne "") { $rc->assign_append(point=>'foot',section=>$username,data=>"pickupgroup=$pickupgroup");                                        }
 
74
if ($callerid ne "")    { $rc->assign_append(point=>'foot',section=>$username,data=>"callerid=$callerid");                                                      }
 
75
if ($mailbox ne "")     { $rc->assign_append(point=>'foot',section=>$username,data=>"mailbox=".$mailbox."\@default");                           }
 
76
if ($qualify ne "")     { $rc->assign_append(point=>'foot',section=>$username,data=>"qualify=$qualify");                                            }
 
77
if ($expiry ne "")              { $rc->assign_append(point=>'foot',section=>$username,data=>"expiry=$expiry");                                              }
 
78
if ($nat ne "")                 { $rc->assign_append(point=>'foot',section=>$username,data=>"nat=$nat");                                                    }
 
79
if ($insecure ne "")    { $rc->assign_append(point=>'foot',section=>$username,data=>"insecure=$insecure");                                      }
 
80
if ($fromdomain ne "")  { $rc->assign_append(point=>'foot',section=>$username,data=>"fromdomain=$fromdomain");                                          }
 
81
if ($fromuser ne "")    { $rc->assign_append(point=>'foot',section=>$username,data=>"fromuser=$fromuser");                                      }
 
82
if ($username ne "")    { $rc->assign_append(point=>'foot',section=>$username,data=>"username=$username");                                      }
 
83
if ($dtmfmode ne "")    { $rc->assign_append(point=>'foot',section=>$username,data=>"dtmfmode=$dtmfmode");                                      }
 
84
if ($canreinvite ne "") { $rc->assign_append(point=>'foot',section=>$username,data=>"canreinvite=$canreinvite");                        }
 
85
if ($auth ne "")                { $rc->assign_append(point=>'foot',section=>$username,data=>"auth=$auth");                                                      }
 
86
if ($authuser ne "")    { $rc->assign_append(point=>'foot',section=>$username,data=>"authuser=$authuser");                                      }
 
87
 
 
88
if ($register == 1) {
 
89
        $rc->assign_append(point=>'foot',section=>'general',data=>"register => ".$username.":".$secret."\@".$host."/".$username);
 
90
}
 
91
        my $rcexten = new Asterisk::config(file=>'/etc/asterisk/extensions.conf',keep_resource_array=>0);
 
92
if ($trunk == 1) {
 
93
        $rcexten->assign_append(point=>'foot',section=>'globals',data=>"TRUNK_". $name . "=SIP/".$username);
 
94
        $rcexten->assign_addsection(section=>$context);
 
95
}
 
96
        if ($exten ne "") {
 
97
                $rcexten->assign_append(point=>'foot',section=>'internal',data=>"exten => ".$exten.",1,Macro(sip-vm)");
 
98
        }
 
99
 
 
100
$rcexten->save_file();
 
101
$rc->save_file();
 
102
 
 
103
 
 
104