From d3f1500bfaaf0c9ef4ddcd911757bf01b4e36344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= Date: Mon, 28 May 2018 10:32:12 +0100 Subject: can set iv --- geheim.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/geheim.rb b/geheim.rb index 40eecbd..ddb5ac5 100644 --- a/geheim.rb +++ b/geheim.rb @@ -70,8 +70,12 @@ module Encryption super() if @@key.nil? @@key = File.read($key_file) - print "IV: " - input = $stdin.gets.chomp + if ENV['IV'] + input = ENV['IV'] + else + print "IV: " + input = $stdin.gets.chomp + end iv = input * 2 + "Hello world" + input * 2 @@iv = iv[0..15] end -- cgit v1.2.3 From 3320577f12f5cbd473cd5dc6079c417a76344301 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= Date: Mon, 28 May 2018 11:09:39 +0100 Subject: /usr/local/bin/fortune Thank goodness modern convenience is a thing of the remote future. -- Pogo, by Walt Kelly --- geheim.rb | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/geheim.rb b/geheim.rb index ddb5ac5..9460c56 100644 --- a/geheim.rb +++ b/geheim.rb @@ -21,7 +21,6 @@ module Git dirname, basename = File.dirname(file), File.basename(file) Dir.chdir(dirname) puts %x{git add "#{basename}"} - #puts %x{git commit -m "Add #{file}"} if commit Dir.chdir(@wd) end @@ -29,7 +28,6 @@ module Git dirname, basename = File.dirname(file), File.basename(file) Dir.chdir(dirname) puts %x{git rm "#{basename}"} - #puts %x{git commit -m "Remove #{file}"} if commit Dir.chdir(@wd) end @@ -241,7 +239,9 @@ class Geheim end end - def ls(search_term: nil, show: false, export: false) + def ls(search_term: nil, show: false, export: false, open: false) + export = true if open + indexes = Array.new walk_indexes(search_term: search_term) do |index| indexes << index @@ -251,7 +251,9 @@ class Geheim if show and !index.is_binary? print index.get_data elsif export - index.get_data.export(destination_file: File.basename(index.description)) + destination_file = File.basename(index.description) + index.get_data.export(destination_file: destination_file) + shred_file(file: open_exported(file: destination_file), delay: 3) if open end end end @@ -307,6 +309,40 @@ class Geheim end end + def shred_all_exported + puts "Shredding all exported files" + Dir.glob("#{$export_dir}/*").each do |file| + shred_file(file: file) + end + end + + private def shred_file(file:, delay: 0) + %x{which shred} + sleep(delay) + if $?.success? + run_command("shred -vu #{file}") + else + run_command("rm -Pfv #{file}") + end + end + + private def open_exported(file:) + file_path = "#{$export_dir}/#{file}" + case ENV['UNAME'] + when 'Darwin' + run_command("open #{file_path}") + when 'Microsoft' + run_command("winopen #{file_path}") + else + run_command("termux-open #{file_path}") + end + file_path + end + + private def run_command(cmd) + puts "#{cmd}: #{%x{#{cmd}}}" + end + private def walk_indexes(search_term:) Dir.glob("#{$data_dir}/**/*.index").each do |index_file| index = Index.new(index_file: index_file.sub($data_dir, "")) @@ -339,10 +375,11 @@ class CLI SEARCHTERM show SEARCHTERM add DESCRIPTION - import FILE + import|export|open FILE import_r DIRECTORY rm SEARCHTERM sync|status|commit|reset + shred help shell END @@ -359,6 +396,8 @@ class CLI geheim.ls(search_term: argv[1], show: true) when 'export' geheim.ls(search_term: argv[1], export: true) + when 'open' + geheim.ls(search_term: argv[1], open: true) when 'add' geheim.add(description: argv[1]) when 'import' @@ -383,6 +422,8 @@ class CLI git_reset when 'sync' git_sync + when 'shred' + geheim.shred_all_exported else geheim.ls(search_term: action) end -- cgit v1.2.3 From 03a3ec4f28bf494902d3046909474c7201542dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paul=20B=C3=BCtow?= Date: Mon, 28 May 2018 13:28:04 +0100 Subject: /usr/local/bin/fortune Suaviter in modo, fortiter in re. Se non e vero, e ben trovato. --- geheim.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/geheim.rb b/geheim.rb index 9460c56..aa8f6f2 100644 --- a/geheim.rb +++ b/geheim.rb @@ -68,10 +68,10 @@ module Encryption super() if @@key.nil? @@key = File.read($key_file) - if ENV['IV'] - input = ENV['IV'] + if ENV['PIN'] + input = ENV['PIN'] else - print "IV: " + print "PIN: " input = $stdin.gets.chomp end iv = input * 2 + "Hello world" + input * 2 -- cgit v1.2.3