mirror of https://github.com/adamveld12/dracli
downloads jnlp
parent
fe4555465a
commit
cfe17184ec
|
|
@ -1,3 +1,6 @@
|
|||
.vscode
|
||||
credentials.json
|
||||
dracli
|
||||
dracli
|
||||
viewer.jnlp
|
||||
.DS_Store
|
||||
drac
|
||||
152
client.go
152
client.go
|
|
@ -14,68 +14,9 @@ import (
|
|||
xj "github.com/basgys/goxml2json"
|
||||
)
|
||||
|
||||
var (
|
||||
PowerStatus = Attribute("pwState")
|
||||
SystemDescription = Attribute("sysDesc")
|
||||
SystemRevision = Attribute("sysRev")
|
||||
HostName = Attribute("hostName")
|
||||
OSName = Attribute("osName")
|
||||
OSVersion = Attribute("osVersion")
|
||||
ServiceTag = Attribute("svcTag")
|
||||
ExpServiceCode = Attribute("expSvcCode")
|
||||
BiosVersion = Attribute("biosVer")
|
||||
FirmwareVersion = Attribute("fwVersion")
|
||||
LCCFirmwareVersion = Attribute("LCCfwVersion")
|
||||
IPV4Enabled = Attribute("v4Enabled")
|
||||
IPV4Address = Attribute("v4IPAddr")
|
||||
IPV6Enabled = Attribute("v6Enabled")
|
||||
IPV6LinkLocal = Attribute("v6LinkLocal")
|
||||
IPV6Address = Attribute("v6Addr")
|
||||
IPV6SiteLocal = Attribute("v6SiteLocal")
|
||||
MacAddress = Attribute("macAddr")
|
||||
Batteries = Attribute("batteries")
|
||||
FanRedundancy = Attribute("fansRedundancy")
|
||||
Fans = Attribute("fans")
|
||||
Intrusion = Attribute("intrusion")
|
||||
PowerSupplyRedundancy = Attribute("psRedundancy")
|
||||
PowerSupplies = Attribute("powerSupplies")
|
||||
RMVRedundancy = Attribute("rmvsRedundancy")
|
||||
RemovableStorage = Attribute("removableStorage")
|
||||
Temperatures = Attribute("temperatures")
|
||||
Voltages = Attribute("voltages")
|
||||
KVMEnabled = Attribute("kvmEnabled")
|
||||
PowerBudgetData = Attribute("budgetpowerdata")
|
||||
EventLog = Attribute("eventLogEntries")
|
||||
BootOnce = Attribute("vmBootOnce")
|
||||
FirstBootDevice = Attribute("firstBootDevice")
|
||||
VFKLicense = Attribute("vfkLicense")
|
||||
User = Attribute("user")
|
||||
IDRACLog = Attribute("racLogEntries")
|
||||
|
||||
PowerOff = PowerState(0)
|
||||
PowerOn = PowerState(1)
|
||||
NonMaskingInterrupt = PowerState(2)
|
||||
GracefulShutdown = PowerState(3)
|
||||
ColdReboot = PowerState(4)
|
||||
WarmReboot = PowerState(5)
|
||||
NoOverride = BootDevice(0)
|
||||
PXE = BootDevice(1)
|
||||
HardDrive = BootDevice(2)
|
||||
BIOS = BootDevice(6)
|
||||
VirtualCD = BootDevice(8)
|
||||
LocalSD = BootDevice(16)
|
||||
LocalCD = BootDevice(5)
|
||||
)
|
||||
|
||||
type Attribute string
|
||||
type PowerState uint8
|
||||
type BootDevice uint8
|
||||
|
||||
type SensorType struct {
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
client *http.Client
|
||||
Username string
|
||||
AuthToken string
|
||||
Host string
|
||||
}
|
||||
|
|
@ -111,6 +52,38 @@ func (c *Client) doHTTP(path, qs string, body io.Reader) (string, []*http.Cookie
|
|||
return jsonData.String(), res.Cookies(), nil
|
||||
}
|
||||
|
||||
func (c *Client) OpenConsole() error {
|
||||
//https://192.168.0.228/viewer.jnlp(192.168.0.228@0@root@1548390931405)
|
||||
uri := fmt.Sprintf("https://%s/viewer.jnlp(%s@0@%s@%d)", c.Host, c.Host, c.Username, time.Now().Unix())
|
||||
req, _ := http.NewRequest("GET", uri, nil)
|
||||
req.AddCookie(&http.Cookie{
|
||||
Name: "_appwebSessionId_",
|
||||
Value: c.AuthToken,
|
||||
})
|
||||
res, err := c.client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode != 200 {
|
||||
return errors.New("bad status")
|
||||
}
|
||||
|
||||
f, err := os.Create("./viewer.jnlp")
|
||||
if err != nil {
|
||||
return errors.New("could not download")
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if _, err := io.Copy(f, res.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) SetPowerState(ps PowerState) (string, error) {
|
||||
res, _, err := c.doHTTP("", fmt.Sprintf("set=pwState:%d", ps), nil)
|
||||
return res, err
|
||||
|
|
@ -148,6 +121,7 @@ func NewFromCredentials(path string) (*Client, error) {
|
|||
return nil, err
|
||||
}
|
||||
c.AuthToken = credential.AuthToken
|
||||
c.Username = credential.Username
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
|
@ -190,3 +164,61 @@ func (c *Client) Login(username, password string) (string, error) {
|
|||
|
||||
return "", errors.New("could not find auth token in cookie")
|
||||
}
|
||||
|
||||
var (
|
||||
PowerStatus = Attribute("pwState")
|
||||
SystemDescription = Attribute("sysDesc")
|
||||
SystemRevision = Attribute("sysRev")
|
||||
HostName = Attribute("hostName")
|
||||
OSName = Attribute("osName")
|
||||
OSVersion = Attribute("osVersion")
|
||||
ServiceTag = Attribute("svcTag")
|
||||
ExpServiceCode = Attribute("expSvcCode")
|
||||
BiosVersion = Attribute("biosVer")
|
||||
FirmwareVersion = Attribute("fwVersion")
|
||||
LCCFirmwareVersion = Attribute("LCCfwVersion")
|
||||
IPV4Enabled = Attribute("v4Enabled")
|
||||
IPV4Address = Attribute("v4IPAddr")
|
||||
IPV6Enabled = Attribute("v6Enabled")
|
||||
IPV6LinkLocal = Attribute("v6LinkLocal")
|
||||
IPV6Address = Attribute("v6Addr")
|
||||
IPV6SiteLocal = Attribute("v6SiteLocal")
|
||||
MacAddress = Attribute("macAddr")
|
||||
Batteries = Attribute("batteries")
|
||||
FanRedundancy = Attribute("fansRedundancy")
|
||||
Fans = Attribute("fans")
|
||||
Intrusion = Attribute("intrusion")
|
||||
PowerSupplyRedundancy = Attribute("psRedundancy")
|
||||
PowerSupplies = Attribute("powerSupplies")
|
||||
RMVRedundancy = Attribute("rmvsRedundancy")
|
||||
RemovableStorage = Attribute("removableStorage")
|
||||
Temperatures = Attribute("temperatures")
|
||||
Voltages = Attribute("voltages")
|
||||
KVMEnabled = Attribute("kvmEnabled")
|
||||
PowerBudgetData = Attribute("budgetpowerdata")
|
||||
EventLog = Attribute("eventLogEntries")
|
||||
BootOnce = Attribute("vmBootOnce")
|
||||
FirstBootDevice = Attribute("firstBootDevice")
|
||||
VFKLicense = Attribute("vfkLicense")
|
||||
User = Attribute("user")
|
||||
IDRACLog = Attribute("racLogEntries")
|
||||
|
||||
PowerOff = PowerState(0)
|
||||
PowerOn = PowerState(1)
|
||||
ColdReboot = PowerState(2)
|
||||
WarmReboot = PowerState(3)
|
||||
NonMaskingInterrupt = PowerState(4)
|
||||
GracefulShutdown = PowerState(5)
|
||||
|
||||
NoOverride = BootDevice(0)
|
||||
PXE = BootDevice(1)
|
||||
HardDrive = BootDevice(2)
|
||||
BIOS = BootDevice(6)
|
||||
VirtualCD = BootDevice(8)
|
||||
LocalSD = BootDevice(16)
|
||||
LocalCD = BootDevice(5)
|
||||
)
|
||||
|
||||
type Attribute string
|
||||
type PowerState uint8
|
||||
type BootDevice uint8
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
|
||||
type Credential struct {
|
||||
Host string
|
||||
Username string
|
||||
AuthToken string
|
||||
}
|
||||
|
||||
|
|
|
|||
20
main.go
20
main.go
|
|
@ -12,11 +12,12 @@ import (
|
|||
|
||||
var (
|
||||
commands = map[string]func(map[string][]string) error{
|
||||
"login": loginAction,
|
||||
"logout": logoutAction,
|
||||
"power": powerStateAction,
|
||||
"query": queryAction,
|
||||
"help": helpAction,
|
||||
"login": loginAction,
|
||||
"logout": logoutAction,
|
||||
"console": consoleAction,
|
||||
"power": powerStateAction,
|
||||
"query": queryAction,
|
||||
"help": helpAction,
|
||||
}
|
||||
|
||||
queryHelp = []Attribute{
|
||||
|
|
@ -172,6 +173,15 @@ func queryAction(args map[string][]string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func consoleAction(args map[string][]string) error {
|
||||
c, err := NewFromCredentials(".")
|
||||
if err != nil || os.IsNotExist(err) {
|
||||
return errors.New("you are already logged in")
|
||||
}
|
||||
|
||||
return c.OpenConsole()
|
||||
}
|
||||
|
||||
func loginAction(args map[string][]string) error {
|
||||
u, ok1 := args["u"]
|
||||
p, ok2 := args["p"]
|
||||
|
|
|
|||
Loading…
Reference in New Issue