diff options
author | 2024-02-18 01:49:42 +0100 | |
---|---|---|
committer | 2024-02-18 06:19:42 +0530 | |
commit | 315728415b2269981a04ee51af7ef18412d7bf70 (patch) | |
tree | 1ee3e41e7022fa376b99bff5413eb6119481b839 /src/stores | |
parent | 6.7.1-nightly.20 [skip ci] (diff) | |
download | ferdium-app-315728415b2269981a04ee51af7ef18412d7bf70.tar.gz ferdium-app-315728415b2269981a04ee51af7ef18412d7bf70.tar.zst ferdium-app-315728415b2269981a04ee51af7ef18412d7bf70.zip |
feat: Parse 2FA SMS token and copy to clipboard (#1561)
Diffstat (limited to 'src/stores')
-rw-r--r-- | src/stores/ServicesStore.ts | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/stores/ServicesStore.ts b/src/stores/ServicesStore.ts index 175a2ce16..d7804a3fe 100644 --- a/src/stores/ServicesStore.ts +++ b/src/stores/ServicesStore.ts | |||
@@ -1,5 +1,5 @@ | |||
1 | import { join } from 'node:path'; | 1 | import { join } from 'node:path'; |
2 | import { ipcRenderer, shell } from 'electron'; | 2 | import { clipboard, ipcRenderer, shell } from 'electron'; |
3 | import { action, reaction, computed, observable, makeObservable } from 'mobx'; | 3 | import { action, reaction, computed, observable, makeObservable } from 'mobx'; |
4 | import { debounce, remove } from 'lodash'; | 4 | import { debounce, remove } from 'lodash'; |
5 | import ms from 'ms'; | 5 | import ms from 'ms'; |
@@ -834,6 +834,54 @@ export default class ServicesStore extends TypedStore { | |||
834 | break; | 834 | break; |
835 | } | 835 | } |
836 | case 'notification': { | 836 | case 'notification': { |
837 | const { notificationId, options } = args[0]; | ||
838 | |||
839 | const { isTwoFactorAutoCatcherEnabled, twoFactorAutoCatcherMatcher } = | ||
840 | this.stores.settings.all.app; | ||
841 | |||
842 | debug( | ||
843 | 'Settings for catch tokens', | ||
844 | isTwoFactorAutoCatcherEnabled, | ||
845 | twoFactorAutoCatcherMatcher, | ||
846 | ); | ||
847 | |||
848 | if (isTwoFactorAutoCatcherEnabled) { | ||
849 | /* | ||
850 | parse the token digits from sms body, find "token" or "code" in options.body which reflect the sms content | ||
851 | --- | ||
852 | Token: 03624 / SMS-Code = PIN Token | ||
853 | --- | ||
854 | Prüfcode 010313 für Microsoft-Authentifizierung verwenden. | ||
855 | --- | ||
856 | 483133 is your GitHub authentication code. @github.com #483133 | ||
857 | --- | ||
858 | eBay: Ihr Sicherheitscode lautet 080090. \nEr läuft in 15 Minuten ab. Geben Sie den Code nicht an andere weiter. | ||
859 | --- | ||
860 | PayPal: Ihr Sicherheitscode lautet: 989605. Geben Sie diesen Code nicht weiter. | ||
861 | */ | ||
862 | |||
863 | const rawBody = options.body; | ||
864 | const { 0: token } = /\d{5,6}/.exec(options.body) || []; | ||
865 | |||
866 | const wordsToCatch = twoFactorAutoCatcherMatcher | ||
867 | .replaceAll(', ', ',') | ||
868 | .split(','); | ||
869 | |||
870 | debug('wordsToCatch', wordsToCatch); | ||
871 | |||
872 | if ( | ||
873 | token && | ||
874 | wordsToCatch.some(a => | ||
875 | options.body.toLowerCase().includes(a.toLowerCase()), | ||
876 | ) | ||
877 | ) { | ||
878 | // with the extra "+ " it shows its copied to clipboard in the notification | ||
879 | options.body = `+ ${rawBody}`; | ||
880 | clipboard.writeText(token); | ||
881 | debug('Token parsed and copied to clipboard'); | ||
882 | } | ||
883 | } | ||
884 | |||
837 | // Check if we are in scheduled Do-not-Disturb time | 885 | // Check if we are in scheduled Do-not-Disturb time |
838 | const { scheduledDNDEnabled, scheduledDNDStart, scheduledDNDEnd } = | 886 | const { scheduledDNDEnabled, scheduledDNDStart, scheduledDNDEnd } = |
839 | this.stores.settings.all.app; | 887 | this.stores.settings.all.app; |
@@ -845,8 +893,6 @@ export default class ServicesStore extends TypedStore { | |||
845 | return; | 893 | return; |
846 | } | 894 | } |
847 | 895 | ||
848 | const { notificationId, options } = args[0]; | ||
849 | |||
850 | if (service.isMuted || this.stores.settings.all.app.isAppMuted) { | 896 | if (service.isMuted || this.stores.settings.all.app.isAppMuted) { |
851 | Object.assign(options, { | 897 | Object.assign(options, { |
852 | silent: true, | 898 | silent: true, |