This file is indexed.

/usr/share/perl5/Asterisk/Extension.pm is in libasterisk-agi-perl 1.08-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
package Asterisk::Extension;

require 5.004;

=head1 NAME

Asterisk::Extension - Stuff to deal with asterisk extension config

=head1 SYNOPSIS

stuff goes here

=head1 DESCRIPTION

description

=cut

use Asterisk;

$VERSION = '0.01';

$DEBUG = 1;

sub version { $VERSION; }

sub new {
	my ($class, %args) = @_;
	my $self = {};
	$self->{'exten'} = {};
	$self->{'contexts'} = {};
	bless $self, ref $class || $class;
#        while (my ($key,$value) = each %args) { $self->set($key,$value); }
	return $self;
}

sub DESTROY { }

sub exten {
	my ($self, $context, $extension, $priority, $value) = @_;

	$self->{'exten'}{$context}{$extension}[$priority] = $value;
}

sub getextensionarr {
	my ($self, $context, $extension) = @_;

	return @{$self->{'exten'}{$context}{$extension}};
}

sub getextensionlist {
	my ($self, $context) = @_;

	my @list = ();
#whats the best way to sort here
	foreach $ext (sort keys %{$self->{'exten'}{$context}} ) {
		push(@list, $ext);
	}
	
	return @list;
}


sub setvar {
	my ($self, $context, $var, $val) = @_;

	$self->{'vars'}{$context}{$var} = $val;
}

sub static {
	my ($self, $static, $context) = @_;

	$self->{'vars'}{$context}{'static'} = $static if defined($static);
	return $self->{'vars'}{$context}{'static'};
}

sub writeprotect {
	my ($self, $wp, $context) = @_;

	$self->{'vars'}{$context}{'writeprotect'} = $wp if defined($wp);
	return $self->{'vars'}{$context}{'writeprotect'};
}

sub matchpattern {
	my ($self, $dialednum, $extension) = @_;
	my $expr = '';
#N 1-9
#X 0-9
#. any one character
#_ or - ignore
	foreach $chr (split(//,$extension)) {
		if (($chr eq '-')||($chr eq '_')) {
			next;
		} elsif ($chr eq 'N') {
			$expr .= '[1-9]';
		} elsif ($chr eq 'X') {
			$expr .= '[0-9]';
		} else {
			$expr .= $chr;
		}
	}

	if ($dialednum =~ /^$expr$/) {
		return 1;
	} else {
		return 0;
	}


}

sub matchextension {
	my ($self, $context, $dialed) = @_;

	my %included = ();

	return 0 if (!defined($context)||!defined($dialed));
	my @contextlist = ( $context );

	foreach $cont (@contextlist) {
		foreach $ext ($self->getextensionlist($cont)) {
			if ($self->matchpattern($dialed, $ext)) {
				return ($ext, $cont);
			}
		}
	

		foreach $inccont (keys %{$self->{'contexts'}{$cont}}) {
			if (!defined($included{$inccont})) {
				push(@contextlist, $inccont);
			}
		}
	}

}

sub context {
	my ($self, $context, $include) = @_;

	if (!defined($self->{'contexts'}{$context}) ) {
		$self->{'contexts'}{$context} = {};
		$self->{'exten'}{$context} = {};
	}

	if (defined($include)) {
		$self->{'contexts'}{$context}{$include} = 1;
	}


}

sub getcontextarr {
	my ($self) = @_;


	my @arr = ();
	foreach $context ( keys %{$self->{'contexts'}} ) {
		push(@arr, $context);
	}

	return @arr;
}


sub writeconfig {
	my ($self, $filename) = @_;

	return if (!defined($filename));

	open(CFG, ">$filename") || die $!;
#	my @contextarr = ( 'general' );
	push(@contextarr, $self->getcontextarr());

	foreach $context (@contextarr) {
		print CFG "[$context]\n";
		foreach $var (keys %{$self->{'vars'}{$context}}) {
			print CFG "$var = " . $self->{'vars'}{$context}{$var} . "\n";
		}

		foreach $exten ($self->getextensionlist($context)) {
			my @extarr = $self->getextensionarr($context, $exten);
			for ($x=0; $x<=$#extarr; $x++) {
				print CFG "exten => $exten,$x,$extarr[$x]\n" if ($extarr[$x]);
			}
		}
				


	}


}

sub readconfig {
	my ($self, $filename) = @_;

	my $context = '';
	my $line = '';

	$filename = '/etc/asterisk/extensions.conf' if (!defined($filename));

	open(FN, "<$filename") || die $!;
	while ($line = <FN>) {
		chop($line);


		$line =~ s/;(.*)$//;
		$line =~ s/\s*$//;
		if ($line =~ /^;/)  {
			next;
		} elsif ($line =~ /^\s*$/) {
			next;
		} elsif ($line =~ /^static\s*[=>]\s*(.*)$/i) {
			$self->static($1,$context);
		} elsif ($line =~ /^writeprotect\s*[=>]\s*(.*)$/i) {
			$self->writeprotect($1,$context);
		} elsif ($line =~ /^\[(\w+)\]$/) {
			$context = $1;
			print STDERR "Context: $context\n" if ($DEBUG>3);
			$self->context($context);
		} elsif ($line =~ /^include\s*[=>]+>\s*(.+)$/) {
			my $include = $1;
			print STDERR "Include: $include\n" if ($DEBUG>3);
			$self->context($context, $include);
		} elsif ($line =~ /^exten\s*[=>]+\s*(.+)/) {
			my $extenstr = $1;
			print STDERR "ExtensionString: $extenstr\n" if ($DEBUG>3);
			my @extarr = split(/,/,$extenstr);
			my $exten = shift(@extarr);
			my $pri = shift(@extarr);
			my $addtl = join(',', @extarr);
			$self->exten($context, $exten, $pri, $addtl);
		} elsif ($line =~ /^(\w+)\s*[=>]+\s*(.*)/) {
			$self->setvar($context, $1, $2);
		} else {
			print STDERR "Unknown line: $line\n" if ($DEBUG);
		}


	}

	close(FN);



}




1;