PNG  IHDR* pHYs+ IDATx]n#; cdLb Ǚ[at¤_:uP}>!Usă cag޿ ֵNu`ݼTâabO7uL&y^wFٝA"l[|ŲHLN밪4*sG3|Dv}?+y߉{OuOAt4Jj.u]Gz*҉sP'VQKbA1u\`& Af;HWj hsO;ogTu uj7S3/QzUr&wS`M$X_L7r2;aE+ώ%vikDA:dR+%KzƉo>eOth$z%: :{WwaQ:wz%4foɹE[9<]#ERINƻv溂E%P1i01 |Jvҗ&{b?9g=^wζXn/lK::90KwrюO\!ջ3uzuGv^;騢wq<Iatv09:tt~hEG`v;3@MNZD.1]L:{ծI3`L(÷ba")Y.iljCɄae#I"1 `3*Bdz>j<fU40⨬%O$3cGt]j%Fߠ_twJ;ABU8vP3uEԑwQ V:h%))LfraqX-ۿX]v-\9I gl8tzX ]ecm)-cgʒ#Uw=Wlێn(0hPP/ӨtQ“&J35 $=]r1{tLuǮ*i0_;NƝ8;-vݏr8+U-kruȕYr0RnC]*ެ(M:]gE;{]tg(#ZJ9y>utRDRMdr9㪩̞zֹb<ģ&wzJM"iI( .ꮅX)Qw:9,i좜\Ԛi7&N0:asϓc];=ΗOӣ APqz93 y $)A*kVHZwBƺnWNaby>XMN*45~ղM6Nvm;A=jֲ.~1}(9`KJ/V F9[=`~[;sRuk]rєT!)iQO)Y$V ی ۤmzWz5IM Zb )ˆC`6 rRa}qNmUfDsWuˤV{ Pݝ'=Kֳbg,UҘVz2ﴻnjNgBb{? ߮tcsͻQuxVCIY۠:(V뺕 ٥2;t`@Fo{Z9`;]wMzU~%UA蛚dI vGq\r82iu +St`cR.6U/M9IENDB` REDROOM
PHP 5.6.40
Preview: build_includes.py Size: 4.98 KB
/usr/share/imunify360-webshield/build_includes.py

#!/opt/imunify360/venv/bin/python3

import codecs
import functools
import os
import re
import subprocess
import sys

import jinja2
from babel.messages.pofile import read_po

EXT = 'html'
LANG_BASENAME = 'lang.conf'
LANG_LINE = '"~^{lang}" {lang};'
LOCALE_PATH = 'locale'

INCLUDE = '{{["{path}/" .. (ngx.var.{item}_lang or "en") .. "/{name}.{ext}"]}}'
CURRENT_LOCALE = '{{{{ngx.var.{item}_lang or "en"}}}}'

VARIABLES = {
    'client_ip': '{{ngx.var.wsuserip or ngx.var.remote_addr}}',
    "domain": '{{ngx.var.host or "Server"}}',
    "webshield": True,
}


def _gettext(message, **_):
    name = _normalize(message)
    item = ''
    return INCLUDE.format(path=LOCALE_PATH, item=item, name=name, ext=EXT)


def _captcha_gettext(message, **_):
    name = _normalize(message)
    item = 'captcha'
    return INCLUDE.format(path=LOCALE_PATH, item=item, name=name, ext=EXT)


def _splashscreen_gettext(message, **_):
    name = _normalize(message)
    item = 'splashscreen'
    return INCLUDE.format(path=LOCALE_PATH, item=item, name=name, ext=EXT)


@functools.lru_cache()
def _normalize(s):
    s = re.sub('<.*?>', '', s)
    s = re.sub('{.*?}', '', s)
    s = s.lower()
    s = re.sub('[^a-z0-9 ]', '', s)
    s = re.sub('\s+', '_', s)
    return s


def _mkdir_p(path):
    try:
        os.makedirs(path)
    except FileExistsError:
        pass


class Template:

    items = {
        'captcha': _captcha_gettext,
        'splashscreen': _splashscreen_gettext}

    def __init__(self, tpl_path, item):
        path, self.filename = os.path.split(tpl_path)
        jinja_env = jinja2.Environment(
            extensions=['jinja2.ext.i18n'],
            loader=jinja2.FileSystemLoader(path or './'),
        )
        jinja_env.globals['_'] = self.items.get(item, _gettext)
        self.jinja_env = jinja_env

    def render(self, context):
        return self.jinja_env.get_template(self.filename).render(context)


def render_template(item, source, destination_dir):
    template = os.path.join(source, item, 'templates', 'index.html')
    destination = os.path.join(destination_dir, item)
    _mkdir_p(destination)
    fullname = os.path.join(destination, 'index.html')
    _vars = dict(VARIABLES, current_locale=CURRENT_LOCALE.format(item=item))
    with codecs.open(fullname, 'w', encoding='utf-8') as w:
        render = Template(template, item).render(_vars)
        w.write(render)


def _make_locale(item, translation_dir, destination_dir, lang):
    path = os.path.join(translation_dir, lang, 'LC_MESSAGES', 'messages.po')
    with codecs.open(path, encoding='utf-8') as r:
        po = read_po(r)

    locale = os.path.join(destination_dir, LOCALE_PATH, lang)
    _mkdir_p(locale)
    _vars = dict(VARIABLES, current_locale=CURRENT_LOCALE.format(item=item))
    for message in po:
        if message.id:
            basename = os.extsep.join([_normalize(message.id), EXT])
            msg = message.string or message.id
            rendered = msg.format(
                client_ip=_vars['client_ip'],
                current_locale=_vars['current_locale'],
                domain=_vars['domain'],
                webshield=_vars['webshield'])
            fullname = os.path.join(locale, basename)
            with codecs.open(fullname, 'w', encoding='utf-8') as w:
                w.write(rendered)


def convert_translations(item, source, dst_prefix):
    translation_dir = os.path.join(source, item, 'translations', 'locale')
    destination_dir = os.path.join(dst_prefix, item)
    locales = os.listdir(translation_dir)
    for lang in locales:
        _make_locale(item, translation_dir, destination_dir, lang)
    return locales


def print_lang(name, locales, target):
    if target is not None:
        conf_dir = os.path.join(target, name)
        _mkdir_p(conf_dir)
        conf_path = os.path.join(conf_dir, LANG_BASENAME)
        with codecs.open(conf_path, 'w', encoding='utf-8') as w:
            for lang in sorted(locales):
                w.write(LANG_LINE.format(lang=lang) + '\n')
    else:
        for lang in sorted(locales):
            print(LANG_LINE.format(lang=lang))


def copy_static(source, destination, prefix):
    static_src = os.path.join(source, prefix, 'static')
    if os.path.isdir(static_src):
        static_dst = os.path.join(
            destination, prefix, 'a9bc224bd710f56d27affffddc764239b58c3faa0')
        _mkdir_p(static_dst)

        # '/.' is a special syntax of 'cp' command, meaning copying
        # the contents of the directory, not the directory itself
        cmd = ['cp', '-r', static_src + '/.', static_dst + '/']
        subprocess.call(cmd,
                        stdout=subprocess.DEVNULL,
                        stderr=subprocess.DEVNULL)


def main():
    items = sys.argv[1].split(',')
    src = sys.argv[2]
    dst = sys.argv[3]
    target = sys.argv[4] if len(sys.argv) > 4 else None
    for item in items:
        render_template(item, src, dst)
        locales = convert_translations(item, src, dst)
        print_lang(item, locales, target)
        copy_static(src, dst, item)


if __name__ == '__main__':
    main()

Directory Contents

Dirs: 3 × Files: 10

Name Size Perms Modified Actions
captcha DIR
- drwxr-xr-x 2025-12-23 23:01:22
Edit Download
modules DIR
- drwxr-xr-x 2025-12-23 23:01:22
Edit Download
- drwxr-xr-x 2025-12-23 23:01:22
Edit Download
12 B lrw-r--r-- 2025-06-30 23:02:48
Edit Download
231 B lrw-r--r-- 2025-12-10 13:08:24
Edit Download
4.98 KB lrwxr-xr-x 2025-12-10 13:08:24
Edit Download
6.75 KB lrwxr-xr-x 2025-12-10 13:08:24
Edit Download
6.75 KB lrwxr-xr-x 2025-12-10 13:08:24
Edit Download
11 B lrw-r--r-- 2025-06-19 23:01:58
Edit Download
8 B lrw-r--r-- 2025-12-10 13:08:24
Edit Download
118 B lrw-r--r-- 2025-12-10 13:08:24
Edit Download
10.61 KB lrwxr-xr-x 2025-12-10 13:08:24
Edit Download
26.70 KB lrwxr-xr-x 2025-12-10 13:08:24
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).
© 2026 REDROOM — Secure File Manager. All rights reserved. Built with ❤️ & Red Dark UI