Rev 24 | Rev 26 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 24 | Rev 25 | ||
---|---|---|---|
Line 65... | Line 65... | ||
65 | else if ($x >= 0 /* 0000 */) $variant = 0; |
65 | else if ($x >= 0 /* 0000 */) $variant = 0; |
66 | else $variant = -1; // should not happen |
66 | else $variant = -1; // should not happen |
67 | 67 | ||
68 | switch ($variant) { |
68 | switch ($variant) { |
69 | case 0: |
69 | case 0: |
70 | echo sprintf("%-24s %s\n", "Variant:", "[0xx] NCS (reserved for backward compatibility)"); |
70 | echo sprintf("%-32s %s\n", "Variant:", "[0xx] NCS (reserved for backward compatibility)"); |
71 | 71 | ||
72 | /* |
72 | /* |
73 | * Internal structure of variant #0 UUIDs |
73 | * Internal structure of variant #0 UUIDs |
74 | * |
74 | * |
75 | * The first 6 octets are the number of 4 usec units of time that have |
75 | * The first 6 octets are the number of 4 usec units of time that have |
Line 110... | Line 110... | ||
110 | $ms = gmp_mod($ts, gmp_init("250000")); |
110 | $ms = gmp_mod($ts, gmp_init("250000")); |
111 | $ts = gmp_div($ts, gmp_init("250000")); |
111 | $ts = gmp_div($ts, gmp_init("250000")); |
112 | $ts = gmp_strval($ts); |
112 | $ts = gmp_strval($ts); |
113 | $ms = gmp_strval($ms); |
113 | $ms = gmp_strval($ms); |
114 | $ts = gmdate('Y-m-d H:i:s', intval($ts))."'".str_pad($ms, 7, '0', STR_PAD_LEFT).' GMT'; |
114 | $ts = gmdate('Y-m-d H:i:s', intval($ts))."'".str_pad($ms, 7, '0', STR_PAD_LEFT).' GMT'; |
115 | echo sprintf("%-24s %s\n", "Timestamp:", "[0x$timestamp] $ts"); |
115 | echo sprintf("%-32s %s\n", "Timestamp:", "[0x$timestamp] $ts"); |
116 | 116 | ||
117 | $reserved = substr($uuid, 12, 4); |
117 | $reserved = substr($uuid, 12, 4); |
118 | echo sprintf("%-24s %s\n", "Reserved:", "0x$reserved"); |
118 | echo sprintf("%-32s %s\n", "Reserved:", "0x$reserved"); |
119 | 119 | ||
120 | # Family 13 (dds) looks like node is 00 | nnnnnn 000000. |
120 | # Family 13 (dds) looks like node is 00 | nnnnnn 000000. |
121 | # Family 2 is presumably (ip). |
121 | # Family 2 is presumably (ip). |
122 | # Not sure if anything else was used. |
122 | # Not sure if anything else was used. |
123 | $family_hex = substr($uuid, 16, 2); |
123 | $family_hex = substr($uuid, 16, 2); |
Line 127... | Line 127... | ||
127 | } else if ($family_dec == 13) { |
127 | } else if ($family_dec == 13) { |
128 | $family_ = 'DDS (Data Link)'; |
128 | $family_ = 'DDS (Data Link)'; |
129 | } else { |
129 | } else { |
130 | $family_ = "Unknown ($family_dec)"; # There are probably no more families |
130 | $family_ = "Unknown ($family_dec)"; # There are probably no more families |
131 | } |
131 | } |
132 | echo sprintf("%-24s %s\n", "Family:", "[0x$family_hex = $family_dec] $family_"); |
132 | echo sprintf("%-32s %s\n", "Family:", "[0x$family_hex = $family_dec] $family_"); |
133 | 133 | ||
134 | $nodeid = substr($uuid, 18, 14); |
134 | $nodeid = substr($uuid, 18, 14); |
135 | echo sprintf("%-24s %s\n", "Node ID:", "0x$nodeid"); |
135 | echo sprintf("%-32s %s\n", "Node ID:", "0x$nodeid"); |
136 | # TODO: interprete node id (the family specifies it) |
136 | # TODO: interprete node id (the family specifies it) |
137 | 137 | ||
138 | break; |
138 | break; |
139 | case 1: |
139 | case 1: |
140 | echo sprintf("%-24s %s\n", "Variant:", "[10x] RFC 4122 (Leach-Mealling-Salz)"); |
140 | echo sprintf("%-32s %s\n", "Variant:", "[10x] RFC 4122 (Leach-Mealling-Salz)"); |
141 | 141 | ||
142 | $version = hexdec(substr($uuid, 12, 1)); |
142 | $version = hexdec(substr($uuid, 12, 1)); |
143 | switch ($version) { |
143 | switch ($version) { |
144 | case 1: |
144 | case 1: |
145 | echo sprintf("%-24s %s\n", "Version:", "[1] Time-based with unique random host identifier"); |
145 | echo sprintf("%-32s %s\n", "Version:", "[1] Time-based with unique random host identifier"); |
146 | 146 | ||
147 | # Timestamp: Count of 100ns intervals since 15 Oct 1582 00:00:00 |
147 | # Timestamp: Count of 100ns intervals since 15 Oct 1582 00:00:00 |
148 | # 1/0,0000001 = 10000000 |
148 | # 1/0,0000001 = 10000000 |
149 | $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).substr($uuid, 0, 8); |
149 | $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).substr($uuid, 0, 8); |
150 | $ts = gmp_init($timestamp, 16); |
150 | $ts = gmp_init($timestamp, 16); |
Line 152... | Line 152... | ||
152 | $ms = gmp_mod($ts, gmp_init("10000000")); |
152 | $ms = gmp_mod($ts, gmp_init("10000000")); |
153 | $ts = gmp_div($ts, gmp_init("10000000")); |
153 | $ts = gmp_div($ts, gmp_init("10000000")); |
154 | $ts = gmp_strval($ts); |
154 | $ts = gmp_strval($ts); |
155 | $ms = gmp_strval($ms); |
155 | $ms = gmp_strval($ms); |
156 | $ts = gmdate('Y-m-d H:i:s', intval($ts))."'".str_pad($ms, 7, '0', STR_PAD_LEFT).' GMT'; |
156 | $ts = gmdate('Y-m-d H:i:s', intval($ts))."'".str_pad($ms, 7, '0', STR_PAD_LEFT).' GMT'; |
157 | echo sprintf("%-24s %s\n", "Timestamp:", "[0x$timestamp] $ts"); |
157 | echo sprintf("%-32s %s\n", "Timestamp:", "[0x$timestamp] $ts"); |
158 | 158 | ||
159 | $x = hexdec(substr($uuid, 16, 4)); |
159 | $x = hexdec(substr($uuid, 16, 4)); |
160 | $dec = $x & 0x3FFF; // The highest 2 bits are used by "variant" (10x) |
160 | $dec = $x & 0x3FFF; // The highest 2 bits are used by "variant" (10x) |
161 | $hex = substr($uuid, 16, 4); |
161 | $hex = substr($uuid, 16, 4); |
162 | echo sprintf("%-24s %s\n", "Clock ID:", "[0x$hex] $dec"); |
162 | echo sprintf("%-32s %s\n", "Clock ID:", "[0x$hex] $dec"); |
163 | 163 | ||
164 | $x = substr($uuid, 20, 12); |
164 | $x = substr($uuid, 20, 12); |
165 | $nodeid = ''; |
165 | $nodeid = ''; |
166 | for ($i=0; $i<6; $i++) { |
166 | for ($i=0; $i<6; $i++) { |
167 | $nodeid .= substr($x, $i*2, 2); |
167 | $nodeid .= substr($x, $i*2, 2); |
168 | if ($i != 5) $nodeid .= ':'; |
168 | if ($i != 5) $nodeid .= '-'; |
169 | } |
169 | } |
170 | echo sprintf("%-24s %s\n", "Node ID:", "$nodeid"); |
170 | echo sprintf("%-32s %s\n", "Node ID:", "$nodeid"); |
171 | 171 | ||
172 | if (function_exists('decode_mac')) { |
172 | if (function_exists('decode_mac')) { |
173 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n"; |
173 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n\n"; |
174 | decode_mac($nodeid); |
174 | decode_mac($nodeid); |
175 | } |
175 | } |
176 | 176 | ||
177 | break; |
177 | break; |
178 | case 2: |
178 | case 2: |
179 | echo sprintf("%-24s %s\n", "Version:", "[2] DCE Security version"); |
179 | echo sprintf("%-32s %s\n", "Version:", "[2] DCE Security version"); |
180 | 180 | ||
181 | # The time_low field (which represents an integer in the range [0, 232-1]) is interpreted as a local-ID; that is, an identifier (within the domain specified by clock_seq_low) meaningful to the local host. In the particular case of a POSIX host, when combined with a POSIX UID or POSIX GID domain in the clock_seq_low field (above), the time_low field represents a POSIX UID or POSIX GID, respectively. |
181 | # The time_low field (which represents an integer in the range [0, 232-1]) is interpreted as a local-ID; that is, an identifier (within the domain specified by clock_seq_low) meaningful to the local host. In the particular case of a POSIX host, when combined with a POSIX UID or POSIX GID domain in the clock_seq_low field (above), the time_low field represents a POSIX UID or POSIX GID, respectively. |
182 | $x = substr($uuid, 0, 8); |
182 | $x = substr($uuid, 0, 8); |
183 | echo sprintf("%-24s %s\n", "Local ID:", "0x$x"); |
183 | echo sprintf("%-32s %s\n", "Local ID:", "0x$x"); |
184 | 184 | ||
185 | # The clock_seq_low field (which represents an integer in the range [0, 28-1]) is interpreted as a local domain (as represented by sec_rgy_domain_t; see sec_rgy_domain_t ); that is, an identifier domain meaningful to the local host. (Note that the data type sec_rgy_domain_t can potentially hold values outside the range [0, 28-1]; however, the only values currently registered are in the range [0, 2], so this type mismatch is not significant.) In the particular case of a POSIX host, the value sec_rgy_domain_person is to be interpreted as the "POSIX UID domain", and the value sec_rgy_domain_group is to be interpreted as the "POSIX GID domain". |
185 | # The clock_seq_low field (which represents an integer in the range [0, 28-1]) is interpreted as a local domain (as represented by sec_rgy_domain_t; see sec_rgy_domain_t ); that is, an identifier domain meaningful to the local host. (Note that the data type sec_rgy_domain_t can potentially hold values outside the range [0, 28-1]; however, the only values currently registered are in the range [0, 2], so this type mismatch is not significant.) In the particular case of a POSIX host, the value sec_rgy_domain_person is to be interpreted as the "POSIX UID domain", and the value sec_rgy_domain_group is to be interpreted as the "POSIX GID domain". |
186 | $x = substr($uuid, 18, 2); |
186 | $x = substr($uuid, 18, 2); |
187 | if ($x == '00') $domain_info = 'POSIX: User-ID / Non-POSIX: site-defined'; |
187 | if ($x == '00') $domain_info = 'POSIX: User-ID / Non-POSIX: site-defined'; |
188 | else if ($x == '01') $domain_info = 'POSIX: Group-ID / Non-POSIX: site-defined'; |
188 | else if ($x == '01') $domain_info = 'POSIX: Group-ID / Non-POSIX: site-defined'; |
189 | else $domain_info = 'site-defined'; |
189 | else $domain_info = 'site-defined'; |
190 | echo sprintf("%-24s %s\n", "Local Domain:", "0x$x ($domain_info)"); |
190 | echo sprintf("%-32s %s\n", "Local Domain:", "0x$x ($domain_info)"); |
191 | 191 | ||
192 | # Timestamp: Count of 100ns intervals since 15 Oct 1582 00:00:00 |
192 | # Timestamp: Count of 100ns intervals since 15 Oct 1582 00:00:00 |
193 | # 1/0,0000001 = 10000000 |
193 | # 1/0,0000001 = 10000000 |
194 | $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).'00000000'; |
194 | $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).'00000000'; |
195 | $ts = gmp_init($timestamp, 16); |
195 | $ts = gmp_init($timestamp, 16); |
Line 208... | Line 208... | ||
208 | $ts = gmp_strval($ts); |
208 | $ts = gmp_strval($ts); |
209 | $ms = gmp_strval($ms); |
209 | $ms = gmp_strval($ms); |
210 | $ts_max = gmdate('Y-m-d H:i:s', intval($ts))."'".str_pad($ms, 7, '0', STR_PAD_LEFT).' GMT'; |
210 | $ts_max = gmdate('Y-m-d H:i:s', intval($ts))."'".str_pad($ms, 7, '0', STR_PAD_LEFT).' GMT'; |
211 | 211 | ||
212 | $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).'xxxxxxxx'; |
212 | $timestamp = substr($uuid, 13, 3).substr($uuid, 8, 4).'xxxxxxxx'; |
213 | echo sprintf("%-24s %s\n", "Timestamp:", "[0x$timestamp] $ts_min - $ts_max"); |
213 | echo sprintf("%-32s %s\n", "Timestamp:", "[0x$timestamp] $ts_min - $ts_max"); |
214 | 214 | ||
215 | $x = hexdec(substr($uuid, 16, 2).'00'); |
215 | $x = hexdec(substr($uuid, 16, 2).'00'); |
216 | $dec_min = $x & 0x3FFF; // The highest 2 bits are used by "variant" (10x) |
216 | $dec_min = $x & 0x3FFF; // The highest 2 bits are used by "variant" (10x) |
217 | $x = hexdec(substr($uuid, 16, 2).'FF'); |
217 | $x = hexdec(substr($uuid, 16, 2).'FF'); |
218 | $dec_max = $x & 0x3FFF; // The highest 2 bits are used by "variant" (10x) |
218 | $dec_max = $x & 0x3FFF; // The highest 2 bits are used by "variant" (10x) |
219 | $hex = substr($uuid, 16, 2).'xx'; |
219 | $hex = substr($uuid, 16, 2).'xx'; |
220 | echo sprintf("%-24s %s\n", "Clock ID:", "[0x$hex] $dec_min - $dec_max"); |
220 | echo sprintf("%-32s %s\n", "Clock ID:", "[0x$hex] $dec_min - $dec_max"); |
221 | 221 | ||
222 | $x = substr($uuid, 20, 12); |
222 | $x = substr($uuid, 20, 12); |
223 | $nodeid = ''; |
223 | $nodeid = ''; |
224 | for ($i=0; $i<6; $i++) { |
224 | for ($i=0; $i<6; $i++) { |
225 | $nodeid .= substr($x, $i*2, 2); |
225 | $nodeid .= substr($x, $i*2, 2); |
226 | if ($i != 5) $nodeid .= ':'; |
226 | if ($i != 5) $nodeid .= '-'; |
227 | } |
227 | } |
228 | echo sprintf("%-24s %s\n", "Node ID:", "$nodeid"); |
228 | echo sprintf("%-32s %s\n", "Node ID:", "$nodeid"); |
229 | 229 | ||
230 | if (function_exists('decode_mac')) { |
230 | if (function_exists('decode_mac')) { |
231 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n"; |
231 | echo "\nIn case that this Node ID is a MAC address, here is the interpretation of that MAC address:\n\n"; |
232 | decode_mac($nodeid); |
232 | decode_mac($nodeid); |
233 | } |
233 | } |
234 | 234 | ||
235 | break; |
235 | break; |
236 | case 3: |
236 | case 3: |
237 | echo sprintf("%-24s %s\n", "Version:", "[3] Name-based (MD5 hash)"); |
237 | echo sprintf("%-32s %s\n", "Version:", "[3] Name-based (MD5 hash)"); |
238 | 238 | ||
239 | $hash = str_replace('-', '', strtolower($uuid)); |
239 | $hash = str_replace('-', '', strtolower($uuid)); |
240 | $hash[12] = '?'; // was overwritten by version |
240 | $hash[12] = '?'; // was overwritten by version |
241 | $hash[16] = '?'; // was partially overwritten by variant |
241 | $hash[16] = '?'; // was partially overwritten by variant |
242 | 242 | ||
243 | echo sprintf("%-24s %s\n", "MD5(Namespace+Subject):", "$hash"); |
243 | echo sprintf("%-32s %s\n", "MD5(Namespace+Subject):", "$hash"); |
244 | 244 | ||
245 | break; |
245 | break; |
246 | case 4: |
246 | case 4: |
247 | echo sprintf("%-24s %s\n", "Version:", "[4] Random"); |
247 | echo sprintf("%-32s %s\n", "Version:", "[4] Random"); |
248 | 248 | ||
- | 249 | $rand_line1 = ''; |
|
249 | $rand = ''; |
250 | $rand_line2 = ''; |
250 | for ($i=0; $i<16; $i++) { |
251 | for ($i=0; $i<16; $i++) { |
251 | $bin = base_convert(substr($uuid, $i*2, 2), 16, 2); |
252 | $bin = base_convert(substr($uuid, $i*2, 2), 16, 2); |
252 | $bin = str_pad($bin, 8, "0", STR_PAD_LEFT); |
253 | $bin = str_pad($bin, 8, "0", STR_PAD_LEFT); |
253 | 254 | ||
254 | if ($i == 6) { |
255 | if ($i == 6) { |
- | 256 | // was overwritten by version |
|
255 | $bin[0] = 'x'; |
257 | $bin[0] = '?'; |
256 | $bin[1] = 'x'; |
258 | $bin[1] = '?'; |
- | 259 | $bin[2] = '?'; |
|
- | 260 | $bin[3] = '?'; |
|
257 | } else if ($i == 8) { |
261 | } else if ($i == 8) { |
258 | $bin[0] = 'x'; |
262 | // was partially overwritten by variant |
259 | $bin[1] = 'x'; |
263 | $bin[0] = '?'; |
260 | $bin[2] = 'x'; |
264 | $bin[1] = '?'; |
261 | $bin[3] = 'x'; |
- | |
262 | } |
265 | } |
263 | 266 | ||
264 | $rand .= "$bin "; |
267 | if ($i<8) $rand_line1 .= "$bin "; |
- | 268 | if ($i>=8) $rand_line2 .= "$bin "; |
|
265 | } |
269 | } |
266 | 270 | ||
267 | echo sprintf("%-24s %s\n", "Random bits:", trim($rand)); |
271 | echo sprintf("%-32s %s\n", "Random bits:", trim($rand_line1)); |
- | 272 | echo sprintf("%-32s %s\n", "", trim($rand_line2)); |
|
268 | 273 | ||
269 | break; |
274 | break; |
270 | case 5: |
275 | case 5: |
271 | echo sprintf("%-24s %s\n", "Version:", "[5] Name-based (SHA-1 hash)"); |
276 | echo sprintf("%-32s %s\n", "Version:", "[5] Name-based (SHA-1 hash)"); |
272 | 277 | ||
273 | $hash = str_replace('-', '', strtolower($uuid)); |
278 | $hash = str_replace('-', '', strtolower($uuid)); |
274 | $hash[12] = '?'; // was overwritten by version |
279 | $hash[12] = '?'; // was overwritten by version |
275 | $hash[16] = '?'; // was partially overwritten by variant |
280 | $hash[16] = '?'; // was partially overwritten by variant |
276 | $hash .= '????????'; // was cut off |
281 | $hash .= '????????'; // was cut off |
277 | 282 | ||
278 | echo sprintf("%-24s %s\n", "SHA1(Namespace+Subject):", "$hash"); |
283 | echo sprintf("%-32s %s\n", "SHA1(Namespace+Subject):", "$hash"); |
279 | 284 | ||
280 | 285 | ||
281 | break; |
286 | break; |
282 | default: |
287 | default: |
283 | echo sprintf("%-24s %s\n", "Version:", "[$version] Unknown"); |
288 | echo sprintf("%-32s %s\n", "Version:", "[$version] Unknown"); |
284 | break; |
289 | break; |
285 | } |
290 | } |
286 | 291 | ||
287 | break; |
292 | break; |
288 | case 2: |
293 | case 2: |
289 | echo sprintf("%-24s %s\n", "Variant:", "[110] Reserved for Microsoft Corporation"); |
294 | echo sprintf("%-32s %s\n", "Variant:", "[110] Reserved for Microsoft Corporation"); |
290 | break; |
295 | break; |
291 | case 3: |
296 | case 3: |
292 | echo sprintf("%-24s %s\n", "Variant:", "[111] Reserved for future use"); |
297 | echo sprintf("%-32s %s\n", "Variant:", "[111] Reserved for future use"); |
293 | break; |
298 | break; |
294 | } |
299 | } |
295 | } |
300 | } |
296 | 301 | ||
297 | function uuid_canonize($uuid) { |
302 | function uuid_canonize($uuid) { |
Line 423... | Line 428... | ||
423 | /* |
428 | /* |
424 | * Node should be set to the 48-bit IEEE node identifier |
429 | * Node should be set to the 48-bit IEEE node identifier |
425 | */ |
430 | */ |
426 | $mac = get_mac_address(); |
431 | $mac = get_mac_address(); |
427 | if ($mac) { |
432 | if ($mac) { |
428 | $node = str_replace(':','',$mac); |
433 | $node = str_replace('-','',str_replace(':','',$mac)); |
429 | for ($i = 0; $i < 6; $i++) { |
434 | for ($i = 0; $i < 6; $i++) { |
430 | $uuid['node'][$i] = hexdec(substr($node, $i*2, 2)); |
435 | $uuid['node'][$i] = hexdec(substr($node, $i*2, 2)); |
431 | } |
436 | } |
432 | 437 | ||
433 | /* |
438 | /* |
Line 466... | Line 471... | ||
466 | exec($cmd, $out, $ec); |
471 | exec($cmd, $out, $ec); |
467 | if ($ec == 0) { |
472 | if ($ec == 0) { |
468 | $out = implode("\n",$out); |
473 | $out = implode("\n",$out); |
469 | $m = array(); |
474 | $m = array(); |
470 | if (preg_match("/([0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2})/ismU", $out, $m)) { |
475 | if (preg_match("/([0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2}\\-[0-9a-f]{2})/ismU", $out, $m)) { |
471 | $detected_mac = str_replace('-', ':', strtolower($m[1])); |
476 | $detected_mac = strtolower($m[1]); |
472 | return $detected_mac; |
477 | return $detected_mac; |
473 | } |
478 | } |
474 | } |
479 | } |
475 | } |
480 | } |
476 | } else if (strtoupper(PHP_OS) == 'DARWIN') { |
481 | } else if (strtoupper(PHP_OS) == 'DARWIN') { |