Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit 7cc93e1

Browse files
authored
Merge pull request #74 from PThorpe92/dev
Dev
2 parents 90c9f0d + 0f88ca7 commit 7cc93e1

File tree

15 files changed

+450
-58
lines changed

15 files changed

+450
-58
lines changed

Cargo.lock

Lines changed: 381 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ name = "cute"
1010
path = "src/main.rs"
1111

1212
[dependencies]
13+
cross = "*"
1314
crossterm = "0.27.0"
1415
tui = { package = "ratatui", features = [
1516
"crossterm",

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
# Rust TUI HTTP Client with API Key Management
55

66
#### This project is still in active development and although it is useable, there may still be bugs and significant changes are still needed to both refactor the codebase and add new features.
7+
#### I am distracted with work and a new project at the moment, so I am not able to put in as much time as I would like here and I am afraid that if I don't open source it now, it will end up in the side-project graveyard. Collaboration is welcome and encouraged, there is LOTS of low-hanging fruit here, while still being a useful tool.
78
![image](screenshot.png)
89

910
Terminal user interface (TUI) HTTP client in Rust designed to simplify the process of making various types of HTTP requests while supporting various different kinds of Authentication (powered by libcURL), recursive downloading of directories (powered by GNU Wget), and storage + management of your previous requests + API keys.
@@ -78,6 +79,10 @@ This project is licensed under the [GPL3.0 License](LICENSE).
7879

7980
---
8081

81-
If you have any questions or need assistance, feel free to reach out to [Preston](https://github.com/PThorpe92)
82+
If you have any questions or need assistance, feel free to [reach out](preston@unlockedlabs.org)
83+
84+
**Fun fact:** This project was written in the Maine State Prison system, the main author and 2nd largest contributor are both currently incarcerated. I would like to bring whatever awareness possible to the importance of education and rehabilitation for those 2.2 million Americans currently incarcerated. Access to education and technology is severely limited in the carceral system and I am incredibly fortunate to be in a situation where I am permitted to have remote employment and access to participate in Open source projects. This is incredibly rare, and I am very grateful for the opportunity, but I recognize that this is very much the exception and not the rule. We need to do better as a society.
85+
86+
If you are interested in helping support the education of incarcerated and justice-impacted individuals, please consider donating to a company like the one I currently work for, [Unlocked Labs](https://unlockedlabs.org/) or similar non-profits like [The Last Mile](https://thelastmile.org/) or [Recidiviz](https://www.recidiviz.org/)
8287

8388
**Disclaimer:** This project is provided as-is, and its creators are not responsible for any misuse or potential security vulnerabilities resulting from the usage of API keys.

src/database/db.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,24 @@ pub struct DB {
2929

3030
impl DB {
3131
pub fn new() -> Result<Self, rusqlite::Error> {
32-
let mut path: PathBuf = PathBuf::new();
32+
let mut _path: PathBuf = PathBuf::new();
3333
if std::env::var("CUTE_DB_PATH").is_ok() {
34-
path = PathBuf::from_str(env::var("CUTE_DB_PATH").unwrap().as_str()).unwrap();
34+
_path = PathBuf::from_str(env::var("CUTE_DB_PATH").unwrap().as_str()).unwrap();
3535
} else {
36-
path = DB::get_default_path();
36+
_path = DB::get_default_path();
3737
}
38-
if !path.exists() {
38+
if !_path.exists() {
3939
// If it doesn't exist, create it
40-
if let Err(err) = std::fs::create_dir_all(&path) {
41-
std::fs::File::create(&path).expect("failed to create database");
40+
if let Err(err) = std::fs::create_dir_all(&_path) {
41+
std::fs::File::create(&_path).expect("failed to create database");
4242
eprintln!("Failed to create CuTE directory: {}", err);
4343
} else {
44-
println!("CuTE directory created at {:?}", path);
44+
println!("CuTE directory created at {:?}", _path);
4545
}
4646
}
4747

4848
let conn_result = Connection::open_with_flags(
49-
path.join("CuTE.db"),
49+
_path.join("CuTE.db"),
5050
OpenFlags::SQLITE_OPEN_READ_WRITE
5151
| OpenFlags::SQLITE_OPEN_CREATE
5252
| OpenFlags::SQLITE_OPEN_URI
@@ -81,7 +81,7 @@ impl DB {
8181
}
8282

8383
pub fn get_default_path() -> PathBuf {
84-
let mut dir = data_local_dir().expect("Failed to get data local directory,\nPlease specify a path at $CONFIG/CuTE/config.toml\nOr with the --db_path={path/to/CuTE.db}");
84+
let dir = data_local_dir().expect("Failed to get data local directory,\nPlease specify a path at $CONFIG/CuTE/config.toml\nOr with the --db_path={path/to/CuTE.db}");
8585
dir.join("CuTE")
8686
}
8787

@@ -226,5 +226,4 @@ impl SavedKey {
226226
pub fn from_json(json: &str) -> Result<Self> {
227227
Ok(serde_json::from_str(json).expect("Failed to deserialize"))
228228
}
229-
//TODO: implement actual encryption
230229
}

src/display/menuopts.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub const DISPLAY_OPT_CA_PATH: &str = " 󰄤 SSL Certificate path: ";
8686
pub const DISPLAY_OPT_AUTH: &str = " Authentication: ";
8787
pub const DISPLAY_OPT_MATCH_WILDCARD: &str = " Match glob wildcard 󰛄 ";
8888
pub const DISPLAY_OPT_CERT_INFO: &str = " Request certificate info 󰄤 ";
89+
pub const DISPLAY_OPT_BODY: &str = " Request Body: ";
8990
pub const DISPLAY_OPT_UPLOAD: &str = " Upload file: ";
9091
pub const DISPLAY_OPT_REQUEST_BODY: &str = " Request Body";
9192
pub const DISPLAY_OPT_TCP_KEEPALIVE: &str = " Enable TCP keepalive 󰗶 ";
@@ -183,10 +184,11 @@ lazy_static! {
183184
"Specify User-Agent 󰖟 ",
184185
"Enable TCP keepalive 󰗶 ",
185186
];
186-
pub static ref RESPONSE_MENU_OPTIONS: [&'static str; 4] = [
187+
pub static ref RESPONSE_MENU_OPTIONS: [&'static str; 5] = [
187188
"Write to file? 󱇧 ",
188189
"View response headers 󰰀 ",
189190
"View response body 󰈮 ",
190-
"Copy command to clipboard 󰅎 "
191+
"Copy command to clipboard 󰅎 ",
192+
"Return to main menu  ",
191193
];
192194
}

src/display/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ use crate::display::menuopts::{
33
};
44

55
use self::menuopts::{
6-
DISPLAY_OPT_AUTH, DISPLAY_OPT_CA_PATH, DISPLAY_OPT_CERT_INFO, DISPLAY_OPT_COMMAND_SAVED,
7-
DISPLAY_OPT_COOKIE, DISPLAY_OPT_FAIL_ON_ERROR, DISPLAY_OPT_FOLLOW_REDIRECTS,
8-
DISPLAY_OPT_HEADERS, DISPLAY_OPT_MATCH_WILDCARD, DISPLAY_OPT_OUTFILE, DISPLAY_OPT_PROGRESS_BAR,
9-
DISPLAY_OPT_PROXY_TUNNEL, DISPLAY_OPT_TCP_KEEPALIVE, DISPLAY_OPT_TOKEN_SAVED,
10-
DISPLAY_OPT_UNIX_SOCKET, DISPLAY_OPT_UNRESTRICTED_AUTH, DISPLAY_OPT_UPLOAD, DISPLAY_OPT_URL,
11-
DISPLAY_OPT_USERAGENT, DISPLAY_OPT_VERBOSE,
6+
DISPLAY_OPT_AUTH, DISPLAY_OPT_BODY, DISPLAY_OPT_CA_PATH, DISPLAY_OPT_CERT_INFO,
7+
DISPLAY_OPT_COMMAND_SAVED, DISPLAY_OPT_COOKIE, DISPLAY_OPT_FAIL_ON_ERROR,
8+
DISPLAY_OPT_FOLLOW_REDIRECTS, DISPLAY_OPT_HEADERS, DISPLAY_OPT_MATCH_WILDCARD,
9+
DISPLAY_OPT_OUTFILE, DISPLAY_OPT_PROGRESS_BAR, DISPLAY_OPT_PROXY_TUNNEL,
10+
DISPLAY_OPT_TCP_KEEPALIVE, DISPLAY_OPT_TOKEN_SAVED, DISPLAY_OPT_UNIX_SOCKET,
11+
DISPLAY_OPT_UNRESTRICTED_AUTH, DISPLAY_OPT_UPLOAD, DISPLAY_OPT_URL, DISPLAY_OPT_USERAGENT,
12+
DISPLAY_OPT_VERBOSE,
1213
};
1314

1415
/*
@@ -138,7 +139,7 @@ impl AppOptions {
138139
AppOptions::TcpKeepAlive => DISPLAY_OPT_TCP_KEEPALIVE.to_string(),
139140
AppOptions::UnrestrictedAuth => format!("{}{}", DISPLAY_OPT_UNRESTRICTED_AUTH, "󰄨"),
140141
AppOptions::UploadFile(file) => format!("{}{}", DISPLAY_OPT_UPLOAD, file.clone()),
141-
AppOptions::RequestBody(body) => format!("{}{}", DISPLAY_OPT_UPLOAD, body.clone()),
142+
AppOptions::RequestBody(body) => format!("{}{}", DISPLAY_OPT_BODY, body.clone()),
142143
}
143144
}
144145
}

src/request/curl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ define_curl_flags! {
957957
Cookie("-b"),
958958
Output("-o"),
959959
User("-u"),
960-
Bearer("-H"),
960+
Bearer("-H"),// bearer/basic auth are just headers
961961
CertInfo("--certinfo"),
962962
Headers("-H"),
963963
Digest("--digest"),
@@ -981,7 +981,7 @@ define_curl_flags! {
981981
// is default on CLI, so flag has no value
982982
TcpKeepAlive(" "),
983983
CaPath("--capath"),
984-
SpnegoAuth("--negotiate"),
984+
SpnegoAuth("--negotiate -u:"),
985985
Progress("--progress-bar"),
986986
RequestBody("--data"),
987987
}

src/screens/auth.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,13 @@ pub fn handle_authentication_screen<B: Backend>(app: &mut App, frame: &mut Frame
5555
4 => {
5656
app.command.as_mut().unwrap().set_auth(AuthKind::Spnego);
5757
app.add_app_option(AppOptions::Auth(AuthType::SPNEGO.to_string()));
58-
app.goto_screen(Screen::RequestMenu(String::from("Alert: Negotiate Auth")));
58+
app.goto_screen(Screen::RequestMenu(String::from("")));
5959
}
6060
5 => {
6161
app.command.as_mut().unwrap().set_auth(AuthKind::Ntlm);
62-
app.goto_screen(Screen::RequestMenu(String::from("Alert: NTLM Auth")));
62+
app.goto_screen(Screen::RequestMenu(String::from(
63+
"Alert: NTLM Auth Enabled",
64+
)));
6365
}
6466
_ => {}
6567
}

src/screens/downloads.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ use crate::screens::screen::Screen;
66
use tui::backend::Backend;
77
use tui::Frame;
88

9+
use super::error_alert_box;
910
use super::render::handle_screen_defaults;
1011

11-
pub fn handle_downloads_screen<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>) {
12+
pub fn handle_downloads_screen<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>, err: &str) {
13+
handle_screen_defaults(app, frame);
14+
if !err.is_empty() {
15+
error_alert_box(frame, err);
16+
}
1217
if app.command.is_none() {
1318
app.set_command(Box::new(Cmd::Wget(Wget::new())));
1419
}
15-
handle_screen_defaults(app, frame);
1620
match app.selected {
1721
// Setting Recursion level
1822
Some(0) => {

src/screens/error.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use tui::text::Text;
88
use tui::widgets::{Block, Borders, ListState, Paragraph, Wrap};
99
use tui::Frame;
1010

11-
1211
fn err_box<B: Backend>(frame: &mut Frame<'_, B>, error_msg: String) {
1312
let popup_layout = Layout::default()
1413
.direction(Direction::Vertical)
@@ -64,7 +63,7 @@ pub fn handle_error_screen<B: Backend>(app: &mut App, frame: &mut Frame<'_, B>,
6463
app.state = Some(state.clone());
6564
app.state.as_mut().unwrap().select(Some(app.cursor));
6665
frame.set_cursor(0, app.cursor as u16);
67-
//frame.render_stateful_widget(new_list, area, &mut state);
66+
frame.render_stateful_widget(new_list, area, &mut state);
6867

6968
err_box(frame, error_msg);
7069
}

0 commit comments

Comments
 (0)