2019-02-04 14:16:41 +00:00
|
|
|
#[macro_use]
|
2019-01-28 12:17:03 +00:00
|
|
|
extern crate proxmox_backup;
|
|
|
|
|
|
|
|
use proxmox_backup::api::router::*;
|
|
|
|
use proxmox_backup::api::config::*;
|
|
|
|
use proxmox_backup::server::rest::*;
|
2019-01-29 16:21:58 +00:00
|
|
|
use proxmox_backup::auth_helpers::*;
|
2019-01-28 12:17:03 +00:00
|
|
|
|
2019-02-04 13:56:07 +00:00
|
|
|
use failure::*;
|
2019-01-28 12:17:03 +00:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
|
|
|
use futures::future::Future;
|
2019-02-04 13:56:07 +00:00
|
|
|
use futures::stream::Stream;
|
2019-01-28 12:17:03 +00:00
|
|
|
|
|
|
|
use hyper;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
|
|
|
|
if let Err(err) = syslog::init(
|
|
|
|
syslog::Facility::LOG_DAEMON,
|
|
|
|
log::LevelFilter::Info,
|
|
|
|
Some("proxmox-backup-proxy")) {
|
|
|
|
eprintln!("unable to inititialize syslog: {}", err);
|
|
|
|
std::process::exit(-1);
|
|
|
|
}
|
|
|
|
|
2019-01-29 16:21:58 +00:00
|
|
|
let _ = public_auth_key(); // load with lazy_static
|
|
|
|
let _ = csrf_secret(); // load with lazy_static
|
|
|
|
|
2019-01-28 12:17:03 +00:00
|
|
|
lazy_static!{
|
|
|
|
static ref ROUTER: Router = proxmox_backup::api2::router();
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut config = ApiConfig::new(
|
2019-01-31 12:43:09 +00:00
|
|
|
env!("PROXMOX_JSDIR"), &ROUTER, RpcEnvironmentType::PUBLIC);
|
2019-01-28 12:17:03 +00:00
|
|
|
|
|
|
|
// add default dirs which includes jquery and bootstrap
|
|
|
|
// my $base = '/usr/share/libpve-http-server-perl';
|
|
|
|
// add_dirs($self->{dirs}, '/css/' => "$base/css/");
|
|
|
|
// add_dirs($self->{dirs}, '/js/' => "$base/js/");
|
|
|
|
// add_dirs($self->{dirs}, '/fonts/' => "$base/fonts/");
|
|
|
|
config.add_alias("novnc", "/usr/share/novnc-pve");
|
|
|
|
config.add_alias("extjs", "/usr/share/javascript/extjs");
|
|
|
|
config.add_alias("fontawesome", "/usr/share/fonts-font-awesome");
|
|
|
|
config.add_alias("xtermjs", "/usr/share/pve-xtermjs");
|
|
|
|
config.add_alias("widgettoolkit", "/usr/share/javascript/proxmox-widget-toolkit");
|
|
|
|
|
|
|
|
let rest_server = RestServer::new(config);
|
|
|
|
|
2019-02-04 13:56:07 +00:00
|
|
|
let identity =
|
|
|
|
native_tls::Identity::from_pkcs12(
|
2019-02-04 14:16:41 +00:00
|
|
|
&std::fs::read(configdir!("/proxy.pfx")).unwrap(),
|
2019-02-04 13:56:07 +00:00
|
|
|
"",
|
|
|
|
).unwrap();
|
|
|
|
|
|
|
|
let addr = ([0,0,0,0,0,0,0,0], 8007).into();
|
|
|
|
let listener = tokio::net::TcpListener::bind(&addr).unwrap();
|
|
|
|
let acceptor = native_tls::TlsAcceptor::new(identity).unwrap();
|
|
|
|
let acceptor = std::sync::Arc::new(tokio_tls::TlsAcceptor::from(acceptor));
|
|
|
|
let connections = listener
|
|
|
|
.incoming()
|
|
|
|
.map_err(|e| Error::from(e))
|
|
|
|
.and_then(move |sock| acceptor.accept(sock).map_err(|e| e.into()))
|
|
|
|
.then(|r| match r {
|
|
|
|
// accept()s can fail here with an Err() when eg. the client rejects
|
|
|
|
// the cert and closes the connection, so we follow up with mapping
|
|
|
|
// it to an option and then filtering None with filter_map
|
|
|
|
Ok(c) => Ok::<_, Error>(Some(c)),
|
|
|
|
Err(_) => Ok(None),
|
|
|
|
})
|
|
|
|
.filter_map(|r| {
|
|
|
|
// Filter out the Nones
|
|
|
|
r
|
|
|
|
});
|
|
|
|
|
|
|
|
let server = hyper::Server::builder(connections)
|
2019-01-28 12:17:03 +00:00
|
|
|
.serve(rest_server)
|
|
|
|
.map_err(|e| eprintln!("server error: {}", e));
|
|
|
|
|
|
|
|
|
|
|
|
// Run this server for... forever!
|
|
|
|
hyper::rt::run(server);
|
|
|
|
}
|