Skip to content

Commit

Permalink
#114 Use relative URLs to call REST APIs from UI
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Feb 10, 2017
1 parent e99865a commit 1434b3d
Show file tree
Hide file tree
Showing 35 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion ui/app/scripts/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ angular.module('thehive', ['ngAnimate', 'ngMessages', 'ui.bootstrap', 'ui.router

$httpProvider.interceptors.push(function($rootScope, $q) {
var isApiCall = function(url) {
return url && url.startsWith('/api') && !url.startsWith('/api/stream');
return url && url.startsWith('./api') && !url.startsWith('./api/stream');
};

return {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/controllers/MigrationCtrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

$scope.migrate = function() {
$scope.migrating = true;
$http.post('/api/maintenance/migrate', {}, {
$http.post('./api/maintenance/migrate', {}, {
timeout: 10 * 60 * 60 * 1000 // 10 minutes
}).success(function() {
console.log('Migration started');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

var computedFieldName = 'computed.handlingDuration';

$http.post('/api/case/_stats', {
$http.post('./api/case/_stats', {
query: options.params.q,
stats: [{
_agg: 'time',
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/charts/histo-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
}
};

$http.post('/api/' + options.params.entity + '/_stats', {
$http.post('./api/' + options.params.entity + '/_stats', {
"query": options.params.q,
"stats": [{
"_agg": "time",
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/charts/metric-histo-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

scope.columnKeys = [];

$http.post('/api/' + options.params.entity + '/_stats', {
$http.post('./api/' + options.params.entity + '/_stats', {
"query": options.params.q,
"stats": [{
"_agg": "time",
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/entityLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
}
// Call the link function to link the given scope and
// a Clone Attach Function,
// http://docs.angularjs.org/api/ng.$compile :
// http://docs.angularjs.org./api/ng.$compile :
// "Calling the linking function returns the element of the
// template.
// It is either the original element passed in,
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/flow/flow-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
};
scope.showImage = function(attachmentId, attachmentName) {
$uibModal.open({
template: '<img style="width:100%" src="/api/datastore/' + attachmentId + '" alt="' + attachmentName + '"></img>',
template: '<img style="width:100%" src="./api/datastore/' + attachmentId + '" alt="' + attachmentName + '"></img>',
size: 'lg'
});
};
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/logEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
};
scope.showImage = function() {
$uibModal.open({
template: '<img style="width:100%" src="/api/datastore/' + scope.log.attachment.id + '" alt="' + scope.log.attachment.name + '"></img>',
template: '<img style="width:100%" src="./api/datastore/' + scope.log.attachment.id + '" alt="' + scope.log.attachment.name + '"></img>',
size: 'lg'
});
};
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
return;
}

var reportUrl = '/api/connector/cortex/report/template/content/' + scope.name + '/' + scope.reportType;
var reportUrl = './api/connector/cortex/report/template/content/' + scope.name + '/' + scope.reportType;

// find report template
$templateRequest(reportUrl, true)
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/directives/search/search-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
};
scope.showImage = function(attachmentId, attachmentName) {
$uibModal.open({
template: '<img style="width:100%" src="/api/datastore/' + attachmentId + '" alt="' + attachmentName + '"></img>',
template: '<img style="width:100%" src="./api/datastore/' + attachmentId + '" alt="' + attachmentName + '"></img>',
size: 'lg'
});
};
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/AfkSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
prompt: function() {
var defer = $q.defer();

$http.get('/api/stream/status').then(function(response) {
$http.get('./api/stream/status').then(function(response) {

if(response.data.warning === true) {
if(current !== null) {
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/services/AnalyzerSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
angular.module('theHiveServices')
.factory('AnalyzerSrv', function ($resource, $q) {
var analyzers = null,
resource = $resource('/api/connector/cortex/analyzer/:analyzerId', {}, {
resource = $resource('./api/connector/cortex/analyzer/:analyzerId', {}, {
query: {
method: 'GET',
url: '/api/connector/cortex/analyzer',
url: './api/connector/cortex/analyzer',
isArray: true
},
get: {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/AuditSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
max = 10;
}

$http.get('/api/flow', {
$http.get('./api/flow', {
'params': {
'rootId': rootId,
'count': max
Expand Down
6 changes: 3 additions & 3 deletions ui/app/scripts/services/AuthenticationSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var self = {
currentUser: null,
login: function(username, password, success, failure) {
$http.post('/api/login', {
$http.post('./api/login', {
'user': username,
'password': password
}).success(function(data, status, headers, config) {
Expand All @@ -18,7 +18,7 @@
});
},
logout: function(success, failure) {
$http.get('/api/logout').success(function(data, status, headers, config) {
$http.get('./api/logout').success(function(data, status, headers, config) {
self.currentUser = null;

if (angular.isFunction(success)) {
Expand All @@ -32,7 +32,7 @@
},
current: function(success, failure) {
var result = {};
$http.get('/api/user/current').success(function(data, status, headers, config) {
$http.get('./api/user/current').success(function(data, status, headers, config) {
self.currentUser = data;

UtilsSrv.shallowClearAndCopy(data, result);
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/services/CaseArtifactSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
var factory = {
api: function() {
if(api === null) {
return FileResource('/api/case/:caseId/artifact/:artifactId', {}, {
return FileResource('./api/case/:caseId/artifact/:artifactId', {}, {
update: {
method: 'PATCH'
},
similar: {
url: '/api/case/artifact/:artifactId/similar',
url: './api/case/artifact/:artifactId/similar',
isArray: true
}
});
Expand Down
6 changes: 3 additions & 3 deletions ui/app/scripts/services/CaseSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
'use strict';
angular.module('theHiveServices')
.factory('CaseSrv', function($resource) {
return $resource('/api/case/:caseId', {}, {
return $resource('./api/case/:caseId', {}, {
update: {
method: 'PATCH'
},
links: {
method: 'GET',
url: '/api/case/:caseId/links',
url: './api/case/:caseId/links',
isArray: true
},
merge: {
method: 'POST',
url: '/api/case/:caseId/_merge/:mergedCaseId',
url: './api/case/:caseId/_merge/:mergedCaseId',
params: {
caseId: '@caseId',
mergedCaseId: '@mergedCaseId',
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/CaseTaskSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';
angular.module('theHiveServices')
.factory('CaseTaskSrv', function($resource) {
return $resource('/api/case/:caseId/task/:taskId', {}, {
return $resource('./api/case/:caseId/task/:taskId', {}, {
update: {
method: 'PATCH'
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/CortexSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
angular.module('theHiveServices')
.factory('CortexSrv', function ($q, $http, $rootScope, $uibModal, StatSrv, StreamSrv, AnalyzerSrv, PSearchSrv) {

var baseUrl = '/api/connector/cortex';
var baseUrl = './api/connector/cortex';

var factory = {
list: function (caseId, observableId, callback) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/JobSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
'use strict';
angular.module('theHiveServices')
.factory('JobSrv', function($resource) {
return $resource('/api/case/artifact/:artifactId/job/:analyzerId', {}, {}, {});
return $resource('./api/case/artifact/:artifactId/job/:analyzerId', {}, {}, {});
});
})();
2 changes: 1 addition & 1 deletion ui/app/scripts/services/ListSrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices').factory('ListSrv', function($resource) {
return $resource('/api/list/:listId', {}, {
return $resource('./api/list/:listId', {}, {
query: {
method: 'GET',
isArray: false
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/MetricsCacheSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
angular.module('theHiveServices').factory('MetricsCacheSrv', function($resource, $q) {

var metrics = null,
resource = $resource('/api/list/:listId', {}, {
resource = $resource('./api/list/:listId', {}, {
query: {
method: 'GET',
isArray: false
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/MispSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
angular.module('theHiveServices')
.factory('MispSrv', function($q, $http, $rootScope, StatSrv, StreamSrv, PSearchSrv) {

var baseUrl = '/api/connector/misp';
var baseUrl = './api/connector/misp';

var factory = {
list: function(callback) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/ReportTemplateSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict';
angular.module('theHiveServices')
.factory('ReportTemplateSrv', function($resource, $http) {
var baseUrl = '/api/connector/cortex/report/template';
var baseUrl = './api/connector/cortex/report/template';
var resource = $resource(baseUrl, {}, {
query: {
method: 'POST',
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/services/SearchSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
return function(cb, filter, objectType, range, sort, nparent, nstats) {
var url;
if (!angular.isString(objectType) || objectType === 'any') {
url = '/api/_search';
url = './api/_search';
} else {
url = '/api/' + objectType.replace(/_/g, '/') + '/_search';
url = './api/' + objectType.replace(/_/g, '/') + '/_search';
}

var params = '';
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/StatSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
_agg: 'count'
});

return $http.post('/api/' + config.objectType.replace(/_/g, '/') + '/_stats', {
return $http.post('./api/' + config.objectType.replace(/_/g, '/') + '/_stats', {
query: config.query,
stats: stats
})
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/services/StreamSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
self.isPolling = true;

// Poll stream changes
$http.get('/api/stream/' + self.streamId).success(function(data, status) {
$http.get('./api/stream/' + self.streamId).success(function(data, status) {
// Flag polling end
self.isPolling = false;

Expand Down Expand Up @@ -118,7 +118,7 @@
return;
}

$http.post('/api/stream').success(function(streamId) {
$http.post('./api/stream').success(function(streamId) {
self.streamId = streamId;
self.poll(self.streamId);
}).error(function(data, status) {
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/TaskLogSrv.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
angular.module('theHiveServices').factory('TaskLogSrv', function(FileResource) {
return FileResource('/api/case/task/:taskId/log/:logId', {}, {
return FileResource('./api/case/task/:taskId/log/:logId', {}, {
update: {
method: 'PATCH'
}
Expand Down
4 changes: 2 additions & 2 deletions ui/app/scripts/services/TemplateSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
'use strict';
angular.module('theHiveServices')
.factory('TemplateSrv', function($resource) {
return $resource('/api/case/template/:templateId', {}, {
return $resource('./api/case/template/:templateId', {}, {
update: {
method: 'PATCH',
},
query: {
method: 'POST',
url: '/api/case/template/_search',
url: './api/case/template/_search',
isArray: true,
params: {
range: 'all'
Expand Down
10 changes: 5 additions & 5 deletions ui/app/scripts/services/UserSrv.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
angular.module('theHiveServices')
.factory('UserSrv', function($resource, $http, $q, AlertSrv, UtilsSrv) {
'use strict';
var res = $resource('/api/user/:userId', {}, {
var res = $resource('./api/user/:userId', {}, {
query: {
method: 'POST',
url: '/api/user/_search',
url: './api/user/_search',
isArray: true
},
update: {
method: 'PATCH'
},
changePass: {
method: 'POST',
url: '/api/user/:userId/password/change'
url: './api/user/:userId/password/change'
},
setPass: {
method: 'POST',
url: '/api/user/:userId/password/set'
url: './api/user/:userId/password/set'
}
});
/**
Expand Down Expand Up @@ -78,7 +78,7 @@ angular.module('theHiveServices')
query: query
};

$http.post('/api/user/_search', post)
$http.post('./api/user/_search', post)
.then(function(response) {
defer.resolve(response.data);
});
Expand Down
2 changes: 1 addition & 1 deletion ui/app/scripts/services/VersionSrv.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if(cache !== null) {
deferred.resolve(cache);
} else {
$http.get('/api/status').then(function(response) {
$http.get('./api/status').then(function(response) {
cache = response.data;
deferred.resolve(cache);
}, function(rejection) {
Expand Down
6 changes: 3 additions & 3 deletions ui/app/views/directives/flow/task-log.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@
<div class="flow-item-updates wrap">
<span ng-bind="base.details.message| limitTo: 250"></span>
<span class="text-muted" ng-if="base.details.message.length > 250">...</span>
</div>
</div>

<div class="flow-item-updates vpad10 clearfix" ng-if="base.object.attachment.name" ng-init="hasImage = isImage(base.object.attachment.contentType)">
<div class="file-box">
<div class="file">
<div class="image" ng-show="hasImage">
<img class="btn img-responsive img-thumbnail" src="/api/datastore/{{base.object.attachment.id}}"
<img class="btn img-responsive img-thumbnail" ng-src="./api/datastore/{{base.object.attachment.id}}"
alt="{{base.object.attachment.name}}"
ng-click="showImage(base.object.attachment.id, base.object.attachment.name)"></img>
</div>

<a href="/api/datastore/{{base.object.attachment.id}}?name={{base.object.attachment.name}}" target="_blank">
<a href="./api/datastore/{{base.object.attachment.id}}?name={{base.object.attachment.name}}" target="_blank">
<div class="icon" ng-hide="isImage(base.object.attachment.contentType)">
<i class="glyphicon glyphicon-file"></i>
</div>
Expand Down
4 changes: 2 additions & 2 deletions ui/app/views/directives/log-entry.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ <h5>
<div class="file-box">
<div class="file">
<div class="image" ng-show="isImage(log.attachment.contentType)">
<img class="btn img-responsive" src="/api/datastore/{{log.attachment.id}}" alt="{{log.attachment.name}}" class="img-thumbnail" width="200px" ng-click="showImage()"></img>
<img class="btn img-responsive" ng-src="./api/datastore/{{log.attachment.id}}" alt="{{log.attachment.name}}" class="img-thumbnail" width="200px" ng-click="showImage()"></img>
</div>

<a href="/api/datastore/{{log.attachment.id}}?name={{log.attachment.name}}" target="_blank">
<a href="./api/datastore/{{log.attachment.id}}?name={{log.attachment.name}}" target="_blank">
<div class="icon" ng-hide="isImage(log.attachment.contentType)">
<i class="glyphicon glyphicon-file"></i>
</div>
Expand Down
Loading

0 comments on commit 1434b3d

Please sign in to comment.