def main(): DecoratorObject.SectionHeader("GATHERING ACTIVE INFORMATION...") DecoratorObject.SuccessMessage("Host information was gathered") datadict = { "System": str(os.uname().sysname) + " v" + str(os.uname().release), "Hostname": str(os.uname().nodename), "Version": str(os.uname().version), "Distribution": str(distro.os_release_info()["name"]) + " " + str(distro.os_release_info()["version_id"]) + " " + str(os.uname().machine), } for indx in datadict.keys(): DecoratorObject.NormalMessage(indx + ": " + datadict[indx]) if str(distro.os_release_info()["name"]) == "Fedora": if int(distro.os_release_info()["version_id"]) >= 32: DecoratorObject.SuccessMessage("Supported OS detected - " + datadict["Distribution"]) else: DecoratorObject.WarningMessage( "Minimally supported OS detected - " + datadict["Distribution"]) else: DecoratorObject.FailureMessage("Unsupported OS detected - " + datadict["Distribution"]) DecoratorObject.FailureMessage("Leaving installer") sys.exit(0)
def avbl(self): if str(distro.os_release_info()["name"]) == "Fedora": if int(distro.os_release_info()["version_id"]) >= 32: return "full" else: return "half" else: return False
def main(self): jsondt = { "System": str(os.uname().sysname) + " v" + str(os.uname().release), "Hostname": str(os.uname().nodename), "Version": str(os.uname().version), "Distribution": str(distro.os_release_info()["name"]) + " " + str(distro.os_release_info()["version_id"]) + " " + str(os.uname().machine), } return jsondt
def _linux_pkg_checks() -> None: """Check that all the packages required by SIERRA are installed on whatever flavor of Linux SIERRA is running on. """ import distro dist = distro.id() os_info = distro.os_release_info() if os_info['id_like'] in ['debian', 'ubuntu']: import apt cache = apt.Cache() missing = [] for pkg in kRequiredDebPackages: logging.trace("Checking for .deb package '%s'", pkg) if pkg not in cache or not cache[pkg].is_installed: missing.append(pkg) if missing: raise RuntimeError( (f"Required .deb packages {missing} missing on " f"Linux distribution '{dist}'. Install all " "required packages before running SIERRA! " "(Did you read the \"Getting Started\" docs?)")) else: logging.warning( ("Unknown Linux distro '%s' detected: skipping package " "check"), dist) logging.warning( ("If SIERRA crashes it might be because you don't have " "all the required packages installed"))
def get_host_state(config): hs("os", distro.os_release_info()) hs("cpus(logical)", psutil.cpu_count()) hs("cpus(physical)", psutil.cpu_count(logical=False)) hs("memory_total", str(round( psutil.virtual_memory().total / GBi, 2)) + " GBi") hs("memory_free", str(round( psutil.virtual_memory().free / GBi, 2)) + " GBi") hs("swap_total", str(round( psutil.swap_memory().total / GBi, 2)) + " GBi") hs("swap_free", str(round( psutil.swap_memory().free / GBi, 2)) + " GBi") infs = {} stats = psutil.net_if_stats() for name, inf in psutil.net_if_addrs().items(): inf_info = {} inf_info['address'] = "/".join((str(inf[0].address), str(inf[0].netmask))) inf_info['status'] = 'up' if stats[name].isup else 'down' inf_info['mtu'] = stats[name].mtu infs[name] = inf_info hs("interfaces", infs) pids = map(lambda x: x.pid, filter(lambda x: 'iscsid' in x.info['name'], psutil.process_iter(attrs=['pid', 'name']))) hs("iscsid_pids", pids)
def check_install(): """check if Percona is installed""" if distro.os_release_info()['id'] not in ['fedora', 'redhat', 'centos']: print("{} is not supported".format(distro.os_release_info()['id'])) os.sys.exit(1) print("\ndetected {} ...".format(distro.os_release_info()['pretty_name'])) percona_installed = None rpmts = rpm.TransactionSet() #pylint: disable=E1101 rpmmi = rpmts.dbMatch() for pkg_set in rpmmi: if pkg_set['name'].decode() == PKG: percona_installed = "{}-{}-{}".format(pkg_set['name'].decode(), pkg_set['version'].decode(), pkg_set['release'].decode()) if percona_installed: print('detected {} ...'.format(percona_installed)) else: print("{}{} not installed{}".format(RED, PKG, WHITE)) os.sys.exit(1) return 'percona'
def check_install(): """check if Percona is installed""" if distro.os_release_info()['id'] not in ['fedora', 'redhat', 'centos']: print("{} is not supported".format(distro.os_release_info()['id'])) os.sys.exit(1) print("\ndetected {} ...".format(distro.os_release_info()['pretty_name'])) import rpm percona_installed = None pkg = 'Percona-XtraDB-Cluster-server-{}'.format(PERCONA_MAJOR_VERSION) rpmts = rpm.TransactionSet() rpmmi = rpmts.dbMatch() for pkg_set in rpmmi: if pkg_set['name'].decode() == pkg: percona_installed = "{}-{}-{}".format(pkg_set['name'].decode(), pkg_set['version'].decode(), pkg_set['release'].decode()) if percona_installed: print('detected {} ...'.format(percona_installed)) else: print("{}{} not installed{}".format(RED, pkg, WHITE)) os.sys.exit(1) return 'percona'
async def help(self, ctx): users = str(len(self.bot.users)) guilds = str(len(self.bot.guilds)) vote_link = "[**Vote link**](http://bit.ly/2mLoBOs) ⬆️" sourcecode_link = "[**Source Code**](https://github.com/TrackRunny/LinuxBoi) <:github:668680155807350792>" personal_website = "[**Personal Website**](https://trackrunny.codes) <:connection:678490219267489795>" cpu = str(psutil.cpu_percent()) ram = str(psutil.virtual_memory()[3] / 1000000000) ram_round = ram[:3] disk = str(psutil.disk_usage('/')[1] / 1000000000) disk_round = disk[:4] boot_time = str(psutil.boot_time() / 100000000) boot_time_round = boot_time[:4] linux_distro = distro.os_release_info() embed = discord.Embed( color=self.bot.embed_color, title=f"→ LinuxBoi", description=f"— " f"\n ➤ Shows info about the server in which the bot is running on! " f"All values are accurate and updated each time the command is ran." f"\n ➤ To view my commands run, `l!commands`" f"\n ➤ Source code for this bot is available here: {sourcecode_link}" f"\n ➤ If you like my bot, consider voting: {vote_link}" f"\n ➤ My personal website: {personal_website}" + "\n—" ) embed.set_thumbnail(url="https://bit.ly/2JGhA94") embed.add_field(name=f"• OPERATING System:", inline=True, value=f":computer: — {linux_distro['pretty_name']}") embed.add_field(name=f"• CPU Usage:", inline=True, value=f":heavy_plus_sign: — {cpu} Percent used") embed.add_field(name=f"• RAM Usage:", inline=True, value=f":closed_book: — {ram_round} / 3 Gigabytes used") embed.add_field(name=f"• DISK Usage:", inline=True, value=f":white_circle: — {disk_round} / 40 Gigabytes") embed.add_field(name=f"• BOOT Time: ", inline=True, value=f":boot: — {boot_time_round} seconds") embed.add_field(name=f"• MEMBER Count:", inline=True, value=f":bust_in_silhouette: — {users} users") embed.add_field(name=f"• GUILD Count:", inline=True, value=f":house: — {guilds} connected guilds") embed.add_field(name=f"• LIBRARY Version:", inline=True, value=f":gear: — discord.py version {discord.__version__}") embed.add_field(name=f"• PYTHON Version:", inline=True, value=f":snake: — Python version {platform.python_version()}") embed.set_footer(text=f"\n\nMade by TrackRunny#0001", icon_url=f"\n\nhttps://i.imgur.com/TiUqRH8.gif") await ctx.send(embed=embed) logger.info(f"Information | Sent Help: {ctx.author}")
async def help(self, ctx): users = str(len(self.bot.users)) guilds = str(len(self.bot.guilds)) cpu0, cpu1, cpu2, cpu3 = psutil.cpu_percent(interval=1, percpu=True) ram = str(psutil.virtual_memory()[3] / 1000000000) ram_round = ram[:3] disk = str(psutil.disk_usage('/')[1] / 1000000000) disk_round = disk[:4] boot_time = str(psutil.boot_time() / 100000000) boot_time_round = boot_time[:4] linux_distro = distro.os_release_info() import os mem_bytes = os.sysconf('SC_PAGE_SIZE') * os.sysconf('SC_PHYS_PAGES') # e.g. 4015976448 mem_gib = mem_bytes/(1024.**3) mem = psutil.virtual_memory() await ctx.send(mem_gib) await ctx.send("```Piero™ Bot\nCPUs:\n\tCPU 0: "+progressBar(cpu0,100)+str(cpu0)+"\n\tCPU 1: "+progressBar(cpu1,100)+str(cpu1)+"\n\tCPU 2: "+progressBar(cpu2,100)+str(cpu2)+"\n\tCPU 3: "+progressBar(cpu3,100)+str(cpu3)+"\nRAM:"+ram+"```")
def sysinfo(request): headers = [ 'CONTENT_LENGTH', 'CONTENT_TYPE', 'HTTP_ACCEPT', 'HTTP_ACCEPT_ENCODING', 'HTTP_ACCEPT_LANGUAGE', 'HTTP_HOST', 'HTTP_REFERER', 'HTTP_USER_AGENT', 'QUERY_STRING', 'REMOTE_ADDR', 'REMOTE_HOST', 'REMOTE_USER', 'REQUEST_METHOD', 'SERVER_NAME', 'SERVER_PORT' ] http_headers = {} for x in headers: try: http_headers[x] = request.META[x] except KeyError: http_headers[x] = "" context = { 'dist': distro.os_release_info(), 'headers': http_headers, } return render(request, 'dashboard/sysinfo.html', context)
def get_os_info(verbose): """ Get operating system details about the system the script is being run on. This will setup future steps and dictate what else needs to be done or checked to ensure a smooth install """ profile = {} if verbose: print('Gathering OS and distribution information') linux_info = distro.distro_release_info() # On SUSE distro_release_info gives an empty {} # so get the info another way if linux_info == {}: linux_info = distro.os_release_info() version = 'UNK' if linux_info.get('version_id'): temp_version = linux_info.get('version_id').split('.') if len(temp_version) > 1: version = '{0}.{1}'.format(temp_version[0], temp_version[1]) else: version = temp_version[0] profile['distribution'] = linux_info.get('id') profile['version'] = version profile['dist_name'] = linux_info.get('name') based_on = None if os.path.isfile('/etc/redhat-release'): based_on = 'rhel' elif os.path.isfile('/etc/debian_version'): based_on = 'debian' elif os.path.isfile('/etc/os-release'): based_on = 'suse' profile['based_on'] = based_on return profile
def checkForUserOperationAndExecute(): while True: option() userOperation = int(input("almf> ")) if (userOperation == 1): clear() cprint(" [1] List processes", "magenta") cprint(" [2] Kill Process", "magenta") cprint(" [0] Return to main menu", "magenta") userSubOperation = int(input("almf> ")) if (userSubOperation == 1): lst.listproc() if (userSubOperation == 2): pidtokill = int(input("PID of the process to kill: ")) kill.kill(pidtokill) if (userSubOperation == 0): continue if (userOperation == 2): distro = distro.os_release_info()['id_like'] if (distro == 'ubuntu' or distro == "debian"): clear() cprint(" [1] Install package", "magenta") cprint(" [2] Remove package", "magenta") cprint(" [3] Install essential packages", "magenta") cprint(" [0] Return to main menu", "magenta") userSubOperation = int(input("almf> ")) if (userSubOperation == 1): packagetoinstall = input("Package to install: ") install.install(packagetoinstall) if (userSubOperation == 2): packagetoremove = input("Package to remove: ") remove.remove(packagetoremove) if (userSubOperation == 3): scriptsrc.installEssential() if (userSubOperation == 0): continue else: cprint("Your system doesn't support APT package manager!", "red") continue if (userOperation == 3): clear() cprint(" [1] Enable firewall (with default rules)", "magenta") cprint(" [2] Disable firewall", "magenta") cprint(" [0] Return to main menu", "magenta") userSubOperation = int(input("almf> ")) if (userSubOperation == 1): defaultFirewall() cprint("Firewall started successfully", "green") if (userSubOperation == 2): firewall.disable() cprint("Firewall disabled successfully", "green") if (userSubOperation == 0): continue if (userOperation == 4): clear() scriptsrc.cleanCache() cprint("Thumbnail cache cleaned successfully", "green") if (userOperation == 5): clear() cprint(" [1] Encrypt", "magenta") cprint(" [2] Decrypt", "magenta") cprint(" [0] Return to main menu", "magenta") userSubOperation = int(input("almf> ")) if (userSubOperation == 1): clear() inputf = input("Enter the input file path: ") outputf = input("Enter the output file path: ") scriptsrc.encrypt(inputf, outputf) if (userSubOperation == 2): clear() inputf = input("Enter the input file path: ") outputf = input("Enter the output file path: ") scriptsrc.decrypt(inputf, outputf) if (userSubOperation == 0): continue if (userOperation == 6): cprint(" [1] Get WAN IP", "magenta") cprint(" [2] Get LAN IP(s)", "magenta") cprint(" [3] Get router IP", "magenta") cprint(" [4] Get DNS Nameserver", "magenta") cprint(" [5] Get MAC Address for interface", "magenta") cprint(" [6] Get current IP Geodata", "magenta") cprint(" [0] Return to main menu", "magenta") userSubOperation = int(input("almf> ")) if (userSubOperation == 1): scriptsrc.wanIp() if (userSubOperation == 2): scriptsrc.lanIp() if (userSubOperation == 3): scriptsrc.routerIp() if (userSubOperation == 4): scriptsrc.dnsNameserver() if (userSubOperation == 5): iface = input("Interface: ") scriptsrc.macAddress(iface) if (userSubOperation == 6): scriptsrc.ipGeodata() if (userSubOperation == 0): continue if (userOperation == 7): clear() cprint(" [1] Create new user", "magenta") cprint(" [2] Delete user", "magenta") cprint(" [3] Set root password", "magenta") cprint(" [0] Return to main menu", "magenta") userSubOperation = int(input("almf> ")) if (userSubOperation == 1): newusername = input("Name of the new user: "******"Name of the user to delete: ") scriptsrc.deluser(usertodel) if (userSubOperation == 3): scriptsrc.rootpasswd() if (userSubOperation == 0): continue if (userOperation == 0): break
# limitations under the License. from __future__ import print_function from pprint import pformat import distro def pprint(obj): for line in pformat(obj).split("\n"): print(4 * " " + line) print("os_release_info:") pprint(distro.os_release_info()) print("lsb_release_info:") pprint(distro.lsb_release_info()) print("distro_release_info:") pprint(distro.distro_release_info()) print("id: {0}".format(distro.id())) print("name: {0}".format(distro.name())) print("name_pretty: {0}".format(distro.name(True))) print("version: {0}".format(distro.version())) print("version_pretty: {0}".format(distro.version(True))) print("like: {0}".format(distro.like())) print("codename: {0}".format(distro.codename())) print("linux_distribution_full: {0}".format(distro.linux_distribution())) print("linux_distribution: {0}".format(distro.linux_distribution(False))) print("major_version: {0}".format(distro.major_version())) print("minor_version: {0}".format(distro.minor_version()))
# # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. import distro print 'os_release_info: {0}'.format(distro.os_release_info()) print 'lsb_release_info: {0}'.format(distro.lsb_release_info()) print 'distro_release_info: {0}'.format(distro.distro_release_info()) print 'id: {0}'.format(distro.id()) print 'name: {0}'.format(distro.name()) print 'name_pretty: {0}'.format(distro.name(True)) print 'version: {0}'.format(distro.version()) print 'version_pretty: {0}'.format(distro.version(True)) print 'like: {0}'.format(distro.like()) print 'codename: {0}'.format(distro.codename()) print 'linux_distribution_full: {0}'.format(distro.linux_distribution()) print 'linux_distribution: {0}'.format(distro.linux_distribution(False)) print 'major_version: {0}'.format(distro.major_version()) print 'minor_version: {0}'.format(distro.minor_version()) print 'build_number: {0}'.format(distro.build_number())
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. from __future__ import print_function import distro from pprint import pformat def pprint(obj): for line in pformat(obj).split('\n'): print(4 * ' ' + line) print('os_release_info:') pprint(distro.os_release_info()) print('lsb_release_info:') pprint(distro.lsb_release_info()) print('distro_release_info:') pprint(distro.distro_release_info()) print('id: {0}'.format(distro.id())) print('name: {0}'.format(distro.name())) print('name_pretty: {0}'.format(distro.name(True))) print('version: {0}'.format(distro.version())) print('version_pretty: {0}'.format(distro.version(True))) print('like: {0}'.format(distro.like())) print('codename: {0}'.format(distro.codename())) print('linux_distribution_full: {0}'.format(distro.linux_distribution())) print('linux_distribution: {0}'.format(distro.linux_distribution(False))) print('major_version: {0}'.format(distro.major_version())) print('minor_version: {0}'.format(distro.minor_version()))