3 $ENV{'PATH'} = '/sbin:/bin:/usr/sbin:/usr/bin';
5 delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
10 use POSIX
":sys_wait_h";
14 # use PVE::Config; # fixme
24 my $pidfile = "/var/run/pveproxy.pid";
25 my $lockfile = "/var/lock/pveproxy.lck";
31 if (!GetOptions
('debug' => \
$opt_debug)) {
32 die "usage: $0 [--debug]\n";
35 $SIG{'__WARN__'} = sub {
39 syslog
('warning', "WARNING: %s", $t);
45 PVE
::APIDaemon
::enable_debug
() if $opt_debug;
48 my ($result_hash, $alias, $subdir) = @_;
50 $result_hash->{$alias} = $subdir;
53 my $dir = $File::Find
::dir
;
54 if ($dir =~m!^$subdir(.*)$!) {
55 my $name = "$alias$1/";
56 $result_hash->{$name} = "$dir/";
60 find
({wanted
=> $wanted, follow
=> 0, no_chdir
=> 1}, $subdir);
69 add_dirs
($dirs, '/pve2/ext4/', '/usr/share/pve-manager/ext4/');
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, '/vncterm/' => '/usr/share/vncterm/');
74 $daemon = PVE
::APIDaemon-
>new(
79 trusted_env
=> 0, # not trusted, anyone can connect
80 logfile
=> '/var/log/pve/access.log',
81 lockfile
=> $lockfile,
83 key_file
=> '/etc/pve/local/pve-ssl.key',
84 cert_file
=> '/etc/pve/local/pve-ssl.pem',
86 # Note: there is no authentication for those pages and dirs!
89 # avoid authentication when accessing favicon
91 file
=> '/usr/share/pve-manager/images/favicon.ico',
101 syslog
('err' , "unable to start server: $err");
106 if ($opt_debug || !($cpid = fork ())) {
108 $SIG{PIPE
} = 'IGNORE';
109 $SIG{INT
} = 'IGNORE' if !$opt_debug;
111 $SIG{TERM
} = $SIG{QUIT
} = sub {
112 syslog
('info' , "server closing");
114 $SIG{INT
} = 'DEFAULT';
121 syslog
('info' , "starting server");
124 # redirect STDIN/STDOUT/SDTERR to /dev/null
125 open STDIN
, '</dev/null' || die "can't read /dev/null [$!]";
126 open STDOUT
, '>/dev/null' || die "can't write /dev/null [$!]";
127 open STDERR
, '>&STDOUT' || die "can't open STDERR to STDOUT [$!]";
133 $daemon->start_server();
138 syslog
('err' , "unexpected server error: $err");
139 print STDERR
$err if $opt_debug;
145 open (PIDFILE
, ">$pidfile") ||
146 die "cant write '$pidfile' - $! :ERROR";
147 print PIDFILE
"$cpid\n";
149 die "cant write '$pidfile' - $! :ERROR";
154 # NOTE: Requests to those pages are not authenticated
155 # so we must be very careful here
158 my ($server, $r, $params) = @_;
164 if (my $cookie = $r->header('Cookie')) {
165 if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
166 if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
170 my $ticket = PVE
::REST
::extract_auth_cookie
($cookie);
171 if (($username = PVE
::AccessControl
::verify_ticket
($ticket, 1))) {
172 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
176 my $args = $r->url->query_form_hash();
178 my $workspace = defined($args->{console
}) ?
179 "PVE.ConsoleWorkspace" : "PVE.StdWorkspace";
181 $username = '' if !$username;
185 PVE.UserName = '$username';
186 PVE.CSRFPreventionToken = '$token';
189 my $langfile = "/usr/share/pve-manager/ext4/locale/ext-lang-${lang}.js";
190 $jssrc .= PVE
::Tools
::file_get_contents
($langfile) if -f
$langfile;
193 $langfile = "/usr/share/pve-manager/root/pve-lang-${lang}.js";
195 $i18nsrc = PVE
::Tools
::file_get_contents
($langfile);
197 $i18nsrc = 'function gettext(buf) { return buf; }';
202 // we need this (the java applet ignores the zindex)
205 Ext.History.fieldid = 'x-history-field';
207 Ext.onReady(function() { Ext.create('$workspace');});
214 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
216 <title>Proxmox Virtual Environment</title>
218 <link rel="stylesheet" type="text/css" href="/pve2/ext4/resources/css/ext-all.css" />
219 <link rel="stylesheet" type="text/css" href="/pve2/css/ext-pve.css" />
221 <script type="text/javascript">$i18nsrc</script>
222 <script type="text/javascript" src="/pve2/ext4/ext-all-debug.js"></script>
223 <script type="text/javascript" src="/pve2/ext4/pvemanagerlib.js"></script>
224 <script type="text/javascript">$jssrc</script>
228 <!-- Fields required for history management -->
229 <form id="history-form" class="x-hidden">
230 <input type="hidden" id="x-history-field"/>
236 my $resp = HTTP
::Response-
>new(200, "OK", undef, $page);
245 pveproxy - the PVE API proxy server
253 This is the REST API proxy server, listening on port 8006.