phpsysinfo / phpsysinfo

phpSysInfo: a customizable PHP script that displays information about your system nicely
http://phpsysinfo.github.io/phpsysinfo
GNU General Public License v2.0
1.38k stars 234 forks source link

Enhancement: Hyper-V #283

Closed LeeThompson closed 3 years ago

LeeThompson commented 3 years ago

I don't have the experience to do this as a PR but here are some enhancements for the Hyper-V plugin.

This adds 3 new variables (they would need to be set and passed in somewhere):

If they are null, this will work as it has always worked.

This allows the plug-in to connect to a different computer to get Hyper-V data (for cases where the Hyper-V host is not on the same machine as the web server).

(This could be expanded to the general WMI function as well to at least provide credentials for the connection.)

(Also /data/hyperv.txt needs to be documented as to what it expects in the file as far as I can tell it wants a list of ElementName| EnabledState).

class.hyperv.inc.php

This is a snippet for the start of execute:

                    $wmic = $objLocator->ConnectServer($wmi_hostname,'root\CIMv2',$wmi_hostuser,$wmi_hostpassword);
                    $buffer = CommonFunctions::getWMI($wmic, 'Win32_OperatingSystem', array('Version'));
                    if ($buffer && isset($buffer[0]) && isset($buffer[0]['Version'])) {
                        if (version_compare($buffer[0]['Version'], "6.2", ">=")) { // minimal windows 2012 or windows 8
                            $wmi = $objLocator->ConnectServer($wmi_hostname, 'root\virtualization\v2', $wmi_hostuser,$wmi_hostpassword);
                        } elseif (version_compare($buffer[0]['Version'], "6.0", ">=")) { // minimal windows 2008
                            $wmi = $objLocator->ConnectServer($wmi_hostname, 'root\virtualization', $wmi_hostuser,$wmi_hostpassword);
LeeThompson commented 3 years ago

If you want to add this to the main wmi functions there are some other fields you might want to be aware of:

When you do the ConnectServer the parameters are (italics are optional fields):

  1. NODE (computer to connect to, default is null which means local, can be NETBIOS name, FQDN or an IP address)
  2. NAMESPACE
  3. USERNAME (for an active directory account the DOMAIN\USER syntax can be used)
  4. PASSWORD
  5. LOCALE (if null the default is used; e.g. MS_409 for American English)
  6. FLAGS (0x80 = WBEM_FLAG_CONNECT_USE_MAX_WAIT which is a 2 minute timeout)
  7. AUTHORITY (default NTLM) (NTLMDOMAIN: or Kerberos:)
  8. CONTEXTOBJECT (usually null; it's a pointer)
  9. IWbemServices Proxy (usually null; it's a pointer)

(NOTE: I'm not sure parameters 8 and 9 are relevant to PHP)

Detail Reference

Other notes:

It's strange that there isn't a way to set the timeout, it's no timeout at all (which can hang indefinitely) or the two minute one with the flag. phpSysInfo should probably be using the 0x80 flag.

namiltd commented 3 years ago

Try https://github.com/phpsysinfo/phpsysinfo/commit/45fc9edc61d4624e2444855b290c5327a1e5e621

phpsysinfo.ini [main] block: WMI_HOSTNAME="192.168.0.23" WMI_USER="User" WMI_PASSWORD="UserPass"

possibly additionally: MAX_TIMEOUT=60

For only hyperv plugin define WMI_HOSTNAME, WMI_USER and WMI_PASSWORD in [hyperv] block instead [main]

LeeThompson commented 3 years ago

Works great, thanks!

Used the [hyperv] option.

(This should also help Windows users so they don't have to run the web process with high permissions as well since they can give WMI credentials in the .ini)