| 1 |
#! /usr/bin/perl -wT |
| 2 |
|
| 3 |
# Written by Tzafrir Cohen <[email protected]> |
| 4 |
# Copyright (C) 2008, Xorcom |
| 5 |
# This program is free software; you can redistribute and/or |
| 6 |
# modify it under the same terms as Perl itself. |
| 7 |
|
| 8 |
use strict; |
| 9 |
use File::Basename; |
| 10 |
BEGIN { my $dir = dirname($0); unshift(@INC, "$dir", "$dir/perl_modules"); } |
| 11 |
|
| 12 |
use CGI::Pretty qw/:standard start_ul start_li start_div start_pre/; |
| 13 |
use Dahdi; |
| 14 |
use Dahdi::Xpp; |
| 15 |
use Dahdi::Hardware; |
| 16 |
|
| 17 |
$ENV{'PATH'} = '/bin:/usr/bin'; |
| 18 |
|
| 19 |
my $DEF_TOK = '<Default>'; |
| 20 |
|
| 21 |
my $style=<<END; |
| 22 |
<!-- |
| 23 |
body { |
| 24 |
margin-left: 0em; |
| 25 |
margin-right: 5em; |
| 26 |
//color: navy; |
| 27 |
background-color: #white; |
| 28 |
} |
| 29 |
|
| 30 |
dfn { |
| 31 |
font-style: italic; |
| 32 |
text-decoration: underline; |
| 33 |
} |
| 34 |
|
| 35 |
#content { |
| 36 |
margin-left: 10em; |
| 37 |
} |
| 38 |
|
| 39 |
h1, h2, h3 { |
| 40 |
color: #d03; |
| 41 |
margin-top: 2ex; |
| 42 |
} |
| 43 |
|
| 44 |
h1 { |
| 45 |
text-align: center; |
| 46 |
color: #d03; |
| 47 |
background-color: #ccc; |
| 48 |
margin-left:5em; |
| 49 |
} |
| 50 |
/* |
| 51 |
li:hover { |
| 52 |
background-color: #44c; |
| 53 |
} |
| 54 |
|
| 55 |
li li:hover { |
| 56 |
background-color: #448; |
| 57 |
} |
| 58 |
*/ |
| 59 |
/*li.status-ok */ |
| 60 |
.status-noconf {background-color: red; } |
| 61 |
.status-notused {background-color: pink; } |
| 62 |
|
| 63 |
#toc { |
| 64 |
position: fixed; |
| 65 |
width: 9em; |
| 66 |
top: 3ex; |
| 67 |
bottom: 0pt; |
| 68 |
height: 100%; |
| 69 |
margins-left: 1em; |
| 70 |
color: #448; |
| 71 |
|
| 72 |
} |
| 73 |
|
| 74 |
#toc p { |
| 75 |
display: block; |
| 76 |
//text-align: center; |
| 77 |
height: 3ex; |
| 78 |
} |
| 79 |
|
| 80 |
#toc a { |
| 81 |
text-decoration: none; |
| 82 |
/* |
| 83 |
background-color: #F0FFF0; |
| 84 |
*/ |
| 85 |
font-weight: bold; |
| 86 |
display: block; |
| 87 |
padding: 0.2em; |
| 88 |
width: 80%; |
| 89 |
margin-bottom: 0.2ex; |
| 90 |
border-top: 1px solid #8bd; |
| 91 |
color: #8bd; |
| 92 |
text-align: right; |
| 93 |
} |
| 94 |
|
| 95 |
--> |
| 96 |
END |
| 97 |
|
| 98 |
my @Toc = (); |
| 99 |
|
| 100 |
sub header_line($$) { |
| 101 |
my ($text, $anchor) = @_; |
| 102 |
print a({-name=>$anchor},h2($text)); |
| 103 |
push(@Toc, [$text, $anchor] ); |
| 104 |
} |
| 105 |
|
| 106 |
print header, |
| 107 |
start_html( |
| 108 |
-title=>"DAHDI Information", |
| 109 |
-style=>{-code=>$style}), |
| 110 |
h1("DAHDI Information"); |
| 111 |
|
| 112 |
print start_div({-id=>'content'}); |
| 113 |
|
| 114 |
sub dahdi_spans() { |
| 115 |
my %ChansStat = (num=>0, configured=>0, inuse=>0); |
| 116 |
|
| 117 |
header_line("DAHDI Spans", 'spans'); |
| 118 |
|
| 119 |
print p('Here we list the ', |
| 120 |
dfn({-title=> 'A span is a logical unit of dahdi |
| 121 |
channels. e.g.: all the channels that come from |
| 122 |
a specific port, or all the analog channels from |
| 123 |
a certain PCI card'}, |
| 124 |
'spans'), |
| 125 |
' that DAHDI devices registered |
| 126 |
with DAHDI. For each span we list all of its channels.' |
| 127 |
), |
| 128 |
p('A channel that appears in ', |
| 129 |
span({-class=>'status-noconf'},'red text'),' ', |
| 130 |
'is one that has not been configured at all. Either not |
| 131 |
listed in system.conf, or dahdi_cfg was not run.' |
| 132 |
), |
| 133 |
p('A channel that appears in ', |
| 134 |
span({-class=>'status-notused'},'pink text'),' ', |
| 135 |
'is one that has been configured but is not used by any |
| 136 |
application. This usually means that either Asterisk is |
| 137 |
not running or Asterisk is not configured to use this |
| 138 |
channel' |
| 139 |
), |
| 140 |
p('If a port is disconnected it will have a "RED" alarm. |
| 141 |
For a FXO port this will only be on the specific port. |
| 142 |
For a BRI, E1 or T1 port it will be an alarm on the apn |
| 143 |
and all of the channels.'), |
| 144 |
; |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
foreach my $span (Dahdi::spans()) { |
| 149 |
my $spanno = $span->num; |
| 150 |
my $index = 0; |
| 151 |
|
| 152 |
print h3(a({-name=>"zap_span_$spanno"}, "Span $spanno: ", |
| 153 |
$span->name, " ", $span->description)), |
| 154 |
start_ul; |
| 155 |
foreach my $chan ($span->chans()) { |
| 156 |
my $batt = ''; |
| 157 |
$batt = "(battery)" if $chan->battery; |
| 158 |
my $type = $chan->type; |
| 159 |
my $sig = $chan->signalling; |
| 160 |
my $info = $chan->info; |
| 161 |
my $chan_stat = 'ok'; |
| 162 |
$ChansStat{num}++; |
| 163 |
if (!$sig) { |
| 164 |
$chan_stat = 'noconf'; |
| 165 |
} else { |
| 166 |
$ChansStat{configured}++; |
| 167 |
if ($info =~ /\(In use\)/) { |
| 168 |
$ChansStat{inuse}++; |
| 169 |
} else { |
| 170 |
$chan_stat = 'notused'; |
| 171 |
} |
| 172 |
} |
| 173 |
# TODO: color differently if no signalling and |
| 174 |
# if not in-use and in alarm. |
| 175 |
print li({-class=>"status-$chan_stat"}, |
| 176 |
$chan->num, " $type, $sig $info $batt"); |
| 177 |
} |
| 178 |
print end_ul; |
| 179 |
} |
| 180 |
} |
| 181 |
|
| 182 |
sub dahdi_hardware() { |
| 183 |
header_line("DAHDI Hardware", 'zap_hard'); |
| 184 |
|
| 185 |
print p('Here we list all the DAHDI hardware devices on your |
| 186 |
system. If a device is not currently handled by a |
| 187 |
driver, it will appear as ', |
| 188 |
span({-class=>'status-noconf'},'red text'),'.'); |
| 189 |
|
| 190 |
my $hardware = Dahdi::Hardware->scan; |
| 191 |
|
| 192 |
print start_ul; |
| 193 |
foreach my $device ($hardware->device_list) { |
| 194 |
my $driver = $device->driver || ""; |
| 195 |
my $status = 'ok'; |
| 196 |
|
| 197 |
if (! $device->loaded) { |
| 198 |
$status = 'noconf'; |
| 199 |
} |
| 200 |
|
| 201 |
print li({-class=>"status-$status"}, |
| 202 |
$device->hardware_name, ": ", $driver, |
| 203 |
" [".$device->vendor,"/". $device->product. "] ", |
| 204 |
$device->description); |
| 205 |
} |
| 206 |
print end_ul; |
| 207 |
} |
| 208 |
|
| 209 |
sub astribanks() { |
| 210 |
header_line("Astribanks", 'astribanks'); |
| 211 |
|
| 212 |
print p('Here we list all the Astribank devices (That are |
| 213 |
handled by the drivers). For each Astribank we list |
| 214 |
its XPDs. A ', |
| 215 |
dfn({-title=> |
| 216 |
'a logical unit of the Astribank. It will '. |
| 217 |
'be registered in DAHDI as a single span. This '. |
| 218 |
'can be either an analog (FXS or FXO) module or '. |
| 219 |
'a single port in case of a BRI and PRI modules.' |
| 220 |
}, |
| 221 |
'XPD'),'. ', |
| 222 |
' that is registered will have a link to the |
| 223 |
information about the span below. One that is not |
| 224 |
registered will appear as ', |
| 225 |
span({-class=>'status-noconf'},'red text'),'.'); |
| 226 |
|
| 227 |
print start_ul; |
| 228 |
|
| 229 |
foreach my $xbus (Dahdi::Xpp::xbuses()) { |
| 230 |
print start_li, |
| 231 |
$xbus->name." (".$xbus->label .", ".$xbus->connector .")", |
| 232 |
start_ul; |
| 233 |
foreach my $xpd ($xbus->xpds) { |
| 234 |
my $chan_stat = 'ok'; |
| 235 |
my $span_str = 'UNREGISTERED'; |
| 236 |
if ($xpd->spanno) { |
| 237 |
my $spanno = $xpd->spanno; |
| 238 |
$span_str = |
| 239 |
a({-href=>"#zap_span_$spanno"}, |
| 240 |
"Span $spanno"); |
| 241 |
} else { |
| 242 |
$chan_stat = 'noconf'; |
| 243 |
} |
| 244 |
print li({-class=>"status-$chan_stat"}, |
| 245 |
'[', $xpd->type, '] ', $span_str, $xpd->fqn |
| 246 |
); |
| 247 |
} |
| 248 |
print end_ul, end_li; |
| 249 |
} |
| 250 |
print end_ul; |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
dahdi_hardware(); |
| 255 |
|
| 256 |
astribanks(); |
| 257 |
|
| 258 |
dahdi_spans(); |
| 259 |
|
| 260 |
print end_div(); # content |
| 261 |
|
| 262 |
print div({-id=>'toc'}, |
| 263 |
p( a{-href=>'/'},'[Homepage]' ), |
| 264 |
( map {p( a({-href=> '#'.$_->[1]},$_->[0] ) )} @Toc ), |
| 265 |
); |