2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-01-31 12:49:34 +00:00

fhem.pl client mode: password support

git-svn-id: https://svn.fhem.de/fhem/trunk@3734 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2013-08-18 10:27:54 +00:00
parent 923bbefb24
commit 3a5fbcde09
3 changed files with 22 additions and 12 deletions

View File

@ -383,14 +383,17 @@ telnet_ActivateInform($)
IAC requests to supress echo while entering the password.
Also all returned lines are terminated with \r\n.
Example:<br>
<ul>
<code>
attr tPort password secret<br>
attr tPort password {use FritzBoxUtils;;FB_checkPw("localhost","$password") }<br>
</code>
or if you defined multiple users on the Fritzbox:<br>
<code>
attr tPort password {use FritzBoxUtils;;FB_checkPw("localhost","$user", "$password") }<br>
attr tPort password {"$password" eq "secret"}
</code>
</ul>
Note: if this attribute is set, you have to specify a password as the
first argument when using fhem.pl in client mode:
<ul>
perl fhem.pl localhost:7072 secret "set lamp on"
</ul>
</li><br>
<a name="globalpassword"></a>

View File

@ -178,7 +178,7 @@ telnet) or single client command (via fhem.pl). Example:
</ul>
or
<ul>
<code>fhem.pl &lt;fhemhost&gt;:7072 "&lt;command&gt;..."</code>
<code>fhem.pl &lt;fhemhost&gt;:7072 "&lt;fhem-command&gt" "..."</code>
</ul>
</ul>

View File

@ -286,10 +286,10 @@ $readingFnAttributes = "event-on-change-reading event-on-update-reading ".
###################################################
# Start the program
if(int(@ARGV) != 1 && int(@ARGV) != 2) {
if(int(@ARGV) < 1) {
print "Usage:\n";
print "as server: fhem configfile\n";
print "as client: fhem [host:]port cmd\n";
print "as client: fhem [host:]port cmd cmd cmd...\n";
CommandHelp(undef, undef);
exit(1);
}
@ -324,15 +324,20 @@ if($^O !~ m/Win/ && $< == 0) {
###################################################
# Client code
if(int(@ARGV) == 2) {
if(int(@ARGV) > 1) {
my $buf;
my $addr = $ARGV[0];
$addr = "localhost:$addr" if($ARGV[0] !~ m/:/);
my $addr = shift @ARGV;
$addr = "localhost:$addr" if($addr !~ m/:/);
my $client = IO::Socket::INET->new(PeerAddr => $addr);
die "Can't connect to $addr\n" if(!$client);
syswrite($client, "$ARGV[1] ; quit\n");
for(my $i=0; $i < int(@ARGV); $i++) {
syswrite($client, $ARGV[$i]."\n");
}
shutdown($client, 1);
while(sysread($client, $buf, 256) > 0) {
$buf =~ s/\xff\xfb\x01Password: //;
$buf =~ s/\xff\xfc\x01\r\n//;
$buf =~ s/\xff\xfd\x00//;
print($buf);
}
exit(0);
@ -576,6 +581,8 @@ sub
Log3($$$)
{
my ($dev, $loglevel, $text) = @_;
$dev = $dev->{NAME} if(defined($dev) && ref($dev) eq "HASH");
if(defined($dev) &&
defined($attr{$dev}) &&