test
[diplomippbx.git] / alterator-asterisk / backend3 / helper / asterisk-helper.pl
blobe55a38910017d3895d8d99291245c741f10aec24
1 #!/usr/bin/perl -w
3 use Data::Dumper;
4 use Asterisk::config;
5 use strict;
6 use warnings;
7 use Getopt::Long;
10 use vars qw / $opt_action $opt_fname $opt_section $opt_key $opt_value $opt_data /;
11 GetOptions("action=s","fname:s","section:s","key:s@"=>\$opt_key,"value:s@"=>\$opt_value,"data:s");
13 ## &&(defined($opt_section))&&(defined(@{$opt_key}))&&(defined(@{$opt_value})))
15 unless (($opt_action)&&(defined($opt_fname)))
17 print STDERR "Not enough params\n";
20 if ($opt_action=~/listsections/i)
22 listsections();
23 exit 0;
26 if ($opt_action=~/addsectionvaluesxt/i)
28 addsectionvaluesxt();
29 exit 0;
32 if ($opt_action=~/addsectionvalues/i)
34 addsectionvalues();
35 exit 0;
38 if ($opt_action=~/getsectionvaluesxt/i)
40 getsectionvaluesxt();
41 exit 0;
44 if ($opt_action=~/getsectionvalues/i)
46 getsectionvalues();
47 exit 0;
50 if ($opt_action=~/delsection/i)
52 delsection();
53 exit 0;
56 #####################################################################
58 sub listsections {
59 my $rc = new Asterisk::config(file=>$opt_fname);
60 my $section_list = $rc->fetch_sections_list();
61 foreach my $section( sort @{$section_list})
63 print "$section "
67 sub addsectionvalues {
68 my $rc = new Asterisk::config(file=>$opt_fname);
69 $rc->assign_addsection(section=>$opt_section);
70 for (my $i=@{$opt_key}-1; $i>-1;$i--)
72 $rc->assign_append(point=>'down',section=>$opt_section,data=>"${$opt_key}[$i]=${$opt_value}[$i]");
74 $rc->save_file(new_file=>$opt_fname);
77 sub addsectionvaluesxt{
78 my $rc = new Asterisk::config(file=>$opt_fname);
79 $rc->assign_addsection(section=>$opt_section);
80 for (my $i=@{$opt_key}-1; $i>-1;$i--)
82 $rc->assign_append(point=>'down',section=>$opt_section,data=>"${$opt_key}[$i] => ${$opt_value}[$i]");
84 $rc->save_file(new_file=>$opt_fname);
87 sub getsectionvalues {
88 my $rc = new Asterisk::config(file=>$opt_fname);
89 my $key_ref = $rc->fetch_keys_hashref(section=>$opt_section);
90 if ( $key_ref == '0') { print "Section not found!\n";}
91 else {
92 for my $k1 ( sort keys %$key_ref )
94 for my $k2 ( @{$key_ref->{ $k1 }} )
96 print "$k1=$k2\n";
103 sub getsectionvaluesxt {
104 my $rc = new Asterisk::config(file=>$opt_fname);
105 my $key_ref = $rc->fetch_keys_hashref(section=>$opt_section);
106 if ( $key_ref == '0') { print "Section not found!\n";}
107 else {
108 for my $k1 ( sort keys %$key_ref )
110 for my $k2 ( @{$key_ref->{ $k1 }} )
112 print "$k1 => $k2\n";
118 sub delsection{
119 my $rc = new Asterisk::config(file=>$opt_fname);
120 $rc->assign_delsection(section=>$opt_section);
121 $rc->save_file(new_file=>$opt_fname);