Ejemplo n.º 1
0
def _setLinkTo(thisFile):
    import os
    try:
        link = thisFile.replace(configs.VIRTUAL_HOSTS_AVAILABLE_PATH, configs.VIRTUAL_HOSTS_ENABLED_PATH)
        os.link(thisFile, link)
        info('Linked file "{}" to "{}"'.format(thisFile, link))
    except Exception as e:
        error('_setLinkTo from helper file', e)
Ejemplo n.º 2
0
def wsgi(
        domain,
        documentRoot,
        wsgiScript,
        email,
        virtualenv,
        StaticFolderName,
        enable_static,
        http2,
):
    """
        Initialize WSGI Template
    """
    try:
        # Check Enable HTTP2 or NOT
        if http2:
            _checkHTTP2Enabled()
        # Check Enable WSGI or NOT
        _checkWSGIEnabled()

        # validation
        DOMAIN = __validUrl(domain)
        email = __validEmail(email if email else "admin@{}".format(DOMAIN))
        __wsgiAddressValidation(
            documentRoot,
            wsgiScript,
            virtualenv,
            StaticFolderName,
            enable_static
        )

        # Load and Mapping
        result = mapping(templateLoader(WSGI_TEMPLATE_NAME),wsgiTemplateMaps(
            domain,
            documentRoot,
            wsgiScript,
            email,
            StaticFolderName,
            virtualenv,
            enable_static,
            http2,
        ))

        # Try to Create VirtualHost File
        if not _createVirtualHost(DOMAIN,result) :
            error('wsgi from cli file',"Cant Create VirtualHost File")

        # # Try add Domain to HOSTS file
        if not _addToHosts(DOMAIN):
            error('wsgi from cli file', "Cant Add Domain to '{}' File".format(HOSTS))

        info('Now Reload Your Apache2 Service: `sudo systemctl reload apache2.service`')
    except Exception as e:
        error('wsgi from cli file', e)
Ejemplo n.º 3
0
def _createVirtualHost(domain, content):
    """
    Create VirtualHost File
    :param content: Your Content That you want Write to File
    :return: True if File Created , False if Not Created
    """
    try:
        PATH = os.path.join(configs.VIRTUAL_HOSTS_AVAILABLE_PATH, domain)
        VirtualHostFileAddress = "{}{}".format(PATH, configs.EXTENSION)
        with open(VirtualHostFileAddress, 'w') as file:
            file.write(content)
        info("VirtualHost Created On '{}'".format(VirtualHostFileAddress))
        _setLinkTo(VirtualHostFileAddress)
        return True
    except Exception as e:
        error('_createVirtualHost from helper file', (e))
Ejemplo n.º 4
0
def _addToHosts(domain):
    """
    Add Your Domain in configs.HOSTS
    :param domain: Your Domain
    """
    try:
        __backup(configs.HOSTS)
        data = mapping(templateLoader(configs.HOST_TEMPLATE_NAME), hostTemplateMaps(
            domain=domain
        ))
        with open(configs.HOSTS, 'a') as file:
            file.write("{}\n".format(data))
        info("Added Domain On '{}'".format(configs.HOSTS))
        return True
    except Exception as e:
        error('_addToHosts from helper file', (e))
Ejemplo n.º 5
0
def php(domain, documentRoot, email, http2):
    """
        Initialize PHP Template
    """
    try:
        # Check Enable HTTP2 or NOT
        if http2:
            _checkHTTP2Enabled()

        # validation
        DOMAIN = __validUrl(domain)
        email = __validEmail(email if email else "admin@{}".format(DOMAIN))
        __phpAddressValidation(documentRoot)

        # get Result
        result = mapping(
            templateLoader(PHP_TEMPLATE_NAME),
            phpTemplateMaps(server_admin=email,
                            document_root=documentRoot,
                            server_name=DOMAIN,
                            http2=http2))

        # Try to Create VirtualHost File
        if not _createVirtualHost(DOMAIN, result):
            error('php from cli file', "Cant Create VirtualHost File")

        # # Try add Domain to HOSTS file
        if not _addToHosts(DOMAIN):
            error('php from cli file',
                  "Cant Add Domain to '{}' File".format(HOSTS))

        info(
            'Now Reload Your Apache2 Service: `sudo systemctl reload apache2.service`'
        )
    except Exception as e:
        error('php from cli file', e)