479 lines
24 KiB
HTML

<!--
Copyright (C) 2016 Intel Corporation
This sample uses btp.min.css which is part of the Bootstrap project and under the following license:
The MIT License (MIT)
Copyright (c) 2011-2015 Twitter, Inc
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<!DOCTYPE html>
<html>
<head>
<title>Web Sample</title>
<meta charset="UTF-8">
<script src="ws.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="btp.min.css">
<style>
body {
background: #efefef;
}
</style>
<script type="text/javascript">
var connectionMgr = null;
var m = null;
/*Connection function*/
function createConnection() {
m = document.getElementById("messages");
AMTConnection.setUserName(document.getElementById("username").value);
AMTConnection.setPassword(document.getElementById("password").value);
AMTConnection.connect({ onSuccess : function(connection) { m.innerHTML = "Successfully Connected to " + window.location.hostname; } });
}
/*End connection function*/
/*Start of Power sample function:*/
function performPowerAction() {
m.innerHTML = "";
var powerOption = document.getElementById("powerOption").value;
//Perform system power state change steps
var CIMPowerManagementService = { className : "CIM_PowerManagementService", selectors : { Name: "Intel(r) AMT Power Management Service" } };
CIMPowerManagementService.method = "RequestPowerStateChange";
CIMPowerManagementService.input = {PowerState : powerOption, ManagedElement : {className : "CIM_ComputerSystem", selectors : { Name: "ManagedSystem" } } };
CIMPowerManagementService.onSuccess = function (response) {
if (response.properties.ReturnValue !== "0") {
m.innerHTML += "Failed to perform power action. Return value: " + response.properties.ReturnValue + "</br>";
return;
}
m.innerHTML = "Success!<br/>";
}
AMTConnection.invokeMethod(CIMPowerManagementService);
}
/*End of Power sample function*/
/*Start of Set-Boot-Source-Next-Boot sample functions:*/
//First, check if such boot source exists
function setNextBoot0() {
m.innerHTML = "";
var bootOption = document.getElementById("bootOption").value;
var bootSourceSettingRef = null;
//First, get the boot source class (in order to check if exists)
if (bootOption === "1") { //PXE
bootSourceSettingRef = {className : "CIM_BootSourceSetting", selectors : { InstanceID: "Intel(r) AMT: Force PXE Boot" }};
}
else if (bootOption === "2") { //Hard-drive
bootSourceSettingRef = {className : "CIM_BootSourceSetting", selectors : { InstanceID: "Intel(r) AMT: Force Hard-drive Boot" }};
}
else if (bootOption === "3") { //CD-DVD
bootSourceSettingRef = {className : "CIM_BootSourceSetting", selectors : { InstanceID: "Intel(r) AMT: Force CD/DVD Boot" }};
}
if (bootSourceSettingRef) {
setNextBoot1(bootSourceSettingRef);
} else {
setNextBoot1(null);
}
}
//Get AMT_BootSettingData reference
function setNextBoot1(bootSourceSettingRef) {
AMTConnection.get({className : "AMT_BootSettingData", selectors : { InstanceID: "Intel(r) AMT:BootSettingData 0" }, onSuccess : setNextBoot2, args : { bootSourceReference : bootSourceSettingRef} });
}
//Callback function - zero boot options
function setNextBoot2(AMTBootSettingDataInstance, arg) {
if (arg.bootSourceReference) {
AMTBootSettingDataInstance.properties.BIOSPause = false;
AMTBootSettingDataInstance.properties.BIOSSetup = false;
AMTBootSettingDataInstance.properties.ReflashBIOS = false;
AMTBootSettingDataInstance.properties.UseIDER = false;
AMTBootSettingDataInstance.properties.UseSOL = false;
}
AMTConnection.put({className : "AMT_BootSettingData", selectors : {InstanceID: "Intel(r) AMT:BootSettingData 0" },
input : AMTBootSettingDataInstance, onSuccess : setNextBoot3, args : arg});
}
//Set boot source
function setNextBoot3(bootSettXmlInst, arg) {
var req = { className : "CIM_BootConfigSetting", selectors : { InstanceID: "Intel(r) AMT: Boot Configuration 0" }, method : "ChangeBootOrder", input : {} };
if (arg.bootSourceReference) {
if (AMTConnection.version.compare(5.1) >= 0) {
req.input.Source = arg.bootSourceReference;
} else {
req.input.source = arg.bootSourceReference;
}
}
req.onSuccess = setNextBoot4;
AMTConnection.invokeMethod(req);
}
function setNextBoot4(response, args) {
var ret = response.properties.ReturnValue;
if (ret !== "0") {
console.log("Failed to set boot source. Return value: " + ret);
m.innerHTML += "Failed to set boot source. Return value: " + ret + "</br>";
return;
}
// Enable the boot configuration for next Intel AMT boot.
var BootConfigSettingRef = { className : "CIM_BootConfigSetting", selectors : { InstanceID: "Intel(r) AMT: Boot Configuration 0" } };
var req = { className : "CIM_BootService", selectors : { Name: "Intel(r) AMT Boot Service" } };
req.method = "SetBootConfigRole";
req.input = {};
req.input.BootConfigSetting = BootConfigSettingRef;
req.input.Role = "1";
req.onSuccess = setNextBoot5;
AMTConnection.invokeMethod(req);
}
function setNextBoot5(response) {
var ret = response.properties.ReturnValue;
if (ret !== "0") {
console.log("Failed to set boot config role. Return value: " + ret);
m.innerHTML += "Failed to set boot config role. Return value: " + ret + "</br>";
return;
}
m.innerHTML += "Success. Result: " + ret + "</br>";
}
/*End of Set-Boot-Source-Next-Boot sample functions*/
/*Start of Boot-Capabilities sample functions*/
function displayBootCapabilities() {
m.innerHTML = "";
AMTConnection.get({className : "AMT_BootCapabilities", selectors : { InstanceID: "Intel(r) AMT:BootCapabilities 0" }, onSuccess : displayBootCapabilities1 })
}
function displayBootCapabilities1(bootCapInstance) {
m.innerHTML += "Displaying Boot Capabilities:" + "</br>";
m.innerHTML += "BIOSPause: " + bootCapInstance.properties.BIOSPause + "</br>";
m.innerHTML += "IDER: " + bootCapInstance.properties.IDER + "</br>";
m.innerHTML += "SOL: " + bootCapInstance.properties.SOL + "</br>";
m.innerHTML += "BIOSReflash: " + bootCapInstance.properties.BIOSReflash + "</br>";
m.innerHTML += "BIOSSetup: " + bootCapInstance.properties.BIOSSetup + "</br>";
m.innerHTML += "ForcePXEBoot: " + bootCapInstance.properties.ForcePXEBoot + "</br>";
m.innerHTML += "ForceHardDriveBoot: " + bootCapInstance.properties.ForceHardDriveBoot + "</br>";
m.innerHTML += "ForceHardDriveSafeModeBoot: " + bootCapInstance.properties.ForceHardDriveSafeModeBoot + "</br>";
m.innerHTML += "ForceDiagnosticBoot: " + bootCapInstance.properties.ForceDiagnosticBoot + "</br>";
m.innerHTML += "ForceCDorDVDBoot: " + bootCapInstance.properties.ForceCDorDVDBoot + "</br>";
m.innerHTML += "VerbosityScreenBlank: " + bootCapInstance.properties.VerbosityScreenBlank + "</br>";
m.innerHTML += "PowerButtonLock: " + bootCapInstance.properties.PowerButtonLock + "</br>";
m.innerHTML += "ResetButtonLock: " + bootCapInstance.properties.ResetButtonLock + "</br>";
m.innerHTML += "KeyboardLock: " + bootCapInstance.properties.KeyboardLock + "</br>";
m.innerHTML += "SleepButtonLock: " + bootCapInstance.properties.SleepButtonLock + "</br>";
m.innerHTML += "UserPasswordBypass: " + bootCapInstance.properties.UserPasswordBypass + "</br>";
m.innerHTML += "ForcedProgressEvents: " + bootCapInstance.properties.ForcedProgressEvents + "</br>";
m.innerHTML += "VerbosityVerbose: " + bootCapInstance.properties.VerbosityVerbose + "</br>";
m.innerHTML += "VerbosityQuiet: " + bootCapInstance.properties.VerbosityQuiet + "</br>";
m.innerHTML += "ConfigurationDataReset: " + bootCapInstance.properties.ConfigurationDataReset + "</br>";
if (AMTConnection.version.compare(11.0) >= 0)
m.innerHTML += "SecureErase: " + bootCapInstance.properties.SecureErase + "</br>";
}
/*End of Boot-Capabilities sample functions*/
/*Start of Filter-Collection-Enum sample functions*/
function enumFilterCollection() {
m.innerHTML = "";
AMTConnection.enumerate({className : "CIM_FilterCollection", onSuccess : enumFilterCollection1 });
}
function enumFilterCollection1(filterCollection) {
m.innerHTML += filterCollection.className + "</br>";
m.innerHTML += "Number of available filters: " + filterCollection.items.length + "</br>";
m.innerHTML += "Available filters:</br>";
for (var i in filterCollection.items) {
m.innerHTML += "Filter InstanceID: " + filterCollection.items[i].properties.InstanceID + "</br>";
}
}
/*End of Filter-Collection-Enum sample functions*/
/*Start of Event-Log sample functions*/
function displayLog0() {
m.innerHTML = "";
AMTConnection.get({className : "AMT_MessageLog", selectors : { Name: "Intel(r) AMT:MessageLog 1" }, onSuccess : displayLog1 })
}
function displayLog1(AMTMessageLog) {
m.innerHTML += "Is log frozen: " + AMTMessageLog.properties.IsFrozen + "</br>";
m.innerHTML += "Max number of records: " + AMTMessageLog.properties.MaxNumberOfRecords + "</br>";
m.innerHTML += "Current number of records in the log: " + AMTMessageLog.properties.CurrentNumberOfRecords + "</br>";
var req = {className : "AMT_MessageLog", selectors : { Name: "Intel(r) AMT:MessageLog 1" }};
req.method = "GetRecords";
req.input = {IterationIdentifier : "1" , MaxReadRecords : "100"};
req.onSuccess = displayLog2;
AMTConnection.invokeMethod(req);
}
function displayLog2(response) {
var record = {};
var ret = response.properties.ReturnValue;
if (ret !== "0") {
console.log("Failed to get records. Return value: " + ret);
m.innerHTML += "Failed to get records. Return value: " + ret + "</br>";
return;
}
var recordArray = response.properties.RecordArray;
//for (var ii in recordArray) {
for (var ii = 0; ii < 5; ii++) {
var byteRecord = window.atob(recordArray[ii]); //Decode from base-64 string
//Get the first 4 bytes to get the time-stamp (the time-stamp is in seconds since 1/1/1970)
var d = 0 , t = 0;
t = byteRecord.charCodeAt(3);
d += t << 24;
t = byteRecord.charCodeAt(2);
d += (t << 16);
t = byteRecord.charCodeAt(1);
d += (t << 8);
t = byteRecord.charCodeAt(0);
d += t;
record.timeStamp = new Date(d * 1000);
//Entity type
record.entityType = getEntityType(byteRecord.charCodeAt(11));
//Sensor type
record.sensorType = getSensorType(byteRecord.charCodeAt(5));
//Event type
record.eventType = getEventType(byteRecord.charCodeAt(6));
m.innerHTML += "</br>" + "Record number " + (ii + 1) + "</br>";
m.innerHTML += "Event-Date: " + record.timeStamp.getDate() + "." + (record.timeStamp.getMonth() + 1) + "." + record.timeStamp.getFullYear() + "</br>";
m.innerHTML += "Event-Entity type: " + record.entityType + "</br>";
m.innerHTML += "Event-Sensor type: " + record.sensorType + "</br>";
m.innerHTML += "Event type: " + record.eventType + "</br>";
}
}
//Event-Log sample Utility functions
function getEntityType(entity) {
var EntityTypes = [ "Unspecified", "Other", "Unknown", "Processor", "Disk or Disk Bay",
"Peripheral Bay", "System Management Module", "System Board", "Memory Module",
"Processor Module", "Power Supply", "Add in Card", "Front Panel Board",
"Back Panel Board", "Power System Board", "Drive Backplane", "System Internal Expansion Board",
"Other System Board", "Processor Board", "Power Unit Power Domain", "Power_Module_Converter",
"Power Management or Distribution Board", "Chassis Back Panel Board", "System Chassis",
"Sub Chassis", "Other Chassis Board", "Disk Drive Bay ", "Device Bay", "Peripheral Bay",
"Device Bay ", "Fan Cooling Device", "Cooling Unit", "Cable Interconnect", "Memory_Device",
"System Management Software", "Bios", "Operating_System", "System_Bus", "Group", "Intel(r) AMT",
"External environment", "Battery", "Processing blade", "Connectivity switch",
"Processor/memory module","I/O module", "Processor I/O module", "Management controller firmware", "IPMI channel",
"PCI bus", "PCI express bus", "SCSI bus", "SATA/SAS bus", "Processor front side bus" ];
if (entity == 0xFF) {return "Match all";}
if (EntityTypes[entity] !== undefined) {
return EntityTypes[entity];
}
return "Unknown Event Type";
}
function getSensorType(sensor) {
var SensorType = [ "Unknown", "Temperature", "Voltage", "Current", "Fan", "Physical security",
"AMT Password Attack", "Processor", "Power supply", "Power unit",
"Cooling device", "Other units based sensor", "Memory", "Drive slot",
"Power memory resize", "System firmware progress", "Event logging disabled",
"Watchdog 1", "System event", "Critical interrupt", "Button", "Module board",
"Microcontroller coprocessor", "Add in card", "Chassis", "Chip set",
"Other FRU", "Cable interconnect", "Terminator", "System boot initiated",
"Boot error", "OS boot", "OS critical stop", "Slot connector",
"System ACPI power state", "Watchdog 2", "Platform alert", "Entity presence", "Monitor ASIC IC",
"LAN", "Management subsystem health", "Battery"];
if (sensor == 0xFF) return "Match all";
if (sensor == 192) return "Intel Specific";
if (sensor == 193) return "Intel(r) AMT diagnostics";
if (SensorType[sensor] !== undefined) {
return SensorType[sensor];
}
return "Unknown Event Sensor Type";
}
function getEventType(type) {
var EventType = ["Unspecified", "Threshold", "Discrete usage", "Discrete state",
"Discrete predictive failure",
"Discrete limit exceeded", "Discrete performance met", "Discrete severity",
"Discrete device presence",
"Discrete device enable", "Discrete availability", "Discrete redundancy",
"Discrete ACPI power", "Sensor specific"];
if (type == 112) return "Intel Specific";
if (EventType[type] !== undefined) {
return EventType[type];
}
return "Unknown Event Type";
}
/*End of Event-Log sample functions*/
/*Start of Power state sample functions*/
function getPowerState() {
m.innerHTML = "";
var CIMAssociatedPowerManagementService = {className : "CIM_AssociatedPowerManagementService",
selectors : { UserOfService : { className : "CIM_ComputerSystem", selectors : {Name:"ManagedSystem"} } } };
CIMAssociatedPowerManagementService.onSuccess = getPowerState1;
AMTConnection.enumerate(CIMAssociatedPowerManagementService);
}
function getPowerState1(CIMAssociatedPowerManagementService) {
for (var i in CIMAssociatedPowerManagementService.items) {
if (CIMAssociatedPowerManagementService.items[i].properties.ServiceProvided.className === "CIM_PowerManagementService") {
m.innerHTML += "System power state: " + getPowerStateType(CIMAssociatedPowerManagementService.items[i].properties.PowerState);
break;
}
}
}
function getPowerStateType(i) {
var powerType = ["Unknown","Other", "On", "Sleep - Light", "Sleep -Deep", "Power Cycle (Off - Soft)",
"Off - Hard", "Hibernate (Off - Soft)"," Off - Soft", "Power Cycle (Off-Hard)", "Master Bus Reset",
"Diagnostic Interrupt (NMI)", "Off - Soft Graceful", "Off - Hard Graceful", "Master Bus Reset Graceful",
"Power Cycle (Off - Soft Graceful)", "Power Cycle (Off - Hard Graceful)", "Diagnostic Interrupt (INIT)"];
if (i == 0x7FFF) return "DMTF Reserved";
if (i == 0xFFFF) return "Vendor Specific";
if (powerType[i] !== undefined) {
return powerType[i];
}
return "Unknown power state";
}
/*End of Power state sample functions*/
function AssetInfo() {
m.innerHTML = "";
AMTConnection.enumerate({className : "CIM_BIOSElement", onSuccess : AssetInfo1 });
}
function AssetInfo1(CIMBIOSElementCollection) {
var biosCollection = CIMBIOSElementCollection.items;
for (var i in biosCollection) {
m.innerHTML += "BIOS #" + i + ":</br>";
m.innerHTML += "Version: " + biosCollection[i].properties.Version + "</br>";
m.innerHTML += "Manufacturer: " + biosCollection[i].properties.Manufacturer + "</br>";
m.innerHTML += "Release Date: " + biosCollection[i].properties.ReleaseDate.Datetime + "</br>";
}
AMTConnection.get({className : "CIM_Chassis", onSuccess : AssetInfo2});
}
function AssetInfo2(CIMChassis) {
m.innerHTML += "System info:</br>";
m.innerHTML += "Manufacturer: " + CIMChassis.properties.Manufacturer + "</br>";
m.innerHTML += "Model: " + CIMChassis.properties.Model + "</br>";
m.innerHTML += "Version: " + CIMChassis.properties.Version + "</br>";
m.innerHTML += "Serial Number: "+ CIMChassis.properties.SerialNumber + "</br>";
AMTConnection.get({className : "CIM_ComputerSystemPackage", onSuccess : function (CIMComputerSystem) {
m.innerHTML += "PlatformGUID: " + CIMComputerSystem.properties.PlatformGUID;
} });
}
</script>
</head>
<body>
<div class="container">
<div id="head" class="row">
<div id="connectionInfo" class="col-xs-offset-4 col-xs-4">
<!--<label for="host" class="sr-only">Host</label>
<input type="text" id="host" class="form-control" placeholder="Host name/IP Address" required/>-->
<label for="username" class="sr-only">User name</label>
<input type="text" class="form-control" id="username" placeholder="User name" required/>
<label for="password" class="sr-only">Password</label>
<input type="password" class="form-control" id="password" placeholder="Password" required/>
<!--<div class="checkbox">
<label for="secure"><input type="checkbox" class="checkbox" id="secure" />Secure</label>
</div>-->
<input type="button" class="btn btn-primary" value="Connect" onclick="createConnection()" />
</div>
<div id="logo">
<img src="logo.png" />
</div>
</div>
<div id="options" class="row">
<div id="powerSample" class="col-xs-offset-4 col-xs-6">
<select id="powerOption" style="width:100px">
<option value="2">Power up</option>
<option value="8">Power down</option>
<option value="10">Reset</option>
<option value="4">Sleep</option>
<option value="7">Hibernate</option>
</select>
<input type="button" onclick="performPowerAction()" value="Perform power request" />
</div>
<div id="bootSourceSample" class="col-xs-offset-4 col-xs-6">
<select id="bootOption" style="width:100px">
<option value="0">None</option>
<option value="1">PXE Boot</option>
<option value="2">Hard Drive Boot</option>
<option value="3">CD or DVD Boot</option>
</select>
<input type="button" onclick="setNextBoot0()" value="Set boot source" />
</div>
<div id="bootCapabilitiesSample" class="col-xs-offset-4 col-xs-6">
<input type="button" onclick="displayBootCapabilities()" value="Display boot capabilities" />
</div>
<div id="powerStateSample" class="col-xs-offset-4 col-xs-6">
<input type="button" onclick="getPowerState()" value="Get system power state" />
</div>
<div id="enumSample" class="col-xs-offset-4 col-xs-6">
<input type="button" onclick="enumFilterCollection()" value="Enumerate subscription filters" />
</div>
<div id="eventLogSample" class="col-xs-offset-4 col-xs-6">
<input type="button" onclick="displayLog0()" value="Event log" />
</div>
<div class="col-xs-offset-4 col-xs-6">
<input type="button" onclick="AssetInfo()" value="System Asset" />
</div>
</div>
<div id="messagesRow" class="row">
<div id="messages" class="col-xs-offset-4 col-xs-6"></div>
</div>
</div>
</body>
</html>