|
|
@ -1,8 +1,7 @@ |
|
|
|
use std::env; |
|
|
|
use regex::Regex; |
|
|
|
use std::io::prelude::*; |
|
|
|
use std::process::{Command, Stdio}; |
|
|
|
use colored::*; |
|
|
|
use std::process::{Command, Stdio, Output}; |
|
|
|
use std::fs; |
|
|
|
|
|
|
|
fn main() { |
|
|
@ -42,43 +41,29 @@ fn export_tor(username: String, dir: String) { |
|
|
|
.output() |
|
|
|
.expect("failed to execute process"); |
|
|
|
|
|
|
|
println!("status: {}", output.status); |
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
|
|
|
assert!(output.status.success()); |
|
|
|
|
|
|
|
//let output = Command::new("/usr/bin/cp")
|
|
|
|
// .arg(src_path)
|
|
|
|
// .arg(dest_path)
|
|
|
|
// .output()
|
|
|
|
// .expect("failed to execute process");
|
|
|
|
|
|
|
|
//println!("status: {}", output.status);
|
|
|
|
//println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
|
|
|
//println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
|
|
|
//assert!(output.status.success());
|
|
|
|
|
|
|
|
print_output(output); |
|
|
|
} |
|
|
|
|
|
|
|
fn le_install(domain: String) { |
|
|
|
|
|
|
|
let output = Command::new("/usr/bin/certbot") |
|
|
|
.arg("--nginx") |
|
|
|
// Using ECDSA
|
|
|
|
.arg("--key-type") |
|
|
|
.arg("rsa") |
|
|
|
.arg("--rsa-key-size") |
|
|
|
.arg("3072") |
|
|
|
.arg("ecdsa") |
|
|
|
.arg("--elliptic-curve") |
|
|
|
.arg("secp384r1") |
|
|
|
// Using RSA
|
|
|
|
//.arg("--key-type")
|
|
|
|
//.arg("rsa")
|
|
|
|
//.arg("--rsa-key-size")
|
|
|
|
//.arg("3072")
|
|
|
|
.arg("-d") |
|
|
|
.arg(&domain) |
|
|
|
.output() |
|
|
|
.expect("failed to execute process"); |
|
|
|
|
|
|
|
println!("status: {}", output.status); |
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
|
|
|
|
|
|
|
assert!(output.status.success()); |
|
|
|
|
|
|
|
print_output(output); |
|
|
|
} |
|
|
|
|
|
|
|
fn reload_nginx() { |
|
|
@ -89,6 +74,10 @@ fn reload_nginx() { |
|
|
|
.output() |
|
|
|
.expect("Error while reloading Nginx config"); |
|
|
|
|
|
|
|
print_output(output); |
|
|
|
} |
|
|
|
|
|
|
|
fn print_output(output: Output) { |
|
|
|
println!("status: {}", output.status); |
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
|
|
@ -98,24 +87,13 @@ fn reload_nginx() { |
|
|
|
|
|
|
|
fn reload_tor() { |
|
|
|
|
|
|
|
Command::new("/usr/bin/systemctl") |
|
|
|
let output = Command::new("/usr/bin/systemctl") |
|
|
|
.arg("reload") |
|
|
|
.arg("tor@default") |
|
|
|
.output() |
|
|
|
.expect("Error while reloading Tor config"); |
|
|
|
|
|
|
|
//let output = Command::new("/usr/bin/chown")
|
|
|
|
// .arg("-R")
|
|
|
|
// .arg("www-data:www-data")
|
|
|
|
// .arg("/var/lib/tor/niver")
|
|
|
|
// .output()
|
|
|
|
// .expect("failed to execute process");
|
|
|
|
|
|
|
|
//println!("status: {}", output.status);
|
|
|
|
//println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
|
|
|
|
//println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
|
|
|
|
//assert!(output.status.success());
|
|
|
|
|
|
|
|
print_output(output); |
|
|
|
} |
|
|
|
|
|
|
|
fn setup_user(username: String, password: String) { |
|
|
@ -142,7 +120,6 @@ fn setup_user(username: String, password: String) { |
|
|
|
} else { |
|
|
|
println!("Erreur : l'username doit faire moins de 32 caractères"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Set disk usage limit to the user by copying another user quota
|
|
|
@ -155,12 +132,7 @@ fn quota(username: String) { |
|
|
|
.output() |
|
|
|
.expect("failed to execute process"); |
|
|
|
|
|
|
|
println!("status: {}", output.status); |
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
|
|
|
|
|
|
|
assert!(output.status.success()); |
|
|
|
|
|
|
|
print_output(output); |
|
|
|
} |
|
|
|
|
|
|
|
// Chown /srv/hyper/username to root:root
|
|
|
@ -178,10 +150,7 @@ fn chroot(username: String) { |
|
|
|
.output() |
|
|
|
.expect("Failed to chown /srv/hyper/<username> to root:root"); |
|
|
|
|
|
|
|
println!("status: {}", output.status); |
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
|
|
|
assert!(output.status.success()); |
|
|
|
print_output(output); |
|
|
|
|
|
|
|
let output = Command::new("/usr/bin/chmod") |
|
|
|
.arg("755") |
|
|
@ -189,15 +158,11 @@ fn chroot(username: String) { |
|
|
|
.output() |
|
|
|
.expect("Failed to chmod /srv/hyper/<username> to 755"); |
|
|
|
|
|
|
|
println!("status: {}", output.status); |
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
|
|
|
assert!(output.status.success()); |
|
|
|
print_output(output); |
|
|
|
|
|
|
|
} else { |
|
|
|
println!("Erreur : l'username doit faire moins de 32 caractères"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Creates a new user in the group 'hyper', which is available only over SFTP
|
|
|
@ -215,12 +180,7 @@ fn newser(username: String) { |
|
|
|
.output() |
|
|
|
.expect("failed to execute process"); |
|
|
|
|
|
|
|
println!("status: {}", output.status); |
|
|
|
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); |
|
|
|
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); |
|
|
|
|
|
|
|
assert!(output.status.success()); |
|
|
|
|
|
|
|
print_output(output); |
|
|
|
} |
|
|
|
|
|
|
|
// Changes password of the newly created user
|
|
|
@ -249,7 +209,6 @@ fn pwd(username: String, password: String) { |
|
|
|
Err(why) => panic!("couldn't read chpasswd stdout: {}", why), |
|
|
|
Ok(_) => print!("chpasswd responded with:\n{}", s), |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
fn is_string_lowercase(stri: String) -> bool { |
|
|
@ -261,5 +220,4 @@ fn is_string_lowercase(stri: String) -> bool { |
|
|
|
} else { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|