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);
50 novnc
=> '/usr/share/novnc-pve',
51 extjs
=> '/usr/share/javascript/extjs',
52 manager
=> '/usr/share/pve-manager',
53 docs
=> '/usr/share/pve-docs',
54 vncterm
=> '/usr/share/vncterm',
60 # we use same ALLOW/DENY/POLICY as pveproxy
61 my $proxyconf = PVE
::API2Tools
::read_proxy_config
();
63 my $accept_lock_fn = "/var/lock/pveproxy.lck";
65 my $lockfh = IO
::File-
>new(">>${accept_lock_fn}") ||
66 die "unable to open lock file '${accept_lock_fn}' - $!\n";
68 my $family = PVE
::Tools
::get_host_address_family
($self->{nodename
});
69 my $socket = $self->create_reusable_socket(8006, undef, $family);
73 add_dirs
($dirs, '/pve2/locale/', "$basedirs->{manager}/locale/");
74 add_dirs
($dirs, '/pve2/touch/', "$basedirs->{manager}/touch/");
75 add_dirs
($dirs, '/pve2/ext6/', "$basedirs->{extjs}/");
76 add_dirs
($dirs, '/pve2/images/' => "$basedirs->{manager}/images/");
77 add_dirs
($dirs, '/pve2/css/' => "$basedirs->{manager}/css/");
78 add_dirs
($dirs, '/pve2/js/' => "$basedirs->{manager}/js/");
79 add_dirs
($dirs, '/pve-docs/' => "$basedirs->{docs}/");
80 add_dirs
($dirs, '/vncterm/' => "$basedirs->{vncterm}/");
81 add_dirs
($dirs, '/novnc/' => "$basedirs->{novnc}/");
83 $self->{server_config
} = {
84 title
=> 'Proxmox VE API',
88 lockfile
=> $accept_lock_fn,
91 debug
=> $self->{debug
},
92 trusted_env
=> 0, # not trusted, anyone can connect
93 logfile
=> '/var/log/pveproxy/access.log',
94 allow_from
=> $proxyconf->{ALLOW_FROM
},
95 deny_from
=> $proxyconf->{DENY_FROM
},
96 policy
=> $proxyconf->{POLICY
},
98 # Note: older versions are considered insecure, for example
99 # search for "Poodle"-Attac
103 cipher_list
=> $proxyconf->{CIPHERS
} || 'HIGH:MEDIUM:!aNULL:!MD5',
104 key_file
=> '/etc/pve/local/pve-ssl.key',
105 cert_file
=> '/etc/pve/local/pve-ssl.pem',
107 # Note: there is no authentication for those pages and dirs!
109 '/' => sub { get_index
($self->{nodename
}, @_) },
110 # avoid authentication when accessing favicon
112 file
=> "$basedirs->{manager}/images/favicon.ico",
118 if ($proxyconf->{DHPARAMS
}) {
119 $self->{server_config
}->{ssl
}->{dh_file
} = $proxyconf->{DHPARAMS
};
121 $self->{server_config
}->{ssl
}->{dh
} = 'skip2048';
124 if (-f
'/etc/pve/local/pveproxy-ssl.pem' && -f
'/etc/pve/local/pveproxy-ssl.key') {
125 $self->{server_config
}->{ssl
}->{cert_file
} = '/etc/pve/local/pveproxy-ssl.pem';
126 $self->{server_config
}->{ssl
}->{key_file
} = '/etc/pve/local/pveproxy-ssl.key';
127 syslog
('info', 'Using \'/etc/pve/local/pveproxy-ssl.pem\' as certificate for the web interface.');
134 my $server = PVE
::HTTPServer-
>new(%{$self->{server_config
}});
138 $daemon->register_start_command();
139 $daemon->register_restart_command(1);
140 $daemon->register_stop_command();
141 $daemon->register_status_command();
144 start
=> [ __PACKAGE__
, 'start', []],
145 restart
=> [ __PACKAGE__
, 'restart', []],
146 stop
=> [ __PACKAGE__
, 'stop', []],
147 status
=> [ __PACKAGE__
, 'status', [], undef, sub { print shift . "\n";} ],
155 return 1 if $ua =~ m/(iPhone|iPod|Windows Phone)/;
157 if ($ua =~ m/Mobile(\/|\s
)/) {
158 return 1 if $ua =~ m/(BlackBerry|BB)/;
159 return 1 if ($ua =~ m/(Android)/) && ($ua !~ m/(Silk)/);
165 # NOTE: Requests to those pages are not authenticated
166 # so we must be very careful here
169 my ($nodename, $server, $r, $args) = @_;
175 if (my $cookie = $r->header('Cookie')) {
176 if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
177 if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
181 my $ticket = PVE
::APIServer
::Formatter
::extract_auth_cookie
($cookie, $server->{cookie_name
});
182 if (($username = PVE
::AccessControl
::verify_ticket
($ticket, 1))) {
183 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
187 $username = '' if !$username;
189 my $mobile = is_phone
($r->header('User-Agent')) ?
1 : 0;
191 if (defined($args->{mobile
})) {
192 $mobile = $args->{mobile
} ?
1 : 0;
197 if (defined($args->{console
}) && $args->{novnc
}) {
198 $page = PVE
::NoVncIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
200 $page = PVE
::TouchIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
202 $page = PVE
::ExtJSIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename,
205 my $headers = HTTP
::Headers-
>new(Content_Type
=> "text/html; charset=utf-8");
206 my $resp = HTTP
::Response-
>new(200, "OK", $headers, $page);