trifid/tfclient/src/main.rs
core 53c6fb18fd
Some checks failed
/ build (push) Failing after 49s
/ build_x64 (push) Successful in 2m26s
/ build_arm64 (push) Successful in 2m33s
/ build_win64 (push) Successful in 2m32s
new work
2023-11-18 22:51:45 -05:00

119 lines
No EOL
3.6 KiB
Rust

// tfclient, an open source client for the Defined Networking nebula management protocol.
// Copyright (C) 2023 c0repwn3r
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub mod apiworker;
pub mod config;
pub mod daemon;
pub mod dirs;
#[cfg(feature = "linked-nebula")]
pub mod nebulaworker;
#[cfg(not(feature = "linked-nebula"))]
#[path = "nebulaworker_inert.rs"]
pub mod nebulaworker;
pub mod socketclient;
pub mod socketworker;
pub mod timerworker;
pub mod util;
use crate::config::load_config;
use clap::{Parser, Subcommand};
use log::{error, info};
use simple_logger::SimpleLogger;
#[derive(Parser)]
#[command(author = "c0repwn3r", version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
subcommand: Commands,
}
#[derive(Subcommand)]
enum Commands {
/// Run the tfclient daemon in the foreground
Run {
#[clap(short, long, default_value = "tfclient")]
/// Service name specified on install
name: String,
#[clap(short, long)]
/// Server to use for API calls.
server: String,
},
/// Enroll this host using a trifid-api-old enrollment code
Enroll {
#[clap(short, long, default_value = "tfclient")]
/// Service name specified on install
name: String,
#[clap(short, long)]
/// Enrollment code used to enroll this node
code: String,
},
/// Manually trigger a config update. It's useful to use this in combination with the `disable_automatic_config_updates` option.
Update {
#[clap(short, long, default_value = "tfclient")]
/// Service name specified on install
name: String,
},
}
fn main() {
SimpleLogger::new().init().unwrap();
let args = Cli::parse();
match args.subcommand {
Commands::Run { name, server } => {
daemon::daemon_main(name, server);
}
Commands::Enroll { name, code } => {
info!("Loading config...");
let config = match load_config(&name) {
Ok(cfg) => cfg,
Err(e) => {
error!("Error loading configuration: {}", e);
std::process::exit(1);
}
};
match socketclient::enroll(&code, &config) {
Ok(_) => (),
Err(e) => {
error!("Error sending enrollment request: {}", e);
std::process::exit(1);
}
};
}
Commands::Update { name } => {
info!("Loading config...");
let config = match load_config(&name) {
Ok(cfg) => cfg,
Err(e) => {
error!("Error loading configuration: {}", e);
std::process::exit(1);
}
};
match socketclient::update(&config) {
Ok(_) => (),
Err(e) => {
error!("Error sending update request: {}", e);
std::process::exit(1);
}
};
}
}
}