[ SEA-GHOST MINI SHELL]

Path : /proc/2/cwd/proc/2/root/var/lib/zabbix/
FILE UPLOADER :
Current File : //proc/2/cwd/proc/2/root/var/lib/zabbix/cpanel_users_count.py

#!/usr/bin/env python

import json
import requests
from sys import exit
from argparse import ArgumentParser

protocol = "http://"
percentage_limit = 85

def get_opts(protocol):
    parser = ArgumentParser(
        usage='%(prog)s -s <Server name,like hosting-api.au.syrahost.com> -a <monitor|discovery> -g <cpanel|wordpress - This is \'type\' field from hosting-api> --sub_group <This is \'group_name\' field from hosting-api> -r <\'region_name\'>',
        description='This program is used to connect to Hosting-API and camparing current accouts and accounts limit for Cpanel Team.'
    )
    parser.add_argument(
        "-s", "--server",
        action="store",
        dest="server",
        help="Hostname of server",
        required=True,
    )
    parser.add_argument(
        "-a", "--action",
        action="store",
        dest="action",
        choices=['monitor', 'discovery'],
        help="Need to choose one of actions",
        required=True,
    )
    parser.add_argument(
        "-r", "--region_name",
        action="store",
        dest="region",
        help="Name of Region",
        required=False,
    )
    parser.add_argument(
        "-g", "--group_name",
        action="append",
        dest="group",
        help="Name of main group",
        required=True,
    )
    parser.add_argument(
        "--sub_group",
        action="store",
        dest="sub_group",
        help="Name of sub group",
    )


    args = parser.parse_args()
    if args.sub_group is None and args.action == "monitor":
        print("2")
        exit(0)
    args.server = protocol + args.server
    return args

def api_call(url):
    try:
        response = requests.get(url,timeout=8)
        response.raise_for_status()
    except requests.exceptions.HTTPError as httperror:
        print("3")
        exit(0)
    except requests.exceptions.ConnectionError as connerror:
        print("4")
        exit(0)
    except requests.exceptions.Timeout as timeerror:
        print("5")
        exit(0)
    except requests.exceptions.RequestException as othererror:
        print("6")
        exit(0)
    try:
        return response.json()
    except ValueError:
        print("7")
        exit(0)


def discovering(server,group):

    api_url = server + "/api/1.0/server/?limit=5000&allowed=1"
    api_response = api_call(api_url)
    unique_list = []
    unique_location = []
    data_output = {"data": [] }
    for main_groups in group:
        try:
            unique_list = []
            for array in api_response['data']:
                if array['type'] == main_groups and array['allowed'] == '1':
                    sub_group_name = array['group_name']
                    if sub_group_name not in unique_list:
                        unique_list.append(sub_group_name)
            for sorted_subgroup in unique_list:
                try:
                    unique_location = []
                    for value in api_response['data']:
                        if value['group_name'] == sorted_subgroup and value['type'] == main_groups:
                            region = value['location']
                            if region not in unique_location:
                                unique_location.append(region)
                    for sorted_location in unique_location:
                        data_output["data"].append({"{#GROUP}": main_groups, "{#SUB_GROUP}": sorted_subgroup, "{#REGION}": sorted_location })
                except Exception:
                    print("10")
                    exit(0)
        except Exception:
            print("8")
            exit(0)
    lld_zabbix = json.dumps(data_output)
    print(lld_zabbix)

def monitoring(server,region,group,sub_group,percentage_limit,status='0'):
    if len(group) != 1:
        print("9")
        exit(0)
    api_url = server + "/api/1.0/server/?limit=5000&allowed=1&type=" + group[0] + "&location=" + region + "&group_name=" + sub_group
    api_response = api_call(api_url)
    try:
        for hosts in api_response['data']:
            if hosts['allowed'] == '1':
                allowed_users = hosts['accounts_limit']
                current_users = hosts['count_accounts']
                percentage = (float(current_users) / float(allowed_users))
                percentage = int(percentage * 100)
                if percentage_limit > percentage:
                    status = '1'
                    break
        print(status)
    except Exception:
        print("10")
        exit(0)

def main():
    args = get_opts(protocol)
    if args.action == "discovery":
        discovering(args.server,args.group)
    elif args.action == "monitor":
        monitoring(args.server,args.region,args.group,args.sub_group,percentage_limit)


if __name__ == "__main__":
    main()

SEA-GHOST - SHELL CODING BY SEA-GHOST