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, '/pve2/js/' => '/usr/share/pve-manager/js/');
73 add_dirs
($dirs, '/pve-docs/' => '/usr/share/pve-docs/');
74 add_dirs
($dirs, '/vncterm/' => '/usr/share/vncterm/');
75 add_dirs
($dirs, '/novnc/' => '/usr/share/novnc-pve/');
77 $self->{server_config
} = {
78 title
=> 'Proxmox VE API',
82 lockfile
=> $accept_lock_fn,
85 debug
=> $self->{debug
},
86 trusted_env
=> 0, # not trusted, anyone can connect
87 logfile
=> '/var/log/pveproxy/access.log',
88 allow_from
=> $proxyconf->{ALLOW_FROM
},
89 deny_from
=> $proxyconf->{DENY_FROM
},
90 policy
=> $proxyconf->{POLICY
},
92 # Note: older versions are considered insecure, for example
93 # search for "Poodle"-Attac
97 cipher_list
=> $proxyconf->{CIPHERS
} || 'HIGH:MEDIUM:!aNULL:!MD5',
98 key_file
=> '/etc/pve/local/pve-ssl.key',
99 cert_file
=> '/etc/pve/local/pve-ssl.pem',
101 # Note: there is no authentication for those pages and dirs!
103 '/' => sub { get_index
($self->{nodename
}, @_) },
104 # avoid authentication when accessing favicon
106 file
=> '/usr/share/pve-manager/images/favicon.ico',
112 if ($proxyconf->{DHPARAMS
}) {
113 $self->{server_config
}->{ssl
}->{dh_file
} = $proxyconf->{DHPARAMS
};
115 $self->{server_config
}->{ssl
}->{dh
} = 'skip2048';
118 if (-f
'/etc/pve/local/pveproxy-ssl.pem' && -f
'/etc/pve/local/pveproxy-ssl.key') {
119 $self->{server_config
}->{ssl
}->{cert_file
} = '/etc/pve/local/pveproxy-ssl.pem';
120 $self->{server_config
}->{ssl
}->{key_file
} = '/etc/pve/local/pveproxy-ssl.key';
121 syslog
('info', 'Using \'/etc/pve/local/pveproxy-ssl.pem\' as certificate for the web interface.');
128 my $server = PVE
::HTTPServer-
>new(%{$self->{server_config
}});
132 $daemon->register_start_command();
133 $daemon->register_restart_command(1);
134 $daemon->register_stop_command();
135 $daemon->register_status_command();
138 start
=> [ __PACKAGE__
, 'start', []],
139 restart
=> [ __PACKAGE__
, 'restart', []],
140 stop
=> [ __PACKAGE__
, 'stop', []],
141 status
=> [ __PACKAGE__
, 'status', [], undef, sub { print shift . "\n";} ],
149 return 1 if $ua =~ m/(iPhone|iPod|Windows Phone)/;
151 if ($ua =~ m/Mobile(\/|\s
)/) {
152 return 1 if $ua =~ m/(BlackBerry|BB)/;
153 return 1 if ($ua =~ m/(Android)/) && ($ua !~ m/(Silk)/);
159 # NOTE: Requests to those pages are not authenticated
160 # so we must be very careful here
163 my ($nodename, $server, $r, $args) = @_;
169 if (my $cookie = $r->header('Cookie')) {
170 if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
171 if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
175 my $ticket = PVE
::APIServer
::Formatter
::extract_auth_cookie
($cookie, $server->{cookie_name
});
176 if (($username = PVE
::AccessControl
::verify_ticket
($ticket, 1))) {
177 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
181 $username = '' if !$username;
183 my $mobile = is_phone
($r->header('User-Agent')) ?
1 : 0;
185 if (defined($args->{mobile
})) {
186 $mobile = $args->{mobile
} ?
1 : 0;
191 if (defined($args->{console
}) && $args->{novnc
}) {
192 $page = PVE
::NoVncIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
194 $page = PVE
::TouchIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
196 $page = PVE
::ExtJSIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename,
199 my $headers = HTTP
::Headers-
>new(Content_Type
=> "text/html; charset=utf-8");
200 my $resp = HTTP
::Response-
>new(200, "OK", $headers, $page);