mirror of
https://github.com/CyberSecurityUP/NeuroSploit.git
synced 2026-12-05 18:44:48 +01:00
Merge pull request #106 from JoasASantos/fix/settings-saved-model
fix(web): Settings saves the selected model (live catalog)
This commit is contained in:
1 file changed
+26
-16
+26
-16
@@ -669,7 +669,7 @@ async function loadProviders() {
|
||||
const parts = cfg.defaultModel.split(':');
|
||||
if (parts.length >= 2) {
|
||||
sel.value = parts[0];
|
||||
onProviderChange();
|
||||
onProviderChange(parts.slice(1).join(':'));
|
||||
$('#fieldModelSelect').value = parts.slice(1).join(':');
|
||||
sanitizeModelSelect();
|
||||
return;
|
||||
@@ -687,12 +687,13 @@ function sanitizeModelSelect(prefer) {
|
||||
if (!opts.includes(ms.value)) ms.value = opts[0];
|
||||
}
|
||||
|
||||
function onProviderChange() {
|
||||
function onProviderChange(preferredModel) {
|
||||
const prefer = typeof preferredModel === 'string' ? preferredModel : '';
|
||||
const p = state.providers.find((x) => x.key === $('#fieldProvider').value) || state.providers[0];
|
||||
const modelSel = $('#fieldModelSelect');
|
||||
const prev = modelSel.value;
|
||||
modelSel.innerHTML = (p?.models || []).map((m) => `<option value="${esc(m)}">${esc(m)}</option>`).join('');
|
||||
sanitizeModelSelect(prev);
|
||||
sanitizeModelSelect(prefer || prev);
|
||||
// The seeded list is only a fallback — pull the provider's full live catalog
|
||||
// (OpenRouter, OpenAI, DeepSeek, Groq, Gemini, local runtimes, …).
|
||||
const provKey = p?.key;
|
||||
@@ -701,7 +702,7 @@ function onProviderChange() {
|
||||
if ($('#fieldProvider')?.value !== provKey) return;
|
||||
const list = r.models || [];
|
||||
if (!list.length) return;
|
||||
const keep = modelSel.value;
|
||||
const keep = (prefer && list.includes(prefer)) ? prefer : modelSel.value;
|
||||
modelSel.innerHTML = list.map((m) => `<option value="${esc(m)}">${esc(m)}</option>`).join('');
|
||||
if (list.includes(keep)) modelSel.value = keep;
|
||||
sanitizeModelSelect();
|
||||
@@ -2601,15 +2602,23 @@ function renderDetailCoverage(detail) {
|
||||
// Auth & Keys modal
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
function openAuthModal() {
|
||||
function selectAuthTab(name) {
|
||||
$$('.modal-tab').forEach((t) => t.classList.toggle('active', t.dataset.mtab === name));
|
||||
$$('.modal-panel').forEach((p) => show(p, p.dataset.mpanel === name));
|
||||
}
|
||||
|
||||
// The tab state survives between opens, so reset it explicitly: opening from
|
||||
// "Authentication" must show Target login, not whatever tab was used last.
|
||||
function openAuthModal(tab = 'target') {
|
||||
show($('#authModal'), true);
|
||||
selectAuthTab(tab);
|
||||
renderRoleList();
|
||||
$('#credsPath').value = state.credsPath;
|
||||
$('#collectionPath').value = state.collectionPath;
|
||||
refreshKeyStatus();
|
||||
}
|
||||
|
||||
['#btnOpenAuth2', '#btnOpenAuth3'].forEach((sel) => $(sel)?.addEventListener('click', openAuthModal));
|
||||
['#btnOpenAuth2', '#btnOpenAuth3'].forEach((sel) => $(sel)?.addEventListener('click', () => openAuthModal('target')));
|
||||
$('#btnCloseAuth').addEventListener('click', () => show($('#authModal'), false));
|
||||
$('#authModal').addEventListener('click', (e) => { if (e.target.id === 'authModal') show($('#authModal'), false); });
|
||||
|
||||
@@ -7227,10 +7236,7 @@ function updateScopeAuthSummary() {
|
||||
: state.auth.header ? `Auth header set${roles ? ` · ${roles} role(s)` : ''}`
|
||||
: roles ? `${roles} role(s)` : 'Not set — agents test as an anonymous user.';
|
||||
}
|
||||
$('[data-open-authz]')?.addEventListener('click', () => {
|
||||
openAuthModal();
|
||||
$('.modal-tab[data-mtab="authz"]')?.click();
|
||||
});
|
||||
$('[data-open-authz]')?.addEventListener('click', () => openAuthModal('authz'));
|
||||
$('#btnCloseAuth')?.addEventListener('click', updateScopeAuthSummary);
|
||||
|
||||
// ---- new pentest entry points ----------------------------------------------
|
||||
@@ -7629,6 +7635,7 @@ loadSettings = async function loadSettingsV5() {
|
||||
const provSel = $('#settingProvider');
|
||||
const modelSel = $('#settingModel');
|
||||
const parts = curDefault.split(':');
|
||||
const savedModel = parts.slice(1).join(':');
|
||||
const setModel = (key, prefer) => {
|
||||
if (!modelSel) return;
|
||||
const p = providers.find((x) => x.key === key);
|
||||
@@ -7636,20 +7643,23 @@ loadSettings = async function loadSettingsV5() {
|
||||
modelSel.innerHTML = list.map((m) => `<option value="${esc(m)}">${esc(m)}</option>`).join('');
|
||||
if (prefer && list.includes(prefer)) modelSel.value = prefer;
|
||||
};
|
||||
const loadCatalog = async (key) => {
|
||||
const loadCatalog = async (key, prefer) => {
|
||||
if (!key || !modelSel) return;
|
||||
try {
|
||||
const r = await api(`/api/providers/${encodeURIComponent(key)}/models`);
|
||||
const list = r.models || [];
|
||||
if (!list.length || $('#settingProvider')?.value !== key) return;
|
||||
const keep = modelSel.value;
|
||||
// The saved model may only exist in the live catalog, not the seed
|
||||
// list; apply it after the catalog replaces the options or the
|
||||
// Settings page would show (and then save) the first model.
|
||||
const keep = (prefer && list.includes(prefer)) ? prefer : modelSel.value;
|
||||
modelSel.innerHTML = list.map((m) => `<option value="${esc(m)}">${esc(m)}</option>`).join('');
|
||||
if (list.includes(keep)) modelSel.value = keep;
|
||||
} catch { /* keep the seed list */ }
|
||||
};
|
||||
if (provSel && parts.length >= 2) provSel.value = parts[0];
|
||||
setModel(provSel?.value || '', parts.slice(1).join(':'));
|
||||
loadCatalog(provSel?.value);
|
||||
setModel(provSel?.value || '', savedModel);
|
||||
loadCatalog(provSel?.value, savedModel);
|
||||
provSel?.addEventListener('change', () => {
|
||||
const key = provSel.value;
|
||||
setModel(key, providers.find((x) => x.key === key)?.models?.[0]);
|
||||
@@ -7799,7 +7809,7 @@ function pickProvider(provider, model) {
|
||||
const sel = $('#fieldProvider');
|
||||
if (!sel || !provider || ![...sel.options].some((o) => o.value === provider)) return;
|
||||
sel.value = provider;
|
||||
onProviderChange();
|
||||
onProviderChange(model);
|
||||
const ms = $('#fieldModelSelect');
|
||||
if (model && ms && [...ms.options].some((o) => o.value === model)) ms.value = model;
|
||||
syncAiSummary();
|
||||
@@ -9495,7 +9505,7 @@ function applyModeFields() {
|
||||
$('.card-title', authCard).textContent = m.auth === 'infra' ? 'Domain or host credentials' : 'Authentication';
|
||||
if (m.auth === 'infra') $('#scopeAuthSummary').textContent = state.credsPath ? `Using ${state.credsPath}` : 'None — add user/password, NTLM hash or SSH key in a creds file.';
|
||||
else if (typeof updateScopeAuthSummary === 'function') updateScopeAuthSummary();
|
||||
authBtn.onclick = m.auth === 'infra' ? (e) => { e.stopImmediatePropagation(); openAuthModal(); $('.modal-tab[data-mtab="creds"]')?.click(); } : null;
|
||||
authBtn.onclick = m.auth === 'infra' ? (e) => { e.stopImmediatePropagation(); openAuthModal('creds'); } : null;
|
||||
}
|
||||
// Launch: only the knobs that mean something for this kind of test.
|
||||
const web = ['run', 'greybox', 'aitest'].includes(state.mode);
|
||||
|
||||
Reference in new issue
Block a user