summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-04-13 21:51:39 +0530
committerAndinus <andinus@nand.sh>2021-04-13 21:51:39 +0530
commita1a1890a6e1b20e654f8a18444562b81e30b8a53 (patch)
tree84e9a7442dee2db7c8550f57f9f610f1ffdd2b4c /lib
parent863b5301e2d2c75683086a608ebdf8f497133b94 (diff)
downloadorion-a1a1890a6e1b20e654f8a18444562b81e30b8a53.tar.gz
Implement basic functionality
Diffstat (limited to 'lib')
-rw-r--r--lib/Orion/CLI.rakumod40
1 files changed, 38 insertions, 2 deletions
diff --git a/lib/Orion/CLI.rakumod b/lib/Orion/CLI.rakumod
index be7085a..bce24a7 100644
--- a/lib/Orion/CLI.rakumod
+++ b/lib/Orion/CLI.rakumod
@@ -1,7 +1,43 @@
-proto MAIN(|) is export { unless so @*ARGS { say $*USAGE; exit }; {*} }
+use LWP::Simple;
+use Digest::SHA;
+
+#proto MAIN(|) is export { unless so @*ARGS { say $*USAGE; exit }; {*} }
 
 multi sub MAIN(
-) { }
+    Bool :$verbose, #=increase verbosity
+) is export {
+    my Str $api = "https://api.pwnedpasswords.com";
+
+    # Gather all `.gpg' files from the store.
+    my @stack = "$*HOME/.password-store".IO;
+    my @files = gather while @stack {
+        with @stack.pop {
+            when :d { @stack.append: .dir }
+            .take when .extension.lc eq 'gpg'
+        }
+    }
+
+    for @files -> $file {
+        my $proc = run <gpg2>, '--decrypt', '--quiet', $file, :out;
+        my Str $hash = uc buf_to_hex sha1 $proc.out.slurp(:close).lines.head;
+
+        for LWP::Simple.get(
+            "$api/range/{ $hash.substr(0, 5) }",
+            {
+                Add-Padding => "true",
+                User-Agent => "Andinus / Orion - https://andinus.nand.sh/orion",
+            }
+        ).lines.map(*.split(":")) -> ($entry, $freq) {
+            next if $freq == 0;
+            if $hash.substr(5, *) eq $entry.split(":").head {
+                say $file.Str.split('.password-store/').tail.split('.gpg').first, " ",
+                "has been seen $freq times before.";
+            };
+        }
+    }
+}
+
+sub buf_to_hex { [~] $^buf.list».fmt: "%02x" }
 
 multi sub MAIN(
     Bool :$version #= print version