Added to FileTransferProtocol bool secure flag to Ftp

This commit is contained in:
ChristianVisintin
2020-12-03 08:16:07 +01:00
parent 9b26b5b99d
commit a328a4f751
6 changed files with 38 additions and 80 deletions

View File

@@ -44,12 +44,6 @@ use tui::{
};
use unicode_width::UnicodeWidthStr;
enum InputProtocol {
Sftp,
Ftp,
Ftps,
}
/// ### InputField
///
/// InputField describes the current input field to edit
@@ -81,13 +75,11 @@ pub struct AuthActivity {
pub protocol: FileTransferProtocol,
pub username: String,
pub password: String,
pub secure: bool, // Special option used by some protocols (such as FTP)
pub submit: bool, // becomes true after user has submitted fields
pub quit: bool, // Becomes true if user has pressed esc
context: Option<Context>,
selected_field: InputField,
input_mode: InputMode,
input_protocol: InputProtocol,
popup_message: Option<String>,
password_placeholder: String,
redraw: bool, // Should ui actually be redrawned?
@@ -104,8 +96,6 @@ impl AuthActivity {
protocol: FileTransferProtocol::Sftp,
username: String::new(),
password: String::new(),
input_protocol: InputProtocol::Sftp,
secure: false,
submit: false,
quit: false,
context: None,
@@ -117,27 +107,6 @@ impl AuthActivity {
}
}
/// ### change_opt_based_on_protocol
///
/// Change current options based on the selected protocol
fn change_opt_based_on_protocol(&mut self) {
// Change options based on current protocol
match self.input_protocol {
InputProtocol::Sftp => {
self.secure = false;
self.protocol = FileTransferProtocol::Sftp;
}
InputProtocol::Ftp => {
self.secure = false;
self.protocol = FileTransferProtocol::Ftp;
}
InputProtocol::Ftps => {
self.secure = true;
self.protocol = FileTransferProtocol::Ftp;
}
}
}
/// ### set_input_mode
///
/// Update input mode based on current parameters
@@ -259,23 +228,25 @@ impl AuthActivity {
KeyCode::Left => {
// If current field is Protocol handle event... (move element left)
if self.selected_field == InputField::Protocol {
self.input_protocol = match self.input_protocol {
InputProtocol::Sftp => InputProtocol::Ftps, // End of list (wrap)
InputProtocol::Ftp => InputProtocol::Sftp,
InputProtocol::Ftps => InputProtocol::Ftp,
self.protocol = match self.protocol {
FileTransferProtocol::Sftp => FileTransferProtocol::Ftp(true), // End of list (wrap)
FileTransferProtocol::Ftp(ftps) => match ftps {
true => FileTransferProtocol::Sftp,
false => FileTransferProtocol::Ftp(true),
}
};
self.change_opt_based_on_protocol();
}
}
KeyCode::Right => {
// If current field is Protocol handle event... ( move element right )
if self.selected_field == InputField::Protocol {
self.input_protocol = match self.input_protocol {
InputProtocol::Sftp => InputProtocol::Ftp,
InputProtocol::Ftp => InputProtocol::Ftps,
InputProtocol::Ftps => InputProtocol::Sftp, // End of list (wrap)
self.protocol = match self.protocol {
FileTransferProtocol::Sftp => FileTransferProtocol::Ftp(false),
FileTransferProtocol::Ftp(ftps) => match ftps {
false => FileTransferProtocol::Ftp(true),
true => FileTransferProtocol::Sftp, // End of list (wrap)
}
};
self.change_opt_based_on_protocol();
}
}
_ => { /* Nothing to do */ }
@@ -337,10 +308,12 @@ impl AuthActivity {
fn draw_protocol_select(&self) -> Tabs {
let protocols: Vec<Spans> =
vec![Spans::from("SFTP"), Spans::from("FTP"), Spans::from("FTPS")];
let index: usize = match self.input_protocol {
InputProtocol::Sftp => 0,
InputProtocol::Ftp => 1,
InputProtocol::Ftps => 2,
let index: usize = match self.protocol {
FileTransferProtocol::Sftp => 0,
FileTransferProtocol::Ftp(ftps) => match ftps {
false => 1,
true => 2,
}
};
Tabs::new(protocols)
.block(Block::default().borders(Borders::ALL).title("Protocol"))

View File

@@ -69,7 +69,6 @@ pub struct FileTransferParams {
pub protocol: FileTransferProtocol,
pub username: Option<String>,
pub password: Option<String>,
pub extra_flag_secure: bool,
}
/// ### InputField
@@ -240,8 +239,8 @@ impl FileTransferActivity {
context: None,
client: match protocol {
FileTransferProtocol::Sftp => Box::new(SftpFileTransfer::new()),
FileTransferProtocol::Ftp => {
Box::new(FtpFileTransfer::new(params.extra_flag_secure))
FileTransferProtocol::Ftp(ftps) => {
Box::new(FtpFileTransfer::new(ftps))
}
},
params: params,