Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 0 additions & 29 deletions assets/css/magicauth-admin.css
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,6 @@ body.admin-bar .magicauth-admin .magicauth-topbar__bar { top: 32px; }
.magicauth-admin .magicauth-row + .magicauth-action-row,
.magicauth-admin .magicauth-action-row + .magicauth-row { border-top: 1px solid var(--ettic-border); }

.magicauth-admin .magicauth-action-row--alert {
background: #FEF2F2;
border-radius: 8px;
padding-left: 14px;
padding-right: 14px;
box-shadow: inset 3px 0 0 #DC2626;
}

.magicauth-admin .magicauth-action-row__main h3 {
margin: 0;
font-size: 13.5px;
Expand Down Expand Up @@ -1095,27 +1087,6 @@ body > .magicauth-modal-backdrop.is-leaving { animation: magicauth-backdrop-out
font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

.magicauth-modal-backdrop .magicauth-modal-list {
margin: 10px 0 0;
padding-left: 18px;
}
.magicauth-modal-backdrop .magicauth-modal-list li { margin: 0 0 4px; }

.magicauth-modal-backdrop .magicauth-salt-block {
width: 100%;
margin: 10px 0;
padding: 10px 12px;
border: 1px solid #E2E5E9;
border-radius: 6px;
background: #F5F7FA;
font-family: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
font-size: 11.5px;
line-height: 1.5;
color: #1F2733;
resize: vertical;
white-space: pre;
}

.magicauth-modal-backdrop .magicauth-modal__foot {
padding: 14px 18px;
background: #F5F7FA;
Expand Down
113 changes: 0 additions & 113 deletions assets/js/magicauth-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
initToastFromUrl();
initDiscardFlash();
initRecoveryActions();
initSaltFix();
initUserProfile();
}

Expand Down Expand Up @@ -686,118 +685,6 @@
} );
}

// Salt-fix wizard — "Fix WordPress salts"
function initSaltFix() {
var root = document.querySelector( '.magicauth-recovery' );
if ( ! root ) {
return;
}
var btn = root.querySelector( '[data-magicauth-salt-fix]' );
if ( ! btn ) {
return;
}

var ajaxurl = root.getAttribute( 'data-ajaxurl' ) || ( window.ajaxurl || '' );
var nonce = root.getAttribute( 'data-nonce' ) || '';

function post( mode ) {
return fetch( ajaxurl, {
method: 'POST',
credentials: 'same-origin',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams( { action: 'magicauth_admin_fix_salts', mode: mode, _ajax_nonce: nonce } )
} ).then( function ( res ) { return res.json(); } );
}

function escapeHtml( str ) {
return String( str ).replace( /[&<>"']/g, function ( c ) {
return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[ c ];
} );
}

var effects =
'<p>Fresh, random values will be generated for all eight WordPress security keys.</p>' +
'<ul class="magicauth-modal-list">' +
'<li><strong>Everyone is signed out.</strong> All sessions (including yours) end — you will sign in again right after.</li>' +
'<li><strong>Pending sign-in links and codes stop working.</strong> They were signed with the old keys, so anyone mid-sign-in requests a fresh email.</li>' +
'<li><strong>The branded login screen stays off.</strong> Fixing salts never flips that toggle — you turn the replacement on yourself when ready.</li>' +
'</ul>';

// Open the salt-fix wizard: hand the admin fresh salts to paste in.
function openManual( block ) {
var body =
effects +
'<p>Copy these freshly generated salts and replace the matching <code>define()</code> lines in <code>wp-config.php</code>, then save the file. Need a hand? <a href="' + ( root.getAttribute( 'data-docs' ) || 'https://docs.ettic.nl/docs/magicauth/weak-salts' ) + '" target="_blank" rel="noopener">Read the step-by-step guide</a>.</p>' +
'<textarea class="magicauth-salt-block" readonly rows="8">' + escapeHtml( block ) + '</textarea>' +
'<button type="button" class="magicauth-btn magicauth-btn--ghost magicauth-btn--sm" data-salt-copy>Copy to clipboard</button>';

showConfirm( {
title: 'Fix WordPress salts',
lede: 'Copy these fresh salts into wp-config.php.',
body: body,
confirmText: 'I have updated wp-config.php',
cancelText: 'Close',
onBody: function ( bodyEl ) {
var copyBtn = bodyEl.querySelector( '[data-salt-copy]' );
var area = bodyEl.querySelector( '.magicauth-salt-block' );
if ( ! copyBtn || ! area ) {
return;
}
copyBtn.addEventListener( 'click', function () {
area.focus();
area.select();
var done = function () { copyBtn.textContent = 'Copied'; setTimeout( function () { copyBtn.textContent = 'Copy to clipboard'; }, 1500 ); };
if ( navigator.clipboard && navigator.clipboard.writeText ) {
navigator.clipboard.writeText( area.value ).then( done, function () {} );
} else {
try { document.execCommand( 'copy' ); done(); } catch ( e ) {}
}
} );
},
onConfirm: function () {
return post( 'recheck' ).then( function ( payload ) {
if ( ! payload || ! payload.success ) {
showToast( { type: 'error', message: ( payload && payload.data && payload.data.message ) || 'Still detecting weak salts.' } );
return false; // keep the modal open so they can fix and retry
}
showToast( { type: 'success', message: payload.data.message || 'Salts updated.' } );
setTimeout( function () { window.location.reload(); }, 1500 );
} ).catch( function () {
showToast( { type: 'error', message: 'Network error. Please try again.' } );
return false;
} );
}
} );
}

function openWizard() {
setLoading( btn, true, 'Checking…' );
post( 'preview' ).then( function ( payload ) {
setLoading( btn, false );
if ( ! payload || ! payload.success ) {
showToast( { type: 'error', message: ( payload && payload.data && payload.data.message ) || 'Could not start the wizard.' } );
return;
}
openManual( payload.data.block || '' );
} ).catch( function () {
setLoading( btn, false );
showToast( { type: 'error', message: 'Network error. Please try again.' } );
} );
}

btn.addEventListener( 'click', function ( ev ) {
ev.preventDefault();
openWizard();
} );

// Auto-open when arriving from the admin notice's "Fix it for me" button.
try {
if ( new URLSearchParams( window.location.search ).get( 'magicauth-fix-salts' ) === '1' ) {
openWizard();
}
} catch ( e ) {}
}

// User-profile actions — surfaced through toasts
function initUserProfile() {
var root = document.querySelector( '.magicauth-user-fields' );
Expand Down
52 changes: 1 addition & 51 deletions includes/Admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public static function setup(): void {
add_action( 'admin_post_magicauth_send_test_email', [ self::class, 'handle_test_send' ] );
add_action( 'wp_ajax_magicauth_admin_revoke_all_tokens', [ self::class, 'ajax_revoke_all_tokens' ] );
add_action( 'wp_ajax_magicauth_admin_reset_throttle', [ self::class, 'ajax_reset_throttle' ] );
add_action( 'wp_ajax_magicauth_admin_fix_salts', [ self::class, 'ajax_fix_salts' ] );
add_action( 'current_screen', [ self::class, 'suppress_foreign_notices' ] );
add_filter( 'plugin_action_links_' . plugin_basename( MAGICAUTH_FILE ), [ self::class, 'plugin_action_links' ] );
}
Expand Down Expand Up @@ -250,20 +249,7 @@ private static function render_section_diagnostics(): void {
</header>
<div class="magicauth-card magicauth-recovery"
data-ajaxurl="<?php echo esc_url( $ajaxurl ); ?>"
data-nonce="<?php echo esc_attr( $recovery_nonce ); ?>"
data-docs="<?php echo esc_url( Installer::DOCS_SALTS_URL ); ?>">

<?php if ( Installer::has_weak_salts() ) : ?>
<div class="magicauth-action-row magicauth-action-row--alert">
<div class="magicauth-action-row__main">
<h3><?php esc_html_e( 'Fix WordPress salts', 'magicauth' ); ?></h3>
<p><?php esc_html_e( 'Your security keys hold placeholder or empty values. Generate fresh ones and paste them into wp-config.php yourself. This does not turn on the branded login screen — you stay in control of that.', 'magicauth' ); ?></p>
</div>
<button type="button" class="magicauth-btn magicauth-btn--primary magicauth-btn--sm" data-magicauth-salt-fix>
<?php esc_html_e( 'Fix salts…', 'magicauth' ); ?>
</button>
</div>
<?php endif; ?>
data-nonce="<?php echo esc_attr( $recovery_nonce ); ?>">

<div class="magicauth-action-row">
<div class="magicauth-action-row__main">
Expand Down Expand Up @@ -823,40 +809,4 @@ public static function ajax_reset_throttle(): void {
]
);
}

/**
* AJAX: salt-fix helper ("Fix WordPress salts"). Two modes:
* - preview: return a ready-to-paste block of freshly generated salts.
* - recheck: re-evaluate the salts and clear the notice once they are strong
* (used after the admin pastes the salts into wp-config.php).
* MagicAuth never writes wp-config.php itself, and never auto-enables the
* branded login replacement.
*/
public static function ajax_fix_salts(): void {
check_ajax_referer( 'magicauth-admin-recovery' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( [ 'message' => __( 'You are not allowed to do this.', 'magicauth' ) ], 403 );
}

$mode = 'preview';
if ( isset( $_POST['mode'] ) && is_string( $_POST['mode'] ) ) {
$mode = sanitize_key( wp_unslash( $_POST['mode'] ) );
}

if ( 'recheck' === $mode ) {
$result = Installer::recheck_salts_from_file();
if ( ! $result['ok'] ) {
wp_send_json_error( [ 'message' => $result['message'] ] );
}
wp_send_json_success( [ 'message' => $result['message'] ] );
}

// Default: preview. MagicAuth never edits wp-config.php; it generates a
// fresh block of salts for the admin to paste in themselves.
wp_send_json_success(
[
'block' => Installer::generate_salt_block(),
]
);
}
}
Loading
Loading