mirror of
https://github.com/Grasscutters/Cultivation.git
synced 2025-12-12 23:24:35 +01:00
fix run_command and finish generate_ca_files
This commit is contained in:
@@ -37,10 +37,12 @@ fn main() {
|
||||
req_get,
|
||||
get_bg_file,
|
||||
base64_decode,
|
||||
system_helpers::run_command,
|
||||
system_helpers::run_program,
|
||||
system_helpers::run_jar,
|
||||
system_helpers::open_in_browser,
|
||||
proxy::set_proxy_addr,
|
||||
proxy::generate_ca_files,
|
||||
unzip::unzip,
|
||||
file_helpers::rename,
|
||||
file_helpers::dir_exists,
|
||||
|
||||
@@ -146,7 +146,8 @@ pub(crate) fn disconnect_from_proxy() {
|
||||
* Additionally installs the certificate and private key in the Root CA store.
|
||||
* Source: https://github.com/zu1k/good-mitm/raw/master/src/ca/gen.rs
|
||||
*/
|
||||
pub(crate) fn generate_ca_files() {
|
||||
#[tauri::command]
|
||||
pub(crate) fn generate_ca_files(path: &str) {
|
||||
let mut params = CertificateParams::default();
|
||||
let mut details = DistinguishedName::new();
|
||||
|
||||
@@ -169,8 +170,23 @@ pub(crate) fn generate_ca_files() {
|
||||
// Create certificate.
|
||||
let cert = Certificate::from_params(params).unwrap();
|
||||
let cert_crt = cert.serialize_pem().unwrap();
|
||||
let cert_path = format!("{}\\ca", path);
|
||||
|
||||
// TODO: Save certificates.
|
||||
fs::create_dir(&cert_path).unwrap();
|
||||
|
||||
println!("{}", cert_crt);
|
||||
|
||||
match fs::write(format!("{}\\cert.crt", &cert_path), cert_crt) {
|
||||
Ok(_) => println!("Wrote certificate to {}", &cert_path),
|
||||
Err(e) => println!("Error writing certificate to {}: {}", &cert_path, e),
|
||||
}
|
||||
|
||||
let private_key = cert.serialize_private_key_pem();
|
||||
|
||||
match fs::write(format!("{}\\private.key", &cert_path), private_key) {
|
||||
Ok(_) => println!("Wrote private key to {}", &cert_path),
|
||||
Err(e) => println!("Error writing private key to {}: {}", &cert_path, e),
|
||||
}
|
||||
|
||||
// Install certificate into the system's Root CA store.
|
||||
install_ca_files();
|
||||
|
||||
@@ -15,11 +15,11 @@ pub fn run_program(path: String) {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn run_command(command: String) -> String {
|
||||
pub fn run_command(command: String) {
|
||||
// Run the specified command.
|
||||
let output = if cfg!(target_os = "windows") {
|
||||
Command::new("cmd")
|
||||
.args(["/C", command])
|
||||
.args(["/C", command.as_str()])
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
} else {
|
||||
@@ -29,8 +29,6 @@ pub fn run_command(command: String) -> String {
|
||||
.output()
|
||||
.expect("failed to execute process")
|
||||
};
|
||||
|
||||
output.stdout.to_string()
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
|
||||
Reference in New Issue
Block a user