HEX
Server: LiteSpeed
System: Linux kapuas.iixcp.rumahweb.net 5.14.0-427.42.1.el9_4.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Nov 1 14:58:02 EDT 2024 x86_64
User: mirz4654 (1666)
PHP: 8.1.33
Disabled: system,exec,escapeshellarg,escapeshellcmd,passthru,proc_close,proc_get_status,proc_nice,proc_open,proc_terminate,shell_exec,popen,pclose,dl,pfsockopen,leak,apache_child_terminate,posix_kill,posix_mkfifo,posix_setsid,posix_setuid,posix_setpgid,ini_alter,show_source,define_syslog_variables,symlink,syslog,openlog,openlog,closelog,ocinumcols,listen,chgrp,apache_note,apache_setenv,debugger_on,debugger_off,ftp_exec,dll,ftp,myshellexec,socket_bind,mail,posix_getwpuid
Upload Files
File: //opt/cloudlinux/venv/lib64/python3.11/site-packages/clwpos/feature_suites/suites.py
# -*- coding: utf-8 -*-

# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2022 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT

# suites.py - definitions of AccelerateWP feature suites
from enum import Enum
from typing import Set, List, Dict, Any

from clwpos.optimization_features import (
    Feature,
    OBJECT_CACHE_FEATURE,
    SITE_OPTIMIZATION_FEATURE,
    CDN_FEATURE,
    CRITICAL_CSS_FEATURE,
    IMAGE_OPTIMIZATION_FEATURE
)
from dataclasses import dataclass, field
from clwpos.utils import is_wp2_environment_safe

PREMIUM_ENABLE_FLAG = '/var/lve/enable-wpos.flag'
IS_FREE_SUITE_ALLOWED_BY_DEFAULT = False
IS_PREMIUM_SUITE_ALLOWED_BY_DEFAULT = False
IS_CDN_SUITE_ALLOWED_BY_DEFAULT = False


class TrafficLimit(Enum):
    LIMIT_50_GB = "50 GB"
    LIMIT_100_GB = "100 GB"
    LIMIT_250_GB = "250 GB"
    LIMIT_500_GB = "500 GB"
    LIMIT_1_TB = "1 TB"
    LIMIT_2_5_TB = "2.5 TB"
    LIMIT_5_TB = "5 TB"
    LIMIT_10_TB = "10 TB"


@dataclass
class Attribute:
    """Base model of attribute supported by suite"""
    name: str
    type: type

    default: Any = None


@dataclass
class Suite:
    """Base Suite implementation"""
    name: str
    features: Set
    # for some cases we need to handle only primary feature (e.g for CDN suite = cdn feature)
    primary: Set
    is_allowed_by_default: bool

    billable_features: Set[Feature] = field(default_factory=set)
    allowed_attrubites: List[Attribute] = field(default_factory=list)

    @property
    def feature_set(self) -> Set[Feature]:
        """"""
        return self.features

    @property
    def primary_features(self) -> Set[Feature]:
        """"""
        return self.primary

    def non_billable_features(self) -> Set[Feature]:
        return self.primary.difference(self.billable_features)


AWPSuite = Suite(
    name='accelerate_wp',
    features={
        SITE_OPTIMIZATION_FEATURE
    },
    primary={
        SITE_OPTIMIZATION_FEATURE
    },
    is_allowed_by_default=IS_FREE_SUITE_ALLOWED_BY_DEFAULT
)

PremiumSuite = Suite(
    name='accelerate_wp_premium',
    features={
        OBJECT_CACHE_FEATURE,
        CRITICAL_CSS_FEATURE,
        IMAGE_OPTIMIZATION_FEATURE
    },
    primary={
        OBJECT_CACHE_FEATURE,
        CRITICAL_CSS_FEATURE,
        IMAGE_OPTIMIZATION_FEATURE
    },
    is_allowed_by_default=IS_PREMIUM_SUITE_ALLOWED_BY_DEFAULT,
    billable_features=(
        {IMAGE_OPTIMIZATION_FEATURE} |
        ({CRITICAL_CSS_FEATURE} if not is_wp2_environment_safe() else set())
    )
)

# Free CDN suite (1GB)
CDNSuite = Suite(
    name='accelerate_wp_cdn',
    features={
        SITE_OPTIMIZATION_FEATURE,
        CDN_FEATURE
    },
    primary={
        CDN_FEATURE
    },
    is_allowed_by_default=IS_CDN_SUITE_ALLOWED_BY_DEFAULT,
    billable_features={
        CDN_FEATURE
    }
)

# Premium CDN suite (50GB)
CDNSuitePro = Suite(
    name='accelerate_wp_cdn_pro',
    features={
        SITE_OPTIMIZATION_FEATURE,
        CDN_FEATURE
    },
    primary={
        CDN_FEATURE
    },
    is_allowed_by_default=IS_PREMIUM_SUITE_ALLOWED_BY_DEFAULT,
    billable_features={
        CDN_FEATURE
    },
    allowed_attrubites=[
        Attribute(name='traffic_limit', type=TrafficLimit, default=TrafficLimit.LIMIT_50_GB)
    ]
)


ALL_SUITES: Dict[str, Suite] = {
    AWPSuite.name: AWPSuite,
    PremiumSuite.name: PremiumSuite,
    CDNSuite.name: CDNSuite,
    CDNSuitePro.name: CDNSuitePro
}

SUPPORTED_SUITES = {
    AWPSuite.name: AWPSuite,
    PremiumSuite.name: PremiumSuite,
    CDNSuite.name: CDNSuite,
    CDNSuitePro.name: CDNSuitePro
}

UNSUPPORTED_SUITES_FOR_RESELLER = [
    CDNSuite.name,
    CDNSuitePro.name,
]

# for backward compatibility with old configs
OLD_NEW_SUITE_NAME_PAIRS = {
    'object_cache': 'accelerate_wp_premium',
    'site_optimization': 'accelerate_wp'
}

BILLABLE_SUITES = {
    name for name, value in ALL_SUITES.items()
    if value.billable_features
}