summaryrefslogtreecommitdiff
path: root/xpp/dahdi.cgi
blob: 5b0e591653015635e65d2ce1aef7e5f642921741 (plain)
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
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#! /usr/bin/perl -wT

# Written by Tzafrir Cohen <tzafrir.cohen@xorcom.com>
# Copyright (C) 2008, Xorcom
# This program is free software; you can redistribute and/or
# modify it under the same terms as Perl itself.

use strict;
use File::Basename;
BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); }

use CGI::Pretty qw/:standard start_ul start_li start_div start_pre/;
use Dahdi;
use Dahdi::Xpp;
use Dahdi::Hardware;

$ENV{'PATH'} = '/bin:/usr/bin';

my $DEF_TOK = '<Default>';

my $style=<<END;
<!--
body {
  margin-left: 0em;
  margin-right: 5em;
  //color: navy;
  background-color: #white;
}

dfn {
  font-style: italic;
  text-decoration: underline;
}

#content {
  margin-left: 10em;
}

h1, h2, h3 {
  color: #d03;
  margin-top: 2ex;
}

h1 { 
  text-align: center;
  color: #d03;
  background-color: #ccc;
  margin-left:5em;
}
/*
li:hover {
  background-color: #44c;
}

li li:hover {
  background-color: #448;
}
*/
/*li.status-ok  */
.status-noconf  {background-color: red; }
.status-notused {background-color: pink; } 

#toc {
  position: fixed;
  width: 9em;
  top: 3ex;
  bottom: 0pt;
  height: 100%;
  margins-left: 1em;
  color: #448;

}

#toc p {
  display: block;
  //text-align: center;
  height: 3ex;
}

#toc a {
  text-decoration: none;
  /*
  background-color: #F0FFF0;
  */
  font-weight: bold; 
  display: block; 
  padding: 0.2em; 
  width: 80%; 
  margin-bottom: 0.2ex; 
  border-top: 1px solid #8bd;
  color: #8bd;
  text-align: right;
}

-->
END

my @Toc = ();

sub header_line($$) {
	my ($text, $anchor) = @_;
	print a({-name=>$anchor},h2($text));
	push(@Toc, [$text, $anchor] );
}

print header,
	start_html(
		-title=>"DAHDI Information",
		-style=>{-code=>$style}),
	h1("DAHDI Information");

print start_div({-id=>'content'});

sub dahdi_spans() {
	my %ChansStat = (num=>0, configured=>0, inuse=>0);

	header_line("DAHDI Spans", 'spans');
	
	print p('Here we list the ',
		dfn({-title=> 'A span is a logical unit of dahdi
			channels. e.g.: all the channels that come from 
			a specific port, or all the analog channels from 
			a certain PCI card'},
			'spans'),
		' that DAHDI devices registered
		with DAHDI. For each span we list all of its channels.'
		),
		p('A channel that appears in ',
		span({-class=>'status-noconf'},'red text'),' ',
		'is one that has not been configured at all. Either not
		listed in system.conf, or dahdi_cfg was not run.'
		),
		p('A channel that appears in ',
		span({-class=>'status-notused'},'pink text'),' ',
		'is one that has been configured but is not used by any
		application. This usually means that either Asterisk is
		not running or Asterisk is not configured to use this
		channel'
		),
		p('If a port is disconnected it will have a "RED" alarm.
		For a FXO port this will only be on the specific port.
		For a BRI, E1 or T1 port it will be an alarm on the apn
		and all of the channels.'),
		;



	foreach my $span (Dahdi::spans()) {
		my $spanno = $span->num;
		my $index = 0;
		
		print h3(a({-name=>"zap_span_$spanno"}, "Span $spanno: ", 
			$span->name, " ", $span->description)),
			start_ul;
		foreach my $chan ($span->chans()) {
			my $batt = '';
			$batt = "(battery)" if $chan->battery;
			my $type = $chan->type;
			my $sig = $chan->signalling;
			my $info = $chan->info;
			my $chan_stat = 'ok';
			$ChansStat{num}++;
			if (!$sig) {
				$chan_stat = 'noconf';
			} else {
				$ChansStat{configured}++;
				if ($info =~ /\(In use\)/) {
					$ChansStat{inuse}++; 
				} else {
					$chan_stat = 'notused';
				}
			}
			# TODO: color differently if no signalling and
			# if not in-use and in alarm.
			print li({-class=>"status-$chan_stat"}, 
				$chan->num, " $type, $sig $info $batt");
		}
		print end_ul;
	}
}

sub dahdi_hardware() {
	header_line("DAHDI Hardware", 'zap_hard');

	print p('Here we list all the DAHDI hardware devices on your 
		system. If a device is not currently handled by a
		driver, it will	appear as ',
		span({-class=>'status-noconf'},'red text'),'.');

	my $hardware = Dahdi::Hardware->scan;

	print start_ul;
	foreach my $device ($hardware->device_list) {
		my $driver = $device->driver || "";
		my $status = 'ok';

		if (! $device->loaded) {
			$status = 'noconf';
		}

		print li({-class=>"status-$status"}, 
			$device->hardware_name, ": ", $driver, 
			" [".$device->vendor,"/". $device->product. "]	",
			$device->description);
	}
	print end_ul;
}

sub astribanks() {
	header_line("Astribanks", 'astribanks');

	print p('Here we list all the Astribank devices (That are
		handled by the drivers). For each Astribank we list
		its XPDs. A ',
		dfn({-title=>
			'a logical unit of the Astribank. It will '.
			'be registered in DAHDI as a single span. This	'.
			'can be either an analog (FXS or FXO) module or	'.
			'a single port in case of a BRI and PRI modules.'
			},
			'XPD'),'. ',
		' that is registered will have a link to the
		information about the span below. One that is not
		registered will appear as ',
		span({-class=>'status-noconf'},'red text'),'.');

	print start_ul;

	foreach my $xbus (Dahdi::Xpp::xbuses()) {
		print start_li, 
		      $xbus->name." (".$xbus->label .", ".$xbus->connector .")",
		      start_ul;
		foreach my $xpd ($xbus->xpds) {
			my $chan_stat = 'ok';
			my $span_str = 'UNREGISTERED';
			if ($xpd->spanno) {
				my $spanno = $xpd->spanno;
				$span_str =
				a({-href=>"#zap_span_$spanno"},
					"Span $spanno");
			} else {
				$chan_stat = 'noconf';
			}
			print li({-class=>"status-$chan_stat"}, 
				'[', $xpd->type, '] ', $span_str, $xpd->fqn
				);
		}
		print end_ul, end_li;
	}
	print end_ul;
}


dahdi_hardware();

astribanks();

dahdi_spans();

print end_div(); # content

print div({-id=>'toc'},
	p( a{-href=>'/'},'[Homepage]' ),
	( map {p( a({-href=> '#'.$_->[1]},$_->[0] ) )}  @Toc ),
);