Compare commits
2 Commits
becc4f9445
...
3176af094e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3176af094e | ||
|
|
e8a14e7e69 |
@@ -5,5 +5,5 @@
|
|||||||
"@/*": ["src/*"]
|
"@/*": ["src/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["src"]
|
"include": ["src", "src/background.js", "src/content.js"]
|
||||||
}
|
}
|
||||||
3645
package-lock.json
generated
Normal file
3645
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@@ -4,11 +4,13 @@
|
|||||||
"version": "4.0",
|
"version": "4.0",
|
||||||
"description": "Rellena automáticamente el código 2FA en la Universidad de Sevilla.",
|
"description": "Rellena automáticamente el código 2FA en la Universidad de Sevilla.",
|
||||||
"permissions": [
|
"permissions": [
|
||||||
"activeTab",
|
|
||||||
"scripting",
|
|
||||||
"tabs",
|
|
||||||
"storage"
|
"storage"
|
||||||
],
|
],
|
||||||
|
"background": {
|
||||||
|
"service_worker": "scripts/background.js",
|
||||||
|
"type": "module",
|
||||||
|
"scripts": ["scripts/background.js"]
|
||||||
|
},
|
||||||
"action": {
|
"action": {
|
||||||
"default_popup": "index.html"
|
"default_popup": "index.html"
|
||||||
},
|
},
|
||||||
@@ -17,12 +19,8 @@
|
|||||||
},
|
},
|
||||||
"content_scripts": [
|
"content_scripts": [
|
||||||
{
|
{
|
||||||
"matches": [
|
"matches": ["*://sso.us.es/*"],
|
||||||
"https://sso.us.es/*"
|
"js": ["scripts/content.js"],
|
||||||
],
|
|
||||||
"js": [
|
|
||||||
"scripts/content.js"
|
|
||||||
],
|
|
||||||
"run_at": "document_idle"
|
"run_at": "document_idle"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
49
src/App.jsx
49
src/App.jsx
@@ -4,11 +4,24 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
|
|||||||
import { faCircleInfo } from "@fortawesome/free-solid-svg-icons";
|
import { faCircleInfo } from "@fortawesome/free-solid-svg-icons";
|
||||||
import { ThemeToggle } from "./components/ThemeToggle";
|
import { ThemeToggle } from "./components/ThemeToggle";
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
const api = typeof browser !== "undefined" ? browser : chrome;
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const [secret, setSecret] = useState(localStorage.getItem('shasecret') || '');
|
const [secret, setSecret] = useState('');
|
||||||
const [token, setToken] = useState('000000');
|
const [token, setToken] = useState('000000');
|
||||||
const [remaining, setRemaining] = useState(30);
|
const [remaining, setRemaining] = useState(30);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (api?.storage?.local) {
|
||||||
|
api.storage.local.get(['shasecret'], (result) => {
|
||||||
|
if (result.shasecret) {
|
||||||
|
setSecret(result.shasecret);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!secret) return;
|
if (!secret) return;
|
||||||
|
|
||||||
@@ -26,22 +39,17 @@ const App = () => {
|
|||||||
const newToken = totp.generate()
|
const newToken = totp.generate()
|
||||||
setToken(newToken);
|
setToken(newToken);
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
if (api?.tabs?.query) {
|
||||||
const api = typeof browser !== "undefined" ? browser : chrome;
|
|
||||||
|
|
||||||
if (api && api.tabs && api.tabs.query) {
|
|
||||||
api.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
api.tabs.query({ active: true, currentWindow: true }, (tabs) => {
|
||||||
if (tabs[0]?.id && tabs[0].url?.includes("sso.us.es")) {
|
if (tabs[0]?.url?.includes("sso.us.es")) {
|
||||||
api.tabs.sendMessage(tabs[0].id, {
|
api.tabs.sendMessage(tabs[0].id, {
|
||||||
action: "autofill",
|
action: "autofill",
|
||||||
code: newToken
|
code: newToken
|
||||||
}).catch(() => {
|
}).catch(() => {});
|
||||||
console.log("Esperando inyección...");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
console.log("Entorno de desarrollo: Autofill desactivado.");
|
console.debug("DevEnv");
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
@@ -68,22 +76,29 @@ const App = () => {
|
|||||||
const handleSaveSecret = (e) => {
|
const handleSaveSecret = (e) => {
|
||||||
if (e.key === 'Enter') {
|
if (e.key === 'Enter') {
|
||||||
const val = e.target.value.trim();
|
const val = e.target.value.trim();
|
||||||
localStorage.setItem('shasecret', val);
|
if (api?.storage?.local) {
|
||||||
|
api.storage.local.set({ 'shasecret': val }, () => {
|
||||||
setSecret(val);
|
setSecret(val);
|
||||||
|
console.log("Secret stored");
|
||||||
|
});
|
||||||
|
}
|
||||||
e.target.value = '';
|
e.target.value = '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const resetSecret = () => {
|
||||||
|
if (api?.storage?.local) {
|
||||||
|
api.storage.local.remove(['shasecret'], () => {
|
||||||
|
setSecret('');
|
||||||
|
setToken('000000');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const copyToClipboard = () => {
|
const copyToClipboard = () => {
|
||||||
navigator.clipboard.writeText(token);
|
navigator.clipboard.writeText(token);
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetSecret = () => {
|
|
||||||
localStorage.removeItem('shasecret');
|
|
||||||
setSecret('');
|
|
||||||
setToken('000000');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container-app">
|
<div className="container-app">
|
||||||
<div className="top-actions">
|
<div className="top-actions">
|
||||||
|
|||||||
23
src/background.js
Normal file
23
src/background.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import * as OTPAuth from 'otpauth';
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
const api = typeof browser !== "undefined" ? browser : chrome;
|
||||||
|
|
||||||
|
api.runtime.onMessage.addListener((request, _sender, sendResponse) => {
|
||||||
|
if (request.action === "GENERATE_TOKEN") {
|
||||||
|
api.storage.local.get(['shasecret'], (data) => {
|
||||||
|
if (data.shasecret) {
|
||||||
|
const totp = new OTPAuth.TOTP({
|
||||||
|
issuer: 'US',
|
||||||
|
label: '2FA',
|
||||||
|
algorithm: 'SHA1',
|
||||||
|
digits: 6,
|
||||||
|
period: 30,
|
||||||
|
secret: OTPAuth.Secret.fromBase32(data.shasecret.trim().toUpperCase()),
|
||||||
|
});
|
||||||
|
sendResponse({ token: totp.generate() });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
@@ -1,25 +1,66 @@
|
|||||||
|
(async function() {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const api = typeof browser !== "undefined" ? browser : chrome;
|
const api = typeof browser !== "undefined" ? browser : chrome;
|
||||||
|
|
||||||
api.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
const fillAndSubmit = (code) => {
|
||||||
if (request.action === "autofill") {
|
const input = document.getElementById("input2factor");
|
||||||
const input = document.getElementById('input2factor');
|
const button = document.getElementById("notification_2factor_button_ok");
|
||||||
const button = document.getElementById('btn-login');
|
|
||||||
|
const errorMsg = document.querySelector(".ui-state-error");
|
||||||
|
const isErrorVisible = errorMsg && errorMsg.style.display !== "none";
|
||||||
|
|
||||||
|
if (!input || input.value.length > 0 || isErrorVisible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("Autofill");
|
||||||
|
|
||||||
if (input) {
|
|
||||||
input.focus();
|
input.focus();
|
||||||
input.value = request.code;
|
input.value = code;
|
||||||
|
['input', 'change', 'keyup', 'keydown'].forEach(evt => {
|
||||||
input.dispatchEvent(new Event('input', { bubbles: true }));
|
input.dispatchEvent(new Event(evt, { bubbles: true }));
|
||||||
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
||||||
|
|
||||||
if (button) {
|
|
||||||
setTimeout(() => {
|
|
||||||
button.click();
|
|
||||||
}, 150);
|
|
||||||
}
|
|
||||||
sendResponse({ status: "bomba" });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (button) {
|
||||||
|
console.log("Clicking 'Aceptar'");
|
||||||
|
const clickEvent = new MouseEvent('click', {
|
||||||
|
view: window,
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
button.dispatchEvent(clickEvent);
|
||||||
|
}
|
||||||
|
}, 400);
|
||||||
|
};
|
||||||
|
|
||||||
|
const tryAutofill = async () => {
|
||||||
|
const data = await api.storage.local.get(['shasecret']);
|
||||||
|
if (data.shasecret) {
|
||||||
|
api.runtime.sendMessage({ action: "GENERATE_TOKEN" }, response => {
|
||||||
|
if (response?.token) {
|
||||||
|
fillAndSubmit(response.token);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const observer = new MutationObserver(() => {
|
||||||
|
if (document.getElementById("input2factor")) {
|
||||||
|
tryAutofill();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
observer.observe(document.body, {
|
||||||
|
childList: true,
|
||||||
|
subtree: true
|
||||||
|
});
|
||||||
|
|
||||||
|
api.runtime.onMessage.addListener((request) => {
|
||||||
|
if (request.action === "autofill") {
|
||||||
|
fillAndSubmit(request.code);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tryAutofill();
|
||||||
|
})();
|
||||||
@@ -6,28 +6,26 @@ export default defineConfig({
|
|||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
build: {
|
build: {
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: [
|
input: {
|
||||||
resolve(__dirname, 'index.html'),
|
main: resolve(__dirname, 'index.html'),
|
||||||
resolve(__dirname, 'src/content.js')
|
content: resolve(__dirname, 'src/content.js'),
|
||||||
],
|
background: resolve(__dirname, 'src/background.js'),
|
||||||
|
},
|
||||||
output: {
|
output: {
|
||||||
|
format: 'es',
|
||||||
entryFileNames: (chunkInfo) => {
|
entryFileNames: (chunkInfo) => {
|
||||||
if (chunkInfo.name === 'content') {
|
if (chunkInfo.name === 'content' || chunkInfo.name === 'background') {
|
||||||
return 'scripts/content.js';
|
return 'scripts/[name].js';
|
||||||
}
|
}
|
||||||
return 'assets/[name]-[hash].js';
|
return 'assets/[name]-[hash].js';
|
||||||
},
|
},
|
||||||
|
manualChunks: undefined,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
server: {
|
|
||||||
port: 3000,
|
|
||||||
},
|
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'@/': '/src/',
|
'@': resolve(__dirname, './src'),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
publicDir: 'public',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user