package amt;

use warnings;
use strict;

use lib '/srv/Intel-AMT/lib/';
use Intel::AMT::RemoteControl;
use Intel::AMT::NetworkAdministration;
use Data::Dump qw/dump/;
use Regexp::Common qw/net/;
use Net::Ping;

use html;

sub info {
	my $amt = shift;
	my ( $passwd, $ip ) = split(/\s+/, $amt);
	( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/;

	my $p = Net::Ping->new;

	if ( ! $p->ping( $ip, 0.7 ) ) {
		return "$ip unreachable";
	}

	warn "amt $ip ", '*' x length($passwd), "\n";

	$ENV{AMT_HOST} = $ip;
	$ENV{AMT_PASSWORD} = $passwd;

	my $out;

	$out = qq|power: S| . Intel::AMT::RemoteControl::SystemPowerState
		. qq|<br>|
		. qq| <a href="http://$ip:16992/" target="$ip">amt</a>|
		. qq| <a href="http://$ip:16992/ip.htm" target="$ip">ip</a>|
		. qq|<br>|
		. html::pre_dump( Intel::AMT::NetworkAdministration::network_settings )
		;

	return $out;
}

1;
