diff options
Diffstat (limited to 'modules-available/rebootcontrol/inc')
-rw-r--r-- | modules-available/rebootcontrol/inc/rebootqueries.inc.php | 44 | ||||
-rw-r--r-- | modules-available/rebootcontrol/inc/sshkey.inc.php | 40 |
2 files changed, 84 insertions, 0 deletions
diff --git a/modules-available/rebootcontrol/inc/rebootqueries.inc.php b/modules-available/rebootcontrol/inc/rebootqueries.inc.php new file mode 100644 index 00000000..df3c13d8 --- /dev/null +++ b/modules-available/rebootcontrol/inc/rebootqueries.inc.php @@ -0,0 +1,44 @@ +<?php + +class RebootQueries +{ + + // Get Client+IP+CurrentVM+CurrentUser+Location to fill the table + public static function getMachineTable($locationId) { + if ($locationId === 0) { + $where = 'machine.locationid IS NULL'; + } else { + $where = 'machine.locationid = :locationid'; + } + $leftJoin = ''; + $sessionField = 'machine.currentsession'; + if (Module::get('dozmod') !== false) { + // SELECT lectureid, displayname FROM sat.lecture WHERE lectureid = :lectureid + $leftJoin = 'LEFT JOIN sat.lecture ON (lecture.lectureid = machine.currentsession)'; + $sessionField = 'IFNULL(lecture.displayname, machine.currentsession) AS currentsession'; + } + $res = Database::simpleQuery(" + SELECT machine.machineuuid, machine.hostname, machine.clientip, + IF(machine.lastboot = 0 OR UNIX_TIMESTAMP() - machine.lastseen >= 600, 0, 1) AS status, + $sessionField, machine.currentuser, machine.locationid + FROM machine + $leftJoin + WHERE " . $where, array('locationid' => $locationId)); + return $res->fetchAll(PDO::FETCH_ASSOC); + } + + /** + * Get machines by list of UUIDs + * @param string[] $list list of system UUIDs + * @return array list of machines with machineuuid, clientip and locationid + */ + public static function getMachinesByUuid($list) + { + if (empty($list)) + return array(); + $qs = '?' . str_repeat(',?', count($list) - 1); + $res = Database::simpleQuery("SELECT machineuuid, clientip, locationid FROM machine WHERE machineuuid IN ($qs)", $list); + return $res->fetchAll(PDO::FETCH_ASSOC); + } + +}
\ No newline at end of file diff --git a/modules-available/rebootcontrol/inc/sshkey.inc.php b/modules-available/rebootcontrol/inc/sshkey.inc.php new file mode 100644 index 00000000..b4e36d25 --- /dev/null +++ b/modules-available/rebootcontrol/inc/sshkey.inc.php @@ -0,0 +1,40 @@ +<?php + +class SSHKey +{ + + public static function getPrivateKey() { + $privKey = Property::get("rebootcontrol-private-key"); + if (!$privKey) { + $rsaKey = openssl_pkey_new(array( + 'private_key_bits' => 2048, + 'private_key_type' => OPENSSL_KEYTYPE_RSA)); + openssl_pkey_export( openssl_pkey_get_private($rsaKey), $privKey); + Property::set("rebootcontrol-private-key", $privKey); + } + return $privKey; + } + + public static function getPublicKey() { + $pkImport = openssl_pkey_get_private(self::getPrivateKey()); + return self::sshEncodePublicKey($pkImport); + } + + private static function sshEncodePublicKey($privKey) { + $keyInfo = openssl_pkey_get_details($privKey); + $buffer = pack("N", 7) . "ssh-rsa" . + self::sshEncodeBuffer($keyInfo['rsa']['e']) . + self::sshEncodeBuffer($keyInfo['rsa']['n']); + return "ssh-rsa " . base64_encode($buffer); + } + + private static function sshEncodeBuffer($buffer) { + $len = strlen($buffer); + if (ord($buffer[0]) & 0x80) { + $len++; + $buffer = "\x00" . $buffer; + } + return pack("Na*", $len, $buffer); + } + +}
\ No newline at end of file |