totp support
This commit is contained in:
37
rbw.el
37
rbw.el
@@ -1,28 +1,28 @@
|
|||||||
|
(setq debug-on-error t)
|
||||||
|
|
||||||
(defun rbw-get-password ()
|
(defun rbw-get-password ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (rbw/unlocked) (kill-new (rbw/list-all)) (message "locked vault")))
|
(if (rbw/unlocked) (kill-new (rbw/list-all 'rbw/get-pass)) (message "locked vault")))
|
||||||
|
|
||||||
|
(defun rbw-get-totp ()
|
||||||
|
(interactive)
|
||||||
|
(if (rbw/unlocked) (kill-new (rbw/list-all 'rbw/get-totp)) (message "locked vault")))
|
||||||
|
|
||||||
(defun rbw-add ()
|
(defun rbw-add ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(let* ((name (read-string "password name: "))
|
(let* ((name (read-string "password name: "))
|
||||||
(username (read-string "username: "))
|
(username (read-string "username: "))
|
||||||
(entry (concat name " " username))
|
(entry (concat name " " username))
|
||||||
(exists? (car (rbw/get entry))))
|
(exists? (car (rbw/gets-pass entry))))
|
||||||
(message exists?)
|
(message exists?)
|
||||||
(if exists? (message "entry already exists")
|
(if exists? (message "entry already exists")
|
||||||
(let* ((length (read-number "length: ")))
|
(let* ((length (read-number "length: ")))
|
||||||
(rbw/generate length name username)))))
|
(rbw/generate length name username)))))
|
||||||
|
|
||||||
;; TODO
|
|
||||||
;; (defun rbw-remove ()
|
|
||||||
;; (interactive)
|
|
||||||
|
|
||||||
;; )
|
|
||||||
|
|
||||||
(defun rbw-get-user ()
|
(defun rbw-get-user ()
|
||||||
(interactive)
|
(interactive)
|
||||||
(if (rbw/unlocked)
|
(if (rbw/unlocked)
|
||||||
(let* ((output (rbw/list-all "--field user"))
|
(let* ((output (rbw/list-all 'rbw/get-pass "--field user"))
|
||||||
(output (string-trim-left output "Username: ")))
|
(output (string-trim-left output "Username: ")))
|
||||||
(kill-new output))
|
(kill-new output))
|
||||||
(message "locked vault")))
|
(message "locked vault")))
|
||||||
@@ -37,16 +37,16 @@
|
|||||||
(let* ((default-directory "/home/luis/"))
|
(let* ((default-directory "/home/luis/"))
|
||||||
(shell-command "rbw sync")))
|
(shell-command "rbw sync")))
|
||||||
|
|
||||||
(defun rbw/list-all (&optional options entries selected)
|
(defun rbw/list-all (getter &optional options entries selected)
|
||||||
(let* ((entries (if entries entries (rbw/list)))
|
(let* ((entries (if entries entries (rbw/list)))
|
||||||
(entry (completing-read "bitwarden entries: " entries))
|
(entry (completing-read "bitwarden entries: " entries))
|
||||||
(selected (concat selected " " entry))
|
(selected (concat selected " " entry))
|
||||||
(selected (string-trim selected))
|
(selected (string-trim selected))
|
||||||
(result (rbw/get selected options))
|
(result (funcall getter selected options)) ; TODO fix when getter fails
|
||||||
(output (car (last result)))
|
(output (car (last result)))
|
||||||
(result (car result)))
|
(result (car result)))
|
||||||
(if result output
|
(if result output
|
||||||
(rbw/list-all options (rbw/extract-multiple output selected) selected))))
|
(rbw/list-all getter options (rbw/extract-multiple output selected) selected))))
|
||||||
|
|
||||||
(defun rbw/generate (length &optional name user)
|
(defun rbw/generate (length &optional name user)
|
||||||
(let* ((default-directory "/home/luis/")
|
(let* ((default-directory "/home/luis/")
|
||||||
@@ -65,7 +65,7 @@
|
|||||||
(entries (split-string output "\n")))
|
(entries (split-string output "\n")))
|
||||||
entries))
|
entries))
|
||||||
|
|
||||||
(defun rbw/get (entry &optional options)
|
(defun rbw/get-pass (entry &optional options)
|
||||||
(let* ((default-directory "/home/luis/")
|
(let* ((default-directory "/home/luis/")
|
||||||
(command (concat "rbw get " options " " entry " ; echo $?"))
|
(command (concat "rbw get " options " " entry " ; echo $?"))
|
||||||
(output (shell-command-to-string command))
|
(output (shell-command-to-string command))
|
||||||
@@ -76,6 +76,17 @@
|
|||||||
(output (car output)))
|
(output (car output)))
|
||||||
(list result output)))
|
(list result output)))
|
||||||
|
|
||||||
|
(defun rbw/get-totp (entry &optional options)
|
||||||
|
(let* ((default-directory "/home/luis/")
|
||||||
|
(command (concat "rbw code " options " " entry " ; echo $?"))
|
||||||
|
(output (shell-command-to-string command))
|
||||||
|
(output (string-trim output))
|
||||||
|
(output (split-string output "\n"))
|
||||||
|
(result (car (last output)))
|
||||||
|
(result (string-equal result "0"))
|
||||||
|
(output (car output)))
|
||||||
|
(list result output)))
|
||||||
|
|
||||||
(defun rbw/extract-multiple (output selected)
|
(defun rbw/extract-multiple (output selected)
|
||||||
(string-match "\\([^:]*\\)$" output)
|
(string-match "\\([^:]*\\)$" output)
|
||||||
(let* ((trimmed (string-trim (match-string 1 output)))
|
(let* ((trimmed (string-trim (match-string 1 output)))
|
||||||
|
|||||||
Reference in New Issue
Block a user