@ ls works phew
This commit is contained in:
parent
fa4711bd04
commit
c86f8a698c
@ -66,8 +66,22 @@ func get_pubkey(encoded_key string) (encryption_version string, pubkey []byte, e
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func wrap_in_escape_code(data []byte) []byte {
|
||||||
|
const prefix = "\x1bP@kitty-cmd"
|
||||||
|
const suffix = "\x1b\\"
|
||||||
|
ans := make([]byte, len(prefix)+len(data)+len(suffix))
|
||||||
|
n := copy(ans, []byte(prefix))
|
||||||
|
n += copy(ans[n:], data)
|
||||||
|
copy(ans[n:], []byte(suffix))
|
||||||
|
return ans
|
||||||
|
}
|
||||||
|
|
||||||
func simple_serializer(rc *utils.RemoteControlCmd) (ans []byte, err error) {
|
func simple_serializer(rc *utils.RemoteControlCmd) (ans []byte, err error) {
|
||||||
ans, err = json.Marshal(rc)
|
ans, err = json.Marshal(rc)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ans = wrap_in_escape_code(ans)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,7 +98,14 @@ func create_serializer(password string, encoded_pubkey string, io_data *rc_io_da
|
|||||||
}
|
}
|
||||||
io_data.serializer = func(rc *utils.RemoteControlCmd) (ans []byte, err error) {
|
io_data.serializer = func(rc *utils.RemoteControlCmd) (ans []byte, err error) {
|
||||||
ec, err := crypto.Encrypt_cmd(rc, global_options.password, pubkey, encryption_version)
|
ec, err := crypto.Encrypt_cmd(rc, global_options.password, pubkey, encryption_version)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
ans, err = json.Marshal(ec)
|
ans, err = json.Marshal(ec)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ans = wrap_in_escape_code(ans)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if io_data.timeout < 120*time.Second {
|
if io_data.timeout < 120*time.Second {
|
||||||
@ -159,6 +180,14 @@ func (self *rc_io_data) next_chunk(limit_size bool) (chunk []byte, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func single_rc_sender(rc *utils.RemoteControlCmd, serializer serializer_func) ([]byte, error) {
|
||||||
|
if rc.SingleSent() {
|
||||||
|
return make([]byte, 0), nil
|
||||||
|
}
|
||||||
|
rc.SetSingleSent()
|
||||||
|
return serializer(rc)
|
||||||
|
}
|
||||||
|
|
||||||
func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_io_data) (ans *Response, err error) {
|
func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_io_data) (ans *Response, err error) {
|
||||||
serialized_response, err := do_io(io_data)
|
serialized_response, err := do_io(io_data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -166,9 +195,7 @@ func get_response(do_io func(io_data *rc_io_data) ([]byte, error), io_data *rc_i
|
|||||||
io_data.rc.Payload = nil
|
io_data.rc.Payload = nil
|
||||||
io_data.rc.CancelAsync = true
|
io_data.rc.CancelAsync = true
|
||||||
io_data.rc.NoResponse = true
|
io_data.rc.NoResponse = true
|
||||||
io_data.next_block = func(rc *utils.RemoteControlCmd, serializer serializer_func) ([]byte, error) {
|
io_data.next_block = single_rc_sender
|
||||||
return serializer(rc)
|
|
||||||
}
|
|
||||||
_, err = do_io(io_data)
|
_, err = do_io(io_data)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -252,6 +279,10 @@ func get_password(password string, password_file string, password_env string, us
|
|||||||
q, err = os.ReadFile(password_file)
|
q, err = os.ReadFile(password_file)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ans = strings.TrimRight(string(q), " \n\t")
|
ans = strings.TrimRight(string(q), " \n\t")
|
||||||
|
} else {
|
||||||
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
|
err = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -62,9 +62,7 @@ func run_CMD_NAME(cmd *cobra.Command, args []string) (err error) {
|
|||||||
rc: rc,
|
rc: rc,
|
||||||
timeout: time.Duration(timeout * float64(time.Second)),
|
timeout: time.Duration(timeout * float64(time.Second)),
|
||||||
string_response_is_err: STRING_RESPONSE_IS_ERROR,
|
string_response_is_err: STRING_RESPONSE_IS_ERROR,
|
||||||
next_block: func(rc *utils.RemoteControlCmd, serializer serializer_func) ([]byte, error) {
|
next_block: single_rc_sender,
|
||||||
return serializer(rc)
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
err = create_payload_CMD_NAME(&io_data, args)
|
err = create_payload_CMD_NAME(&io_data, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -74,6 +74,9 @@ func do_chunked_io(io_data *rc_io_data) (serialized_response []byte, err error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = loop.Run()
|
err = loop.Run()
|
||||||
|
if err == nil {
|
||||||
|
loop.KillIfSignalled()
|
||||||
|
}
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,8 +10,13 @@ type RemoteControlCmd struct {
|
|||||||
Timestamp int64 `json:"timestamp,omitempty"`
|
Timestamp int64 `json:"timestamp,omitempty"`
|
||||||
Password string `json:"password,omitempty"`
|
Password string `json:"password,omitempty"`
|
||||||
CancelAsync bool `json:"cancel_async,omitempty"`
|
CancelAsync bool `json:"cancel_async,omitempty"`
|
||||||
|
|
||||||
|
single_sent bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (self *RemoteControlCmd) SingleSent() bool { return self.single_sent }
|
||||||
|
func (self *RemoteControlCmd) SetSingleSent() { self.single_sent = true }
|
||||||
|
|
||||||
type EncryptedRemoteControlCmd struct {
|
type EncryptedRemoteControlCmd struct {
|
||||||
Version [3]int `json:"version"`
|
Version [3]int `json:"version"`
|
||||||
IV string `json:"iv"`
|
IV string `json:"iv"`
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user