pwman-tools

Check-in [2165591f67]
Login

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

Overview
Comment:Much more sensible escaping of quotes

I'd tried unicode before, but couldn't get it to work, I think because I was
missing an extra backslash that is required for some reason.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: 2165591f678d32e75ee8c7306342b3a2a92fa0a4b67123f8a2c8748decae6211
User & Date: atomicules 2019-08-09 15:48:23
Context
2019-08-09
17:13
Remove some of the unnecessary prints and comments check-in: 1baafd9e95 user: atomicules tags: master, trunk
15:48
Much more sensible escaping of quotes

I'd tried unicode before, but couldn't get it to work, I think because I was
missing an extra backslash that is required for some reason. check-in: 2165591f67 user: atomicules tags: master, trunk

13:36
Handle single and double quotes. Update README with assumptions

Quite a hacky mess to handle single and double quotes but seems to work. This was the test file used:

```
<?xml version="1.0"?>
<PWMan_PasswordList version="3"><PwList name="Main"><PwList name="SECURE-NOTES"><PwItem><name>test 1</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff '</launch></PwItem><PwItem><name>test 2</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff "</launch></PwItem><PwItem><name>test 3</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff ;</launch></PwItem></PwList></PwList></PWMan_PasswordList>
``` check-in: e97152f612 user: atomicules tags: master, trunk

Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to pwman2op.lisp.

8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
34
35
36
37
38
39
40
41
42
43
44

45
46
47
48
49
50
51
; Had parsing errors with xmls so use cxml instead
(ql:quickload "cxml")
(ql:quickload "cl-ppcre")

; "Escape" certain characters. Will replace back on cli call
(defun escape-quotes
	(text)
	(cl-ppcre:regex-replace-all "\"" (cl-ppcre:regex-replace-all "'" text "SINGLEQUOTE" :preserve-case t) "DOUBLEQUOTE" :preserve-case t))

; Just assume two template types
; Obtained from `op get template <category>`
(defun template-secure-note
	(content)
	(concatenate 'string "{\"notesPlain\":\"" (escape-quotes content) "\",\"sections\":[]}"))

................................................................................
				; 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))))
		; Command line notes, because multiple levels of escaping are confusing
		; echo | sed 's#DOUBLEQUOTE#\\"#'
		; echo | sed s#SINGLEQUOTE#\\\'#
		; should work
		(defparameter extproc (sb-ext:run-program "sh" (list "-c" (concatenate 'string "echo '" template "' | sed 's#DOUBLEQUOTE#\\\\\"#g' | sed s#SINGLEQUOTE#\\\'#g | op encode")) :search :environment :output :stream))
		(print template)
		(print (concatenate 'string "echo '" template "' | sed 's#DOUBLEQUOTE#\\\"#g' | sed s#SINGLEQUOTE#\\\'#g | op encode"))
		(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.
		; Need to only send url if it's a Login item
		(defparameter defaultargs (list  "create" "item" op-category encoded-item (concatenate 'string "--title=" name) (concatenate 'string "--tags=" pwman-category)))
		(defparameter args
			(if (string= op-category "Login")







|







 







|
<
<

>







8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
..
34
35
36
37
38
39
40
41


42
43
44
45
46
47
48
49
50
; Had parsing errors with xmls so use cxml instead
(ql:quickload "cxml")
(ql:quickload "cl-ppcre")

; "Escape" certain characters. Will replace back on cli call
(defun escape-quotes
	(text)
	(cl-ppcre:regex-replace-all "\"" (cl-ppcre:regex-replace-all "'" text "\\u0027" :preserve-case t) "\\u0022" :preserve-case t))

; Just assume two template types
; Obtained from `op get template <category>`
(defun template-secure-note
	(content)
	(concatenate 'string "{\"notesPlain\":\"" (escape-quotes content) "\",\"sections\":[]}"))

................................................................................
				; 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))))
		; Command line notes, because multiple levels of escaping are confusing
		; echo | sed 's#DOUBLEQUOTE#\\"#'
		; echo | sed s#SINGLEQUOTE#\\\'#
		; should work
		(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 template)
		(print encoded-item)
		; Create item
		; Just going to send blanks, etc if that's what some fields are. It doesn't seem to matter.
		; Need to only send url if it's a Login item
		(defparameter defaultargs (list  "create" "item" op-category encoded-item (concatenate 'string "--title=" name) (concatenate 'string "--tags=" pwman-category)))
		(defparameter args
			(if (string= op-category "Login")