diff --git a/src/commands.rs b/src/commands.rs index 87f256d6..e25bce6d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1,4 +1,5 @@ use dialoguer::Confirm; +use std::net::IpAddr; use std::{fs::File, io::prelude::*, path::PathBuf, process, time::Duration}; #[cfg(feature = "web_server_capability")] @@ -159,7 +160,14 @@ pub(crate) fn start_server(path: PathBuf, debug: bool) { } #[cfg(feature = "web_server_capability")] -pub(crate) fn start_web_server(opts: CliArgs, run_daemonized: bool) { +pub(crate) fn start_web_server( + opts: CliArgs, + run_daemonized: bool, + ip: Option, + port: Option, + cert: Option, + key: Option, +) { // TODO: move this outside of this function let (config, _layout, config_options, _config_without_layout, _config_options_without_layout) = match Setup::from_cli_args(&opts) { @@ -174,12 +182,27 @@ pub(crate) fn start_web_server(opts: CliArgs, run_daemonized: bool) { process::exit(1); }, }; - - start_web_client_impl(config, config_options, opts.config, run_daemonized); + start_web_client_impl( + config, + config_options, + opts.config, + run_daemonized, + ip, + port, + cert, + key, + ); } #[cfg(not(feature = "web_server_capability"))] -pub(crate) fn start_web_server(_opts: CliArgs, _run_daemonized: bool) { +pub(crate) fn start_web_server( + _opts: CliArgs, + _run_daemonized: bool, + _ip: Option, + _port: Option, + _cert: Option, + _key: Option, +) { log::error!( "This version of Zellij was compiled without web server support, cannot run web server!" ); diff --git a/src/main.rs b/src/main.rs index 4720a13a..a2f23162 100644 --- a/src/main.rs +++ b/src/main.rs @@ -231,7 +231,14 @@ fn main() { } else if let Some(Command::Web(web_opts)) = &opts.command { if web_opts.get_start() { let daemonize = web_opts.daemonize; - commands::start_web_server(opts, daemonize); + commands::start_web_server( + opts.clone(), + daemonize, + web_opts.ip, + web_opts.port, + web_opts.cert.clone(), + web_opts.key.clone(), + ); } else if web_opts.stop { match commands::stop_web_server() { Ok(()) => { diff --git a/zellij-client/src/web_client/mod.rs b/zellij-client/src/web_client/mod.rs index 649f95f5..ed689961 100644 --- a/zellij-client/src/web_client/mod.rs +++ b/zellij-client/src/web_client/mod.rs @@ -67,6 +67,10 @@ pub fn start_web_client( config_options: Options, config_file_path: Option, run_daemonized: bool, + custom_ip: Option, + custom_port: Option, + custom_server_cert: Option, + custom_server_key: Option, ) { std::panic::set_hook({ Box::new(move |info| { @@ -87,12 +91,15 @@ pub fn start_web_client( std::process::exit(2); }) }); - let web_server_ip = config_options - .web_server_ip - .unwrap_or_else(|| IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))); - let web_server_port = config_options.web_server_port.unwrap_or_else(|| 8082); - let web_server_cert = &config.options.web_server_cert; - let web_server_key = &config.options.web_server_key; + let web_server_ip = custom_ip.unwrap_or_else(|| { + config_options + .web_server_ip + .unwrap_or_else(|| IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1))) + }); + let web_server_port = + custom_port.unwrap_or_else(|| config_options.web_server_port.unwrap_or_else(|| 8082)); + let web_server_cert = custom_server_cert.or_else(|| config.options.web_server_cert.clone()); + let web_server_key = custom_server_key.or_else(|| config.options.web_server_key.clone()); let has_https_certificate = web_server_cert.is_some() && web_server_key.is_some(); if let Err(e) = should_use_https( @@ -274,8 +281,8 @@ pub async fn serve_web_client( fn daemonize_web_server( web_server_ip: IpAddr, web_server_port: u16, - web_server_cert: &Option, - web_server_key: &Option, + web_server_cert: Option, + web_server_key: Option, ) -> (Runtime, std::net::TcpListener, Option) { let (mut exit_message_tx, exit_message_rx) = pipe().unwrap(); let (mut exit_status_tx, mut exit_status_rx) = pipe().unwrap(); diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index b85d975f..bca031bc 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -6,6 +6,7 @@ use crate::{ }; use clap::{Args, Parser, Subcommand}; use serde::{Deserialize, Serialize}; +use std::net::IpAddr; use std::path::PathBuf; use url::Url; @@ -144,6 +145,38 @@ pub struct WebCli { /// List token names and their creation dates (cannot show actual tokens) #[clap(long, value_parser, exclusive(true), display_order = 8)] pub list_tokens: bool, + /// The ip address to listen on locally for connections (defaults to 127.0.0.1) + #[clap( + long, + value_parser, + conflicts_with_all(&["stop", "status", "create-token", "revoke-token", "revoke-all-tokens"]), + display_order = 9 + )] + pub ip: Option, + /// The port to listen on locally for connections (defaults to 8082) + #[clap( + long, + value_parser, + conflicts_with_all(&["stop", "status", "create-token", "revoke-token", "revoke-all-tokens"]), + display_order = 10 + )] + pub port: Option, + /// The path to the SSL certificate (required if not listening on 127.0.0.1) + #[clap( + long, + value_parser, + conflicts_with_all(&["stop", "status", "create-token", "revoke-token", "revoke-all-tokens"]), + display_order = 11 + )] + pub cert: Option, + /// The path to the SSL key (required if not listening on 127.0.0.1) + #[clap( + long, + value_parser, + conflicts_with_all(&["stop", "status", "create-token", "revoke-token", "revoke-all-tokens"]), + display_order = 12 + )] + pub key: Option, } impl WebCli {