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.ActiveControls.TActiveButton');
24 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
25 Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
26 Prado::using('System.Web.UI.ActiveControls.TActiveCheckBox');
27 Prado::using('System.Web.UI.ActiveControls.TActiveLinkButton');
29 class Home extends BaculumPage
31 protected $app_config;
35 public $openWindow = null;
37 public $initWindowId = null;
39 public $initElementId = null;
41 public $jobs_states = null;
45 public $windowIds = array('Storage', 'Client', 'Volume', 'Pool', 'Job', 'JobRun');
49 public function onPreInit($param) {
50 parent::onPreInit($param);
51 if (!$this->IsPostBack && !$this->IsCallBack) {
53 * Reload page if refresh_page written in session.
54 * Useful in login and re-login (back from wizards).
55 * Otherwise HTTP Basic login prompt occurs.
57 if (array_key_exists('refresh_page', $_SESSION)) {
58 $refresh_page = $_SESSION['refresh_page'];
59 header('Location: ' . $refresh_page);
60 unset($_SESSION['refresh_page']);
66 public function onInit($param) {
67 parent::onInit($param);
68 $this->Application->getModule('users')->loginUser();
70 if (!$this->IsPostBack && !$this->IsCallBack) {
71 $this->getModule('api')->initSessionCache(true);
74 $isConfigExists = $this->getModule('configuration')->isApplicationConfig();
75 if($isConfigExists === false) {
76 $this->goToPage('ConfigurationWizard');
79 $this->userPattern = $this->getModule('configuration')->getUserPattern();
80 $this->app_config = $this->getModule('configuration')->getApplicationConfig();
82 $this->Users->Visible = $this->User->getIsAdmin();
83 $this->SettingsWizardBtn->Visible = $this->User->getIsAdmin();
84 $this->PoolBtn->Visible = $this->User->getIsAdmin();
85 $this->VolumeBtn->Visible = $this->User->getIsAdmin();
86 $this->ClearBvfsCache->Visible = $this->User->getIsAdmin();
87 $this->Logging->Visible = $this->User->getIsAdmin();
88 $this->BconsoleCustomPath->Text = $this->app_config['bconsole']['cfg_custom_path'];
90 if(!$this->IsPostBack && !$this->IsCallBack) {
91 $this->Logging->Checked = $this->getModule('logging')->isDebugOn();
94 if(!$this->IsPostBack && !$this->IsCallBack) {
95 $directors = $this->getModule('api')->get(array('directors'))->output;
96 if(!array_key_exists('director', $_SESSION) || $directors[0] != $_SESSION['director']) {
97 $_SESSION['director'] = $directors[0];
99 $this->Director->dataSource = array_combine($directors, $directors);
100 $this->Director->SelectedValue = $_SESSION['director'];
101 $this->Director->dataBind();
102 if ($this->User->getIsAdmin() === true) {
103 $this->dbtype = $this->getModule('configuration')->getDbNameByType($this->app_config['db']['type']);
105 $this->setJobsStates();
109 $this->setWindowOpen();
113 public function restore($sender, $param) {
114 $this->goToPage('RestoreWizard');
117 public function configuration($sender, $param) {
118 $this->goToPage('ConfigurationWizard');
121 public function director($sender, $param) {
122 $_SESSION['director'] = $this->Director->SelectedValue;
125 public function setDebug($sender, $param) {
126 if($this->User->getIsAdmin() === true) {
127 $this->getModule('logging')->enableDebug($this->Logging->Checked);
128 $this->goToDefaultPage();
132 public function clearBvfsCache($sender, $param) {
133 if($this->User->getIsAdmin() === true) {
134 $this->getModule('api')->set(array('bvfs', 'clear'), array());
138 public function getJobs() {
139 return json_encode($this->jobs);
142 public function setJobsStates() {
143 $jobs_summary = array(
146 'warning' => array(),
150 $job_types = $jobs_summary;
151 $job_states = array();
153 $misc = $this->getModule('misc');
154 foreach($job_types as $type => $arr) {
155 $states = $misc->getJobStatesByType($type);
156 foreach($states as $state => $desc) {
157 $desc['type'] = $type;
158 $jobs_states[$state] = $desc;
162 $this->jobs_states = json_encode($jobs_states);
165 public function setJobs() {
166 $this->jobs = $this->getModule('api')->get(array('jobs'));
167 $jobs = array('@' => Prado::localize('select job'));
168 foreach($this->jobs->output as $key => $job) {
169 $jobs[$job->name] = $job->name;
171 $this->Jobs->dataSource = $jobs;
172 $this->Jobs->dataBind();
175 public function setClients() {
176 $clients_obj = $this->getModule('api')->get(array('clients'));
177 $clients = array('@' => Prado::localize('select client'));
178 foreach($clients_obj->output as $key => $client) {
179 $clients[$client->clientid] = $client->name;
181 $this->Clients->dataSource = $clients;
182 $this->Clients->dataBind();
185 public function setUsers() {
186 if($this->User->getIsAdmin() === true) {
187 $allUsers = $this->getModule('configuration')->getAllUsers();
188 $users = array_keys($allUsers);
190 $this->UsersList->dataSource = $users;
191 $this->UsersList->dataBind();
195 public function userAction($sender, $param) {
196 if($this->User->getIsAdmin() === true) {
197 list($action, $param, $value) = explode(';', $param->CallbackParameter, 3);
203 if ($param === $this->app_config['baculum']['login']) {
204 $this->app_config['baculum']['password'] = $value;
205 $valid = $this->getModule('configuration')->setApplicationConfig($this->app_config);
208 if ($valid === true) {
209 $this->getModule('configuration')->setUsersConfig($param, $value);
211 if ($admin === true) {
212 // if admin password changed then try to auto-login by async request
213 $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
214 $this->getModule('configuration')->switchToUser(
216 $_SERVER['SERVER_NAME'],
217 $_SERVER['SERVER_PORT'],
223 // if normal user's password changed then update users grid
229 if ($param != $this->User->getName()) {
230 $this->getModule('configuration')->removeUser($param);
239 public function setWindowOpen() {
240 if (isset($this->Request['open']) && in_array($this->Request['open'], $this->windowIds) && $this->Request['open'] != 'JobRun') {
241 $btn = $this->Request['open'] . 'Btn';
242 $this->openWindow = $this->{$btn}->ClientID;
243 if (isset($this->Request['id']) && (is_numeric($this->Request['id']))) {
244 $this->initWindowId = $this->Request['open'];
245 $this->initElementId = $this->Request['id'];
250 public function logout($sender, $param) {
251 $cfg = $this->getModule('configuration');
252 $http_protocol = isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) ? 'https' : 'http';
253 $fake_pwd = $cfg->getRandomString();
254 $cfg->switchToUser($http_protocol, $_SERVER['SERVER_NAME'], $_SERVER['SERVER_PORT'], $this->User->getName(), $fake_pwd);