1 <%@ MasterClass="Application.API.Layouts.Main" Theme="Baculum-v1"%>
2 <com:TContent ID="Main">
3 <com:TClientScript ScriptUrl=<%~ ../../JavaScript/misc.js %> />
4 <h3 style="clear: left">Welcome on the Baculum API default page <input type="button" class="bbutton" onclick="window.location.href='<%=$this->getService()->constructUrl('Panel.APIInstallWizard')%>'" value="<%[ Go to configuration wizard ]%>" style="float: right" /></h3>
7 <li><a href="#tab1">Baculum API Client</a></li>
8 <li><a href="#tab2"><%[ List HTTP Basic users ]%></a></li>
9 <li><a href="#tab3"><%[ List OAuth2 clients ]%></a></li>
12 <p>Here you can try one from API commands</p>
14 <com:TJuiProgressbar ID="Progress" Options.Max="3" Options.Value="false" Width="700px" CssClass="center" Style="float: left">
15 <span id="progress_label">Starting...</span>
16 </com:TJuiProgressbar>
17 <img id="api_refresh" src="<%=$this->getPage()->getTheme()->getBaseUrl()%>/icon_refresh.png" alt="<%[ Refresh token ]%>" title="<%[ Refresh token ]%>" onclick="oAPIHome.init_oauth2_client();" />
19 <div style="clear: left; margin-top: 60px;">
20 <select id="section" class="api_select">
21 <option value="none"><%[ Please select API endpoint ]%></option>
22 <option value="storages">storages</option>
23 <option value="clients">clients</option>
24 <option value="volumes">volumes</option>
25 <option value="jobs">jobs</option>
26 <option value="joblog">joblog</option>
27 <option value="bvfs">bvfs</option>
29 <input id="api_command" name="command" onkeydown="if (event.keyCode == 13) { oAPIHome.send_request(); }" /> <input class="api_button" type="button" name="apply" value="Send request" onclick="oAPIHome.send_request();" />
32 <pre id="api_result"></pre>
36 <input type="button" class="bbutton" onclick="$('#<%=$this->NewBasicClient->ClientID%>new_auth_client').slideToggle();" value="<%[ New HTTP Basic user ]%>" />
37 <com:Application.Common.Portlets.NewAuthClient ID="NewBasicClient" AuthType="basic" OnCallback="loadBasicUsers" />
40 AutoGenerateColumns="false"
42 AlternatingItemStyle.BackColor="#4e4e50"
46 ID="BasicUsernameColumn"
51 ID="BasicDeleteColumn"
53 ItemStyle.HorizontalAlign="Center"
56 <com:TActiveLinkButton
58 OnCommand="SourceTemplateControl.deleteBasicItem"
59 CommandParameter="<%=$this->getParent()->Data['username']%>"
60 Attributes.onclick="if(!confirm('<%[ Are you sure? ]%>')) return false;"
63 </com:TTemplateColumn>
64 </com:TActiveDataGrid>
67 <input type="button" class="bbutton" onclick="$('#<%=$this->NewOAuth2Client->ClientID%>new_auth_client').slideToggle();" value="<%[ New OAuth2 client ]%>" />
68 <com:Application.Common.Portlets.NewAuthClient ID="NewOAuth2Client" AuthType="oauth2" OnCallback="loadOAuth2Users" />
71 AutoGenerateColumns="false"
73 AlternatingItemStyle.BackColor="#4e4e50"
78 HeaderText="Client ID"
82 HeaderText="Redirect URI"
83 DataField="redirect_uri"
90 HeaderText="Bconsole Path"
91 DataField="bconsole_cfg_path"
94 ID="OAuth2DeleteColumn"
96 ItemStyle.HorizontalAlign="Center"
99 <com:TActiveLinkButton
101 OnCommand="SourceTemplateControl.deleteOAuth2Item"
102 CommandParameter="<%=$this->getParent()->Data['client_id']%>"
103 Attributes.onclick="if(!confirm('<%[ Are you sure? ]%>')) return false;"
104 Visible="<%=($this->getParent()->Data['client_id'] != $this->getPage()->main_client_id)%>"
107 </com:TTemplateColumn>
108 </com:TActiveDataGrid>
115 command: 'api_command',
116 result: 'api_result',
117 progress_bar: '<%=$this->Progress->ClientID%>',
118 progress_label: 'progress_label',
119 refresh_token: 'api_refresh'
122 storages: '/api/storages/',
123 clients: '/api/clients/limit/5/',
124 volumes: '/api/volumes/limit/4/',
125 jobs: '/api/jobs/limit/10/',
126 joblog: '/api/joblog/1/',
127 bvfs: '/api/bvfs/lsdirs/limit/8/'
130 baculum_auth: JSON.parse('<%=$this->auth_params%>'),
133 if (typeof(this.baculum_auth) == 'object') {
134 if (this.baculum_auth.auth_type == 'oauth2') {
135 this.init_oauth2_client();
136 } else if (this.baculum_auth.auth_type == 'basic') {
142 set_progress: function(value, text) {
143 $('#' + this.ids.progress_bar).progressbar('value', value);
144 $('#' + this.ids.progress_label).text(text);
146 init_tabs: function() {
147 $('#tabs').tabs({active: 0});
149 init_basic: function() {
150 this.set_progress(3, 'Basic auth ready...');
151 document.getElementById(this.ids.refresh_token).style.display = 'none';
153 init_oauth2_client: function() {
154 this.set_progress(1, 'Sending auth code request...');
155 var authorization_uri = document.location.origin + '/api/auth';
157 response_type: 'code',
158 client_id: this.baculum_auth.client_id,
159 redirect_uri: this.baculum_auth.redirect_uri,
160 scope: this.baculum_auth.scope.join(' ')
162 var uri = authorization_uri + '?' + $.param(auth_params);
163 var xhr = new XMLHttpRequest();
164 xhr.open('GET', uri, true);
165 xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
166 xhr.onreadystatechange = function() {
167 if (xhr.readyState == 4 && xhr.status == 200) {
168 var code_regex = /code=([\w]+)$/;
169 result = xhr.responseURL.match(code_regex);
171 this.send_token_request(result[1])
177 send_token_request: function(code) {
178 this.set_progress(2, 'Sending token request...');
179 var uri = document.location.origin + '/api/token';
181 grant_type: 'authorization_code',
183 client_id: this.baculum_auth.client_id,
184 client_secret: this.baculum_auth.client_secret,
185 redirect_uri: this.baculum_auth.redirect_uri
187 var request = $.ajax({
193 request.done(function(data) {
194 if (typeof(data) == 'object' && data.hasOwnProperty('access_token')) {
195 this.token = data.access_token;
196 this.set_progress(3, 'Access token: ' + this.token);
200 set_events: function() {
201 document.getElementById(this.ids.section).addEventListener('change', function(e) {
202 var el = e.srcElement || e.target;
203 this.set_default_command(el.value);
206 set_default_command: function(section) {
207 if (this.default_commands.hasOwnProperty(section)) {
208 document.getElementById(this.ids.command).value = this.default_commands[section];
211 send_request: function() {
212 var url = document.getElementById(this.ids.command).value;
214 if (this.baculum_auth.auth_type == 'oauth2' && this.token) {
215 headers = {'Authorization': 'Bearer ' + this.token};
216 } else if (this.baculum_auth.auth_type == 'basic') {
217 headers = {'Authorization': 'Basic ' + btoa(this.baculum_auth.login + ":" + this.baculum_auth.password)};
219 var request = $.ajax({
225 request.done(function(data) {
226 this.show_result(data);
229 show_result: function(data) {
230 document.getElementById(this.ids.result).textContent = JSON.stringify(data, null, 2);