o2system /
security
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the O2System Framework package. |
||
| 4 | * |
||
| 5 | * For the full copyright and license information, please view the LICENSE |
||
| 6 | * file that was distributed with this source code. |
||
| 7 | * |
||
| 8 | * @author Steeve Andrian Salim |
||
| 9 | * @copyright Copyright (c) Steeve Andrian Salim |
||
| 10 | */ |
||
| 11 | |||
| 12 | /** |
||
| 13 | * Created by PhpStorm. |
||
| 14 | * User: steevenz |
||
| 15 | * Date: 05/04/18 |
||
| 16 | * Time: 10.11 |
||
| 17 | */ |
||
| 18 | |||
| 19 | namespace O2System\Security\Generators; |
||
| 20 | |||
| 21 | use O2System\Kernel\Http\Message\Uri; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Class MachineId |
||
| 25 | * |
||
| 26 | * Generate Machine ID based on System Metadata information in UUID (Universally Unique Identifier) format. |
||
| 27 | * |
||
| 28 | * @package O2System\Security\Generators |
||
| 29 | */ |
||
| 30 | class MachineId |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * MachineId::generate |
||
| 34 | * |
||
| 35 | * @return string |
||
| 36 | */ |
||
| 37 | public static function generate() |
||
| 38 | { |
||
| 39 | if (class_exists('O2System\Filesystem\System')) { |
||
| 40 | $system = new \O2System\Filesystem\System(); |
||
|
0 ignored issues
–
show
|
|||
| 41 | |||
| 42 | $metadata = [ |
||
| 43 | 'machine' => $system->getMachine(), |
||
| 44 | 'operatingSystem' => [ |
||
| 45 | 'name' => $system->getName(), |
||
| 46 | 'version' => $system->getVersion(), |
||
| 47 | 'release' => $system->getRelease(), |
||
| 48 | ], |
||
| 49 | 'hostname' => $system->getHostname(), |
||
| 50 | 'cpuCores' => $system->getCpuCores(), |
||
| 51 | 'macAddress' => $system->getMacAddress(), |
||
| 52 | ]; |
||
| 53 | } else { |
||
| 54 | $metadata = [ |
||
| 55 | 'machine' => php_uname('m'), |
||
| 56 | 'operatingSystem' => [ |
||
| 57 | 'name' => php_uname('s'), |
||
| 58 | 'version' => php_uname('v'), |
||
| 59 | 'release' => php_uname('r'), |
||
| 60 | ], |
||
| 61 | 'hostname' => php_uname('n'), |
||
| 62 | 'cpuCores' => 1, |
||
| 63 | 'macAddress' => implode(':', str_split(substr(md5('none'), 0, 12), 2)), |
||
| 64 | ]; |
||
| 65 | } |
||
| 66 | |||
| 67 | $uri = new Uri(); |
||
| 68 | |||
| 69 | $metadata[ 'domain' ] = $uri->getHost(); |
||
| 70 | $metadata[ 'ipAddress' ] = $_SERVER[ 'SERVER_ADDR' ]; |
||
| 71 | |||
| 72 | $string = json_encode($metadata); |
||
| 73 | $string = md5($string); |
||
| 74 | |||
| 75 | // Converts to UUID (Universally Unique Identifier) |
||
| 76 | $parts[] = substr($string, 0, 8); |
||
|
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
|
|||
| 77 | $parts[] = substr($string, 8, 4); |
||
| 78 | $parts[] = substr($string, 12, 4); |
||
| 79 | $parts[] = substr($string, 16, 4); |
||
| 80 | $parts[] = substr($string, 20, 12); |
||
| 81 | |||
| 82 | $parts = array_map('strtoupper', $parts); |
||
| 83 | |||
| 84 | return implode('-', $parts); |
||
| 85 | } |
||
| 86 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths