2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-03 10:46:53 +00:00

Port passwort second round:

- make fhem2fhem sending work
- parse telnet parameters: disable echo


git-svn-id: https://svn.fhem.de/fhem/trunk@1614 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2012-06-14 15:15:42 +00:00
parent 811afcbd4f
commit de1a345e1f
3 changed files with 13 additions and 4 deletions

View File

@ -70,7 +70,6 @@ FHEM2FHEM_Define($$)
$hash->{Host} = $dev;
$hash->{portpassword} = $a[4] if(@a == 5);
FHEM2FHEM_CloseDev($hash); # Modify...
return FHEM2FHEM_OpenDev($hash, 0);
}
@ -94,6 +93,8 @@ FHEM2FHEM_Write($$)
my $conn = IO::Socket::INET->new(PeerAddr => $dev);
return if(!$conn); # Hopefuly it is reported elsewhere
$hash->{TCPDev2} = $conn;
syswrite($hash->{TCPDev2}, $hash->{portpassword} . "\n")
if($hash->{portpassword});
}
my $rdev = $hash->{rawDevice};
syswrite($hash->{TCPDev2}, "iowrite $rdev $fn $msg\n");

View File

@ -1339,8 +1339,7 @@ A line ending with \ will be concatenated with the next one, so long lines
<a name="portpassword"></a>
<li>portpassword<br>
Specify a port password, which has to be entered as the very first
string after the connection is established. Note: the password will be
visible when you are typing it in a the telnet connection.
string after the connection is established.
</li><br>

View File

@ -463,6 +463,9 @@ while (1) {
$client{$fd}{addr} = "$caddr:$port";
$client{$fd}{buffer} = "";
Log 4, "Connection accepted from $client{$fd}{addr}";
# Telnet is strange: tell "Will echo" to supress password
syswrite($fd, sprintf("%c%c%cPassword: ", 255, 251, 1))
if($attr{global}{portpassword});
}
foreach my $c (keys %client) {
@ -480,6 +483,12 @@ while (1) {
next;
}
$buf =~ s/\r//g;
if($attr{global}{portpassword}) {
$buf =~ s/\xff..//g; # Telnet IAC stuff
$buf =~ s/\xfd(.)//; # Telnet Do ?
syswrite($client{$c}{fd}, sprintf("%c%c%c", 0xff, 0xfc, ord($1)))
if(defined($1)) # Wont / ^C handling
}
$client{$c}{buffer} .= $buf;
AnalyzeInput($c);
}
@ -640,11 +649,11 @@ AnalyzeInput($)
$client{$c}{buffer} = $rest;
if($attr{global}{portpassword} && !$client{$c}{pwEntered}) {
syswrite($client{$c}{fd}, sprintf("%c%c%c\n", 255, 252, 1)); # Wont echo.
if($attr{global}{portpassword} eq $cmd) {
$client{$c}{pwEntered} = 1;
next;
} else {
syswrite($client{$c}{fd}, "Password required\r\n");
DoClose($c);
return;
}