<?php /*

 Composr
 Copyright (c) Christopher Graham, 2004-2024

 See docs/LICENSE.md for full licensing information.


 NOTE TO PROGRAMMERS:
   Do not edit this file. If you need to make changes, save your changed file to the appropriate *_custom folder
   **** If you ignore this advice, then your website upgrades (e.g. for bug fixes) will likely kill your changes ****

*/

/**
 * @license    http://opensource.org/licenses/cpal_1.0 Common Public Attribution License
 * @copyright  Christopher Graham
 * @package    securitylogging
 */

/**
 * Hook class.
 */
class Hook_addon_registry_securitylogging
{
    /**
     * Get a list of file permissions to set.
     *
     * @param  boolean $runtime Whether to include wildcards represented runtime-created chmoddable files
     * @return array File permissions to set
     */
    public function get_chmod_array(bool $runtime = false) : array
    {
        return [];
    }

    /**
     * Get the version of the software this addon is for (used in generating the TAR filename).
     *
     * @return float Version number
     */
    public function get_version() : float
    {
        return cms_version_number();
    }

    /**
     * Get the minimum required version of the website software needed to use this addon.
     *
     * @return float Minimum required website software version
     */
    public function get_min_cms_version() : float
    {
        return 11.0;
    }

    /**
     * Get the maximum compatible version of the website software to use this addon.
     *
     * @return ?float Maximum compatible website software version (null: no maximum version currently)
     */
    public function get_max_cms_version() : ?float
    {
        return 11.9;
    }

    /**
     * Get the addon category.
     *
     * @return string The category
     */
    public function get_category() : string
    {
        return 'Admin Utilities';
    }

    /**
     * Get the description of the addon.
     *
     * @return string Description of the addon
     */
    public function get_description() : string
    {
        return 'Log/display security alerts.';
    }

    /**
     * Get a list of tutorials that apply to this addon.
     *
     * @return array List of tutorials
     */
    public function get_applicable_tutorials() : array
    {
        return [
            'tut_security',
            'tut_trace',
        ];
    }

    /**
     * Get a mapping of dependency types.
     *
     * @return array A structure specifying dependency information
     */
    public function get_dependencies() : array
    {
        return [
            'requires' => [],
            'recommends' => [],
            'conflicts_with' => [],
            'previously_in_addon' => ['core_securitylogging'],
        ];
    }

    /**
     * Explicitly say which icon should be used.
     *
     * @return URLPATH Icon
     */
    public function get_default_icon() : string
    {
        return 'themes/default/images/icons/menu/adminzone/audit/security_log.svg';
    }

    /**
     * Get a list of files that belong to this addon.
     *
     * @return array List of files
     */
    public function get_file_list() : array
    {
        return [
            'adminzone/pages/modules/admin_ip_ban.php',
            'adminzone/pages/modules/admin_lookup.php',
            'adminzone/pages/modules/admin_security.php',
            'data/xml_config/advanced_banning.xml',
            'lang/EN/lookup.ini',
            'lang/EN/security.ini',
            'lang/EN/submitban.ini',
            'sources/hooks/modules/admin_stats/security_incidents.php',
            'sources/hooks/systems/actionlog/securitylogging.php',
            'sources/hooks/systems/addon_registry/securitylogging.php',
            'sources/hooks/systems/cns_warnings/ban_ip.php',
            'sources/hooks/systems/cns_warnings/syndicate.php',
            'sources/hooks/systems/commandr_commands/whois.php',
            'sources/hooks/systems/commandr_fs_extended_config/ip_banned.php',
            'sources/hooks/systems/commandr_fs_extended_config/ip_unbannable.php',
            'sources/hooks/systems/commandr_fs_extended_member/banned_from_submitting.php',
            'sources/hooks/systems/privacy/securitylogging.php',
            'sources/hooks/systems/realtime_rain/security.php',
            'sources/lookup.php',
            'themes/default/images/icons/menu/adminzone/audit/security_log.svg',
            'themes/default/images/icons/menu/adminzone/security/ip_ban.svg',
            'themes/default/images/icons/menu/adminzone/tools/users/investigate_user.svg',
            'themes/default/images/icons_monochrome/menu/adminzone/audit/security_log.svg',
            'themes/default/images/icons_monochrome/menu/adminzone/security/ip_ban.svg',
            'themes/default/images/icons_monochrome/menu/adminzone/tools/users/investigate_user.svg',
            'themes/default/javascript/securitylogging.js',
            'themes/default/templates/SECURITY_ALERT_SCREEN.tpl',
            'themes/default/templates/SECURITY_SCREEN.tpl',
            'themes/default/text/HACK_ATTEMPT_MAIL.txt',
        ];
    }

    /**
     * Get mapping between template names and the method of this class that can render a preview of them.
     *
     * @return array The mapping
     */
    public function tpl_previews() : array
    {
        return [
            'templates/SECURITY_SCREEN.tpl' => 'administrative__security_screen',
            'templates/SECURITY_ALERT_SCREEN.tpl' => 'administrative__security_alert_screen',
            'text/HACK_ATTEMPT_MAIL.txt' => 'administrative__hack_attempt_mail',
            'templates/IP_BAN_SCREEN.tpl' => 'ip_ban_screen',
            'templates/LOOKUP_IP_LIST_ENTRY.tpl' => 'administrative__lookup_screen',
            'templates/LOOKUP_IP_LIST_GROUP.tpl' => 'administrative__lookup_screen',
            'templates/LOOKUP_SCREEN.tpl' => 'administrative__lookup_screen',
        ];
    }

    /**
     * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
     * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declarative.
     * Assumptions: You can assume all Lang/CSS/JavaScript files in this addon have been pre-required.
     *
     * @return Tempcode Preview
     */
    public function tpl_preview__ip_ban_screen() : object
    {
        return lorem_globalise(do_lorem_template('IP_BAN_SCREEN', [
            'PING_URL' => placeholder_url(),
            'WARNING_DETAILS' => '',
            'TITLE' => lorem_screen_title(),
            'BANS' => placeholder_ip(),
            'UNBANNABLE' => placeholder_ip(),
            'LOCKED_BANS' => placeholder_ip(),
            'URL' => placeholder_url(),
        ]), null, '', true);
    }

    /**
     * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
     * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declarative.
     * Assumptions: You can assume all Lang/CSS/JavaScript files in this addon have been pre-required.
     *
     * @return Tempcode Preview
     */
    public function tpl_preview__administrative__hack_attempt_mail() : object
    {
        return lorem_globalise(do_lorem_template('HACK_ATTEMPT_MAIL', [
            'STACK_TRACE' => lorem_phrase(),
            'USER_AGENT' => lorem_phrase(),
            'REFERER' => lorem_phrase(),
            'USER_OS' => lorem_phrase(),
            'REASON' => lorem_phrase(),
            'IP' => placeholder_ip(),
            'ID' => placeholder_numeric_id(),
            'USERNAME' => lorem_word(),
            'TIME_RAW' => placeholder_date_raw(),
            'DATE' => placeholder_date(),
            'URL' => placeholder_url(),
            'POST' => lorem_phrase(),
        ], null, false, null, '.txt', 'text'), null, '', true);
    }

    /**
     * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
     * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declarative.
     * Assumptions: You can assume all Lang/CSS/JavaScript files in this addon have been pre-required.
     *
     * @return Tempcode Preview
     */
    public function tpl_preview__administrative__security_screen() : object
    {
        return lorem_globalise(do_lorem_template('SECURITY_SCREEN', [
            'TITLE' => lorem_screen_title(),
            'FAILED_LOGINS' => placeholder_table(),
            'NUM_FAILED_LOGINS' => placeholder_number(),
            'ALERTS' => lorem_phrase(),
            'NUM_ALERTS' => placeholder_number(),
            'URL' => placeholder_url(),
        ]), null, '', true);
    }

    /**
     * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
     * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declarative.
     * Assumptions: You can assume all Lang/CSS/JavaScript files in this addon have been pre-required.
     *
     * @return Tempcode Preview
     */
    public function tpl_preview__administrative__security_alert_screen() : object
    {
        return lorem_globalise(do_lorem_template('SECURITY_ALERT_SCREEN', [
            'TITLE' => lorem_screen_title(),
            'USER_AGENT' => lorem_phrase(),
            'REFERER' => lorem_phrase(),
            'USER_OS' => lorem_phrase(),
            'REASON' => lorem_phrase(),
            'IP' => lorem_phrase(),
            'USERNAME' => lorem_word(),
            'POST' => lorem_phrase(),
            'URL' => placeholder_url(),
            '_RISK_SCORE' => placeholder_number(),
            'RISK_SCORE' => placeholder_number(),
        ]), null, '', true);
    }

    /**
     * Get a preview(s) of a (group of) template(s), as a full standalone piece of HTML in Tempcode format.
     * Uses sources/lorem.php functions to place appropriate stock-text. Should not hard-code things, as the code is intended to be declarative.
     * Assumptions: You can assume all Lang/CSS/JavaScript files in this addon have been pre-required.
     *
     * @return Tempcode Preview
     */
    public function tpl_preview__administrative__lookup_screen() : object
    {
        $inner_ip_list = new Tempcode();
        foreach (placeholder_array() as $value) {
            $inner_ip_list->attach(do_lorem_template('LOOKUP_IP_LIST_ENTRY', [
                'LOOKUP_URL' => placeholder_url(),
                'DATE' => placeholder_date(),
                '_DATE' => placeholder_date(),
                'IP' => placeholder_ip(),
                'BANNED' => do_lang_tempcode('YES'),
                'RISK_SCORE' => placeholder_number(),
            ]));
        }

        $group = do_lorem_template('LOOKUP_IP_LIST_GROUP', [
            'BANNED' => do_lang_tempcode('YES'),
            'MASK' => placeholder_ip(),
            'GROUP' => $inner_ip_list,
            'OPEN_DEFAULT' => true,
        ]);
        return lorem_globalise(do_lorem_template('LOOKUP_SCREEN', [
            'TITLE' => lorem_screen_title(),
            'ALERTS' => lorem_phrase(),
            'STATS' => lorem_phrase(),
            'IP_LIST' => $group,
            'IP_BANNED' => lorem_phrase(),
            'SUBMITTER_BANNED' => lorem_phrase(),
            'MEMBER_BANNED' => lorem_phrase(),
            'MEMBER_ID' => placeholder_numeric_id(),
            'IP' => placeholder_ip(),
            'RISK_SCORE' => placeholder_number(),
            'EMAIL_ADDRESS' => lorem_phrase(),
            'USERNAME' => lorem_word(),
            'SEARCH_URL' => placeholder_url(),
            'AUTHOR_URL' => placeholder_url(),
            'POINTS_URL' => placeholder_url(),
            'PROFILE_URL' => placeholder_url(),
            'ACTIONLOG_URL' => placeholder_url(),
        ]), null, '', true);
    }
}
