Skip to content

Commit d6af708

Browse files
authored
Merge pull request #6 from KUACC-VALAR-HPC-KOC-UNIVERSITY/extra-pages-handling
Extra pages handling
2 parents 32b286e + 1d75dfb commit d6af708

File tree

14 files changed

+922
-767
lines changed

14 files changed

+922
-767
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
[package]
22
name = "kuvpn"
3-
version = "2.0.0"
3+
version = "2.0.1"
44
edition = "2021"
55
description = "A convenient tool for connecting to Koç University's VPN using OpenConnect."
66
repository = "https://github.com/KUACC-VALAR-HPC-KOC-UNIVERSITY/kuvpn"
77
license = "MIT"
88

99
[dependencies]
1010
anyhow = "1.0.99"
11-
clap = { version = "4.5.46", features = ["derive"] }
11+
clap = { version = "4.5.47", features = ["derive"] }
1212
colored = "3.0.0"
1313
env_logger = "0.11.8"
14-
headless_chrome = { version = "1.0.17", features = ["fetch", "rustls"] }
14+
headless_chrome = { version = "1.0.18", features = ["fetch", "rustls"] }
1515
log = "0.4.27"
1616
rpassword = "7.4.0"
1717
which = "8.0.0"
18+
19+
[profile.release]
20+
opt-level = "z" # Minimize size (use "z" or "s" for small codegen)
21+
lto = true # Enable link-time optimization
22+
panic = "abort" # Abort on panic (smaller than "unwind")
23+
strip = true # Strip debug symbols from build (requires Rust 1.70+)
24+
codegen-units = 1 # Single codegen unit for better LTO of small binaries

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# KUVPN v2.0.0
1+
# KUVPN v2.0.1
22

33
KUVPN is a simple CLI tool written in Rust that retrieves the DSID cookie and executes the OpenConnect command to connect to the VPN for Koç University.
44

@@ -23,6 +23,7 @@ KUVPN is a simple CLI tool written in Rust that retrieves the DSID cookie and ex
2323
-**Retrieve DSID cookie**
2424
-**Execute OpenConnect command**
2525
-**Headless Execution**
26+
-**Automatic or Manuel Login Navigation**
2627
-**Session management**
2728
-**CLI Based**
2829
-**Openconnect Wrapper**
@@ -149,6 +150,9 @@ Options:
149150

150151
[default: openconnect]
151152

153+
--no-auto-login
154+
Disable automatic login handlers and only poll for DSID in a headful browser
155+
152156
-h, --help
153157
Print help (see a summary with '-h')
154158

@@ -170,6 +174,16 @@ You can clear your session like this:
170174
kuvpn -c
171175
```
172176
177+
### Troubleshooting: Unable to login?
178+
179+
If you aren't able to login via the cli'a automation, you can disable the auto login so that you can do it via the browser's gui.
180+
To do this run the following command:
181+
```
182+
kuvpn --no-auto-login --disable-headless
183+
```
184+
185+
Later, once you login, it will remember your session so you can login without the need for this, on the next logins.
186+
173187
## License
174188
175189
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

src/args.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,8 @@ pub struct Args {
5252
/// Can be a relative or absolute path.
5353
#[arg(long, default_value = "openconnect")]
5454
pub openconnect_path: String,
55+
56+
/// Disable automatic login handlers and only poll for DSID in a headful browser
57+
#[arg(long, default_value_t = false)]
58+
pub no_auto_login: bool,
5559
}

src/browser.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use crate::utils::get_user_data_dir;
2+
use headless_chrome::browser::default_executable;
3+
use headless_chrome::{Browser, LaunchOptions};
4+
use std::error::Error;
5+
use std::ffi::OsString;
6+
use std::time::Duration;
7+
8+
/// Creates a browser instance configured with a blank page, a custom user agent,
9+
/// and a dedicated user data directory.
10+
///
11+
/// The browser is launched with the following settings:
12+
/// - **Headless or non-headless mode** based on the `headless` parameter.
13+
/// - **A blank app window** containing a minimal HTML page.
14+
/// - **Custom user agent** as specified by the `agent` parameter.
15+
/// - **Custom user data directory** for isolated session data.
16+
/// - **Custom window size** of 800x800 pixels.
17+
/// - **Sandbox disabled** and an infinite idle timeout.
18+
///
19+
/// # Arguments
20+
///
21+
/// * `agent` - A string slice representing the desired user agent.
22+
/// * `headless` - Whether to run the browser in headless mode.
23+
///
24+
/// # Returns
25+
///
26+
/// A `Result` containing the configured `Browser` instance on success, or an error on failure.
27+
pub fn create_browser(agent: &str, headless: bool) -> Result<Browser, Box<dyn Error>> {
28+
// Retrieve the user data directory.
29+
let user_data_dir = get_user_data_dir()?;
30+
31+
// Build the command-line arguments for launching the browser.
32+
let user_agent = OsString::from(format!("--user-agent={agent}"));
33+
let body = OsString::from("--app=data:text/html,");
34+
let window = OsString::from("--new-window");
35+
36+
// Configure the browser launch options.
37+
let mut options = LaunchOptions::default_builder();
38+
let mut launch_options = options
39+
.headless(headless)
40+
.sandbox(false)
41+
.idle_browser_timeout(Duration::MAX)
42+
.window_size(Some((800, 800)))
43+
.args(vec![
44+
body.as_os_str(),
45+
window.as_os_str(),
46+
user_agent.as_os_str(),
47+
])
48+
.user_data_dir(Some(user_data_dir));
49+
50+
// If the default Chrome executable is available, specify its path.
51+
if let Ok(executable_path) = default_executable() {
52+
launch_options = launch_options.path(Some(executable_path));
53+
}
54+
55+
// Build and return the Browser instance.
56+
Ok(Browser::new(launch_options.build()?)?)
57+
}

0 commit comments

Comments
 (0)