self::SLUG ), admin_url( 'admin.php' ) );
array_unshift( $links, '' . esc_html__( 'Settings', '360-orbit-login-guard' ) . '' );
return $links;
}
public static function register_menu() {
self::$hook = add_submenu_page(
Wp360_Login_Guard_Orbit_Menu::SLUG,
'Login Guard',
'Login Guard',
'manage_options',
self::SLUG,
array( __CLASS__, 'render_page' )
);
add_action( 'load-' . self::$hook, array( __CLASS__, 'add_screen_options' ) );
add_action( 'load-' . self::$hook, array( __CLASS__, 'add_help_tabs' ) );
}
/**
* Einheitliches Hilfe-Panel (README "Suite-übergreifend"): WordPress'
* eigene "Hilfe"-Lasche oben rechts mit den drei wichtigsten Fragen,
* statt sie ungenutzt zu lassen. Reine Texte, keine Logik.
*/
public static function add_help_tabs() {
$screen = get_current_screen();
if ( ! $screen ) {
return;
}
$screen->add_help_tab(
array(
'id' => 'wp360-lg-help-basics',
'title' => __( 'What does Login Guard do?', '360-orbit-login-guard' ),
'content' => '
' . __( 'It rate-limits login attempts per IP address (default: 5 failed attempts within 15 minutes locks that IP out for 20 minutes) and per account, and keeps a short login history. An administrator is only locked out of their own account from an address they recently signed in from after ten times the usual number of failed attempts, so a few typos cannot lock you out.', '360-orbit-login-guard' ) . '
' . __( 'Unlock any IP from the "Status & Lockouts" tab, or run "wp 360-orbit-login-guard unlock " via WP-CLI. If you also forgot a custom login URL (Pro), deleting the "wp360_lg_settings" option via WP-CLI or deactivating the plugin restores the default /wp-login.php.', '360-orbit-login-guard' ) . '
',
)
);
}
/**
* Deaktivierungs-Rückfrage (README "Suite-übergreifend"): kein Formular,
* nur ein kurzer Hinweis vor dem eigentlichen Deaktivieren in der
* Plugin-Liste, was dabei aufhoert und was erhalten bleibt.
*/
public static function enqueue_deactivation_notice_script( $hook ) {
if ( 'plugins.php' !== $hook || ! defined( 'WP360_LG_FILE' ) ) {
return;
}
$basename = plugin_basename( WP360_LG_FILE );
$message = __( 'Deactivate Login Guard? Rate limiting, two-factor enforcement (Pro) and any custom login URL (Pro) stop immediately — /wp-login.php becomes reachable again. Your settings and login history stay saved and come back if you reactivate the plugin.', '360-orbit-login-guard' );
// Kein eigenes Script-Tag im Markup (WordPress.org-Richtlinie): ein Handle
// ohne Datei, an das der Code per wp_add_inline_script() haengt.
wp_register_script( 'wp360-lg-deactivate', false, array(), WP360_LG_VERSION, true );
wp_enqueue_script( 'wp360-lg-deactivate' );
wp_add_inline_script(
'wp360-lg-deactivate',
sprintf(
'( function () {
var row = document.querySelector( %s );
var link = row ? row.querySelector( \'a[href*="action=deactivate"]\' ) : null;
if ( ! link ) {
return;
}
link.addEventListener( \'click\', function ( event ) {
if ( ! window.confirm( %s ) ) {
event.preventDefault();
}
} );
} )();',
wp_json_encode( 'tr[data-plugin="' . $basename . '"]' ),
wp_json_encode( $message )
)
);
}
/**
* Gesundheitscheck (README "Suite-übergreifend"): traegt zur
* gemeinsamen "360 WP Orbit"-Uebersicht bei -- rein lesend, nichts
* wird hier ausgeloest. Bewusst am gemeinsamen, nicht praefigierten
* Filter 'wp360_orbit_health' registriert (siehe class-orbit-menu.php).
*/
public static function health_lines( array $lines, $slug ) {
if ( '360-orbit-login-guard' !== $slug ) {
return $lines;
}
if ( class_exists( 'Wp360_Login_Guard_Guard' ) ) {
$locked = count( Wp360_Login_Guard_Guard::locked_entries() );
if ( $locked > 0 ) {
$lines[] = sprintf(
/* translators: %d: number of currently locked-out IP addresses */
_n( '%d IP currently locked out.', '%d IPs currently locked out.', $locked, '360-orbit-login-guard' ),
$locked
);
}
}
return $lines;
}
public static function add_screen_options() {
if ( 'history' !== self::current_tab() ) {
return;
}
add_screen_option(
'per_page',
array(
'label' => __( 'Entries per page', '360-orbit-login-guard' ),
'default' => 30,
'option' => Wp360_Login_Guard_List_Table::PER_PAGE_OPTION,
)
);
}
public static function sanitize_screen_option( $status, $option, $value ) {
return Wp360_Login_Guard_List_Table::PER_PAGE_OPTION === $option ? (int) $value : $status;
}
private static function current_tab() {
$valid = array( 'status', 'history', 'settings', 'transfer', 'pro' );
if ( isset( $_GET['tab'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
$tab = sanitize_key( wp_unslash( $_GET['tab'] ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
if ( in_array( $tab, $valid, true ) ) {
return $tab;
}
}
return 'status';
}
public static function enqueue_assets( $hook ) {
$is_profile = 'profile.php' === $hook;
if ( self::$hook !== $hook && ! $is_profile ) {
return;
}
wp_enqueue_style( 'wp360-lg-admin', WP360_LG_URL . 'assets/admin.css', array(), WP360_LG_VERSION );
$admin_deps = array( 'jquery' );
// QR-Code-Renderer fuer die Zwei-Faktor-Einrichtung (lokal, keine
// Drittanbieter-API); der 2FA-Block in admin.js ist per Element-Guard
// abgesichert.
wp_enqueue_script( 'wp360-lg-qrcode', WP360_LG_URL . 'assets/qrcode.js', array(), WP360_LG_VERSION, true );
$admin_deps[] = 'wp360-lg-qrcode';
wp_enqueue_script( 'wp360-lg-admin', WP360_LG_URL . 'assets/admin.js', $admin_deps, WP360_LG_VERSION, true );
wp_localize_script(
'wp360-lg-admin',
'wp360LoginGuard',
array(
'ajaxUrl' => admin_url( 'admin-ajax.php' ),
'nonce' => wp_create_nonce( 'wp360_lg_nonce' ),
'strings' => array(
'saved' => __( 'Saved.', '360-orbit-login-guard' ),
'saveError' => __( 'Error while saving.', '360-orbit-login-guard' ),
'unlocking' => __( 'Unlocking …', '360-orbit-login-guard' ),
'unlockError' => __( 'Error while unlocking.', '360-orbit-login-guard' ),
'quickstarting' => __( 'Applying …', '360-orbit-login-guard' ),
'quickstartError' => __( 'Error while applying the recommended settings.', '360-orbit-login-guard' ),
'enrolling' => __( 'Checking …', '360-orbit-login-guard' ),
'enrollError' => __( 'Invalid code. Please try again.', '360-orbit-login-guard' ),
'importing' => __( 'Importing …', '360-orbit-login-guard' ),
'importNoFile' => __( 'Please choose a file first.', '360-orbit-login-guard' ),
'importError' => __( 'Error while importing.', '360-orbit-login-guard' ),
'imported' => __( 'Imported. Reloading …', '360-orbit-login-guard' ),
),
)
);
}
private static function render_tabs( $current_tab ) {
$tabs = array( 'status' => __( 'Status & Lockouts', '360-orbit-login-guard' ) );
$tabs['history'] = __( 'Login History', '360-orbit-login-guard' );
// Ein einziger Pro-Tab statt mehrerer gesperrter Attrappen-Tabs
// (WordPress.org-Richtlinie 11: Upgrade-Hinweise sparsam und nur auf
// der eigenen Einstellungsseite).
$show_pro_tab = true;
$tabs['settings'] = __( 'Settings', '360-orbit-login-guard' );
$tabs['transfer'] = __( 'Export/Import', '360-orbit-login-guard' );
if ( $show_pro_tab ) {
$tabs['pro'] = __( 'Login Guard Pro', '360-orbit-login-guard' );
}
?>
$label ) { ?>
user_login;
}
}
return $found;
}
/**
* Zeigt der Anzeigename den Benutzernamen? Reine Logik.
*
* @param string $login Benutzername.
* @param string $display Anzeigename.
*/
public static function display_reveals_login( $login, $display ): bool {
return '' !== trim( (string) $login ) && 0 === strcasecmp( trim( (string) $login ), trim( (string) $display ) );
}
/**
* Konten, die Beitraege schreiben duerfen und deren oeffentlich sichtbarer
* Name der Benutzername ist. Angreifer muessen dann nur noch das Passwort raten.
*
* @return string[] Benutzernamen.
*/
private static function logins_shown_publicly() {
$found = array();
foreach ( get_users(
array(
'capability__in' => array( 'edit_posts' ),
'fields' => array( 'user_login', 'display_name' ),
'number' => 200,
)
) as $user ) {
if ( self::display_reveals_login( $user->user_login, $user->display_name ) ) {
$found[] = $user->user_login;
}
}
return $found;
}
private static function render_status_tab() {
$locked = Wp360_Login_Guard_Guard::locked_entries();
$locked_accounts = Wp360_Login_Guard_Guard::locked_accounts();
$recent = Wp360_Login_Guard_Database::recent_attempts( 10 );
$settings = Wp360_Login_Guard_Settings::get();
$weak_names = self::guessable_usernames();
?>
Beschriftung. Alle Felder bleiben in einer Box, damit das
* Speichern nie eine Gruppe zuruecksetzt; die nicht gewaehlten Gruppen sind nur ausgeblendet.
*
* @return array
*/
private static function settings_sections() {
return array(
'lockouts' => __( 'Lockouts', '360-orbit-login-guard' ),
'login' => __( 'Login form', '360-orbit-login-guard' ),
'hardening' => __( 'Hardening', '360-orbit-login-guard' ),
);
}
/**
* @return string Schluessel der gewaehlten Gruppe.
*/
private static function current_section() {
$section = isset( $_GET['section'] ) ? sanitize_key( wp_unslash( $_GET['section'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- nur lesende Auswahl der Gruppe.
return isset( self::settings_sections()[ $section ] ) ? $section : 'lockouts';
}
/**
* Alle Felder in EINER Box/EINEM Formular, auch wenn PRO-Felder dazu
* kommen -- der "Speichern"-Button ist ueber .wp360-lg-save unten rechts
* fixiert (siehe admin.css); zwei gleichzeitig sichtbare Buttons wuerden
* exakt uebereinander liegen und nur der zuletzt im DOM stehende waere
* klickbar, sodass ein Klick auf den (einzigen sichtbaren) Button lautlos
* die FALSCHEN Felder speichert. Frueher waren die PRO-Felder eine
* zweite Box mit eigenem Button -- genau dieser Effekt fuehrte dazu,
* dass angehakte Free-Felder beim Speichern verloren gingen.
*/
private static function render_settings_tab( array $settings ) {
$section = self::current_section();
$intros = array(
'lockouts' => __( 'When an IP address or account gets locked out, and who is told about it.', '360-orbit-login-guard' ),
'login' => __( 'What the login form shows and who gets a warning about a login.', '360-orbit-login-guard' ),
'hardening' => __( 'Which headers are trusted and which doors stay closed.', '360-orbit-login-guard' ),
);
?>
>
>
' . esc_html__( 'The WordPress registration is closed at the moment (Settings → General → Membership), so only other plugins can create accounts.', '360-orbit-login-guard' ) . '';
}
?>
ID );
// Wer 2FA schon nutzt, sieht den Block immer -- sie muss sich auch
// ohne Lizenz abschalten lassen. Einrichten: Administratoren (auch in
// der kostenlosen Version) und, mit Pro-Lizenz, Rollen mit 2FA-Pflicht.
if ( ! $enabled && ! ( Wp360_Login_Guard_Two_Factor::can_enroll( $user ) && ( user_can( $user, 'manage_options' ) || Wp360_Login_Guard_Two_Factor::is_required_for( $user ) ) ) ) {
return;
}
?>
360 Orbit ()
-- das steckt hier im Flex-Branding-Block, die Meldung erschiene also neben der Ueberschrift statt darunter. ?>
$plugin,
'status' => 'ok',
'label' => __( 'Login attempts are limited', '360-orbit-login-guard' ),
/* translators: 1: number of failed attempts, 2: lockout in minutes */
'hint' => sprintf( __( 'Lockout after %1$d failed attempts for %2$d minutes.', '360-orbit-login-guard' ), $settings['max_attempts'], $settings['lockout_minutes'] ),
'url' => $url,
);
$checks[] = array(
'plugin' => $plugin,
'status' => $settings['disable_xmlrpc'] ? 'ok' : 'warn',
'label' => $settings['disable_xmlrpc'] ? __( 'XML-RPC is switched off', '360-orbit-login-guard' ) : __( 'XML-RPC is open', '360-orbit-login-guard' ),
'hint' => $settings['disable_xmlrpc'] ? '' : __( 'Attackers can try many passwords in one request there. Switch it off unless an app needs it.', '360-orbit-login-guard' ),
'url' => $url,
);
$checks[] = array(
'plugin' => $plugin,
'status' => $settings['block_user_enumeration'] ? 'ok' : 'warn',
'label' => $settings['block_user_enumeration'] ? __( 'User names are hidden', '360-orbit-login-guard' ) : __( 'User names can be listed', '360-orbit-login-guard' ),
'hint' => '',
'url' => $url,
);
if ( get_option( 'users_can_register' ) ) {
$pending = Wp360_Login_Guard_Registration_Approval::count_pending();
$checks[] = array(
'plugin' => $plugin,
'status' => $settings['approve_registrations'] ? ( $pending ? 'warn' : 'ok' ) : 'info',
'label' => $settings['approve_registrations']
/* translators: %d: number of accounts */
? ( $pending ? sprintf( _n( '%d registration is waiting for approval', '%d registrations are waiting for approval', $pending, '360-orbit-login-guard' ), $pending ) : __( 'New registrations are approved by hand', '360-orbit-login-guard' ) )
: __( 'Anyone can register and sign in at once', '360-orbit-login-guard' ),
'hint' => $settings['approve_registrations'] ? '' : __( 'Approve new accounts by hand under Login Guard → Settings → Login form.', '360-orbit-login-guard' ),
'url' => $pending ? admin_url( 'users.php?wp360_lg_pending=1' ) : admin_url( 'admin.php?page=wp360-login-guard&tab=settings§ion=login' ),
);
}
$shown = self::logins_shown_publicly();
if ( $shown ) {
$checks[] = array(
'plugin' => $plugin,
'status' => 'warn',
/* translators: %s: list of usernames */
'label' => sprintf( __( 'The public name shows the username: %s', '360-orbit-login-guard' ), implode( ', ', $shown ) ),
'hint' => __( 'Choose a nickname as public name in the profile.', '360-orbit-login-guard' ),
'url' => admin_url( 'users.php' ),
);
}
$two_factor = Wp360_Login_Guard_Two_Factor::is_enabled( get_current_user_id() );
$checks[] = array(
'plugin' => $plugin,
'status' => $two_factor ? 'ok' : 'warn',
'label' => $two_factor ? __( 'Two-factor is active on your account', '360-orbit-login-guard' ) : __( 'Two-factor is not set up on your account', '360-orbit-login-guard' ),
'hint' => $two_factor ? '' : __( 'With a code from an authenticator app, a stolen password alone is not enough.', '360-orbit-login-guard' ),
'url' => admin_url( 'profile.php#wp360-lg-2fa' ),
);
$checks[] = array(
'plugin' => $plugin,
'status' => $settings['check_pwned_passwords'] ? 'ok' : 'info',
'label' => $settings['check_pwned_passwords'] ? __( 'Leaked passwords are rejected', '360-orbit-login-guard' ) : __( 'Leaked passwords are not checked', '360-orbit-login-guard' ),
'hint' => '',
'url' => $url,
);
return $checks;
}
}