├── LICENSE.md ├── README.md ├── composer.json ├── config └── linfo.php └── src ├── Linfo.php ├── LinfoServiceProvider.php └── Model.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2015 Tom Witkowski 4 | Copyright (c) 29 Sep 2016 Astrotomic 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Laravel Linfo 2 | 3 | [![Latest Version](http://img.shields.io/packagist/v/linfo/laravel.svg?label=Release&style=for-the-badge)](https://packagist.org/packages/linfo/laravel) 4 | [![MIT License](https://img.shields.io/github/license/Astrotomic/laravel-linfo.svg?label=License&color=blue&style=for-the-badge)](https://github.com/Astrotomic/laravel-linfo/blob/master/LICENSE.md) 5 | [![Offset Earth](https://img.shields.io/badge/Treeware-%F0%9F%8C%B3-green?style=for-the-badge)](https://plant.treeware.earth/Astrotomic/laravel-linfo) 6 | 7 | [![GitHub Workflow Status](https://img.shields.io/github/workflow/status/Astrotomic/laravel-linfo/run-tests?style=flat-square&logoColor=white&logo=github&label=Tests)](https://github.com/Astrotomic/laravel-linfo/actions?query=workflow%3Arun-tests) 8 | [![StyleCI](https://styleci.io/repos/42302702/shield)](https://styleci.io/repos/42302702) 9 | [![Total Downloads](https://img.shields.io/packagist/dt/linfo/laravel.svg?label=Downloads&style=flat-square)](https://packagist.org/packages/linfo/laravel) 10 | 11 | This is a Laravel 5 Wrapper for the linfo package from jrgp - https://github.com/jrgp/linfo 12 | 13 | ## Installation 14 | 15 | ```console 16 | composer require linfo/laravel 17 | ``` 18 | 19 | Publish config file `linfo.php` by running this command. 20 | 21 | ```console 22 | php artisan vendor:publish --provider="Linfo\Laravel\LinfoServiceProvider" 23 | ``` 24 | 25 | ## Usage 26 | 27 | You can use the function like this. 28 | 29 | ```php 30 | use Linfo\Laravel\Linfo; 31 | 32 | $linfo = new Linfo(); 33 | 34 | $os = $linfo->os; // string 35 | $kernel = $linfo->kernel; // string 36 | $model = $linfo->model; // string 37 | $ram = $linfo->ram; // array 38 | $cpu = $linfo->cpu; // array 39 | $arc = $linfo->cpuarchitecture; // string 40 | 41 | ``` 42 | 43 | You can see other data using `dump($linfo)` or `var_dump($linfo)` 44 | 45 | ## Testing 46 | 47 | ```bash 48 | composer test 49 | ``` 50 | 51 | ## Contributing 52 | 53 | Please see [CONTRIBUTING](https://github.com/Astrotomic/.github/blob/master/CONTRIBUTING.md) for details. You could also be interested in [CODE OF CONDUCT](https://github.com/Astrotomic/.github/blob/master/CODE_OF_CONDUCT.md). 54 | 55 | ### Security 56 | 57 | If you discover any security related issues, please check [SECURITY](https://github.com/Astrotomic/.github/blob/master/SECURITY.md) for steps to report it. 58 | 59 | ## Credits 60 | 61 | - [Tom Witkowski](https://github.com/Gummibeer) 62 | - [All Contributors](../../contributors) 63 | 64 | ## License 65 | 66 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 67 | 68 | ## Treeware 69 | 70 | You're free to use this package, but if it makes it to your production environment I would highly appreciate you buying the world a tree. 71 | 72 | It’s now common knowledge that one of the best tools to tackle the climate crisis and keep our temperatures from rising above 1.5C is to [plant trees](https://www.bbc.co.uk/news/science-environment-48870920). If you contribute to my forest you’ll be creating employment for local families and restoring wildlife habitats. 73 | 74 | You can buy trees at [offset.earth/treeware](https://plant.treeware.earth/Astrotomic/laravel-linfo) 75 | 76 | Read more about Treeware at [treeware.earth](https://treeware.earth) 77 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "linfo/laravel", 3 | "description": "This is a Laravel Wrapper for the linfo package from jrgp", 4 | "keywords": [ 5 | "laravel", 6 | "health", 7 | "system", 8 | "load" 9 | ], 10 | "homepage": "https://astrotomic.info", 11 | "license": "MIT", 12 | "authors": [ 13 | { 14 | "name": "Tom Witkowski", 15 | "email": "gummibeer@astrotomic.info", 16 | "homepage": "https://gummibeer.de", 17 | "role": "Developer" 18 | } 19 | ], 20 | "require": { 21 | "php": "^7.3", 22 | "ext-json": "*", 23 | "illuminate/contracts": "^7.0 || ^8.0", 24 | "illuminate/database": "^7.0 || ^8.0", 25 | "illuminate/support": "^7.0 || ^8.0", 26 | "linfo/linfo": "^4.0.2", 27 | "nesbot/carbon": "^2.0" 28 | }, 29 | "require-dev": { 30 | "orchestra/testbench": "^5.0 || ^6.0", 31 | "phpunit/phpunit": "^9.0" 32 | }, 33 | "config": { 34 | "sort-packages": true 35 | }, 36 | "extra": { 37 | "laravel": { 38 | "providers": [ 39 | "Linfo\\Laravel\\LinfoServiceProvider" 40 | ] 41 | } 42 | }, 43 | "autoload": { 44 | "psr-4": { 45 | "Linfo\\Laravel\\": "src" 46 | } 47 | }, 48 | "autoload-dev": { 49 | "psr-4": { 50 | "Linfo\\Laravel\\Tests\\": "tests" 51 | } 52 | }, 53 | "minimum-stability": "stable", 54 | "prefer-stable": true, 55 | "scripts": { 56 | "test": "vendor/bin/phpunit" 57 | }, 58 | "support": { 59 | "email": "dev@astrotomic.info", 60 | "issues": "https://github.com/Astrotomic/laravel-linfo/issues", 61 | "source": "https://github.com/Astrotomic/laravel-linfo" 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /config/linfo.php: -------------------------------------------------------------------------------- 1 | [ 6 | 'byte_notation' => 1024, 7 | 'dates' => 'U', 8 | 'language' => 'en', 9 | 'icons' => true, 10 | 'theme' => 'default', 11 | 'cpu_usage' => true, 12 | 13 | 'show' => [ 14 | 'uptime' => true, 15 | 'load' => true, 16 | 'ram' => true, 17 | 'cpu' => true, 18 | 'hostname' => true, 19 | 'distro' => true, 20 | 'kernel' => true, 21 | 'os' => true, 22 | 'hd' => false, 23 | 'mounts' => false, 24 | 'mounts_options' => false, 25 | 'network' => false, 26 | 'process_stats' => false, 27 | 'devices' => false, 28 | 'model' => false, 29 | 'numLoggedIn' => false, 30 | 'virtualization' => false, 31 | 'duplicate_mounts' => false, 32 | 'temps' => false, 33 | 'raid' => false, 34 | 'battery' => false, 35 | 'sound' => false, 36 | 'wifi' => false, 37 | 'services' => false, 38 | ], 39 | 40 | 'hide' => [ 41 | 'filesystems' => [ 42 | 'tmpfs', 43 | 'ecryptfs', 44 | 'nfsd', 45 | 'rpc_pipefs', 46 | 'usbfs', 47 | 'devpts', 48 | 'fusectl', 49 | 'securityfs', 50 | 'fuse.truecrypt', 51 | ], 52 | 'storage_devices' => [ 53 | 'gvfs-fuse-daemon', 54 | 'none', 55 | ], 56 | 'mountpoints_regex' => [], 57 | 'fs_mount_options' => [ 58 | 'ecryptfs', 59 | ], 60 | 'sg' => true, 61 | ], 62 | 63 | 'raid' => [ 64 | 'gmirror' => false, 65 | 'mdadm' => false, 66 | ], 67 | 68 | 'temps' => [ 69 | 'hwmon' => true, 70 | 'hddtemp' => false, 71 | 'mbmon' => false, 72 | 'sensord' => false, 73 | ], 74 | 'temps_show0rpmfans' => false, 75 | 76 | 'hddtemp' => [ 77 | 'mode' => 'daemon', 78 | 'address' => [ 79 | 'host' => 'localhost', 80 | 'port' => 7634, 81 | ], 82 | ], 83 | 84 | 'mbmon' => [ 85 | 'address' => [ 86 | 'host' => 'localhost', 87 | 'port' => 411, 88 | ], 89 | ], 90 | 91 | 'additional_paths' => [], 92 | 'services' => [ 93 | 'pidFiles' => [], 94 | 'executables' => [], 95 | ], 96 | 'show_errors' => false, 97 | 'timer' => false, 98 | 'compress_content' => true, 99 | 'sudo_apps' => [], 100 | ], 101 | ]; 102 | -------------------------------------------------------------------------------- /src/Linfo.php: -------------------------------------------------------------------------------- 1 | attributes['uptime'] = $value; 23 | $this->attributes['uptime']['bootedtimestamp'] = $this->fromDateTime($value['bootedtimestamp']); 24 | } else { 25 | $valArray = explode(';', $value); 26 | $uptime = trim($valArray[0]); 27 | $bootedtime = trim(explode(' ', trim($valArray[1]))[1]); 28 | $this->attributes['uptime']['text'] = $uptime; 29 | $this->attributes['uptime']['bootedtimestamp'] = $this->fromDateTime($bootedtime); 30 | } 31 | } 32 | 33 | public function getUptimeAttribute(array $value): array 34 | { 35 | return [ 36 | 'text' => $value['text'], 37 | 'bootedtimestamp' => $this->asDateTime($value['bootedtimestamp']), 38 | ]; 39 | } 40 | 41 | public function getBootedAtAttribute(): Carbon 42 | { 43 | return $this['uptime']['bootedtimestamp']; 44 | } 45 | 46 | public function getCreatedAtAttribute(): Carbon 47 | { 48 | return $this['timestamp']; 49 | } 50 | 51 | public function setPhpversionAttribute(?string $value): void 52 | { 53 | $this->attributes['phpversion'] = $value ?: phpversion(); 54 | } 55 | 56 | public function setWebserviceAttribute(?string $value): void 57 | { 58 | $this->attributes['webservice'] = $value ?: (! empty($_SERVER['SERVER_SOFTWARE']) ? $_SERVER['SERVER_SOFTWARE'] : null); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/LinfoServiceProvider.php: -------------------------------------------------------------------------------- 1 | app->runningInConsole()) { 12 | $this->publishes([ 13 | __DIR__.'/../config/linfo.php' => config_path('linfo.php'), 14 | ], 'config'); 15 | } 16 | 17 | $this->mergeConfigFrom(__DIR__.'/../config/linfo.php', 'linfo'); 18 | 19 | $this->app->bind(Linfo::class); 20 | $this->app->alias(Linfo::class, 'linfo'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Model.php: -------------------------------------------------------------------------------- 1 | refresh(); 23 | } 24 | 25 | public function refresh(): self 26 | { 27 | $linfo = new LinfoBase(config('linfo.source')); 28 | $linfo->scan(); 29 | foreach ($this->normalizeArrayKeys($linfo->getInfo()) as $key => $value) { 30 | $this->setAttribute($key, $value); 31 | } 32 | $this->syncOriginal(); 33 | $this->classCastCache = []; 34 | 35 | return $this; 36 | } 37 | 38 | public function fresh(): self 39 | { 40 | return new static(); 41 | } 42 | 43 | public function getOriginals(): array 44 | { 45 | return $this->original; 46 | } 47 | 48 | protected function normalizeArrayKeys(array $array): array 49 | { 50 | $tmp = []; 51 | foreach ($array as $key => $value) { 52 | if (is_array($value)) { 53 | $value = $this->normalizeArrayKeys($value); 54 | } 55 | $tmp[Str::slug($key, '_')] = $value; 56 | } 57 | 58 | return $tmp; 59 | } 60 | 61 | protected function getIncrementing(): bool 62 | { 63 | return false; 64 | } 65 | 66 | protected function usesTimestamps(): bool 67 | { 68 | return false; 69 | } 70 | 71 | public function getCreatedAtColumn(): ?string 72 | { 73 | return null; 74 | } 75 | 76 | public function getUpdatedAtColumn(): ?string 77 | { 78 | return null; 79 | } 80 | 81 | public function getRelationValue($key) 82 | { 83 | } 84 | 85 | public function getDateFormat() 86 | { 87 | return DateTimeInterface::ATOM; 88 | } 89 | 90 | public function toArray(): array 91 | { 92 | return $this->attributesToArray(); 93 | } 94 | 95 | public function toJson($options = 0): string 96 | { 97 | return json_encode($this->jsonSerialize(), $options); 98 | } 99 | 100 | public function jsonSerialize(): array 101 | { 102 | return $this->toArray(); 103 | } 104 | 105 | public function offsetExists($offset): bool 106 | { 107 | return $this->getAttribute($offset) !== null; 108 | } 109 | 110 | public function offsetGet($offset) 111 | { 112 | return $this->getAttribute($offset); 113 | } 114 | 115 | public function offsetSet($offset, $value): void 116 | { 117 | $this->setAttribute($offset, $value); 118 | } 119 | 120 | public function offsetUnset($offset): void 121 | { 122 | unset($this->attributes[$offset]); 123 | } 124 | 125 | public function __get($key) 126 | { 127 | return $this->getAttribute($key); 128 | } 129 | 130 | public function __set($key, $value): void 131 | { 132 | $this->setAttribute($key, $value); 133 | } 134 | 135 | public function __isset($key): bool 136 | { 137 | return $this->offsetExists($key); 138 | } 139 | 140 | public function __unset($key): void 141 | { 142 | $this->offsetUnset($key); 143 | } 144 | } 145 | --------------------------------------------------------------------------------