Update supermicro.php

This commit is contained in:
Volker 2021-06-29 09:44:18 +02:00 committed by GitHub
parent a370366996
commit 82a0633afc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,43 +1,34 @@
<?php <?php
class Supermicro { class Supermicro {
private function getBin($hexdata) const SUPERMICRO_OOB_PRIVATE_KEY_HEX = '8544E3B47ECA58F9583043F8';
{
$bindata = ""; /**
for ($i = 0;$i < strlen($hexdata);$i += 2) { * @param string $BMC_MAC
$bindata .= chr(hexdec(substr($hexdata, $i, 2))); * @return string
} */
return $bindata; public function getLicense(string $BMC_MAC, bool $source = false)
} {
$key = $this->getKey($BMC_MAC);
private function getKey($dmac) return $source ? $key : implode(
{ ' - ',
return substr(hash_hmac("sha1", $this->getBin($dmac), hex2bin('8544E3B47ECA58F9583043F8')), 0, 24); array_slice(
} str_split(
$key, 4
public function getLicense($mac, $source = false) ), 0, 6
{ )
$mac = str_replace(":", "", $mac); );
if(preg_match("/^[a-z0-9]{12}$/", $mac)) { }
$key = $this->getKey($mac);
if(empty($key)) { protected function getKey(string $BMC_MAC)
return false; {
} return hash_hmac(
if($source) { 'sha1',
return $key; hex2bin(
} preg_replace(
$s = 0; '![^A-F0-9]!i', '', $BMC_MAC
$result = ""; )
for($i = 0;$i < strlen($key);$i++) { ), hex2bin(self::SUPERMICRO_OOB_PRIVATE_KEY_HEX)
$s++; );
$result .= $key[$i]; }
if($s == 4 && $i !== strlen($key) - 1) {
$result .= "-";
$s = 0;
}
}
return $result;
}
return false;
}
} }