pwman-tools

Check-in [11718ac61a]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Correctly identify Secure Notes, correctly send optional args

- I had SECURE-NOTE whereas in my pwman it's SECURE-NOTES. Dur!
- For creating items with op need to use args like: `--title=Title` not
`--title Title`. Will have to see if things need quoting as well.
- Remove some print statements

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 11718ac61a1c7b1d373dc4f0d3d31f450255b66a6b28f066ec290a42e3562804
User & Date: atomicules 2019-06-25 12:07:56
Context
2019-06-25
12:30
Only send --url if it's a login item

Not applicable for Secure Notes and op won't allow it. Using append and
wrapping in a list because cons inserts at the front and this is no good for
what we need. check-in: 2c99721959 user: atomicules tags: master, trunk

12:07
Correctly identify Secure Notes, correctly send optional args

- I had SECURE-NOTE whereas in my pwman it's SECURE-NOTES. Dur!
- For creating items with op need to use args like: `--title=Title` not
`--title Title`. Will have to see if things need quoting as well.
- Remove some print statements check-in: 11718ac61a user: atomicules tags: master, trunk

11:12
Initial commit of pwman2op

It "works", but doesn't yet. Main issues are:

- Seems to send everything as a Login item... but maybe that's correct based on
my test data, need to check
- Not setting titles
- Not setting tags

Update README to reflect that this repo now includes this file as well. check-in: 81d3818ee0 user: atomicules tags: master, trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pwman2op.lisp.

23
24
25
26
27
28
29


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
..
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
...
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
	(progn
		; Case would be better if I can figure that out
		; Need to fill in correct template
		(print "op-category:")
		(print op-category)
		(print "pwman-category")
		(print pwman-category)


		(defparameter template
			(if (string= op-category "Login")
				(template-login username passwd launch)
				; Errr... I guess just assume it's... need to do this and not multiple ifs in progn as otherwise template picks up NIL from progmn
				; Need to combine fields for Secure notes
				(template-secure-note (concatenate 'string "host: " host "; user: " username "; password: " passwd "; launch: " launch))))
		(print "template:")
		(print template)
		; Encode first and get return
		; Probably many better ways to do this...
		; Myabe base64 encode directly here... subtle differences though it seems with op
		; Need to single quote encode the json
		(defparameter extproc (sb-ext:run-program "sh" (list "-c" (concatenate 'string "echo '" template "' | op encode")) :search :environment :output :stream))
		(defparameter encoded-item (read-line (sb-ext:process-output extproc)))
		(print encoded-item)
		; Create item
		; Just going to send blanks, etc if that's what some fields are. It doesn't seem to matter.
		; ALMOST working...
		; Need to pick up correct env... I.e. thinks not logged in...
		; Maybe pass session variable to this? Maybe no need...?
		(defparameter cproc (sb-ext:run-program "op" (list  "create" "item" op-category encoded-item "--title" name "--url" host "--tags" pwman-category) :search :environment :output :stream))
		(defparameter output (read-line (sb-ext:process-output cproc)))
		(print output)))


; Mappings are as follows:
; `op create item <category> <encodeditem> [--title=<title>] [--url=<url>] [--vault=<vault>] [--tags=<tags>]`
;
................................................................................
;(dom:do-node-list (category *categories*) (print (dom:get-attribute category "name")))

(dom:do-node-list (category *categories*)
	(progn
		(defparameter category-name (dom:get-attribute category "name"))
		(defparameter pwlists (dom:child-nodes category))
		; Kept for ref - prints category
		(print category-name)
		(dom:do-node-list (pwlist pwlists)
			(progn
				; Rather than loop through at this point, call things explicitly so can then build the op command
				(defparameter pwitems (dom:child-nodes pwlist))
				; Kept for ref - prints Name
				(print (dom:tag-name (dom:item pwitems 0)))
				(print (dom:data (dom:item (dom:child-nodes (dom:item pwitems 0)) 0)))
				; Need to check for NIL and only then set paremter. E.g:
				(defparameter name
					(if (dom:item (dom:child-nodes (dom:item pwitems 0)) 0)
						(dom:data (dom:item (dom:child-nodes (dom:item pwitems 0)) 0))
						"")))
				(defparameter host
					(if (dom:item (dom:child-nodes (dom:item pwitems 1)) 0)
................................................................................
					(if (dom:item (dom:child-nodes (dom:item pwitems 3)) 0)
						(dom:data (dom:item (dom:child-nodes (dom:item pwitems 3)) 0))
						""))
				(defparameter launch
					(if (dom:item (dom:child-nodes (dom:item pwitems 4)) 0)
						(dom:data (dom:item (dom:child-nodes (dom:item pwitems 4)) 0))
						""))
				(if (string= category-name "SECURE-NOTE")
					(send-to-op "Secure Note" category-name name host username passwd launch)
					(progn
						(if (string/= category-name "INACTIVE")
							(send-to-op "Login" category-name name host username passwd launch))))))))

; Only right at end do we want to delete file
;	(if (= 0 (sb-ext:process-exit-code proc))
;		;If that was successful, then delete the un-encrypted files
;		(progn
;			(delete-file infile)
;			(delete-file "pwman.txt"))
;		;If not restore backup and leave plain text files (otherwise will fail next time on above rename)
;		(progn
;			(rename-file (concatenate 'string (sb-unix::posix-getenv "HOME") "/.pwman.db.bak") (concatenate 'string (sb-unix::posix-getenv "HOME") "/.pwman.db"))
;			(print "Couldn't encrypt file, plain text files have not been deleted"))))







>
>






|
|






|





|







 







|





|
|







 







|



|











23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
	(progn
		; Case would be better if I can figure that out
		; Need to fill in correct template
		(print "op-category:")
		(print op-category)
		(print "pwman-category")
		(print pwman-category)
		(print "name")
		(print name)
		(defparameter template
			(if (string= op-category "Login")
				(template-login username passwd launch)
				; Errr... I guess just assume it's... need to do this and not multiple ifs in progn as otherwise template picks up NIL from progmn
				; Need to combine fields for Secure notes
				(template-secure-note (concatenate 'string "host: " host "; user: " username "; password: " passwd "; launch: " launch))))
		;(print "template:")
		;(print template)
		; Encode first and get return
		; Probably many better ways to do this...
		; Myabe base64 encode directly here... subtle differences though it seems with op
		; Need to single quote encode the json
		(defparameter extproc (sb-ext:run-program "sh" (list "-c" (concatenate 'string "echo '" template "' | op encode")) :search :environment :output :stream))
		(defparameter encoded-item (read-line (sb-ext:process-output extproc)))
		;(print encoded-item)
		; Create item
		; Just going to send blanks, etc if that's what some fields are. It doesn't seem to matter.
		; ALMOST working...
		; Need to pick up correct env... I.e. thinks not logged in...
		; Maybe pass session variable to this? Maybe no need...?
		(defparameter cproc (sb-ext:run-program "op" (list  "create" "item" op-category encoded-item (concatenate 'string "--title=" name) (concatenate 'string "--url=" host) (concatenate 'string "--tags=" pwman-category)) :search :environment :output :stream))
		(defparameter output (read-line (sb-ext:process-output cproc)))
		(print output)))


; Mappings are as follows:
; `op create item <category> <encodeditem> [--title=<title>] [--url=<url>] [--vault=<vault>] [--tags=<tags>]`
;
................................................................................
;(dom:do-node-list (category *categories*) (print (dom:get-attribute category "name")))

(dom:do-node-list (category *categories*)
	(progn
		(defparameter category-name (dom:get-attribute category "name"))
		(defparameter pwlists (dom:child-nodes category))
		; Kept for ref - prints category
		;(print category-name)
		(dom:do-node-list (pwlist pwlists)
			(progn
				; Rather than loop through at this point, call things explicitly so can then build the op command
				(defparameter pwitems (dom:child-nodes pwlist))
				; Kept for ref - prints Name
				;(print (dom:tag-name (dom:item pwitems 0)))
				;(print (dom:data (dom:item (dom:child-nodes (dom:item pwitems 0)) 0)))
				; Need to check for NIL and only then set paremter. E.g:
				(defparameter name
					(if (dom:item (dom:child-nodes (dom:item pwitems 0)) 0)
						(dom:data (dom:item (dom:child-nodes (dom:item pwitems 0)) 0))
						"")))
				(defparameter host
					(if (dom:item (dom:child-nodes (dom:item pwitems 1)) 0)
................................................................................
					(if (dom:item (dom:child-nodes (dom:item pwitems 3)) 0)
						(dom:data (dom:item (dom:child-nodes (dom:item pwitems 3)) 0))
						""))
				(defparameter launch
					(if (dom:item (dom:child-nodes (dom:item pwitems 4)) 0)
						(dom:data (dom:item (dom:child-nodes (dom:item pwitems 4)) 0))
						""))
				(if (string= category-name "SECURE-NOTES")
					(send-to-op "Secure Note" category-name name host username passwd launch)
					(progn
						(if (string/= category-name "INACTIVE")
							(send-to-op "Login" category-name name host username passwd launch)))))))

; Only right at end do we want to delete file
;	(if (= 0 (sb-ext:process-exit-code proc))
;		;If that was successful, then delete the un-encrypted files
;		(progn
;			(delete-file infile)
;			(delete-file "pwman.txt"))
;		;If not restore backup and leave plain text files (otherwise will fail next time on above rename)
;		(progn
;			(rename-file (concatenate 'string (sb-unix::posix-getenv "HOME") "/.pwman.db.bak") (concatenate 'string (sb-unix::posix-getenv "HOME") "/.pwman.db"))
;			(print "Couldn't encrypt file, plain text files have not been deleted"))))