3 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
5 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
11 use POSIX
":sys_wait_h";
23 use PVE
::API2
::Formatter
::Standard
;
24 use PVE
::API2
::Formatter
::HTML
;
26 my $pidfile = "/var/run/pveproxy/pveproxy.pid";
27 my $lockfile = "/var/lock/pveproxy.lck";
33 if (!GetOptions
('debug' => \
$opt_debug)) {
34 die "usage: $0 [--debug]\n";
37 $SIG{'__WARN__'} = sub {
41 syslog
('warning', "WARNING: %s", $t);
48 my $gid = getgrnam('www-data') || die "getgrnam failed - $!\n";
49 POSIX
::setgid
($gid) || die "setgid $gid failed - $!\n";
50 $EGID = "$gid $gid"; # this calls setgroups
51 my $uid = getpwnam('www-data') || die "getpwnam failed - $!\n";
52 POSIX
::setuid
($uid) || die "setuid $uid failed - $!\n";
55 die "detected strange uid/gid\n" if !($UID == $uid && $EUID == $uid && $GID eq "$gid $gid" && $EGID eq "$gid $gid");
57 my $proxyconf = PVE
::APIDaemon
::read_proxy_config
();
60 my ($result_hash, $alias, $subdir) = @_;
62 $result_hash->{$alias} = $subdir;
65 my $dir = $File::Find
::dir
;
66 if ($dir =~m!^$subdir(.*)$!) {
67 my $name = "$alias$1/";
68 $result_hash->{$name} = "$dir/";
72 find
({wanted
=> $wanted, follow
=> 0, no_chdir
=> 1}, $subdir);
81 add_dirs
($dirs, '/pve2/ext4/', '/usr/share/pve-manager/ext4/');
82 add_dirs
($dirs, '/pve2/images/' => '/usr/share/pve-manager/images/');
83 add_dirs
($dirs, '/pve2/css/' => '/usr/share/pve-manager/css/');
84 add_dirs
($dirs, '/pve2/js/' => '/usr/share/pve-manager/js/');
85 add_dirs
($dirs, '/vncterm/' => '/usr/share/vncterm/');
86 add_dirs
($dirs, '/novnc/' => '/usr/share/novnc-pve/');
88 $daemon = PVE
::APIDaemon-
>new(
89 base_handler_class
=> 'PVE::API2',
95 allow_from
=> $proxyconf->{ALLOW_FROM
},
96 deny_from
=> $proxyconf->{DENY_FROM
},
97 policy
=> $proxyconf->{POLICY
},
98 trusted_env
=> 0, # not trusted, anyone can connect
99 logfile
=> '/var/log/pveproxy/access.log',
100 lockfile
=> $lockfile,
102 cipher_list
=> $proxyconf->{CIPHERS
} || 'HIGH:MEDIUM:!aNULL:!MD5',
103 key_file
=> '/etc/pve/local/pve-ssl.key',
104 cert_file
=> '/etc/pve/local/pve-ssl.pem',
106 # Note: there is no authentication for those pages and dirs!
109 # avoid authentication when accessing favicon
111 file
=> '/usr/share/pve-manager/images/favicon.ico',
121 syslog
('err' , "unable to start server: $err");
127 if ($opt_debug || !($cpid = fork ())) {
129 $SIG{PIPE
} = 'IGNORE';
130 $SIG{INT
} = 'IGNORE' if !$opt_debug;
132 $SIG{TERM
} = $SIG{QUIT
} = sub {
133 syslog
('info' , "server closing");
135 $SIG{INT
} = 'DEFAULT';
137 unlink "$pidfile" if !$opt_debug;
142 syslog
('info' , "starting server");
145 # redirect STDIN/STDOUT/SDTERR to /dev/null
146 open STDIN
, '</dev/null' || die "can't read /dev/null [$!]";
147 open STDOUT
, '>/dev/null' || die "can't write /dev/null [$!]";
148 open STDERR
, '>&STDOUT' || die "can't open STDERR to STDOUT [$!]";
154 $daemon->start_server();
159 syslog
('err' , "unexpected server error: $err");
160 print STDERR
$err if $opt_debug;
166 open (PIDFILE
, ">$pidfile") ||
167 die "cant write '$pidfile' - $! :ERROR";
168 print PIDFILE
"$cpid\n";
170 die "cant write '$pidfile' - $! :ERROR";
175 # NOTE: Requests to those pages are not authenticated
176 # so we must be very careful here
179 my ($server, $r, $args) = @_;
185 if (my $cookie = $r->header('Cookie')) {
186 if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
187 if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
191 my $ticket = PVE
::REST
::extract_auth_cookie
($cookie);
192 if (($username = PVE
::AccessControl
::verify_ticket
($ticket, 1))) {
193 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
197 my $workspace = defined($args->{console
}) ?
198 "PVE.ConsoleWorkspace" : "PVE.StdWorkspace";
200 $username = '' if !$username;
204 PVE.UserName = '$username';
205 PVE.CSRFPreventionToken = '$token';
208 my $langfile = "/usr/share/pve-manager/ext4/locale/ext-lang-${lang}.js";
209 $jssrc .= PVE
::Tools
::file_get_contents
($langfile) if -f
$langfile;
212 $langfile = "/usr/share/pve-manager/root/pve-lang-${lang}.js";
214 $i18nsrc = PVE
::Tools
::file_get_contents
($langfile);
216 $i18nsrc = 'function gettext(buf) { return buf; }';
221 // we need this (the java applet ignores the zindex)
224 Ext.History.fieldid = 'x-history-field';
226 Ext.onReady(function() { Ext.create('$workspace');});
233 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
234 <meta http-equiv="X-UA-Compatible" content="IE=10">
235 <title>Proxmox Virtual Environment</title>
237 <link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" />
238 <link rel="stylesheet" type="text/css" href="/pve2/css/ext-pve.css" />
240 <script type="text/javascript">$i18nsrc</script>
241 <script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script>
242 <script type="text/javascript" src="/pve2/ext4/pvemanagerlib.js"></script>
243 <script type="text/javascript">$jssrc</script>
247 <!-- Fields required for history management -->
248 <form id="history-form" class="x-hidden">
249 <input type="hidden" id="x-history-field"/>
255 my $headers = HTTP
::Headers-
>new(Content_Type
=> "text/html; charset=utf-8");
256 my $resp = HTTP
::Response-
>new(200, "OK", $headers, $page);
265 pveproxy - the PVE API proxy server
273 This is the REST API proxy server, listening on port 8006. This is usually started
276 # service pveproxy start
278 =head1 Host based access control
280 It is possible to configure apache2 like access control lists. Values are read
281 from file /etc/default/pveproxy. For example:
283 ALLOW_FROM="10.0.0.1-10.0.0.5,192.168.0.0/22"
287 IP addresses can be specified using any syntax understoop by Net::IP. The
288 name 'all' is an alias for '0/0'.
290 The default policy is 'allow'.
292 Match | POLICY=deny | POLICY=allow
293 ---------------------------|-------------|------------
294 Match Allow only | allow | allow
295 Match Deny only | deny | deny
296 No match | deny | allow
297 Match Both Allow & Deny | deny | allow
299 =head1 SSL Cipher Suite
301 You can define the chiper list in /etc/default/pveproxy, for example
303 CIPHERS="HIGH:MEDIUM:!aNULL:!MD5"
305 Above is the default. See the ciphers(1) man page from the openssl
306 package for list of all available options.
310 /etc/default/pveproxy
312 =head1 COPYRIGHT AND DISCLAIMER
314 Copyright (C) 2007-2013 Proxmox Server Solutions GmbH
316 This program is free software: you can redistribute it and/or modify it
317 under the terms of the GNU Affero General Public License as published
318 by the Free Software Foundation, either version 3 of the License, or
319 (at your option) any later version.
321 This program is distributed in the hope that it will be useful, but
322 WITHOUT ANY WARRANTY; without even the implied warranty of
323 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
324 Affero General Public License for more details.
326 You should have received a copy of the GNU Affero General Public
327 License along with this program. If not, see
328 <http://www.gnu.org/licenses/>.