multi language support
support for small devices
This commit is contained in:
		@@ -8,7 +8,7 @@ class OptionsPage
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        add_options_page(BDP_LV_PLUGIN_SLUG . '-limit-login-attempts',
 | 
			
		||||
            'Protect Login',
 | 
			
		||||
            __('Login-Protection', BDP_LV_PLUGIN_SLUG),
 | 
			
		||||
            'site-health.php',
 | 
			
		||||
            BDP_LV_PLUGIN_SLUG . '-limit-login-attempts',
 | 
			
		||||
            [$this, 'limit_login_option_page'],2048);
 | 
			
		||||
@@ -21,19 +21,52 @@ class OptionsPage
 | 
			
		||||
        update_option('kompass_limit_login_lockouts', $allIps);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	public static function addToBlocklist(string $ip)
 | 
			
		||||
	{
 | 
			
		||||
		$blockedIps = get_option('kompass_limit_login_blocklist', []);
 | 
			
		||||
		$blockedIps[] = $ip;
 | 
			
		||||
		update_option('kompass_limit_login_blocklist', $blockedIps);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
    public static function addToAllowlist(string $ip)
 | 
			
		||||
    {
 | 
			
		||||
        $allowedIps = get_option('kompass_limit_login_allowlist', []);
 | 
			
		||||
        $allowedIps[] = $ip;
 | 
			
		||||
        update_option('kompass_limit_login_allowlist', $allowedIps);
 | 
			
		||||
        self::releaseIp($ip);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function removeFromList(string $listType, string $ip){
 | 
			
		||||
        update_option(
 | 
			
		||||
                'kompass_limit_login_' . $listType,
 | 
			
		||||
                array_diff(get_option('kompass_limit_login_' . $listType, []), [$ip])
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public function getBlockedIps()
 | 
			
		||||
    {
 | 
			
		||||
        $ips = '';
 | 
			
		||||
        foreach (get_option('kompass_limit_login_lockouts', []) as $ip => $blockedUntil) {
 | 
			
		||||
            $ips .= '<tr>' .
 | 
			
		||||
                        '<td style="padding-right: 10px;">' . $ip . '</td>' .
 | 
			
		||||
                        '<td style="padding-right: 10px;">' . date('d.m.Y H:i', $blockedUntil) . ' Uhr</td>' .
 | 
			
		||||
                        '<td>
 | 
			
		||||
                            <a href="admin.php?page=bdp-kompass-limit-login-attempts&tab=tab4&action=release&ip=' .
 | 
			
		||||
                                        base64_encode($ip) . '">Freigeben</a></td>' .
 | 
			
		||||
                    '</tr>';
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
            $ips .= '<tr style="vertical-align: top;">' .
 | 
			
		||||
                '<td style="padding-right: 50px;">' . $ip . '</td>';
 | 
			
		||||
            if (in_array($ip, get_option('protect_login_limit_login_blocklist', []))) {
 | 
			
		||||
                $ips .= '<td style="padding-right: 50px;">Dauerhaft blockiert</td>' .
 | 
			
		||||
                    '<td>' .
 | 
			
		||||
                    'Keine Aktion möglich' .
 | 
			
		||||
                    '</td></tr>';
 | 
			
		||||
            } else {
 | 
			
		||||
                $ips .= '<td style="padding-right: 50px;">' . date('d.m.Y', $blockedUntil) . '<br />' . date('H:i', $blockedUntil) . ' Uhr</td>' .
 | 
			
		||||
                    '<td>
 | 
			
		||||
                                         <a href="admin.php?page=kompass-limit-login-attempts&tab=tab4&action=release&ip=' .
 | 
			
		||||
                    base64_encode($ip) . '">' . __('Release ip address', BDP_LV_PLUGIN_SLUG) . '</a><br />
 | 
			
		||||
                                        <a href="admin.php?page=bdp-kompass-limit-login-attempts&tab=tab4&action=toBlock&ip=' .
 | 
			
		||||
                    base64_encode($ip) . '">' . __('Add ip address to blocklist', BDP_LV_PLUGIN_SLUG) . '</a><br />
 | 
			
		||||
                                        <a href="admin.php?page=bdp-kompass-limit-login-attempts&tab=tab4&action=toAllow&ip=' .
 | 
			
		||||
                    base64_encode($ip) . '">' . __('Add ip address to allowlist and release', BDP_LV_PLUGIN_SLUG) . '</a><br /> ' .
 | 
			
		||||
                            '</td></tr>';
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
        return $ips;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -44,14 +77,14 @@ class OptionsPage
 | 
			
		||||
 | 
			
		||||
        if (isset($_POST['update_options'])) {
 | 
			
		||||
            update_settings($_POST);
 | 
			
		||||
            $showMessage = 'Die Einstellungen wurden gespeichert';
 | 
			
		||||
            $showMessage = __('The settings were saved.', BDP_LV_PLUGIN_SLUG);
 | 
			
		||||
        }
 | 
			
		||||
        if (isset($_GET['action']) && $_GET['action'] == 'release') {
 | 
			
		||||
            $showMessage = 'Die IP-Adresse wurde freigegeben.';
 | 
			
		||||
            $showMessage = __('The ip address was released.', BDP_LV_PLUGIN_SLUG);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if(isset($_POST['save_kompass_balist_list_type'])) {
 | 
			
		||||
            $showMessage = 'Die Liste wurde gespeichert.';
 | 
			
		||||
            $showMessage = __('The list was saved.', BDP_LV_PLUGIN_SLUG);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (null !== $showMessage && $errors === false) {
 | 
			
		||||
@@ -62,15 +95,26 @@ class OptionsPage
 | 
			
		||||
 | 
			
		||||
        if ($errors) {
 | 
			
		||||
            echo '<div class="notice notice-error" style="padding: 5px 10px;">';
 | 
			
		||||
            echo 'Beim Durchführen der Aktion ist ein Fehler aufgetreten.';
 | 
			
		||||
            echo __('An error occured.', BDP_LV_PLUGIN_SLUG);
 | 
			
		||||
            echo '</div>';
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $tab = isset($_GET['tab']) ? $_GET['tab'] : 'tab1';
 | 
			
		||||
 | 
			
		||||
        if (isset($_GET['action']) && $_GET['action'] == 'removeFromList') {
 | 
			
		||||
            $this->removeFromList($_GET['list'], base64_decode($_GET['ip']));
 | 
			
		||||
            if ($_GET['list'] == 'blocklist') {
 | 
			
		||||
                $tab = 'tab2';
 | 
			
		||||
            } else {
 | 
			
		||||
                $tab = 'tab3';
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        ?>
 | 
			
		||||
 | 
			
		||||
        <div class="wrap">
 | 
			
		||||
            <h1 class="wp-heading-inline">Protect Login - Einstellungen</h1>
 | 
			
		||||
            <h1 class="wp-heading-inline">
 | 
			
		||||
                <?= __('Login-Protection', BDP_LV_PLUGIN_SLUG); ?> - <?= __('Settings', BDP_LV_PLUGIN_SLUG); ?></h1>
 | 
			
		||||
            <hr class="wp-header-end">
 | 
			
		||||
            <?= kompass_print_tab_header($tab); ?>
 | 
			
		||||
 | 
			
		||||
@@ -101,22 +145,39 @@ class OptionsPage
 | 
			
		||||
                        if (isset($_GET['action']) && $_GET['action'] == 'release') {
 | 
			
		||||
                            $this->releaseIp(base64_decode($_GET['ip']));
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (isset($_GET['action']) && $_GET['action'] == 'toBlock') {
 | 
			
		||||
                            $this->addToBlocklist(base64_decode($_GET['ip']));
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        if (isset($_GET['action']) && $_GET['action'] == 'toAllow') {
 | 
			
		||||
                            $this->addToAllowlist(base64_decode($_GET['ip']));
 | 
			
		||||
                        }
 | 
			
		||||
                        $blockedIps = $this->getBlockedIps();
 | 
			
		||||
                        ?>
 | 
			
		||||
                        <h3>Gesperrte IPs</h3>
 | 
			
		||||
                        <?php
 | 
			
		||||
                        echo '<h2>'. __('Blocked IP addresses', BDP_LV_PLUGIN_SLUG) .'</h2>';
 | 
			
		||||
 | 
			
		||||
                            if (strlen($blockedIps) == 0) {
 | 
			
		||||
                                echo '<div class="protect-login-no-blocked-ips">';
 | 
			
		||||
                                echo 'Derzeit sind keine Adressen gesperrt.';
 | 
			
		||||
                                echo '<div class="bdp-kompass-no-blocked-ips">';
 | 
			
		||||
                                echo __('There are no ip addresses blocked.', BDP_LV_PLUGIN_SLUG);
 | 
			
		||||
                                echo '</div>';
 | 
			
		||||
                            } else { ?>
 | 
			
		||||
                                <table>
 | 
			
		||||
                                    <tr>
 | 
			
		||||
                                        <th>IP</th>
 | 
			
		||||
                                        <th>Gesperrt bis</th>
 | 
			
		||||
                                        <th>Aktion</th>
 | 
			
		||||
                                    </tr>
 | 
			
		||||
                                    <?= $blockedIps ?>
 | 
			
		||||
                                    <p style="width: 100%; text-align: right">
 | 
			
		||||
                                        <input type="text" id="searchInput"
 | 
			
		||||
                                               onkeyup="searchTable('myTable', this)"
 | 
			
		||||
                                               placeholder="<?=__('Search for ip address', BDP_LV_PLUGIN_SLUG); ?>">
 | 
			
		||||
                                    </p>
 | 
			
		||||
 | 
			
		||||
                                <table class="wp-list-table widefat fixed striped table-view-list" id="myTable">
 | 
			
		||||
                                    <thead>
 | 
			
		||||
                                        <tr>
 | 
			
		||||
                                            <th scope="col" class="manage-column column-name"><?= __('IP address', BDP_LV_PLUGIN_SLUG); ?></th>
 | 
			
		||||
                                            <th class="manage-column column-name"><?= __('Blocked until', BDP_LV_PLUGIN_SLUG); ?></th>
 | 
			
		||||
                                            <th class="manage-column column-name"><?= __('Actions', BDP_LV_PLUGIN_SLUG); ?></th>
 | 
			
		||||
                                        </tr>
 | 
			
		||||
                                    </thead>
 | 
			
		||||
                                    <tbody>
 | 
			
		||||
                                        <?= $blockedIps ?>
 | 
			
		||||
                                    </tbody>
 | 
			
		||||
                                </table>
 | 
			
		||||
                            <?php
 | 
			
		||||
                            }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user