Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion crates/sshx-core/proto/sshx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ message OpenRequest {
string origin = 1; // Web origin of the server.
bytes encrypted_zeros = 2; // Encrypted zero block, for client verification.
string name = 3; // Name of the session (user@hostname).
optional bytes write_password_hash = 4; // Hashed write password, if read-only mode is enabled.
string addr = 4; // Sub path of the URL
optional bytes write_password_hash = 5; // Hashed write password, if write protection is not disabled.
}

// Details of a newly-created sshx session.
Expand Down
12 changes: 8 additions & 4 deletions crates/sshx-server/src/grpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ impl SshxService for GrpcServer {
if origin.is_empty() {
return Err(Status::invalid_argument("origin is empty"));
}
let name = rand_alphanumeric(10);
let name = if request.addr.is_empty() {
rand_alphanumeric(10)
} else {
request.addr
};
info!(%name, "creating new session");

match self.0.lookup(&name) {
Expand Down Expand Up @@ -195,19 +199,19 @@ async fn handle_update(tx: &ServerTx, session: &Session, update: ClientUpdate) -
}
Some(ClientMessage::Data(data)) => {
if let Err(err) = session.add_data(Sid(data.id), data.data, data.seq) {
return send_err(tx, format!("add data: {:?}", err)).await;
return send_err(tx, format!("add data: {err:?}")).await;
}
}
Some(ClientMessage::CreatedShell(new_shell)) => {
let id = Sid(new_shell.id);
let center = (new_shell.x, new_shell.y);
if let Err(err) = session.add_shell(id, center) {
return send_err(tx, format!("add shell: {:?}", err)).await;
return send_err(tx, format!("add shell: {err:?}")).await;
}
}
Some(ClientMessage::ClosedShell(id)) => {
if let Err(err) = session.close_shell(Sid(id)) {
return send_err(tx, format!("close shell: {:?}", err)).await;
return send_err(tx, format!("close shell: {err:?}")).await;
}
}
Some(ClientMessage::Pong(ts)) => {
Expand Down
2 changes: 1 addition & 1 deletion crates/sshx-server/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl ClientSocket {
let msg = self.inner.next().await.unwrap().unwrap();
match msg {
Message::Close(Some(frame)) => assert!(frame.code == code.into()),
_ => panic!("unexpected non-close message over WebSocket: {:?}", msg),
_ => panic!("unexpected non-close message over WebSocket: {msg:?}"),
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/sshx-server/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ async fn test_rpc() -> Result<()> {
let req = OpenRequest {
origin: "sshx.io".into(),
encrypted_zeros: Encrypt::new("").zeros().into(),
addr: "".into(),
name: String::new(),
write_password_hash: None,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/sshx-server/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub mod common;
async fn test_basic_restore() -> Result<()> {
let server = TestServer::new().await;

let mut controller = Controller::new(&server.endpoint(), "", Runner::Echo, false).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, false).await?;
let name = controller.name().to_owned();
let key = controller.encryption_key().to_owned();
tokio::spawn(async move { controller.run().await });
Expand Down
16 changes: 8 additions & 8 deletions crates/sshx-server/tests/with_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub mod common;
#[tokio::test]
async fn test_handshake() -> Result<()> {
let server = TestServer::new().await;
let controller = Controller::new(&server.endpoint(), "", Runner::Echo, false).await?;
let controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, false).await?;
controller.close().await?;
Ok(())
}
Expand All @@ -23,7 +23,7 @@ async fn test_handshake() -> Result<()> {
async fn test_command() -> Result<()> {
let server = TestServer::new().await;
let runner = Runner::Shell("/bin/bash".into());
let mut controller = Controller::new(&server.endpoint(), "", runner, false).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", runner, false).await?;

let session = server
.state()
Expand Down Expand Up @@ -71,7 +71,7 @@ async fn test_ws_missing() -> Result<()> {
async fn test_ws_basic() -> Result<()> {
let server = TestServer::new().await;

let mut controller = Controller::new(&server.endpoint(), "", Runner::Echo, false).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, false).await?;
let name = controller.name().to_owned();
let key = controller.encryption_key().to_owned();
tokio::spawn(async move { controller.run().await });
Expand Down Expand Up @@ -103,7 +103,7 @@ async fn test_ws_basic() -> Result<()> {
async fn test_ws_resize() -> Result<()> {
let server = TestServer::new().await;

let mut controller = Controller::new(&server.endpoint(), "", Runner::Echo, false).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, false).await?;
let name = controller.name().to_owned();
let key = controller.encryption_key().to_owned();
tokio::spawn(async move { controller.run().await });
Expand Down Expand Up @@ -147,7 +147,7 @@ async fn test_ws_resize() -> Result<()> {
async fn test_users_join() -> Result<()> {
let server = TestServer::new().await;

let mut controller = Controller::new(&server.endpoint(), "", Runner::Echo, false).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, false).await?;
let name = controller.name().to_owned();
let key = controller.encryption_key().to_owned();
tokio::spawn(async move { controller.run().await });
Expand Down Expand Up @@ -176,7 +176,7 @@ async fn test_users_join() -> Result<()> {
async fn test_users_metadata() -> Result<()> {
let server = TestServer::new().await;

let mut controller = Controller::new(&server.endpoint(), "", Runner::Echo, false).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, false).await?;
let name = controller.name().to_owned();
let key = controller.encryption_key().to_owned();
tokio::spawn(async move { controller.run().await });
Expand All @@ -201,7 +201,7 @@ async fn test_users_metadata() -> Result<()> {
async fn test_chat_messages() -> Result<()> {
let server = TestServer::new().await;

let mut controller = Controller::new(&server.endpoint(), "", Runner::Echo, false).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, false).await?;
let name = controller.name().to_owned();
let key = controller.encryption_key().to_owned();
tokio::spawn(async move { controller.run().await });
Expand Down Expand Up @@ -234,7 +234,7 @@ async fn test_read_write_permissions() -> Result<()> {
let server = TestServer::new().await;

// create controller with read-only mode enabled
let mut controller = Controller::new(&server.endpoint(), "", Runner::Echo, true).await?;
let mut controller = Controller::new(&server.endpoint(), "", "", Runner::Echo, true).await?;
let name = controller.name().to_owned();
let key = controller.encryption_key().to_owned();
let write_url = controller
Expand Down
2 changes: 2 additions & 0 deletions crates/sshx/src/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ impl Controller {
pub async fn new(
origin: &str,
name: &str,
addr: &str,
runner: Runner,
enable_readers: bool,
) -> Result<Self> {
Expand Down Expand Up @@ -84,6 +85,7 @@ impl Controller {
origin: origin.into(),
encrypted_zeros: encrypt.zeros().into(),
name: name.into(),
addr: addr.into(),
write_password_hash,
};
let mut resp = client.open(req).await?.into_inner();
Expand Down
9 changes: 7 additions & 2 deletions crates/sshx/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ struct Args {
#[clap(long)]
name: Option<String>,

/// Sub path to use
#[clap(long, default_value = "")]
addr: String,

/// Enable read-only access mode - generates separate URLs for viewers and
/// editors.
#[clap(long)]
Expand Down Expand Up @@ -90,10 +94,11 @@ async fn start(args: Args) -> Result<()> {
});

let runner = Runner::Shell(shell.clone());
let mut controller = Controller::new(&args.server, &name, runner, args.enable_readers).await?;
let mut controller =
Controller::new(&args.server, &name, &args.addr, runner, args.enable_readers).await?;
if args.quiet {
if let Some(write_url) = controller.write_url() {
println!("{}", write_url);
println!("{write_url}");
} else {
println!("{}", controller.url());
}
Expand Down
Loading