2023-10-17 06:31:13 +02:00
|
|
|
// Copyright 2023, Command Line Inc.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
2022-07-01 21:17:19 +02:00
|
|
|
package remote
|
|
|
|
|
|
|
|
import (
|
2022-08-24 11:14:16 +02:00
|
|
|
"bytes"
|
2022-07-02 02:38:36 +02:00
|
|
|
"context"
|
2024-04-17 01:58:17 +02:00
|
|
|
"crypto/ecdh"
|
|
|
|
"crypto/rand"
|
|
|
|
"crypto/x509"
|
2022-07-07 07:46:22 +02:00
|
|
|
"encoding/base64"
|
2022-07-07 04:01:00 +02:00
|
|
|
"errors"
|
2022-07-01 21:17:19 +02:00
|
|
|
"fmt"
|
2022-08-19 22:23:00 +02:00
|
|
|
"io"
|
2022-11-27 23:12:15 +01:00
|
|
|
"log"
|
2022-08-19 22:23:00 +02:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
2022-08-17 21:24:09 +02:00
|
|
|
"path"
|
2022-09-14 22:01:52 +02:00
|
|
|
"regexp"
|
2024-03-15 00:50:58 +01:00
|
|
|
"runtime/debug"
|
2022-08-24 06:05:49 +02:00
|
|
|
"strconv"
|
2022-08-17 21:24:09 +02:00
|
|
|
"strings"
|
2022-07-01 21:17:19 +02:00
|
|
|
"sync"
|
2022-08-19 22:23:00 +02:00
|
|
|
"syscall"
|
2022-10-01 02:22:28 +02:00
|
|
|
"time"
|
2022-07-01 21:17:19 +02:00
|
|
|
|
2023-12-31 07:52:30 +01:00
|
|
|
"github.com/alessio/shellescape"
|
2022-09-15 08:10:35 +02:00
|
|
|
"github.com/armon/circbuf"
|
2023-11-01 09:26:19 +01:00
|
|
|
"github.com/creack/pty"
|
|
|
|
"github.com/google/uuid"
|
2023-10-16 22:30:10 +02:00
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/base"
|
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/packet"
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/server"
|
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/shellapi"
|
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/shellenv"
|
2023-10-16 22:30:10 +02:00
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/shexec"
|
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/statediff"
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
"github.com/wavetermdev/waveterm/waveshell/pkg/utilfn"
|
2024-04-03 00:46:32 +02:00
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/ephemeral"
|
2023-10-16 22:30:10 +02:00
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/scbase"
|
2024-02-16 01:45:47 +01:00
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/scbus"
|
2023-10-16 22:30:10 +02:00
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/scpacket"
|
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/sstore"
|
2024-03-26 04:20:52 +01:00
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/telemetry"
|
2024-02-29 20:37:03 +01:00
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/userinput"
|
2024-04-17 01:58:17 +02:00
|
|
|
"github.com/wavetermdev/waveterm/wavesrv/pkg/waveenc"
|
2024-02-16 01:45:47 +01:00
|
|
|
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
"golang.org/x/crypto/ssh"
|
2022-09-25 04:54:06 +02:00
|
|
|
"golang.org/x/mod/semver"
|
2022-07-01 21:17:19 +02:00
|
|
|
)
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
const RemoteTypeWaveshell = "mshell"
|
2022-07-07 04:01:00 +02:00
|
|
|
const DefaultTerm = "xterm-256color"
|
2022-08-19 22:23:00 +02:00
|
|
|
const DefaultMaxPtySize = 1024 * 1024
|
2022-09-15 08:10:35 +02:00
|
|
|
const CircBufSize = 64 * 1024
|
2022-09-16 02:09:04 +02:00
|
|
|
const RemoteTermRows = 8
|
2022-09-15 09:17:23 +02:00
|
|
|
const RemoteTermCols = 80
|
|
|
|
const PtyReadBufSize = 100
|
2023-04-04 03:57:38 +02:00
|
|
|
const RemoteConnectTimeout = 15 * time.Second
|
2024-02-08 21:37:23 +01:00
|
|
|
const RpcIterChannelSize = 100
|
2024-03-21 07:38:05 +01:00
|
|
|
const MaxInputDataSize = 1000
|
2024-04-17 01:58:17 +02:00
|
|
|
const SudoTimeoutTime = 5 * time.Minute
|
2022-07-01 21:17:19 +02:00
|
|
|
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
var envVarsToStrip map[string]bool = map[string]bool{
|
|
|
|
"PROMPT": true,
|
|
|
|
"PROMPT_VERSION": true,
|
|
|
|
"MSHELL": true,
|
|
|
|
"MSHELL_VERSION": true,
|
|
|
|
"WAVETERM": true,
|
|
|
|
"WAVETERM_VERSION": true,
|
|
|
|
"TERM_PROGRAM": true,
|
|
|
|
"TERM_PROGRAM_VERSION": true,
|
|
|
|
"TERM_SESSION_ID": true,
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
// we add this ping packet to the WaveshellServer Commands in order to deal with spurious SSH output
|
2023-12-18 21:42:40 +01:00
|
|
|
// basically we guarantee the parser will see a valid packet (either an init error or a ping)
|
|
|
|
// so we can pass ignoreUntilValid to PacketParser
|
|
|
|
const PrintPingPacket = `printf "\n##N{\"type\": \"ping\"}\n"`
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
const WaveshellServerCommandFmt = `
|
2022-08-17 21:24:09 +02:00
|
|
|
PATH=$PATH:~/.mshell;
|
2022-09-27 06:09:43 +02:00
|
|
|
which mshell-[%VERSION%] > /dev/null;
|
2022-08-17 21:24:09 +02:00
|
|
|
if [[ "$?" -ne 0 ]]
|
|
|
|
then
|
|
|
|
printf "\n##N{\"type\": \"init\", \"notfound\": true, \"uname\": \"%s | %s\"}\n" "$(uname -s)" "$(uname -m)"
|
|
|
|
else
|
2023-12-18 21:42:40 +01:00
|
|
|
[%PINGPACKET%]
|
2022-09-27 06:09:43 +02:00
|
|
|
mshell-[%VERSION%] --server
|
2022-08-17 21:24:09 +02:00
|
|
|
fi
|
|
|
|
`
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func MakeLocalWaveshellCommandStr(isSudo bool) (string, error) {
|
|
|
|
waveshellPath, err := scbase.LocalWaveshellBinaryPath()
|
2022-12-29 08:09:37 +01:00
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2022-12-29 09:07:16 +01:00
|
|
|
if isSudo {
|
2024-05-02 23:16:00 +02:00
|
|
|
return fmt.Sprintf(`%s; sudo %s --server`, PrintPingPacket, shellescape.Quote(waveshellPath)), nil
|
2022-12-29 09:07:16 +01:00
|
|
|
} else {
|
2024-05-02 23:16:00 +02:00
|
|
|
return fmt.Sprintf(`%s; %s --server`, PrintPingPacket, shellescape.Quote(waveshellPath)), nil
|
2022-12-29 09:07:16 +01:00
|
|
|
}
|
2022-12-29 08:09:37 +01:00
|
|
|
}
|
|
|
|
|
2022-09-27 06:09:43 +02:00
|
|
|
func MakeServerCommandStr() string {
|
2024-05-02 23:16:00 +02:00
|
|
|
rtn := strings.ReplaceAll(WaveshellServerCommandFmt, "[%VERSION%]", semver.MajorMinor(scbase.WaveshellVersion))
|
2023-12-18 21:42:40 +01:00
|
|
|
rtn = strings.ReplaceAll(rtn, "[%PINGPACKET%]", PrintPingPacket)
|
|
|
|
return rtn
|
2022-09-27 06:09:43 +02:00
|
|
|
}
|
|
|
|
|
2022-07-02 02:38:36 +02:00
|
|
|
const (
|
ssh config import (#156)
* create migrations for required database change
This is a first attempt that does not appear to be working properly. It
requires review.
* fix errors in db migrations
The previous commit had an extra json call that broke the update and did
not remove the imported interies during a downgrade.
* change migrations to use column instead of json
It makes more sense to associate the source of a config with the remote
type than the sshopts type. This change makes that clear in the database
structure.
* ensure adding a remote manually tags correctly
Using the usual way of adding a remote should result in a sshconfigsrc
of "waveterm-manual". This will be important for filtering out remotes
installed manually and remotes installed via import
* create basic structure for parsing ssh config
This entails creating a new command, making it possible to query only
the imported remotes from the database, and implementing the logic to
handle all of the updates needed.
This needs improvements in a few areas:
- the /etc/ssh/config needs to be parsed as well
- the logic for editing exisiting imported remotes needs to be written
- error handling needs to be improved
- update packet responses need to be provided
* add sshkey support and implement editing
We now search for the ssh identity keyfile and add it if it is found.
Additionally, the logic to edit previously imported ssh hosts has been
added.
* combine hosts from user and system ssh config
We now check both the user ~/.ssh/config as well as the /etc/ssh/config
for hosts. This loops through each file starting with the user one. For
each host, it selects the first pattern without a wildcard and chooses
that to be the alias. If any future hosts are found to have the same
alias, they are skipped. Errors are raised if neither config file can be
opened or no aliases were found.
* improve logging and error reporting
Error reporting is now shortcircuited in cases of individual remotes in
order to allow the other remotes to continue. These errors are now
printed to logs instead.
* allow imports to edit ssh port
Previously, ssh ports could not be edited after the fact. Unfortunately,
this can cause problems since the port can be changed in an ssh config
file. To address this, we allow imports to change the port if a host
with the same canonical name had previously been imported.
* fix response to parse command
* fix error handline for alias parsing
Small mistake of checking for equality instead of inequality
* fix the ability to overwrite hostName with alias
if ssh_config does not find Hostname, it won't output an error. Now we
compare against the result instead of looking for an error.
* fix the error catching for User and Port
This fixes the same problem where parsing the config doesn't give an
error in the case when nothing is found. As before, this checks for a
blank result instead.
* remove unused code
* remove repeated canonical name check
The logic that checks for an existing canonical name already exists in
the AddRemote function, so it is not needed here.
Secondly, we now only allow edits of previously created remotes if they
have not been archived. If they have, the usual logic for creating a new
remote takes precedence.
Lastly, there is no need to archive a remote that has already been
archived so an additional check has been added.
* allow archives to preserve the SSHConfigSrc
* add log message for archiving of imported remotes
* create variables for string variants
Matches existing code style
* add cleanup for opened files
* move migration 25 to migration 26 (already merged a migration 25)
* fix RemoteRuntimeState in ModelUpdate by moving type to sstore.go. Fix some bugs in remote:parse. Fix key/identityfile, return value, and remote editing (should go through msh). remote sudo. add info messages around parse status
* fix issue with archiving the sshconfigsrc
A bug in RemoteType's FromMap caused the loss of sshconfigsrc during the
conversion. This has been corrected and the schema has been updated.
* fix order of archiving removed imported remotes
Previously, if the canonical name changed, the code would try to create
a new remote before archiving the old one. This did not work if the
alias didn't change. Now we archive first and add a new remote after.
* fix ability to change port when importing config
Importing from sshconfig needs to allow the port to change. This was not
happening because of a bug that has been corrected.
* always use host in place of hostname
Since host is the key actually searched for in the ssh config file,
searching for user@hostName may not actually work. To avoid this, we now
always use user@host instead.
* automatically determine ConnectMode
This aims to select a connection mode based off what is provided in the
ssh config file. It aims for auto connections when possible but will
fall back to manual if we can't easily support it
* remove sshkeysource migration number confilict
Previously had conflicting migration numbers of 26. The change not in
the main branch has been moved to 27 to remove the conflict.
* move sshkeysource migration to migration 28
* add WaveOptions flag parsing for ssh config
This is currently being used to allow users to force manual connect mode
if desired. It will also be used to force skipping options in the future
but that is not complete in this commit.
* implement ignore flag for ssh config parsing
The ignore flag will now archive an imported remote if it previously
existed and not create a new remote in its place.
* fix discovery of identity file
Previously, a ~ in the identity file's path was not expanded to the home
dir. Because of this, files with a ~ were previously identified as
invalid files. By expanding it during the search, this is no longer the
case.
* disable frontend edit button for imported remotes
Imported Remotes should not be editable in waveterm by users. This edit
makes it clear that the button will not work for those cases. Further
edits may be needed to explain why it doesn't work and what to do
instead.
* add backend rejection of updating imported remote
As before, we don't want manual editing of an imported remote inside the
app. This ensures that it can't happen on the backend.
* create tooltips for sshconfig edit/delete buttons
For remotes that are imported, edits are not allowed. This adds a
tooltip that explains what to do instead.
Deleting remotes that are imported is allowed, but they will come back
if the user imports again. The tooltip explains a way to avoid this.
* add logo after name for imported remotes
In the connections screen, there previously was not a way to tell
imported connections from manually created connections. This change adds
a logo after the imported ones to differentiate them.
* small formatting updates
* add import tooltip to connection modal
Added the logo for an imported config to the connection modal. It also
provides a short description when it the mouse hovers over it.
* add button to import ssh config
Make the command into a button for a simple gui interface.
Also ran prettier to clean up some syntax.
* remove strict casing on WaveOptions
WaveOptions was previously very specific about the casing of the ignore
and connectmode subcommands. With this update, the casing is
automatically converted to lowercase and can be ignored.
* add status dot before name in connections screen
* add space and tooltip to connection imported icon
* re-prettier
2023-12-28 20:09:41 +01:00
|
|
|
StatusConnected = sstore.RemoteStatus_Connected
|
|
|
|
StatusConnecting = sstore.RemoteStatus_Connecting
|
|
|
|
StatusDisconnected = sstore.RemoteStatus_Disconnected
|
|
|
|
StatusError = sstore.RemoteStatus_Error
|
2022-07-02 02:38:36 +02:00
|
|
|
)
|
|
|
|
|
2022-09-25 04:54:06 +02:00
|
|
|
func init() {
|
2024-05-02 23:16:00 +02:00
|
|
|
if scbase.WaveshellVersion != base.WaveshellVersion {
|
|
|
|
panic(fmt.Sprintf("prompt-server apishell version must match '%s' vs '%s'", scbase.WaveshellVersion, base.WaveshellVersion))
|
2022-09-25 04:54:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-02 02:38:36 +02:00
|
|
|
var GlobalStore *Store
|
|
|
|
|
2022-07-01 23:57:42 +02:00
|
|
|
type Store struct {
|
2022-09-05 23:49:23 +02:00
|
|
|
Lock *sync.Mutex
|
2024-05-02 23:16:00 +02:00
|
|
|
Map map[string]*WaveshellProc // key=remoteid
|
2022-09-06 01:31:22 +02:00
|
|
|
CmdWaitMap map[base.CommandKey][]func()
|
2022-07-01 23:57:42 +02:00
|
|
|
}
|
|
|
|
|
2023-11-10 02:47:24 +01:00
|
|
|
type pendingStateKey struct {
|
|
|
|
ScreenId string
|
|
|
|
RemotePtr sstore.RemotePtrType
|
|
|
|
}
|
|
|
|
|
2024-03-21 07:38:05 +01:00
|
|
|
// provides state, acccess, and control for a waveshell server process
|
2024-05-02 23:16:00 +02:00
|
|
|
type WaveshellProc struct {
|
2022-09-01 21:47:10 +02:00
|
|
|
Lock *sync.Mutex
|
|
|
|
Remote *sstore.RemoteType
|
|
|
|
|
|
|
|
// runtime
|
2022-10-28 07:22:17 +02:00
|
|
|
RemoteId string // can be read without a lock
|
2022-09-16 21:28:09 +02:00
|
|
|
Status string
|
2024-03-21 07:38:05 +01:00
|
|
|
ServerProc *shexec.ClientProc // the server process
|
2022-09-16 21:28:09 +02:00
|
|
|
UName string
|
|
|
|
Err error
|
2023-04-03 10:37:36 +02:00
|
|
|
ErrNoInitPk bool
|
2022-09-16 21:28:09 +02:00
|
|
|
ControllingPty *os.File
|
|
|
|
PtyBuffer *circbuf.Buffer
|
|
|
|
MakeClientCancelFn context.CancelFunc
|
2023-04-04 03:57:38 +02:00
|
|
|
MakeClientDeadline *time.Time
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
StateMap *server.ShellStateMap
|
2022-12-28 22:56:19 +01:00
|
|
|
NumTryConnect int
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
InitPkShellType string
|
2024-01-27 01:25:21 +01:00
|
|
|
DataPosMap *utilfn.SyncMap[base.CommandKey, int64]
|
2022-09-27 06:09:43 +02:00
|
|
|
|
|
|
|
// install
|
2024-05-02 23:16:00 +02:00
|
|
|
InstallStatus string
|
|
|
|
NeedsWaveshellUpgrade bool
|
|
|
|
InstallCancelFn context.CancelFunc
|
|
|
|
InstallErr error
|
2022-09-01 21:47:10 +02:00
|
|
|
|
2024-03-21 07:38:05 +01:00
|
|
|
// for synthetic commands (not run through RunCommand), this provides a way for them
|
|
|
|
// to register to receive input events from the frontend (e.g. ReInit)
|
|
|
|
CommandInputMap map[base.CommandKey]CommandInputSink
|
|
|
|
|
2024-03-14 02:52:41 +01:00
|
|
|
RunningCmds map[base.CommandKey]*RunCmdType
|
2024-03-21 07:38:05 +01:00
|
|
|
PendingStateCmds map[pendingStateKey]base.CommandKey // key=[remoteinstance name] (in progress commands that might update the state)
|
|
|
|
|
2024-04-17 01:58:17 +02:00
|
|
|
Client *ssh.Client
|
|
|
|
sudoPw []byte
|
|
|
|
sudoClearDeadline int64
|
2024-03-21 07:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type CommandInputSink interface {
|
|
|
|
HandleInput(feInput *scpacket.FeInputPacketType) error
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type RunCmdType struct {
|
2024-04-03 00:46:32 +02:00
|
|
|
CK base.CommandKey
|
|
|
|
SessionId string
|
|
|
|
ScreenId string
|
|
|
|
RemotePtr sstore.RemotePtrType
|
|
|
|
RunPacket *packet.RunPacketType
|
|
|
|
EphemeralOpts *ephemeral.EphemeralRunOpts
|
2022-09-01 21:47:10 +02:00
|
|
|
}
|
|
|
|
|
2024-03-21 07:38:05 +01:00
|
|
|
type ReinitCommandSink struct {
|
2024-05-02 23:16:00 +02:00
|
|
|
Remote *WaveshellProc
|
2024-03-21 07:38:05 +01:00
|
|
|
ReqId string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rcs *ReinitCommandSink) HandleInput(feInput *scpacket.FeInputPacketType) error {
|
|
|
|
realData, err := base64.StdEncoding.DecodeString(feInput.InputData64)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error decoding input data: %v", err)
|
|
|
|
}
|
|
|
|
inputPk := packet.MakeRpcInputPacket(rcs.ReqId)
|
|
|
|
inputPk.Data = realData
|
|
|
|
rcs.Remote.ServerProc.Input.SendPacket(inputPk)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
ssh config import (#156)
* create migrations for required database change
This is a first attempt that does not appear to be working properly. It
requires review.
* fix errors in db migrations
The previous commit had an extra json call that broke the update and did
not remove the imported interies during a downgrade.
* change migrations to use column instead of json
It makes more sense to associate the source of a config with the remote
type than the sshopts type. This change makes that clear in the database
structure.
* ensure adding a remote manually tags correctly
Using the usual way of adding a remote should result in a sshconfigsrc
of "waveterm-manual". This will be important for filtering out remotes
installed manually and remotes installed via import
* create basic structure for parsing ssh config
This entails creating a new command, making it possible to query only
the imported remotes from the database, and implementing the logic to
handle all of the updates needed.
This needs improvements in a few areas:
- the /etc/ssh/config needs to be parsed as well
- the logic for editing exisiting imported remotes needs to be written
- error handling needs to be improved
- update packet responses need to be provided
* add sshkey support and implement editing
We now search for the ssh identity keyfile and add it if it is found.
Additionally, the logic to edit previously imported ssh hosts has been
added.
* combine hosts from user and system ssh config
We now check both the user ~/.ssh/config as well as the /etc/ssh/config
for hosts. This loops through each file starting with the user one. For
each host, it selects the first pattern without a wildcard and chooses
that to be the alias. If any future hosts are found to have the same
alias, they are skipped. Errors are raised if neither config file can be
opened or no aliases were found.
* improve logging and error reporting
Error reporting is now shortcircuited in cases of individual remotes in
order to allow the other remotes to continue. These errors are now
printed to logs instead.
* allow imports to edit ssh port
Previously, ssh ports could not be edited after the fact. Unfortunately,
this can cause problems since the port can be changed in an ssh config
file. To address this, we allow imports to change the port if a host
with the same canonical name had previously been imported.
* fix response to parse command
* fix error handline for alias parsing
Small mistake of checking for equality instead of inequality
* fix the ability to overwrite hostName with alias
if ssh_config does not find Hostname, it won't output an error. Now we
compare against the result instead of looking for an error.
* fix the error catching for User and Port
This fixes the same problem where parsing the config doesn't give an
error in the case when nothing is found. As before, this checks for a
blank result instead.
* remove unused code
* remove repeated canonical name check
The logic that checks for an existing canonical name already exists in
the AddRemote function, so it is not needed here.
Secondly, we now only allow edits of previously created remotes if they
have not been archived. If they have, the usual logic for creating a new
remote takes precedence.
Lastly, there is no need to archive a remote that has already been
archived so an additional check has been added.
* allow archives to preserve the SSHConfigSrc
* add log message for archiving of imported remotes
* create variables for string variants
Matches existing code style
* add cleanup for opened files
* move migration 25 to migration 26 (already merged a migration 25)
* fix RemoteRuntimeState in ModelUpdate by moving type to sstore.go. Fix some bugs in remote:parse. Fix key/identityfile, return value, and remote editing (should go through msh). remote sudo. add info messages around parse status
* fix issue with archiving the sshconfigsrc
A bug in RemoteType's FromMap caused the loss of sshconfigsrc during the
conversion. This has been corrected and the schema has been updated.
* fix order of archiving removed imported remotes
Previously, if the canonical name changed, the code would try to create
a new remote before archiving the old one. This did not work if the
alias didn't change. Now we archive first and add a new remote after.
* fix ability to change port when importing config
Importing from sshconfig needs to allow the port to change. This was not
happening because of a bug that has been corrected.
* always use host in place of hostname
Since host is the key actually searched for in the ssh config file,
searching for user@hostName may not actually work. To avoid this, we now
always use user@host instead.
* automatically determine ConnectMode
This aims to select a connection mode based off what is provided in the
ssh config file. It aims for auto connections when possible but will
fall back to manual if we can't easily support it
* remove sshkeysource migration number confilict
Previously had conflicting migration numbers of 26. The change not in
the main branch has been moved to 27 to remove the conflict.
* move sshkeysource migration to migration 28
* add WaveOptions flag parsing for ssh config
This is currently being used to allow users to force manual connect mode
if desired. It will also be used to force skipping options in the future
but that is not complete in this commit.
* implement ignore flag for ssh config parsing
The ignore flag will now archive an imported remote if it previously
existed and not create a new remote in its place.
* fix discovery of identity file
Previously, a ~ in the identity file's path was not expanded to the home
dir. Because of this, files with a ~ were previously identified as
invalid files. By expanding it during the search, this is no longer the
case.
* disable frontend edit button for imported remotes
Imported Remotes should not be editable in waveterm by users. This edit
makes it clear that the button will not work for those cases. Further
edits may be needed to explain why it doesn't work and what to do
instead.
* add backend rejection of updating imported remote
As before, we don't want manual editing of an imported remote inside the
app. This ensures that it can't happen on the backend.
* create tooltips for sshconfig edit/delete buttons
For remotes that are imported, edits are not allowed. This adds a
tooltip that explains what to do instead.
Deleting remotes that are imported is allowed, but they will come back
if the user imports again. The tooltip explains a way to avoid this.
* add logo after name for imported remotes
In the connections screen, there previously was not a way to tell
imported connections from manually created connections. This change adds
a logo after the imported ones to differentiate them.
* small formatting updates
* add import tooltip to connection modal
Added the logo for an imported config to the connection modal. It also
provides a short description when it the mouse hovers over it.
* add button to import ssh config
Make the command into a button for a simple gui interface.
Also ran prettier to clean up some syntax.
* remove strict casing on WaveOptions
WaveOptions was previously very specific about the casing of the ignore
and connectmode subcommands. With this update, the casing is
automatically converted to lowercase and can be ignored.
* add status dot before name in connections screen
* add space and tooltip to connection imported icon
* re-prettier
2023-12-28 20:09:41 +01:00
|
|
|
type RemoteRuntimeState = sstore.RemoteRuntimeState
|
2022-08-24 22:21:54 +02:00
|
|
|
|
2023-05-02 21:43:54 +02:00
|
|
|
func CanComplete(remoteType string) bool {
|
|
|
|
switch remoteType {
|
|
|
|
case sstore.RemoteTypeSsh:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetStatus() string {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.Status
|
2022-09-16 21:28:09 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetRemoteId() string {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.Remote.RemoteId
|
2022-10-04 20:45:24 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetInstallStatus() string {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.InstallStatus
|
2022-09-27 06:09:43 +02:00
|
|
|
}
|
|
|
|
|
2022-07-02 02:38:36 +02:00
|
|
|
func LoadRemotes(ctx context.Context) error {
|
|
|
|
GlobalStore = &Store{
|
2022-09-05 23:49:23 +02:00
|
|
|
Lock: &sync.Mutex{},
|
2024-05-02 23:16:00 +02:00
|
|
|
Map: make(map[string]*WaveshellProc),
|
2022-09-06 01:31:22 +02:00
|
|
|
CmdWaitMap: make(map[base.CommandKey][]func()),
|
2022-07-02 02:38:36 +02:00
|
|
|
}
|
|
|
|
allRemotes, err := sstore.GetAllRemotes(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-10-04 20:45:24 +02:00
|
|
|
var numLocal int
|
2022-12-29 09:07:16 +01:00
|
|
|
var numSudoLocal int
|
2022-07-02 02:38:36 +02:00
|
|
|
for _, remote := range allRemotes {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := MakeWaveshell(remote)
|
|
|
|
GlobalStore.Map[remote.RemoteId] = wsh
|
2022-08-21 21:31:29 +02:00
|
|
|
if remote.ConnectMode == sstore.ConnectModeStartup {
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.Launch(false)
|
2022-07-02 02:38:36 +02:00
|
|
|
}
|
2022-10-04 20:45:24 +02:00
|
|
|
if remote.Local {
|
2023-05-02 21:43:54 +02:00
|
|
|
if remote.IsSudo() {
|
2022-12-29 09:07:16 +01:00
|
|
|
numSudoLocal++
|
|
|
|
} else {
|
|
|
|
numLocal++
|
|
|
|
}
|
2022-10-04 20:45:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if numLocal == 0 {
|
|
|
|
return fmt.Errorf("no local remote found")
|
|
|
|
}
|
|
|
|
if numLocal > 1 {
|
|
|
|
return fmt.Errorf("multiple local remotes found")
|
2022-07-02 02:38:36 +02:00
|
|
|
}
|
2022-12-29 09:07:16 +01:00
|
|
|
if numSudoLocal > 1 {
|
|
|
|
return fmt.Errorf("multiple local sudo remotes found")
|
|
|
|
}
|
2022-07-02 02:38:36 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-01 21:47:10 +02:00
|
|
|
func LoadRemoteById(ctx context.Context, remoteId string) error {
|
|
|
|
r, err := sstore.GetRemoteById(ctx, remoteId)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if r == nil {
|
|
|
|
return fmt.Errorf("remote %s not found", remoteId)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := MakeWaveshell(r)
|
2022-09-01 21:47:10 +02:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
|
|
|
existingRemote := GlobalStore.Map[remoteId]
|
|
|
|
if existingRemote != nil {
|
2022-12-28 22:56:19 +01:00
|
|
|
return fmt.Errorf("cannot add remote %s, already in global map", remoteId)
|
2022-09-01 21:47:10 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
GlobalStore.Map[r.RemoteId] = wsh
|
2022-09-01 21:47:10 +02:00
|
|
|
if r.ConnectMode == sstore.ConnectModeStartup {
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.Launch(false)
|
2022-09-01 21:47:10 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-15 08:10:35 +02:00
|
|
|
func ReadRemotePty(ctx context.Context, remoteId string) (int64, []byte, error) {
|
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := GlobalStore.Map[remoteId]
|
|
|
|
if wsh == nil {
|
2022-09-15 08:10:35 +02:00
|
|
|
return 0, nil, nil
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
barr := wsh.PtyBuffer.Bytes()
|
|
|
|
offset := wsh.PtyBuffer.TotalWritten() - int64(len(barr))
|
2022-09-15 08:10:35 +02:00
|
|
|
return offset, barr, nil
|
|
|
|
}
|
|
|
|
|
2023-01-23 22:28:00 +01:00
|
|
|
func AddRemote(ctx context.Context, r *sstore.RemoteType, shouldStart bool) error {
|
2022-09-14 02:11:36 +02:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
|
|
|
|
|
|
|
existingRemote := getRemoteByCanonicalName_nolock(r.RemoteCanonicalName)
|
|
|
|
if existingRemote != nil {
|
2022-09-14 21:56:05 +02:00
|
|
|
erCopy := existingRemote.GetRemoteCopy()
|
2022-09-14 02:11:36 +02:00
|
|
|
if !erCopy.Archived {
|
|
|
|
return fmt.Errorf("duplicate canonical name %q: cannot create new remote", r.RemoteCanonicalName)
|
|
|
|
}
|
|
|
|
r.RemoteId = erCopy.RemoteId
|
|
|
|
}
|
2022-10-04 20:45:24 +02:00
|
|
|
if r.Local {
|
|
|
|
return fmt.Errorf("cannot create another local remote (there can be only one)")
|
|
|
|
}
|
|
|
|
|
2022-09-14 02:11:36 +02:00
|
|
|
err := sstore.UpsertRemote(ctx, r)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("cannot create remote %q: %v", r.RemoteCanonicalName, err)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
newWsh := MakeWaveshell(r)
|
|
|
|
GlobalStore.Map[r.RemoteId] = newWsh
|
|
|
|
go newWsh.NotifyRemoteUpdate()
|
2023-01-23 22:28:00 +01:00
|
|
|
if shouldStart {
|
2024-05-02 23:16:00 +02:00
|
|
|
go newWsh.Launch(true)
|
2022-09-14 02:11:36 +02:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func ArchiveRemote(ctx context.Context, remoteId string) error {
|
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := GlobalStore.Map[remoteId]
|
|
|
|
if wsh == nil {
|
2022-09-14 02:11:36 +02:00
|
|
|
return fmt.Errorf("remote not found, cannot archive")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Status == StatusConnected {
|
2022-09-14 02:11:36 +02:00
|
|
|
return fmt.Errorf("cannot archive connected remote")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Remote.Local {
|
2022-10-04 20:45:24 +02:00
|
|
|
return fmt.Errorf("cannot archive local remote")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
rcopy := wsh.GetRemoteCopy()
|
2022-09-14 02:11:36 +02:00
|
|
|
archivedRemote := &sstore.RemoteType{
|
|
|
|
RemoteId: rcopy.RemoteId,
|
|
|
|
RemoteType: rcopy.RemoteType,
|
|
|
|
RemoteCanonicalName: rcopy.RemoteCanonicalName,
|
|
|
|
ConnectMode: sstore.ConnectModeManual,
|
|
|
|
Archived: true,
|
ssh config import (#156)
* create migrations for required database change
This is a first attempt that does not appear to be working properly. It
requires review.
* fix errors in db migrations
The previous commit had an extra json call that broke the update and did
not remove the imported interies during a downgrade.
* change migrations to use column instead of json
It makes more sense to associate the source of a config with the remote
type than the sshopts type. This change makes that clear in the database
structure.
* ensure adding a remote manually tags correctly
Using the usual way of adding a remote should result in a sshconfigsrc
of "waveterm-manual". This will be important for filtering out remotes
installed manually and remotes installed via import
* create basic structure for parsing ssh config
This entails creating a new command, making it possible to query only
the imported remotes from the database, and implementing the logic to
handle all of the updates needed.
This needs improvements in a few areas:
- the /etc/ssh/config needs to be parsed as well
- the logic for editing exisiting imported remotes needs to be written
- error handling needs to be improved
- update packet responses need to be provided
* add sshkey support and implement editing
We now search for the ssh identity keyfile and add it if it is found.
Additionally, the logic to edit previously imported ssh hosts has been
added.
* combine hosts from user and system ssh config
We now check both the user ~/.ssh/config as well as the /etc/ssh/config
for hosts. This loops through each file starting with the user one. For
each host, it selects the first pattern without a wildcard and chooses
that to be the alias. If any future hosts are found to have the same
alias, they are skipped. Errors are raised if neither config file can be
opened or no aliases were found.
* improve logging and error reporting
Error reporting is now shortcircuited in cases of individual remotes in
order to allow the other remotes to continue. These errors are now
printed to logs instead.
* allow imports to edit ssh port
Previously, ssh ports could not be edited after the fact. Unfortunately,
this can cause problems since the port can be changed in an ssh config
file. To address this, we allow imports to change the port if a host
with the same canonical name had previously been imported.
* fix response to parse command
* fix error handline for alias parsing
Small mistake of checking for equality instead of inequality
* fix the ability to overwrite hostName with alias
if ssh_config does not find Hostname, it won't output an error. Now we
compare against the result instead of looking for an error.
* fix the error catching for User and Port
This fixes the same problem where parsing the config doesn't give an
error in the case when nothing is found. As before, this checks for a
blank result instead.
* remove unused code
* remove repeated canonical name check
The logic that checks for an existing canonical name already exists in
the AddRemote function, so it is not needed here.
Secondly, we now only allow edits of previously created remotes if they
have not been archived. If they have, the usual logic for creating a new
remote takes precedence.
Lastly, there is no need to archive a remote that has already been
archived so an additional check has been added.
* allow archives to preserve the SSHConfigSrc
* add log message for archiving of imported remotes
* create variables for string variants
Matches existing code style
* add cleanup for opened files
* move migration 25 to migration 26 (already merged a migration 25)
* fix RemoteRuntimeState in ModelUpdate by moving type to sstore.go. Fix some bugs in remote:parse. Fix key/identityfile, return value, and remote editing (should go through msh). remote sudo. add info messages around parse status
* fix issue with archiving the sshconfigsrc
A bug in RemoteType's FromMap caused the loss of sshconfigsrc during the
conversion. This has been corrected and the schema has been updated.
* fix order of archiving removed imported remotes
Previously, if the canonical name changed, the code would try to create
a new remote before archiving the old one. This did not work if the
alias didn't change. Now we archive first and add a new remote after.
* fix ability to change port when importing config
Importing from sshconfig needs to allow the port to change. This was not
happening because of a bug that has been corrected.
* always use host in place of hostname
Since host is the key actually searched for in the ssh config file,
searching for user@hostName may not actually work. To avoid this, we now
always use user@host instead.
* automatically determine ConnectMode
This aims to select a connection mode based off what is provided in the
ssh config file. It aims for auto connections when possible but will
fall back to manual if we can't easily support it
* remove sshkeysource migration number confilict
Previously had conflicting migration numbers of 26. The change not in
the main branch has been moved to 27 to remove the conflict.
* move sshkeysource migration to migration 28
* add WaveOptions flag parsing for ssh config
This is currently being used to allow users to force manual connect mode
if desired. It will also be used to force skipping options in the future
but that is not complete in this commit.
* implement ignore flag for ssh config parsing
The ignore flag will now archive an imported remote if it previously
existed and not create a new remote in its place.
* fix discovery of identity file
Previously, a ~ in the identity file's path was not expanded to the home
dir. Because of this, files with a ~ were previously identified as
invalid files. By expanding it during the search, this is no longer the
case.
* disable frontend edit button for imported remotes
Imported Remotes should not be editable in waveterm by users. This edit
makes it clear that the button will not work for those cases. Further
edits may be needed to explain why it doesn't work and what to do
instead.
* add backend rejection of updating imported remote
As before, we don't want manual editing of an imported remote inside the
app. This ensures that it can't happen on the backend.
* create tooltips for sshconfig edit/delete buttons
For remotes that are imported, edits are not allowed. This adds a
tooltip that explains what to do instead.
Deleting remotes that are imported is allowed, but they will come back
if the user imports again. The tooltip explains a way to avoid this.
* add logo after name for imported remotes
In the connections screen, there previously was not a way to tell
imported connections from manually created connections. This change adds
a logo after the imported ones to differentiate them.
* small formatting updates
* add import tooltip to connection modal
Added the logo for an imported config to the connection modal. It also
provides a short description when it the mouse hovers over it.
* add button to import ssh config
Make the command into a button for a simple gui interface.
Also ran prettier to clean up some syntax.
* remove strict casing on WaveOptions
WaveOptions was previously very specific about the casing of the ignore
and connectmode subcommands. With this update, the casing is
automatically converted to lowercase and can be ignored.
* add status dot before name in connections screen
* add space and tooltip to connection imported icon
* re-prettier
2023-12-28 20:09:41 +01:00
|
|
|
SSHConfigSrc: rcopy.SSHConfigSrc,
|
2022-09-14 02:11:36 +02:00
|
|
|
}
|
|
|
|
err := sstore.UpsertRemote(ctx, archivedRemote)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
newWsh := MakeWaveshell(archivedRemote)
|
|
|
|
GlobalStore.Map[remoteId] = newWsh
|
|
|
|
go newWsh.NotifyRemoteUpdate()
|
2022-09-14 02:11:36 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-09-14 22:01:52 +02:00
|
|
|
var partialUUIDRe = regexp.MustCompile("^[0-9a-f]{8}$")
|
|
|
|
|
|
|
|
func isPartialUUID(s string) bool {
|
|
|
|
return partialUUIDRe.MatchString(s)
|
|
|
|
}
|
|
|
|
|
2023-02-22 07:41:56 +01:00
|
|
|
func NumRemotes() int {
|
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
|
|
|
return len(GlobalStore.Map)
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func GetRemoteByArg(arg string) *WaveshellProc {
|
2022-07-02 02:38:36 +02:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
2022-09-14 22:01:52 +02:00
|
|
|
isPuid := isPartialUUID(arg)
|
2024-05-02 23:16:00 +02:00
|
|
|
for _, wsh := range GlobalStore.Map {
|
|
|
|
rcopy := wsh.GetRemoteCopy()
|
2022-09-14 22:01:52 +02:00
|
|
|
if rcopy.RemoteAlias == arg || rcopy.RemoteCanonicalName == arg || rcopy.RemoteId == arg {
|
2024-05-02 23:16:00 +02:00
|
|
|
return wsh
|
2022-09-14 22:01:52 +02:00
|
|
|
}
|
|
|
|
if isPuid && strings.HasPrefix(rcopy.RemoteId, arg) {
|
2024-05-02 23:16:00 +02:00
|
|
|
return wsh
|
2022-07-06 01:54:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func getRemoteByCanonicalName_nolock(name string) *WaveshellProc {
|
|
|
|
for _, wsh := range GlobalStore.Map {
|
|
|
|
rcopy := wsh.GetRemoteCopy()
|
2022-09-14 02:11:36 +02:00
|
|
|
if rcopy.RemoteCanonicalName == name {
|
2024-05-02 23:16:00 +02:00
|
|
|
return wsh
|
2022-09-14 02:11:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func GetRemoteById(remoteId string) *WaveshellProc {
|
2022-07-06 01:54:49 +02:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
|
|
|
return GlobalStore.Map[remoteId]
|
2022-07-02 02:38:36 +02:00
|
|
|
}
|
2022-07-01 23:57:42 +02:00
|
|
|
|
2023-03-29 21:42:04 +02:00
|
|
|
func GetRemoteCopyById(remoteId string) *sstore.RemoteType {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := GetRemoteById(remoteId)
|
|
|
|
if wsh == nil {
|
2023-03-29 21:42:04 +02:00
|
|
|
return nil
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
rcopy := wsh.GetRemoteCopy()
|
2023-03-29 21:42:04 +02:00
|
|
|
return &rcopy
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func GetRemoteMap() map[string]*WaveshellProc {
|
2022-12-31 02:01:17 +01:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
2024-05-02 23:16:00 +02:00
|
|
|
rtn := make(map[string]*WaveshellProc)
|
|
|
|
for remoteId, wsh := range GlobalStore.Map {
|
|
|
|
rtn[remoteId] = wsh
|
2022-12-31 02:01:17 +01:00
|
|
|
}
|
|
|
|
return rtn
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func GetLocalRemote() *WaveshellProc {
|
2022-10-04 20:45:24 +02:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
2024-05-02 23:16:00 +02:00
|
|
|
for _, wsh := range GlobalStore.Map {
|
|
|
|
if wsh.IsLocal() && !wsh.IsSudo() {
|
|
|
|
return wsh
|
2022-10-04 20:45:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-08-30 01:31:06 +02:00
|
|
|
func ResolveRemoteRef(remoteRef string) *RemoteRuntimeState {
|
2022-08-24 11:14:16 +02:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
|
|
|
|
|
|
|
_, err := uuid.Parse(remoteRef)
|
|
|
|
if err == nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := GlobalStore.Map[remoteRef]
|
|
|
|
if wsh != nil {
|
|
|
|
state := wsh.GetRemoteRuntimeState()
|
2022-08-24 11:14:16 +02:00
|
|
|
return &state
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
for _, wsh := range GlobalStore.Map {
|
|
|
|
if wsh.Remote.RemoteAlias == remoteRef || wsh.Remote.RemoteCanonicalName == remoteRef {
|
|
|
|
state := wsh.GetRemoteRuntimeState()
|
2022-08-24 11:14:16 +02:00
|
|
|
return &state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
func SendSignalToCmd(ctx context.Context, cmd *sstore.CmdType, sig string) error {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := GetRemoteById(cmd.Remote.RemoteId)
|
|
|
|
if wsh == nil {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
return fmt.Errorf("no connection found")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if !wsh.IsConnected() {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
return fmt.Errorf("not connected")
|
|
|
|
}
|
|
|
|
cmdCk := base.MakeCommandKey(cmd.ScreenId, cmd.LineId)
|
2024-05-02 23:16:00 +02:00
|
|
|
if !wsh.IsCmdRunning(cmdCk) {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
// this could also return nil (depends on use case)
|
|
|
|
// settled on coded error so we can check for this error
|
|
|
|
return base.CodedErrorf(packet.EC_CmdNotRunning, "cmd not running")
|
|
|
|
}
|
|
|
|
sigPk := packet.MakeSpecialInputPacket()
|
|
|
|
sigPk.CK = cmdCk
|
|
|
|
sigPk.SigName = sig
|
2024-05-02 23:16:00 +02:00
|
|
|
return wsh.ServerProc.Input.SendPacket(sigPk)
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
}
|
|
|
|
|
2022-08-23 01:00:25 +02:00
|
|
|
func unquoteDQBashString(str string) (string, bool) {
|
|
|
|
if len(str) < 2 {
|
|
|
|
return str, false
|
|
|
|
}
|
|
|
|
if str[0] != '"' || str[len(str)-1] != '"' {
|
|
|
|
return str, false
|
|
|
|
}
|
|
|
|
rtn := make([]byte, 0, len(str)-2)
|
|
|
|
for idx := 1; idx < len(str)-1; idx++ {
|
|
|
|
ch := str[idx]
|
|
|
|
if ch == '"' {
|
|
|
|
return str, false
|
|
|
|
}
|
|
|
|
if ch == '\\' {
|
|
|
|
if idx == len(str)-2 {
|
|
|
|
return str, false
|
|
|
|
}
|
|
|
|
nextCh := str[idx+1]
|
|
|
|
if nextCh == '\n' {
|
|
|
|
idx++
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if nextCh == '$' || nextCh == '"' || nextCh == '\\' || nextCh == '`' {
|
|
|
|
idx++
|
|
|
|
rtn = append(rtn, nextCh)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
rtn = append(rtn, '\\')
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
rtn = append(rtn, ch)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return string(rtn), true
|
|
|
|
}
|
|
|
|
|
2022-08-24 06:05:49 +02:00
|
|
|
func makeShortHost(host string) string {
|
|
|
|
dotIdx := strings.Index(host, ".")
|
|
|
|
if dotIdx == -1 {
|
|
|
|
return host
|
|
|
|
}
|
|
|
|
return host[0:dotIdx]
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) IsLocal() bool {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.Remote.Local
|
2022-10-04 20:45:24 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) IsSudo() bool {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.Remote.IsSudo()
|
2022-12-29 09:07:16 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) tryAutoInstall() {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
if !wsh.Remote.AutoInstall || !wsh.NeedsWaveshellUpgrade || wsh.InstallErr != nil {
|
2023-04-04 07:15:43 +02:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToPtyBuffer_nolock("trying auto-install\n")
|
|
|
|
go wsh.RunInstall(true)
|
2023-04-04 07:15:43 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
// if wsh.IsConnected() then GetShellPref() should return a valid shell
|
|
|
|
// if wsh is not connected, then InitPkShellType might be empty
|
|
|
|
func (wsh *WaveshellProc) GetShellPref() string {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
if wsh.Remote.ShellPref == sstore.ShellTypePref_Detect {
|
|
|
|
return wsh.InitPkShellType
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Remote.ShellPref == "" {
|
2024-02-16 02:42:43 +01:00
|
|
|
return packet.ShellType_bash
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
return wsh.Remote.ShellPref
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetRemoteRuntimeState() RemoteRuntimeState {
|
|
|
|
shellPref := wsh.GetShellPref()
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
2022-08-30 01:31:06 +02:00
|
|
|
state := RemoteRuntimeState{
|
2024-05-02 23:16:00 +02:00
|
|
|
RemoteType: wsh.Remote.RemoteType,
|
|
|
|
RemoteId: wsh.Remote.RemoteId,
|
|
|
|
RemoteAlias: wsh.Remote.RemoteAlias,
|
|
|
|
RemoteCanonicalName: wsh.Remote.RemoteCanonicalName,
|
|
|
|
Status: wsh.Status,
|
|
|
|
ConnectMode: wsh.Remote.ConnectMode,
|
|
|
|
AutoInstall: wsh.Remote.AutoInstall,
|
|
|
|
Archived: wsh.Remote.Archived,
|
|
|
|
RemoteIdx: wsh.Remote.RemoteIdx,
|
|
|
|
SSHConfigSrc: wsh.Remote.SSHConfigSrc,
|
|
|
|
UName: wsh.UName,
|
|
|
|
InstallStatus: wsh.InstallStatus,
|
|
|
|
NeedsWaveshellUpgrade: wsh.NeedsWaveshellUpgrade,
|
|
|
|
Local: wsh.Remote.Local,
|
|
|
|
IsSudo: wsh.Remote.IsSudo(),
|
|
|
|
NoInitPk: wsh.ErrNoInitPk,
|
|
|
|
AuthType: sstore.RemoteAuthTypeNone,
|
|
|
|
ShellPref: wsh.Remote.ShellPref,
|
|
|
|
DefaultShellType: shellPref,
|
|
|
|
}
|
|
|
|
if wsh.Remote.SSHOpts != nil {
|
|
|
|
state.AuthType = wsh.Remote.SSHOpts.GetAuthType()
|
|
|
|
}
|
|
|
|
if wsh.Remote.RemoteOpts != nil {
|
|
|
|
optsCopy := *wsh.Remote.RemoteOpts
|
2022-12-29 09:07:16 +01:00
|
|
|
state.RemoteOpts = &optsCopy
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Err != nil {
|
|
|
|
state.ErrorStr = wsh.Err.Error()
|
2022-09-04 22:51:49 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.InstallErr != nil {
|
|
|
|
state.InstallErrorStr = wsh.InstallErr.Error()
|
2022-09-27 08:23:04 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Status == StatusConnecting {
|
|
|
|
state.WaitingForPassword = wsh.isWaitingForPassword_nolock()
|
|
|
|
if wsh.MakeClientDeadline != nil {
|
|
|
|
state.ConnectTimeout = int(time.Until(*wsh.MakeClientDeadline) / time.Second)
|
2023-04-04 03:57:38 +02:00
|
|
|
if state.ConnectTimeout < 0 {
|
|
|
|
state.ConnectTimeout = 0
|
|
|
|
}
|
2024-02-16 00:58:50 +01:00
|
|
|
state.CountdownActive = true
|
|
|
|
} else {
|
|
|
|
state.CountdownActive = false
|
2023-04-04 03:57:38 +02:00
|
|
|
}
|
2022-10-01 02:22:28 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
vars := wsh.Remote.StateVars
|
2023-03-29 21:42:04 +02:00
|
|
|
if vars == nil {
|
|
|
|
vars = make(map[string]string)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
vars["user"] = wsh.Remote.RemoteUser
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["bestuser"] = vars["user"]
|
2024-05-02 23:16:00 +02:00
|
|
|
vars["host"] = wsh.Remote.RemoteHost
|
|
|
|
vars["shorthost"] = makeShortHost(wsh.Remote.RemoteHost)
|
|
|
|
vars["alias"] = wsh.Remote.RemoteAlias
|
|
|
|
vars["cname"] = wsh.Remote.RemoteCanonicalName
|
|
|
|
vars["remoteid"] = wsh.Remote.RemoteId
|
|
|
|
vars["status"] = wsh.Status
|
|
|
|
vars["type"] = wsh.Remote.RemoteType
|
|
|
|
if wsh.Remote.IsSudo() {
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["sudo"] = "1"
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Remote.Local {
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["local"] = "1"
|
|
|
|
}
|
2022-10-03 21:25:43 +02:00
|
|
|
vars["port"] = "22"
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Remote.SSHOpts != nil {
|
|
|
|
if wsh.Remote.SSHOpts.SSHPort != 0 {
|
|
|
|
vars["port"] = strconv.Itoa(wsh.Remote.SSHOpts.SSHPort)
|
2022-10-04 04:04:48 +02:00
|
|
|
}
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Remote.RemoteOpts != nil && wsh.Remote.RemoteOpts.Color != "" {
|
|
|
|
vars["color"] = wsh.Remote.RemoteOpts.Color
|
2022-10-03 21:25:43 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.ServerProc != nil && wsh.ServerProc.InitPk != nil {
|
|
|
|
initPk := wsh.ServerProc.InitPk
|
2023-04-13 06:42:16 +02:00
|
|
|
if initPk.BuildTime == "" || initPk.BuildTime == "0" {
|
2024-05-02 23:16:00 +02:00
|
|
|
state.WaveshellVersion = initPk.Version
|
2023-04-13 06:42:16 +02:00
|
|
|
} else {
|
2024-05-02 23:16:00 +02:00
|
|
|
state.WaveshellVersion = fmt.Sprintf("%s+%s", initPk.Version, initPk.BuildTime)
|
2023-04-13 06:42:16 +02:00
|
|
|
}
|
|
|
|
vars["home"] = initPk.HomeDir
|
|
|
|
vars["remoteuser"] = initPk.User
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["bestuser"] = vars["remoteuser"]
|
2023-04-13 06:42:16 +02:00
|
|
|
vars["remotehost"] = initPk.HostName
|
|
|
|
vars["remoteshorthost"] = makeShortHost(initPk.HostName)
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["besthost"] = vars["remotehost"]
|
|
|
|
vars["bestshorthost"] = vars["remoteshorthost"]
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Remote.Local && wsh.Remote.IsSudo() {
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["bestuser"] = "sudo"
|
2024-05-02 23:16:00 +02:00
|
|
|
} else if wsh.Remote.IsSudo() {
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["bestuser"] = "sudo@" + vars["bestuser"]
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Remote.Local {
|
2022-08-24 11:14:16 +02:00
|
|
|
vars["bestname"] = vars["bestuser"] + "@local"
|
|
|
|
vars["bestshortname"] = vars["bestuser"] + "@local"
|
|
|
|
} else {
|
|
|
|
vars["bestname"] = vars["bestuser"] + "@" + vars["besthost"]
|
|
|
|
vars["bestshortname"] = vars["bestuser"] + "@" + vars["bestshorthost"]
|
2022-08-23 23:01:52 +02:00
|
|
|
}
|
2023-05-09 01:06:51 +02:00
|
|
|
if vars["remoteuser"] == "root" || vars["sudo"] == "1" {
|
|
|
|
vars["isroot"] = "1"
|
|
|
|
}
|
2024-02-08 21:37:23 +01:00
|
|
|
varsCopy := make(map[string]string)
|
|
|
|
// deep copy so that concurrent calls don't collide on this data
|
|
|
|
for key, value := range vars {
|
|
|
|
varsCopy[key] = value
|
|
|
|
}
|
|
|
|
state.RemoteVars = varsCopy
|
2022-08-23 23:01:52 +02:00
|
|
|
return state
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) NotifyRemoteUpdate() {
|
|
|
|
rstate := wsh.GetRemoteRuntimeState()
|
2024-02-16 01:45:47 +01:00
|
|
|
update := scbus.MakeUpdatePacket()
|
|
|
|
update.AddUpdate(rstate)
|
|
|
|
scbus.MainUpdateBus.DoUpdate(update)
|
2022-08-26 22:12:17 +02:00
|
|
|
}
|
|
|
|
|
2024-02-10 02:19:44 +01:00
|
|
|
func GetAllRemoteRuntimeState() []*RemoteRuntimeState {
|
2022-07-05 07:18:01 +02:00
|
|
|
GlobalStore.Lock.Lock()
|
|
|
|
defer GlobalStore.Lock.Unlock()
|
|
|
|
|
2024-02-10 02:19:44 +01:00
|
|
|
var rtn []*RemoteRuntimeState
|
2022-07-05 07:18:01 +02:00
|
|
|
for _, proc := range GlobalStore.Map {
|
2022-08-30 01:31:06 +02:00
|
|
|
state := proc.GetRemoteRuntimeState()
|
2024-02-10 02:19:44 +01:00
|
|
|
rtn = append(rtn, &state)
|
2022-07-05 07:18:01 +02:00
|
|
|
}
|
|
|
|
return rtn
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func MakeWaveshell(r *sstore.RemoteType) *WaveshellProc {
|
2022-09-15 08:10:35 +02:00
|
|
|
buf, err := circbuf.NewBuffer(CircBufSize)
|
|
|
|
if err != nil {
|
|
|
|
panic(err) // this should never happen (NewBuffer only returns an error if CirBufSize <= 0)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
rtn := &WaveshellProc{
|
2022-10-28 07:00:10 +02:00
|
|
|
Lock: &sync.Mutex{},
|
|
|
|
Remote: r,
|
2022-10-28 07:22:17 +02:00
|
|
|
RemoteId: r.RemoteId,
|
2022-10-28 07:00:10 +02:00
|
|
|
Status: StatusDisconnected,
|
|
|
|
PtyBuffer: buf,
|
|
|
|
InstallStatus: StatusDisconnected,
|
2024-03-21 07:38:05 +01:00
|
|
|
CommandInputMap: make(map[base.CommandKey]CommandInputSink),
|
2024-03-14 02:52:41 +01:00
|
|
|
RunningCmds: make(map[base.CommandKey]*RunCmdType),
|
2023-11-10 02:47:24 +01:00
|
|
|
PendingStateCmds: make(map[pendingStateKey]base.CommandKey),
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
StateMap: server.MakeShellStateMap(),
|
2024-01-27 01:25:21 +01:00
|
|
|
DataPosMap: utilfn.MakeSyncMap[base.CommandKey, int64](),
|
2022-09-15 08:10:35 +02:00
|
|
|
}
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
|
2023-04-04 06:31:40 +02:00
|
|
|
rtn.WriteToPtyBuffer("console for connection [%s]\n", r.GetName())
|
2022-07-02 02:38:36 +02:00
|
|
|
return rtn
|
2022-07-01 23:57:42 +02:00
|
|
|
}
|
|
|
|
|
2022-09-16 02:09:04 +02:00
|
|
|
func SendRemoteInput(pk *scpacket.RemoteInputPacketType) error {
|
|
|
|
data, err := base64.StdEncoding.DecodeString(pk.InputData64)
|
|
|
|
if err != nil {
|
2024-02-29 20:37:03 +01:00
|
|
|
return fmt.Errorf("cannot decode base64: %v", err)
|
2022-09-16 02:09:04 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := GetRemoteById(pk.RemoteId)
|
|
|
|
if wsh == nil {
|
2022-09-16 02:09:04 +02:00
|
|
|
return fmt.Errorf("remote not found")
|
|
|
|
}
|
|
|
|
var cmdPty *os.File
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
cmdPty = wsh.ControllingPty
|
2022-09-16 02:09:04 +02:00
|
|
|
})
|
|
|
|
if cmdPty == nil {
|
|
|
|
return fmt.Errorf("remote has no attached pty")
|
|
|
|
}
|
|
|
|
_, err = cmdPty.Write(data)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("writing to pty: %v", err)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.resetClientDeadline()
|
2022-09-16 02:09:04 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) getClientDeadline() *time.Time {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.MakeClientDeadline
|
2023-04-04 03:57:38 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) resetClientDeadline() {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
if wsh.Status != StatusConnecting {
|
2023-04-04 03:57:38 +02:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
deadline := wsh.MakeClientDeadline
|
2023-04-04 03:57:38 +02:00
|
|
|
if deadline == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
newDeadline := time.Now().Add(RemoteConnectTimeout)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.MakeClientDeadline = &newDeadline
|
2023-04-04 03:57:38 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) watchClientDeadlineTime() {
|
2023-04-04 03:57:38 +02:00
|
|
|
for {
|
|
|
|
time.Sleep(1 * time.Second)
|
2024-05-02 23:16:00 +02:00
|
|
|
status := wsh.GetStatus()
|
2023-04-04 03:57:38 +02:00
|
|
|
if status != StatusConnecting {
|
|
|
|
break
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
deadline := wsh.getClientDeadline()
|
2023-04-04 03:57:38 +02:00
|
|
|
if deadline == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if time.Now().After(*deadline) {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Disconnect(false)
|
2023-04-04 03:57:38 +02:00
|
|
|
break
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.NotifyRemoteUpdate()
|
2023-04-04 03:57:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-17 21:24:09 +02:00
|
|
|
func convertSSHOpts(opts *sstore.SSHOpts) shexec.SSHOpts {
|
2022-08-24 11:14:16 +02:00
|
|
|
if opts == nil || opts.Local {
|
|
|
|
opts = &sstore.SSHOpts{}
|
2022-08-17 21:24:09 +02:00
|
|
|
}
|
|
|
|
return shexec.SSHOpts{
|
|
|
|
SSHHost: opts.SSHHost,
|
|
|
|
SSHOptsStr: opts.SSHOptsStr,
|
|
|
|
SSHIdentity: opts.SSHIdentity,
|
|
|
|
SSHUser: opts.SSHUser,
|
2023-03-17 23:07:29 +01:00
|
|
|
SSHPort: opts.SSHPort,
|
2022-08-17 21:24:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) addControllingTty(ecmd *exec.Cmd) (*os.File, error) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
2022-08-25 07:57:41 +02:00
|
|
|
|
2022-08-19 22:23:00 +02:00
|
|
|
cmdPty, cmdTty, err := pty.Open()
|
|
|
|
if err != nil {
|
2022-08-25 07:57:41 +02:00
|
|
|
return nil, err
|
2022-08-19 22:23:00 +02:00
|
|
|
}
|
2022-09-15 09:17:23 +02:00
|
|
|
pty.Setsize(cmdPty, &pty.Winsize{Rows: RemoteTermRows, Cols: RemoteTermCols})
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ControllingPty = cmdPty
|
2022-08-19 22:23:00 +02:00
|
|
|
ecmd.ExtraFiles = append(ecmd.ExtraFiles, cmdTty)
|
|
|
|
if ecmd.SysProcAttr == nil {
|
|
|
|
ecmd.SysProcAttr = &syscall.SysProcAttr{}
|
|
|
|
}
|
|
|
|
ecmd.SysProcAttr.Setsid = true
|
|
|
|
ecmd.SysProcAttr.Setctty = true
|
|
|
|
ecmd.SysProcAttr.Ctty = len(ecmd.ExtraFiles) + 3 - 1
|
2022-08-25 07:57:41 +02:00
|
|
|
return cmdPty, nil
|
2022-08-19 22:23:00 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) setErrorStatus(err error) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
wsh.Status = StatusError
|
|
|
|
wsh.Err = err
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2022-08-25 07:57:41 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) setInstallErrorStatus(err error) {
|
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", err.Error())
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
wsh.InstallStatus = StatusError
|
|
|
|
wsh.InstallErr = err
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2022-09-27 06:09:43 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetRemoteCopy() sstore.RemoteType {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return *wsh.Remote
|
2022-08-25 07:57:41 +02:00
|
|
|
}
|
2022-07-02 02:38:36 +02:00
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetUName() string {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.UName
|
2022-09-22 08:26:24 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetNumRunningCommands() int {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return len(wsh.RunningCmds)
|
2022-09-01 21:47:10 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) UpdateRemote(ctx context.Context, editMap map[string]interface{}) error {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
updatedRemote, err := sstore.UpdateRemote(ctx, wsh.Remote.RemoteId, editMap)
|
2022-10-03 03:52:55 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if updatedRemote == nil {
|
|
|
|
return fmt.Errorf("no remote returned from UpdateRemote")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Remote = updatedRemote
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2022-10-03 03:52:55 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) Disconnect(force bool) {
|
|
|
|
status := wsh.GetStatus()
|
2022-09-27 08:23:04 +02:00
|
|
|
if status != StatusConnected && status != StatusConnecting {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("remote already disconnected (no action taken)\n")
|
2022-09-27 08:23:04 +02:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
numCommands := wsh.GetNumRunningCommands()
|
2022-09-27 08:23:04 +02:00
|
|
|
if numCommands > 0 && !force {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("remote not disconnected, has %d running commands. use force=1 to force disconnection\n", numCommands)
|
2022-09-27 08:23:04 +02:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
if wsh.ServerProc != nil {
|
|
|
|
wsh.ServerProc.Close()
|
|
|
|
wsh.Client = nil
|
2022-09-14 02:11:36 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.MakeClientCancelFn != nil {
|
|
|
|
wsh.MakeClientCancelFn()
|
|
|
|
wsh.MakeClientCancelFn = nil
|
2022-09-16 21:28:09 +02:00
|
|
|
}
|
2022-09-01 21:47:10 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) CancelInstall() {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
if wsh.InstallCancelFn != nil {
|
|
|
|
wsh.InstallCancelFn()
|
|
|
|
wsh.InstallCancelFn = nil
|
2022-09-27 08:23:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetRemoteName() string {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.Remote.GetName()
|
2022-09-06 21:58:16 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) WriteToPtyBuffer(strFmt string, args ...interface{}) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
wsh.writeToPtyBuffer_nolock(strFmt, args...)
|
2022-09-15 08:10:35 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) writeToPtyBuffer_nolock(strFmt string, args ...interface{}) {
|
2022-09-15 08:10:35 +02:00
|
|
|
// inefficient string manipulation here and read of PtyBuffer, but these messages are rare, nbd
|
|
|
|
realStr := fmt.Sprintf(strFmt, args...)
|
|
|
|
if !strings.HasPrefix(realStr, "~") {
|
|
|
|
realStr = strings.ReplaceAll(realStr, "\n", "\r\n")
|
|
|
|
if !strings.HasSuffix(realStr, "\r\n") {
|
|
|
|
realStr = realStr + "\r\n"
|
|
|
|
}
|
2022-09-15 09:37:17 +02:00
|
|
|
if strings.HasPrefix(realStr, "*") {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
realStr = "\033[0m\033[31mwave>\033[0m " + realStr[1:]
|
2022-09-15 09:37:17 +02:00
|
|
|
} else {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
realStr = "\033[0m\033[32mwave>\033[0m " + realStr
|
2022-09-15 09:37:17 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
barr := wsh.PtyBuffer.Bytes()
|
2022-09-15 08:10:35 +02:00
|
|
|
if len(barr) > 0 && barr[len(barr)-1] != '\n' {
|
|
|
|
realStr = "\r\n" + realStr
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
realStr = realStr[1:]
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
curOffset := wsh.PtyBuffer.TotalWritten()
|
2022-09-15 09:17:23 +02:00
|
|
|
data := []byte(realStr)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.PtyBuffer.Write(data)
|
|
|
|
sendRemotePtyUpdate(wsh.Remote.RemoteId, curOffset, data)
|
2022-09-15 09:17:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func sendRemotePtyUpdate(remoteId string, dataOffset int64, data []byte) {
|
|
|
|
data64 := base64.StdEncoding.EncodeToString(data)
|
2024-02-16 01:45:47 +01:00
|
|
|
update := scbus.MakePtyDataUpdate(&scbus.PtyDataUpdate{
|
2022-09-15 09:17:23 +02:00
|
|
|
RemoteId: remoteId,
|
|
|
|
PtyPos: dataOffset,
|
|
|
|
PtyData64: data64,
|
|
|
|
PtyDataLen: int64(len(data)),
|
2024-02-16 01:45:47 +01:00
|
|
|
})
|
|
|
|
scbus.MainUpdateBus.DoUpdate(update)
|
2022-09-15 08:10:35 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) isWaitingForPassword_nolock() bool {
|
|
|
|
barr := wsh.PtyBuffer.Bytes()
|
2022-10-01 02:22:28 +02:00
|
|
|
if len(barr) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
nlIdx := bytes.LastIndex(barr, []byte{'\n'})
|
|
|
|
var lastLine string
|
|
|
|
if nlIdx == -1 {
|
|
|
|
lastLine = string(barr)
|
|
|
|
} else {
|
|
|
|
lastLine = string(barr[nlIdx+1:])
|
|
|
|
}
|
|
|
|
pwIdx := strings.Index(lastLine, "assword")
|
|
|
|
return pwIdx != -1
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) isWaitingForPassphrase_nolock() bool {
|
|
|
|
barr := wsh.PtyBuffer.Bytes()
|
2023-12-12 23:17:53 +01:00
|
|
|
if len(barr) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
nlIdx := bytes.LastIndex(barr, []byte{'\n'})
|
|
|
|
var lastLine string
|
|
|
|
if nlIdx == -1 {
|
|
|
|
lastLine = string(barr)
|
|
|
|
} else {
|
|
|
|
lastLine = string(barr[nlIdx+1:])
|
|
|
|
}
|
|
|
|
pwIdx := strings.Index(lastLine, "Enter passphrase for key")
|
|
|
|
return pwIdx != -1
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) RunPasswordReadLoop(cmdPty *os.File) {
|
2024-02-29 20:37:03 +01:00
|
|
|
buf := make([]byte, PtyReadBufSize)
|
|
|
|
for {
|
|
|
|
_, readErr := cmdPty.Read(buf)
|
|
|
|
if readErr == io.EOF {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if readErr != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error reading from controlling-pty: %v\n", readErr)
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
var newIsWaiting bool
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
newIsWaiting = wsh.isWaitingForPassword_nolock()
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
|
|
|
if newIsWaiting {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
request := &userinput.UserInputRequestType{
|
|
|
|
QueryText: "Please enter your password",
|
|
|
|
ResponseType: "text",
|
|
|
|
Title: "Sudo Password",
|
|
|
|
Markdown: false,
|
|
|
|
}
|
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
defer cancelFn()
|
|
|
|
response, err := userinput.GetUserInput(ctx, scbus.MainRpcBus, request)
|
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error timed out waiting for password: %v\n", err)
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
curOffset := wsh.PtyBuffer.TotalWritten()
|
|
|
|
wsh.PtyBuffer.Write([]byte(response.Text))
|
|
|
|
sendRemotePtyUpdate(wsh.Remote.RemoteId, curOffset, []byte(response.Text))
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) RunPtyReadLoop(cmdPty *os.File) {
|
2022-09-16 02:44:39 +02:00
|
|
|
buf := make([]byte, PtyReadBufSize)
|
2022-10-01 02:22:28 +02:00
|
|
|
var isWaiting bool
|
2022-09-16 02:44:39 +02:00
|
|
|
for {
|
|
|
|
n, readErr := cmdPty.Read(buf)
|
|
|
|
if readErr == io.EOF {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if readErr != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error reading from controlling-pty: %v\n", readErr)
|
2022-09-16 02:44:39 +02:00
|
|
|
break
|
|
|
|
}
|
2022-10-01 02:22:28 +02:00
|
|
|
var newIsWaiting bool
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
curOffset := wsh.PtyBuffer.TotalWritten()
|
|
|
|
wsh.PtyBuffer.Write(buf[0:n])
|
|
|
|
sendRemotePtyUpdate(wsh.Remote.RemoteId, curOffset, buf[0:n])
|
|
|
|
newIsWaiting = wsh.isWaitingForPassword_nolock()
|
2022-09-16 02:44:39 +02:00
|
|
|
})
|
2022-10-01 02:22:28 +02:00
|
|
|
if newIsWaiting != isWaiting {
|
|
|
|
isWaiting = newIsWaiting
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.NotifyRemoteUpdate()
|
2022-10-01 02:22:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) CheckPasswordRequested(ctx context.Context, requiresPassword chan bool) {
|
2024-02-29 20:37:03 +01:00
|
|
|
for {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.isWaitingForPassword_nolock() {
|
2024-02-29 20:37:03 +01:00
|
|
|
select {
|
|
|
|
case requiresPassword <- true:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Status != StatusConnecting {
|
2024-02-29 20:37:03 +01:00
|
|
|
select {
|
|
|
|
case requiresPassword <- false:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
})
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) SendPassword(pw string) {
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.ControllingPty == nil {
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
pwBytes := []byte(pw + "\r")
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToPtyBuffer_nolock("~[sent password]\r\n")
|
|
|
|
_, err := wsh.ControllingPty.Write(pwBytes)
|
2024-02-29 20:37:03 +01:00
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToPtyBuffer_nolock("*cannot write password to controlling pty: %v\n", err)
|
2024-02-29 20:37:03 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) WaitAndSendPasswordNew(pw string) {
|
2024-02-29 20:37:03 +01:00
|
|
|
requiresPassword := make(chan bool, 1)
|
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
defer cancelFn()
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.CheckPasswordRequested(ctx, requiresPassword)
|
2024-02-29 20:37:03 +01:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err := ctx.Err()
|
|
|
|
var errMsg error
|
|
|
|
if err == context.Canceled {
|
|
|
|
errMsg = fmt.Errorf("canceled by the user")
|
|
|
|
} else {
|
|
|
|
errMsg = fmt.Errorf("timed out waiting for password prompt")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", errMsg.Error())
|
|
|
|
wsh.setErrorStatus(errMsg)
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
case required := <-requiresPassword:
|
|
|
|
if !required {
|
|
|
|
// we don't need user input in this case, so we exit early
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
request := &userinput.UserInputRequestType{
|
|
|
|
QueryText: "Please enter your password",
|
|
|
|
ResponseType: "text",
|
|
|
|
Title: "Sudo Password",
|
|
|
|
Markdown: false,
|
|
|
|
}
|
|
|
|
response, err := userinput.GetUserInput(ctx, scbus.MainRpcBus, request)
|
|
|
|
if err != nil {
|
|
|
|
var errMsg error
|
|
|
|
if err == context.Canceled {
|
|
|
|
errMsg = fmt.Errorf("canceled by the user")
|
|
|
|
} else {
|
|
|
|
errMsg = fmt.Errorf("timed out waiting for user input")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", errMsg.Error())
|
|
|
|
wsh.setErrorStatus(errMsg)
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.SendPassword(response.Text)
|
2024-02-29 20:37:03 +01:00
|
|
|
|
|
|
|
//error out if requested again
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.CheckPasswordRequested(ctx, requiresPassword)
|
2024-02-29 20:37:03 +01:00
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
err := ctx.Err()
|
|
|
|
var errMsg error
|
|
|
|
if err == context.Canceled {
|
|
|
|
errMsg = fmt.Errorf("canceled by the user")
|
|
|
|
} else {
|
|
|
|
errMsg = fmt.Errorf("timed out waiting for password prompt")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", errMsg.Error())
|
|
|
|
wsh.setErrorStatus(errMsg)
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
case required := <-requiresPassword:
|
|
|
|
if !required {
|
|
|
|
// we don't need user input in this case, so we exit early
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errMsg := fmt.Errorf("*error, incorrect password")
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", errMsg.Error())
|
|
|
|
wsh.setErrorStatus(errMsg)
|
2024-02-29 20:37:03 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) WaitAndSendPassword(pw string) {
|
2022-10-01 02:22:28 +02:00
|
|
|
var numWaits int
|
|
|
|
for {
|
|
|
|
var isWaiting bool
|
|
|
|
var isConnecting bool
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.Remote.SSHOpts.GetAuthType() == sstore.RemoteAuthTypeKeyPassword {
|
|
|
|
isWaiting = wsh.isWaitingForPassphrase_nolock()
|
2023-12-12 23:17:53 +01:00
|
|
|
} else {
|
2024-05-02 23:16:00 +02:00
|
|
|
isWaiting = wsh.isWaitingForPassword_nolock()
|
2023-12-12 23:17:53 +01:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
isConnecting = wsh.Status == StatusConnecting
|
2022-10-01 02:22:28 +02:00
|
|
|
})
|
|
|
|
if !isConnecting {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
if !isWaiting {
|
|
|
|
numWaits = 0
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
numWaits++
|
|
|
|
if numWaits < 10 {
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
} else {
|
|
|
|
// send password
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.ControllingPty == nil {
|
2022-10-01 02:22:28 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
pwBytes := []byte(pw + "\r")
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToPtyBuffer_nolock("~[sent password]\r\n")
|
|
|
|
_, err := wsh.ControllingPty.Write(pwBytes)
|
2022-10-01 02:22:28 +02:00
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToPtyBuffer_nolock("*cannot write password to controlling pty: %v\n", err)
|
2022-10-01 02:22:28 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
break
|
|
|
|
}
|
2022-09-16 02:44:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) RunInstall(autoInstall bool) {
|
2024-03-15 00:50:58 +01:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
errMsg := fmt.Errorf("this should not happen. if it does, please reach out to us in our discord or open an issue on our github\n\n"+
|
|
|
|
"error:\n%v\n\nstack trace:\n%s", r, string(debug.Stack()))
|
|
|
|
log.Printf("fatal error, %s\n", errMsg)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*fatal error, %s\n", errMsg)
|
|
|
|
wsh.setErrorStatus(errMsg)
|
2024-03-15 00:50:58 +01:00
|
|
|
}
|
|
|
|
}()
|
2024-05-02 23:16:00 +02:00
|
|
|
remoteCopy := wsh.GetRemoteCopy()
|
2022-09-27 06:09:43 +02:00
|
|
|
if remoteCopy.Archived {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error: cannot install on archived remote\n")
|
2022-09-27 08:23:04 +02:00
|
|
|
return
|
|
|
|
}
|
2024-03-08 07:37:00 +01:00
|
|
|
|
|
|
|
var makeClientCtx context.Context
|
|
|
|
var makeClientCancelFn context.CancelFunc
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
2024-03-08 07:37:00 +01:00
|
|
|
makeClientCtx, makeClientCancelFn = context.WithCancel(context.Background())
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.MakeClientCancelFn = makeClientCancelFn
|
|
|
|
wsh.MakeClientDeadline = nil
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2024-03-08 07:37:00 +01:00
|
|
|
})
|
|
|
|
defer makeClientCancelFn()
|
|
|
|
clientData, err := sstore.EnsureClientData(makeClientCtx)
|
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error: cannot obtain client data: %v", err)
|
2024-03-08 07:37:00 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
hideShellPrompt := clientData.ClientOpts.ConfirmFlags["hideshellprompt"]
|
2024-05-02 23:16:00 +02:00
|
|
|
baseStatus := wsh.GetStatus()
|
2024-03-08 07:37:00 +01:00
|
|
|
|
|
|
|
if baseStatus == StatusConnected {
|
|
|
|
ctx, cancelFn := context.WithTimeout(makeClientCtx, 60*time.Second)
|
|
|
|
defer cancelFn()
|
|
|
|
request := &userinput.UserInputRequestType{
|
|
|
|
ResponseType: "confirm",
|
|
|
|
QueryText: "Waveshell is running on your connection and must be restarted to re-install. Would you like to continue?",
|
|
|
|
Title: "Restart Waveshell",
|
|
|
|
}
|
|
|
|
response, err := userinput.GetUserInput(ctx, scbus.MainRpcBus, request)
|
|
|
|
if err != nil {
|
|
|
|
if err == context.Canceled {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("installation canceled by user\n")
|
2024-03-08 07:37:00 +01:00
|
|
|
} else {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("timed out waiting for user input\n")
|
2024-03-08 07:37:00 +01:00
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if !response.Confirm {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("installation canceled by user\n")
|
2024-03-08 07:37:00 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
} else if !hideShellPrompt {
|
|
|
|
ctx, cancelFn := context.WithTimeout(makeClientCtx, 60*time.Second)
|
|
|
|
defer cancelFn()
|
2024-03-04 20:56:20 +01:00
|
|
|
request := &userinput.UserInputRequestType{
|
|
|
|
ResponseType: "confirm",
|
|
|
|
QueryText: "Waveshell must be reinstalled on the connection to continue. Would you like to install it?",
|
|
|
|
Title: "Install Waveshell",
|
2024-03-08 07:37:00 +01:00
|
|
|
CheckBoxMsg: "Don't show me this again",
|
2024-03-04 20:56:20 +01:00
|
|
|
}
|
|
|
|
response, err := userinput.GetUserInput(ctx, scbus.MainRpcBus, request)
|
|
|
|
if err != nil {
|
|
|
|
var errMsg error
|
|
|
|
if err == context.Canceled {
|
|
|
|
errMsg = fmt.Errorf("installation canceled by user")
|
|
|
|
} else {
|
|
|
|
errMsg = fmt.Errorf("timed out waiting for user input")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = nil
|
2024-03-04 20:56:20 +01:00
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", errMsg)
|
|
|
|
wsh.setErrorStatus(errMsg)
|
2024-03-04 20:56:20 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if !response.Confirm {
|
|
|
|
errMsg := fmt.Errorf("installation canceled by user")
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", errMsg.Error())
|
|
|
|
wsh.setErrorStatus(err)
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = nil
|
2024-03-04 20:56:20 +01:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2024-03-08 07:37:00 +01:00
|
|
|
if response.CheckboxStat {
|
|
|
|
clientData.ClientOpts.ConfirmFlags["hideshellprompt"] = true
|
|
|
|
err = sstore.SetClientOpts(makeClientCtx, clientData.ClientOpts)
|
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", err)
|
|
|
|
wsh.setErrorStatus(err)
|
2024-03-08 07:37:00 +01:00
|
|
|
return
|
2024-03-04 20:56:20 +01:00
|
|
|
}
|
2024-03-08 07:37:00 +01:00
|
|
|
|
|
|
|
//reload updated clientdata before sending
|
|
|
|
clientData, err = sstore.EnsureClientData(makeClientCtx)
|
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", err)
|
|
|
|
wsh.setErrorStatus(err)
|
2024-03-08 07:37:00 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
update := scbus.MakeUpdatePacket()
|
|
|
|
update.AddUpdate(*clientData)
|
2024-03-04 20:56:20 +01:00
|
|
|
}
|
2022-09-27 06:09:43 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
curStatus := wsh.GetInstallStatus()
|
2022-09-27 06:09:43 +02:00
|
|
|
if curStatus == StatusConnecting {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error: cannot install on remote that is already trying to install, cancel current install to try again\n")
|
2022-09-27 06:09:43 +02:00
|
|
|
return
|
|
|
|
}
|
2024-02-29 20:37:03 +01:00
|
|
|
if remoteCopy.Local {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error: cannot install on a local remote\n")
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
}
|
2024-09-18 01:29:26 +02:00
|
|
|
sapi, err := shellapi.MakeShellApi(wsh.GetShellType())
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error: %v\n", err)
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.Client == nil {
|
2024-03-04 20:56:20 +01:00
|
|
|
remoteDisplayName := fmt.Sprintf("%s [%s]", remoteCopy.RemoteAlias, remoteCopy.RemoteCanonicalName)
|
2024-09-18 01:29:26 +02:00
|
|
|
sshAuthSock, _ := exec.CommandContext(makeClientCtx, sapi.GetLocalShellPath(), "-c", "echo \"${SSH_AUTH_SOCK}\"").CombinedOutput()
|
|
|
|
client, err := ConnectToClient(makeClientCtx, remoteCopy.SSHOpts, remoteDisplayName, strings.TrimSpace(string(sshAuthSock)))
|
2024-02-29 20:37:03 +01:00
|
|
|
if err != nil {
|
|
|
|
statusErr := fmt.Errorf("ssh cannot connect to client: %w", err)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.setInstallErrorStatus(statusErr)
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = client
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
session, err := wsh.Client.NewSession()
|
2022-09-27 06:09:43 +02:00
|
|
|
if err != nil {
|
2024-02-29 20:37:03 +01:00
|
|
|
statusErr := fmt.Errorf("ssh cannot connect to client: %w", err)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.setInstallErrorStatus(statusErr)
|
2022-09-27 06:09:43 +02:00
|
|
|
return
|
|
|
|
}
|
2024-02-29 20:37:03 +01:00
|
|
|
installSession := shexec.SessionWrap{Session: session, StartCmd: shexec.MakeInstallCommandStr()}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("installing waveshell %s to %s...\n", scbase.WaveshellVersion, remoteCopy.RemoteCanonicalName)
|
2022-09-27 06:09:43 +02:00
|
|
|
clientCtx, clientCancelFn := context.WithCancel(context.Background())
|
|
|
|
defer clientCancelFn()
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.InstallErr = nil
|
|
|
|
wsh.InstallStatus = StatusConnecting
|
|
|
|
wsh.InstallCancelFn = clientCancelFn
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2022-09-27 06:09:43 +02:00
|
|
|
})
|
|
|
|
msgFn := func(msg string) {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("%s", msg)
|
2022-09-27 06:09:43 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
err = shexec.RunInstallFromCmd(clientCtx, installSession, true, nil, scbase.WaveshellBinaryReader, msgFn)
|
2022-09-27 08:23:04 +02:00
|
|
|
if err == context.Canceled {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*install canceled\n")
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.InstallStatus = StatusDisconnected
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2022-09-27 08:23:04 +02:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2022-09-27 06:09:43 +02:00
|
|
|
if err != nil {
|
|
|
|
statusErr := fmt.Errorf("install failed: %w", err)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.setInstallErrorStatus(statusErr)
|
2022-09-27 06:09:43 +02:00
|
|
|
return
|
|
|
|
}
|
2023-04-04 07:15:43 +02:00
|
|
|
var connectMode string
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.InstallStatus = StatusDisconnected
|
|
|
|
wsh.InstallCancelFn = nil
|
|
|
|
wsh.NeedsWaveshellUpgrade = false
|
|
|
|
wsh.Status = StatusDisconnected
|
|
|
|
wsh.Err = nil
|
|
|
|
connectMode = wsh.Remote.ConnectMode
|
2022-09-27 08:23:04 +02:00
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("successfully installed waveshell %s to ~/.mshell\n", scbase.WaveshellVersion)
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2024-03-04 20:56:20 +01:00
|
|
|
if connectMode == sstore.ConnectModeStartup || connectMode == sstore.ConnectModeAuto || autoInstall {
|
|
|
|
// the install was successful, and we didn't click the install button with manual connect mode, try to connect
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.Launch(true)
|
2023-04-04 07:15:43 +02:00
|
|
|
}
|
2022-09-27 06:09:43 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) updateRemoteStateVars(ctx context.Context, remoteId string, initPk *packet.InitPacketType) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
2023-03-29 21:42:04 +02:00
|
|
|
stateVars := getStateVarsFromInitPk(initPk)
|
|
|
|
if stateVars == nil {
|
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Remote.StateVars = stateVars
|
2023-03-29 21:42:04 +02:00
|
|
|
err := sstore.UpdateRemoteStateVars(ctx, remoteId, stateVars)
|
|
|
|
if err != nil {
|
|
|
|
// ignore error, nothing to do
|
|
|
|
log.Printf("error updating remote statevars: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func getStateVarsFromInitPk(initPk *packet.InitPacketType) map[string]string {
|
|
|
|
if initPk == nil || initPk.NotFound {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
rtn := make(map[string]string)
|
|
|
|
rtn["home"] = initPk.HomeDir
|
|
|
|
rtn["remoteuser"] = initPk.User
|
|
|
|
rtn["remotehost"] = initPk.HostName
|
|
|
|
rtn["remoteuname"] = initPk.UName
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
rtn["shelltype"] = initPk.Shell
|
2023-03-29 21:42:04 +02:00
|
|
|
return rtn
|
|
|
|
}
|
|
|
|
|
2024-03-26 04:20:52 +01:00
|
|
|
func makeReinitErrorUpdate(shellType string) telemetry.ActivityUpdate {
|
|
|
|
rtn := telemetry.ActivityUpdate{}
|
2024-01-24 02:19:03 +01:00
|
|
|
if shellType == packet.ShellType_bash {
|
|
|
|
rtn.ReinitBashErrors = 1
|
|
|
|
} else if shellType == packet.ShellType_zsh {
|
|
|
|
rtn.ReinitZshErrors = 1
|
|
|
|
}
|
|
|
|
return rtn
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) ReInit(ctx context.Context, ck base.CommandKey, shellType string, dataFn func([]byte), verbose bool) (rtnPk *packet.ShellStatePacketType, rtnErr error) {
|
|
|
|
if !wsh.IsConnected() {
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
return nil, fmt.Errorf("cannot reinit, remote is not connected")
|
|
|
|
}
|
|
|
|
if shellType != packet.ShellType_bash && shellType != packet.ShellType_zsh {
|
|
|
|
return nil, fmt.Errorf("invalid shell type %q", shellType)
|
|
|
|
}
|
2024-03-20 00:38:38 +01:00
|
|
|
if dataFn == nil {
|
|
|
|
dataFn = func([]byte) {}
|
|
|
|
}
|
|
|
|
defer func() {
|
|
|
|
if rtnErr != nil {
|
2024-04-24 02:40:14 +02:00
|
|
|
telemetry.GoUpdateActivityWrap(makeReinitErrorUpdate(shellType), "reiniterror")
|
2024-03-20 00:38:38 +01:00
|
|
|
}
|
|
|
|
}()
|
|
|
|
startTs := time.Now()
|
2022-10-28 02:10:36 +02:00
|
|
|
reinitPk := packet.MakeReInitPacket()
|
|
|
|
reinitPk.ReqId = uuid.New().String()
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
reinitPk.ShellType = shellType
|
2024-05-02 23:16:00 +02:00
|
|
|
rpcIter, err := wsh.PacketRpcIter(ctx, reinitPk)
|
2022-10-28 02:10:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-03-20 00:38:38 +01:00
|
|
|
defer rpcIter.Close()
|
2024-03-21 07:38:05 +01:00
|
|
|
if ck != "" {
|
|
|
|
reinitSink := &ReinitCommandSink{
|
2024-05-02 23:16:00 +02:00
|
|
|
Remote: wsh,
|
2024-03-21 07:38:05 +01:00
|
|
|
ReqId: reinitPk.ReqId,
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.registerInputSink(ck, reinitSink)
|
|
|
|
defer wsh.unregisterInputSink(ck)
|
2024-03-21 07:38:05 +01:00
|
|
|
}
|
2024-03-20 00:38:38 +01:00
|
|
|
var ssPk *packet.ShellStatePacketType
|
|
|
|
for {
|
|
|
|
resp, err := rpcIter.Next(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if resp == nil {
|
|
|
|
return nil, fmt.Errorf("channel closed with no response")
|
|
|
|
}
|
|
|
|
var ok bool
|
|
|
|
ssPk, ok = resp.(*packet.ShellStatePacketType)
|
|
|
|
if ok {
|
|
|
|
break
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
}
|
2024-03-20 00:38:38 +01:00
|
|
|
respPk, ok := resp.(*packet.ResponsePacketType)
|
|
|
|
if ok {
|
|
|
|
if respPk.Error != "" {
|
|
|
|
return nil, fmt.Errorf("error reinitializing remote: %s", respPk.Error)
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("invalid response from waveshell")
|
|
|
|
}
|
|
|
|
dataPk, ok := resp.(*packet.FileDataPacketType)
|
|
|
|
if ok {
|
|
|
|
dataFn(dataPk.Data)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
invalidPkStr := fmt.Sprintf("\r\ninvalid packettype from waveshell: %s\r\n", resp.GetType())
|
|
|
|
dataFn([]byte(invalidPkStr))
|
2022-10-28 02:10:36 +02:00
|
|
|
}
|
2024-03-20 00:38:38 +01:00
|
|
|
if ssPk == nil || ssPk.State == nil {
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
return nil, fmt.Errorf("invalid reinit response shellstate packet does not contain remote state")
|
2022-10-28 07:52:38 +02:00
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
// TODO: maybe we don't need to save statebase here. should be possible to save it on demand
|
|
|
|
// when it is actually used. complication from other functions that try to get the statebase
|
2024-05-02 23:16:00 +02:00
|
|
|
// from the DB. probably need to route those through WaveshellProc.
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
err = sstore.StoreStateBase(ctx, ssPk.State)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error storing remote state: %w", err)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.StateMap.SetCurrentState(ssPk.State.GetShellType(), ssPk.State)
|
2024-03-20 00:38:38 +01:00
|
|
|
timeDur := time.Since(startTs)
|
|
|
|
dataFn([]byte(makeShellInitOutputMsg(verbose, ssPk.State, ssPk.Stats, timeDur, false)))
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("%s", makeShellInitOutputMsg(false, ssPk.State, ssPk.Stats, timeDur, true))
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
return ssPk, nil
|
2022-10-28 02:10:36 +02:00
|
|
|
}
|
|
|
|
|
2024-03-20 00:38:38 +01:00
|
|
|
func makeShellInitOutputMsg(verbose bool, state *packet.ShellState, stats *packet.ShellStateStats, dur time.Duration, ptyMsg bool) string {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
waveStr := fmt.Sprintf("%swave>%s", utilfn.AnsiGreenColor(), utilfn.AnsiResetColor())
|
2024-03-20 00:38:38 +01:00
|
|
|
if !verbose || ptyMsg {
|
|
|
|
if ptyMsg {
|
|
|
|
return fmt.Sprintf("initialized state shell:%s statehash:%s %dms\n", state.GetShellType(), state.GetHashVal(false), dur.Milliseconds())
|
|
|
|
} else {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
return fmt.Sprintf("%s initialized connection state (shell:%s)\r\n", waveStr, state.GetShellType())
|
2024-03-20 00:38:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
var buf bytes.Buffer
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
buf.WriteString(fmt.Sprintf("%s initialized connection shell:%s statehash:%s %dms\r\n", waveStr, state.GetShellType(), state.GetHashVal(false), dur.Milliseconds()))
|
2024-03-20 00:38:38 +01:00
|
|
|
if stats != nil {
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
buf.WriteString(fmt.Sprintf("%s outsize:%s size:%s env:%d, vars:%d, aliases:%d, funcs:%d\r\n", waveStr, scbase.NumFormatDec(stats.OutputSize), scbase.NumFormatDec(stats.StateSize), stats.EnvCount, stats.VarCount, stats.AliasCount, stats.FuncCount))
|
2024-03-20 00:38:38 +01:00
|
|
|
}
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) WriteFile(ctx context.Context, writePk *packet.WriteFilePacketType) (*packet.RpcResponseIter, error) {
|
|
|
|
return wsh.PacketRpcIter(ctx, writePk)
|
2024-02-08 21:37:23 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) StreamFile(ctx context.Context, streamPk *packet.StreamFilePacketType) (*packet.RpcResponseIter, error) {
|
|
|
|
return wsh.PacketRpcIter(ctx, streamPk)
|
2023-09-01 07:04:31 +02:00
|
|
|
}
|
|
|
|
|
2022-11-02 05:42:56 +01:00
|
|
|
func addScVarsToState(state *packet.ShellState) *packet.ShellState {
|
|
|
|
if state == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
rtn := *state
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
envMap := shellenv.DeclMapFromState(&rtn)
|
|
|
|
envMap["WAVETERM"] = &shellenv.DeclareDeclType{Name: "WAVETERM", Value: "1", Args: "x"}
|
|
|
|
envMap["WAVETERM_VERSION"] = &shellenv.DeclareDeclType{Name: "WAVETERM_VERSION", Value: scbase.WaveVersion, Args: "x"}
|
|
|
|
envMap["TERM_PROGRAM"] = &shellenv.DeclareDeclType{Name: "TERM_PROGRAM", Value: "waveterm", Args: "x"}
|
|
|
|
envMap["TERM_PROGRAM_VERSION"] = &shellenv.DeclareDeclType{Name: "TERM_PROGRAM_VERSION", Value: scbase.WaveVersion, Args: "x"}
|
2024-03-21 07:38:05 +01:00
|
|
|
if scbase.IsDevMode() {
|
|
|
|
envMap["WAVETERM_DEV"] = &shellenv.DeclareDeclType{Name: "WAVETERM_DEV", Value: "1", Args: "x"}
|
|
|
|
}
|
2024-01-09 03:31:17 +01:00
|
|
|
if _, exists := envMap["LANG"]; !exists {
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
envMap["LANG"] = &shellenv.DeclareDeclType{Name: "LANG", Value: scbase.DetermineLang(), Args: "x"}
|
2024-01-09 03:31:17 +01:00
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
rtn.ShellVars = shellenv.SerializeDeclMap(envMap)
|
2022-11-02 05:42:56 +01:00
|
|
|
return &rtn
|
|
|
|
}
|
|
|
|
|
|
|
|
func stripScVarsFromState(state *packet.ShellState) *packet.ShellState {
|
|
|
|
if state == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
rtn := *state
|
2022-11-29 03:03:02 +01:00
|
|
|
rtn.HashVal = ""
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
envMap := shellenv.DeclMapFromState(&rtn)
|
|
|
|
for key := range envVarsToStrip {
|
|
|
|
delete(envMap, key)
|
|
|
|
}
|
|
|
|
rtn.ShellVars = shellenv.SerializeDeclMap(envMap)
|
2022-11-02 05:42:56 +01:00
|
|
|
return &rtn
|
|
|
|
}
|
|
|
|
|
2022-11-29 03:03:02 +01:00
|
|
|
func stripScVarsFromStateDiff(stateDiff *packet.ShellStateDiff) *packet.ShellStateDiff {
|
|
|
|
if stateDiff == nil || len(stateDiff.VarsDiff) == 0 {
|
|
|
|
return stateDiff
|
|
|
|
}
|
|
|
|
rtn := *stateDiff
|
|
|
|
rtn.HashVal = ""
|
|
|
|
var mapDiff statediff.MapDiffType
|
|
|
|
err := mapDiff.Decode(stateDiff.VarsDiff)
|
|
|
|
if err != nil {
|
2023-04-13 21:53:15 +02:00
|
|
|
log.Printf("error decoding statediff in stripScVarsFromStateDiff: %v\n", err)
|
2022-11-29 03:03:02 +01:00
|
|
|
return stateDiff
|
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
for key := range envVarsToStrip {
|
|
|
|
delete(mapDiff.ToAdd, key)
|
|
|
|
}
|
2022-11-29 03:03:02 +01:00
|
|
|
rtn.VarsDiff = mapDiff.Encode()
|
|
|
|
return &rtn
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) getActiveShellTypes(ctx context.Context) ([]string, error) {
|
|
|
|
shellPref := wsh.GetShellPref()
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
rtn := []string{shellPref}
|
2024-05-02 23:16:00 +02:00
|
|
|
activeShells, err := sstore.GetRemoteActiveShells(ctx, wsh.RemoteId)
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return utilfn.CombineStrArrays(rtn, activeShells), nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) createWaveshellSession(clientCtx context.Context, remoteCopy sstore.RemoteType) (shexec.ConnInterface, error) {
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Err = nil
|
|
|
|
wsh.ErrNoInitPk = false
|
|
|
|
wsh.Status = StatusConnecting
|
|
|
|
wsh.MakeClientDeadline = nil
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
sapi, err := shellapi.MakeShellApi(wsh.GetShellType())
|
2024-02-29 20:37:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var wsSession shexec.ConnInterface
|
|
|
|
if remoteCopy.SSHOpts.SSHHost == "" && remoteCopy.Local {
|
2024-05-02 23:16:00 +02:00
|
|
|
cmdStr, err := MakeLocalWaveshellCommandStr(remoteCopy.IsSudo())
|
2024-02-29 20:37:03 +01:00
|
|
|
if err != nil {
|
2024-03-04 20:56:20 +01:00
|
|
|
return nil, fmt.Errorf("cannot find local waveshell binary: %v", err)
|
2024-02-29 20:37:03 +01:00
|
|
|
}
|
|
|
|
ecmd := shexec.MakeLocalExecCmd(cmdStr, sapi)
|
|
|
|
var cmdPty *os.File
|
2024-05-02 23:16:00 +02:00
|
|
|
cmdPty, err = wsh.addControllingTty(ecmd)
|
2024-02-29 20:37:03 +01:00
|
|
|
if err != nil {
|
2024-03-04 20:56:20 +01:00
|
|
|
return nil, fmt.Errorf("cannot attach controlling tty to waveshell command: %v", err)
|
2024-02-29 20:37:03 +01:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.RunPtyReadLoop(cmdPty)
|
|
|
|
go wsh.WaitAndSendPasswordNew(remoteCopy.SSHOpts.SSHPassword)
|
2024-02-29 20:37:03 +01:00
|
|
|
wsSession = shexec.CmdWrap{Cmd: ecmd}
|
2024-05-02 23:16:00 +02:00
|
|
|
} else if wsh.Client == nil {
|
2024-03-04 20:56:20 +01:00
|
|
|
remoteDisplayName := fmt.Sprintf("%s [%s]", remoteCopy.RemoteAlias, remoteCopy.RemoteCanonicalName)
|
2024-09-18 01:29:26 +02:00
|
|
|
sshAuthSock, _ := exec.CommandContext(clientCtx, sapi.GetLocalShellPath(), "-c", "echo \"${SSH_AUTH_SOCK}\"").CombinedOutput()
|
|
|
|
client, err := ConnectToClient(clientCtx, remoteCopy.SSHOpts, remoteDisplayName, strings.TrimSpace(string(sshAuthSock)))
|
2024-02-29 20:37:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ssh cannot connect to client: %w", err)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = client
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
|
|
|
session, err := client.NewSession()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ssh cannot create session: %w", err)
|
|
|
|
}
|
2024-03-04 20:56:20 +01:00
|
|
|
cmd := fmt.Sprintf("%s -c %s", sapi.GetLocalShellPath(), shellescape.Quote(MakeServerCommandStr()))
|
|
|
|
wsSession = shexec.SessionWrap{Session: session, StartCmd: cmd}
|
2024-02-29 20:37:03 +01:00
|
|
|
} else {
|
2024-05-02 23:16:00 +02:00
|
|
|
session, err := wsh.Client.NewSession()
|
2024-02-29 20:37:03 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("ssh cannot create session: %w", err)
|
|
|
|
}
|
2024-03-04 20:56:20 +01:00
|
|
|
cmd := fmt.Sprintf(`%s -c %s`, sapi.GetLocalShellPath(), shellescape.Quote(MakeServerCommandStr()))
|
|
|
|
wsSession = shexec.SessionWrap{Session: session, StartCmd: cmd}
|
2024-02-29 20:37:03 +01:00
|
|
|
}
|
|
|
|
return wsSession, nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) Launch(interactive bool) {
|
2024-03-15 00:50:58 +01:00
|
|
|
defer func() {
|
|
|
|
if r := recover(); r != nil {
|
|
|
|
errMsg := fmt.Errorf("this should not happen. if it does, please reach out to us in our discord or open an issue on our github\n\n"+
|
|
|
|
"error:\n%v\n\nstack trace:\n%s", r, string(debug.Stack()))
|
|
|
|
log.Printf("fatal error, %s\n", errMsg)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*fatal error, %s\n", errMsg)
|
|
|
|
wsh.setErrorStatus(errMsg)
|
2024-03-15 00:50:58 +01:00
|
|
|
}
|
|
|
|
}()
|
2024-05-02 23:16:00 +02:00
|
|
|
remoteCopy := wsh.GetRemoteCopy()
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
if remoteCopy.Archived {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("cannot launch archived remote\n")
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
curStatus := wsh.GetStatus()
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
if curStatus == StatusConnected {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("remote is already connected (no action taken)\n")
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if curStatus == StatusConnecting {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("remote is already connecting, disconnect before trying to connect again\n")
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
istatus := wsh.GetInstallStatus()
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
if istatus == StatusConnecting {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("remote is trying to install, cancel install before trying to connect again\n")
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
return
|
|
|
|
}
|
2024-02-29 20:37:03 +01:00
|
|
|
var makeClientCtx context.Context
|
|
|
|
var makeClientCancelFn context.CancelFunc
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
2024-02-29 20:37:03 +01:00
|
|
|
makeClientCtx, makeClientCancelFn = context.WithCancel(context.Background())
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.MakeClientCancelFn = makeClientCancelFn
|
|
|
|
wsh.MakeClientDeadline = nil
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
|
|
|
defer makeClientCancelFn()
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("connecting to %s...\n", remoteCopy.RemoteCanonicalName)
|
|
|
|
wsSession, err := wsh.createWaveshellSession(makeClientCtx, remoteCopy)
|
2024-03-08 07:37:00 +01:00
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", err.Error())
|
|
|
|
wsh.setErrorStatus(err)
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = nil
|
2024-03-08 07:37:00 +01:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2024-02-29 20:37:03 +01:00
|
|
|
cproc, err := shexec.MakeClientProc(makeClientCtx, wsSession)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.MakeClientCancelFn = nil
|
|
|
|
wsh.MakeClientDeadline = nil
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
|
|
|
if err == context.DeadlineExceeded {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*connect timeout\n")
|
|
|
|
wsh.setErrorStatus(errors.New("connect timeout"))
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = nil
|
2024-02-16 00:58:50 +01:00
|
|
|
})
|
2024-02-29 20:37:03 +01:00
|
|
|
return
|
|
|
|
} else if err == context.Canceled {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*forced disconnection\n")
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Status = StatusDisconnected
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2024-02-16 00:58:50 +01:00
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = nil
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
|
|
|
return
|
|
|
|
} else if serr, ok := err.(shexec.WaveshellLaunchError); ok {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.UName = serr.InitPk.UName
|
|
|
|
wsh.NeedsWaveshellUpgrade = true
|
|
|
|
wsh.InitPkShellType = serr.InitPk.Shell
|
2024-02-16 00:58:50 +01:00
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.StateMap.Clear()
|
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", serr.Error())
|
|
|
|
wsh.setErrorStatus(serr)
|
|
|
|
go wsh.tryAutoInstall()
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
return
|
2024-02-29 20:37:03 +01:00
|
|
|
} else if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error, %s\n", err.Error())
|
|
|
|
wsh.setErrorStatus(err)
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.Client = nil
|
2024-02-29 20:37:03 +01:00
|
|
|
})
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.UName = cproc.InitPk.UName
|
|
|
|
wsh.InitPkShellType = cproc.InitPk.Shell
|
|
|
|
wsh.StateMap.Clear()
|
2024-02-29 20:37:03 +01:00
|
|
|
// no notify here, because we'll call notify in either case below
|
|
|
|
})
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.updateRemoteStateVars(context.Background(), wsh.RemoteId, cproc.InitPk)
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.ServerProc = cproc
|
|
|
|
wsh.Status = StatusConnected
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("connected to %s\n", remoteCopy.RemoteCanonicalName)
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
go func() {
|
|
|
|
exitErr := cproc.Cmd.Wait()
|
2024-04-09 20:33:23 +02:00
|
|
|
exitCode := utilfn.GetExitCode(exitErr)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.Status == StatusConnected || wsh.Status == StatusConnecting {
|
|
|
|
wsh.Status = StatusDisconnected
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
}
|
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*disconnected exitcode=%d\n", exitCode)
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
}()
|
2024-05-02 23:16:00 +02:00
|
|
|
go wsh.ProcessPackets()
|
|
|
|
// wsh.initActiveShells()
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
Use ssh library for remote connections (#250)
* create proof of concept ssh library integration
This is a first attempt to integrate the golang crypto/ssh library for
handling remote connections. As it stands, this features is limited to
identity files without passphrases. It needs to be expanded to include
key+passphrase and password verifications as well.
* add password and keyboard-interactive ssh auth
This adds several new ssh auth methods. In addition to the PublicKey
method used previously, this adds password authentication,
keyboard-interactive authentication, and PublicKey+Passphrase
authentication.
Furthermore, it refactores the ssh connection code into its own wavesrv
file rather than storing int in waveshell's shexec file.
* clean up old mshell launch methods
In the debugging the addition of the ssh library, i had several versions
of the MShellProc Launch function. Since this seems mostly stable, I
have removed the old version and the experimental version in favor of
the combined version.
* allow switching between new and old ssh for dev
It is inconvenient to create milestones without being able to merge into
the main branch. But due to the experimental nature of the ssh changes,
it is not desired to use these changes in the main branch yet. This
change disables the new ssh launcher by default. It can be used by
changing the UseSshLibrary constant to true in remote.go. With this, it
becomes possible to merge these changes into the main branch without
them being used in production.
* fix: allow retry after ssh auth failure
Previously, the error status was not set when an ssh connection failed.
Because of this, an ssh connection failure would lock the failed remote
until waveterm was rebooted. This fix properly sets the error status so
this cannot happen.
2024-01-25 19:18:11 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) initActiveShells() {
|
2024-03-21 07:38:05 +01:00
|
|
|
gasCtx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
defer cancelFn()
|
2024-05-02 23:16:00 +02:00
|
|
|
activeShells, err := wsh.getActiveShellTypes(gasCtx)
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
if err != nil {
|
|
|
|
// we're not going to fail the connect for this error (it will be unusable, but technically connected)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error getting active shells: %v\n", err)
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
return
|
|
|
|
}
|
2024-03-21 07:38:05 +01:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
for _, shellTypeForVar := range activeShells {
|
|
|
|
wg.Add(1)
|
|
|
|
go func(shellType string) {
|
|
|
|
defer wg.Done()
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
reinitCtx, cancelFn := context.WithTimeout(context.Background(), 12*time.Second)
|
2024-03-21 07:38:05 +01:00
|
|
|
defer cancelFn()
|
2024-05-02 23:16:00 +02:00
|
|
|
_, err = wsh.ReInit(reinitCtx, base.CommandKey(""), shellType, nil, false)
|
2024-03-21 07:38:05 +01:00
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*error reiniting shell %q: %v\n", shellType, err)
|
2024-03-21 07:38:05 +01:00
|
|
|
}
|
|
|
|
}(shellTypeForVar)
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
}
|
2024-03-21 07:38:05 +01:00
|
|
|
wg.Wait()
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) IsConnected() bool {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.Status == StatusConnected
|
2022-07-01 21:17:19 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetShellType() string {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
return wsh.InitPkShellType
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
}
|
|
|
|
|
2022-08-24 11:14:16 +02:00
|
|
|
func replaceHomePath(pathStr string, homeDir string) string {
|
|
|
|
if homeDir == "" {
|
|
|
|
return pathStr
|
|
|
|
}
|
|
|
|
if pathStr == homeDir {
|
|
|
|
return "~"
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(pathStr, homeDir+"/") {
|
|
|
|
return "~" + pathStr[len(homeDir):]
|
|
|
|
}
|
|
|
|
return pathStr
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) IsCmdRunning(ck base.CommandKey) bool {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
_, ok := wsh.RunningCmds[ck]
|
2024-01-27 01:25:21 +01:00
|
|
|
return ok
|
2022-07-08 07:46:28 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) KillRunningCommandAndWait(ctx context.Context, ck base.CommandKey) error {
|
|
|
|
if !wsh.IsCmdRunning(ck) {
|
2024-01-27 01:25:21 +01:00
|
|
|
return nil
|
|
|
|
}
|
2024-03-21 07:38:05 +01:00
|
|
|
feiPk := scpacket.MakeFeInputPacket()
|
|
|
|
feiPk.CK = ck
|
|
|
|
feiPk.SigName = "SIGTERM"
|
2024-05-02 23:16:00 +02:00
|
|
|
err := wsh.HandleFeInput(feiPk)
|
2024-01-27 01:25:21 +01:00
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("error trying to kill running cmd: %w", err)
|
|
|
|
}
|
|
|
|
for {
|
|
|
|
if ctx.Err() != nil {
|
|
|
|
return ctx.Err()
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if !wsh.IsCmdRunning(ck) {
|
2024-01-27 01:25:21 +01:00
|
|
|
return nil
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
// TODO fix busy wait (sync with wsh.RunningCmds)
|
2024-01-27 01:25:21 +01:00
|
|
|
// not a huge deal though since this is not processor intensive and not widely used
|
|
|
|
time.Sleep(100 * time.Millisecond)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) SendFileData(dataPk *packet.FileDataPacketType) error {
|
|
|
|
if !wsh.IsConnected() {
|
2023-09-01 07:04:31 +02:00
|
|
|
return fmt.Errorf("remote is not connected, cannot send input")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
return wsh.ServerProc.Input.SendPacket(dataPk)
|
2023-09-01 07:04:31 +02:00
|
|
|
}
|
|
|
|
|
2022-09-04 08:36:15 +02:00
|
|
|
func makeTermOpts(runPk *packet.RunPacketType) sstore.TermOpts {
|
2023-12-12 23:24:09 +01:00
|
|
|
return sstore.TermOpts{Rows: int64(runPk.TermOpts.Rows), Cols: int64(runPk.TermOpts.Cols), FlexRows: runPk.TermOpts.FlexRows, MaxPtySize: DefaultMaxPtySize}
|
2022-07-07 09:10:37 +02:00
|
|
|
}
|
|
|
|
|
2024-03-19 05:29:39 +01:00
|
|
|
// returns (ok, rct)
|
|
|
|
// if ok is true, rct will be nil
|
|
|
|
// if ok is false, rct will be the existing pending state command (not nil)
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) testAndSetPendingStateCmd(screenId string, rptr sstore.RemotePtrType, newCK *base.CommandKey) (bool, *RunCmdType) {
|
2023-11-10 02:47:24 +01:00
|
|
|
key := pendingStateKey{ScreenId: screenId, RemotePtr: rptr}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
ck, found := wsh.PendingStateCmds[key]
|
2022-10-28 07:00:10 +02:00
|
|
|
if found {
|
2024-05-02 23:16:00 +02:00
|
|
|
// we don't call GetRunningCmd here because we already hold wsh.Lock
|
|
|
|
rct := wsh.RunningCmds[ck]
|
2024-03-19 05:29:39 +01:00
|
|
|
if rct != nil {
|
|
|
|
return false, rct
|
|
|
|
}
|
|
|
|
// ok, so rct is nil (that's strange). allow command to proceed, but log
|
|
|
|
log.Printf("[warning] found pending state cmd with no running cmd: %s\n", ck)
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
|
|
|
if newCK != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.PendingStateCmds[key] = *newCK
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
|
|
|
return true, nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) removePendingStateCmd(screenId string, rptr sstore.RemotePtrType, ck base.CommandKey) {
|
2023-11-10 02:47:24 +01:00
|
|
|
key := pendingStateKey{ScreenId: screenId, RemotePtr: rptr}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
existingCK, found := wsh.PendingStateCmds[key]
|
2022-10-28 07:00:10 +02:00
|
|
|
if !found {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if existingCK == ck {
|
2024-05-02 23:16:00 +02:00
|
|
|
delete(wsh.PendingStateCmds, key)
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-27 01:25:21 +01:00
|
|
|
type RunCommandOpts struct {
|
|
|
|
SessionId string
|
|
|
|
ScreenId string
|
|
|
|
RemotePtr sstore.RemotePtrType
|
|
|
|
|
|
|
|
// optional, if not provided shellstate will look up state from remote instance
|
|
|
|
// ReturnState cannot be used with StatePtr
|
|
|
|
// this will also cause this command to bypass the pending state cmd logic
|
2024-03-29 00:56:39 +01:00
|
|
|
StatePtr *packet.ShellStatePtr
|
2024-01-27 01:25:21 +01:00
|
|
|
|
|
|
|
// set to true to skip creating the pty file (for restarted commands)
|
|
|
|
NoCreateCmdPtyFile bool
|
2024-03-14 02:52:41 +01:00
|
|
|
|
|
|
|
// this command will not go into the DB, and will not have a ptyout file created
|
2024-04-03 00:46:32 +02:00
|
|
|
// forces special packet handling (sets RunCommandType.EphemeralOpts)
|
|
|
|
EphemeralOpts *ephemeral.EphemeralRunOpts
|
2024-01-27 01:25:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// returns (CmdType, allow-updates-callback, err)
|
|
|
|
// we must persist the CmdType to the DB before calling the callback to allow updates
|
|
|
|
// otherwise an early CmdDone packet might not get processed (since cmd will not exist in DB)
|
|
|
|
func RunCommand(ctx context.Context, rcOpts RunCommandOpts, runPacket *packet.RunPacketType) (rtnCmd *sstore.CmdType, rtnCallback func(), rtnErr error) {
|
|
|
|
sessionId, screenId, remotePtr := rcOpts.SessionId, rcOpts.ScreenId, rcOpts.RemotePtr
|
2022-08-24 22:21:54 +02:00
|
|
|
if remotePtr.OwnerId != "" {
|
2022-09-05 23:49:23 +02:00
|
|
|
return nil, nil, fmt.Errorf("cannot run command against another user's remote '%s'", remotePtr.MakeFullRemoteRef())
|
2022-08-24 22:21:54 +02:00
|
|
|
}
|
2023-03-21 03:20:57 +01:00
|
|
|
if screenId != runPacket.CK.GetGroupId() {
|
|
|
|
return nil, nil, fmt.Errorf("run commands screenids do not match")
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh := GetRemoteById(remotePtr.RemoteId)
|
|
|
|
if wsh == nil {
|
2022-09-05 23:49:23 +02:00
|
|
|
return nil, nil, fmt.Errorf("no remote id=%s found", remotePtr.RemoteId)
|
2022-07-06 01:54:49 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if !wsh.IsConnected() {
|
2022-09-05 23:49:23 +02:00
|
|
|
return nil, nil, fmt.Errorf("remote '%s' is not connected", remotePtr.RemoteId)
|
2022-07-16 02:37:32 +02:00
|
|
|
}
|
2022-10-28 07:52:38 +02:00
|
|
|
if runPacket.State != nil {
|
|
|
|
return nil, nil, fmt.Errorf("runPacket.State should not be set, it is set in RunCommand")
|
2022-07-06 01:54:49 +02:00
|
|
|
}
|
2024-01-27 01:25:21 +01:00
|
|
|
if rcOpts.StatePtr != nil && runPacket.ReturnState {
|
|
|
|
return nil, nil, fmt.Errorf("RunCommand: cannot use ReturnState with StatePtr")
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
2024-03-29 00:56:39 +01:00
|
|
|
if runPacket.StatePtr != nil {
|
|
|
|
return nil, nil, fmt.Errorf("runPacket.StatePtr should not be set, it is set in RunCommand")
|
|
|
|
}
|
2024-01-27 01:25:21 +01:00
|
|
|
|
|
|
|
// pending state command logic
|
|
|
|
// if we are currently running a command that can change the state, we need to wait for it to finish
|
|
|
|
if rcOpts.StatePtr == nil {
|
|
|
|
var newPSC *base.CommandKey
|
|
|
|
if runPacket.ReturnState {
|
|
|
|
newPSC = &runPacket.CK
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
ok, existingRct := wsh.testAndSetPendingStateCmd(screenId, remotePtr, newPSC)
|
2024-01-27 01:25:21 +01:00
|
|
|
if !ok {
|
2024-04-03 00:46:32 +02:00
|
|
|
if rcOpts.EphemeralOpts != nil {
|
2024-03-14 02:52:41 +01:00
|
|
|
// if the existing command is ephemeral, we cancel it and continue
|
2024-04-03 00:46:32 +02:00
|
|
|
log.Printf("[warning] canceling existing ephemeral state cmd: %s\n", existingRct.CK)
|
|
|
|
rcOpts.EphemeralOpts.Canceled.Store(true)
|
2024-03-14 02:52:41 +01:00
|
|
|
} else {
|
2024-03-19 05:29:39 +01:00
|
|
|
line, _, err := sstore.GetLineCmdByLineId(ctx, screenId, existingRct.CK.GetCmdId())
|
|
|
|
return nil, nil, makePSCLineError(existingRct.CK, line, err)
|
2024-01-27 01:25:21 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if newPSC != nil {
|
|
|
|
defer func() {
|
|
|
|
// if we get an error, remove the pending state cmd
|
|
|
|
// if no error, PSC will get removed when we see a CmdDone or CmdFinal packet
|
|
|
|
if rtnErr != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.removePendingStateCmd(screenId, remotePtr, *newPSC)
|
2024-01-27 01:25:21 +01:00
|
|
|
}
|
|
|
|
}()
|
2022-10-28 02:10:36 +02:00
|
|
|
}
|
2024-01-27 01:25:21 +01:00
|
|
|
}
|
|
|
|
|
2022-10-28 07:52:38 +02:00
|
|
|
// get current remote-instance state
|
2024-03-29 00:56:39 +01:00
|
|
|
var statePtr *packet.ShellStatePtr
|
2024-01-27 01:25:21 +01:00
|
|
|
if rcOpts.StatePtr != nil {
|
|
|
|
statePtr = rcOpts.StatePtr
|
|
|
|
} else {
|
|
|
|
var err error
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
statePtr, err = sstore.GetRemoteStatePtr(ctx, sessionId, screenId, remotePtr)
|
2024-01-27 01:25:21 +01:00
|
|
|
if err != nil {
|
2024-04-03 00:46:32 +02:00
|
|
|
log.Printf("[error] RunCommand: cannot get remote state: %v\n", err)
|
2024-03-07 01:37:54 +01:00
|
|
|
return nil, nil, fmt.Errorf("cannot run command: %w", err)
|
2024-01-27 01:25:21 +01:00
|
|
|
}
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
if statePtr == nil {
|
2024-04-03 00:46:32 +02:00
|
|
|
log.Printf("[error] RunCommand: no valid shell state found\n")
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
return nil, nil, fmt.Errorf("cannot run command: no valid shell state found")
|
|
|
|
}
|
2022-11-29 03:03:02 +01:00
|
|
|
}
|
2024-03-29 00:56:39 +01:00
|
|
|
// statePtr will not be nil
|
|
|
|
runPacket.StatePtr = statePtr
|
2022-11-29 03:03:02 +01:00
|
|
|
currentState, err := sstore.GetFullState(ctx, *statePtr)
|
2024-04-03 00:46:32 +02:00
|
|
|
|
|
|
|
if rcOpts.EphemeralOpts != nil {
|
|
|
|
// Setting UsePty to false will ensure that the outputs get written to the correct file descriptors to extract stdout and stderr
|
|
|
|
runPacket.UsePty = rcOpts.EphemeralOpts.UsePty
|
|
|
|
|
2024-04-30 03:29:27 +02:00
|
|
|
// Ephemeral commands can override the current working directory. We need to expand the home dir if it's relative.
|
2024-04-03 00:46:32 +02:00
|
|
|
if rcOpts.EphemeralOpts.OverrideCwd != "" {
|
2024-04-30 03:29:27 +02:00
|
|
|
overrideCwd := rcOpts.EphemeralOpts.OverrideCwd
|
|
|
|
if !strings.HasPrefix(overrideCwd, "/") {
|
2024-05-02 23:16:00 +02:00
|
|
|
expandedCwd, err := wsh.GetRemoteRuntimeState().ExpandHomeDir(overrideCwd)
|
2024-04-30 03:29:27 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, fmt.Errorf("cannot expand home dir for cwd: %w", err)
|
|
|
|
}
|
|
|
|
overrideCwd = expandedCwd
|
|
|
|
}
|
|
|
|
currentState.Cwd = overrideCwd
|
|
|
|
}
|
|
|
|
|
|
|
|
// Ephemeral commands can override the timeout
|
|
|
|
if rcOpts.EphemeralOpts.TimeoutMs > 0 {
|
|
|
|
runPacket.Timeout = time.Duration(rcOpts.EphemeralOpts.TimeoutMs) * time.Millisecond
|
2024-04-03 00:46:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Ephemeral commands can override the env without persisting it to the DB
|
|
|
|
if len(rcOpts.EphemeralOpts.Env) > 0 {
|
|
|
|
curEnvs := shellenv.DeclMapFromState(currentState)
|
|
|
|
for key, val := range rcOpts.EphemeralOpts.Env {
|
|
|
|
curEnvs[key] = &shellenv.DeclareDeclType{Name: key, Value: val, Args: "x"}
|
|
|
|
}
|
|
|
|
currentState.ShellVars = shellenv.SerializeDeclMap(curEnvs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-29 03:03:02 +01:00
|
|
|
if err != nil || currentState == nil {
|
2024-01-27 01:25:21 +01:00
|
|
|
return nil, nil, fmt.Errorf("cannot load current remote state: %w", err)
|
2022-10-28 07:52:38 +02:00
|
|
|
}
|
2022-11-02 05:42:56 +01:00
|
|
|
runPacket.State = addScVarsToState(currentState)
|
2022-10-28 07:52:38 +02:00
|
|
|
runPacket.StateComplete = true
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
runPacket.ShellType = currentState.GetShellType()
|
2024-01-27 01:25:21 +01:00
|
|
|
|
|
|
|
// start cmdwait. must be started before sending the run packet
|
|
|
|
// this ensures that we don't process output, or cmddone packets until we set up the line, cmd, and ptyout file
|
|
|
|
startCmdWait(runPacket.CK)
|
|
|
|
defer func() {
|
|
|
|
// if we get an error, remove the cmdwait
|
|
|
|
// if no error, cmdwait will get removed by the caller w/ the callback fn that's returned on success
|
|
|
|
if rtnErr != nil {
|
|
|
|
removeCmdWait(runPacket.CK)
|
|
|
|
}
|
|
|
|
}()
|
2024-04-05 00:08:45 +02:00
|
|
|
runningCmdType := &RunCmdType{
|
|
|
|
CK: runPacket.CK,
|
|
|
|
SessionId: sessionId,
|
|
|
|
ScreenId: screenId,
|
|
|
|
RemotePtr: remotePtr,
|
|
|
|
RunPacket: runPacket,
|
|
|
|
EphemeralOpts: rcOpts.EphemeralOpts,
|
|
|
|
}
|
2024-01-27 01:25:21 +01:00
|
|
|
// RegisterRpc + WaitForResponse is used to get any waveshell side errors
|
|
|
|
// waveshell will either return an error (in a ResponsePacketType) or a CmdStartPacketType
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ServerProc.Output.RegisterRpc(runPacket.ReqId)
|
2024-04-05 00:08:45 +02:00
|
|
|
go func() {
|
2024-05-02 23:16:00 +02:00
|
|
|
startPk, err := wsh.sendRunPacketAndReturnResponse(runPacket)
|
2024-04-05 00:08:45 +02:00
|
|
|
runCmdUpdateFn(runPacket.CK, func() {
|
|
|
|
if err != nil {
|
|
|
|
// the cmd failed (never started)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.handleCmdStartError(runningCmdType, err)
|
2024-04-05 00:08:45 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancelFn()
|
2024-05-02 23:16:00 +02:00
|
|
|
err = sstore.UpdateCmdStartInfo(ctx, runPacket.CK, startPk.Pid, startPk.WaveshellPid)
|
2024-04-05 00:08:45 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("error updating cmd start info (in remote.RunCommand): %v\n", err)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}()
|
2024-01-27 01:25:21 +01:00
|
|
|
// command is now successfully runnning
|
2022-07-08 01:29:14 +02:00
|
|
|
status := sstore.CmdStatusRunning
|
|
|
|
if runPacket.Detached {
|
|
|
|
status = sstore.CmdStatusDetached
|
|
|
|
}
|
2022-07-07 09:10:37 +02:00
|
|
|
cmd := &sstore.CmdType{
|
2023-07-31 02:16:43 +02:00
|
|
|
ScreenId: runPacket.CK.GetGroupId(),
|
|
|
|
LineId: runPacket.CK.GetCmdId(),
|
|
|
|
CmdStr: runPacket.Command,
|
|
|
|
RawCmdStr: runPacket.Command,
|
|
|
|
Remote: remotePtr,
|
|
|
|
FeState: sstore.FeStateFromShellState(currentState),
|
|
|
|
StatePtr: *statePtr,
|
|
|
|
TermOpts: makeTermOpts(runPacket),
|
|
|
|
Status: status,
|
|
|
|
ExitCode: 0,
|
|
|
|
DurationMs: 0,
|
|
|
|
RunOut: nil,
|
|
|
|
RtnState: runPacket.ReturnState,
|
|
|
|
}
|
2024-04-03 00:46:32 +02:00
|
|
|
if !rcOpts.NoCreateCmdPtyFile && rcOpts.EphemeralOpts == nil {
|
2024-01-27 01:25:21 +01:00
|
|
|
err = sstore.CreateCmdPtyFile(ctx, cmd.ScreenId, cmd.LineId, cmd.TermOpts.MaxPtySize)
|
|
|
|
if err != nil {
|
|
|
|
// TODO the cmd is running, so this is a tricky error to handle
|
|
|
|
return nil, nil, fmt.Errorf("cannot create local ptyout file for running command: %v", err)
|
2022-10-28 07:52:38 +02:00
|
|
|
}
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.AddRunningCmd(runningCmdType)
|
2024-01-27 01:25:21 +01:00
|
|
|
return cmd, func() { removeCmdWait(runPacket.CK) }, nil
|
2022-10-28 07:52:38 +02:00
|
|
|
}
|
|
|
|
|
2024-04-05 00:08:45 +02:00
|
|
|
// no context because it is called as a goroutine
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) sendRunPacketAndReturnResponse(runPacket *packet.RunPacketType) (*packet.CmdStartPacketType, error) {
|
2024-04-05 00:08:45 +02:00
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancelFn()
|
2024-05-02 23:16:00 +02:00
|
|
|
err := shexec.SendRunPacketAndRunData(ctx, wsh.ServerProc.Input, runPacket)
|
2024-04-05 00:08:45 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("sending run packet to remote: %w", err)
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
rtnPk := wsh.ServerProc.Output.WaitForResponse(ctx, runPacket.ReqId)
|
2024-04-05 00:08:45 +02:00
|
|
|
if rtnPk == nil {
|
|
|
|
return nil, ctx.Err()
|
|
|
|
}
|
|
|
|
startPk, ok := rtnPk.(*packet.CmdStartPacketType)
|
|
|
|
if !ok {
|
|
|
|
respPk, ok := rtnPk.(*packet.ResponsePacketType)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("invalid response received from server for run packet: %s", packet.AsString(rtnPk))
|
|
|
|
}
|
|
|
|
if respPk.Error != "" {
|
|
|
|
return nil, respPk.Err()
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("invalid response received from server for run packet: %s", packet.AsString(rtnPk))
|
|
|
|
}
|
|
|
|
return startPk, nil
|
|
|
|
}
|
|
|
|
|
2024-03-14 02:52:41 +01:00
|
|
|
// helper func to construct the proper error given what information we have
|
|
|
|
func makePSCLineError(existingPSC base.CommandKey, line *sstore.LineType, lineErr error) error {
|
|
|
|
if lineErr != nil {
|
|
|
|
return fmt.Errorf("cannot run command while a stateful command is still running: %v", lineErr)
|
|
|
|
}
|
|
|
|
if line == nil {
|
|
|
|
return fmt.Errorf("cannot run command while a stateful command is still running %s", existingPSC)
|
|
|
|
}
|
|
|
|
return fmt.Errorf("cannot run command while a stateful command (linenum=%d) is still running", line.LineNum)
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) registerInputSink(ck base.CommandKey, sink CommandInputSink) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
wsh.CommandInputMap[ck] = sink
|
2024-03-21 07:38:05 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) unregisterInputSink(ck base.CommandKey) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
delete(wsh.CommandInputMap, ck)
|
2024-03-21 07:38:05 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) HandleFeInput(inputPk *scpacket.FeInputPacketType) error {
|
2024-03-21 07:38:05 +01:00
|
|
|
if inputPk == nil {
|
|
|
|
return nil
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if !wsh.IsConnected() {
|
2024-03-21 07:38:05 +01:00
|
|
|
return fmt.Errorf("connection is not connected, cannot send input")
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.IsCmdRunning(inputPk.CK) {
|
2024-03-21 07:38:05 +01:00
|
|
|
if len(inputPk.InputData64) > 0 {
|
|
|
|
inputLen := packet.B64DecodedLen(inputPk.InputData64)
|
|
|
|
if inputLen > MaxInputDataSize {
|
|
|
|
return fmt.Errorf("input data size too large, len=%d (max=%d)", inputLen, MaxInputDataSize)
|
|
|
|
}
|
|
|
|
dataPk := packet.MakeDataPacket()
|
|
|
|
dataPk.CK = inputPk.CK
|
|
|
|
dataPk.FdNum = 0 // stdin
|
|
|
|
dataPk.Data64 = inputPk.InputData64
|
2024-05-02 23:16:00 +02:00
|
|
|
err := wsh.ServerProc.Input.SendPacket(dataPk)
|
2024-03-21 07:38:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if inputPk.SigName != "" || inputPk.WinSize != nil {
|
|
|
|
siPk := packet.MakeSpecialInputPacket()
|
|
|
|
siPk.CK = inputPk.CK
|
|
|
|
siPk.SigName = inputPk.SigName
|
|
|
|
siPk.WinSize = inputPk.WinSize
|
2024-05-02 23:16:00 +02:00
|
|
|
err := wsh.ServerProc.Input.SendPacket(siPk)
|
2024-03-21 07:38:05 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Lock.Lock()
|
|
|
|
sink := wsh.CommandInputMap[inputPk.CK]
|
|
|
|
wsh.Lock.Unlock()
|
2024-03-21 07:38:05 +01:00
|
|
|
if sink == nil {
|
|
|
|
// no sink and no running command
|
reinit updates (#500)
* working on re-init when you create a tab. some refactoring of existing reinit to make the messaging clearer. auto-connect, etc.
* working to remove the 'default' shell states out of MShellProc. each tab should have its own state that gets set on open.
* refactor newtab settings into individual components (and move to a new file)
* more refactoring of tab settings -- use same control in settings and newtab
* have screensettings use the same newtab settings components
* use same conn dropdown, fix classes, update some of the confirm messages to be less confusing (replace screen with tab)
* force a cr on a new tab to initialize state in a new line. poc right now, need to add to new workspace workflow as well
* small fixups
* remove nohist from GetRawStr, make const
* update hover behavior for tabs
* fix interaction between change remote dropdown, cmdinput, error handling, and selecting a remote
* only switch screen remote if the activemainview is session (new remote flow). don't switch it if we're on the connections page which is confusing. also make it interactive
* fix wording on tos modal
* allow empty workspaces. also allow the last workspace to be deleted. (prep for new startup sequence where we initialize the first session after tos modal)
* add some dead code that might come in use later (when we change how we show connection in cmdinput)
* working a cople different angles. new settings tab-pulldown (likely orphaned). and then allowing null activeScreen and null activeSession in workspaceview (show appropriate messages, and give buttons to create new tabs/workspaces). prep for new startup flow
* don't call initActiveShells anymore. also call ensureWorkspace() on TOS close
* trying to use new pulldown screen settings
* experiment with an escape keybinding
* working on tab settings close triggers
* close tab settings on tab switch
* small updates to tos popup, reorder, update button text/size, small wording updates
* when deleting a screen, send SIGHUP to all running commands
* not sure how this happened, lineid should not be passed to setLineFocus
* remove context timeouts for ReInit (it is now interactive, so it gets canceled like a normal command -- via ^C, and should not timeout on its own)
* deal with screen/session tombstones updates (ignore to quite warning)
* remove defaultfestate from remote
* fix issue with removing default ris
* remove dead code
* open the settings pulldown for new screens
* update prompt to show when the shell is still initializing (or if it failed)
* switch buttons to use wave button class, update messages, and add warning for no shell state
* all an override of rptr for dyncmds. needed for the 'connect' command (we need to set the rptr to the *new* connection rather than the old one)
* remove old commented out code
2024-03-27 08:22:57 +01:00
|
|
|
return fmt.Errorf("cannot send input, cmd is not running (%s)", inputPk.CK)
|
2024-03-21 07:38:05 +01:00
|
|
|
}
|
|
|
|
return sink.HandleInput(inputPk)
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) AddRunningCmd(rct *RunCmdType) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
wsh.RunningCmds[rct.RunPacket.CK] = rct
|
2022-07-06 01:54:49 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetRunningCmd(ck base.CommandKey) *RunCmdType {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
rtn := wsh.RunningCmds[ck]
|
2024-04-03 00:46:32 +02:00
|
|
|
return rtn
|
2022-09-27 08:23:04 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) RemoveRunningCmd(ck base.CommandKey) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
|
|
|
delete(wsh.RunningCmds, ck)
|
|
|
|
for key, pendingCk := range wsh.PendingStateCmds {
|
2022-10-28 07:00:10 +02:00
|
|
|
if pendingCk == ck {
|
2024-05-02 23:16:00 +02:00
|
|
|
delete(wsh.PendingStateCmds, key)
|
2022-10-28 07:00:10 +02:00
|
|
|
}
|
|
|
|
}
|
2022-07-08 07:13:45 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) PacketRpcIter(ctx context.Context, pk packet.RpcPacketType) (*packet.RpcResponseIter, error) {
|
|
|
|
if !wsh.IsConnected() {
|
2023-09-01 07:04:31 +02:00
|
|
|
return nil, fmt.Errorf("remote is not connected")
|
|
|
|
}
|
|
|
|
if pk == nil {
|
|
|
|
return nil, fmt.Errorf("PacketRpc passed nil packet")
|
|
|
|
}
|
|
|
|
reqId := pk.GetReqId()
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ServerProc.Output.RegisterRpcSz(reqId, RpcIterChannelSize)
|
|
|
|
err := wsh.ServerProc.Input.SendPacketCtx(ctx, pk)
|
2023-09-01 07:04:31 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
return wsh.ServerProc.Output.GetResponseIter(reqId), nil
|
2023-09-01 07:04:31 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) PacketRpcRaw(ctx context.Context, pk packet.RpcPacketType) (packet.RpcResponsePacketType, error) {
|
|
|
|
if !wsh.IsConnected() {
|
2023-09-01 07:04:31 +02:00
|
|
|
return nil, fmt.Errorf("remote is not connected")
|
2022-07-02 02:38:36 +02:00
|
|
|
}
|
2022-07-01 21:17:19 +02:00
|
|
|
if pk == nil {
|
|
|
|
return nil, fmt.Errorf("PacketRpc passed nil packet")
|
|
|
|
}
|
2022-07-07 04:01:00 +02:00
|
|
|
reqId := pk.GetReqId()
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ServerProc.Output.RegisterRpc(reqId)
|
|
|
|
defer wsh.ServerProc.Output.UnRegisterRpc(reqId)
|
|
|
|
err := wsh.ServerProc.Input.SendPacketCtx(ctx, pk)
|
2022-07-07 04:01:00 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
rtnPk := wsh.ServerProc.Output.WaitForResponse(ctx, reqId)
|
2022-07-07 04:01:00 +02:00
|
|
|
if rtnPk == nil {
|
|
|
|
return nil, ctx.Err()
|
2022-07-01 21:17:19 +02:00
|
|
|
}
|
2022-10-28 02:10:36 +02:00
|
|
|
return rtnPk, nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) PacketRpc(ctx context.Context, pk packet.RpcPacketType) (*packet.ResponsePacketType, error) {
|
|
|
|
rtnPk, err := wsh.PacketRpcRaw(ctx, pk)
|
2022-10-28 02:10:36 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2022-07-07 04:01:00 +02:00
|
|
|
if respPk, ok := rtnPk.(*packet.ResponsePacketType); ok {
|
|
|
|
return respPk, nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("invalid response packet received: %s", packet.AsString(rtnPk))
|
2022-07-01 21:17:19 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) WithLock(fn func()) {
|
|
|
|
wsh.Lock.Lock()
|
|
|
|
defer wsh.Lock.Unlock()
|
2022-07-02 02:38:36 +02:00
|
|
|
fn()
|
|
|
|
}
|
|
|
|
|
2022-07-07 07:46:22 +02:00
|
|
|
func makeDataAckPacket(ck base.CommandKey, fdNum int, ackLen int, err error) *packet.DataAckPacketType {
|
|
|
|
ack := packet.MakeDataAckPacket()
|
|
|
|
ack.CK = ck
|
|
|
|
ack.FdNum = fdNum
|
|
|
|
ack.AckLen = ackLen
|
|
|
|
if err != nil {
|
|
|
|
ack.Error = err.Error()
|
|
|
|
}
|
|
|
|
return ack
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) notifyHangups_nolock() {
|
|
|
|
for ck := range wsh.RunningCmds {
|
2023-03-21 03:20:57 +01:00
|
|
|
cmd, err := sstore.GetCmdByScreenId(context.Background(), ck.GetGroupId(), ck.GetCmdId())
|
2022-09-05 23:49:23 +02:00
|
|
|
if err != nil {
|
|
|
|
continue
|
|
|
|
}
|
2024-02-16 01:45:47 +01:00
|
|
|
update := scbus.MakeUpdatePacket()
|
|
|
|
update.AddUpdate(*cmd)
|
|
|
|
scbus.MainUpdateBus.DoScreenUpdate(ck.GetGroupId(), update)
|
2024-01-28 22:47:36 +01:00
|
|
|
go pushNumRunningCmdsUpdate(&ck, -1)
|
2022-09-05 23:49:23 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.RunningCmds = make(map[base.CommandKey]*RunCmdType)
|
|
|
|
wsh.PendingStateCmds = make(map[pendingStateKey]base.CommandKey)
|
2022-09-05 23:49:23 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) resolveFinalState(ctx context.Context, origState *packet.ShellState, origStatePtr *packet.ShellStatePtr, donePk *packet.CmdDonePacketType) (*packet.ShellState, error) {
|
2022-11-02 05:42:56 +01:00
|
|
|
if donePk.FinalState != nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
if origStatePtr == nil {
|
|
|
|
return nil, fmt.Errorf("command must have a stateptr to resolve final state")
|
|
|
|
}
|
2024-03-14 02:52:41 +01:00
|
|
|
finalState := stripScVarsFromState(donePk.FinalState)
|
2024-03-29 00:56:39 +01:00
|
|
|
return finalState, nil
|
2022-11-02 05:42:56 +01:00
|
|
|
}
|
2022-11-29 03:03:02 +01:00
|
|
|
if donePk.FinalStateDiff != nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
if donePk.FinalStateBasePtr == nil {
|
|
|
|
return nil, fmt.Errorf("invalid rtnstate, has diff but no baseptr")
|
|
|
|
}
|
2024-03-14 02:52:41 +01:00
|
|
|
stateDiff := stripScVarsFromStateDiff(donePk.FinalStateDiff)
|
2024-03-29 00:56:39 +01:00
|
|
|
if origStatePtr == donePk.FinalStateBasePtr {
|
|
|
|
// this is the normal case. the stateptr from the run-packet should match the baseptr from the done-packet
|
|
|
|
// this is also the most efficient, because we don't need to fetch the original state
|
|
|
|
sapi, err := shellapi.MakeShellApi(origState.GetShellType())
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot make shellapi from initial state: %w", err)
|
|
|
|
}
|
|
|
|
fullState, err := sapi.ApplyShellStateDiff(origState, stateDiff)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot apply shell state diff: %w", err)
|
|
|
|
}
|
|
|
|
return fullState, nil
|
|
|
|
}
|
|
|
|
// this is strange (why is backend returning non-original stateptr?)
|
|
|
|
// but here, we fetch the stateptr, and then apply the diff against that
|
|
|
|
realOrigState, err := sstore.GetFullState(ctx, *donePk.FinalStateBasePtr)
|
2024-03-14 02:52:41 +01:00
|
|
|
if err != nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
return nil, fmt.Errorf("cannot get original state for diff: %w", err)
|
2024-03-14 02:52:41 +01:00
|
|
|
}
|
2024-03-29 00:56:39 +01:00
|
|
|
if realOrigState == nil {
|
|
|
|
return nil, fmt.Errorf("cannot get original state for diff: not found")
|
2024-03-14 02:52:41 +01:00
|
|
|
}
|
2024-03-29 00:56:39 +01:00
|
|
|
sapi, err := shellapi.MakeShellApi(realOrigState.GetShellType())
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot make shellapi from original state: %w", err)
|
|
|
|
}
|
|
|
|
fullState, err := sapi.ApplyShellStateDiff(realOrigState, stateDiff)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("cannot apply shell state diff: %w", err)
|
|
|
|
}
|
|
|
|
return fullState, nil
|
|
|
|
}
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// after this limit we'll switch to persisting the full state
|
|
|
|
const NewStateDiffSizeThreshold = 30 * 1024
|
|
|
|
|
|
|
|
// will update the remote instance with the final state
|
|
|
|
// this is complicated because we want to be as efficient as possible.
|
|
|
|
// so we pull the current remote-instance state (just the baseptr). then we compute the diff.
|
|
|
|
// then we check the size of the diff, and only persist the diff it is under some size threshold
|
|
|
|
// also we check to see if the diff succeeds (it can fail if the shell or version changed).
|
|
|
|
// in those cases we also update the RI with the full state
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) updateRIWithFinalState(ctx context.Context, rct *RunCmdType, newState *packet.ShellState) (*sstore.RemoteInstance, error) {
|
2024-03-29 00:56:39 +01:00
|
|
|
curRIState, err := sstore.GetRemoteStatePtr(ctx, rct.SessionId, rct.ScreenId, rct.RemotePtr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error trying to get current screen stateptr: %w", err)
|
|
|
|
}
|
|
|
|
feState := sstore.FeStateFromShellState(newState)
|
|
|
|
if curRIState == nil {
|
|
|
|
// no current state, so just persist the full state
|
|
|
|
return sstore.UpdateRemoteState(ctx, rct.SessionId, rct.ScreenId, rct.RemotePtr, feState, newState, nil)
|
|
|
|
}
|
|
|
|
// pull the base (not the diff) state from the RI (right now we don't want to make multi-level diffs)
|
|
|
|
riBaseState, err := sstore.GetStateBase(ctx, curRIState.BaseHash)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error trying to get statebase: %w", err)
|
|
|
|
}
|
|
|
|
sapi, err := shellapi.MakeShellApi(riBaseState.GetShellType())
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("error trying to make shellapi: %w", err)
|
2022-11-29 03:03:02 +01:00
|
|
|
}
|
2024-03-29 00:56:39 +01:00
|
|
|
newStateDiff, err := sapi.MakeShellStateDiff(riBaseState, curRIState.BaseHash, newState)
|
|
|
|
if err != nil {
|
|
|
|
// if we can't make a diff, just persist the full state (this could happen if the shell type changes)
|
|
|
|
return sstore.UpdateRemoteState(ctx, rct.SessionId, rct.ScreenId, rct.RemotePtr, feState, newState, nil)
|
|
|
|
}
|
|
|
|
// we have a diff, let's check the diff size first
|
|
|
|
_, encodedDiff := newStateDiff.EncodeAndHash()
|
|
|
|
if len(encodedDiff) > NewStateDiffSizeThreshold {
|
|
|
|
// diff is too large, persist the full state
|
|
|
|
return sstore.UpdateRemoteState(ctx, rct.SessionId, rct.ScreenId, rct.RemotePtr, feState, newState, nil)
|
|
|
|
}
|
|
|
|
// diff is small enough, persist the diff
|
|
|
|
return sstore.UpdateRemoteState(ctx, rct.SessionId, rct.ScreenId, rct.RemotePtr, feState, nil, newStateDiff)
|
2024-03-14 02:52:41 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) handleSudoError(ck base.CommandKey, sudoErr error) {
|
2024-04-17 01:58:17 +02:00
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancelFn()
|
|
|
|
screenId, lineId := ck.Split()
|
|
|
|
|
|
|
|
update := scbus.MakeUpdatePacket()
|
|
|
|
errOutputStr := fmt.Sprintf("%serror: %v%s\n", utilfn.AnsiRedColor(), sudoErr, utilfn.AnsiResetColor())
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToCmdPtyOut(ctx, screenId, lineId, []byte(errOutputStr))
|
2024-04-17 01:58:17 +02:00
|
|
|
doneInfo := sstore.CmdDoneDataValues{
|
|
|
|
Ts: time.Now().UnixMilli(),
|
|
|
|
ExitCode: 1,
|
|
|
|
DurationMs: 0,
|
|
|
|
}
|
|
|
|
err := sstore.UpdateCmdDoneInfo(ctx, update, ck, doneInfo, sstore.CmdStatusError)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error updating cmddone info (in handleSudoError): %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
screen, err := sstore.UpdateScreenFocusForDoneCmd(ctx, screenId, lineId)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error trying to update screen focus type (in handleSudoError): %v\n", err)
|
|
|
|
// fall-through (nothing to do)
|
|
|
|
}
|
|
|
|
if screen != nil {
|
|
|
|
update.AddUpdate(*screen)
|
|
|
|
}
|
|
|
|
scbus.MainUpdateBus.DoUpdate(update)
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) handleCmdStartError(rct *RunCmdType, startErr error) {
|
2024-04-05 00:08:45 +02:00
|
|
|
if rct == nil {
|
|
|
|
log.Printf("handleCmdStartError, no rct\n")
|
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
defer wsh.RemoveRunningCmd(rct.CK)
|
2024-04-05 00:08:45 +02:00
|
|
|
if rct.EphemeralOpts != nil {
|
|
|
|
// nothing to do for ephemeral commands besides remove the running command
|
2024-04-30 03:29:27 +02:00
|
|
|
log.Printf("ephemeral command start error: %v\n", startErr)
|
2024-04-05 00:08:45 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancelFn()
|
|
|
|
update := scbus.MakeUpdatePacket()
|
|
|
|
errOutputStr := fmt.Sprintf("%serror: %v%s\n", utilfn.AnsiRedColor(), startErr, utilfn.AnsiResetColor())
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToCmdPtyOut(ctx, rct.ScreenId, rct.CK.GetCmdId(), []byte(errOutputStr))
|
2024-04-05 00:08:45 +02:00
|
|
|
doneInfo := sstore.CmdDoneDataValues{
|
|
|
|
Ts: time.Now().UnixMilli(),
|
|
|
|
ExitCode: 1,
|
|
|
|
DurationMs: 0,
|
|
|
|
}
|
|
|
|
err := sstore.UpdateCmdDoneInfo(ctx, update, rct.CK, doneInfo, sstore.CmdStatusError)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error updating cmddone info (in handleCmdStartError): %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
screen, err := sstore.UpdateScreenFocusForDoneCmd(ctx, rct.CK.GetGroupId(), rct.CK.GetCmdId())
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error trying to update screen focus type (in handleCmdDonePacket): %v\n", err)
|
|
|
|
// fall-through (nothing to do)
|
|
|
|
}
|
|
|
|
if screen != nil {
|
|
|
|
update.AddUpdate(*screen)
|
|
|
|
}
|
|
|
|
scbus.MainUpdateBus.DoUpdate(update)
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) handleCmdDonePacket(rct *RunCmdType, donePk *packet.CmdDonePacketType) {
|
2024-03-14 02:52:41 +01:00
|
|
|
if rct == nil {
|
|
|
|
log.Printf("cmddone packet received, but no running command found for it %q\n", donePk.CK)
|
2022-07-08 01:29:14 +02:00
|
|
|
return
|
|
|
|
}
|
2024-03-14 02:52:41 +01:00
|
|
|
// this will remove from RunningCmds and from PendingStateCmds
|
2024-05-02 23:16:00 +02:00
|
|
|
defer wsh.RemoveRunningCmd(donePk.CK)
|
2024-04-03 00:46:32 +02:00
|
|
|
if rct.EphemeralOpts != nil && rct.EphemeralOpts.Canceled.Load() {
|
|
|
|
log.Printf("cmddone %s (ephemeral canceled)\n", donePk.CK)
|
2024-03-14 02:52:41 +01:00
|
|
|
// do nothing when an ephemeral command is canceled
|
|
|
|
return
|
2022-10-12 08:11:43 +02:00
|
|
|
}
|
2024-03-14 02:52:41 +01:00
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 5*time.Second)
|
|
|
|
defer cancelFn()
|
|
|
|
update := scbus.MakeUpdatePacket()
|
2024-04-03 00:46:32 +02:00
|
|
|
if rct.EphemeralOpts == nil {
|
2024-03-14 02:52:41 +01:00
|
|
|
// only update DB for non-ephemeral commands
|
2024-04-05 00:08:45 +02:00
|
|
|
cmdDoneInfo := sstore.CmdDoneDataValues{
|
|
|
|
Ts: donePk.Ts,
|
|
|
|
ExitCode: donePk.ExitCode,
|
|
|
|
DurationMs: donePk.DurationMs,
|
|
|
|
}
|
|
|
|
err := sstore.UpdateCmdDoneInfo(ctx, update, donePk.CK, cmdDoneInfo, sstore.CmdStatusDone)
|
2024-03-14 02:52:41 +01:00
|
|
|
if err != nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
log.Printf("error updating cmddone info (in handleCmdDonePacket): %v\n", err)
|
2024-03-14 02:52:41 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
screen, err := sstore.UpdateScreenFocusForDoneCmd(ctx, donePk.CK.GetGroupId(), donePk.CK.GetCmdId())
|
|
|
|
if err != nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
log.Printf("error trying to update screen focus type (in handleCmdDonePacket): %v\n", err)
|
2024-03-14 02:52:41 +01:00
|
|
|
// fall-through (nothing to do)
|
|
|
|
}
|
|
|
|
if screen != nil {
|
|
|
|
update.AddUpdate(*screen)
|
|
|
|
}
|
2023-03-25 02:35:29 +01:00
|
|
|
}
|
2024-04-03 00:46:32 +02:00
|
|
|
|
|
|
|
// Close the ephemeral response writer if it exists
|
|
|
|
if rct.EphemeralOpts != nil && rct.EphemeralOpts.ExpectsResponse {
|
2024-04-30 03:29:27 +02:00
|
|
|
if donePk.ExitCode != 0 {
|
|
|
|
// if the command failed, we need to write the error to the response writer
|
|
|
|
log.Printf("writing error to ephemeral response writer\n")
|
|
|
|
rct.EphemeralOpts.StderrWriter.Write([]byte(fmt.Sprintf("error: %d\n", donePk.ExitCode)))
|
|
|
|
}
|
2024-04-03 00:46:32 +02:00
|
|
|
log.Printf("closing ephemeral response writers\n")
|
|
|
|
defer rct.EphemeralOpts.StdoutWriter.Close()
|
|
|
|
defer rct.EphemeralOpts.StderrWriter.Close()
|
|
|
|
}
|
|
|
|
|
2024-03-14 02:52:41 +01:00
|
|
|
// ephemeral commands *do* update the remote state
|
2024-03-29 00:56:39 +01:00
|
|
|
// not all commands get a final state (only RtnState commands have this returned)
|
|
|
|
// so in those cases finalState will be nil
|
2024-05-02 23:16:00 +02:00
|
|
|
finalState, err := wsh.resolveFinalState(ctx, rct.RunPacket.State, rct.RunPacket.StatePtr, donePk)
|
2024-03-29 00:56:39 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("error resolving final state for cmd: %v\n", err)
|
|
|
|
// fallthrough
|
|
|
|
}
|
|
|
|
if finalState != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
newRI, err := wsh.updateRIWithFinalState(ctx, rct, finalState)
|
2022-11-28 09:13:00 +01:00
|
|
|
if err != nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
log.Printf("error updating RI with final state (in handleCmdDonePacket): %v\n", err)
|
|
|
|
// fallthrough
|
2022-11-28 09:13:00 +01:00
|
|
|
}
|
2024-03-29 00:56:39 +01:00
|
|
|
if newRI != nil {
|
|
|
|
update.AddUpdate(sstore.MakeSessionUpdateForRemote(rct.SessionId, newRI))
|
2022-11-28 09:13:00 +01:00
|
|
|
}
|
2024-03-14 02:52:41 +01:00
|
|
|
// ephemeral commands *do not* update cmd state (there is no command)
|
2024-04-03 00:46:32 +02:00
|
|
|
if newRI != nil && rct.EphemeralOpts == nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
newRIStatePtr := packet.ShellStatePtr{BaseHash: newRI.StateBaseHash, DiffHashArr: newRI.StateDiffHashArr}
|
|
|
|
err = sstore.UpdateCmdRtnState(ctx, donePk.CK, newRIStatePtr)
|
2022-10-28 07:22:17 +02:00
|
|
|
if err != nil {
|
2024-03-29 00:56:39 +01:00
|
|
|
log.Printf("error trying to update cmd rtnstate: %v\n", err)
|
2022-10-28 07:22:17 +02:00
|
|
|
// fall-through (nothing to do)
|
|
|
|
}
|
|
|
|
}
|
2022-07-08 07:13:45 +02:00
|
|
|
}
|
2024-02-16 01:45:47 +01:00
|
|
|
scbus.MainUpdateBus.DoUpdate(update)
|
2022-07-08 01:29:14 +02:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) handleCmdFinalPacket(rct *RunCmdType, finalPk *packet.CmdFinalPacketType) {
|
2024-03-14 02:52:41 +01:00
|
|
|
if rct == nil {
|
|
|
|
// this is somewhat expected, since cmddone should have removed the running command
|
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
defer wsh.RemoveRunningCmd(finalPk.CK)
|
2023-03-21 03:20:57 +01:00
|
|
|
rtnCmd, err := sstore.GetCmdByScreenId(context.Background(), finalPk.CK.GetGroupId(), finalPk.CK.GetCmdId())
|
2022-11-27 23:12:15 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("error calling GetCmdById in handleCmdFinalPacket: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
2023-07-31 02:16:43 +02:00
|
|
|
if rtnCmd == nil || rtnCmd.DoneTs > 0 {
|
2022-11-27 23:12:15 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
log.Printf("finalpk %s (hangup): %s\n", finalPk.CK, finalPk.Error)
|
2023-04-13 21:53:15 +02:00
|
|
|
screen, err := sstore.HangupCmd(context.Background(), finalPk.CK)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error in hangup-cmd in handleCmdFinalPacket: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
2023-03-21 03:20:57 +01:00
|
|
|
rtnCmd, err = sstore.GetCmdByScreenId(context.Background(), finalPk.CK.GetGroupId(), finalPk.CK.GetCmdId())
|
2022-11-27 23:12:15 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("error getting cmd(2) in handleCmdFinalPacket: %v\n", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if rtnCmd == nil {
|
|
|
|
log.Printf("error getting cmd(2) in handleCmdFinalPacket (not found)\n")
|
|
|
|
return
|
|
|
|
}
|
2024-02-16 01:45:47 +01:00
|
|
|
update := scbus.MakeUpdatePacket()
|
|
|
|
update.AddUpdate(*rtnCmd)
|
2023-04-13 21:53:15 +02:00
|
|
|
if screen != nil {
|
2024-02-16 01:45:47 +01:00
|
|
|
update.AddUpdate(*screen)
|
2023-04-13 21:53:15 +02:00
|
|
|
}
|
2024-01-28 22:47:36 +01:00
|
|
|
go pushNumRunningCmdsUpdate(&finalPk.CK, -1)
|
2024-02-16 01:45:47 +01:00
|
|
|
scbus.MainUpdateBus.DoUpdate(update)
|
2022-11-27 23:12:15 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) ResetDataPos(ck base.CommandKey) {
|
|
|
|
wsh.DataPosMap.Delete(ck)
|
2024-01-27 01:25:21 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) writeToCmdPtyOut(ctx context.Context, screenId string, lineId string, data []byte) error {
|
|
|
|
dataPos := wsh.DataPosMap.Get(base.MakeCommandKey(screenId, lineId))
|
2024-04-05 00:08:45 +02:00
|
|
|
update, err := sstore.AppendToCmdPtyBlob(ctx, screenId, lineId, data, dataPos)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
utilfn.IncSyncMap(wsh.DataPosMap, base.MakeCommandKey(screenId, lineId), int64(len(data)))
|
2024-04-05 00:08:45 +02:00
|
|
|
if update != nil {
|
|
|
|
scbus.MainUpdateBus.DoScreenUpdate(screenId, update)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) handleDataPacket(rct *RunCmdType, dataPk *packet.DataPacketType, dataPosMap *utilfn.SyncMap[base.CommandKey, int64]) {
|
2024-03-14 02:52:41 +01:00
|
|
|
if rct == nil {
|
2024-04-03 00:46:32 +02:00
|
|
|
log.Printf("error handling data packet: no running cmd found %s\n", dataPk.CK)
|
2024-03-14 02:52:41 +01:00
|
|
|
ack := makeDataAckPacket(dataPk.CK, dataPk.FdNum, 0, fmt.Errorf("no running cmd found"))
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ServerProc.Input.SendPacket(ack)
|
2024-03-14 02:52:41 +01:00
|
|
|
return
|
|
|
|
}
|
2022-09-05 23:49:23 +02:00
|
|
|
realData, err := base64.StdEncoding.DecodeString(dataPk.Data64)
|
|
|
|
if err != nil {
|
2024-04-03 00:46:32 +02:00
|
|
|
log.Printf("error decoding data packet: %v\n", err)
|
2022-09-05 23:49:23 +02:00
|
|
|
ack := makeDataAckPacket(dataPk.CK, dataPk.FdNum, 0, err)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ServerProc.Input.SendPacket(ack)
|
2022-09-05 23:49:23 +02:00
|
|
|
return
|
|
|
|
}
|
2024-04-03 00:46:32 +02:00
|
|
|
if rct.EphemeralOpts != nil {
|
|
|
|
// Write to the response writer if it's set
|
|
|
|
if len(realData) > 0 && rct.EphemeralOpts.ExpectsResponse {
|
|
|
|
switch dataPk.FdNum {
|
|
|
|
case 1:
|
|
|
|
_, err := rct.EphemeralOpts.StdoutWriter.Write(realData)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("*error writing to ephemeral stdout writer: %v\n", err)
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
_, err := rct.EphemeralOpts.StderrWriter.Write(realData)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("*error writing to ephemeral stderr writer: %v\n", err)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
log.Printf("error handling data packet: invalid fdnum %d\n", dataPk.FdNum)
|
|
|
|
}
|
|
|
|
}
|
2024-04-30 03:29:27 +02:00
|
|
|
if dataPk.Error != "" {
|
|
|
|
log.Printf("ephemeral data packet error: %s\n", dataPk.Error)
|
|
|
|
}
|
2024-03-14 02:52:41 +01:00
|
|
|
ack := makeDataAckPacket(dataPk.CK, dataPk.FdNum, len(realData), nil)
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ServerProc.Input.SendPacket(ack)
|
2024-03-14 02:52:41 +01:00
|
|
|
return
|
|
|
|
}
|
2024-04-03 00:46:32 +02:00
|
|
|
|
2022-09-05 23:49:23 +02:00
|
|
|
var ack *packet.DataAckPacketType
|
|
|
|
if len(realData) > 0 {
|
2024-01-27 01:25:21 +01:00
|
|
|
dataPos := dataPosMap.Get(dataPk.CK)
|
2024-03-14 02:52:41 +01:00
|
|
|
update, err := sstore.AppendToCmdPtyBlob(context.Background(), rct.ScreenId, dataPk.CK.GetCmdId(), realData, dataPos)
|
2022-08-20 02:14:53 +02:00
|
|
|
if err != nil {
|
2022-09-05 23:49:23 +02:00
|
|
|
ack = makeDataAckPacket(dataPk.CK, dataPk.FdNum, 0, err)
|
|
|
|
} else {
|
|
|
|
ack = makeDataAckPacket(dataPk.CK, dataPk.FdNum, len(realData), nil)
|
|
|
|
}
|
2024-01-27 01:25:21 +01:00
|
|
|
utilfn.IncSyncMap(dataPosMap, dataPk.CK, int64(len(realData)))
|
2022-09-05 23:49:23 +02:00
|
|
|
if update != nil {
|
2024-02-16 01:45:47 +01:00
|
|
|
scbus.MainUpdateBus.DoScreenUpdate(dataPk.CK.GetGroupId(), update)
|
2022-07-08 07:13:45 +02:00
|
|
|
}
|
|
|
|
}
|
2022-09-05 23:49:23 +02:00
|
|
|
if ack != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.ServerProc.Input.SendPacket(ack)
|
2022-09-05 23:49:23 +02:00
|
|
|
}
|
2022-11-27 23:12:15 +01:00
|
|
|
}
|
|
|
|
|
2023-04-13 21:53:15 +02:00
|
|
|
func sendScreenUpdates(screens []*sstore.ScreenType) {
|
|
|
|
for _, screen := range screens {
|
2024-02-16 01:45:47 +01:00
|
|
|
update := scbus.MakeUpdatePacket()
|
|
|
|
update.AddUpdate(*screen)
|
|
|
|
scbus.MainUpdateBus.DoUpdate(update)
|
2023-04-13 21:53:15 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) startSudoPwClearChecker(clientData *sstore.ClientData) {
|
2024-04-26 03:19:43 +02:00
|
|
|
ctx, cancelFn := context.WithCancel(context.Background())
|
|
|
|
defer cancelFn()
|
|
|
|
sudoPwStore := clientData.FeOpts.SudoPwStore
|
2024-04-17 01:58:17 +02:00
|
|
|
for {
|
2024-04-26 03:19:43 +02:00
|
|
|
clientData, err := sstore.EnsureClientData(ctx)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("*error: cannot obtain client data in sudo pw loop. using fallback: %v", err)
|
|
|
|
} else {
|
|
|
|
sudoPwStore = clientData.FeOpts.SudoPwStore
|
|
|
|
}
|
|
|
|
|
2024-04-17 01:58:17 +02:00
|
|
|
shouldExit := false
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.sudoClearDeadline > 0 && time.Now().Unix() > wsh.sudoClearDeadline && sudoPwStore != "notimeout" {
|
|
|
|
wsh.sudoPw = nil
|
|
|
|
wsh.sudoClearDeadline = 0
|
2024-04-17 01:58:17 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
if wsh.sudoClearDeadline == 0 {
|
2024-04-17 01:58:17 +02:00
|
|
|
shouldExit = true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
if shouldExit {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
time.Sleep(time.Second * 2)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) sendSudoPassword(sudoPk *packet.SudoRequestPacketType) error {
|
2024-04-17 01:58:17 +02:00
|
|
|
var storedPw []byte
|
|
|
|
var rawSecret []byte
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
storedPw = wsh.sudoPw
|
2024-04-17 01:58:17 +02:00
|
|
|
})
|
|
|
|
if storedPw != nil && sudoPk.SudoStatus == "first-attempt" {
|
|
|
|
rawSecret = storedPw
|
|
|
|
} else {
|
|
|
|
request := &userinput.UserInputRequestType{
|
|
|
|
QueryText: "Please enter your password",
|
|
|
|
ResponseType: "text",
|
|
|
|
Title: "Sudo Password",
|
|
|
|
Markdown: false,
|
|
|
|
}
|
|
|
|
ctx, cancelFn := context.WithTimeout(context.Background(), 60*time.Second)
|
|
|
|
defer cancelFn()
|
|
|
|
guiResponse, err := userinput.GetUserInput(ctx, scbus.MainRpcBus, request)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rawSecret = []byte(guiResponse.Text)
|
|
|
|
}
|
2024-04-26 03:19:43 +02:00
|
|
|
|
|
|
|
ctx, cancelFn := context.WithCancel(context.Background())
|
|
|
|
defer cancelFn()
|
|
|
|
clientData, err := sstore.EnsureClientData(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("*error: cannot obtain client data: %v", err)
|
|
|
|
}
|
|
|
|
sudoPwTimeout := clientData.FeOpts.SudoPwTimeoutMs / 1000 / 60
|
|
|
|
if sudoPwTimeout == 0 {
|
|
|
|
// 0 maps to default
|
|
|
|
sudoPwTimeout = sstore.DefaultSudoTimeout
|
|
|
|
}
|
|
|
|
pwTimeoutDur := time.Duration(sudoPwTimeout) * time.Minute
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.sudoPw = rawSecret
|
|
|
|
if wsh.sudoClearDeadline == 0 {
|
|
|
|
go wsh.startSudoPwClearChecker(clientData)
|
2024-04-17 01:58:17 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.sudoClearDeadline = time.Now().Add(pwTimeoutDur).Unix()
|
2024-04-17 01:58:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
srvPrivKey, err := ecdh.P256().GenerateKey(rand.Reader)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("generate ecdh: %e", err)
|
|
|
|
}
|
|
|
|
encryptor, err := waveenc.MakeEncryptorEcdh(srvPrivKey, sudoPk.ShellPubKey)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
encryptedSecret, err := encryptor.EncryptData(rawSecret, "sudopw")
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("encrypt secret: %e", err)
|
|
|
|
}
|
|
|
|
srvPubKey, err := x509.MarshalPKIXPublicKey(srvPrivKey.PublicKey())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("marshal pub key: %e", err)
|
|
|
|
}
|
|
|
|
sudoResponse := packet.MakeSudoResponsePacket(sudoPk.CK, encryptedSecret, srvPubKey)
|
|
|
|
select {
|
2024-05-02 23:16:00 +02:00
|
|
|
case wsh.ServerProc.Input.SendCh <- sudoResponse:
|
2024-04-17 01:58:17 +02:00
|
|
|
default:
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) processSinglePacket(pk packet.PacketType) {
|
2024-03-14 02:52:41 +01:00
|
|
|
if _, ok := pk.(*packet.DataAckPacketType); ok {
|
|
|
|
// TODO process ack (need to keep track of buffer size for sending)
|
|
|
|
// this is low priority though since most input is coming from keyboard and won't overflow this buffer
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if dataPk, ok := pk.(*packet.DataPacketType); ok {
|
|
|
|
runCmdUpdateFn(dataPk.CK, func() {
|
2024-05-02 23:16:00 +02:00
|
|
|
rct := wsh.GetRunningCmd(dataPk.CK)
|
|
|
|
wsh.handleDataPacket(rct, dataPk, wsh.DataPosMap)
|
2024-03-14 02:52:41 +01:00
|
|
|
})
|
|
|
|
go pushStatusIndicatorUpdate(&dataPk.CK, sstore.StatusIndicatorLevel_Output)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if donePk, ok := pk.(*packet.CmdDonePacketType); ok {
|
|
|
|
runCmdUpdateFn(donePk.CK, func() {
|
2024-05-02 23:16:00 +02:00
|
|
|
rct := wsh.GetRunningCmd(donePk.CK)
|
|
|
|
wsh.handleCmdDonePacket(rct, donePk)
|
2024-03-14 02:52:41 +01:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if finalPk, ok := pk.(*packet.CmdFinalPacketType); ok {
|
|
|
|
runCmdUpdateFn(finalPk.CK, func() {
|
2024-05-02 23:16:00 +02:00
|
|
|
rct := wsh.GetRunningCmd(finalPk.CK)
|
|
|
|
wsh.handleCmdFinalPacket(rct, finalPk)
|
2024-03-14 02:52:41 +01:00
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
2024-04-17 01:58:17 +02:00
|
|
|
if sudoPk, ok := pk.(*packet.SudoRequestPacketType); ok {
|
|
|
|
// final failure case -- clear cache
|
|
|
|
if sudoPk.SudoStatus == "failure" {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.sudoPw = nil
|
|
|
|
wsh.handleSudoError(sudoPk.CK, fmt.Errorf("sudo: incorrect password entered"))
|
2024-04-17 01:58:17 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// handle waveshell errors here
|
|
|
|
if sudoPk.SudoStatus == "error" {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.handleSudoError(sudoPk.CK, fmt.Errorf("sudo: shell: %s", sudoPk.ErrStr))
|
2024-04-17 01:58:17 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
err := wsh.sendSudoPassword(sudoPk)
|
2024-04-17 01:58:17 +02:00
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.handleSudoError(sudoPk.CK, fmt.Errorf("sudo: srv: %s", err))
|
2024-04-17 01:58:17 +02:00
|
|
|
}
|
|
|
|
}
|
2024-03-14 02:52:41 +01:00
|
|
|
if msgPk, ok := pk.(*packet.MessagePacketType); ok {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("msg> [remote %s] [%s] %s\n", wsh.GetRemoteName(), msgPk.CK, msgPk.Message)
|
2024-03-14 02:52:41 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if rawPk, ok := pk.(*packet.RawPacketType); ok {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("stderr> [remote %s] %s\n", wsh.GetRemoteName(), rawPk.Data)
|
2024-03-14 02:52:41 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WriteToPtyBuffer("*[remote %s] unhandled packet %s\n", wsh.GetRemoteName(), packet.AsString(pk))
|
2024-03-14 02:52:41 +01:00
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) ClearCachedSudoPw() {
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
wsh.sudoPw = nil
|
|
|
|
wsh.sudoClearDeadline = 0
|
2024-04-17 01:58:17 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) ChangeSudoTimeout(deltaTime int64) {
|
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.sudoClearDeadline != 0 {
|
|
|
|
updated := wsh.sudoClearDeadline + deltaTime*60
|
|
|
|
wsh.sudoClearDeadline = max(0, updated)
|
2024-04-26 03:19:43 +02:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) ProcessPackets() {
|
|
|
|
defer wsh.WithLock(func() {
|
|
|
|
if wsh.Status == StatusConnected {
|
|
|
|
wsh.Status = StatusDisconnected
|
2022-07-02 02:38:36 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
screens, err := sstore.HangupRunningCmdsByRemoteId(context.Background(), wsh.Remote.RemoteId)
|
2022-07-08 01:29:14 +02:00
|
|
|
if err != nil {
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.writeToPtyBuffer_nolock("error calling HUP on cmds %v\n", err)
|
2022-07-08 01:29:14 +02:00
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.notifyHangups_nolock()
|
|
|
|
go wsh.NotifyRemoteUpdate()
|
2023-04-13 21:53:15 +02:00
|
|
|
if len(screens) > 0 {
|
|
|
|
go sendScreenUpdates(screens)
|
|
|
|
}
|
2022-07-02 02:38:36 +02:00
|
|
|
})
|
2024-05-02 23:16:00 +02:00
|
|
|
for pk := range wsh.ServerProc.Output.MainCh {
|
|
|
|
wsh.processSinglePacket(pk)
|
2022-07-01 21:17:19 +02:00
|
|
|
}
|
|
|
|
}
|
2022-08-24 06:05:49 +02:00
|
|
|
|
2022-08-24 11:14:16 +02:00
|
|
|
// returns number of chars (including braces) for brace-expr
|
|
|
|
func getBracedStr(runeStr []rune) int {
|
|
|
|
if len(runeStr) < 3 {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
if runeStr[0] != '{' {
|
|
|
|
return 0
|
2022-08-24 06:05:49 +02:00
|
|
|
}
|
2022-08-24 11:14:16 +02:00
|
|
|
for i := 1; i < len(runeStr); i++ {
|
|
|
|
if runeStr[i] == '}' {
|
|
|
|
if i == 1 { // cannot have {}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return i + 1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
func isDigit(r rune) bool {
|
|
|
|
return r >= '0' && r <= '9' // just check ascii digits (not unicode)
|
|
|
|
}
|
|
|
|
|
2022-10-17 08:51:04 +02:00
|
|
|
func EvalPrompt(promptFmt string, vars map[string]string, state *packet.ShellState) string {
|
2022-08-24 11:14:16 +02:00
|
|
|
var buf bytes.Buffer
|
|
|
|
promptRunes := []rune(promptFmt)
|
|
|
|
for i := 0; i < len(promptRunes); i++ {
|
|
|
|
ch := promptRunes[i]
|
|
|
|
if ch == '\\' && i != len(promptRunes)-1 {
|
|
|
|
nextCh := promptRunes[i+1]
|
|
|
|
if nextCh == 'x' || nextCh == 'y' {
|
|
|
|
nr := getBracedStr(promptRunes[i+2:])
|
|
|
|
if nr > 0 {
|
|
|
|
escCode := string(promptRunes[i+1 : i+1+nr+1]) // start at "x" or "y", extend nr+1 runes
|
|
|
|
escStr := evalPromptEsc(escCode, vars, state)
|
|
|
|
buf.WriteString(escStr)
|
|
|
|
i += nr + 1
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
buf.WriteRune(ch) // invalid escape, so just write ch and move on
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else if isDigit(nextCh) {
|
|
|
|
if len(promptRunes) >= i+4 && isDigit(promptRunes[i+2]) && isDigit(promptRunes[i+3]) {
|
|
|
|
i += 3
|
|
|
|
escStr := evalPromptEsc(string(promptRunes[i+1:i+4]), vars, state)
|
|
|
|
buf.WriteString(escStr)
|
|
|
|
continue
|
|
|
|
} else {
|
|
|
|
buf.WriteRune(ch) // invalid escape, so just write ch and move on
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
i += 1
|
|
|
|
escStr := evalPromptEsc(string(nextCh), vars, state)
|
|
|
|
buf.WriteString(escStr)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
buf.WriteRune(ch)
|
|
|
|
}
|
|
|
|
return buf.String()
|
|
|
|
}
|
|
|
|
|
2022-10-17 08:51:04 +02:00
|
|
|
func evalPromptEsc(escCode string, vars map[string]string, state *packet.ShellState) string {
|
2022-08-24 06:05:49 +02:00
|
|
|
if strings.HasPrefix(escCode, "x{") && strings.HasSuffix(escCode, "}") {
|
|
|
|
varName := escCode[2 : len(escCode)-1]
|
|
|
|
return vars[varName]
|
|
|
|
}
|
|
|
|
if strings.HasPrefix(escCode, "y{") && strings.HasSuffix(escCode, "}") {
|
2022-08-24 11:14:16 +02:00
|
|
|
if state == nil {
|
|
|
|
return ""
|
|
|
|
}
|
2022-08-24 06:05:49 +02:00
|
|
|
varName := escCode[2 : len(escCode)-1]
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
varMap := shellenv.ShellVarMapFromState(state)
|
2022-08-24 06:05:49 +02:00
|
|
|
return varMap[varName]
|
|
|
|
}
|
|
|
|
if escCode == "h" {
|
|
|
|
return vars["remoteshorthost"]
|
|
|
|
}
|
|
|
|
if escCode == "H" {
|
|
|
|
return vars["remotehost"]
|
|
|
|
}
|
|
|
|
if escCode == "s" {
|
|
|
|
return "mshell"
|
|
|
|
}
|
|
|
|
if escCode == "u" {
|
|
|
|
return vars["remoteuser"]
|
|
|
|
}
|
|
|
|
if escCode == "w" {
|
2022-08-24 11:14:16 +02:00
|
|
|
if state == nil {
|
|
|
|
return "?"
|
|
|
|
}
|
|
|
|
return replaceHomePath(state.Cwd, vars["home"])
|
2022-08-24 06:05:49 +02:00
|
|
|
}
|
|
|
|
if escCode == "W" {
|
2022-08-24 11:14:16 +02:00
|
|
|
if state == nil {
|
|
|
|
return "?"
|
|
|
|
}
|
|
|
|
return path.Base(replaceHomePath(state.Cwd, vars["home"]))
|
2022-08-24 06:05:49 +02:00
|
|
|
}
|
|
|
|
if escCode == "$" {
|
2022-08-24 11:14:16 +02:00
|
|
|
if vars["remoteuser"] == "root" || vars["sudo"] == "1" {
|
2022-08-24 06:05:49 +02:00
|
|
|
return "#"
|
|
|
|
} else {
|
|
|
|
return "$"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if len(escCode) == 3 {
|
|
|
|
// \nnn escape
|
|
|
|
ival, err := strconv.ParseInt(escCode, 8, 32)
|
|
|
|
if err != nil {
|
|
|
|
return escCode
|
|
|
|
}
|
2023-12-27 22:11:53 +01:00
|
|
|
if ival >= 0 && ival <= 255 {
|
|
|
|
return string([]byte{byte(ival)})
|
|
|
|
} else {
|
|
|
|
// if it was out of range just return the string (invalid escape)
|
|
|
|
return escCode
|
|
|
|
}
|
2022-08-24 06:05:49 +02:00
|
|
|
}
|
|
|
|
if escCode == "e" {
|
|
|
|
return "\033"
|
|
|
|
}
|
|
|
|
if escCode == "n" {
|
|
|
|
return "\n"
|
|
|
|
}
|
|
|
|
if escCode == "r" {
|
|
|
|
return "\r"
|
|
|
|
}
|
|
|
|
if escCode == "a" {
|
|
|
|
return "\007"
|
|
|
|
}
|
|
|
|
if escCode == "\\" {
|
|
|
|
return "\\"
|
|
|
|
}
|
|
|
|
if escCode == "[" {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
if escCode == "]" {
|
|
|
|
return ""
|
|
|
|
}
|
2022-08-24 11:14:16 +02:00
|
|
|
|
|
|
|
// we don't support date/time escapes (d, t, T, @), version escapes (v, V), cmd number (#, !), terminal device (l), jobs (j)
|
2022-08-24 06:05:49 +02:00
|
|
|
return "(" + escCode + ")"
|
|
|
|
}
|
2022-11-28 09:13:00 +01:00
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) getFullState(shellType string, stateDiff *packet.ShellStateDiff) (*packet.ShellState, error) {
|
|
|
|
baseState := wsh.StateMap.GetStateByHash(shellType, stateDiff.BaseHash)
|
2022-11-28 09:13:00 +01:00
|
|
|
if baseState != nil && len(stateDiff.DiffHashArr) == 0 {
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
sapi, err := shellapi.MakeShellApi(baseState.GetShellType())
|
|
|
|
newState, err := sapi.ApplyShellStateDiff(baseState, stateDiff)
|
2022-11-28 09:13:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
return newState, nil
|
2022-11-28 09:13:00 +01:00
|
|
|
} else {
|
2024-03-29 00:56:39 +01:00
|
|
|
fullState, err := sstore.GetFullState(context.Background(), packet.ShellStatePtr{BaseHash: stateDiff.BaseHash, DiffHashArr: stateDiff.DiffHashArr})
|
2022-11-28 09:13:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
sapi, err := shellapi.MakeShellApi(fullState.GetShellType())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
newState, err := sapi.ApplyShellStateDiff(fullState, stateDiff)
|
|
|
|
return newState, nil
|
2022-11-28 09:13:00 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// internal func, first tries the StateMap, otherwise will fallback on sstore.GetFullState
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) getFeStateFromDiff(stateDiff *packet.ShellStateDiff) (map[string]string, error) {
|
|
|
|
baseState := wsh.StateMap.GetStateByHash(stateDiff.GetShellType(), stateDiff.BaseHash)
|
2022-11-28 09:13:00 +01:00
|
|
|
if baseState != nil && len(stateDiff.DiffHashArr) == 0 {
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
sapi, err := shellapi.MakeShellApi(baseState.GetShellType())
|
2022-11-28 09:13:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
newState, err := sapi.ApplyShellStateDiff(baseState, stateDiff)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return sstore.FeStateFromShellState(newState), nil
|
2022-11-28 09:13:00 +01:00
|
|
|
} else {
|
2024-03-29 00:56:39 +01:00
|
|
|
fullState, err := sstore.GetFullState(context.Background(), packet.ShellStatePtr{BaseHash: stateDiff.BaseHash, DiffHashArr: stateDiff.DiffHashArr})
|
2022-11-28 09:13:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
sapi, err := shellapi.MakeShellApi(fullState.GetShellType())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
newState, err := sapi.ApplyShellStateDiff(fullState, stateDiff)
|
2022-11-28 09:13:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
zsh support (#227)
adds zsh support to waveterm. big change, lots going on here. lots of other improvements and bug fixes added while debugging and building out the feature.
Commits:
* refactor shexec parser.go into new package shellenv. separate out bash specific parsing from generic functions
* checkpoint
* work on refactoring shexec. created two new packages shellapi (for bash/zsh specific stuff), and shellutil (shared between shellapi and shexec)
* more refactoring
* create shellapi interface to abstract bash specific functionality
* more refactoring, move bash shell state parsing to shellapi
* move makeRcFile to shellapi. remove all of the 'client' options CLI options from waveshell
* get shellType passed through to server/single paths for waveshell
* add a local shelltype detector
* mock out a zshapi
* move shelltype through more of the code
* get a command to run via zsh
* zsh can now switch directories. poc, needs cleanup
* working on ShellState encoding differences between zsh/bash. Working on parsing zsh decls. move utilfn package into waveshell (shouldn't have been in wavesrv)
* switch to use []byte for vardecl serialization + diffs
* progress on zsh environment. still have issues reconciling init environment with trap environment
* fix typeset argument parsing
* parse promptvars, more zsh specific ignores
* fix bug with promptvar not getting set (wrong check in FeState func)
* add sdk (issue #188) to list of rtnstate commands
* more zsh compatibility -- working with a larger ohmyzsh environment. ignore more variables, handle exit trap better. unique path/fpath. add a processtype variable to base.
* must return a value
* zsh alias parsing/restoring. diff changes (and rtnstate changes). introduces linediff v1.
* force zmodload of zsh/parameter
* starting work on zsh functions
* need a v1 of mapdiff as well (to handle null chars)
* pack/unpack of ints was wrong (one used int and one use uint). turned out we only ever encoded '0' so it worked. that also means it is safe to change unpack to unpackUInt
* reworking for binary encoding of aliases and functions (because of zsh allows any character, including nulls, in names and values)
* fixes, working on functions, issue with line endings
* zsh functions. lots of ugliness here around dealing with line dicipline and cooked stty. new runcommand function to grab output from a non-tty fd. note that we still to run the actual command in a stty to get the proper output.
* write uuid tempdir, cleanup with tmprcfilename code
* hack in some simple zsh function declaration finding code for rtnstate. create function diff for rtnstate that supports zsh
* make sure key order is constant so shell hashes are consistent
* fix problems with state diffs to support new zsh formats. add diff/apply code to shellapi (moved from shellenv), that is now specific to zsh or bash
* add log packet and new shellstate packets
* switch to shellstate map that's also keyed by shelltype
* add shelltype to remoteinstance
* remove shell argument from waveshell
* added new shelltype statemap to remote.go (msh), deal with fallout
* move shellstate out of init packet, and move to an explicit reinit call. try to initialize all of the active shell states
* change dont always store init state (only store on demand). initialize shell states on demand (if not already initialized). allow reset to change shells
* add shellpref field to remote table. use to drive the default shell choice for new tabs
* show shelltag on cmdinput, pass through ri and remote (defaultshellstate)
* bump mshell version to v0.4
* better version validation for shellstate. also relax compatibility requirements for diffing states (shelltype + major version need to match)
* better error handling, check shellstate compatibility during run (on waveshell server)
* add extra separator for bash shellstate processing to deal with spurious output from rc files
* special migration for v30 -- flag invalid bash shell states and show special button in UI to fix
* format
* remove zsh-decls (unused)
* remove test code
* remove debug print
* fix typo
2024-01-17 01:11:04 +01:00
|
|
|
return sstore.FeStateFromShellState(newState), nil
|
2022-11-28 09:13:00 +01:00
|
|
|
}
|
|
|
|
}
|
2022-12-28 22:56:19 +01:00
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) TryAutoConnect() error {
|
|
|
|
if wsh.IsConnected() {
|
2022-12-28 22:56:19 +01:00
|
|
|
return nil
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
rcopy := wsh.GetRemoteCopy()
|
2022-12-29 01:59:54 +01:00
|
|
|
if rcopy.ConnectMode == sstore.ConnectModeManual {
|
2022-12-28 22:56:19 +01:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
var err error
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.WithLock(func() {
|
|
|
|
if wsh.NumTryConnect > 5 {
|
2022-12-29 01:59:54 +01:00
|
|
|
err = fmt.Errorf("too many unsuccessful tries")
|
2022-12-28 22:56:19 +01:00
|
|
|
return
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.NumTryConnect++
|
2022-12-28 22:56:19 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2024-05-02 23:16:00 +02:00
|
|
|
wsh.Launch(false)
|
|
|
|
if !wsh.IsConnected() {
|
2022-12-29 01:59:54 +01:00
|
|
|
return fmt.Errorf("error connecting")
|
|
|
|
}
|
2022-12-28 22:56:19 +01:00
|
|
|
return nil
|
|
|
|
}
|
2022-12-31 02:01:17 +01:00
|
|
|
|
2024-05-02 23:16:00 +02:00
|
|
|
func (wsh *WaveshellProc) GetDisplayName() string {
|
|
|
|
rcopy := wsh.GetRemoteCopy()
|
2022-12-31 02:01:17 +01:00
|
|
|
return rcopy.GetName()
|
|
|
|
}
|
2024-01-17 19:07:01 +01:00
|
|
|
|
|
|
|
// Identify the screen for a given CommandKey and push the given status indicator update for that screen
|
|
|
|
func pushStatusIndicatorUpdate(ck *base.CommandKey, level sstore.StatusIndicatorLevel) {
|
|
|
|
screenId := ck.GetGroupId()
|
2024-01-28 22:47:36 +01:00
|
|
|
err := sstore.SetStatusIndicatorLevel(context.Background(), screenId, level, false)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("error setting status indicator level: %v\n", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func pushNumRunningCmdsUpdate(ck *base.CommandKey, delta int) {
|
|
|
|
screenId := ck.GetGroupId()
|
|
|
|
sstore.IncrementNumRunningCmds(screenId, delta)
|
2024-01-17 19:07:01 +01:00
|
|
|
}
|