Subversion Repositories uuid_mac_utils

Rev

Rev 4 | Rev 9 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4 Rev 8
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 - 2021 Daniel Marschall, ViaThinkSoft
6
 * Version 2021-05-21
6
 * Version 2021-12-29
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 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
                }