diff --git a/lib/Machine.lib.php b/lib/Machine.lib.php index 716fc8f..fded1b6 100644 --- a/lib/Machine.lib.php +++ b/lib/Machine.lib.php @@ -35,6 +35,31 @@ class Machine { return $database->has('machines', ['machineid' => $id]); } + /** + * Check if a given serial number can identify exactly one machine. + * @global $database $database + * @param type $serial + * @return bool + */ + public static function serialExists(string $serial): bool { + global $database; + return $database->has('machines', ['serial' => $serial]) && $database->count('machines', ['serial' => $serial]) == 1; + } + + /** + * Convert a serial into a machine ID. + * @global $database $database + * @param string $serial + * @return string|bool machine ID if found, otherwise false. + */ + public static function getIDFromSerial(string $serial) { + global $database; + if (Machine::serialExists($serial)) { + return $database->get('machines', 'machineid', ['serial' => $serial]) . ""; + } + return false; + } + public function save() { global $database; if ($this->exists) { diff --git a/public/index.php b/public/index.php index 2eaccb1..ca185d8 100644 --- a/public/index.php +++ b/public/index.php @@ -23,7 +23,7 @@ require_once __DIR__ . "/../lib/required_public.php";

@@ -33,7 +33,7 @@ require_once __DIR__ . "/../lib/required_public.php";

No machine with ID could be found.