1 package PVE
::Service
::pveproxy
;
16 use PVE
::API2
::Formatter
::Standard
;
17 use PVE
::API2
::Formatter
::HTML
;
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);
46 my ($result_hash, $alias, $subdir) = @_;
48 $result_hash->{$alias} = $subdir;
51 my $dir = $File::Find
::dir
;
52 if ($dir =~m!^$subdir(.*)$!) {
53 my $name = "$alias$1/";
54 $result_hash->{$name} = "$dir/";
58 find
({wanted
=> $wanted, follow
=> 0, no_chdir
=> 1}, $subdir);
64 # we use same ALLOW/DENY/POLICY as pveproxy
65 my $proxyconf = PVE
::API2Tools
::read_proxy_config
();
67 my $accept_lock_fn = "/var/lock/pveproxy.lck";
69 my $lockfh = IO
::File-
>new(">>${accept_lock_fn}") ||
70 die "unable to open lock file '${accept_lock_fn}' - $!\n";
72 my $family = PVE
::Tools
::get_host_address_family
($self->{nodename
});
73 my $socket = $self->create_reusable_socket(8006, undef, $family);
75 $ext6_dir_exists = (-d
'/usr/share/pve-manager/ext6');
79 add_dirs
($dirs, '/pve2/locale/', '/usr/share/pve-manager/locale/');
80 add_dirs
($dirs, '/pve2/touch/', '/usr/share/pve-manager/touch/');
81 add_dirs
($dirs, '/pve2/ext4/', '/usr/share/pve-manager/ext4/');
83 if ($ext6_dir_exists) { # only add ext6 dirs if they exist
84 add_dirs
($dirs, '/pve2/ext6/', '/usr/share/pve-manager/ext6/');
85 add_dirs
($dirs, '/pve2/manager6/', '/usr/share/pve-manager/manager6/');
88 add_dirs
($dirs, '/pve2/images/' => '/usr/share/pve-manager/images/');
89 add_dirs
($dirs, '/pve2/css/' => '/usr/share/pve-manager/css/');
90 add_dirs
($dirs, '/pve2/js/' => '/usr/share/pve-manager/js/');
91 add_dirs
($dirs, '/vncterm/' => '/usr/share/vncterm/');
92 add_dirs
($dirs, '/novnc/' => '/usr/share/novnc-pve/');
94 $self->{server_config
} = {
95 base_handler_class
=> 'PVE::API2',
99 lockfile
=> $accept_lock_fn,
102 debug
=> $self->{debug
},
103 trusted_env
=> 0, # not trusted, anyone can connect
104 logfile
=> '/var/log/pveproxy/access.log',
105 allow_from
=> $proxyconf->{ALLOW_FROM
},
106 deny_from
=> $proxyconf->{DENY_FROM
},
107 policy
=> $proxyconf->{POLICY
},
109 # Note: older versions are considered insecure, for example
110 # search for "Poodle"-Attac
114 cipher_list
=> $proxyconf->{CIPHERS
} || 'HIGH:MEDIUM:!aNULL:!MD5',
115 key_file
=> '/etc/pve/local/pve-ssl.key',
116 cert_file
=> '/etc/pve/local/pve-ssl.pem',
118 # Note: there is no authentication for those pages and dirs!
121 # avoid authentication when accessing favicon
123 file
=> '/usr/share/pve-manager/images/favicon.ico',
129 if ($proxyconf->{DHPARAMS
}) {
130 $self->{server_config
}->{ssl
}->{dh_file
} = $proxyconf->{DHPARAMS
};
132 $self->{server_config
}->{ssl
}->{dh
} = 'skip2048';
139 my $server = PVE
::HTTPServer-
>new(%{$self->{server_config
}});
143 $daemon->register_start_command();
144 $daemon->register_restart_command(1);
145 $daemon->register_stop_command();
146 $daemon->register_status_command();
149 start
=> [ __PACKAGE__
, 'start', []],
150 restart
=> [ __PACKAGE__
, 'restart', []],
151 stop
=> [ __PACKAGE__
, 'stop', []],
152 status
=> [ __PACKAGE__
, 'status', [], undef, sub { print shift . "\n";} ],
160 return 1 if $ua =~ m/(iPhone|iPod|Windows Phone)/;
162 if ($ua =~ m/Mobile(\/|\s
)/) {
163 return 1 if $ua =~ m/(BlackBerry|BB)/;
164 return 1 if ($ua =~ m/(Android)/) && ($ua !~ m/(Silk)/);
170 # NOTE: Requests to those pages are not authenticated
171 # so we must be very careful here
174 my ($server, $r, $args) = @_;
180 if (my $cookie = $r->header('Cookie')) {
181 if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
182 if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
186 my $ticket = PVE
::REST
::extract_auth_cookie
($cookie);
187 if (($username = PVE
::AccessControl
::verify_ticket
($ticket, 1))) {
188 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
192 $username = '' if !$username;
194 my $mobile = is_phone
($r->header('User-Agent')) ?
1 : 0;
196 if (defined($args->{mobile
})) {
197 $mobile = $args->{mobile
} ?
1 : 0;
201 if (defined($args->{ext6
})) {
202 $ext6 = $args->{ext6
} ?
1 : 0;
207 if (defined($args->{console
}) && $args->{novnc
}) {
208 $page = PVE
::NoVncIndex
::get_index
($lang, $username, $token, $args->{console
});
210 $page = PVE
::TouchIndex
::get_index
($lang, $username, $token, $args->{console
});
211 } elsif ($ext6 && $ext6_dir_exists) {
212 $page = PVE
::ExtJSIndex6
::get_index
($lang, $username, $token, $args->{console
});
214 $page = PVE
::ExtJSIndex
::get_index
($lang, $username, $token, $args->{console
});
216 my $headers = HTTP
::Headers-
>new(Content_Type
=> "text/html; charset=utf-8");
217 my $resp = HTTP
::Response-
>new(200, "OK", $headers, $page);
228 pveproxy - the PVE API proxy server
236 This is the REST API proxy server, listening on port 8006. This is usually
237 started as service using:
239 # service pveproxy start
241 =head1 Host based access control
243 It is possible to configure apache2 like access control lists. Values are read
244 from file /etc/default/pveproxy. For example:
246 ALLOW_FROM="10.0.0.1-10.0.0.5,192.168.0.0/22"
250 IP addresses can be specified using any syntax understood by Net::IP. The
251 name 'all' is an alias for '0/0'.
253 The default policy is 'allow'.
255 Match | POLICY=deny | POLICY=allow
256 ---------------------------|-------------|------------
257 Match Allow only | allow | allow
258 Match Deny only | deny | deny
259 No match | deny | allow
260 Match Both Allow & Deny | deny | allow
262 =head1 SSL Cipher Suite
264 You can define the cipher list in /etc/default/pveproxy, for example
266 CIPHERS="HIGH:MEDIUM:!aNULL:!MD5"
268 Above is the default. See the ciphers(1) man page from the openssl
269 package for a list of all available options.
271 =head1 Diffie-Hellman Parameters
273 You can define the used Diffie-Hellman parameters in /etc/default/pveproxy
274 by setting DHPARAMS to the path of a file containing DH parameters in PEM
277 DHPARAMS="/path/to/dhparams.pem"
279 If this option is not set, the built-in 'skip2048' parameters will be used.
281 Note: DH parameters are only used if a cipher suite utilizing the DH key
282 exchange algorithm is negotiated.
286 /etc/default/pveproxy
288 =include pve_copyright