mirror of
https://github.com/FliegendeWurst/KIT-ILIAS-downloader.git
synced 2024-08-28 04:04:18 +00:00
Load username and password from .iliaslogin
This commit is contained in:
parent
97ac79b19f
commit
f195911531
48
src/main.rs
48
src/main.rs
@ -28,7 +28,7 @@ const ILIAS_URL: &str = "https://ilias.studium.kit.edu/";
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
let opt = Opt::from_args();
|
let mut opt = Opt::from_args();
|
||||||
create_dir(&opt.output).await.expect("failed to create output directory");
|
create_dir(&opt.output).await.expect("failed to create output directory");
|
||||||
// need this because task scheduling is WIP
|
// need this because task scheduling is WIP
|
||||||
// (would wait forever on paniced task)
|
// (would wait forever on paniced task)
|
||||||
@ -39,9 +39,34 @@ async fn main() {
|
|||||||
PANIC_HOOK.lock()(info);
|
PANIC_HOOK.lock()(info);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
let user = rprompt::prompt_reply_stdout("Username: ").expect("username prompt");
|
// load .iliasignore file
|
||||||
let pass = rpassword::read_password_from_tty(Some("Password: ")).expect("password prompt");
|
opt.output.push(".iliasignore");
|
||||||
let ilias = match ILIAS::login(opt, user, pass).await {
|
let (ignore, error) = Gitignore::new(&opt.output);
|
||||||
|
if let Some(err) = error {
|
||||||
|
println!("Warning: .iliasignore error: {}", err);
|
||||||
|
}
|
||||||
|
opt.output.pop();
|
||||||
|
// loac .iliaslogin file
|
||||||
|
opt.output.push(".iliaslogin");
|
||||||
|
let login = std::fs::read_to_string(&opt.output);
|
||||||
|
let (user, pass) = if let Ok(login) = login {
|
||||||
|
let mut lines = login.split('\n');
|
||||||
|
let user = lines.next();
|
||||||
|
let pass = lines.next();
|
||||||
|
if user.is_some() && pass.is_some() {
|
||||||
|
let user = user.unwrap().trim();
|
||||||
|
let pass = pass.unwrap().trim();
|
||||||
|
(user.to_owned(), pass.to_owned())
|
||||||
|
} else {
|
||||||
|
println!("Warning: .iliaslogin incomplete");
|
||||||
|
ask_user_pass()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ask_user_pass()
|
||||||
|
};
|
||||||
|
opt.output.pop();
|
||||||
|
|
||||||
|
let ilias = match ILIAS::login(opt, user, pass, ignore).await {
|
||||||
Ok(ilias) => ilias,
|
Ok(ilias) => ilias,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
print!("{:?}", e);
|
print!("{:?}", e);
|
||||||
@ -87,6 +112,12 @@ lazy_static!{
|
|||||||
static ref PANIC_HOOK: Mutex<Box<dyn Fn(&panic::PanicInfo) + Sync + Send + 'static>> = Mutex::new(Box::new(|_| {}));
|
static ref PANIC_HOOK: Mutex<Box<dyn Fn(&panic::PanicInfo) + Sync + Send + 'static>> = Mutex::new(Box::new(|_| {}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ask_user_pass() -> (String, String) {
|
||||||
|
let user = rprompt::prompt_reply_stdout("Username: ").expect("username prompt");
|
||||||
|
let pass = rpassword::read_password_from_tty(Some("Password: ")).expect("password prompt");
|
||||||
|
(user, pass)
|
||||||
|
}
|
||||||
|
|
||||||
fn process_gracefully(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl Future<Output = ()> + Send { async move {
|
fn process_gracefully(ilias: Arc<ILIAS>, path: PathBuf, obj: Object) -> impl Future<Output = ()> + Send { async move {
|
||||||
*TASKS_QUEUED.lock() += 1;
|
*TASKS_QUEUED.lock() += 1;
|
||||||
loop {
|
loop {
|
||||||
@ -564,7 +595,7 @@ struct ILIAS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ILIAS {
|
impl ILIAS {
|
||||||
async fn login<S1: Into<String>, S2: Into<String>>(mut opt: Opt, user: S1, pass: S2) -> Result<Self> {
|
async fn login<S1: Into<String>, S2: Into<String>>(opt: Opt, user: S1, pass: S2, ignore: Gitignore) -> Result<Self> {
|
||||||
let user = user.into();
|
let user = user.into();
|
||||||
let pass = pass.into();
|
let pass = pass.into();
|
||||||
let client = Client::builder()
|
let client = Client::builder()
|
||||||
@ -572,13 +603,6 @@ impl ILIAS {
|
|||||||
.user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")))
|
.user_agent(concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION")))
|
||||||
// timeout is infinite by default
|
// timeout is infinite by default
|
||||||
.build()?;
|
.build()?;
|
||||||
// load .iliasignore file
|
|
||||||
opt.output.push(".iliasignore");
|
|
||||||
let (ignore, error) = Gitignore::new(&opt.output);
|
|
||||||
if let Some(err) = error {
|
|
||||||
println!("Warning: .iliasignore error: {}", err);
|
|
||||||
}
|
|
||||||
opt.output.pop();
|
|
||||||
let this = ILIAS {
|
let this = ILIAS {
|
||||||
opt, client, user, pass, ignore
|
opt, client, user, pass, ignore
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user