Skip to content

Commit 9e13931

Browse files
committedMar 2, 2023
Added SystemProfile class.
1 parent 5bcc1af commit 9e13931

File tree

5 files changed

+1280
-0
lines changed

5 files changed

+1280
-0
lines changed
 

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Classes
2626
* SerialNumber - Generates and validates encrypted 16 character serial numbers. The basis of [CubicleSoft License Server](https://github.com/cubiclesoft/php-license-server). [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/serial_number.md)
2727
* Str - Static functions in a class for doing basic, common, but missing string manipulation. Common initialization routines for CubicleSoft applications. Some minor carryover from extremely old C++ libraries. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/str_basics.md)
2828
* StringBitStream - Parse data stored in a bit stream such as Flash (SWF) files. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/bits.md)
29+
* SystemProfile - Static functions in a class to generate an array of internal device hardware information for the current device. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/system_profile.md)
2930
* UTF8 - Flexible UTF-8 string manipulation static functions in a class. CubicleSoft was doing Unicode and UTF-8 long before Unicode and UTF-8 were cool. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/utf8.md)
3031
* UTFUtils - Convert between various Unicode Transformation Formats (UTF-8, UTF-16, UTF-32) and a Punycode implementation. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/utf_utils.md)
3132
* XTerm - Static functions in a class for emitting XTerm-compatible escape codes to alter terminal behavior. Mostly for changing font styles and colors but also supports most escape codes with easier to comprehend functions. Many features also work with the Command Prompt in Windows 10 and later. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/xterm.md)

‎docs/system_profile.md

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
SystemProfile Class: 'support/system_profile.php'
2+
==================================================
3+
4+
The SystemProfile class generates an array of internal device hardware information for the current device and also calculates a unique device fingerprint. Works for Windows, Mac OSX, various Linux distros (primarily Debian, RedHat, and Arch), FreeBSD, and perhaps other OSes.
5+
6+
Example usage:
7+
8+
```php
9+
<?php
10+
require_once "support/system_profile.php";
11+
12+
$result = SystemProfile::GetProfile();
13+
14+
var_dump($result);
15+
?>
16+
```
17+
18+
SystemProfile::GetHostname()
19+
----------------------------
20+
21+
Access: public static
22+
23+
Parameters: None.
24+
25+
Returns: A string containing the hostname on success, a boolean of false otherwise.
26+
27+
This static function returns the hostname of the current device.
28+
29+
SystemProfile::GetMachineID()
30+
-----------------------------
31+
32+
Access: public static
33+
34+
Parameters: None.
35+
36+
Returns: A string containing the unique machine ID on success, a boolean of false otherwise.
37+
38+
This static function returns the unique machine ID of the current device.
39+
40+
SystemProfile::GetMotherboardInfo()
41+
-----------------------------------
42+
43+
Access: public static
44+
45+
Parameters: None.
46+
47+
Returns: An array containing information about the motherboard on success, a boolean of false otherwise.
48+
49+
This static function returns information about the motherboard for the current device. Not all OSes have the ability to retrieve this information.
50+
51+
SystemProfile::GetCPUInfo()
52+
---------------------------
53+
54+
Access: public static
55+
56+
Parameters: None.
57+
58+
Returns: An array containing information about the CPU(s) on success, a boolean of false otherwise.
59+
60+
This static function returns information about the CPU(s) for the current device.
61+
62+
SystemProfile::GetRAMInfo()
63+
---------------------------
64+
65+
Access: public static
66+
67+
Parameters: None.
68+
69+
Returns: An array containing information about the RAM on success, a boolean of false otherwise.
70+
71+
This static function returns information about the RAM for the current device. Most OSes just return the total capacity. Windows returns information about each individual stick/chip.
72+
73+
SystemProfile::GetGPUInfo()
74+
---------------------------
75+
76+
Access: public static
77+
78+
Parameters: None.
79+
80+
Returns: An array containing information about the GPU on success, a boolean of false otherwise.
81+
82+
This static function returns information about the GPU for the current device.
83+
84+
SystemProfile::GetNICInfo()
85+
---------------------------
86+
87+
Access: public static
88+
89+
Parameters: None.
90+
91+
Returns: An array containing information about the network interfaces on success, a boolean of false otherwise.
92+
93+
This static function returns information about the network interfaces for the current device. Where possible, physical controllers are included.
94+
95+
SystemProfile::GetDiskInfo()
96+
----------------------------
97+
98+
Access: public static
99+
100+
Parameters: None.
101+
102+
Returns: An array containing information about the internal storage on success, a boolean of false otherwise.
103+
104+
This static function returns information about the internal storage for the current device.
105+
106+
SystemProfile::GetOSInfo()
107+
--------------------------
108+
109+
Access: public static
110+
111+
Parameters: None.
112+
113+
Returns: An array containing information about the current OS on success, a boolean of false otherwise.
114+
115+
This static function returns information about the current OS for the current device.
116+
117+
SystemProfile::GetProfile()
118+
---------------------------
119+
120+
Access: public static
121+
122+
Parameters: None.
123+
124+
Returns: An array containing information about the device.
125+
126+
This static function returns information about the current device and calculates a unique device fingerprint. Depending on the OS, this function can take upwards of several seconds to run.
127+
128+
SystemProfile::ExtractWMICResults($data, $expectedheader)
129+
---------------------------------------------------------
130+
131+
Access: protected static
132+
133+
Parameters:
134+
135+
* $data - A string containing the output from `wmic.exe`.
136+
* $expectedheader - A string containing an expected header to exist.
137+
138+
Returns: An array containing the extracted data on success, a boolean of false otherwise.
139+
140+
This internal static function extracts columnar data from `wmic.exe` output.
141+
142+
SystemProfile::GetPCIConfBSD()
143+
------------------------------
144+
145+
Access: protected static
146+
147+
Parameters: None.
148+
149+
Returns: An array of information from `pciconf` on FreeBSD and similar systems on success, a boolean of false otherwise.
150+
151+
This internal static function extracts data from `pciconf` on FreeBSD and similar systems.
152+
153+
SystemProfile::GetIORegPlatformDeviceOSX()
154+
------------------------------------------
155+
156+
Access: protected static
157+
158+
Parameters: None.
159+
160+
Returns: An array of information from `IOPlatformExpertDevice` data via `ioreg` on Mac OSX on success, a boolean of false otherwise.
161+
162+
This internal static function extracts `IOPlatformExpertDevice` data via `ioreg` on Mac OSX and similar systems.
163+
164+
SystemProfile::FindExecutable($file, $path = false)
165+
---------------------------------------------------
166+
167+
Access: protected static
168+
169+
Parameters:
170+
171+
* $file - A string containing an executable filename to locate on the system.
172+
* $path - A boolean of false or a string containing the initial path to look in (Default is false).
173+
174+
Returns: A string containing the full path and filename to the executable on success, a boolean of false otherwise.
175+
176+
This internal static function attempts to locate a matching executable file. When $path is not supplied or the file is not found in the specified path, the environment PATH variable is processed. Identical to `ProcessHelper::FindExecutable()`.
177+
178+
SystemProfile::RunCommand($cmd)
179+
-------------------------------
180+
181+
Access: protected static
182+
183+
Parameters:
184+
185+
* $cmd - A string containing the command line to execute.
186+
187+
Returns: A string containing the `stdout` output from the process on success, a boolean of false otherwise.
188+
189+
This internal static function runs an executable and gathers output. On Windows, this function can optionally utilize the `ProcessHelper` class to avoid flashing console windows via `createprocess-win.exe`.

‎readme_src/classes.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"SerialNumber": "Generates and validates encrypted 16 character serial numbers. The basis of [CubicleSoft License Server](https://github.com/cubiclesoft/php-license-server). [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/serial_number.md)",
1818
"Str": "Static functions in a class for doing basic, common, but missing string manipulation. Common initialization routines for CubicleSoft applications. Some minor carryover from extremely old C++ libraries. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/str_basics.md)",
1919
"StringBitStream": "Parse data stored in a bit stream such as Flash (SWF) files. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/bits.md)",
20+
"SystemProfile": "Static functions in a class to generate an array of internal device hardware information for the current device. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/system_profile.md)",
2021
"UTF8": "Flexible UTF-8 string manipulation static functions in a class. CubicleSoft was doing Unicode and UTF-8 long before Unicode and UTF-8 were cool. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/utf8.md)",
2122
"UTFUtils": "Convert between various Unicode Transformation Formats (UTF-8, UTF-16, UTF-32) and a Punycode implementation. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/utf_utils.md)",
2223
"XTerm": "Static functions in a class for emitting XTerm-compatible escape codes to alter terminal behavior. Mostly for changing font styles and colors but also supports most escape codes with easier to comprehend functions. Many features also work with the Command Prompt in Windows 10 and later. [Documentation](https://github.com/cubiclesoft/php-misc/blob/master/docs/xterm.md)"

‎support/system_profile.php

Lines changed: 1079 additions & 0 deletions
Large diffs are not rendered by default.

‎test.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
require_once $rootpath . "/support/utf8.php";
2121
require_once $rootpath . "/support/utf_utils.php";
2222
require_once $rootpath . "/support/serial_number.php";
23+
require_once $rootpath . "/support/system_profile.php";
2324
require_once $rootpath . "/support/php_minifier.php";
2425
require_once $rootpath . "/support/natural_language.php";
2526
require_once $rootpath . "/support/str_basics.php";
@@ -271,6 +272,15 @@ function GlobalTestEventCallback($event, $msg, $data)
271272
}
272273
echo "\n\n";
273274

275+
echo "SystemProfile test\n";
276+
$result = SystemProfile::GetProfile();
277+
foreach ($result as $key => $info)
278+
{
279+
if (is_string($info) || is_numeric($info)) echo $key . ": " . $info . "\n";
280+
else if (is_array($info)) echo $key . ": " . $info["type"] . " (" . count($info["data"]) . " items)\n";
281+
}
282+
echo "\n\n";
283+
274284
echo "PHPMinifier test\n";
275285
$result = PHPMinifier::Minify("test_request.php", file_get_contents("test_request.php"));
276286
echo $result["data"] . "\n";

0 commit comments

Comments
 (0)
Please sign in to comment.