1 package PVE
::Service
::pveproxy
;
16 use PVE
::API2
::Formatter
::Standard
;
17 use PVE
::API2
::Formatter
::HTML
;
26 use base
qw(PVE::Daemon);
28 my $cmdline = [$0, @ARGV];
30 my %daemon_options = (
32 restart_on_error
=> 5,
34 leave_children_open_on_reload
=> 1,
37 pidfile
=> '/var/run/pveproxy/pveproxy.pid',
40 my $daemon = __PACKAGE__-
>new('pveproxy', $cmdline, %daemon_options);
43 my ($result_hash, $alias, $subdir) = @_;
45 $result_hash->{$alias} = $subdir;
48 my $dir = $File::Find
::dir
;
49 if ($dir =~m!^$subdir(.*)$!) {
50 my $name = "$alias$1/";
51 $result_hash->{$name} = "$dir/";
55 find
({wanted
=> $wanted, follow
=> 0, no_chdir
=> 1}, $subdir);
61 # we use same ALLOW/DENY/POLICY as pveproxy
62 my $proxyconf = PVE
::API2Tools
::read_proxy_config
();
64 my $accept_lock_fn = "/var/lock/pveproxy.lck";
66 my $lockfh = IO
::File-
>new(">>${accept_lock_fn}") ||
67 die "unable to open lock file '${accept_lock_fn}' - $!\n";
69 my $family = PVE
::Tools
::get_host_address_family
($self->{nodename
});
70 my $socket = $self->create_reusable_socket(8006, undef, $family);
74 add_dirs
($dirs, '/pve2/locale/', '/usr/share/pve-manager/locale/');
75 add_dirs
($dirs, '/pve2/touch/', '/usr/share/pve-manager/touch/');
76 add_dirs
($dirs, '/pve2/ext6/', '/usr/share/pve-manager/ext6/');
77 add_dirs
($dirs, '/pve2/manager6/', '/usr/share/pve-manager/manager6/');
79 add_dirs
($dirs, '/pve2/images/' => '/usr/share/pve-manager/images/');
80 add_dirs
($dirs, '/pve2/css/' => '/usr/share/pve-manager/css/');
81 add_dirs
($dirs, '/pve2/js/' => '/usr/share/pve-manager/js/');
82 add_dirs
($dirs, '/pve-docs/' => '/usr/share/pve-docs/');
83 add_dirs
($dirs, '/vncterm/' => '/usr/share/vncterm/');
84 add_dirs
($dirs, '/novnc/' => '/usr/share/novnc-pve/');
86 $self->{server_config
} = {
87 base_handler_class
=> 'PVE::API2',
91 lockfile
=> $accept_lock_fn,
94 debug
=> $self->{debug
},
95 trusted_env
=> 0, # not trusted, anyone can connect
96 logfile
=> '/var/log/pveproxy/access.log',
97 allow_from
=> $proxyconf->{ALLOW_FROM
},
98 deny_from
=> $proxyconf->{DENY_FROM
},
99 policy
=> $proxyconf->{POLICY
},
101 # Note: older versions are considered insecure, for example
102 # search for "Poodle"-Attac
106 cipher_list
=> $proxyconf->{CIPHERS
} || 'HIGH:MEDIUM:!aNULL:!MD5',
107 key_file
=> '/etc/pve/local/pve-ssl.key',
108 cert_file
=> '/etc/pve/local/pve-ssl.pem',
110 # Note: there is no authentication for those pages and dirs!
112 '/' => sub { get_index
($self->{nodename
}, @_) },
113 # avoid authentication when accessing favicon
115 file
=> '/usr/share/pve-manager/images/favicon.ico',
121 if ($proxyconf->{DHPARAMS
}) {
122 $self->{server_config
}->{ssl
}->{dh_file
} = $proxyconf->{DHPARAMS
};
124 $self->{server_config
}->{ssl
}->{dh
} = 'skip2048';
127 if (-f
'/etc/pve/local/pveproxy-ssl.pem' && -f
'/etc/pve/local/pveproxy-ssl.key') {
128 $self->{server_config
}->{ssl
}->{cert_file
} = '/etc/pve/local/pveproxy-ssl.pem';
129 $self->{server_config
}->{ssl
}->{key_file
} = '/etc/pve/local/pveproxy-ssl.key';
130 syslog
('info', 'Using \'/etc/pve/local/pveproxy-ssl.pem\' as certificate for the web interface.');
137 my $server = PVE
::HTTPServer-
>new(%{$self->{server_config
}});
141 $daemon->register_start_command();
142 $daemon->register_restart_command(1);
143 $daemon->register_stop_command();
144 $daemon->register_status_command();
147 start
=> [ __PACKAGE__
, 'start', []],
148 restart
=> [ __PACKAGE__
, 'restart', []],
149 stop
=> [ __PACKAGE__
, 'stop', []],
150 status
=> [ __PACKAGE__
, 'status', [], undef, sub { print shift . "\n";} ],
158 return 1 if $ua =~ m/(iPhone|iPod|Windows Phone)/;
160 if ($ua =~ m/Mobile(\/|\s
)/) {
161 return 1 if $ua =~ m/(BlackBerry|BB)/;
162 return 1 if ($ua =~ m/(Android)/) && ($ua !~ m/(Silk)/);
168 # NOTE: Requests to those pages are not authenticated
169 # so we must be very careful here
172 my ($nodename, $server, $r, $args) = @_;
178 if (my $cookie = $r->header('Cookie')) {
179 if (my $newlang = ($cookie =~ /(?:^|\s)PVELangCookie=([^;]*)/)[0]) {
180 if ($newlang =~ m/^[a-z]{2,3}(_[A-Z]{2,3})?$/) {
184 my $ticket = PVE
::HTTPServer
::extract_auth_cookie
($cookie, $server->{cookie_name
});
185 if (($username = PVE
::AccessControl
::verify_ticket
($ticket, 1))) {
186 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
190 $username = '' if !$username;
192 my $mobile = is_phone
($r->header('User-Agent')) ?
1 : 0;
194 if (defined($args->{mobile
})) {
195 $mobile = $args->{mobile
} ?
1 : 0;
200 if (defined($args->{console
}) && $args->{novnc
}) {
201 $page = PVE
::NoVncIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
203 $page = PVE
::TouchIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename);
205 $page = PVE
::ExtJSIndex
::get_index
($lang, $username, $token, $args->{console
}, $nodename,
208 my $headers = HTTP
::Headers-
>new(Content_Type
=> "text/html; charset=utf-8");
209 my $resp = HTTP
::Response-
>new(200, "OK", $headers, $page);