openbullet / OpenBullet2

OpenBullet reinvented
MIT License
1.64k stars 456 forks source link

[REQUEST] Host Info as Variables #990

Closed APT-ZERO closed 2 weeks ago

APT-ZERO commented 2 weeks ago

Hello Please add 3 variable to show - if OB2 is running on Windows or Linux or else What is it's architecture (amd64, 386 or arm64) Is it running as Administrator / Root or not

It's needed when running External Tools For example when some part of my config is a golang script and there is 3 release and i must know which release to run And if my external tool needs admin/root access, i must check and stop the bots if current OB2 is not running as admin/root

openbullet commented 2 weeks ago

You can find out those things using C# directly from your config. You can add this code to the Startup LoliCode script (so it only runs once at the start of the job) and you will have them available inside the globals variable.

globals.OS = System.Runtime.InteropServices.RuntimeInformation.OSDescription; // string
globals.ARCH = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture; // string
globals.ROOT = RuriLib.Helpers.RootChecker.IsRoot(); // bool

Then you can use them in your config's body, e.g.,

CLOG OrangeYellow $"OS: {globals.OS}"
CLOG OrangeYellow $"ARCH: {globals.ARCH}"
CLOG OrangeYellow $"ROOT: {globals.ROOT}"

No need to add them separately since it's something easily available to you. Also, if you want to check for a specific platform, you can also do something like

globals.WINDOWS = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows); // bool

And the same for OSX and Linux. Find out more here