PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /proc/thread-self/root/proc/self/root/proc/self/root/proc/self/root/opt/tier1adv/bin/
Server: Linux ngx353.inmotionhosting.com 4.18.0-553.22.1.lve.1.el8.x86_64 #1 SMP Tue Oct 8 15:52:54 UTC 2024 x86_64
IP: 209.182.202.254
Choose File :

Url:
Dir : //proc/thread-self/root/proc/self/root/proc/self/root/proc/self/root/opt/tier1adv/bin/create_db

#!/opt/imh-python/bin/python3
"""CLI tool to run as a cPanel user which creates a MySQL database"""
from argparse import ArgumentParser
import sys
import string
import random
from cpapis import uapi, CpAPIExecFail, CpAPIErrorMsg


def create_database(suffix: str):
    prefix = api('Mysql::get_restrictions')['data']['prefix']
    name = f"{prefix}{suffix}"
    chars = string.ascii_letters + string.digits + '_'
    passwd = ''.join([random.choice(chars) for _ in range(15)])
    api('Mysql::create_database', name=name)
    print("Created database:", name)
    api('Mysql::create_user', name=name, password=passwd)
    print("Created database user:", name)
    print(f"Password: '{passwd}'")
    api(
        'Mysql::set_privileges_on_database',
        user=name,
        database=name,
        privileges='ALL',
    )
    print("Assigned privileges.")


def api(mod: str, **kwargs):
    try:
        return uapi(mod, args=kwargs, check=True)['result']
    except CpAPIExecFail as exc:
        sys.exit(exc.stderr)


def main():
    try:
        parser = ArgumentParser(description=__doc__)
        parser.add_argument(
            'suffix', help='end of database name: USER_{suffix}'
        )
        suffix = parser.parse_args().suffix
        create_database(suffix)
    except KeyboardInterrupt:
        sys.exit(1)
    except CpAPIErrorMsg as exc:
        sys.exit(exc)


if __name__ == '__main__':
    main()