2018-12-20 09:32:49 +00:00
|
|
|
extern crate proxmox_backup;
|
2018-11-16 12:14:11 +00:00
|
|
|
|
2019-01-29 16:21:58 +00:00
|
|
|
//use proxmox_backup::tools;
|
2018-12-20 09:32:49 +00:00
|
|
|
use proxmox_backup::api::router::*;
|
|
|
|
use proxmox_backup::api::config::*;
|
|
|
|
use proxmox_backup::server::rest::*;
|
2019-01-29 15:55:49 +00:00
|
|
|
use proxmox_backup::auth_helpers::*;
|
2018-10-31 09:42:14 +00:00
|
|
|
|
2018-11-15 09:14:08 +00:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
use futures::future::Future;
|
2018-11-09 07:22:54 +00:00
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
use hyper;
|
2018-10-31 09:42:14 +00:00
|
|
|
|
2018-10-30 09:04:30 +00:00
|
|
|
fn main() {
|
|
|
|
|
2019-01-26 09:56:11 +00:00
|
|
|
if let Err(err) = syslog::init(
|
|
|
|
syslog::Facility::LOG_DAEMON,
|
|
|
|
log::LevelFilter::Info,
|
|
|
|
Some("proxmox-backup-api")) {
|
|
|
|
eprintln!("unable to inititialize syslog: {}", err);
|
|
|
|
std::process::exit(-1);
|
|
|
|
}
|
|
|
|
|
2019-01-29 12:15:33 +00:00
|
|
|
if let Err(err) = generate_auth_key() {
|
2019-01-29 11:59:07 +00:00
|
|
|
eprintln!("unable to generate auth key: {}", err);
|
|
|
|
std::process::exit(-1);
|
|
|
|
}
|
2019-01-29 16:21:58 +00:00
|
|
|
let _ = private_auth_key(); // load with lazy_static
|
2019-01-29 11:59:07 +00:00
|
|
|
|
2019-01-29 12:15:33 +00:00
|
|
|
if let Err(err) = generate_csrf_key() {
|
|
|
|
eprintln!("unable to generate csrf key: {}", err);
|
|
|
|
std::process::exit(-1);
|
|
|
|
}
|
2019-01-29 16:21:58 +00:00
|
|
|
let _ = csrf_secret(); // load with lazy_static
|
2019-01-29 12:15:33 +00:00
|
|
|
|
2019-01-28 12:17:03 +00:00
|
|
|
let addr = ([127,0,0,1], 82).into();
|
2018-10-31 09:42:14 +00:00
|
|
|
|
2018-11-14 10:57:01 +00:00
|
|
|
lazy_static!{
|
2019-01-22 11:10:38 +00:00
|
|
|
static ref ROUTER: Router = proxmox_backup::api2::router();
|
2018-11-14 10:57:01 +00:00
|
|
|
}
|
2018-11-13 13:47:03 +00:00
|
|
|
|
2019-01-28 12:17:03 +00:00
|
|
|
let config = ApiConfig::new(
|
|
|
|
"/usr/share/javascript/proxmox-backup", &ROUTER, RpcEnvironmentType::PRIVILEDGED);
|
2018-11-13 13:47:03 +00:00
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
let rest_server = RestServer::new(config);
|
2018-10-31 09:42:14 +00:00
|
|
|
|
2018-11-15 07:18:48 +00:00
|
|
|
let server = hyper::Server::bind(&addr)
|
|
|
|
.serve(rest_server)
|
2018-10-31 09:42:14 +00:00
|
|
|
.map_err(|e| eprintln!("server error: {}", e));
|
|
|
|
|
2018-11-18 14:01:19 +00:00
|
|
|
|
2018-10-31 09:42:14 +00:00
|
|
|
// Run this server for... forever!
|
|
|
|
hyper::rt::run(server);
|
2018-10-30 09:04:30 +00:00
|
|
|
}
|