summaryrefslogtreecommitdiffstats
path: root/amttool
diff options
context:
space:
mode:
authorkraxel <kraxel>2007-08-24 11:46:47 +0000
committerkraxel <kraxel>2007-08-24 11:46:47 +0000
commit569222657a9fc97c97e15a77117cc436ad63ca61 (patch)
tree48be7b8be76cf136e2a9dbb046229b280e7797ab /amttool
parent6f083c88dc92b5bf96aa2c588f244e208c6a2050 (diff)
downloadamtterm-569222657a9fc97c97e15a77117cc436ad63ca61.tar.gz
amttool improved
Diffstat (limited to 'amttool')
-rwxr-xr-xamttool172
1 files changed, 118 insertions, 54 deletions
diff --git a/amttool b/amttool
index e9aa4a4..0095048 100755
--- a/amttool
+++ b/amttool
@@ -2,83 +2,147 @@
use strict;
use warnings;
use SOAP::Lite;
+#use SOAP::Lite +trace => 'all';
my $amt_host = shift;
my $amt_port = "16992";
$main::amt_user = "admin";
$main::amt_pass = $ENV{'AMT_PASSWORD'};
+my $amt_command = shift;
+$amt_command = "info" if !defined($amt_command);
+
+#########################################################################################
+# data
+
+my @ps = ("S0", "S1", "S2", "S3", "S4", "S5 (soft-off)", "S4/S5", "Off");
+my %rcc = (
+ "reset" => "16",
+ "powerup" => "17",
+ "powerdown" => "18",
+ "powercycle" => "19",
+);
+
+
+#########################################################################################
+# soap setup
+
+my ($nas, $sas, $rcs);
+
sub SOAP::Transport::HTTP::Client::get_basic_credentials {
return $main::amt_user => $main::amt_pass;
}
-#########################################################################################
-#
+sub soap_init() {
+ my $proxybase = "http://$amt_host:$amt_port";
+ my $schemabase = "http://schemas.intel.com/platform/client";
+
+ $nas = SOAP::Lite->new(
+ proxy => "$proxybase/NetworkAdministrationService",
+ default_ns => "$schemabase/NetworkAdministration/2004/01");
+ $sas = SOAP::Lite->new(
+ proxy => "$proxybase/SecurityAdministrationService",
+ default_ns => "$schemabase/SecurityAdministration/2004/01");
+ $rcs = SOAP::Lite->new(
+ proxy => "$proxybase/RemoteControlService",
+ default_ns => "$schemabase/RemoteControl/2004/01");
+ $rcs->autotype(0);
+}
-my @ps = ("S0", "S1", "S2", "S3", "S4", "S5 (soft-off)", "S4/S5", "Off");
#########################################################################################
-# main
+# functions
-if (!defined($amt_host)) {
+sub usage() {
print STDERR <<EOF;
This utility can talk to Intel AMT managed machines.
-usage: amttool [ options ] <hostname>
-options:
- none yet, right now it just gathers and prints some infos.
+usage: amttool <hostname> [ <command> ]
+commands:
+ info - print some machine info (default).
+ reset - reset machine.
+ powerup - turn on machine.
+ powerdown - turn off machine.
+ powercycle - powercycle machine.
Password is passed via AMT_PASSWORD environment variable.
EOF
+}
+
+sub print_info() {
+ printf "### AMT info on machine '%s' ###\n", $amt_host;
+
+ my $amt_version = $sas->GetCoreVersion()->paramsout;
+ printf "AMT version: %s\n", $amt_version;
+
+ my $hostname = $nas->GetHostName()->paramsout;
+ my $domainname = $nas->GetDomainName()->paramsout;
+ printf "Hostname: %s.%s\n", $hostname, $domainname;
+
+ my $powerstate = $rcs->GetSystemPowerState()->paramsout;
+ printf "Powerstate: %s\n", $ps [ $powerstate & 0x0f ];
+
+ my @rccaps = $rcs->GetRemoteControlCapabilities()->paramsout;
+ printf "Remote Capabilities:\n";
+ printf " IanaOemNumber %x\n", $rccaps[0];
+ printf " OemDefinedCapabilities %s%s%s%s%s\n",
+ $rccaps[1] & 0x01 ? "IDER " : "",
+ $rccaps[1] & 0x02 ? "SOL " : "",
+ $rccaps[1] & 0x04 ? "BiosReflash " : "",
+ $rccaps[1] & 0x08 ? "BiosSetup " : "",
+ $rccaps[1] & 0x10 ? "BiosPause " : "";
+
+ printf " SpecialCommandsSupported %s%s%s%s%s\n",
+ $rccaps[2] & 0x0100 ? "PXE-boot " : "",
+ $rccaps[2] & 0x0200 ? "HD-boot " : "",
+ $rccaps[2] & 0x0400 ? "HD-boot-safemode " : "",
+ $rccaps[2] & 0x0800 ? "diag-boot " : "",
+ $rccaps[2] & 0x1000 ? "cd-boot " : "";
+
+ printf " SystemCapabilitiesSupported %s%s%s%s\n",
+ $rccaps[3] & 0x01 ? "powercycle " : "",
+ $rccaps[3] & 0x02 ? "powerdown " : "",
+ $rccaps[3] & 0x03 ? "powerup " : "",
+ $rccaps[3] & 0x04 ? "reset " : "";
+
+ printf " SystemFirmwareCapabilities %x\n", $rccaps[4];
+}
+
+sub remote_control($) {
+ my $command = shift;
+
+ my $hostname = $nas->GetHostName()->paramsout;
+ my $domainname = $nas->GetDomainName()->paramsout;
+ printf "host %s.%s, %s [y/N] ? ", $hostname, $domainname, $command;
+ my $reply = <>;
+ if ($reply =~ m/^(y|yes)$/i) {
+ printf "execute: %s\n", $command;
+ my $arg1 = SOAP::Data->name('Command' => $rcc{$command});
+ my $arg2 = SOAP::Data->name('IanaOemNumber' => 4542);
+ my $rc = $rcs->RemoteControl($arg1, $arg2)->result;
+ printf "result: %s\n", defined($rc) ? $rc : "failed";
+ } else {
+ printf "canceled\n";
+ }
+}
+
+
+#########################################################################################
+# main
+
+if (!defined($amt_host)) {
+ usage();
exit 1;
}
-my $nas = SOAP::Lite->new(
- proxy => "http://$amt_host:$amt_port/NetworkAdministrationService",
- ns => "http://schemas.intel.com/platform/client/NetworkAdministration/2004/01");
-my $sas = SOAP::Lite->new(
- proxy => "http://$amt_host:$amt_port/SecurityAdministrationService",
- ns => "http://schemas.intel.com/platform/client/SecurityAdministration/2004/01");
-my $rcs = SOAP::Lite->new(
- proxy => "http://$amt_host:$amt_port/RemoteControlService",
- ns => "http://schemas.intel.com/platform/client/RemoteControl/2004/01");
-
-printf "### query host %s ###\n", $amt_host;
-
-my $amt_version = $sas->GetCoreVersion()->paramsout;
-printf "AMT version: %s\n", $amt_version;
-
-my $hostname = $nas->GetHostName()->paramsout;
-my $domainname = $nas->GetDomainName()->paramsout;
-printf "Hostname: %s.%s\n", $hostname, $domainname;
-
-my $powerstate = $rcs->GetSystemPowerState()->paramsout;
-printf "Powerstate: %s\n", $ps [ $powerstate & 0x0f ];
-
-my @rccaps = $rcs->GetRemoteControlCapabilities()->paramsout;
-printf "Remote Capabilities:\n";
-printf " IanaOemNumber %x\n", $rccaps[0];
-printf " OemDefinedCapabilities %s%s%s%s%s\n",
- $rccaps[1] & 0x01 ? "IDER " : "",
- $rccaps[1] & 0x02 ? "SOL " : "",
- $rccaps[1] & 0x04 ? "BiosReflash " : "",
- $rccaps[1] & 0x08 ? "BiosSetup " : "",
- $rccaps[1] & 0x10 ? "BiosPause " : "";
-
-printf " SpecialCommandsSupported %s%s%s%s%s\n",
- $rccaps[2] & 0x0100 ? "PXE-boot " : "",
- $rccaps[2] & 0x0200 ? "HD-boot " : "",
- $rccaps[2] & 0x0400 ? "HD-boot-safemode " : "",
- $rccaps[2] & 0x0800 ? "diag-boot " : "",
- $rccaps[2] & 0x1000 ? "cd-boot " : "";
-
-printf " SystemCapabilitiesSupported %s%s%s%s\n",
- $rccaps[3] & 0x01 ? "powercycle " : "",
- $rccaps[3] & 0x02 ? "powerdown " : "",
- $rccaps[3] & 0x03 ? "powerup " : "",
- $rccaps[3] & 0x04 ? "reset " : "";
-
-printf " SystemFirmwareCapabilities %x\n", $rccaps[4];
+soap_init;
+if ($amt_command eq "info") {
+ print_info;
+} elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) {
+ remote_control($amt_command);
+} else {
+ print "unknown command: $amt_command\n";
+}