-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.web.ajOnuMenu(Stels12)_toggleEth.pl
More file actions
58 lines (55 loc) · 2.32 KB
/
patch.web.ajOnuMenu(Stels12)_toggleEth.pl
File metadata and controls
58 lines (55 loc) · 2.32 KB
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
#<ACTION> file=>'web/ajOnuMenu.pl',hook=>'menu_settings', after=>'Ponmon'
push @menuItems, { order => 22, title => L('Вкл/Викл порт ONU'), act=>'toggleOnuEthStels12' } if lc($p{vendor}) =~ 'stels12';
#<ACTION> file=>'web/ajOnuMenu.pl',hook=>'subs', after=>'Ponmon'
sub act_toggleOnuEthStels12 {
# 2024.08.31
# https://t.me/MrMethod
my $attr = shift;
# return $ajax_url->a($lang::btn_Execute, act=>'rebootOnuStels12', go=>1) unless ses::input_int('go');
# ToLog(L('Запросив Reboot ОНУ sn=[]', $attr->{sn}));
my $res = '';
my $addr = $attr->{name};
$addr =~ s/[A-Za-z]//mgi;
$addr =~ m/(\d+)\/(\d+)\/(\d+)\:(\d+)$/;
my ($frame, $slot, $port, $onu) = ($1, $2, $3, $4);
my $tc = _telnetConnect($attr);
_tnCmd($tc, '');
my $pt = $tc->last_prompt();
$pt = $tc->last_prompt();
if ($tc->last_prompt() !~ m/config\)\#\s*\S*$/) {
$res = "error prompt epon: $pt";
} else {
_tnCmd($tc, sprintf('interface epon %d/%d', $frame, $slot));
select(undef, undef, undef, 0.1);
#!!!!!!!! NEED Duplicate some cmd from web
$tc->cmd(sprintf('interface epon %d/%d', $frame, $slot)); # DUPLICATE
#!!!!!!!! NEED Duplicate some cmd from web
my $pt = $tc->last_prompt();
my $rt = "(config-interface-epon-$frame/$slot)#";
if ($tc->last_prompt() !~ /\Q$rt\E\s*/) {
$res = "error prompt olt: ".$tc->last_prompt();
debug $res;
} else {
my @o = (_tnCmd($tc, sprintf('show ont port state %d %d eth 1', $port, $onu)));
my $current;
foreach my $ln (@o) {
chomp($ln);
next unless $ln =~ 'ONT port switch';
$ln =~ s/^\s*|\s*$//gmi;
my ($a, $b) = split /\s*\:\s*/, $ln;
debug $ln;
debug 'pre', "$a, $b";
$current = lc($b) eq 'on' ? 1 : 0;
}
my $cmd = sprintf('ont port attribute %d %d eth 1 operational-state %s', $port, $onu, $current ? 'off' : 'on');
debug $cmd;
my @a = (_tnCmd($tc, $cmd));
my $pt = $tc->last_prompt();
debug $pt;
debug 'pre', \@a;
$res = $current ? 'Sent cmd "eth 1 off"' : 'Sent cmd "eth 1 on"';
}
}
_telnetClose($tc);
return $res;
}