Rev 16 | Rev 33 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 16 | Rev 27 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | <?php |
1 | <?php |
2 | 2 | ||
3 | /* |
3 | /* |
4 | * UUID utils for PHP |
4 | * UUID utils for PHP |
5 | * Copyright 2011 - 2021 Daniel Marschall, ViaThinkSoft |
5 | * Copyright 2011 - 2022 Daniel Marschall, ViaThinkSoft |
6 | * Version 2021-05-21 |
6 | * Version 2022-01-06 |
7 | * |
7 | * |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
8 | * Licensed under the Apache License, Version 2.0 (the "License"); |
9 | * you may not use this file except in compliance with the License. |
9 | * you may not use this file except in compliance with the License. |
10 | * You may obtain a copy of the License at |
10 | * You may obtain a copy of the License at |
11 | * |
11 | * |
Line 160... | Line 160... | ||
160 | } |
160 | } |
161 | echo sprintf("%-24s %s\n", "Node ID:", "$nodeid"); |
161 | echo sprintf("%-24s %s\n", "Node ID:", "$nodeid"); |
162 | 162 | ||
163 | if (function_exists('decode_mac')) { |
163 | if (function_exists('decode_mac')) { |
164 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n"; |
164 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n"; |
165 | echo decode_mac($nodeid); /** @phpstan-ignore-line */ |
165 | echo decode_mac($nodeid); |
166 | } |
166 | } |
167 | 167 | ||
168 | break; |
168 | break; |
169 | case 2: |
169 | case 2: |
170 | echo sprintf("%-24s %s\n", "Version:", "[2] DCE Security version"); |
170 | echo sprintf("%-24s %s\n", "Version:", "[2] DCE Security version"); |
Line 218... | Line 218... | ||
218 | } |
218 | } |
219 | echo sprintf("%-24s %s\n", "Node ID:", "$nodeid"); |
219 | echo sprintf("%-24s %s\n", "Node ID:", "$nodeid"); |
220 | 220 | ||
221 | if (function_exists('decode_mac')) { |
221 | if (function_exists('decode_mac')) { |
222 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n"; |
222 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n"; |
223 | echo decode_mac($nodeid); /** @phpstan-ignore-line */ |
223 | echo decode_mac($nodeid); |
224 | } |
224 | } |
225 | 225 | ||
226 | break; |
226 | break; |
227 | case 3: |
227 | case 3: |
228 | echo sprintf("%-24s %s\n", "Version:", "[3] Name-based (MD5 hash)"); |
228 | echo sprintf("%-24s %s\n", "Version:", "[3] Name-based (MD5 hash)"); |
Line 291... | Line 291... | ||
291 | } |
291 | } |
292 | 292 | ||
293 | function oid_to_uuid($oid) { |
293 | function oid_to_uuid($oid) { |
294 | if (!is_uuid_oid($oid)) return false; |
294 | if (!is_uuid_oid($oid)) return false; |
295 | 295 | ||
296 | if ($oid[0] == '.') { |
296 | if (substr($oid,0,1) == '.') { |
297 | $oid = substr($oid, 1); |
297 | $oid = substr($oid, 1); |
298 | } |
298 | } |
299 | $ary = explode('.', $oid); |
299 | $ary = explode('.', $oid); |
300 | 300 | ||
301 | if (!isset($ary[2])) return false; |
301 | if (!isset($ary[2])) return false; |
Line 311... | Line 311... | ||
311 | substr($y, 16, 4).'-'. |
311 | substr($y, 16, 4).'-'. |
312 | substr($y, 20, 12); |
312 | substr($y, 20, 12); |
313 | } |
313 | } |
314 | 314 | ||
315 | function is_uuid_oid($oid, $only_allow_root=false) { |
315 | function is_uuid_oid($oid, $only_allow_root=false) { |
316 | if ($oid[0] == '.') $oid = substr($oid, 1); // remove leading dot |
316 | if (substr($oid,0,1) == '.') $oid = substr($oid, 1); // remove leading dot |
317 | 317 | ||
318 | $ary = explode('.', $oid); |
318 | $ary = explode('.', $oid); |
319 | 319 | ||
320 | if ($only_allow_root) { |
320 | if ($only_allow_root) { |
321 | if (count($ary) != 3) return false; |
321 | if (count($ary) != 3) return false; |
Line 483... | Line 483... | ||
483 | } |
483 | } |
484 | } |
484 | } |
485 | } |
485 | } |
486 | } else { |
486 | } else { |
487 | // Linux |
487 | // Linux |
488 | foreach (glob('/sys/class/net/'.'*'.'/address') as $x) { |
488 | $addresses = @glob('/sys/class/net/'.'*'.'/address'); |
- | 489 | foreach ($addresses as $x) { |
|
489 | if (!strstr($x,'/lo/')) { |
490 | if (!strstr($x,'/lo/')) { |
490 | $detected_mac = trim(file_get_contents($x)); |
491 | $detected_mac = trim(file_get_contents($x)); |
491 | return $detected_mac; |
492 | return $detected_mac; |
492 | } |
493 | } |
493 | } |
494 | } |