Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
aws
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
aws
Commits
5da0866c
Commit
5da0866c
authored
Nov 07, 2024
by
Ahmad
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
inikt
parent
2e1b7867
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
14 deletions
+45
-14
fff.js
fff.js
+45
-13
package.json
package.json
+0
-1
No files found.
fff.js
View file @
5da0866c
import
clipboardy
from
'
clipboardy
'
;
// Import required packages
const
{
exec
}
=
require
(
"
child_process
"
);
const
otplib
=
require
(
"
otplib
"
);
// Store the last generated token and clipboard content
let
lastToken
=
""
;
let
previousSecret
=
""
;
// Stores the previous clipboard content to detect changes
// Function to read the clipboard content on Windows
let
previousContent
=
""
;
function
readClipboard
(
callback
)
{
exec
(
"
powershell Get-Clipboard
"
,
(
error
,
stdout
)
=>
{
if
(
error
)
{
console
.
error
(
"
Error reading clipboard:
"
,
error
);
return
;
}
// Function to check the clipboard content
// Pass the clipboard content to the callback function
const
checkClipboard
=
()
=>
{
callback
(
stdout
.
trim
());
const
currentContent
=
clipboardy
.
readSync
();
});
}
// If the content has changed, display it
// Function to generate and display the TOTP code if the secret changes
if
(
currentContent
!==
previousContent
)
{
function
checkForNewCode
(
secret
)
{
console
.
log
(
"
Clipboard Content:
"
,
currentContent
);
if
(
secret
!==
previousSecret
)
{
previousContent
=
currentContent
;
console
.
log
(
`Detected new secret key from clipboard:
${
secret
}
`
);
previousSecret
=
secret
;
}
}
};
// Check the clipboard every second
// Generate TOTP code using the current secret
setInterval
(
checkClipboard
,
1000
);
const
currentToken
=
otplib
.
authenticator
.
generate
(
secret
);
// If the current token is different from the last token, log it
if
(
currentToken
!==
lastToken
)
{
console
.
log
(
`New 2FA code:
${
currentToken
}
`
);
lastToken
=
currentToken
;
}
}
// Run the clipboard read and TOTP generation every second, only on Windows
if
(
process
.
platform
===
"
win32
"
)
{
setInterval
(()
=>
{
// Read the secret from clipboard and generate TOTP code
readClipboard
((
secret
)
=>
{
if
(
secret
)
{
checkForNewCode
(
secret
);
}
});
},
1000
);
}
else
{
console
.
log
(
"
This script only runs on Windows.
"
);
}
package.json
View file @
5da0866c
{
{
"name"
:
"aws"
,
"name"
:
"aws"
,
"version"
:
"1.0.0"
,
"version"
:
"1.0.0"
,
"type"
:
"module"
,
"description"
:
""
,
"description"
:
""
,
"main"
:
"index.js"
,
"main"
:
"index.js"
,
"scripts"
:
{
"scripts"
:
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment