3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2017 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.TActiveLabel');
24 Prado::using('System.Web.UI.ActiveControls.TActiveButton');
25 Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
26 Prado::using('System.Web.UI.TTemplateControl');
27 Prado::using('Application.Common.Class.OAuth2');
28 Prado::using('Application.Common.Portlets.PortletTemplate');
30 class NewHost extends PortletTemplate {
32 private $error = false;
34 private $show_buttons = true;
36 private $client_mode = false;
38 private $force_host_name;
40 private $api_required;
42 public function onLoad($param) {
43 $host_name = $this->getForceHostName();
44 if (!empty($host_name)) {
45 $this->APIHostName->Text = $host_name;
46 $this->APIHostName->setReadOnly(true);
50 public function connectionAPITest($sender, $param) {
51 $host = $this->APIAddress->Text;
56 'protocol' => $this->APIProtocol->SelectedValue,
57 'address' => $this->APIAddress->Text,
58 'port' => $this->APIPort->Text,
62 if ($this->AuthBasic->Checked) {
63 $host_params['auth_type'] = 'basic';
64 $host_params['login'] = $this->APIBasicLogin->Text;
65 $host_params['password'] = $this->APIBasicPassword->Text;
66 } elseif ($this->AuthOAuth2->Checked) {
67 $host_params['auth_type'] = 'oauth2';
68 $host_params['client_id'] = $this->APIOAuth2ClientId->Text;
69 $host_params['client_secret'] = $this->APIOAuth2ClientSecret->Text;
70 $host_params['redirect_uri'] = $this->APIOAuth2RedirectURI->Text;
71 $host_params['scope'] = $this->APIOAuth2Scope->Text;
73 $api = $this->getModule('api');
76 $api->setHostParams($host, $host_params);
77 $catalog = $api->get(array('catalog'), $host, false);
80 $api->setHostParams($host, $host_params);
81 $console = $api->set(array('console'), array('version'), $host, false);
84 $api->setHostParams($host, $host_params);
85 $config = $api->get(array('config'), $host, false);
87 $is_catalog = (is_object($catalog) && $catalog->error === 0);
88 $is_console = (is_object($console) && $console->error === 0);
89 $is_config = (is_object($config) && $config->error === 0);
92 if (in_array('catalog', $this->api_required)) {
93 $status_ok = $is_catalog;
95 if ($status_ok && in_array('console', $this->api_required)) {
96 $status_ok = $is_console;
98 if ($status_ok && in_array('config', $this->api_required)) {
99 $status_ok = $is_config;
102 $this->APITestResultOk->Display = ($status_ok === true) ? 'Dynamic' : 'None';
103 $this->APITestResultErr->Display = ($status_ok === false) ? 'Dynamic' : 'None';
104 $this->APICatalogSupportYes->Display = ($is_catalog === true) ? 'Dynamic' : 'None';
105 $this->APICatalogSupportNo->Display = ($is_catalog === false) ? 'Dynamic' : 'None';
106 $this->APIConsoleSupportYes->Display = ($is_console === true) ? 'Dynamic' : 'None';
107 $this->APIConsoleSupportNo->Display = ($is_console === false) ? 'Dynamic' : 'None';
108 $this->APIConfigSupportYes->Display = ($is_config === true) ? 'Dynamic' : 'None';
109 $this->APIConfigSupportNo->Display = ($is_config === false) ? 'Dynamic' : 'None';
112 public function addNewHost($sender, $param) {
118 'client_secret' => '',
119 'redirect_uri' => '',
122 $cfg_host['protocol'] = $this->APIProtocol->Text;
123 $cfg_host['address'] = $this->APIAddress->Text;
124 $cfg_host['port'] = $this->APIPort->Text;
125 $cfg_host['url_prefix'] = '';
126 $cfg_host['login'] = $this->APIBasicLogin->Text;
127 $cfg_host['password'] = $this->APIBasicPassword->Text;
128 if ($this->AuthBasic->Checked == true) {
129 $cfg_host['auth_type'] = 'basic';
130 $cfg_host['login'] = $this->APIBasicLogin->Text;
131 $cfg_host['password'] = $this->APIBasicPassword->Text;
132 } elseif($this->AuthOAuth2->Checked == true) {
133 $cfg_host['auth_type'] = 'oauth2';
134 $cfg_host['client_id'] = $this->APIOAuth2ClientId->Text;
135 $cfg_host['client_secret'] = $this->APIOAuth2ClientSecret->Text;
136 $cfg_host['redirect_uri'] = $this->APIOAuth2RedirectURI->Text;
137 $cfg_host['scope'] = $this->APIOAuth2Scope->Text;
139 $config = $this->getModule('host_config')->getConfig();
140 $this->NewHostAddOk->Display = 'None';
141 $this->NewHostAddError->Display = 'None';
142 $this->NewHostAddExists->Display = 'None';
143 $host_name = trim($this->APIHostName->Text);
144 if (empty($host_name)) {
145 $host_name = $cfg_host['address'];
147 if (!array_key_exists($host_name, $config)) {
148 $config[$host_name] = $cfg_host;
149 $res = $this->getModule('host_config')->setConfig($config);
151 $this->APIAddress->Text = '';
152 $this->APIPort->Text = '9096';
153 $this->APIBasicLogin->Text = '';
154 $this->APIBasicPassword->Text = '';
155 $this->APIHostName->Text = '';
156 $this->NewHostAddOk->Display = 'Dynamic';
157 $this->APITestResultOk->Display = 'None';
158 $this->APITestResultErr->Display = 'None';
159 $this->APICatalogSupportYes->Display = 'None';
160 $this->APICatalogSupportNo->Display = 'None';
161 $this->APIConsoleSupportYes->Display = 'None';
162 $this->APIConsoleSupportNo->Display = 'None';
163 $this->APIConfigSupportYes->Display = 'None';
164 $this->APIConfigSupportNo->Display = 'None';
167 $this->NewHostAddError->Display = 'Dynamic';
170 $this->NewHostAddExists->Display = 'Dynamic';
172 $this->onCallback($param);
175 public function setForceHostName($host_name) {
176 $this->force_host_name = $host_name;
179 public function getForceHostName() {
180 return $this->force_host_name;
183 public function setShowButtons($show) {
184 $show = TPropertyValue::ensureBoolean($show);
185 $this->show_buttons = $show;
188 public function getShowButtons() {
189 return $this->show_buttons;
192 public function bubbleEvent($sender, $param) {
193 if ($param instanceof TCommandEventParameter) {
194 if ($this->error === true) {
195 $this->raiseBubbleEvent($this,$param);
203 public function setAPIRequired($api_required) {
204 $this->api_required = explode('|', $api_required);
207 public function getAPIRequired() {
208 return $this->api_required;
211 public function setClientMode($client_mode) {
212 $client_mode = TPropertyValue::ensureBoolean($client_mode);
213 $this->client_mode = $client_mode;
216 public function getClientMode() {
217 return $this->client_mode;
220 public function onCallback($param) {
221 $this->raiseEvent('OnCallback', $this, $param);