Overview
Comment: | add clipserv |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
5e680bdd135eea1f3007b2e0bbb400fb |
User & Date: | lexi on 2019-07-21 06:15:31 |
Other Links: | manifest | tags |
Context
2019-07-21
| ||
06:35 | add clipserv check-in: 6a5d1f9f67 user: lexi tags: trunk | |
06:15 | add clipserv check-in: 5e680bdd13 user: lexi tags: trunk | |
2019-07-20
| ||
23:37 | udpate xpriv to use sysv shmem by default; give iaia an option to generate its own types, and allow selecting between 7-bit and 8-bit encodings for ascii (defaulting to 8-bit); update mkpw to work with new iaia; update ord to add flag controlling byte length (7 or 8) for iaia's ascii mode check-in: 6a14de1811 user: lexi tags: trunk | |
Changes
Added clipserv/ansi.b version [96ef78cae7].
1 +; [ʞ] ansi.b 2 +; ~ lexi hale <lexi@hale.su> 3 +; © AGPLv3 4 +; ? a terminal text formatter for boron 5 +; > do read/text %ansi.b 6 +; @ vim: ft=rebol 7 + 8 +stdin: open 0 9 +stdout: open 1 10 +stderr: open 2 11 + 12 +fmt-code-stack: [] 13 + 14 +in-list: func [i lst] [ either (find lst i) [true] [false] ] 15 + 16 +ansi: context [ 17 + escape: to-string #{1B5B} 18 + fmt: "m" with: ";" 19 + style: context [ 20 + hl: "1" ul: "4" rv: "7" sl: "3" dim: "2" 21 + ] 22 + color: context [ 23 + red: "1" green: "2" 24 + yellow: "3" blue: "4" 25 + purple: "5" cyan: "6" 26 + white: "7" black: "0" 27 + ] 28 + fg: color bg: color 29 + 30 + frame: context [ 31 + kind: none 32 + value: none 33 + ] 34 +] 35 + 36 +fmt-push: func[k v] [ any [ 37 + all [ 38 + f-kind: in ansi k 39 + f-val: in (do f-kind) v 40 + 41 + frame: make ansi/frame [ 42 + kind: f-kind 43 + value: f-val 44 + ] 45 + 46 + append fmt-code-stack frame 47 + ] throw 'bad-argument 48 +]] 49 + 50 +fmt-pop: does [ pop fmt-code-stack ] 51 + 52 +fmt-seq: func[/local] [ 53 + active-styles: [] 54 + active-colors: context [ 55 + fg: none 56 + bg: none 57 + ] 58 + 59 + foreach frame fmt-code-stack [ 60 + either eq? frame/kind 'style [ 61 + ifn in-list frame/value active-styles [ 62 + append active-styles frame/value 63 + ] 64 + ] /* or */ [ 65 + ck: in active-colors (unbind frame/kind) 66 + set ck frame/value 67 + ] 68 + ] 69 + 70 + style-string: rejoin (map i active-styles [join ";" (do i)]) 71 + 72 + key: context [ 73 + plain: context [ fg: "3" bg: "4" ] 74 + bright: context [ fg: "9" bg: "10" ] 75 + ] 76 + foreach i [fg bg] [ 77 + code: do (in key/plain i) 78 + color: do (in active-colors i) 79 + if color [ 80 + style-string: join style-string rejoin 81 + [";" code do color] 82 + ] 83 + ] 84 + 85 + free active-styles 86 + 87 + rejoin [ ansi/escape style-string ansi/fmt ] 88 +] 89 + 90 +fmt: func [lst] [ 91 + depth: 0 92 + evaluated: map term (join lst fmt-seq) [ 93 + case [ 94 + paren? term [ 95 + fmt-push (first term) (second term) 96 + ++ depth fmt-seq 97 + ] 98 + word? term [ do term ] 99 + block? term [ fmt term ] 100 + string? term [ term ] 101 + ] 102 + ] 103 + loop depth [fmt-pop] 104 + rejoin evaluated 105 +]
Added clipserv/clip.b version [589ffdd50a].
1 +#!/usr/bin/env -S boron -sp 2 +; [ʞ] clipserv.b 3 +; ~ lexi hale <lexi@hale.su> 4 +; # boron 5 +; @ vim: ft=rebol 6 +; ? a tool for transmitting clipboard from one 7 +; host to another over the network. WARNING: 8 +; simple nonce authentication is used but the 9 +; clipboard is sent IN THE CLEAR 10 + 11 +do read/text %ansi.b 12 + 13 +verbose: no 14 +readonly: no 15 +port: "42069" 16 +key: #{981A7879} 17 + 18 +proto: context [ 19 + writecb: #{3E} 20 + readcb: #{C5} 21 +] 22 + 23 +debug: func [x] [ 24 + if verbose [ 25 + x: either block? x [rejoin x] [x] 26 + 27 + write stderr fmt [ 28 + [(fg red) "["] [(style hl) "debug"] " " x [(fg red) "]"] "^/" 29 + ] 30 + ] 31 +] 32 + 33 +entropy-sink: open %/dev/urandom 34 +rand-block: func[sz] [ read/part entropy-sink sz ] 35 +key-hash: func[k z /local] [ 36 + cksum: checksum join k z 37 + slice cksum 0,4 38 +] 39 + 40 +debug "parsing arguments" 41 + 42 +usage: does [ 43 + write stderr fmt [[(style hl)"usage:"] 44 + " ./clip.b get <hostname> | send <hostname>" ] 45 +] 46 + 47 +flag: func [f /extern verbose readonly] [ 48 + debug ["found flag " i] 49 + do select [ 50 + "-v" [ verbose: yes ] 51 + "-q" [ verbose: no ] 52 + "-r" [ readonly: yes ] 53 + ] f 54 +] 55 + 56 +set-clipboard: func[c] [ execute/in "xsel -bi" c ] 57 + 58 +get-clipboard: func[/local] [ 59 + clip-out: "" 60 + execute/out "xsel -bo" clip-out 61 + clip-out 62 +] 63 + 64 +start-server: func[/local] [ 65 + debug ["serving clipboard from " hostname none ] 66 + sock: open join "tcp://:" port 67 + forever [ 68 + connection: read wait sock 69 + nonce: rand-block 4 70 + expect-key: (key-hash nonce key) 71 + write connection nonce 72 + debug [ "sent nonce " nonce ";" 73 + "expecting password " expect-key ";"] 74 + 75 + client-message: read wait connection 76 + client-key: slice client-message 0,4 77 + client-command: slice client-message 4,1 78 + client-body: slice client-message 5,-1 79 + 80 + debug [ "received pw " client-key ] 81 + either eq? client-key expect-key [ 82 + debug [ "admitted access" ] 83 + debug [ "got command " client-command ] 84 + case [ 85 + eq? client-command proto/readcb [ 86 + debug {sending clipboard to client} 87 + write connection get-clipboard 88 + ] 89 + eq? client-command proto/writecb [ 90 + new-clipboard: to-string client-body 91 + debug ["got cb " new-clipboard] 92 + set-clipboard new-clipboard 93 + ] 94 + true [ write connection "bad command" ] 95 + ] 96 + ] [ 97 + debug "denied access" 98 + write connection "access denied" 99 + ] 100 + close connection 101 + debug [ "closed connection" ] 102 + ] 103 +] 104 + 105 +send-clip: func[host] [ 106 + debug ["sending clipboard to " host ] 107 + sock: open rejoin ["tcp://" host ":" port] 108 + nonce: read wait sock 109 + debug [ "got nonce " nonce ] 110 + client-key: key-hash nonce key 111 + debug [ "sending password " client-key ] 112 + msg: rejoin [ 113 + client-key 114 + proto/writecb 115 + get-clipboard #{00} 116 + ] 117 + write sock msg 118 +] 119 +get-clip: func[host] [ 120 + debug ["getting clipboard from " host ] 121 + sock: open rejoin ["tcp://" host ":" port] 122 + nonce: read wait sock 123 + debug [ "got nonce " nonce ] 124 + client-key: key-hash nonce key 125 + debug [ "sending password " client-key ] 126 + msg: rejoin [ client-key proto/readcb ] 127 + write sock msg 128 + clipboard: read wait sock 129 + print ["server response: " to-string clipboard] 130 +] 131 + 132 +main: func [argv checked-flags] [ 133 + case [ 134 + none? argv [ usage ] 135 + parse argv ["get" host: string!] [ get-clip host ] 136 + parse argv ["send" host: string!] [ send-clip host ] 137 + parse argv ["serve"] [ start-server ] 138 + not checked-flags [ 139 + new-args: [] 140 + foreach i argv [ 141 + either eq? first i '-' [ flag i ] [ 142 + new-args: join new-args i ] ] 143 + main new-args yes 144 + ] 145 + true [ usage ] 146 + ] 147 +] 148 + 149 +main args no