]> git.proxmox.com Git - proxmox-backup.git/blame - src/bin/proxmox-backup-proxy.rs
access: use proxmox-backup-auth for pam
[proxmox-backup.git] / src / bin / proxmox-backup-proxy.rs
CommitLineData
9d02e5c3 1#[macro_use]
02c7a755
DM
2extern crate proxmox_backup;
3
02c7a755
DM
4use proxmox_backup::api::router::*;
5use proxmox_backup::api::config::*;
6use proxmox_backup::server::rest::*;
d01e2420 7use proxmox_backup::auth_helpers::*;
02c7a755 8
0d176f36 9use failure::*;
02c7a755
DM
10use lazy_static::lazy_static;
11
12use futures::future::Future;
0d176f36 13use futures::stream::Stream;
02c7a755
DM
14
15use hyper;
16
17fn main() {
18
19 if let Err(err) = syslog::init(
20 syslog::Facility::LOG_DAEMON,
21 log::LevelFilter::Info,
22 Some("proxmox-backup-proxy")) {
23 eprintln!("unable to inititialize syslog: {}", err);
24 std::process::exit(-1);
25 }
26
d01e2420
DM
27 let _ = public_auth_key(); // load with lazy_static
28 let _ = csrf_secret(); // load with lazy_static
29
02c7a755
DM
30 lazy_static!{
31 static ref ROUTER: Router = proxmox_backup::api2::router();
32 }
33
34 let mut config = ApiConfig::new(
6285b251 35 env!("PROXMOX_JSDIR"), &ROUTER, RpcEnvironmentType::PUBLIC);
02c7a755
DM
36
37 // add default dirs which includes jquery and bootstrap
38 // my $base = '/usr/share/libpve-http-server-perl';
39 // add_dirs($self->{dirs}, '/css/' => "$base/css/");
40 // add_dirs($self->{dirs}, '/js/' => "$base/js/");
41 // add_dirs($self->{dirs}, '/fonts/' => "$base/fonts/");
42 config.add_alias("novnc", "/usr/share/novnc-pve");
43 config.add_alias("extjs", "/usr/share/javascript/extjs");
44 config.add_alias("fontawesome", "/usr/share/fonts-font-awesome");
45 config.add_alias("xtermjs", "/usr/share/pve-xtermjs");
46 config.add_alias("widgettoolkit", "/usr/share/javascript/proxmox-widget-toolkit");
47
48 let rest_server = RestServer::new(config);
49
0d176f36
WB
50 let identity =
51 native_tls::Identity::from_pkcs12(
9d02e5c3 52 &std::fs::read(configdir!("/proxy.pfx")).unwrap(),
0d176f36
WB
53 "",
54 ).unwrap();
55
56 let addr = ([0,0,0,0,0,0,0,0], 8007).into();
57 let listener = tokio::net::TcpListener::bind(&addr).unwrap();
58 let acceptor = native_tls::TlsAcceptor::new(identity).unwrap();
59 let acceptor = std::sync::Arc::new(tokio_tls::TlsAcceptor::from(acceptor));
60 let connections = listener
61 .incoming()
62 .map_err(|e| Error::from(e))
63 .and_then(move |sock| acceptor.accept(sock).map_err(|e| e.into()))
64 .then(|r| match r {
65 // accept()s can fail here with an Err() when eg. the client rejects
66 // the cert and closes the connection, so we follow up with mapping
67 // it to an option and then filtering None with filter_map
68 Ok(c) => Ok::<_, Error>(Some(c)),
69 Err(_) => Ok(None),
70 })
71 .filter_map(|r| {
72 // Filter out the Nones
73 r
74 });
75
76 let server = hyper::Server::builder(connections)
02c7a755
DM
77 .serve(rest_server)
78 .map_err(|e| eprintln!("server error: {}", e));
79
80
81 // Run this server for... forever!
82 hyper::rt::run(server);
83}