1 package PVE
::Service
::pveproxy
;
15 use PVE
::APIServer
::Formatter
;
16 use PVE
::APIServer
::Formatter
::Standard
;
17 use PVE
::APIServer
::Formatter
::HTML
;
18 use PVE
::APIServer
::AnyEvent
;
27 use base
qw(PVE::Daemon);
29 my $cmdline = [$0, @ARGV];
31 my %daemon_options = (
33 restart_on_error
=> 5,
35 leave_children_open_on_reload
=> 1,
38 pidfile
=> '/var/run/pveproxy/pveproxy.pid',
41 my $daemon = __PACKAGE__-
>new('pveproxy', $cmdline, %daemon_options);
44 my ($result_hash, $alias, $subdir) = @_;
46 PVE
::APIServer
::AnyEvent
::add_dirs
($result_hash, $alias, $subdir);
52 # we use same ALLOW/DENY/POLICY as pveproxy
53 my $proxyconf = PVE
::API2Tools
::read_proxy_config
();
55 my $accept_lock_fn = "/var/lock/pveproxy.lck";
57 my $lockfh = IO
::File-
>new(">>${accept_lock_fn}") ||
58 die "unable to open lock file '${accept_lock_fn}' - $!\n";
60 my $family = PVE
::Tools
::get_host_address_family
($self->{nodename
});
61 my $socket = $self->create_reusable_socket(8006, undef, $family);
65 add_dirs
($dirs, '/pve2/locale/', '/usr/share/pve-manager/locale/');
66 add_dirs
($dirs, '/pve2/touch/', '/usr/share/pve-manager/touch/');
67 add_dirs
($dirs, '/pve2/ext6/', '/usr/share/pve-manager/ext6/');
68 add_dirs
($dirs, '/pve2/manager6/', '/usr/share/pve-manager/manager6/');
70 add_dirs
($dirs, '/pve2/images/' => '/usr/share/pve-manager/images/');
71 add_dirs
($dirs, '/pve2/css/' => '/usr/share/pve-manager/css/');
72 add_dirs
($dirs, '/pve-docs/' => '/usr/share/pve-docs/');
73 add_dirs
($dirs, '/vncterm/' => '/usr/share/vncterm/');
74 add_dirs
($dirs, '/novnc/' => '/usr/share/novnc-pve/');
76 $self->{server_config
} = {
77 title
=> 'Proxmox VE API',
81 lockfile
=> $accept_lock_fn,
84 debug
=> $self->{debug
},
85 trusted_env
=> 0, # not trusted, anyone can connect
86 logfile
=> '/var/log/pveproxy/access.log',
87 allow_from
=> $proxyconf->{ALLOW_FROM
},
88 deny_from
=> $proxyconf->{DENY_FROM
},
89 policy
=> $proxyconf->{POLICY
},
91 # Note: older versions are considered insecure, for example
92 # search for "Poodle"-Attac
96 cipher_list
=> $proxyconf->{CIPHERS
} || 'HIGH:MEDIUM:!aNULL:!MD5',
97 key_file
=> '/etc/pve/local/pve-ssl.key',
98 cert_file
=> '/etc/pve/local/pve-ssl.pem',
100 # Note: there is no authentication for those pages and dirs!
102 '/' => sub { get_index
($self->{nodename
}, @_) },
103 # avoid authentication when accessing favicon
105 file
=> '/usr/share/pve-manager/images/favicon.ico',
111 if ($proxyconf->{DHPARAMS
}) {
112 $self->{server_config
}->{ssl
}->{dh_file
} = $proxyconf->{DHPARAMS
};
114 $self->{server_config
}->{ssl
}->{dh
} = 'skip2048';
117 if (-f
'/etc/pve/local/pveproxy-ssl.pem' && -f
'/etc/pve/local/pveproxy-ssl.key') {
118 $self->{server_config
}->{ssl
}->{cert_file
} = '/etc/pve/local/pveproxy-ssl.pem';
119 $self->{server_config
}->{ssl
}->{key_file
} = '/etc/pve/local/pveproxy-ssl.key';
120 syslog
('info', 'Using \'/etc/pve/local/pveproxy-ssl.pem\' as certificate for the web interface.');
127 my $server = PVE
::HTTPServer-
>new(%{$self->{server_config
}});
131 $daemon->register_start_command();
132 $daemon->register_restart_command(1);
133 $daemon->register_stop_command();
134 $daemon->register_status_command();
137 start
=> [ __PACKAGE__
, 'start', []],
138 restart
=> [ __PACKAGE__
, 'restart', []],
139 stop
=> [ __PACKAGE__
, 'stop', []],
140 status
=> [ __PACKAGE__
, 'status', [], undef, sub { print shift . "\n";} ],
148 return 1 if $ua =~ m/(iPhone|iPod|Windows Phone)/;
150 if ($ua =~ m/Mobile(\/|\s
)/) {
151 return 1 if $ua =~ m/(BlackBerry|BB)/;
152 return 1 if ($ua =~ m/(Android)/) && ($ua !~ m/(Silk)/);
158 # NOTE: Requests to those pages are not authenticated
159 # so we must be very careful here
162 my ($nodename, $server, $r, $args) = @_;
168 if (my $cookie = $r->header('Cookie')) {
169 if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
170 if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
174 my $ticket = PVE
::APIServer
::Formatter
::extract_auth_cookie
($cookie, $server->{cookie_name
});
175 if (($username = PVE
::AccessControl
::verify_ticket
($ticket, 1))) {
176 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
180 $username = '' if !$username;
182 my $mobile = is_phone
($r->header('User-Agent')) ?
1 : 0;
184 if (defined($args->{mobile
})) {
185 $mobile = $args->{mobile
} ?
1 : 0;
190 if (defined($args->{console
}) && $args->{novnc
}) {
191 $page = PVE
::NoVncIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
193 $page = PVE
::TouchIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
195 $page = PVE
::ExtJSIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename,
198 my $headers = HTTP
::Headers-
>new(Content_Type
=> "text/html; charset=utf-8");
199 my $resp = HTTP
::Response-
>new(200, "OK", $headers, $page);