3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
8 * The main author of Baculum is Marcin Haba.
9 * The original author of Bacula is Kern Sibbald, with contributions
10 * from many others, a complete list can be found in the file AUTHORS.
12 * You may use this file and others of this release according to the
13 * license defined in the LICENSE file, which includes the Affero General
14 * Public License, v3.0 ("AGPLv3") and some additional permissions and
15 * terms pursuant to its AGPLv3 Section 7.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 Prado::using('System.Web.UI.TPage');
27 * The module contains methods that are common for all pages (wizards, main
28 * page and error pages).
30 * @author Marcin Haba <marcin.haba@bacula.pl>
32 class BaculumPage extends TPage {
34 public function onPreInit($param) {
35 parent::onPreInit($param);
36 $this->setURLPrefixForSubdir();
40 * Shortcut method for getting application modules instances by
44 * @param string $name application module name
45 * @return object module class instance
47 public function getModule($name) {
48 return $this->getApplication()->getModule($name);
52 * Redirection to a page.
53 * Page name is given in PRADO notation with "dot", for example: (Home.SomePage).
56 * @param string $page_name page name to redirect
57 * @param array $params HTTP GET method parameters in associative array
60 public function goToPage($page_name, $params = null) {
61 $url = $this->Service->constructUrl($page_name, $params, false);
62 $url = str_replace('/index.php', '', $url);
63 header('Location: ' . $url);
68 * Redirection to default page defined in application config.
71 * @param array $params HTTP GET method parameters in associative array
74 public function goToDefaultPage($params = null) {
75 $this->goToPage($this->Service->DefaultPage, $params);
79 * Set prefix when Baculum is running in document root subdirectory.
81 * web server document root: /var/www/
82 * Baculum directory /var/www/baculum/
83 * URL prefix: /baculum/
84 * In this case to base url is added '/baculum/' such as:
85 * http://localhost:9095/baculum/
90 private function setURLPrefixForSubdir() {
91 $full_document_root = preg_replace('#(\/)$#', '', $this->getFullDocumentRoot());
92 $url_prefix = str_replace($full_document_root, '', APPLICATION_DIRECTORY);
93 if (!empty($url_prefix)) {
94 $this->Application->getModule('url_manager')->setUrlPrefix($url_prefix);
99 * Get full document root directory path.
100 * Symbolic links in document root path are translated to full paths.
103 * return string full document root directory path
105 private function getFullDocumentRoot() {
107 $dirs = explode('/', $_SERVER['DOCUMENT_ROOT']);
108 for($i = 0; $i < count($dirs); $i++) {
109 $document_root_part = implode('/', $root_dir) . '/' . $dirs[$i];
110 if (is_link($document_root_part)) {
111 $root_dir = array(readlink($document_root_part));
113 $root_dir[] = $dirs[$i];
117 $root_dir = implode('/', $root_dir);
122 * Log in as specific user.
124 * Note, usually after this method call there required is using exit() just
125 * after method execution. Otherwise the HTTP redirection may be canceled on some
129 * @param string $user user name to log in
130 * @param string $string plain text user's password
133 public function switchToUser($user, $password) {
134 $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
135 $host = $_SERVER['SERVER_NAME'];
136 $port = $_SERVER['SERVER_PORT'];
137 $url_prefix = $this->Application->getModule('url_manager')->getUrlPrefix();
138 $url_prefix = str_replace('/index.php', '', $url_prefix);
139 $location = sprintf("%s://%s:%s@%s:%d%s", $http_protocol, $user, $password, $host, $port, $url_prefix);
142 header("Location: $location");