mirror of
https://github.com/veeso/termscp.git
synced 2026-09-26 05:51:20 -07:00
Auth view enhanchements: check if port and host are valid
This commit is contained in:
@@ -48,10 +48,13 @@ Released on FIXME: ??
|
|||||||
- Enhancements:
|
- Enhancements:
|
||||||
- Show a "wait" message when deleting, copying and moving files and when executing commands
|
- Show a "wait" message when deleting, copying and moving files and when executing commands
|
||||||
- Replaced all `...` with `…` in texts
|
- Replaced all `...` with `…` in texts
|
||||||
|
- Check if remote host is valid in authentication form
|
||||||
|
- Check if port number is valid in authentication form
|
||||||
- Bugfix:
|
- Bugfix:
|
||||||
- Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2)
|
- Fixed broken input cursor when typing UTF8 characters (tui-realm 0.3.2)
|
||||||
- Fixed save bookmark dialog: you could switch out from dialog with `<TAB>`
|
- Fixed save bookmark dialog: you could switch out from dialog with `<TAB>`
|
||||||
- Fixed transfer interruption: it was not possible to abort a transfer if the size of the file was less than 65k
|
- Fixed transfer interruption: it was not possible to abort a transfer if the size of the file was less than 65k
|
||||||
|
- Changed `Remote address` to `Remote host` in authentication form
|
||||||
- Dependencies:
|
- Dependencies:
|
||||||
- Added `argh 0.1.5`
|
- Added `argh 0.1.5`
|
||||||
- Added `open 1.7.0`
|
- Added `open 1.7.0`
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
* SOFTWARE.
|
* SOFTWARE.
|
||||||
*/
|
*/
|
||||||
use super::{AuthActivity, FileTransferProtocol};
|
use super::{AuthActivity, FileTransferParams, FileTransferProtocol};
|
||||||
|
|
||||||
impl AuthActivity {
|
impl AuthActivity {
|
||||||
/// ### protocol_opt_to_enum
|
/// ### protocol_opt_to_enum
|
||||||
@@ -80,4 +80,37 @@ impl AuthActivity {
|
|||||||
self.umount_size_err();
|
self.umount_size_err();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// ### collect_host_params
|
||||||
|
///
|
||||||
|
/// Get input values from fields or return an error if fields are invalid
|
||||||
|
pub(super) fn collect_host_params(&self) -> Result<FileTransferParams, &'static str> {
|
||||||
|
let (address, port, protocol, username, password): (
|
||||||
|
String,
|
||||||
|
u16,
|
||||||
|
FileTransferProtocol,
|
||||||
|
String,
|
||||||
|
String,
|
||||||
|
) = self.get_input();
|
||||||
|
if address.is_empty() {
|
||||||
|
return Err("Invalid host");
|
||||||
|
}
|
||||||
|
if port == 0 {
|
||||||
|
return Err("Invalid port");
|
||||||
|
}
|
||||||
|
Ok(FileTransferParams {
|
||||||
|
address,
|
||||||
|
port,
|
||||||
|
protocol,
|
||||||
|
username: match username.is_empty() {
|
||||||
|
true => None,
|
||||||
|
false => Some(username),
|
||||||
|
},
|
||||||
|
password: match password.is_empty() {
|
||||||
|
true => None,
|
||||||
|
false => Some(password),
|
||||||
|
},
|
||||||
|
entry_directory: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,9 +27,9 @@
|
|||||||
*/
|
*/
|
||||||
// locals
|
// locals
|
||||||
use super::{
|
use super::{
|
||||||
AuthActivity, FileTransferParams, FileTransferProtocol, COMPONENT_BOOKMARKS_LIST,
|
AuthActivity, FileTransferProtocol, COMPONENT_BOOKMARKS_LIST, COMPONENT_INPUT_ADDR,
|
||||||
COMPONENT_INPUT_ADDR, COMPONENT_INPUT_BOOKMARK_NAME, COMPONENT_INPUT_PASSWORD,
|
COMPONENT_INPUT_BOOKMARK_NAME, COMPONENT_INPUT_PASSWORD, COMPONENT_INPUT_PORT,
|
||||||
COMPONENT_INPUT_PORT, COMPONENT_INPUT_USERNAME, COMPONENT_RADIO_BOOKMARK_DEL_BOOKMARK,
|
COMPONENT_INPUT_USERNAME, COMPONENT_RADIO_BOOKMARK_DEL_BOOKMARK,
|
||||||
COMPONENT_RADIO_BOOKMARK_DEL_RECENT, COMPONENT_RADIO_BOOKMARK_SAVE_PWD,
|
COMPONENT_RADIO_BOOKMARK_DEL_RECENT, COMPONENT_RADIO_BOOKMARK_SAVE_PWD,
|
||||||
COMPONENT_RADIO_PROTOCOL, COMPONENT_RADIO_QUIT, COMPONENT_RECENTS_LIST, COMPONENT_TEXT_ERROR,
|
COMPONENT_RADIO_PROTOCOL, COMPONENT_RADIO_QUIT, COMPONENT_RECENTS_LIST, COMPONENT_TEXT_ERROR,
|
||||||
COMPONENT_TEXT_HELP, COMPONENT_TEXT_NEW_VERSION_NOTES, COMPONENT_TEXT_SIZE_ERR,
|
COMPONENT_TEXT_HELP, COMPONENT_TEXT_NEW_VERSION_NOTES, COMPONENT_TEXT_SIZE_ERR,
|
||||||
@@ -327,27 +327,20 @@ impl Update for AuthActivity {
|
|||||||
}
|
}
|
||||||
// On submit on any unhandled (connect)
|
// On submit on any unhandled (connect)
|
||||||
(_, Msg::OnSubmit(_)) | (_, &MSG_KEY_ENTER) => {
|
(_, Msg::OnSubmit(_)) | (_, &MSG_KEY_ENTER) => {
|
||||||
// Match <ENTER> key for all other components
|
// Validate fields
|
||||||
self.save_recent();
|
match self.collect_host_params() {
|
||||||
let (address, port, protocol, username, password) = self.get_input();
|
Err(err) => {
|
||||||
// Set file transfer params to context
|
// mount error
|
||||||
let params: FileTransferParams = FileTransferParams {
|
self.mount_error(err);
|
||||||
address,
|
}
|
||||||
port,
|
Ok(params) => {
|
||||||
protocol,
|
self.save_recent();
|
||||||
username: match username.is_empty() {
|
// Set file transfer params to context
|
||||||
true => None,
|
self.context_mut().set_ftparams(params);
|
||||||
false => Some(username),
|
// Set exit reason
|
||||||
},
|
self.exit_reason = Some(super::ExitReason::Connect);
|
||||||
password: match password.is_empty() {
|
}
|
||||||
true => None,
|
}
|
||||||
false => Some(password),
|
|
||||||
},
|
|
||||||
entry_directory: None,
|
|
||||||
};
|
|
||||||
self.context_mut().set_ftparams(params);
|
|
||||||
// Set exit reason
|
|
||||||
self.exit_reason = Some(super::ExitReason::Connect);
|
|
||||||
// Return None
|
// Return None
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,7 +138,7 @@ impl AuthActivity {
|
|||||||
InputPropsBuilder::default()
|
InputPropsBuilder::default()
|
||||||
.with_foreground(addr_color)
|
.with_foreground(addr_color)
|
||||||
.with_borders(Borders::ALL, BorderType::Rounded, addr_color)
|
.with_borders(Borders::ALL, BorderType::Rounded, addr_color)
|
||||||
.with_label(String::from("Remote address"))
|
.with_label(String::from("Remote host"))
|
||||||
.build(),
|
.build(),
|
||||||
)),
|
)),
|
||||||
);
|
);
|
||||||
@@ -823,8 +823,11 @@ impl AuthActivity {
|
|||||||
|
|
||||||
pub(super) fn get_input_port(&self) -> u16 {
|
pub(super) fn get_input_port(&self) -> u16 {
|
||||||
match self.view.get_state(super::COMPONENT_INPUT_PORT) {
|
match self.view.get_state(super::COMPONENT_INPUT_PORT) {
|
||||||
Some(Payload::One(Value::Usize(x))) => x as u16,
|
Some(Payload::One(Value::Usize(x))) => match x > 65535 {
|
||||||
_ => Self::get_default_port_for_protocol(FileTransferProtocol::Sftp),
|
true => 0,
|
||||||
|
false => x as u16,
|
||||||
|
},
|
||||||
|
_ => 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user